summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson@vistahigherlearning.com>2022-08-10 18:12:44 -0400
committerDavid Thompson <dthompson@vistahigherlearning.com>2022-08-10 18:50:08 -0400
commitc441f8f092cd5da5b09e3e4e826141d915189ab5 (patch)
tree93400e2620238f29cbd527eec8684ea117a6be6f
Step 1: Integers
-rw-r--r--Makefile7
-rw-r--r--compiler.scm17
-rw-r--r--test.c6
3 files changed, 30 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..513a132
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,7 @@
+test:
+ gcc -c scheme_entry.S
+ gcc -c test.c
+ gcc -o test scheme_entry.o test.o
+ ./test
+
+.PHONY: test
diff --git a/compiler.scm b/compiler.scm
new file mode 100644
index 0000000..1285ac6
--- /dev/null
+++ b/compiler.scm
@@ -0,0 +1,17 @@
+(use-modules (ice-9 format))
+
+(define (emit template-string . args)
+ (apply format #t template-string args)
+ (newline))
+
+(define (compile-program x)
+ (with-output-to-file "scheme_entry.S"
+ (lambda ()
+ (display ".text
+.p2align 4
+.globl scheme_entry
+.type scheme_entry, @function
+scheme_entry:
+")
+ (emit "movl $~a, %eax" x)
+ (emit "ret"))))
diff --git a/test.c b/test.c
new file mode 100644
index 0000000..2d814e0
--- /dev/null
+++ b/test.c
@@ -0,0 +1,6 @@
+#include <stdio.h>
+
+int main(int argc, char** argv) {
+ printf("%d\n", scheme_entry());
+ return 0;
+}