From 872ea81adcef0c62568f886bd2c4fcd6edc56f6d Mon Sep 17 00:00:00 2001 From: Danny Yoo Date: Mon, 7 Mar 2011 18:33:31 -0500 Subject: [PATCH] starting to work on debugging the generated il --- compile.rkt | 11 ++++++++++- test-compiler.rkt | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 test-compiler.rkt diff --git a/compile.rkt b/compile.rkt index a6ef1f8..8780fdf 100644 --- a/compile.rkt +++ b/compile.rkt @@ -9,8 +9,17 @@ "sets.rkt" racket/list) -(provide compile-top) +(provide (rename-out [-compile compile])) +;(provide compile-top) + +(: -compile (ExpressionCore Target Linkage -> (Listof Statement))) +(define (-compile exp target linkage) + (statements + (compile exp + (list (make-Prefix (find-toplevel-variables exp))) + target + linkage))) diff --git a/test-compiler.rkt b/test-compiler.rkt new file mode 100644 index 0000000..4772b9b --- /dev/null +++ b/test-compiler.rkt @@ -0,0 +1,37 @@ +#lang racket + +(require "simulator.rkt" + "simulator-structs.rkt" + "compile.rkt" + "parse.rkt") + +;; Test out the compiler, using the simulator. +(define-syntax (test stx) + (syntax-case stx () + [(_ code exp) + (with-syntax ([stx stx]) + (syntax/loc #'stx + (let* ([a-machine (run (new-machine (compile (parse code) 'val 'next)))] + [actual (machine-val a-machine)]) + (unless (equal? actual exp) + (raise-syntax-error #f (format "Expected ~s, got ~s" exp actual) + #'stx)))))])) + +;; run: machine -> machine +;; Run the machine to completion. +(define (run m) + (cond + [(can-step? m) + (run (step m))] + [else + m])) + + +(test 42 42) +(test '(begin (define x 42) + (+ x x)) + 84) + + +;(simulate (compile (parse '42) 'val 'next)) +;(compile (parse '(+ 3 4)) 'val 'next) \ No newline at end of file