diff options
Diffstat (limited to 'csc')
| -rw-r--r-- | csc/compiler.csc | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/csc/compiler.csc b/csc/compiler.csc index ee0b3b4..fcf7598 100644 --- a/csc/compiler.csc +++ b/csc/compiler.csc @@ -33,6 +33,8 @@ %library-define %library-ref %sequence) + (only (csc ir2) + *tail*) (only (csc linker) link) (only (csc list) @@ -41,6 +43,7 @@ loop return) (only (csc macros) + builtins-environment expand-body) (only (csc match) match) @@ -90,7 +93,7 @@ (loop for dir in library-roots for file-path = (loop for part in name collect (symbol->string part) into path - finally (return (join "/" (cons dir path)))) + finally (return (sprintf "{}/{}.csc" dir (join "/" path)))) if (file-exists? file-path) return file-path else @@ -109,11 +112,7 @@ (define env (make-map compare-symbols)) (loop for import in imports do (set! env - (merge env - (or (lookup library-symbols import #f) - (call-with-input-file (find-library import) - (lambda (f) - (compile-library (read f))))))) + (merge env (load-library import))) finally (return env))) (define library-code '()) (define (compile-library lib) @@ -144,8 +143,17 @@ (lookup env sym))))) (set! library-symbols (insert library-symbols library-name exported-symbols)) - (set! library-code (cons (ir1->bytecode expanded-body) library-code))) + (set! library-code (cons (ir1->bytecode expanded-body) library-code)) + exported-symbols) (_ (error "unexpected form in compile-library" lib)))) + (define (load-library lib) + (match lib + ('(csc builtins) + builtins-environment) + (_ (or (lookup library-symbols lib #f) + (call-with-input-file (find-library lib) + (lambda (f) + (compile-library (read f)))))))) (match program ((('import . imports1) ('import . imports2) . rest) |
