forth/scat-forth.ss
#lang scheme/base

;; PLT language for SCAT with Forth syntax.

(require
 "../scat.ss"
 (for-syntax
  "../scat-tx.ss"
  "parser-tx.ss"
  syntax/stx
  scheme/base))

(provide
 define-words scat/: 
 (rename-out (module-begin #%module-begin))
 (except-out (all-from-out scheme/base) #%module-begin)
 (all-from-out "../scat.ss"))

;; macro + forth are not defined: this is a single mode language.
(define-syntax-ns (scat) : :-tx)

;; The function 'forth->records' is the entry point to the Forth
;; compiler. Here were're running it parameterized with scat
;; syntax. The macro mode is currently not supported.

(define-syntax (define-words stx)
  (syntax-case stx ()
    ((_ . code)
     #`(begin
         #,@(map
             (lambda (record)
               (syntax-case record (forth)
                 ((name forth srcloc rep)
                  #`(define-ns (scat) name rep))))
             (with-scat-syntax
              (lambda ()
                (forth->records
                 #'forth #'void #'void
                 #'code))))))))

(define-syntax (module-begin stx)
  (define (top form)
    (datum->syntax stx form))
  (syntax-case stx ()
    ((_ code ...)
     #`(#%plain-module-begin
        #,(top '(provide
                 scat: scat::
                 (all-defined-out))) ;; FIXME: add forth provide support
        (define-words code ...)))))