aboutsummaryrefslogtreecommitdiff
path: root/module/c/cpp-environment.scm
diff options
context:
space:
mode:
Diffstat (limited to 'module/c/cpp-environment.scm')
-rw-r--r--module/c/cpp-environment.scm41
1 files changed, 17 insertions, 24 deletions
diff --git a/module/c/cpp-environment.scm b/module/c/cpp-environment.scm
index 39e596d1..da8e4413 100644
--- a/module/c/cpp-environment.scm
+++ b/module/c/cpp-environment.scm
@@ -1,7 +1,6 @@
(define-module (c cpp-environment)
:use-module (srfi srfi-1)
:use-module (srfi srfi-88)
- :use-module (ice-9 hash-table)
:use-module ((hnh util) :select (->>))
:use-module (hnh util object)
:use-module (hnh util type)
@@ -18,7 +17,6 @@
macro-identifier-list
macro-variadic?
cpp-macro?
- ;; pprint-macro
enter-into-if
transition-to-if
@@ -39,10 +37,8 @@
object-macro?
internal-macro?
- cpp-environment
cpp-environment?
cpp-if-status
- ;; cpp-variables
cpp-file-stack
make-environment in-environment?
@@ -108,10 +104,8 @@
(cpp-if-status type: (and (list-of if-status?)
(not null?))
default: (list (if-status outside)))
- ;; not exported since type signatures don't hold inside the hash table
- ;; TODO replace hash table with something that doesn't require copying the
- ;; entire structure every time
- (cpp-variables type: hash-table? default: (make-hash-table))
+ (cpp-variables type: (alist-of string? cpp-macro?)
+ default: '())
(cpp-file-stack type: (and (not null?)
(list-of (pair-of string? exact-integer?)))
default: '(("*outside*" . 1))))
@@ -208,32 +202,31 @@
(define (make-environment) (cpp-environment))
-(define (clone-hash-table ht)
- (alist->hash-table (hash-map->list cons ht)))
+;; (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 (clone-environment environment)
+;; (modify environment cpp-variables clone-hash-table))
(define (in-environment? environment key)
- (hash-get-handle (cpp-variables environment) key))
+ (assoc key (cpp-variables environment)))
(define (remove-identifier environment key)
(typecheck key string?)
- (let ((environment (clone-environment environment)))
- (hash-remove! (cpp-variables environment) key)
- environment))
+ (modify environment cpp-variables
+ (lambda (vars) (remove (lambda (slot) (string=? key (car slot)))
+ vars))))
(define (add-identifier environment key value)
(typecheck key string?)
(typecheck value cpp-macro?)
- (let ((environment (clone-environment environment)))
- (hash-set! (cpp-variables environment) key value)
- environment))
+ (modify environment cpp-variables
+ (lambda (vars) (acons key value vars))))
(define (get-identifier environment key)
- (hash-ref (cpp-variables environment) key))
+ (assoc-ref (cpp-variables environment) key))
(define (extend-environment environment macros)
@@ -250,10 +243,10 @@
(define* (pprint-environment environment optional: (port (current-error-port)))
(display "== Environment ==\n" port)
- (hash-for-each (lambda (key macro)
- (pprint-macro macro port)
- (newline port))
- (cpp-variables environment)))
+ (for-each (lambda (pair)
+ (pprint-macro (cdr pair) port)
+ (newline port))
+ (cpp-variables environment)))
(define* (pprint-macro x optional: (p (current-output-port)))
(cond ((internal-macro? x)