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-name
lib-exports lib-exports
imported-globals imported-globals
globals) globals
required-libs)
(set! *global-syms* (append globals imported-globals)) (set! *global-syms* (append globals imported-globals))
(let ((compiled-program (let ((compiled-program
(apply string-append (apply string-append
@ -966,9 +967,15 @@
lambdas) lambdas)
; Emit entry point ; Emit entry point
(if program? (cond
(emit "static void c_entry_pt(argc, env,cont) int argc; closure env,cont; { ") (program?
(emit (string-append "void c_" (lib:name->string lib-name) "_entry_pt(argc, env,cont) int argc; closure env,cont; { "))) (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 ;; Initialize global table
(for-each (for-each
@ -1041,8 +1048,30 @@
(emits (emits
(string-append "Cyc_global_variables = &" head-pair ";")))) (string-append "Cyc_global_variables = &" head-pair ";"))))
(if program? (cond
(emit compiled-program)) (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 "}") (emit "}")
(if program? (if program?
(emit *c-main-function*)))) (emit *c-main-function*))))

View file

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