More library integration

This commit is contained in:
Justin Ethier 2015-05-12 18:20:48 -04:00
parent 7b0d1a74a0
commit c9af448be2
3 changed files with 36 additions and 15 deletions

View file

@ -164,16 +164,6 @@
assign (number->string n) ";")
""))
(define (c-macro-declare-globals)
(for-each
(lambda (global)
(emits "object ")
(emits (mangle-global (car global)))
(emits " = nil;\n"))
*globals*)
(emit "")
(emit ""))
;;; Compilation routines.
;; Return generated code that also requests allocation of C variables on stack
@ -916,14 +906,33 @@
"}\n"))
formals*))))
(define (mta:code-gen input-program globals program? lib-name lib-exports imports)
(set! *global-syms* globals)
(define (mta:code-gen input-program
program?
lib-name
lib-exports
imported-globals
globals)
(set! *global-syms* (append globals imported-globals))
(let ((compiled-program
(apply string-append
(map c-compile-program input-program))))
(emit-c-arity-macros 0)
(emit "#include \"cyclone.h\"")
(c-macro-declare-globals)
;; Globals defined in this module
(for-each
(lambda (global)
(emits "object ")
(emits (mangle-global (car global)))
(emits " = nil;\n"))
*globals*)
;; Globals defined by another module
(for-each
(lambda (global)
(emits "extern object ")
(emits (mangle-global global))
(emits ";\n"))
imported-globals)
(emit "#include \"runtime.h\"")
(if program?

View file

@ -28,6 +28,7 @@
(call/cc
(lambda (return)
(define globals '())
(define module-globals '()) ;; Globals defined by this module
(define program? #t) ;; Are we building a program or a library?
(define imports '())
(define imported-vars '())
@ -92,7 +93,8 @@
; set!'s below, since all remaining phases operate on set!, not define.
;
; TODO: consider moving some of this alpha-conv logic below back into trans?
(set! globals (append imported-vars (global-vars input-program)))
(set! module-globals (global-vars input-program))
(set! globals (append imported-vars module-globals))
(set! input-program
(map
(lambda (expr)
@ -108,6 +110,7 @@
(cond
(program?
(set! globals (cons 'call/cc globals))
(set! module-globals (cons 'call/cc module-globals))
(set! input-program
(cons
;; call/cc must be written in CPS form, so it is added here
@ -172,7 +175,12 @@
(exit)))
(trace:info "---------------- C code:")
(mta:code-gen input-program globals program? lib-name lib-exports imports)
(mta:code-gen input-program
program?
lib-name
lib-exports
imported-vars
module-globals)
(return '())))) ;; No codes to return
;; TODO: longer-term, will be used to find where cyclone's data is installed
@ -223,6 +231,7 @@
(if program?
(system
;; -I is a hack, real answer is to use 'make install' to place .h file
TODO: need to link to object files from lib:import->obj-file
(string-append "gcc " src-file " -L. -lcyclone -lm -I. -g -o " exec-file))
(system
(string-append "gcc " src-file " -I. -g -c -o " exec-file ".o"))))))

View file

@ -1801,6 +1801,9 @@
(string-append "/" (symbol->string i)))
import))
".sld"))
;; Resolve, EG: (libs lib2) ==> lib2.o
(define (lib:import->obj-file import)
'TODO)
;; Read export list for a given import
(define (lib:import->export-list import basedir)
(let* ((dir (string-append basedir (lib:import->filename import)))