* Clean up the high-level interface, making arg order consistent.
* Rename syntactic-environment->environment as syntactic-environment->runtime.
* Eliminate ->syntactic-environment in favor of runtime-environment->syntactic.
* Rename syntactic-environment/top-level? to top-level-syntactic-environment?.
* Export closed-identifier? to (runtime syntax).
(define (car-constant? components)
(and (identifier=? environment (caar components)
- (->syntactic-environment system-global-environment)
+ (runtime-environment->syntactic
+ system-global-environment)
'quote)
(bit-string? (cadar components))))
free-names
(compile/expression
`(,(close-syntax 'begin
- (->syntactic-environment system-global-environment))
+ (runtime-environment->syntactic
+ system-global-environment))
,@body)
environment)))))))
(import (runtime ffi)
make-alien-function
alien-function/filename)
- (import (runtime syntax environment)
- syntactic-environment->environment)
+ (import (runtime syntax)
+ syntactic-environment->runtime)
(export ()
c-include
load-c-includes
(call-with-destructured-c-include-form
form
(lambda (library)
- (let ((ienv (syntactic-environment->environment usage-env)))
+ (let ((ienv (syntactic-environment->runtime usage-env)))
(if (and (environment-bound? ienv 'C-INCLUDES)
(environment-assigned? ienv 'C-INCLUDES))
(let ((value (environment-lookup ienv 'C-INCLUDES))
(define (find-c-includes env)
;; Returns the c-includes structure bound to 'C-INCLUDES in ENV.
(guarantee syntactic-environment? env 'find-c-includes)
- (let ((ienv (syntactic-environment->environment env)))
+ (let ((ienv (syntactic-environment->runtime env)))
(if (and (environment-bound? ienv 'C-INCLUDES)
(environment-assigned? ienv 'C-INCLUDES))
(let ((includes (environment-lookup ienv 'C-INCLUDES)))
(vector-ref (gc-space-status) 0))
env))
- (if (unbound? env '->syntactic-environment)
- (eval '(define (->syntactic-environment object)
+ (if (unbound? env 'runtime-environment->syntactic)
+ (eval '(define (runtime-environment->syntactic object)
object)
env))
(let ((item
(transformer->expander (transformer-eval transformer senv)
senv)))
- (if (syntactic-environment/top-level? senv)
+ (if (top-level-syntactic-environment? senv)
(keyword-value-item
item
(expr-item
;; Force order -- bind names before classifying body.
(let ((bvl
(map-mit-lambda-list (lambda (identifier)
- (bind-variable environment identifier))
+ (bind-variable identifier environment))
bvl)))
(values bvl
(compile-body-item
(classifier->keyword
(lambda (form environment)
(let ((name (cadr form)))
- (reserve-identifier environment name)
+ (reserve-identifier name environment)
(variable-binder defn-item
environment
name
(keyword-binder environment name item)
;; User-defined macros at top level are preserved in the output.
(if (and (keyword-value-item? item)
- (syntactic-environment/top-level? environment))
+ (top-level-syntactic-environment? environment))
(defn-item name item)
(seq-item '()))))
(define (keyword-binder environment name item)
(if (not (keyword-item? item))
(syntax-error "Keyword binding value must be a keyword:" name))
- (bind-keyword environment name item))
+ (bind-keyword name environment item))
(define (variable-binder k environment name item)
(if (keyword-item? item)
(syntax-error "Variable binding value must not be a keyword:" name))
- (k (bind-variable environment name) item))
+ (k (bind-variable name environment) item))
\f
;;;; LET-like
(body (cddr form))
(binding-env (make-internal-syntactic-environment env)))
(for-each (lambda (binding)
- (reserve-identifier binding-env (car binding)))
+ (reserve-identifier (car binding) binding-env))
bindings)
;; Classify right-hand sides first, in order to catch references to
;; reserved names. Then bind names prior to classifying body.
(define (compiler:the-environment form environment)
(syntax-check '(KEYWORD) form)
- (if (not (syntactic-environment/top-level? environment))
+ (if (not (top-level-syntactic-environment? environment))
(syntax-error "This form allowed only at top level:" form))
(output/the-environment))
(make-synthetic-identifier new-identifier)
capture-syntactic-environment
close-syntax
+ closed-identifier?
identifier->symbol
identifier=?
identifier?
syntax*
syntax-error)
(export (runtime syntax)
- bind-keyword
- bind-variable
classifier->keyword
compile/expression
compiler->keyword
- lookup-identifier
- raw-identifier?
- reserve-identifier))
+ raw-identifier?))
(define-package (runtime syntax items)
(files "syntax-items")
(files "syntax-environment")
(parent (runtime syntax))
(export ()
- ->syntactic-environment
+ runtime-environment->syntactic
syntactic-environment?)
(export (runtime syntax)
+ bind-keyword
+ bind-variable
+ lookup-identifier
make-internal-syntactic-environment
make-keyword-syntactic-environment
make-partial-syntactic-environment
- syntactic-environment->environment
- syntactic-environment/bind-keyword
- syntactic-environment/bind-variable
- syntactic-environment/lookup
- syntactic-environment/reserve
- syntactic-environment/top-level?
+ reserve-identifier
+ syntactic-environment->runtime
+ top-level-syntactic-environment?
syntactic-environment?))
(define-package (runtime syntax check)
(declare (usual-integrations))
\f
+(define (runtime-environment->syntactic env)
+ (cond ((interpreter-environment? env) (%top-level-runtime-senv env))
+ ((environment? env) (%internal-runtime-senv env))
+ (else (error:not-a environment? env 'runtime-environment->syntactic))))
+
+(define (syntactic-environment->runtime senv)
+ ((senv-get-runtime senv)))
+
+(define (top-level-syntactic-environment? senv)
+ (eq? 'top-level ((senv-get-type senv))))
+
+(define ((id-dispatcher handle-raw caller) identifier senv)
+ (cond ((raw-identifier? identifier)
+ (handle-raw identifier senv))
+ ((closed-identifier? identifier)
+ (handle-raw (syntactic-closure-form identifier)
+ (syntactic-closure-senv identifier)))
+ (else
+ (error:not-a identifier? identifier caller))))
+
+(define lookup-identifier
+ (id-dispatcher (lambda (identifier senv)
+ (let ((item ((senv-lookup senv) identifier)))
+ (if (reserved-name-item? item)
+ (syntax-error "Premature reference to reserved name:"
+ identifier))
+ (or item
+ (var-item identifier))))
+ 'lookup-identifier))
+
+(define reserve-identifier
+ (id-dispatcher (lambda (identifier senv)
+ ((senv-store senv) identifier (reserved-name-item)))
+ 'reserve-identifier))
+
+(define (bind-keyword identifier senv item)
+ (guarantee keyword-item? item 'bind-keyword)
+ ((id-dispatcher (lambda (identifier senv)
+ ((senv-store senv) identifier item))
+ 'bind-keyword)
+ identifier
+ senv))
+
+(define bind-variable
+ (id-dispatcher (lambda (identifier senv)
+ (let ((rename ((senv-rename senv) identifier)))
+ ((senv-store senv) identifier (var-item rename))
+ rename))
+ 'bind-variable))
+
(define-record-type <syntactic-environment>
(make-senv get-type get-runtime lookup store rename describe)
syntactic-environment?
(rename senv-rename)
(describe senv-describe))
-(define (senv-type senv)
- ((senv-get-type senv)))
-
-(define (syntactic-environment/top-level? senv)
- (eq? 'top-level (senv-type senv)))
-
-(define (syntactic-environment->environment senv)
- ((senv-get-runtime senv)))
-
-(define (syntactic-environment/lookup senv identifier)
- (guarantee raw-identifier? identifier 'syntactic-environment/lookup)
- ((senv-lookup senv) identifier))
-
-(define (syntactic-environment/reserve senv identifier)
- (guarantee raw-identifier? identifier 'syntactic-environment/reserve)
- ((senv-store senv) identifier (reserved-name-item)))
-
-(define (syntactic-environment/bind-keyword senv identifier item)
- (guarantee raw-identifier? identifier 'syntactic-environment/bind-keyword)
- (guarantee keyword-item? item 'syntactic-environment/bind-keyword)
- ((senv-store senv) identifier item))
-
-(define (syntactic-environment/bind-variable senv identifier)
- (guarantee raw-identifier? identifier 'syntactic-environment/bind-variable)
- (let ((rename ((senv-rename senv) identifier)))
- ((senv-store senv) identifier (var-item rename))
- rename))
+(define-unparser-method syntactic-environment?
+ (simple-unparser-method 'syntactic-environment
+ (lambda (senv)
+ (list ((senv-get-type senv))))))
(define-pp-describer syntactic-environment?
(lambda (senv)
- (cons `(type ,((senv-get-type senv)))
- ((senv-describe senv)))))
+ ((senv-describe senv))))
\f
-(define (->syntactic-environment object #!optional caller)
- (declare (ignore caller))
- (cond ((syntactic-environment? object) object)
- ((interpreter-environment? object) (%top-level-runtime-senv object))
- ((environment? object) (%internal-runtime-senv object))
- (else (error "Unable to convert to a syntactic environment:" object))))
-
;;; Runtime syntactic environments are wrappers around runtime environments.
;;; Wrappers around top-level runtime environments.
(define (%internal-runtime-senv env)
(define (get-type)
- 'runtime)
+ 'internal-runtime)
(define (get-runtime)
env)
(declare (usual-integrations))
\f
(define (transformer-eval output environment)
- (eval output (syntactic-environment->environment environment)))
+ (eval output (syntactic-environment->runtime environment)))
(define (output/variable name)
(make-scode-variable name))
(declare (usual-integrations))
\f
-(define (sc-macro-transformer->expander transformer closing-environment)
+(define (sc-macro-transformer->expander transformer closing-env)
(expander-item
- (lambda (form use-environment)
- (close-syntax (transformer form use-environment)
- (->syntactic-environment closing-environment)))))
+ (lambda (form use-senv)
+ (close-syntax (transformer form use-senv)
+ (->senv closing-env)))))
-(define (rsc-macro-transformer->expander transformer closing-environment)
+(define (rsc-macro-transformer->expander transformer closing-env)
(expander-item
- (lambda (form use-environment)
- (close-syntax (transformer form
- (->syntactic-environment closing-environment))
- use-environment))))
+ (lambda (form use-senv)
+ (close-syntax (transformer form (->senv closing-env))
+ use-senv))))
-(define (er-macro-transformer->expander transformer closing-environment)
+(define (er-macro-transformer->expander transformer closing-env)
(expander-item
- (lambda (form use-environment)
+ (lambda (form use-senv)
(close-syntax (transformer form
- (make-er-rename
- (->syntactic-environment closing-environment))
- (make-er-compare use-environment))
- use-environment))))
+ (make-er-rename (->senv closing-env))
+ (make-er-compare use-senv))
+ use-senv))))
+
+(define (->senv env)
+ (if (syntactic-environment? env)
+ env
+ (runtime-environment->syntactic env)))
-(define (make-er-rename closing-environment)
- (let ((renames '()))
- (lambda (identifier)
- (let ((p (assq identifier renames)))
- (if p
- (cdr p)
- (let ((rename (close-syntax identifier closing-environment)))
- (set! renames (cons (cons identifier rename) renames))
- rename))))))
+(define (make-er-rename closing-senv)
+ (lambda (identifier)
+ (close-syntax identifier closing-senv)))
-(define (make-er-compare use-environment)
+(define (make-er-compare use-senv)
(lambda (x y)
- (identifier=? use-environment x
- use-environment y)))
+ (identifier=? use-senv x use-senv y)))
(define (syntactic-keyword->item keyword environment)
(let ((item (environment-lookup-macro environment keyword)))
(if (not item)
- (error:bad-range-argument keyword 'SYNTACTIC-KEYWORD->ITEM))
+ (error:bad-range-argument keyword 'syntactic-keyword->item))
item))
\ No newline at end of file
(define (syntax* forms environment)
(guarantee list? forms 'syntax*)
- (let ((senv (->syntactic-environment environment 'syntax*)))
+ (let ((senv
+ (if (syntactic-environment? environment)
+ environment
+ (runtime-environment->syntactic environment))))
(with-identifier-renaming
(lambda ()
- (if (syntactic-environment/top-level? senv)
+ (if (top-level-syntactic-environment? senv)
(compile-body-item/top-level (classify/body forms senv))
(output/sequence (compile/expressions forms senv)))))))
((closed-identifier? identifier) (syntactic-closure-form identifier))
(else (error:not-a identifier? identifier 'identifier->symbol))))
-(define (lookup-identifier identifier senv)
- (cond ((raw-identifier? identifier)
- (%lookup-raw-identifier identifier senv))
- ((closed-identifier? identifier)
- (%lookup-raw-identifier (syntactic-closure-form identifier)
- (syntactic-closure-senv identifier)))
- (else
- (error:not-a identifier? identifier 'lookup-identifier))))
-
-(define (%lookup-raw-identifier identifier senv)
- (let ((item (syntactic-environment/lookup senv identifier)))
- (if (reserved-name-item? item)
- (syntax-error "Premature reference to reserved name:" identifier))
- (or item
- (var-item identifier))))
-
(define (identifier=? environment-1 identifier-1 environment-2 identifier-2)
(let ((item-1 (lookup-identifier identifier-1 environment-1))
(item-2 (lookup-identifier identifier-2 environment-2)))
(var-item? item-2)
(eq? (var-item-id item-1)
(var-item-id item-2))))))
-
-(define (reserve-identifier senv identifier)
- (cond ((raw-identifier? identifier)
- (syntactic-environment/reserve senv identifier))
- ((closed-identifier? identifier)
- (syntactic-environment/reserve (syntactic-closure-senv identifier)
- (syntactic-closure-form identifier)))
- (else
- (error:not-a identifier? identifier 'reserve-identifier))))
-
-(define (bind-keyword senv identifier item)
- (cond ((raw-identifier? identifier)
- (syntactic-environment/bind-keyword senv identifier item))
- ((closed-identifier? identifier)
- (syntactic-environment/bind-keyword
- (syntactic-closure-senv identifier)
- (syntactic-closure-form identifier)
- item))
- (else
- (error:not-a identifier? identifier 'bind-keyword))))
-
-(define (bind-variable senv identifier)
- (cond ((raw-identifier? identifier)
- (syntactic-environment/bind-variable senv identifier))
- ((closed-identifier? identifier)
- (syntactic-environment/bind-variable
- (syntactic-closure-senv identifier)
- (syntactic-closure-form identifier)))
- (else
- (error:not-a identifier? identifier 'bind-variable))))
\f
;;;; Utilities
(syntax* (if (null? declarations)
s-expressions
(cons (cons (close-syntax 'declare
- (->syntactic-environment
+ (runtime-environment->syntactic
system-global-environment))
declarations)
s-expressions))