mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-23 20:15:05 +02:00
Allow generated C files to compile
This commit is contained in:
parent
92e25a8640
commit
4b211430c4
2 changed files with 11 additions and 15 deletions
2
Makefile
2
Makefile
|
@ -42,7 +42,7 @@ test: $(TESTFILES) cyclone
|
||||||
# A temporary testing directive
|
# A temporary testing directive
|
||||||
.PHONY: test2
|
.PHONY: test2
|
||||||
test2: examples/hello-library/int-test/hello.c libcyclone.a
|
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
|
# ./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/lib2.c -I. -g -c -o lib2.o
|
||||||
# gcc examples/hello-library/int-test/hello.c -L. -lcyclone -lm -I. -g -o hello
|
# gcc examples/hello-library/int-test/hello.c -L. -lcyclone -lm -I. -g -o hello
|
||||||
|
|
24
cgen.scm
24
cgen.scm
|
@ -99,11 +99,6 @@
|
||||||
(else
|
(else
|
||||||
(vector-set! *c-call-arity* arity #t))))
|
(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)
|
(define (emit-c-arity-macros arity)
|
||||||
(when (<= arity *c-call-max-args*)
|
(when (<= arity *c-call-max-args*)
|
||||||
(cond
|
(cond
|
||||||
|
@ -172,25 +167,20 @@
|
||||||
(define (c-macro-GC-globals)
|
(define (c-macro-GC-globals)
|
||||||
; emit directly to be more efficient
|
; emit directly to be more efficient
|
||||||
; TODO: convert all c-macro functions to direct emit???
|
; TODO: convert all c-macro functions to direct emit???
|
||||||
(emit "#define GC_GLOBALS \\")
|
|
||||||
(emits "{")
|
|
||||||
(for-each
|
(for-each
|
||||||
(lambda (global)
|
(lambda (global)
|
||||||
(emits " \\\n transp(")
|
(emits "\n add_global((object *) &")
|
||||||
(emits (mangle-global (car global)))
|
(emits (mangle-global (car global)))
|
||||||
(emits ");"))
|
(emits ");"))
|
||||||
*globals*)
|
*globals*)
|
||||||
(emit "}")
|
|
||||||
(emit ""))
|
(emit ""))
|
||||||
|
|
||||||
(define (c-macro-declare-globals)
|
(define (c-macro-declare-globals)
|
||||||
(emits "#define DECLARE_GLOBALS ")
|
|
||||||
(for-each
|
(for-each
|
||||||
(lambda (global)
|
(lambda (global)
|
||||||
(emit " \\")
|
(emits "object ")
|
||||||
(emits " static volatile object ")
|
|
||||||
(emits (mangle-global (car global)))
|
(emits (mangle-global (car global)))
|
||||||
(emits " = nil;"))
|
(emits " = nil;\n"))
|
||||||
*globals*)
|
*globals*)
|
||||||
(emit "")
|
(emit "")
|
||||||
(emit ""))
|
(emit ""))
|
||||||
|
@ -945,8 +935,11 @@
|
||||||
(if (member 'eval globals)
|
(if (member 'eval globals)
|
||||||
(emit "#define CYC_EVAL"))
|
(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.h\"")
|
||||||
|
(emit "#include \"runtime-main.h\"")
|
||||||
|
|
||||||
;; Emit symbols
|
;; Emit symbols
|
||||||
(for-each
|
(for-each
|
||||||
|
@ -978,6 +971,9 @@
|
||||||
(emit "
|
(emit "
|
||||||
static void c_entry_pt(argc, env,cont) int argc; closure env,cont; { ")
|
static void c_entry_pt(argc, env,cont) int argc; closure env,cont; { ")
|
||||||
|
|
||||||
|
;; Initialize global table
|
||||||
|
(c-macro-GC-globals)
|
||||||
|
|
||||||
;; Initialize symbol table
|
;; Initialize symbol table
|
||||||
(for-each
|
(for-each
|
||||||
(lambda (sym)
|
(lambda (sym)
|
||||||
|
|
Loading…
Add table
Reference in a new issue