simplify compiled control flow instructions

This commit is contained in:
Remko Tronçon 2022-04-17 15:47:06 +02:00
parent ef01a303ca
commit 9c647ef565

View file

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