Remove C dependency, directly emit _start
[scheme.git] / codegen.scm
index a19b53df53fa239bc700a5d06cccfd86298d7601..968a428cd2f442bf820ea37c0a01a3e92047e4b5 100644 (file)
 
     (for-each codegen-lambda lambdas)
 
-    (emit ".globl _scheme_entry")
-    (emit "_scheme_entry:")
+    (emit ".globl _start")
+    (emit "_start:")
+    (codegen-expr xform-prog 0 '())
 
-
-    (amd64-abi
-     (lambda () (codegen-expr xform-prog 0 '())))))
+                                       ; exit syscall
+    (emit "mov %rax, %rdi")
+    (emit "mov $60, %rax")
+    (emit "syscall")))
 
 (define (compile-to-binary program output)
   (when (not (eq? (typecheck program) 'int)) (error #f "not an int"))
     (when (file-exists? tmp-path) (delete-file tmp-path))
     (with-output-to-file tmp-path
       (lambda () (codegen program)))
-    (system (format "clang -fomit-frame-pointer /tmp/a.s rts.c -o ~a" output))))
+    (system (format "clang -nostdlib /tmp/a.s -o ~a" output))))