mirror of
https://github.com/remko/waforth
synced 2024-12-27 09:59:29 +01:00
Simplify interpreter
This commit is contained in:
parent
d481a1cdb1
commit
1c9d8182e5
1 changed files with 18 additions and 22 deletions
|
@ -815,11 +815,7 @@
|
|||
|
||||
;; 6.1.1710
|
||||
(func $immediate (param i32)
|
||||
(i32.store
|
||||
(i32.add (get_global $latest) (i32.const 4))
|
||||
(i32.or
|
||||
(i32.load (i32.add (get_global $latest) (i32.const 4)))
|
||||
(i32.const !fImmediate))))
|
||||
(call $setFlag (i32.const !fImmediate)))
|
||||
(!def_word "IMMEDIATE" "$immediate")
|
||||
|
||||
;; 6.1.1720
|
||||
|
@ -1404,25 +1400,18 @@ EOF
|
|||
(br $endLoop))))
|
||||
(else ;; Found the word.
|
||||
(set_local $body (call $body (get_local $findToken)))
|
||||
;; Are we compiling?
|
||||
(if (i32.eqz (i32.load (i32.const !stateBase)))
|
||||
;; Are we compiling or is it immediate?
|
||||
(if (i32.or (i32.eqz (i32.load (i32.const !stateBase)))
|
||||
(i32.eq (get_local $findResult) (i32.const 1)))
|
||||
(then
|
||||
;; We're not compiling. Execute the word.
|
||||
(call_indirect (type $word)
|
||||
(i32.add (get_local $body) (i32.const 4))
|
||||
(i32.load (get_local $body))))
|
||||
(call $push (get_local $findToken))
|
||||
(call $EXECUTE (i32.const -1)))
|
||||
(else
|
||||
;; We're compiling. Is it immediate?
|
||||
(if (i32.eq (get_local $findResult) (i32.const 1))
|
||||
(then ;; Immediate. Execute the word.
|
||||
(call_indirect (type $word)
|
||||
(i32.add (get_local $body) (i32.const 4))
|
||||
(i32.load (get_local $body))))
|
||||
(else ;; Not Immediate. Compile the word call.
|
||||
(call $emitConst (i32.add (get_local $body) (i32.const 4)))
|
||||
(call $emitICall
|
||||
(i32.const 1)
|
||||
(i32.load (get_local $body)))))))))
|
||||
;; We're compiling a non-immediate
|
||||
(call $emitConst (i32.add (get_local $body) (i32.const 4)))
|
||||
(call $emitICall
|
||||
(i32.const 1)
|
||||
(i32.load (get_local $body)))))))
|
||||
(br $loop)))
|
||||
;; 'WORD' left the address on the stack
|
||||
(drop (call $pop))
|
||||
|
@ -1647,6 +1636,13 @@ EOF
|
|||
;; Helper functions
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(func $setFlag (param $v i32)
|
||||
(i32.store
|
||||
(i32.add (get_global $latest) (i32.const 4))
|
||||
(i32.or
|
||||
(i32.load (i32.add (get_global $latest) (i32.const 4)))
|
||||
(get_local $v))))
|
||||
|
||||
(func $ensureCompiling
|
||||
(if (i32.eqz (i32.load (i32.const !stateBase)))
|
||||
(then
|
||||
|
|
Loading…
Reference in a new issue