diff options
| author | Rose Hogenson <rhogenson@posteo.net> | 2022-08-01 19:37:49 -0700 |
|---|---|---|
| committer | Rose Hogenson <rhogenson@posteo.net> | 2022-08-01 19:37:49 -0700 |
| commit | 25750ee505bd976d3c606200fec7253ad40c46d9 (patch) | |
| tree | 5984514f625db2f7fa01256adef4d3c7be2e3615 | |
| parent | acc561366f3fe6ec0377103f52ef0f7e923711c9 (diff) | |
| download | chromatopelma-25750ee505bd976d3c606200fec7253ad40c46d9.tar.zst | |
Remove mutable globals.
Per a closer reading of R7RS, it's an error to mutate an imported
binding with set!. My apologies to Guile when I said they had a bug.
| -rw-r--r-- | csc.csc | 4 | ||||
| -rw-r--r-- | lib/csc/compiler.csc | 6 | ||||
| -rw-r--r-- | lib/csc/flag.csc | 13 |
3 files changed, 14 insertions, 9 deletions
@@ -4,7 +4,7 @@ (only (scheme read) read) (only (csc compiler) - *library-search-dirs* + add-library-search-dirs compile) (only (csc flag) *args* @@ -69,7 +69,7 @@ ((file) file) (_ (printf "Error: must pass exactly one file to csc.\n{}" *help-msg*) (exit 2)))) - (set! *library-search-dirs* *include*) + (add-library-search-dirs *include*) (write-file *output* (compile (read-file input-file)))) diff --git a/lib/csc/compiler.csc b/lib/csc/compiler.csc index 20d5d37..7054f10 100644 --- a/lib/csc/compiler.csc +++ b/lib/csc/compiler.csc @@ -1,6 +1,6 @@ (define-library (csc compiler) (export - *library-search-dirs* + add-library-search-dirs compile) (import (scheme base) (only (scheme file) @@ -88,6 +88,10 @@ (define *library-search-dirs* '()) + (define (add-library-search-dirs ds) + (set! *library-search-dirs* (append *library-search-dirs* ds))) + + (define (find-library name) (define library-roots (cons *standard-library-dir* *library-search-dirs*)) (loop for dir in library-roots diff --git a/lib/csc/flag.csc b/lib/csc/flag.csc index c0a28a8..c26fa90 100644 --- a/lib/csc/flag.csc +++ b/lib/csc/flag.csc @@ -38,9 +38,11 @@ (define *parsers* (make-map compare-strings)) - ; I'm working around a Guile bug, which wrongly concludes - ; that *parsers* is immutable. - (set! *parsers* *parsers*) + + + (define (add-parser flag bool? setter) + (set! *parsers* (insert *parsers* flag + (make-flag bool? setter)))) (define-record-type <flag> @@ -55,9 +57,8 @@ ((define-flag name flag type default) (begin (define name default) - (set! *parsers* (insert *parsers* flag - (make-flag (eq? type bool-flag) - (lambda (x) (set! name (type x)))))))))) + (add-parser flag (eq? type bool-flag) + (lambda (x) (set! name (type x)))))))) (define *args* '()) |
