blob: c1563a0b857284bb0963e6ada2ef8205d803fadc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
(define-module (c compiler)
:use-module ((srfi srfi-1) :select (remove))
:use-module (srfi srfi-71)
:use-module ((c cpp-environment) :select (enter-file))
:use-module ((hnh util) :select (-> ->>))
:use-module ((hnh util io) :select (read-file))
:use-module ((c preprocessor2)
:select (preprocess-string
make-default-environment))
:use-module ((hnh util values) :select (abort* on-fst))
:use-module ((c ast) :select (build-ast))
:export (run-compiler
compile-string
compile-string*
the-environment
))
;;; 5.1.11.2 Translation phases
(define* (run-compiler path key: (environment (make-default-environment)))
(-> path read-file (compile-string (enter-file environment path))))
(define* (compile-string str optional: (environment (make-default-environment)))
(on-fst (build-ast (abort* (preprocess-string str environment)))))
(define the-environment (make-parameter (make-default-environment)))
(define* (compile-string* str)
(let ((result cpp-env (compile-string str)))
(if (null? result)
(compile-string (string-append str ";")
(the-environment))
result)))
|