scat/scat-tx.ss
#lang scheme/base
(provide
 (all-defined-out))
(require
 syntax/stx
 "rpn-tx.ss"
 "ns-tx.ss"
 (for-template
  "rep.ss"
  "stack.ss"
  scheme/base))

;; compilers specific to the state data + code rep
;; DATA = stack structure
;; CODE = unary stack -> stack functions
(define (scat-immediate im e) #`(stack-cons #,im #,e))
(define (scat-function  fn e) #`(#,fn #,e))



(define (scat-lambda body)
  #`(make-word
     #,(rpn-default-lambda body)))


;; FIXME: can't get this to expand to (word <id>) like in macro-tx.ss

;; base/base-tx.ss:28:5: require: namespace mismatch; reference (phase 0) to a module "/home/tom/scat/base/base.ss" that is not available (phase 0) in: base-word

;;  === context ===
;; /home/tom/scat/base/rpn-tx.ss:47:0: map-identifier/expand
;; /home/tom/scat/base/rpn-tx.ss:67:0: next
;; /home/tom/scat/base/base-tx.ss:18:0: base-represent
;; /usr/local/plt-3.99.0.12/collects/scheme/sandbox.ss:445:4: loop

(define (scat-map-identifier id)
  ;; #`(scat-word #,id))
  (ns-prefixed #'(scat) id))
 

(define (with-scat-syntax thunk)
  (parameterize
      ((rpn-immediate      scat-immediate)
       (rpn-function       scat-function)
       (rpn-lambda         scat-lambda)
       (rpn-map-identifier scat-map-identifier)
       (rpn-context        with-scat-syntax))
    (thunk)))

(define (scat:-tx stx)
  (syntax-case stx ()
    ((_ . code)
     (with-scat-syntax
      (lambda () (rpn-compile #'code))))))