EVALUATE

( i * x c-addr u -- j * x )

Save the current input source specification. Store minus-one (-1) in SOURCE-ID if it is present. Make the string described by c-addr and u both the input source and input buffer, set >IN to zero, and interpret. When the parse area is empty, restore the prior input source specification. Other stack effects are due to the words EVALUATEd.

Testing:

: GE1 S" 123" ; IMMEDIATE
: GE2 S" 123 1+" ; IMMEDIATE
: GE3 S" : GE4 345 ;" ;
: GE5 EVALUATE ; IMMEDIATE

T{ GE1 EVALUATE -> 123 }T ( TEST EVALUATE IN INTERP. STATE )
T{ GE2 EVALUATE -> 124 }T
T{ GE3 EVALUATE ->     }T
T{ GE4          -> 345 }T

T{ : GE6 GE1 GE5 ; -> }T ( TEST EVALUATE IN COMPILE STATE )
T{ GE6 -> 123 }T
T{ : GE7 GE2 GE5 ; -> }T
T{ GE7 -> 124 }T

See F.9.3.6 for additional test.

ContributeContributions

BerndPaysanavatar of BerndPaysan Check for evaluate SOURCE is the string itself, not a copySuggested Testcase2016-03-21 02:32:54

: GS1 S" SOURCE" ;
T{ GS1 EVALUATE -> GS1 }T

GerryJacksonavatar of GerryJackson 2016-05-22 20:23:13

Both John Hayes' core test program and the specification for SOURCE already have this test case:

: GS1 S" SOURCE" 2DUP EVALUATE
       >R SWAP >R = R> R> = ;
T{ GS1 -> <TRUE> <TRUE> }T

which does the same thing, albeit less efficiently.

Reply