3 ms·
That is brilliant! So the embedded FORTH compiler written in AWK reads the FORTH code in a comment like this: //@C SPACES // \ n -- // BEGIN //
by Stratoscope 11y ago
That is brilliant!
So the embedded FORTH compiler written in AWK reads the FORTH code in a comment like this:
//@C SPACES
// \ n --
// BEGIN
// DUP 0>
// WHILE
// SPACE 1-
// REPEAT
// DROP
and compiles it into C code like this (reformatted here to help illustrate):
COM(
spaces_word, codeword, "SPACES", &space_word,
(void*)&dup_word, (void*)&more0_word,
(void*)&branch0_word, (void*)(&spaces_word.payload[0] + 8),
(void*)&space_word, (void*)&sub_one_word,
(void*)&branch_word, (void*)(&spaces_word.payload[0] + 0),
(void*)&drop_word,
(void*)&exit_word
)
- david-given 11y agoYup! COM() is a varargs macro that actually assembles the data in memory --- the actual word layout is not the traditional one Forth uses (to make it C friendly). But the end result is a linked list of Forth words in exactly the same format that user words have, which the user dictionary extends. It all means that the C source can just be compiled in a single step --- gcc -o fforth fforth.c --- without needing a precompilation stage, which makes it vastly easier to manage. It's even portable!