mirror of
https://github.com/nineties/planckforth
synced 2025-01-13 08:01:10 +01:00
Add "case" statement
This commit is contained in:
parent
a1242df09e
commit
cf75d5474e
1 changed files with 47 additions and 0 deletions
47
core.fs
47
core.fs
|
@ -686,6 +686,53 @@ alias-builtin xor ^
|
|||
latest @ >cfa ,
|
||||
; immediate
|
||||
|
||||
\ === Case ===
|
||||
|
||||
\ ---
|
||||
\ <value> case
|
||||
\ <value1> of <case1> endof
|
||||
\ <value2> of <case2> endof
|
||||
\ ...
|
||||
\ <default case>
|
||||
\ endcase
|
||||
\ ---
|
||||
\ This is equivalent to
|
||||
\ ---
|
||||
\ <value>
|
||||
\ <value1> over = if drop <case1> else
|
||||
\ <value2> over = if drop <case2> else
|
||||
\ ...
|
||||
\ <default case>
|
||||
\ then ... then then
|
||||
\ ---
|
||||
|
||||
|
||||
\ compile: ( -- 0 )
|
||||
\ runtime: ( n -- )
|
||||
: case
|
||||
0 \ push 0 to indicate there is no more case
|
||||
; immediate
|
||||
|
||||
\ compile: ( -- orig )
|
||||
: of
|
||||
compile over
|
||||
compile =
|
||||
[compile] if
|
||||
compile drop
|
||||
; immediate
|
||||
|
||||
\ compile: ( orig1 -- orig2 )
|
||||
: endof
|
||||
[compile] else
|
||||
; immediate
|
||||
|
||||
: endcase
|
||||
compile drop
|
||||
begin ?dup while
|
||||
[compile] then
|
||||
repeat
|
||||
; immediate
|
||||
|
||||
\ === Multiline Comment ===
|
||||
|
||||
: '(' [ key ( ] literal ;
|
||||
|
|
Loading…
Reference in a new issue