15.6.2.0930 CODE TOOLS EXT

( "<spaces>name" -- )

Skip leading space delimiters. Parse name delimited by a space. Create a definition for name, called a "code definition", with the execution semantics defined below.

Subsequent characters in the parse area typically represent source code in a programming language, usually some form of assembly language. Those characters are processed in an implementation-defined manner, generating the corresponding machine code. The process continues, refilling the input buffer as needed, until an implementation-defined ending sequence is processed.

name Execution:

( i * x -- j * x )

Execute the machine code sequence that was generated following CODE.

See:

Rationale:

Some Forth systems implement the assembly function by adding an ASSEMBLER word list to the search order, using the text interpreter to parse a postfix assembly language with lexical characteristics similar to Forth source code. Typically, in such systems, assembly ends when a word END-CODE is interpreted.

ContributeContributions

ruvavatar of ruv [372] May `CODE` be a parsing word?Request for clarification2024-12-30 17:37:44

15.6.2.0930 CODE says:

Those characters are processed in an implementation-defined manner, generating the corresponding machine code. The process continues, refilling the input buffer as needed, until an implementation-defined ending sequence is processed.

Does this imply that code actively parses the input source?

If it actively parses, is it standard-compliant?

AntonErtlavatar of AntonErtl

The traditional implementation is to use the Forth parser. But given the specification, how would you detect the difference? So yes, I think that both kinds of implementations are standard-conforming.

Reply New Version