rm-hull / byok

A bare-metal x86 Forth interpreter & compiler
MIT License
56 stars 11 forks source link

LITERAL use in [CHAR] / ASCII #11

Closed rm-hull closed 9 years ago

rm-hull commented 9 years ago

LITERAL is defined (as a primitive), along the lines:

: LITERAL ( n -- ) compile (lit) , ; immediate

When used to implement [CHAR]:

: [CHAR]  ( <char> -- char , for compile mode )
    char [compile] literal 
; immediate

Which we can then test with a trivial definition:

: f [char] F ;

yields the following disassembly:

00004828:  58 71 11 00  |Xq..|  NEST
0000482c:  70 ff 00 00  |p...|  (LIT)
00004830:  46 00 00 00  |F...|
00004834:  90 71 11 00  |.q..|  ,
00004838:  74 71 11 00  |tq..|  UNNEST

Using LITERAL for this seems incorrect, or at least should be used with a different compiler-controlling word