mirror of
https://github.com/nineties/planckforth
synced 2024-12-27 21:58:35 +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 ;
|
: c, B ;
|
||||||
: cmove, m ;
|
: cmove, m ;
|
||||||
: strlen z ;
|
: strlen z ;
|
||||||
|
: str= E ;
|
||||||
: state M ;
|
: state M ;
|
||||||
: aligned a ;
|
: aligned a ;
|
||||||
: align A ;
|
: align A ;
|
||||||
|
@ -1643,4 +1644,45 @@ stdin_ push-inputstream
|
||||||
|
|
||||||
switch-to-4th-stage
|
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
|
." Ready" cr
|
||||||
|
|
Loading…
Reference in a new issue