From 9af496fd66a9a8f3d4bd75d71ac1db5ec294d34c Mon Sep 17 00:00:00 2001 From: Koichi Nakamura Date: Tue, 5 Jan 2021 09:19:04 +0900 Subject: [PATCH] Add [if]..[else]..[then] --- bootstrap.fs | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/bootstrap.fs b/bootstrap.fs index b92d712..4bc6269 100644 --- a/bootstrap.fs +++ b/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