rainwarrior wrote:
My knowledge of FORTH is a bit rudimentary but I'm curious about terms like (OAM+1) and (128<<8).
I should probably clarify that this is not a true FORTH. Rather, it is a stack language that takes certain ideas from FORTH, certain ideas from Factor, and mixes in some convenient syntax to mesh with CA65 better. Actually, it's probably closer to Factor than to FORTH. Maybe I should have called it NACTOR.
rainwarrior wrote:
Does () pass the enclosed text directly to the assembler without being processed by FORTH?
Yes, that's it. Stuff inside parenthesis is copied verboten into the output.
rainwarrior wrote:
If you're willing, it might be useful to see the assembly output (example.inc?) to understand an example of how things get translated, for people that don't have make and haskell (or other dependencies?) ready to go.
https://pastebin.com/raw/f1WcCYfrFor whatever reason, FORTH people like to call subroutines "words" and so that's the terminology I'm using. Anyway, the compiler understands six types of expressions:
Integer LiteralsInteger literals (e.g. 100, $FF, -5, %0101) are translated to:
Code:
__push value
(where value is the integer literal)
Word LiteralsWord literals, which are just identifiers prefixed by an apostrophe (e.g. 'foo, 'bar, 'qux, '+, '-) are translated to:
Code:
__push wordname
(where wordname is the CA65 label of the word after name mangling)
CA65 LiteralsCA65 literals, which are CA65 expressions inside parenthesis (e.g. (OAM+0), (128<<8), (.lobyte(FOO))) are translated to:
Code:
__push expression
(where expression is the CA65 expression copied verboten) Note that (foo) is equivalent to 'foo except it doesn't perform name mangling.
WordsWords (e.g. foo, bar, +, -) are translated to:
Code:
__call sub,wordname
(where wordname is the CA65 label of the word after name mangling) This gets translated into "jsr wordname", though the macro can inline certain calls.
Tail calls have the form:
Code:
__call tail,wordname
And gets translated into "jmp wordname" instead.
Quotations (Lambdas)Quotations, which are code expressions enclosed in [ ] brackets (e.g. [foo bar qux], [2 +]) are translated to:
Code:
__push __quotN
(where __quotN is a CA65 label corresponding to the quotation subroutine, which will be defined later on in the assembly output)
Address OperationsAddress operations, which are labels or CA65 expressions followed by a period and an operation name (e.g. foo.store, bar.load, (OAM+0).store) get translated to:
Code:
__addrOp op,addr
(where addr is the expression to the left of the period and op is the expression to the right.)
Address operations are used to implement loads and stores inline, which would otherwise require slow indirect addressing. The operations are all defined in the macro body.