From fb1057dae461cce902fa9434a86ad01e769719c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Mon, 25 Jul 2022 01:11:33 +0200 Subject: Made pprint-environment differentiate between "public" and "private" macros. --- module/c/cpp-environment.scm | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/module/c/cpp-environment.scm b/module/c/cpp-environment.scm index 951540fa..bc4ceb1b 100644 --- a/module/c/cpp-environment.scm +++ b/module/c/cpp-environment.scm @@ -4,6 +4,7 @@ :use-module (hnh util object) :use-module (hnh util type) :use-module (hnh util lens) + :use-module ((hnh util) :select (group-by)) :use-module ((c lex2) :select (lexeme?)) :use-module ((c unlex) :select (unlex)) :use-module ((rnrs enums)) @@ -245,11 +246,20 @@ (define* (pprint-environment environment optional: (port (current-output-port))) - (display "/*** Environment ***/\n" port) - (for-each (lambda (pair) - (pprint-macro (cdr pair) port) - (newline port)) - (cpp-variables environment))) + (let* ((grouped + (group-by (lambda (pair) + (if (char=? #\_ (string-ref (car pair) 0)) + 'private 'public)) + (cpp-variables environment))) + (private (map cdr (car (assoc-ref grouped 'private)))) + (public (map cdr (car (assoc-ref grouped 'public)))) + (proc (lambda (x) (pprint-macro x port) (newline port)))) + (with-output-to-port port + (lambda () + (display "/*** Private Environment ***/") (newline) + (for-each proc private) + (display "/*** Public Environment ***/") (newline) + (for-each proc public))))) (define* (pprint-macro x optional: (p (current-output-port))) (cond ((internal-macro? x) -- cgit v1.2.3