X-Git-Url: https://git.lukelau.me/?p=scheme.git;a=blobdiff_plain;f=codegen.scm;h=d30adc54e61a144097c3b0bb541a5835af8c028a;hp=04816ab75d533b6b950ff7fe17813cfce1880383;hb=e51b9e423665428c41cddac0642d1e34b18ca1da;hpb=43f8c4631ae0a3163c780e7511a96f6b05054544 diff --git a/codegen.scm b/codegen.scm index 04816ab..d30adc5 100644 --- a/codegen.scm +++ b/codegen.scm @@ -59,6 +59,8 @@ (for-each (lambda (form) (codegen-expr form inner-si inner-env)) body))) (define (codegen-var name si env) + (when (not (assoc name env)) + (error #f (format "Variable ~a is not bound" name))) (let ((offset (cdr (assoc name env)))) (emit "movq ~a(%rsp), %rax" offset))) @@ -259,10 +261,10 @@ (amd64-abi (lambda () (codegen-expr xform-prog 0 '()))))) -(define (compile-to-binary program) +(define (compile-to-binary program output) (when (not (eq? (typecheck program) 'int)) (error #f "not an int")) (let ([tmp-path "/tmp/a.s"]) (when (file-exists? tmp-path) (delete-file tmp-path)) (with-output-to-file tmp-path (lambda () (codegen program))) - (system "clang -fomit-frame-pointer /tmp/a.s rts.c"))) + (system (format "clang -fomit-frame-pointer /tmp/a.s rts.c -o ~a" output))))