From 0f07ef8ebfcbb7f9077246eec08fd1435cdaee46 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 26 Apr 2025 01:35:36 +0530 Subject: Compile library to WASM using GraalVM. Add main functions for library. Convert to WASM image. Setup public for cljcc website. --- public/index.html | 268 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 268 insertions(+) create mode 100644 public/index.html (limited to 'public/index.html') diff --git a/public/index.html b/public/index.html new file mode 100644 index 0000000..c0820b2 --- /dev/null +++ b/public/index.html @@ -0,0 +1,268 @@ + + + + + + cljcc: C compiler in Clojure + + + + + +
+
+

cljcc

+

C compiler implemented in Clojure.

+
+ +
+

C compiler implemented in Clojure. Based on Writing a C Compiler by Nora Sandler

+

+ Clojure codebase is compiled to WASM using GraalVM native image. +

+ +
+ +
+

+ I have only implemented the first 12 chapters of the book. Refer the supported syntax section below. +

+ +

+ Wrote about how I approached implementing this in Clojure. Writing a C Compiler in Clojure +

+
+ + + +
+
+ + +
+ +
+ + +
+
+ +
+

Compilation Stage:

+
+ + + + + + +
+
+ +
+ +
+ + + +
+

Supported Syntax

+ +
+
+

Basic Features

+
+// Types
+int, long
+
+// Variables
+int x;                  // Local variables
+static long count = 0;   // Static variables
+extern long count2 = 0;  // Extern variables
+
+// Control Flow
+if (x > 0) { ... } else { ... }
+for (int i = 0; i < n; i++) { ... }
+while (condition) { ... }
+do { ... } while (condition);
+
+// Functions
+int main(void);
+int add(int a, int b) { return a + b; }
+
+// Operators
++, -, *, /, %, =, ==, !=, >, <, >=, <=, &&, ||, !
+
+ +
+

Example Code

+ +
+int main(void) {
+  return 42;
+}
+
+ +
+int main(void) {
+  static int x = 1;
+  if (x == 42)
+    return x;
+  x = x + 1;
+  return main();
+}
+ + +
+static int x = 20;
+
+int main(void) {
+  int y = 22;
+  return x + y;
+}
+
+ +
+ + + + -- cgit v1.2.3