mirror of
https://github.com/nineties/planckforth
synced 2024-12-26 21:58:42 +01:00
Add [if]..[else]..[then]
This commit is contained in:
parent
f1b92c39d7
commit
9af496fd66
1 changed files with 42 additions and 0 deletions
42
bootstrap.fs
42
bootstrap.fs
|
@ -461,6 +461,7 @@ alias-builtin xor ^
|
|||
: c, B ;
|
||||
: cmove, m ;
|
||||
: strlen z ;
|
||||
: str= E ;
|
||||
: state M ;
|
||||
: aligned a ;
|
||||
: align A ;
|
||||
|
@ -1643,4 +1644,45 @@ stdin_ push-inputstream
|
|||
|
||||
switch-to-4th-stage
|
||||
|
||||
( === [if]..[else]..[then] === )
|
||||
|
||||
: [if] ( f -- )
|
||||
unless
|
||||
\ skip inputs until corresponding [else] or [then]
|
||||
0 \ depth
|
||||
begin
|
||||
word throw
|
||||
dup s" [if]" str= if
|
||||
drop 1+
|
||||
else dup s" [else]" str= if
|
||||
drop
|
||||
dup 0= if drop exit then
|
||||
else s" [then]" str= if
|
||||
dup 0= if drop exit then
|
||||
1-
|
||||
then then then
|
||||
again
|
||||
then
|
||||
; immediate
|
||||
|
||||
: [else]
|
||||
\ If the condition is false, [else] is skipped by [if].
|
||||
\ So when the execution reaches [else] it means that
|
||||
\ the condition was true.
|
||||
|
||||
\ skip inputs until corresponding [then]
|
||||
0 \ depth
|
||||
begin
|
||||
word throw
|
||||
dup s" [if]" str= if
|
||||
drop 1+
|
||||
else s" [then]" str= if
|
||||
dup 0= if drop exit then
|
||||
1-
|
||||
then then
|
||||
again
|
||||
; immediate
|
||||
|
||||
: [then] ; immediate \ do nothing
|
||||
|
||||
." Ready" cr
|
||||
|
|
Loading…
Reference in a new issue