starting to work on debugging the generated il

This commit is contained in:
Danny Yoo 2011-03-07 18:33:31 -05:00
parent 414f806580
commit 872ea81adc
2 changed files with 47 additions and 1 deletions

View File

@ -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)))

37
test-compiler.rkt Normal file
View File

@ -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)