#lang scheme/base
(require
"../target.ss"
"../scat.ss"
"tethered.ss"
"console.ss"
"commands.ss"
(for-syntax
"../tools-tx.ss"
"../scat-tx.ss"
"../forth-tx.ss"
scheme/base))
(provide (all-defined-out))
(define (target-interpret fn e)
(cond
((procedure? fn) (fn e))
((target-word? fn) ((scat: ',(target-word-address fn) texec/w) e))
(else (error 'target-interpret))))
(define-syntax (target: stx)
(define (immediate im e) #`((scat: ' #,im >t) #,e))
(define (function fn e) #`(target-interpret #,fn #,e))
(define (map-id id) (ns-prefixed #'(target) id))
(with-scat-syntax
(lambda ()
(parameterize
((rpn-map-identifier map-id)
(rpn-immediate immediate)
(rpn-function function)
(rpn-lambda scat-lambda)
(rpn-context with-scat-syntax)) (rpn-compile (stx-cdr stx))))))
(define-syntax-rule (target> code ...) (scat-console (target: code ...)))
(define-syntax (forth-command stx)
(syntax-case stx ()
((_ str) #`(target> #,@(string->forth-syntax #'str)))))