From 487ece4158035f51c807c2952f40db26de151e1f Mon Sep 17 00:00:00 2001 From: Koichi Nakamura Date: Sat, 16 Jan 2021 08:36:03 +0900 Subject: [PATCH] Add "value" and "to" --- bootstrap.fs | 19 ++++++++++++++++++- test/coreexttest.fs | 12 ++++++------ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/bootstrap.fs b/bootstrap.fs index aa9b335..0706d7f 100644 --- a/bootstrap.fs +++ b/bootstrap.fs @@ -915,6 +915,22 @@ allot-cell : &find! [ ' L , , ] ; \ ( c-addr -- nt ) Throw exception at error \ ( n "name" -- ) : constant create , does> @ ; +( === Value === ) + +\ ( n "name" -- ) +: value create , does> @ ; + +\ ( n "name" -- ) +: to + word! find! >cfa >body + state @ if + [compile] literal + compile ! + else + ! + then +; immediate + ( === Throw and Catch === ) \ 'xt catch' saves data stack pointer and a marker @@ -2561,7 +2577,8 @@ need-defined (read) .s . .r u. u.r dec. hex. type typen ." s" bl '\n' cr space base decimal hex catch throw success - : ; [ ] immediate create >body :noname does> variable constant + : ; [ ] immediate create >body :noname does> + variable constant value to ' ['] compile [compile] literal state + - * /mod / mod negate not and or xor invert within max min abs < > <= >= = <> 0< 0> 0<= 0>= 0= 0<> 1+ 1- diff --git a/test/coreexttest.fs b/test/coreexttest.fs index 9d230a5..de016dc 100644 --- a/test/coreexttest.fs +++ b/test/coreexttest.fs @@ -324,22 +324,22 @@ skip T{ 111 BUF:TEST ! 222 BUF:TEST CELL+ ! -> }T skip T{ BUF:TEST @ BUF:TEST CELL+ @ -> 111 222 }T \ ----------------------------------------------------------------------------- -testing VALUE TO +testing value to -T{ 111 VALUE VAL1 -999 VALUE VAL2 -> }T +T{ 111 value VAL1 -999 value VAL2 -> }T T{ VAL1 -> 111 }T T{ VAL2 -> -999 }T -T{ 222 TO VAL1 -> }T +T{ 222 to VAL1 -> }T T{ VAL1 -> 222 }T T{ : VD1 VAL1 ; -> }T T{ VD1 -> 222 }T -T{ : VD2 TO VAL2 ; -> }T +T{ : VD2 to VAL2 ; -> }T T{ VAL2 -> -999 }T T{ -333 VD2 -> }T T{ VAL2 -> -333 }T T{ VAL1 -> 222 }T -T{ 123 VALUE VAL3 IMMEDIATE VAL3 -> 123 }T -T{ : VD3 VAL3 LITERAL ; VD3 -> 123 }T +T{ 123 value VAL3 immediate VAL3 -> 123 }T +T{ : VD3 VAL3 literal ; VD3 -> 123 }T \ ----------------------------------------------------------------------------- testing CASE OF ENDOF ENDCASE