cgen:mangle-global

This commit is contained in:
Justin Ethier 2016-03-30 01:22:47 -04:00
parent e67b67895f
commit 067f8b0ad7

View file

@ -885,7 +885,7 @@
(define (c-compile-ref exp) (define (c-compile-ref exp)
(c-code (c-code
(if (member exp *global-syms*) (if (member exp *global-syms*)
(mangle-global exp) (cgen:mangle-global exp)
(mangle exp)))) (mangle exp))))
; c-compile-args : list[exp] (string -> void) -> string ; c-compile-args : list[exp] (string -> void) -> string
@ -1346,6 +1346,8 @@
"}\n")) "}\n"))
formals*)))) formals*))))
(define cgen:mangle-global #f)
(define (mta:code-gen input-program (define (mta:code-gen input-program
program? program?
lib-name lib-name
@ -1355,6 +1357,9 @@
required-libs required-libs
src-file) src-file)
(set! *global-syms* (append globals (lib:idb:ids imported-globals))) (set! *global-syms* (append globals (lib:idb:ids imported-globals)))
(set! cgen:mangle-global
(lambda (ident)
(mangle-global ident)))
(let ((compiled-program-lst '()) (let ((compiled-program-lst '())
(compiled-program #f)) (compiled-program #f))
;; Compile program, using for-each to guarantee execution order, ;; Compile program, using for-each to guarantee execution order,
@ -1376,14 +1381,14 @@
(for-each (for-each
(lambda (global) (lambda (global)
(emits "object ") (emits "object ")
(emits (mangle-global (car global))) (emits (cgen:mangle-global (car global)))
(emits " = nil;\n")) (emits " = nil;\n"))
*globals*) *globals*)
;; Globals defined by another module ;; Globals defined by another module
(for-each (for-each
(lambda (global) (lambda (global)
(emits "extern object ") (emits "extern object ")
(emits (mangle-global global)) (emits (cgen:mangle-global global))
(emits ";\n")) (emits ";\n"))
(lib:idb:ids imported-globals)) (lib:idb:ids imported-globals))
(emit "#include \"cyclone/runtime.h\"") (emit "#include \"cyclone/runtime.h\"")
@ -1461,7 +1466,7 @@
(for-each (for-each
(lambda (global) (lambda (global)
(emits "\n add_global((object *) &") (emits "\n add_global((object *) &")
(emits (mangle-global (car global))) (emits (cgen:mangle-global (car global)))
(emits ");")) (emits ");"))
*globals*) *globals*)
(emit "") (emit "")
@ -1478,7 +1483,7 @@
(lambda (global) (lambda (global)
(emits (c:allocs->str2 (c:allocs (caddr global)) prefix " \n")) (emits (c:allocs->str2 (c:allocs (caddr global)) prefix " \n"))
(emits prefix) (emits prefix)
(emits (mangle-global (car global))) (emits (cgen:mangle-global (car global)))
(emits " = ") (emits " = ")
(emits (c:body (caddr global))) (emits (c:body (caddr global)))
(emit "; ")))) (emit "; "))))
@ -1496,7 +1501,7 @@
(pair-sym (mangle (gensym 'pair)))) (pair-sym (mangle (gensym 'pair))))
(emits* (emits*
" make_cvar(" cvar-sym " make_cvar(" cvar-sym
", (object *)&" (mangle-global (car g)) ");") ", (object *)&" (cgen:mangle-global (car g)) ");")
(emits* (emits*
"make_cons(" pair-sym ", find_or_add_symbol(\"" (symbol->string (car g)) "make_cons(" pair-sym ", find_or_add_symbol(\"" (symbol->string (car g))
"\"), &" cvar-sym ");\n") "\"), &" cvar-sym ");\n")
@ -1559,7 +1564,7 @@
;(emit "((cont)->fn)(1, cont, cont);") ;(emit "((cont)->fn)(1, cont, cont);")
(emit* (emit*
"(((closure)" "(((closure)"
(mangle-global (lib:name->symbol lib-name)) (cgen:mangle-global (lib:name->symbol lib-name))
")->fn)(data, 1, cont, cont);") ")->fn)(data, 1, cont, cont);")
)) ))