[<<][staapl][>>][..]Sat Nov 12 19:06:53 EST 2011
Compile a macro into a word
This was the attempt, but it seems I'm confusing macro (state->state)
and state types.
;; FIXME: compile a word outside of the current chain.
(([qw label] [qw macro])) ,(add-word label macro))
(define (add-word label macro)
((dict : (struct dict (current chain store))
-> (make-dict current
(cons (make-dict-entry label macro)
(define (make-dict-entry label macro)
That's where I saw that I'm dealing with apples and oranges. How to
call the compiler recursively? Or how to avoid that, and do the chain
Looks like what's really needed is something that does state stack
juggling, like this:
(macro: ',label label-org-begin ,macro exit org-end)
So I've wrapped it in a 'compile-macro' word, which seems to work.
The code is compiled outside the current chain.
box> (forth> ": foo 5 6 begin make-label [ 123 + ] compile-macro 7 8 again")
.L11: 0052 00A4 0F7B [addlw 123]
0053 00A6 0012 [return 0]
foo: 0054 00A8 6EEC [movwf PREINC0 0]
0055 00AA 0E05 [movlw 5]
0056 00AC 6EEC [movwf PREINC0 0]
0057 00AE 0E06 [movlw 6]
.L10: 0058 00B0 6EEC [movwf PREINC0 0]
0059 00B2 0E07 [movlw 7]
005A 00B4 6EEC [movwf PREINC0 0]
005B 00B6 0E08 [movlw 8]
005C 00B8 D7FB [jsr 1 .L10]
Trouble is though, if I want to use this for one-shot compilation of
code that's used whenever a macro is invoked that needs support code,
it will be compiled again for incremental compilation, as this kind of
state is not saved.