This commit is contained in:
Justin Ethier 2015-05-18 22:11:56 -04:00
parent d2049f0f7e
commit 9b1b833b89
2 changed files with 21 additions and 10 deletions

View file

@ -969,13 +969,16 @@
; Emit entry point ; Emit entry point
(cond (cond
(program? (program?
(emit "static void c_entry_pt_first_lambda();")
(for-each (for-each
(lambda (lib-name) (lambda (lib-name)
(emit (string-append "extern void c_" (lib:name->string lib-name) "_entry_pt(int argc, closure env, closure cont);"))) (emit (string-append "extern void c_" (lib:name->string lib-name) "_entry_pt(int argc, closure env, closure cont);")))
required-libs) required-libs)
(emit "static void c_entry_pt(argc, env,cont) int argc; closure env,cont; { ")) (emit "static void c_entry_pt(argc, env,cont) int argc; closure env,cont; { "))
(else (else
(emit (string-append "void c_" (lib:name->string lib-name) "_entry_pt(argc, env,cont) int argc; closure env,cont; { ")))) (emit (string-append "void c_" (lib:name->string lib-name) "_entry_pt(argc, env,cont) int argc; closure env,cont; { "))
(emit (string-append "printf(\"init " (lib:name->string lib-name) "\\n\");"))
))
;; Initialize global table ;; Initialize global table
(for-each (for-each
@ -1053,24 +1056,32 @@
;; Emit code to initialize each module (compiled Scheme library) ;; Emit code to initialize each module (compiled Scheme library)
(let ((this-clo "c_done") (let ((this-clo "c_done")
(prev-clo "c_done")) (prev-clo "c_done"))
;; TODO: need to wrap this in a well-known function (c_program_main??) (emit
;; and call into it from the closure chain (string-append
(emit compiled-program) "mclosure1(" this-clo
", c_entry_pt_first_lambda, &" prev-clo ");"))
(for-each (for-each
(lambda (lib-name) (lambda (lib-name)
(set! prev-clo this-clo)
(set! this-clo (mangle (gensym "c")))
(emit (emit
(string-append (string-append
"mclosure1(" this-clo "mclosure1(" this-clo
", c_" (lib:name->string lib-name) "_entry_pt" ", c_" (lib:name->string lib-name) "_entry_pt"
", &" prev-clo ");")) ", &" prev-clo ");"))
(set! prev-clo this-clo)
(set! this-clo (mangle (gensym "c")))
) )
required-libs) required-libs)
(emit (emit
(string-append "(" prev-clo ".fn)(0, &" prev-clo ");")) ;; Start cont chain, but do not assume funcall1 macro was defined
))) (string-append "(" prev-clo ".fn)(0, &" prev-clo ", &" prev-clo ");"))
(emit "}")
(emit "static void c_entry_pt_first_lambda(int argc, closure env, closure cont) {")
(emit (string-append "printf(\"init first lambda\\n\");"))
(emit compiled-program)))
(else
;; Do not use funcall1 macro as it might not have been defined
(emit "cont = ((closure1_type *)cont)->elt1;")
(emit "((cont)->fn)(1, cont, cont);")))
(emit "}") (emit "}")
(if program? (if program?

View file

@ -7,5 +7,5 @@
(write "hello") (write "hello")
;(test-lib1-hello) ;(test-lib1-hello)
(write lib1-hello) (write (lib1-hello))
(write "world") (write "world")