Adding code to call into library entry pt's

This commit is contained in:
Justin Ethier 2015-05-18 18:08:45 -04:00
parent a4a6e7d602
commit d2049f0f7e
2 changed files with 39 additions and 9 deletions

View file

@ -911,7 +911,8 @@
lib-name
lib-exports
imported-globals
globals)
globals
required-libs)
(set! *global-syms* (append globals imported-globals))
(let ((compiled-program
(apply string-append
@ -966,9 +967,15 @@
lambdas)
; Emit entry point
(if program?
(emit "static void c_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; { ")))
(cond
(program?
(for-each
(lambda (lib-name)
(emit (string-append "extern void c_" (lib:name->string lib-name) "_entry_pt(int argc, closure env, closure cont);")))
required-libs)
(emit "static void c_entry_pt(argc, env,cont) int argc; closure env,cont; { "))
(else
(emit (string-append "void c_" (lib:name->string lib-name) "_entry_pt(argc, env,cont) int argc; closure env,cont; { "))))
;; Initialize global table
(for-each
@ -1041,8 +1048,30 @@
(emits
(string-append "Cyc_global_variables = &" head-pair ";"))))
(if program?
(emit compiled-program))
(cond
(program?
;; Emit code to initialize each module (compiled Scheme library)
(let ((this-clo "c_done")
(prev-clo "c_done"))
;; TODO: need to wrap this in a well-known function (c_program_main??)
;; and call into it from the closure chain
(emit compiled-program)
(for-each
(lambda (lib-name)
(emit
(string-append
"mclosure1(" this-clo
", c_" (lib:name->string lib-name) "_entry_pt"
", &" prev-clo ");"))
(set! prev-clo this-clo)
(set! this-clo (mangle (gensym "c")))
)
required-libs)
(emit
(string-append "(" prev-clo ".fn)(0, &" prev-clo ");"))
)))
(emit "}")
(if program?
(emit *c-main-function*))))

View file

@ -30,7 +30,7 @@
;; Code emission.
; c-compile-and-emit : (string -> A) exp -> void
(define (c-compile-and-emit input-program)
(define (c-compile-and-emit input-program lib-deps)
(call/cc
(lambda (return)
(define globals '())
@ -196,7 +196,8 @@
lib-name
lib-exports
imported-vars
module-globals)
module-globals
lib-deps)
(return '())))) ;; No codes to return
;; TODO: longer-term, will be used to find where cyclone's data is installed
@ -228,7 +229,7 @@
(with-output-to-file
src-file
(lambda ()
(c-compile-and-emit program)))))
(c-compile-and-emit program lib-deps)))))
(result (create-c-file in-prog)))
;; Load other modules if necessary
(cond