From b3f27f132f8ac405f8cdf7e201f03d157f366125 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Sun, 10 Jul 2022 20:24:01 +0200 Subject: work --- module/c/cpp-environment.scm | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'module/c/cpp-environment.scm') diff --git a/module/c/cpp-environment.scm b/module/c/cpp-environment.scm index 51f16168..fa69e1fc 100644 --- a/module/c/cpp-environment.scm +++ b/module/c/cpp-environment.scm @@ -15,6 +15,7 @@ macro-identifier-list macro-variadic? macro? + ;; pprint-macro enter-active-if enter-inactive-if @@ -31,13 +32,14 @@ internal-macro? cpp-environment + cpp-environment? cpp-if-status cpp-variables make-environment in-environment? remove-identifier! add-identifier! get-identifier extend-environment - + disjoin-macro )) (define (macro-identifier x) @@ -73,6 +75,9 @@ (fun:function-like-macro? x) (int:internal-macro? x))) + + + (define-type (cpp-environment) (cpp-if-status type: (list-of (memv '(outside active-if inactive-if))) default: '(outside)) @@ -81,6 +86,7 @@ (list-of (pair-of string? exact-integer?))) default: '(("*outside*" . 1)))) + (define (enter-active-if environment) @@ -112,7 +118,13 @@ (define (make-environment) (cpp-environment)) -(define (in-envirnoment? environment key) +(define (clone-hash-table ht) + (alist->hash-table (hash-map->list cons ht))) + +(define (clone-environment environment) + (modify environment cpp-variables clone-hash-table)) + +(define (in-environment? environment key) (hash-get-handle (cpp-variables environment) key)) (define (remove-identifier! environment key) @@ -134,11 +146,15 @@ (define (get-identifier environment key) (hash-ref (cpp-variables environment) key)) -(define (clone-hash-table ht) - (alist->hash-table (hash-map->list cons ht))) (define (extend-environment environment macros) - (let ((env (modify environment cpp-variables clone-hash-table))) + (typecheck macros (list-of macro?)) + (let ((env (clone-environment environment))) (fold (lambda (m env) (add-identifier! env (macro-identifier m) m)) env macros))) +(define (disjoin-macro environment name) + (typecheck name string?) + (let ((env (clone-environment environment))) + (remove-identifier! env name) + env)) -- cgit v1.2.3