ame)) (('lexical (and name (? symbol?))) (make-lexical-ref loc name name)) (('lexical (and name (? symbol?)) (and sym (? symbol?))) (make-lexical-ref loc name sym)) (('set! ('lexical (and name (? symbol?))) exp) (make-lexical-set loc name name (retrans exp))) (('set! ('lexical (and name (? symbol?)) (and sym (? symbol?))) exp) (make-lexical-set loc name sym (retrans exp))) (('@ ((and mod (? symbol?)) ...) (and name (? symbol?))) (make-module-ref loc mod name #t)) (('set! ('@ ((and mod (? symbol?)) ...) (and name (? symbol?))) exp) (make-module-set loc mod name #t (retrans exp))) (('@@ ((and mod (? symbol?)) ...) (and name (? symbol?))) (make-module-ref loc mod name #f)) (('set! ('@@ ((and mod (? symbol?)) ...) (and name (? symbol?))) exp) (make-module-set loc mod name #f (retrans exp))) (('toplevel (and name (? symbol?))) (make-toplevel-ref loc #f name)) (('set! ('toplevel (and name (? symbol?))) exp) (make-toplevel-set loc #f name (retrans exp))) (('define (and name (? symbol?)) exp) (make-toplevel-define loc #f name (retrans exp))) (('lambda meta body) (make-lambda loc meta (retrans body))) (('lambda-case ((req opt rest kw inits gensyms) body) alternate) (make-lambda-case loc req opt rest kw (map retrans inits) gensyms (retrans body) (and=> alternate retrans))) (('lambda-case ((req opt rest kw inits gensyms) body)) (make-lambda-case loc req opt rest kw (map retrans inits) gensyms (retrans body) #f)) (('const exp) (make-const loc exp)) (('seq head tail) (make-seq loc (retrans head) (retrans tail))) ;; Convenience. (('begin . exps) (list->seq loc (map retrans exps))) (('let names gensyms vals body) (make-let loc names gensyms (map retrans vals) (retrans body))) (('letrec names gensyms vals body) (make-letrec loc #f names gensyms (map retrans vals) (retrans body))) (('letrec* names gensyms vals body) (make-letrec loc #t names gensyms (map retrans vals) (retrans body))) (('fix names gensyms vals body) (make-fix loc names gensyms (map retrans vals) (retrans body))) (('let-values exp body) (make-let-values loc (retrans exp) (retrans body))) (('prompt escape-only? tag body handler) (make-prompt loc escape-only? (retrans tag) (retrans body) (retrans handler))) (('abort tag args tail) (make-abort loc (retrans tag) (map retrans args) (retrans tail))) (else (error "unrecognized tree-il" exp))))) (define (unparse-tree-il tree-il) (match tree-il (($ src) '(void)) (($ src proc args) `(call ,(unparse-tree-il proc) ,@(map unparse-tree-il args))) (($ src name args) `(primcall ,name ,@(map unparse-tree-il args))) (($ src test consequent alternate) `(if ,(unparse-tree-il test) ,(unparse-tree-il consequent) ,(unparse-tree-il alternate))) (($ src name) `(primitive ,name)) (($ src name gensym) `(lexical ,name ,gensym)) (($ src name gensym exp) `(set! (lexical ,name ,gensym) ,(unparse-tree-il exp))) (($ src mod name public?) `(,(if public? '@ '@@) ,mod ,name)) (($ src mod name public? exp) `(set! (,(if public? '@ '@@) ,mod ,name) ,(unparse-tree-il exp))) (($ src mod name) `(toplevel ,name)) (($ src mod name exp) `(set! (toplevel ,name) ,(unparse-tree-il exp))) (($ src mod name exp) `(define ,name ,(unparse-tree-il exp))) (($ src meta body) (if body `(lambda ,meta ,(unparse-tree-il body)) `(lambda ,meta (lambda-case)))) (($ src req opt rest kw inits gensyms body alternate) `(lambda-case ((,req ,opt ,rest ,kw ,(map unparse-tree-il inits) ,gensyms) ,(unparse-tree-il body)) . ,(if alternate (list (unparse-tree-il alternate)) '()))) (($ src exp) `(const ,exp)) (($ src head tail) `(seq ,(unparse-tree-il head) ,(unparse-tree-il tail))) (($ src names gensyms vals body) `(let ,names ,gensyms ,(map unparse-tree-il vals) ,(unparse-tree-il body))) (($ src in-order? names gensyms vals body) `(,(if in-order? 'letrec* 'letrec) ,names ,gensyms ,(map unparse-tree-il vals) ,(unparse-tree-il body))) (($ src names gensyms vals body) `(fix ,names ,gensyms ,(map unparse-tree-il vals) ,(unparse-tree-il body))) (($ src exp body) `(let-values ,(unparse-tree-il exp) ,(unparse-tree-il body))) (($ src escape-only? tag body handler) `(prompt ,escape-only? ,(unparse-tree-il tag) ,(unparse-tree-il body) ,(unparse-tree-il handler))) (($ src tag args tail) `(abort ,(unparse-tree-il tag) ,(map unparse-tree-il args) ,(unparse-tree-il tail))))) (define* (tree-il->scheme e #:optional (env #f) (opts '())) (values ((@ (language scheme decompile-tree-il) decompile-tree-il) e env opts)))