LITERAL - CORE (original) (raw)
6.1.1780 LITERAL CORE
Interpretation:
Interpretation semantics for this word are undefined.
Compilation:
( x -- )
Append the run-time semantics given below to the current definition.
Run-time:
( -- x )
Place x on the stack.
See:
Rationale:
Typical use:: X
...[ x
] LITERAL ... ;
Testing:
T{ : GT3 GT2 LITERAL ; -> }T
T{ GT3 -> ' GT1 }T
ContributeContributions
kumaym
[353] compile semantics or compile action of literal wordRequest for clarification2024-07-29 13:31:50
it's said compile semantics ( x -- ) of literal is to compile the rutime semantics of place x on stack ( -- x ) , in other words the action literal is supposed to do in compilation state is to compile a literal in the definition of currently defining word, and the literal compiled is obtained from the stack at the moment literal is executed (or compiled since it is a immediate word).
so,
: foo [ 4 ] literal ;
is supposed to define a word foo as having 4 in its body, and that's true
see foo
: foo 4 ; ok
following the compilation of foo step by step we first create a word foo then switch to interpretation mode and push 4 to the stack and then go back to compilation mode to compile literal witch being an immediate word gets executed just to compile 4 (what is on the stack) to the definition of foo and then ; ends the definiton, getting a word containing 4 in its body.
But, then shouldn't be equivalent these two definitions?
: foo [ 4 ] literal ;
4 : foo literal ;
so strange they're not, the first one is ok but the last one gives this error in gforth:
*the terminal*:20:17: error: Control structure mismatch
4 : foo literal >>>;<<<
Backtrace:
kernel/cond.fs:114:26 0 $6FFFFF810200 throw
glocals.fs:635:5 1 $6FFFFF821AB0 ?struc
kernel/comp.fs:773:5 2 $6FFFFF806BF0 ;-hook
why?