From 4b211430c4d800503944316c5b67a85f854d7a33 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Thu, 7 May 2015 15:15:17 -0400 Subject: [PATCH] Allow generated C files to compile --- Makefile | 2 +- cgen.scm | 24 ++++++++++-------------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index f5f428de..29eff41f 100644 --- a/Makefile +++ b/Makefile @@ -42,7 +42,7 @@ test: $(TESTFILES) cyclone # A temporary testing directive .PHONY: test2 test2: examples/hello-library/int-test/hello.c libcyclone.a -# ./cyclone -t examples/hello-library/hello.scm + ./cyclone -t examples/hello-library/hello.scm # ./cyclone -t examples/hello-library/libs/lib2.sld # gcc examples/hello-library/int-test/lib2.c -I. -g -c -o lib2.o # gcc examples/hello-library/int-test/hello.c -L. -lcyclone -lm -I. -g -o hello diff --git a/cgen.scm b/cgen.scm index b4b59a00..3f590408 100644 --- a/cgen.scm +++ b/cgen.scm @@ -99,11 +99,6 @@ (else (vector-set! *c-call-arity* arity #t)))) -(define (emit-c-macros) - (c-macro-declare-globals) - (c-macro-GC-globals) - (emit-c-arity-macros 0)) - (define (emit-c-arity-macros arity) (when (<= arity *c-call-max-args*) (cond @@ -172,25 +167,20 @@ (define (c-macro-GC-globals) ; emit directly to be more efficient ; TODO: convert all c-macro functions to direct emit??? - (emit "#define GC_GLOBALS \\") - (emits "{") (for-each (lambda (global) - (emits " \\\n transp(") + (emits "\n add_global((object *) &") (emits (mangle-global (car global))) (emits ");")) *globals*) - (emit "}") (emit "")) (define (c-macro-declare-globals) - (emits "#define DECLARE_GLOBALS ") (for-each (lambda (global) - (emit " \\") - (emits " static volatile object ") + (emits "object ") (emits (mangle-global (car global))) - (emits " = nil;")) + (emits " = nil;\n")) *globals*) (emit "") (emit "")) @@ -945,8 +935,11 @@ (if (member 'eval globals) (emit "#define CYC_EVAL")) - (emit-c-macros) + (emit-c-arity-macros 0) + (emit "#include \"cyclone.h\"") + (c-macro-declare-globals) (emit "#include \"runtime.h\"") + (emit "#include \"runtime-main.h\"") ;; Emit symbols (for-each @@ -978,6 +971,9 @@ (emit " static void c_entry_pt(argc, env,cont) int argc; closure env,cont; { ") + ;; Initialize global table + (c-macro-GC-globals) + ;; Initialize symbol table (for-each (lambda (sym)