From 7d6ddd4ee5152e8ff84905c950ec3a6e0f79617e Mon Sep 17 00:00:00 2001 From: Danny Yoo Date: Wed, 14 Dec 2011 14:51:27 -0500 Subject: [PATCH] A sample run of the compiler from scratch --- sandbox/sample-run.rkt | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 sandbox/sample-run.rkt diff --git a/sandbox/sample-run.rkt b/sandbox/sample-run.rkt new file mode 100644 index 0000000..8e76146 --- /dev/null +++ b/sandbox/sample-run.rkt @@ -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) \ No newline at end of file