mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-14 08:17:35 +02:00
WIP - mangling of library globals
This commit is contained in:
parent
067f8b0ad7
commit
de8196aa80
1 changed files with 27 additions and 1 deletions
|
@ -1348,6 +1348,12 @@
|
||||||
|
|
||||||
(define cgen:mangle-global #f)
|
(define cgen:mangle-global #f)
|
||||||
|
|
||||||
|
(define (import->string import)
|
||||||
|
(foldr (lambda (id s)
|
||||||
|
(string-append "_" (mangle id) s))
|
||||||
|
""
|
||||||
|
import))
|
||||||
|
|
||||||
(define (mta:code-gen input-program
|
(define (mta:code-gen input-program
|
||||||
program?
|
program?
|
||||||
lib-name
|
lib-name
|
||||||
|
@ -1359,7 +1365,27 @@
|
||||||
(set! *global-syms* (append globals (lib:idb:ids imported-globals)))
|
(set! *global-syms* (append globals (lib:idb:ids imported-globals)))
|
||||||
(set! cgen:mangle-global
|
(set! cgen:mangle-global
|
||||||
(lambda (ident)
|
(lambda (ident)
|
||||||
(mangle-global ident)))
|
(cond
|
||||||
|
;; Do not perform additional mangling for top-level globals
|
||||||
|
((and program?
|
||||||
|
(member ident globals))
|
||||||
|
(mangle-global ident))
|
||||||
|
;; Identifier exported by the library being compiled
|
||||||
|
((member ident globals)
|
||||||
|
(let ((suffix (import->string lib-name))
|
||||||
|
(prefix (mangle-global ident)))
|
||||||
|
(string-append prefix suffix)))
|
||||||
|
;; Identifier exported by another library
|
||||||
|
(else
|
||||||
|
(let ((import (lib:idb:id->import imported-globals ident)))
|
||||||
|
(cond
|
||||||
|
((not import)
|
||||||
|
(error `(Unable to find a library importing ,ident)))
|
||||||
|
(else
|
||||||
|
(let ((suffix (import->string import))
|
||||||
|
(prefix (mangle-global ident)))
|
||||||
|
(string-append prefix suffix)))))))))
|
||||||
|
|
||||||
(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,
|
||||||
|
|
Loading…
Add table
Reference in a new issue