Commit 02e2ce2d authored by William G Hatch's avatar William G Hatch
Browse files

update to use xsmith/app and new render-node stuff

parent 16a1e082
#lang racket/base
(require xsmith racr racket/pretty racket/string racket/port)
(require xsmith xsmith/app racr racket/pretty racket/string racket/port)
(define-spec-component arith)
......@@ -39,19 +39,19 @@
(λ (n)
`(let* (,@(map (λ (d)
`[,(string->symbol (ast-child 'name d))
,(render-node
,($xsmith_render-node
(ast-child 'Expression d))])
(ast-children (ast-child 'definitions n))))
,@(map (λ (c) (render-node c))
,@(map (λ (c) ($xsmith_render-node c))
(ast-children (ast-child 'sideEs n)))
,(render-node (ast-child 'Expression n))))]
,($xsmith_render-node (ast-child 'Expression n))))]
[LiteralInt (λ (n) (ast-child 'v n))]
[VariableReference (λ (n) (string->symbol (ast-child 'name n)))]
[SetBangRet (λ (n) `(begin (set! ,(string->symbol (ast-child 'name n))
,(render-node
,($xsmith_render-node
(ast-child 'Expression n)))
,(string->symbol (ast-child 'name n))))]
[Addition (λ (n) `(+ ,@(map (λ (c) (render-node c))
[Addition (λ (n) `(+ ,@(map (λ (c) ($xsmith_render-node c))
(ast-children (ast-child 'es n)))))])
......
......@@ -31,6 +31,7 @@
(require
xsmith
xsmith/racr-convenience
xsmith/app
racr
racket/class
racket/pretty
......@@ -353,9 +354,9 @@
,@(map (λ (global)
`(global ,(string->symbol (format "$~a" (ast-child 'name global)))
(mut i32)
,(render-node (ast-child 'initialvalue global))))
,($xsmith_render-node (ast-child 'initialvalue global))))
(reverse (ast-children (ast-child 'globals n))))
,(render-node (ast-child 'Func n))
,($xsmith_render-node (ast-child 'Func n))
(global $mem_base_internal (mut i32) (i32.const 0))
(global $mem_max_internal (mut i32) (i32.const 0))
(func (export "__post_instantiate")
......@@ -373,66 +374,66 @@
(reverse (ast-children (ast-child 'globals n))))))))]
[Func (λ (n) `(func (export "_func") (result i32)
(local ,@(make-list (ast-child 'localcount n) 'i32))
,@(render-node (ast-child 'root n))))]
,@($xsmith_render-node (ast-child 'root n))))]
[LiteralInt (λ (n) (list 'i32.const (ast-child 'v n)))]
[Noop (λ (n) (append
'(nop)
(render-node (ast-child 'expr n))))]
($xsmith_render-node (ast-child 'expr n))))]
[Binop (λ (n) (append
(render-node (ast-child 'l n))
(render-node (ast-child 'r n))
($xsmith_render-node (ast-child 'l n))
($xsmith_render-node (ast-child 'r n))
(list (att-value 'math-op n))))]
[Unop (λ (n) (append
(render-node (ast-child 'expr n))
($xsmith_render-node (ast-child 'expr n))
(list (att-value 'math-op n))))]
[IfElse (λ (n)
(append
(render-node (ast-child 'cond n))
($xsmith_render-node (ast-child 'cond n))
'(if (result i32))
(render-node (ast-child 'then n))
($xsmith_render-node (ast-child 'then n))
'(else)
(render-node (ast-child 'else n))
($xsmith_render-node (ast-child 'else n))
'(end)))]
[If (λ (n)
(append
(render-node (ast-child 'cond n))
($xsmith_render-node (ast-child 'cond n))
'(if (result i32))
(render-node (ast-child 'then n))
($xsmith_render-node (ast-child 'then n))
'(end)))]
[Block (λ (n)
(append
'(block (result i32))
(render-node (ast-child 'expr n))
($xsmith_render-node (ast-child 'expr n))
'(end)))]
[Loop (λ (n)
(append
'(loop (result i32))
(render-node (ast-child 'expr n))
($xsmith_render-node (ast-child 'expr n))
'(end)))]
[ForLoop (λ (n)
(append
(render-node (ast-child 'val (ast-child 'loopvar n)))
($xsmith_render-node (ast-child 'val (ast-child 'loopvar n)))
`(global.set ,(string->symbol (format "$~a" (ast-child 'name (ast-child 'loopvar n)))))
(render-node (ast-child 'loop n))))]
($xsmith_render-node (ast-child 'loop n))))]
[Branch (λ (n)
(append
(render-node (ast-child 'val n))
($xsmith_render-node (ast-child 'val n))
`(br ,(ast-child 'targetindex n))))]
[BranchIf (λ (n)
(append
(render-node (ast-child 'val n))
(render-node (ast-child 'cond n))
($xsmith_render-node (ast-child 'val n))
($xsmith_render-node (ast-child 'cond n))
`(br_if ,(ast-child 'targetindex n))))]
[MemStore (λ (n)
(append
(render-node (ast-child 'address n))
(render-node (ast-child 'value n))
($xsmith_render-node (ast-child 'address n))
($xsmith_render-node (ast-child 'value n))
`(i32.store ,(string->symbol (format "offset=~a" (ast-child 'offset n)))
,(string->symbol (format "align=~a" (expt 2 (ast-child 'alignment n)))))
(render-node (ast-child 'expr n))))]
($xsmith_render-node (ast-child 'expr n))))]
[MemLoad (λ (n)
(append
(render-node (ast-child 'address n))
($xsmith_render-node (ast-child 'address n))
`(i32.load ,(string->symbol (format "offset=~a" (ast-child 'offset n)))
,(string->symbol (format "align=~a" (expt 2 (ast-child 'alignment n)))))))]
[LocalGet (λ (n)
......@@ -440,21 +441,21 @@
`(local.get ,(ast-child 'index n))))]
[LocalSet (λ (n)
(append
(render-node (ast-child 'val n))
($xsmith_render-node (ast-child 'val n))
`(local.set ,(ast-child 'index n))
(render-node (ast-child 'expr n))))]
($xsmith_render-node (ast-child 'expr n))))]
[LocalTee (λ (n)
(append
(render-node (ast-child 'val n))
($xsmith_render-node (ast-child 'val n))
`(local.tee ,(ast-child 'index n))))]
[GlobalGet (λ (n)
(append
`(global.get ,(string->symbol (format "$~a" (ast-child 'name n))))))]
[GlobalSet (λ (n)
(append
(render-node (ast-child 'val n))
($xsmith_render-node (ast-child 'val n))
`(global.set ,(string->symbol (format "$~a" (ast-child 'name n))))
(render-node (ast-child 'expr n))))]
($xsmith_render-node (ast-child 'expr n))))]
)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment