A sample run of the compiler from scratch

This commit is contained in:
Danny Yoo 2011-12-14 14:51:27 -05:00
parent 719ec6a554
commit 7d6ddd4ee5

23
sandbox/sample-run.rkt Normal file
View File

@ -0,0 +1,23 @@
#lang racket
(require (planet dyoo/whalesong/get-module-bytecode)
(planet dyoo/whalesong/parser/parse-bytecode)
(planet dyoo/whalesong/compiler/compiler)
(planet dyoo/whalesong/compiler/compiler-structs)
(planet dyoo/whalesong/js-assembler/assemble))
(define bytecode
(get-module-bytecode
(open-input-string
(string-append "#lang planet dyoo/whalesong\n"
"(define (f x)\n"
" (if (= x 0)\n"
" 1\n"
" (* x (f (sub1 x)))))\n\n"
"(provide f)"))))
(define ast (parse-bytecode (open-input-bytes bytecode)))
(define stmts (compile ast 'val next-linkage/drop-multiple))
(define op (open-output-string))
(assemble/write-invoke stmts op)