From d846a9b166f5dd72a83e9a11b1be5590d60ced3e Mon Sep 17 00:00:00 2001 From: Chris Hanson Date: Sat, 19 Sep 2009 23:54:13 -0700 Subject: [PATCH] Refactor syntax to break it into smaller, more coherent pieces. Simplify where easy to do so. --- src/compiler/machines/C/compiler.pkg | 4 +- src/compiler/machines/i386/compiler.pkg | 4 +- src/edwin/clsmac.scm | 33 +- src/edwin/edwin.pkg | 8 +- src/runtime/defstr.scm | 50 +- src/runtime/ed-ffi.scm | 22 +- src/runtime/lambda-list.scm | 184 ++++ src/runtime/make.scm | 11 +- src/runtime/mit-macros.scm | 568 +++++++++++ src/runtime/mit-syntax.scm | 1203 +++++------------------ src/runtime/parse.scm | 13 +- src/runtime/record.scm | 13 +- src/runtime/runtime.pkg | 308 +++++- src/runtime/syntactic-closures.scm | 1140 --------------------- src/runtime/syntax-check.scm | 122 +-- src/runtime/syntax-classify.scm | 130 +++ src/runtime/syntax-compile.scm | 118 +++ src/runtime/syntax-declaration.scm | 146 +++ src/runtime/syntax-definitions.scm | 64 ++ src/runtime/syntax-environment.scm | 303 ++++++ src/runtime/syntax-items.scm | 124 +++ src/runtime/syntax-output.scm | 449 +++------ src/runtime/syntax-rules.scm | 91 +- src/runtime/syntax-transforms.scm | 91 +- src/runtime/syntax.scm | 193 ++++ src/runtime/sysmac.scm | 16 +- src/runtime/unpars.scm | 8 +- src/runtime/unsyn.scm | 6 +- src/sf/sf.pkg | 4 +- src/sf/subst.scm | 2 +- 30 files changed, 2665 insertions(+), 2763 deletions(-) create mode 100644 src/runtime/lambda-list.scm create mode 100644 src/runtime/mit-macros.scm delete mode 100644 src/runtime/syntactic-closures.scm create mode 100644 src/runtime/syntax-classify.scm create mode 100644 src/runtime/syntax-compile.scm create mode 100644 src/runtime/syntax-declaration.scm create mode 100644 src/runtime/syntax-definitions.scm create mode 100644 src/runtime/syntax-environment.scm create mode 100644 src/runtime/syntax-items.scm create mode 100644 src/runtime/syntax.scm diff --git a/src/compiler/machines/C/compiler.pkg b/src/compiler/machines/C/compiler.pkg index 839dc510b..17272cda4 100644 --- a/src/compiler/machines/C/compiler.pkg +++ b/src/compiler/machines/C/compiler.pkg @@ -213,9 +213,7 @@ USA. make-rvalue make-snode package - rule-matcher) - (import (runtime syntactic-closures) - syntax-match?)) + rule-matcher)) (define-package (compiler declarations) (files "machines/C/decls") diff --git a/src/compiler/machines/i386/compiler.pkg b/src/compiler/machines/i386/compiler.pkg index 34314bdb9..572de333f 100644 --- a/src/compiler/machines/i386/compiler.pkg +++ b/src/compiler/machines/i386/compiler.pkg @@ -214,9 +214,7 @@ USA. make-rvalue make-snode package - rule-matcher) - (import (runtime syntactic-closures) - syntax-match?)) + rule-matcher)) (define-package (compiler declarations) (files "machines/i386/decls") diff --git a/src/edwin/clsmac.scm b/src/edwin/clsmac.scm index af5d48ed0..24dae1590 100644 --- a/src/edwin/clsmac.scm +++ b/src/edwin/clsmac.scm @@ -86,24 +86,21 @@ USA. (define with-instance-variables (make-unmapped-macro-reference-trap (make-compiler-item - (lambda (form environment history) - (if (syntax-match? '(IDENTIFIER EXPRESSION (* IDENTIFIER) + EXPRESSION) - (cdr form)) - (let ((class-name (cadr form)) - (self (caddr form)) - (free-names (cadddr form)) - (body (cddddr form))) - (transform-instance-variables - (class-instance-transforms - (name->class (identifier->symbol class-name))) - (compile/subexpression self environment history select-caddr) - free-names - (compile/subexpression - `(,(close-syntax 'BEGIN system-global-environment) ,@body) - environment - history - select-cddddr))) - (ill-formed-syntax form)))))) + (lambda (form environment) + (syntax-check '(KEYWORD IDENTIFIER EXPRESSION (* IDENTIFIER) + EXPRESSION) + form) + (let ((class-name (cadr form)) + (self (caddr form)) + (free-names (cadddr form)) + (body (cddddr form))) + (transform-instance-variables + (class-instance-transforms + (name->class (identifier->symbol class-name))) + (compile/expression self environment) + free-names + (compile/expression + `(,(close-syntax 'BEGIN system-global-environment) ,@body) + environment))))))) (define-syntax ==> (syntax-rules () diff --git a/src/edwin/edwin.pkg b/src/edwin/edwin.pkg index cba2d0e8f..05499b982 100644 --- a/src/edwin/edwin.pkg +++ b/src/edwin/edwin.pkg @@ -135,11 +135,9 @@ USA. define-method usual==> with-instance-variables) - (import (runtime syntactic-closures) - compile/subexpression - make-compiler-item - select-caddr - select-cddddr)) + (import (runtime syntax) + compile/expression + make-compiler-item)) (define-package (edwin class-macros transform-instance-variables) (files "xform") diff --git a/src/runtime/defstr.scm b/src/runtime/defstr.scm index 7b8e5575a..21362245a 100644 --- a/src/runtime/defstr.scm +++ b/src/runtime/defstr.scm @@ -73,37 +73,35 @@ differences: |# -(define-expander 'DEFINE-STRUCTURE system-global-environment - (lambda (form environment closing-environment) - (if (not (and (pair? (cdr form)) (list? (cddr form)))) - (error "Ill-formed special form:" form)) - (make-syntactic-closure closing-environment '() - (let ((name-and-options (cadr form)) - (slot-descriptions (cddr form))) +(define-syntax define-structure + (sc-macro-transformer + (lambda (form use-environment) + (syntax-check '(KEYWORD + DATUM) form) + (capture-syntactic-environment + (lambda (closing-environment) (let ((structure - (call-with-values - (lambda () + (receive (name options) + (let ((name-and-options (cadr form))) (if (pair? name-and-options) (values (car name-and-options) (cdr name-and-options)) (values name-and-options '()))) - (lambda (name options) - (if (not (symbol? name)) - (error "Structure name must be a symbol:" name)) - (if (not (list? options)) - (error "Structure options must be a list:" options)) - (let ((context - (make-parser-context name - environment - closing-environment))) - (parse/options options - (parse/slot-descriptions slot-descriptions) - context)))))) + (if (not (symbol? name)) + (error "Structure name must be a symbol:" name)) + (if (not (list? options)) + (error "Structure options must be a list:" options)) + (let ((context + (make-parser-context name + use-environment + closing-environment))) + (parse/options options + (parse/slot-descriptions (cddr form)) + context))))) `(BEGIN ,@(type-definitions structure) ,@(constructor-definitions structure) ,@(accessor-definitions structure) ,@(modifier-definitions structure) ,@(predicate-definitions structure) - ,@(copier-definitions structure))))))) + ,@(copier-definitions structure)))))))) ;;;; Parse options @@ -255,7 +253,7 @@ differences: (and (identifier? object) (there-exists? false-expression-names (lambda (name) - (identifier=? (parser-context/environment context) + (identifier=? (parser-context/use-environment context) object (parser-context/closing-environment context) name)))))) @@ -563,10 +561,10 @@ differences: (eq? (structure/physical-type structure) 'RECORD)) (define-record-type - (make-parser-context name environment closing-environment) + (make-parser-context name use-environment closing-environment) parser-context? (name parser-context/name) - (environment parser-context/environment) + (use-environment parser-context/use-environment) (closing-environment parser-context/closing-environment)) (define-record-type