diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2022-07-10 23:36:56 +0200 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2022-07-10 23:36:56 +0200 |
commit | f7b18cc72dd5b2ca90b6670dbe81c3ef3204d6d9 (patch) | |
tree | dcc40399f08285a9a308079098e735fb5bf192bd /module/c/cpp-environment | |
parent | Add of-type? to (hnh util type). (diff) | |
download | calp-f7b18cc72dd5b2ca90b6670dbe81c3ef3204d6d9.tar.gz calp-f7b18cc72dd5b2ca90b6670dbe81c3ef3204d6d9.tar.xz |
Resolve recursive macros.
Diffstat (limited to '')
-rw-r--r-- | module/c/cpp-environment.scm | 20 | ||||
-rw-r--r-- | module/c/cpp-environment/function-like-macro.scm | 15 | ||||
-rw-r--r-- | module/c/cpp-environment/object-like-macro.scm | 13 |
3 files changed, 31 insertions, 17 deletions
diff --git a/module/c/cpp-environment.scm b/module/c/cpp-environment.scm index fa69e1fc..2ad60b56 100644 --- a/module/c/cpp-environment.scm +++ b/module/c/cpp-environment.scm @@ -53,15 +53,17 @@ (identifier x)) -(define (macro-body macro) - (define body-proc - (cond ((obj:object-like-macro? macro) obj:body) - ((fun:function-like-macro? macro) fun:body) - ((int:internal-macro? macro) int:body) - (else (scm-error 'wrong-type-arg "macro-body" - "Not a macro: ~s" - (list macro) #f)))) - (body-proc macro)) +(define (macro-body-proc macro) + (cond ((obj:object-like-macro? macro) obj:body) + ((fun:function-like-macro? macro) fun:body) + ((int:internal-macro? macro) int:body) + (else (scm-error 'wrong-type-arg "macro-body" + "Not a macro: ~s" + (list macro) #f)))) + +(define macro-body + (case-lambda ((macro) ((macro-body-proc macro) macro)) + ((macro value) ((macro-body-proc macro) macro value)))) (define macro-identifier-list fun:identifier-list) (define macro-variadic? fun:variadic?) diff --git a/module/c/cpp-environment/function-like-macro.scm b/module/c/cpp-environment/function-like-macro.scm index 26512439..a4b58487 100644 --- a/module/c/cpp-environment/function-like-macro.scm +++ b/module/c/cpp-environment/function-like-macro.scm @@ -1,6 +1,8 @@ (define-module (c cpp-environment function-like-macro) :use-module (hnh util object) :use-module (hnh util type) + :use-module ((c lex2) :select (lexeme?)) + :use-module ((c unlex) :select (unlex)) :export (function-like-macro function-like-macro? identifier @@ -8,11 +10,16 @@ body variadic?)) -(define-type (function-like-macro) +(define-type (function-like-macro + printer: (lambda (r p) + (format p "#<#define ~a(~a) ~a>" + (identifier r) + (append (identifier-list r) + (if (variadic? r) + '("...") '())) + (unlex (body r))))) (identifier type: string?) (identifier-list type: (list-of string?)) - ;; TODO import these - (body type: list? ; (list-of (or whitespace-token? preprocessing-token?)) - ) + (body type: (list-of lexeme?)) (variadic? type: boolean? default: #f)) diff --git a/module/c/cpp-environment/object-like-macro.scm b/module/c/cpp-environment/object-like-macro.scm index 5d4c8810..90a3ad23 100644 --- a/module/c/cpp-environment/object-like-macro.scm +++ b/module/c/cpp-environment/object-like-macro.scm @@ -1,13 +1,18 @@ (define-module (c cpp-environment object-like-macro) :use-module (hnh util object) + :use-module (hnh util type) + :use-module ((c lex2) :select (lexeme?)) + :use-module ((c unlex) :select (unlex)) :export (object-like-macro object-like-macro? identifier body)) -(define-type (object-like-macro) +(define-type (object-like-macro + printer: (lambda (r p) + (format p "#<#define ~a ~a>" + (identifier r) + (unlex (body r))))) (identifier type: string?) - ;; TODO import these - (body type: list? ; (list-of (or whitespace-token? preprocessing-token?)) - )) + (body type: (list-of lexeme?))) |