#lang scheme/unit


(export code^)

;; Provide context for evaluation of macro.
(define (unwrap x)
  (if (word? x)
      (state-unwrap (x (state:stack)))

 ;; Quoted delayed code.         
 (([qw ma] [qw mb] compose)   ([qw (macro: ,ma ,mb)]))
 ;; Get the address from the macro that wraps a postponed
 ;; word. Perform the macro->data part immediately (as a type check
 ;; for the macro). Postpone the address evaluation, since it is only
 ;; available during assembly.
 (([qw a] address) ([qw (unwrap a)]))

 ;; The basic behaviour is 'i, which will invoke a quoted macro, or
 ;; will delegate a call to the run-time word.

 (([qw (? macro-word? w)] i) w)
 ;; ((i) (macro: ~i))  ;; FIXME

 ((nop) ())

 ;; 'execute has a lower level semantics: it operates on quoted
 ;; numbers/labels instead, and will not execute macros.
 (([qw label] execute) ([cw label]))
 ;; ((execute) (macro: ~i))  ;; FIXME

 ;; 'compile will operate on both macros and labels, but won't
 ;; delegate to run-time.
 (([qw (? target-word? w)] compile) ([cw w]))
 (([qw (? macro-word? w)] compile)  w)