#lang scheme/base

;; PLT language for SCAT with Forth syntax.

;; FIXME: This seems to be broken.. If you have use for it, I'll fix
;; it. Other than that, it's mostly a toy. Might some day be used for
;; simulating .f code or so.

(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)
                 ((#f _ _ _)
                  #`(void))
                 ((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
                 (all-defined-out))) ;; FIXME: add forth provide support
        (define-words code ...)))))

