testing assembly
This commit is contained in:
parent
e6362835bf
commit
5f42959da5
|
@ -4,7 +4,10 @@
|
||||||
racket/string
|
racket/string
|
||||||
racket/list)
|
racket/list)
|
||||||
|
|
||||||
(provide (all-defined-out))
|
(provide assemble/write-invoke
|
||||||
|
fracture
|
||||||
|
assemble-basic-block
|
||||||
|
assemble-statement)
|
||||||
|
|
||||||
|
|
||||||
;; assemble/write-invoke: (listof statement) output-port -> void
|
;; assemble/write-invoke: (listof statement) output-port -> void
|
||||||
|
|
42
test-assemble.rkt
Normal file
42
test-assemble.rkt
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
#lang racket
|
||||||
|
|
||||||
|
(require "assemble.rkt"
|
||||||
|
"browser-evaluate.rkt"
|
||||||
|
"parse.rkt"
|
||||||
|
"il-structs.rkt"
|
||||||
|
racket/port
|
||||||
|
racket/runtime-path)
|
||||||
|
|
||||||
|
(define-runtime-path runtime.js "runtime.js")
|
||||||
|
(define runtime (call-with-input-file runtime.js
|
||||||
|
(lambda (ip) (port->string ip))))
|
||||||
|
|
||||||
|
; Test out the compiler, using the simulator.
|
||||||
|
(define-syntax (test stx)
|
||||||
|
(syntax-case stx ()
|
||||||
|
[(_ expr expected)
|
||||||
|
(with-syntax ([stx stx])
|
||||||
|
(syntax/loc #'stx
|
||||||
|
(begin
|
||||||
|
(printf "Running ~s ...\n" 'exp)
|
||||||
|
(let ([actual expr])
|
||||||
|
(unless (equal? actual expected)
|
||||||
|
(raise-syntax-error #f (format "Expected ~s, got ~s" exp actual)
|
||||||
|
#'stx))
|
||||||
|
(printf "ok.\n\n")))))]))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
(define e (make-evaluate
|
||||||
|
(lambda (a-statement op)
|
||||||
|
(let ([code
|
||||||
|
(string-append
|
||||||
|
"(function() { "
|
||||||
|
runtime
|
||||||
|
"return function(success, fail, params){" (assemble-statement a-statement) "success(String(MACHINE.val)); };"
|
||||||
|
"});")])
|
||||||
|
(display code op)))))
|
||||||
|
|
||||||
|
|
||||||
|
(test (evaluated-value (e (make-AssignImmediateStatement 'val (make-Const 42))))
|
||||||
|
"42")
|
Loading…
Reference in New Issue
Block a user