diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2022-07-10 20:24:01 +0200 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2022-07-10 20:24:01 +0200 |
commit | b3f27f132f8ac405f8cdf7e201f03d157f366125 (patch) | |
tree | 2d3f94aff2c55dd09eded50b63756042ad472bcc /module/c/cpp-environment | |
parent | Extend type-clauses with not. (diff) | |
download | calp-b3f27f132f8ac405f8cdf7e201f03d157f366125.tar.gz calp-b3f27f132f8ac405f8cdf7e201f03d157f366125.tar.xz |
work
Diffstat (limited to '')
-rw-r--r-- | module/c/cpp-environment.scm | 26 |
1 files changed, 21 insertions, 5 deletions
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)) |