From 98dbf19a454a19405fde535f4fa2cf366223dec0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Remko=20Tron=C3=A7on?= Date: Wed, 30 May 2018 22:49:16 +0200 Subject: [PATCH] Compile push & pop using global TOS. --- src/waforth.wat | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/waforth.wat b/src/waforth.wat index 0879b69..0b77da4 100644 --- a/src/waforth.wat +++ b/src/waforth.wat @@ -1667,12 +1667,22 @@ EOF ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (func $compilePushConst (param $n i32) + (call $emitGetGlobal (i32.const !tosIndex)) (call $emitConst (get_local $n)) - (call $emitICall (i32.const 1) (i32.const !pushIndex))) + (call $emitStore) + (call $emitGetGlobal (i32.const !tosIndex)) + (call $emitConst (i32.const 4)) + (call $emitAdd) + (call $emitSetGlobal (i32.const !tosIndex))) (func $compilePushLocal (param $n i32) + (call $emitGetGlobal (i32.const !tosIndex)) (call $emitGetLocal (get_local $n)) - (call $emitICall (i32.const 1) (i32.const !pushIndex))) + (call $emitStore) + (call $emitGetGlobal (i32.const !tosIndex)) + (call $emitConst (i32.const 4)) + (call $emitAdd) + (call $emitSetGlobal (i32.const !tosIndex))) (func $compileIf (call $compilePop) @@ -1796,9 +1806,14 @@ EOF (set_global $cp (i32.add (get_global $cp) (i32.const 1))) (i32.store8 (get_global $cp) (i32.const 0x00)) (set_global $cp (i32.add (get_global $cp) (i32.const 1)))) - + (func $compilePop - (call $emitICall (i32.const 2) (i32.const !popIndex))) + (call $emitGetGlobal (i32.const !tosIndex)) + (call $emitConst (i32.const 4)) + (call $emitSub) + (call $emitSetGlobal (i32.const !tosIndex)) + (call $emitGetGlobal (i32.const !tosIndex)) + (call $emitLoad)) (func $compileCall (param $findToken i32)