mirror of
https://github.com/remko/waforth
synced 2025-02-07 20:46:34 +01:00
simplify compiled control flow instructions
This commit is contained in:
parent
ef01a303ca
commit
9c647ef565
1 changed files with 8 additions and 15 deletions
|
@ -1931,14 +1931,8 @@
|
||||||
(func $compileIf
|
(func $compileIf
|
||||||
(call $compilePop)
|
(call $compilePop)
|
||||||
(call $emitConst (i32.const 0))
|
(call $emitConst (i32.const 0))
|
||||||
|
(call $emitNotEqual)
|
||||||
;; ne
|
|
||||||
(i32.store8 (global.get $cp) (i32.const 0x47))
|
|
||||||
(global.set $cp (i32.add (global.get $cp) (i32.const 1)))
|
|
||||||
|
|
||||||
;; if (empty block)
|
|
||||||
(call $emitIf)
|
(call $emitIf)
|
||||||
|
|
||||||
(global.set $branchNesting (i32.add (global.get $branchNesting) (i32.const 1))))
|
(global.set $branchNesting (i32.add (global.get $branchNesting) (i32.const 1))))
|
||||||
|
|
||||||
(func $compileThen
|
(func $compileThen
|
||||||
|
@ -2016,27 +2010,22 @@
|
||||||
(call $emitBr (i32.add (global.get $branchNesting) (i32.const 1))))
|
(call $emitBr (i32.add (global.get $branchNesting) (i32.const 1))))
|
||||||
|
|
||||||
(func $compileBegin
|
(func $compileBegin
|
||||||
(call $emitBlock)
|
|
||||||
(call $emitLoop)
|
(call $emitLoop)
|
||||||
(global.set $branchNesting (i32.add (global.get $branchNesting) (i32.const 2))))
|
(global.set $branchNesting (i32.add (global.get $branchNesting) (i32.const 2))))
|
||||||
|
|
||||||
(func $compileWhile
|
(func $compileWhile
|
||||||
(call $compilePop)
|
(call $compileIf))
|
||||||
(call $emitEqualsZero)
|
|
||||||
(call $emitBrIf (i32.const 1)))
|
|
||||||
|
|
||||||
(func $compileRepeat
|
(func $compileRepeat
|
||||||
(call $emitBr (i32.const 0))
|
(call $emitBr (i32.const 1)) ;; Jump across while to repeat
|
||||||
(call $emitEnd)
|
(call $emitEnd)
|
||||||
(call $emitEnd)
|
(call $emitEnd)
|
||||||
(global.set $branchNesting (i32.sub (global.get $branchNesting) (i32.const 2))))
|
(global.set $branchNesting (i32.sub (global.get $branchNesting) (i32.const 1))))
|
||||||
|
|
||||||
(func $compileUntil
|
(func $compileUntil
|
||||||
(call $compilePop)
|
(call $compilePop)
|
||||||
(call $emitEqualsZero)
|
(call $emitEqualsZero)
|
||||||
(call $emitBrIf (i32.const 0))
|
(call $emitBrIf (i32.const 0))
|
||||||
(call $emitBr (i32.const 1))
|
|
||||||
(call $emitEnd)
|
|
||||||
(call $emitEnd)
|
(call $emitEnd)
|
||||||
(global.set $branchNesting (i32.sub (global.get $branchNesting) (i32.const 2))))
|
(global.set $branchNesting (i32.sub (global.get $branchNesting) (i32.const 2))))
|
||||||
|
|
||||||
|
@ -2133,6 +2122,10 @@
|
||||||
(i32.store8 (global.get $cp) (i32.const 0x45))
|
(i32.store8 (global.get $cp) (i32.const 0x45))
|
||||||
(global.set $cp (i32.add (global.get $cp) (i32.const 1))))
|
(global.set $cp (i32.add (global.get $cp) (i32.const 1))))
|
||||||
|
|
||||||
|
(func $emitNotEqual
|
||||||
|
(i32.store8 (global.get $cp) (i32.const 0x47))
|
||||||
|
(global.set $cp (i32.add (global.get $cp) (i32.const 1))))
|
||||||
|
|
||||||
(func $emitGreaterEqualSigned
|
(func $emitGreaterEqualSigned
|
||||||
(i32.store8 (global.get $cp) (i32.const 0x4e))
|
(i32.store8 (global.get $cp) (i32.const 0x4e))
|
||||||
(global.set $cp (i32.add (global.get $cp) (i32.const 1))))
|
(global.set $cp (i32.add (global.get $cp) (i32.const 1))))
|
||||||
|
|
Loading…
Add table
Reference in a new issue