add parsers and unparser for ghil; ,language ghil works now
* module/system/repl/common.scm (repl-print): Slightly refine the meaning of "language-printer": a language printer prints an expression of a language, not the result of evaluation. `write' prints values. * module/language/ghil/spec.scm (ghil): Define a language printer, and a translator for turning s-expressions (not scheme, mind you) into GHIL. * module/language/scheme/translate.scm (quote, quasiquote): Add some #:keyword action, so that we can (quote #:keywords). * module/system/base/language.scm (<language>): * module/system/base/compile.scm (read-file-in): Don't require that a language have a read-file; instead error when read-file is called. (compile-passes, compile-in): Refactor to call a helper method to turn the language + set of options into a set of compiler passes. * module/system/base/syntax.scm (define-type): Allow the type to be a list, with the car being the name and the cdr being keyword options. Interpret #:printer as a printer, and pass it down to... (define-record): Here. * module/system/il/ghil.scm (print-ghil, <ghil>): New printer for GHIL, yay! (parse-ghil, unparse-ghil): New lovely functions. Will document them in the manual.
This commit is contained in:
parent
f698d111b4
commit
f38624b349
7 changed files with 225 additions and 184 deletions
|
|
@ -30,6 +30,7 @@
|
|||
#:use-module (system vm vm) ;; for compile-time evaluation
|
||||
#:use-module (ice-9 regex)
|
||||
#:use-module (ice-9 optargs)
|
||||
#:use-module ((srfi srfi-1) #:select (fold))
|
||||
#:export (syntax-error compile-file load-source-file load-file
|
||||
*current-language*
|
||||
compiled-file-name
|
||||
|
|
@ -197,27 +198,35 @@ time. Useful for supporting some forms of dynamic compilation. Returns
|
|||
;;;
|
||||
|
||||
(define (read-file-in file lang)
|
||||
(call-with-input-file file (language-read-file lang)))
|
||||
(call-with-input-file file (or (language-read-file lang)
|
||||
(error "language has no #:read-file" lang))))
|
||||
|
||||
;;; FIXME: fold run-pass x (compile-passes lang opts)
|
||||
(define (compile-passes lang opts)
|
||||
(let lp ((passes (list
|
||||
(language-expander lang)
|
||||
(language-translator lang)
|
||||
(lambda (x e) (apply compile-il x e opts))
|
||||
(lambda (x e) (apply assemble x e opts))))
|
||||
(keys '(#f #:e #:t #:c))
|
||||
(out '()))
|
||||
(if (or (null? keys)
|
||||
(and (car keys) (memq (car keys) opts)))
|
||||
(reverse! out)
|
||||
(lp (cdr passes) (cdr keys)
|
||||
(if (car passes)
|
||||
(cons (car passes) out)
|
||||
out)))))
|
||||
|
||||
(define (compile-in x e lang . opts)
|
||||
(save-module-excursion
|
||||
(lambda ()
|
||||
(catch 'result
|
||||
(lambda ()
|
||||
(and=> (cenv-module e) set-current-module)
|
||||
(set! e (cenv-ghil-env e))
|
||||
;; expand
|
||||
(set! x ((language-expander lang) x e))
|
||||
(if (memq #:e opts) (throw 'result x))
|
||||
;; translate
|
||||
(set! x ((language-translator lang) x e))
|
||||
(if (memq #:t opts) (throw 'result x))
|
||||
;; compile
|
||||
(set! x (apply compile-il x e opts))
|
||||
(if (memq #:c opts) (throw 'result x))
|
||||
;; assemble
|
||||
(apply assemble x e opts))
|
||||
(lambda (key val) val)))))
|
||||
(and=> (cenv-module e) set-current-module)
|
||||
(let ((env (cenv-ghil-env e)))
|
||||
(fold (lambda (pass exp)
|
||||
(pass exp env))
|
||||
x
|
||||
(compile-passes lang opts))))))
|
||||
|
||||
;;;
|
||||
;;;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue