Add dodgy uname based host OS detection
[scheme.git] / codegen.scm
index 517cc110e545d9fe3490b0eeaf5c5d35b2c3d375..7c1c3a150727c969a991021fd2c3470e221f573e 100644 (file)
@@ -1,7 +1,8 @@
 (load "typecheck.scm")
 (load "ast.scm")
+(load "platform.scm")
 
-(define target 'darwin)
+(define target host-os)
 
 (define (emit . s)
   (begin
   (emit "not %rcx")      ; -%rcx = strlen + 1
   (emit "dec %rcx")
   
-  (case target
-    ('darwin
   (emit "movq %rbx, %rsi") ; string addr
   (emit "movq %rcx, %rdx") ; num bytes
   (emit "movq $1, %rdi")   ; file handle (stdout)
-     (emit "movq $0x2000004, %rax")) ; syscall 4 (write)
-    ('linux
-     (emit "mov %rbx, %rsi")  ; string addr
-     (emit "mov %rcx, %rdx")  ; num bytes
-     (emit "mov $1, %rax")    ; file handle (stdout)
-     (emit "mov $1, %rdi"))) ; syscall 1 (write)
+  (case target
+    ('darwin (emit "mov $0x2000004, %rax")) ; syscall 4 (write)
+    ('linux  (emit "mov $1, %rax"))) ; syscall 1 (write)
   (emit "syscall"))
 
 (define (range s n)
     (else (error #f "don't know how to codegen this"))))
 
 
-(define (fold-map f x) (fold-left append '() (map f x)))
 
 (define (free-vars prog)
   (define bound '())
       ('+ "_add")
       ('- "_sub")
       ('* "_mul")
+      ('! "_not")
+      ('= "_eq")
       ('bool->int "_bool2int")
-      (else (error #f "fill this out"))))
+      ('print "_print")
+      (else (error #f "don't know this builtin"))))
   (define (builtin-args e)
     (case e
       ('+ '(x y))
       ('- '(x y))
       ('* '(x y))
+      ('! '(x))
+      ('= '(x y))
       ('bool->int '(x))
-      (else (error #f "fill this out"))))
+      ('print '(x))
+      (else (error #f "don't know this builtin"))))
 
   (define (add-builtin-lambda e)
     (let* [(label (builtin-name e))