From 8fad25c25f1d28a2009c882275bceea8ebefa550 Mon Sep 17 00:00:00 2001 From: Andy Wingo Date: Mon, 9 Aug 2010 21:17:57 +0200 Subject: [PATCH] reindent psyntax.scm * module/ice-9/psyntax.scm: Reindent. --- module/ice-9/psyntax.scm | 4512 +++++++++++++++++++------------------- 1 file changed, 2255 insertions(+), 2257 deletions(-) diff --git a/module/ice-9/psyntax.scm b/module/ice-9/psyntax.scm index 34efa2b0f..69cd1a584 100644 --- a/module/ice-9/psyntax.scm +++ b/module/ice-9/psyntax.scm @@ -156,2441 +156,2439 @@ (set-current-module (resolve-module '(guile)))) (let () -;;; Private version of and-map that handles multiple lists. -(define and-map* - (lambda (f first . rest) - (or (null? first) - (if (null? rest) - (let andmap ((first first)) - (let ((x (car first)) (first (cdr first))) - (if (null? first) - (f x) - (and (f x) (andmap first))))) - (let andmap ((first first) (rest rest)) - (let ((x (car first)) - (xr (map car rest)) - (first (cdr first)) - (rest (map cdr rest))) - (if (null? first) - (apply f x xr) - (and (apply f x xr) (andmap first rest))))))))) + ;; Private version of and-map that handles multiple lists. + (define and-map* + (lambda (f first . rest) + (or (null? first) + (if (null? rest) + (let andmap ((first first)) + (let ((x (car first)) (first (cdr first))) + (if (null? first) + (f x) + (and (f x) (andmap first))))) + (let andmap ((first first) (rest rest)) + (let ((x (car first)) + (xr (map car rest)) + (first (cdr first)) + (rest (map cdr rest))) + (if (null? first) + (apply f x xr) + (and (apply f x xr) (andmap first rest))))))))) -(define-syntax define-expansion-constructors - (lambda (x) - (syntax-case x () - ((_) - (let lp ((n 0) (out '())) - (if (< n (vector-length %expanded-vtables)) - (lp (1+ n) - (let* ((vtable (vector-ref %expanded-vtables n)) - (stem (struct-ref vtable (+ vtable-offset-user 0))) - (fields (struct-ref vtable (+ vtable-offset-user 2))) - (sfields (map (lambda (f) (datum->syntax x f)) fields)) - (ctor (datum->syntax x (symbol-append 'make- stem)))) - (cons #`(define (#,ctor #,@sfields) - (make-struct (vector-ref %expanded-vtables #,n) 0 - #,@sfields)) - out))) - #`(begin #,@(reverse out)))))))) + (define-syntax define-expansion-constructors + (lambda (x) + (syntax-case x () + ((_) + (let lp ((n 0) (out '())) + (if (< n (vector-length %expanded-vtables)) + (lp (1+ n) + (let* ((vtable (vector-ref %expanded-vtables n)) + (stem (struct-ref vtable (+ vtable-offset-user 0))) + (fields (struct-ref vtable (+ vtable-offset-user 2))) + (sfields (map (lambda (f) (datum->syntax x f)) fields)) + (ctor (datum->syntax x (symbol-append 'make- stem)))) + (cons #`(define (#,ctor #,@sfields) + (make-struct (vector-ref %expanded-vtables #,n) 0 + #,@sfields)) + out))) + #`(begin #,@(reverse out)))))))) -(define-syntax define-expansion-accessors - (lambda (x) - (syntax-case x () - ((_ stem field ...) - (let lp ((n 0)) - (let ((vtable (vector-ref %expanded-vtables n)) - (stem (syntax->datum #'stem))) - (if (eq? (struct-ref vtable (+ vtable-offset-user 0)) stem) - #`(begin - (define (#,(datum->syntax x (symbol-append stem '?)) x) - (and (struct? x) - (eq? (struct-vtable x) - (vector-ref %expanded-vtables #,n)))) - #,@(map - (lambda (f) - (let ((get (datum->syntax x (symbol-append stem '- f))) - (set (datum->syntax x (symbol-append 'set- stem '- f '!))) - (idx (list-index (struct-ref vtable - (+ vtable-offset-user 2)) - f))) - #`(begin - (define (#,get x) - (struct-ref x #,idx)) - (define (#,set x v) - (struct-set! x #,idx v))))) - (syntax->datum #'(field ...)))) - (lp (1+ n))))))))) + (define-syntax define-expansion-accessors + (lambda (x) + (syntax-case x () + ((_ stem field ...) + (let lp ((n 0)) + (let ((vtable (vector-ref %expanded-vtables n)) + (stem (syntax->datum #'stem))) + (if (eq? (struct-ref vtable (+ vtable-offset-user 0)) stem) + #`(begin + (define (#,(datum->syntax x (symbol-append stem '?)) x) + (and (struct? x) + (eq? (struct-vtable x) + (vector-ref %expanded-vtables #,n)))) + #,@(map + (lambda (f) + (let ((get (datum->syntax x (symbol-append stem '- f))) + (set (datum->syntax x (symbol-append 'set- stem '- f '!))) + (idx (list-index (struct-ref vtable + (+ vtable-offset-user 2)) + f))) + #`(begin + (define (#,get x) + (struct-ref x #,idx)) + (define (#,set x v) + (struct-set! x #,idx v))))) + (syntax->datum #'(field ...)))) + (lp (1+ n))))))))) -(define-syntax define-structure - (lambda (x) - (define construct-name - (lambda (template-identifier . args) - (datum->syntax - template-identifier - (string->symbol + (define-syntax define-structure + (lambda (x) + (define construct-name + (lambda (template-identifier . args) + (datum->syntax + template-identifier + (string->symbol (apply string-append (map (lambda (x) (if (string? x) x (symbol->string (syntax->datum x)))) args)))))) - (syntax-case x () - ((_ (name id1 ...)) - (and-map identifier? #'(name id1 ...)) - (with-syntax - ((constructor (construct-name #'name "make-" #'name)) - (predicate (construct-name #'name #'name "?")) - ((access ...) - (map (lambda (x) (construct-name x #'name "-" x)) - #'(id1 ...))) - ((assign ...) - (map (lambda (x) - (construct-name x "set-" #'name "-" x "!")) - #'(id1 ...))) - (structure-length - (+ (length #'(id1 ...)) 1)) - ((index ...) - (let f ((i 1) (ids #'(id1 ...))) - (if (null? ids) - '() - (cons i (f (+ i 1) (cdr ids))))))) - #'(begin - (define constructor - (lambda (id1 ...) - (vector 'name id1 ... ))) - (define predicate - (lambda (x) - (and (vector? x) - (= (vector-length x) structure-length) - (eq? (vector-ref x 0) 'name)))) - (define access - (lambda (x) - (vector-ref x index))) - ... - (define assign - (lambda (x update) - (vector-set! x index update))) - ...)))))) + (syntax-case x () + ((_ (name id1 ...)) + (and-map identifier? #'(name id1 ...)) + (with-syntax + ((constructor (construct-name #'name "make-" #'name)) + (predicate (construct-name #'name #'name "?")) + ((access ...) + (map (lambda (x) (construct-name x #'name "-" x)) + #'(id1 ...))) + ((assign ...) + (map (lambda (x) + (construct-name x "set-" #'name "-" x "!")) + #'(id1 ...))) + (structure-length + (+ (length #'(id1 ...)) 1)) + ((index ...) + (let f ((i 1) (ids #'(id1 ...))) + (if (null? ids) + '() + (cons i (f (+ i 1) (cdr ids))))))) + #'(begin + (define constructor + (lambda (id1 ...) + (vector 'name id1 ... ))) + (define predicate + (lambda (x) + (and (vector? x) + (= (vector-length x) structure-length) + (eq? (vector-ref x 0) 'name)))) + (define access + (lambda (x) + (vector-ref x index))) + ... + (define assign + (lambda (x update) + (vector-set! x index update))) + ...)))))) -(let () - (define-expansion-constructors) - (define-expansion-accessors lambda meta) + (let () + (define-expansion-constructors) + (define-expansion-accessors lambda meta) -;;; hooks to nonportable run-time helpers - (begin - (define fx+ +) - (define fx- -) - (define fx= =) - (define fx< <) + ;; hooks to nonportable run-time helpers + (begin + (define fx+ +) + (define fx- -) + (define fx= =) + (define fx< <) - (define top-level-eval-hook - (lambda (x mod) - (primitive-eval x))) + (define top-level-eval-hook + (lambda (x mod) + (primitive-eval x))) - (define local-eval-hook - (lambda (x mod) - (primitive-eval x))) + (define local-eval-hook + (lambda (x mod) + (primitive-eval x))) - (define-syntax gensym-hook - (syntax-rules () - ((_) (gensym)))) + (define-syntax gensym-hook + (syntax-rules () + ((_) (gensym)))) - (define put-global-definition-hook - (lambda (symbol type val) - (module-define! (current-module) - symbol - (make-syntax-transformer symbol type val)))) + (define put-global-definition-hook + (lambda (symbol type val) + (module-define! (current-module) + symbol + (make-syntax-transformer symbol type val)))) - (define get-global-definition-hook - (lambda (symbol module) - (if (and (not module) (current-module)) - (warn "module system is booted, we should have a module" symbol)) - (let ((v (module-variable (if module - (resolve-module (cdr module)) - (current-module)) - symbol))) - (and v (variable-bound? v) - (let ((val (variable-ref v))) - (and (macro? val) (macro-type val) - (cons (macro-type val) - (macro-binding val))))))))) + (define get-global-definition-hook + (lambda (symbol module) + (if (and (not module) (current-module)) + (warn "module system is booted, we should have a module" symbol)) + (let ((v (module-variable (if module + (resolve-module (cdr module)) + (current-module)) + symbol))) + (and v (variable-bound? v) + (let ((val (variable-ref v))) + (and (macro? val) (macro-type val) + (cons (macro-type val) + (macro-binding val))))))))) - (define (decorate-source e s) - (if (and (pair? e) s) - (set-source-properties! e s)) - e) + (define (decorate-source e s) + (if (and (pair? e) s) + (set-source-properties! e s)) + e) - (define (maybe-name-value! name val) - (if (lambda? val) - (let ((meta (lambda-meta val))) - (if (not (assq 'name meta)) - (set-lambda-meta! val (acons 'name name meta)))))) + (define (maybe-name-value! name val) + (if (lambda? val) + (let ((meta (lambda-meta val))) + (if (not (assq 'name meta)) + (set-lambda-meta! val (acons 'name name meta)))))) - ;;; output constructors - (define build-void - (lambda (source) - (make-void source))) + ;; output constructors + (define build-void + (lambda (source) + (make-void source))) - (define build-application - (lambda (source fun-exp arg-exps) - (make-application source fun-exp arg-exps))) + (define build-application + (lambda (source fun-exp arg-exps) + (make-application source fun-exp arg-exps))) - (define build-conditional - (lambda (source test-exp then-exp else-exp) - (make-conditional source test-exp then-exp else-exp))) + (define build-conditional + (lambda (source test-exp then-exp else-exp) + (make-conditional source test-exp then-exp else-exp))) - (define build-dynlet - (lambda (source fluids vals body) - (make-dynlet source fluids vals body))) + (define build-dynlet + (lambda (source fluids vals body) + (make-dynlet source fluids vals body))) - (define build-lexical-reference - (lambda (type source name var) - (make-lexical-ref source name var))) + (define build-lexical-reference + (lambda (type source name var) + (make-lexical-ref source name var))) - (define build-lexical-assignment - (lambda (source name var exp) - (maybe-name-value! name exp) - (make-lexical-set source name var exp))) + (define build-lexical-assignment + (lambda (source name var exp) + (maybe-name-value! name exp) + (make-lexical-set source name var exp))) - (define (analyze-variable mod var modref-cont bare-cont) - (if (not mod) - (bare-cont var) - (let ((kind (car mod)) - (mod (cdr mod))) - (case kind - ((public) (modref-cont mod var #t)) - ((private) (if (not (equal? mod (module-name (current-module)))) - (modref-cont mod var #f) - (bare-cont var))) - ((bare) (bare-cont var)) - ((hygiene) (if (and (not (equal? mod (module-name (current-module)))) - (module-variable (resolve-module mod) var)) - (modref-cont mod var #f) - (bare-cont var))) - (else (syntax-violation #f "bad module kind" var mod)))))) + (define (analyze-variable mod var modref-cont bare-cont) + (if (not mod) + (bare-cont var) + (let ((kind (car mod)) + (mod (cdr mod))) + (case kind + ((public) (modref-cont mod var #t)) + ((private) (if (not (equal? mod (module-name (current-module)))) + (modref-cont mod var #f) + (bare-cont var))) + ((bare) (bare-cont var)) + ((hygiene) (if (and (not (equal? mod (module-name (current-module)))) + (module-variable (resolve-module mod) var)) + (modref-cont mod var #f) + (bare-cont var))) + (else (syntax-violation #f "bad module kind" var mod)))))) - (define build-global-reference - (lambda (source var mod) - (analyze-variable - mod var - (lambda (mod var public?) - (make-module-ref source mod var public?)) - (lambda (var) - (make-toplevel-ref source var))))) + (define build-global-reference + (lambda (source var mod) + (analyze-variable + mod var + (lambda (mod var public?) + (make-module-ref source mod var public?)) + (lambda (var) + (make-toplevel-ref source var))))) - (define build-global-assignment - (lambda (source var exp mod) - (maybe-name-value! var exp) - (analyze-variable - mod var - (lambda (mod var public?) - (make-module-set source mod var public? exp)) - (lambda (var) - (make-toplevel-set source var exp))))) + (define build-global-assignment + (lambda (source var exp mod) + (maybe-name-value! var exp) + (analyze-variable + mod var + (lambda (mod var public?) + (make-module-set source mod var public? exp)) + (lambda (var) + (make-toplevel-set source var exp))))) - (define build-global-definition - (lambda (source var exp) - (maybe-name-value! var exp) - (make-toplevel-define source var exp))) + (define build-global-definition + (lambda (source var exp) + (maybe-name-value! var exp) + (make-toplevel-define source var exp))) - (define build-simple-lambda - (lambda (src req rest vars meta exp) - (make-lambda src - meta - ;; hah, a case in which kwargs would be nice. - (make-lambda-case - ;; src req opt rest kw inits vars body else - src req #f rest #f '() vars exp #f)))) + (define build-simple-lambda + (lambda (src req rest vars meta exp) + (make-lambda src + meta + ;; hah, a case in which kwargs would be nice. + (make-lambda-case + ;; src req opt rest kw inits vars body else + src req #f rest #f '() vars exp #f)))) - (define build-case-lambda - (lambda (src meta body) - (make-lambda src meta body))) + (define build-case-lambda + (lambda (src meta body) + (make-lambda src meta body))) - (define build-lambda-case - ;; req := (name ...) - ;; opt := (name ...) | #f - ;; rest := name | #f - ;; kw := (allow-other-keys? (keyword name var) ...) | #f - ;; inits: (init ...) - ;; vars: (sym ...) - ;; vars map to named arguments in the following order: - ;; required, optional (positional), rest, keyword. - ;; the body of a lambda: anything, already expanded - ;; else: lambda-case | #f - (lambda (src req opt rest kw inits vars body else-case) - (make-lambda-case src req opt rest kw inits vars body else-case))) + (define build-lambda-case + ;; req := (name ...) + ;; opt := (name ...) | #f + ;; rest := name | #f + ;; kw := (allow-other-keys? (keyword name var) ...) | #f + ;; inits: (init ...) + ;; vars: (sym ...) + ;; vars map to named arguments in the following order: + ;; required, optional (positional), rest, keyword. + ;; the body of a lambda: anything, already expanded + ;; else: lambda-case | #f + (lambda (src req opt rest kw inits vars body else-case) + (make-lambda-case src req opt rest kw inits vars body else-case))) - (define build-primref - (lambda (src name) - (if (equal? (module-name (current-module)) '(guile)) - (make-toplevel-ref src name) - (make-module-ref src '(guile) name #f)))) + (define build-primref + (lambda (src name) + (if (equal? (module-name (current-module)) '(guile)) + (make-toplevel-ref src name) + (make-module-ref src '(guile) name #f)))) - (define (build-data src exp) - (make-const src exp)) + (define (build-data src exp) + (make-const src exp)) - (define build-sequence - (lambda (src exps) - (if (null? (cdr exps)) - (car exps) - (make-sequence src exps)))) + (define build-sequence + (lambda (src exps) + (if (null? (cdr exps)) + (car exps) + (make-sequence src exps)))) - (define build-let - (lambda (src ids vars val-exps body-exp) - (for-each maybe-name-value! ids val-exps) - (if (null? vars) - body-exp - (make-let src ids vars val-exps body-exp)))) + (define build-let + (lambda (src ids vars val-exps body-exp) + (for-each maybe-name-value! ids val-exps) + (if (null? vars) + body-exp + (make-let src ids vars val-exps body-exp)))) - (define build-named-let - (lambda (src ids vars val-exps body-exp) - (let ((f (car vars)) - (f-name (car ids)) - (vars (cdr vars)) - (ids (cdr ids))) - (let ((proc (build-simple-lambda src ids #f vars '() body-exp))) - (maybe-name-value! f-name proc) - (for-each maybe-name-value! ids val-exps) - (make-letrec - src #f - (list f-name) (list f) (list proc) - (build-application src (build-lexical-reference 'fun src f-name f) - val-exps)))))) - - (define build-letrec - (lambda (src in-order? ids vars val-exps body-exp) - (if (null? vars) - body-exp - (begin + (define build-named-let + (lambda (src ids vars val-exps body-exp) + (let ((f (car vars)) + (f-name (car ids)) + (vars (cdr vars)) + (ids (cdr ids))) + (let ((proc (build-simple-lambda src ids #f vars '() body-exp))) + (maybe-name-value! f-name proc) (for-each maybe-name-value! ids val-exps) - (make-letrec src in-order? ids vars val-exps body-exp))))) + (make-letrec + src #f + (list f-name) (list f) (list proc) + (build-application src (build-lexical-reference 'fun src f-name f) + val-exps)))))) + + (define build-letrec + (lambda (src in-order? ids vars val-exps body-exp) + (if (null? vars) + body-exp + (begin + (for-each maybe-name-value! ids val-exps) + (make-letrec src in-order? ids vars val-exps body-exp))))) - ;; FIXME: use a faster gensym - (define-syntax build-lexical-var - (syntax-rules () - ((_ src id) (gensym (string-append (symbol->string id) " "))))) + ;; FIXME: use a faster gensym + (define-syntax build-lexical-var + (syntax-rules () + ((_ src id) (gensym (string-append (symbol->string id) " "))))) - (define-structure (syntax-object expression wrap module)) + (define-structure (syntax-object expression wrap module)) - (define-syntax no-source (identifier-syntax #f)) + (define-syntax no-source (identifier-syntax #f)) - (define source-annotation - (lambda (x) - (cond - ((syntax-object? x) - (source-annotation (syntax-object-expression x))) - ((pair? x) (let ((props (source-properties x))) - (if (pair? props) - props - #f))) - (else #f)))) + (define source-annotation + (lambda (x) + (cond + ((syntax-object? x) + (source-annotation (syntax-object-expression x))) + ((pair? x) (let ((props (source-properties x))) + (if (pair? props) + props + #f))) + (else #f)))) - (define-syntax arg-check - (syntax-rules () - ((_ pred? e who) - (let ((x e)) - (if (not (pred? x)) (syntax-violation who "invalid argument" x)))))) + (define-syntax arg-check + (syntax-rules () + ((_ pred? e who) + (let ((x e)) + (if (not (pred? x)) (syntax-violation who "invalid argument" x)))))) -;;; compile-time environments + ;; compile-time environments -;;; wrap and environment comprise two level mapping. -;;; wrap : id --> label -;;; env : label --> + ;; wrap and environment comprise two level mapping. + ;; wrap : id --> label + ;; env : label --> -;;; environments are represented in two parts: a lexical part and a global -;;; part. The lexical part is a simple list of associations from labels -;;; to bindings. The global part is implemented by -;;; {put,get}-global-definition-hook and associates symbols with -;;; bindings. + ;; environments are represented in two parts: a lexical part and a global + ;; part. The lexical part is a simple list of associations from labels + ;; to bindings. The global part is implemented by + ;; {put,get}-global-definition-hook and associates symbols with + ;; bindings. -;;; global (assumed global variable) and displaced-lexical (see below) -;;; do not show up in any environment; instead, they are fabricated by -;;; lookup when it finds no other bindings. + ;; global (assumed global variable) and displaced-lexical (see below) + ;; do not show up in any environment; instead, they are fabricated by + ;; lookup when it finds no other bindings. -;;; ::= ((