From f7b18cc72dd5b2ca90b6670dbe81c3ef3204d6d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Sun, 10 Jul 2022 23:36:56 +0200 Subject: Resolve recursive macros. --- module/c/cpp-environment/function-like-macro.scm | 15 +++++++++++---- module/c/cpp-environment/object-like-macro.scm | 13 +++++++++---- 2 files changed, 20 insertions(+), 8 deletions(-) (limited to 'module/c/cpp-environment') 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?))) -- cgit v1.2.3