rosella/compiler.scm

66 lines
2.3 KiB
Scheme
Executable File

#! /usr/bin/mzscheme
#lang scheme/base
(require scheme/path)
(require scheme/pretty)
(require scheme/cmdline)
(require (file "libcompiler/reader.scm"))
(require (file "libcompiler/compiler.scm"))
(require (file "libcompiler/simplifier.scm"))
(require (file "libcompiler/writer.scm"))
(define simplify-code? (make-parameter #t))
(define reduce-code? (make-parameter #t))
(define map-bytecode? (make-parameter #t))
(define write-rla-bytecode? (make-parameter #t))
(define source-file
(command-line
#:once-each
[("-O") ol "Set the optimization level"
(optimize? (>= (string->number ol) 1))]
[("-E" "--read-only") "Stop before simplifying code"
(write-rla-bytecode? #f)
(map-bytecode? #f)
(reduce-code? #f)
(simplify-code? #f)]
[("-S" "--simplify-only") "Stop before reducing code to lowest terms"
(write-rla-bytecode? #f)
(map-bytecode? #f)
(reduce-code? #f)]
[("-R" "--reduce-only") "Stop before mapping forms to VM bytecode"
(write-rla-bytecode? #f)
(map-bytecode? #f)]
[("-M" "--map-only") "Stop before translating mapped forms to RLA syntax"
(write-rla-bytecode? #f)]
[("-v" "--verbose") "Output verbose intermediate (.rla) representation"
(verbose-rla? #t)]
#:args source-file
(if (null? source-file)
"-"
(car source-file))))
(define source-module
(if (string=? source-file "-")
(read-module)
(let* ([complete-path (path->complete-path source-file)]
[directory (path-only complete-path)])
(with-input-from-file complete-path
(lambda ()
(parameterize ([current-directory directory])
(read-module)))))))
(cond [(write-rla-bytecode?)
(write-rla-value (compile-function source-module))
(write-char #\Newline)]
[(map-bytecode?)
(pretty-print (compile-function source-module))]
[(reduce-code?)
(pretty-print (reduce-function source-module))]
[(simplify-code?)
(pretty-print (simplify-lambda source-module))]
[else
(pretty-print source-module)])
; vim:set sw=2 expandtab: