coma/macro.ss
#lang scheme/base

;; Bundles lowlevel macro code and adds some convenience functions.

(require
 "../tools.ss")
(provide
 (all-from-out "../tools.ss"))

(require/provide
 "../ns.ss"
 "../scat.ss"
 "../sig.ss"
 "../op.ss"
 "pattern.ss"
 "pattern-meta.ss"
 "pattern-runtime.ss"
 "macro-utils.ss"
 "rpn-macro.ss"
 "macro-eval.ss"
 "op.ss"       ;; compile + literal
 "../target.ss"
 "target-scat.ss"  ;; target:
;; "../asm/directives.ss"
 )

(provide (all-defined-out))


;; Universal list -> macro convertor: each element is quoted and
;; posprocessed with a glue macro. This can be used to construct
;; tables or simple embedded point-free languages.
(define (list->macro glue lst)
  (scat-compose
   (map (lambda (el) (macro: ',el ,glue)) lst)))



;; Convert a wrapper macro to the word instance, leave other types
;; intact.  NOTE: it might be best to restrict this to 'address' only,
;; because ticked words (macros) are really different from addresses.
(define (state-unwrap state)
  (let ((word (state->value state (ns (op ? cw)))))
    (tv: word)))

(define macro-word? word?)