diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2022-07-03 12:36:35 +0200 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2022-07-07 21:31:32 +0200 |
commit | cba504b509cd59f376063f6e590362b197147a2c (patch) | |
tree | 954e90b0053ab4c0247ef242607654c862d02e48 /module/c/compiler.scm | |
parent | Merge branch 'new-object-system' into c-parser (diff) | |
download | calp-cba504b509cd59f376063f6e590362b197147a2c.tar.gz calp-cba504b509cd59f376063f6e590362b197147a2c.tar.xz |
Major work.
Diffstat (limited to '')
-rw-r--r-- | module/c/compiler.scm | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/module/c/compiler.scm b/module/c/compiler.scm new file mode 100644 index 00000000..121e6c07 --- /dev/null +++ b/module/c/compiler.scm @@ -0,0 +1,65 @@ +(define-module (c compiler) + :use-module ((c lex2) :select (lex)) + :use-module ((c trigraph) :select (replace-trigraphs)) + :use-module ((c line-fold) :select (fold-lines)) + :use-module (hnh util) + :export (run-compiler)) + +(define (comment->whitespace expr) + (match expr + (('comment _) '(whitespace " ")) + (other other))) + +" +#define __STDC__ 1 +#define __STDC_HOSTED__ 1 +#define __STDC_VERSION__ 201112L +" + +(define now (localtime (current-time))) +(define default-macros + (list + ;; 6.10.8 + (object-like-macro + identifier: "__STDC__" + body: '(preprocessing-token (pp-number "1"))) + (object-like-macro + identifier: "__STDC_HOSTED__" + body: '(preprocessing-token (pp-number "1"))) + (object-like-macro + identifier: "__STDC_VERSION__" + body: '(preprocessing-token (pp-number "201112L"))) + (object-like-macro + identifier: "__DATE__" + ;; TODO format should always be in + ;; english, and not tranlated + body: `(preprocessing-token (string-literal ,(strftime "%b %_d %Y" now)))) + (object-like-macro + identifier: "__TIME__" + body: (preprocessing-token + (string-literal + ,(strftime "%H:%M:%S" now)))))) + +(define environment + (-> (make-environment) + (extend-environment default-macros))) + + +(define (read-file path) + (call-with-input-file path read-string)) + +;;; 5.1.11.2 Translation phases + + + +(define (run-compiler path) + (define environment (enter-file (make-environment) path)) + (-> (load-and-tokenize-file path) + (handle-preprocessing-tokens environment)) +;;; 5. (something with character sets) +;;; 6. concatenation of string literals +;;; 7. Whitespace tokens are discarded, each preprocessing token is converted into a token + ;; 6.4 paragraph 2 + ;; Each preprocessing toket thas is converted to a token shall have the lexcal form of a keyword, an identifier, a constant, a string literal, or a puncturtor +;;; 8. All external objects and functions are resolved + ) |