;; This implements a shorthand interface to a selection of host code ;; which interacts with the target system. The goal of this is to ;; prevent the use of explicit host code, where host and target ;; treated as separate entities, in cases where a "console attached to ;; target" model is simpler. ;; This mechanism is supposed to be extensible through the global name ;; space. (module interactive mzscheme ;; Translate interactive forth code to (prj:) code using a forth ;; parser. This is PURE SYNTAX. All semantic problems are to be ;; solved somewhere else. (require "stx-stream.ss" "ns.ss" "forth.ss" ;; misc forth parsing ) (provide (all-defined)) (named-parsers (live) ;; Words that modify the semantics of the following symbol. ;; FIXME: either >> or 2/ needs 'truncate' for simulation, or ;; explicit signed/unsigned conversion. (see ((dc w) ('w tsee))) (msee ((dc w) ('w msee))) (vsee ((dc w) ('w vsee))) (help ((dc w) ('w print-doc))) (ul ((dc w) (maybe-empty mark 'w ->string file>asm! commit))) (load ((dc w) ('w ->string file>asm!))) (prj ((dc w) ("prj/" 'w ->string string-append project))) (project ((dc w) ('w ->string project))) (start ((dc w) ('w tfind tstart/w))) (|'| ((dc w) ('w tfind _>t))) (dump ((dc w) ('w tfind 1 <<< f! fdump))) (plot ((dc n) ('n plot))) (2plot ((dc n) ('n 2plot))) (_1cmd ((w) (t> t> hilo> w))) (1cmd ((w) (t> w))) (0cmd ((w) (w))) ;; To simulate or not is decided by the 'sim/target' word. We ;; just provide the word symbol and simulation code. The ;; arguments to 'sim' are the number of atoms to get from the ;; target stack in a list, and the function to apply to this ;; list before putting back the result. (2sim ((w) ('w (2 (w) sim) sim/target))) (1sim ((w) ('w (1 (w) sim) sim/target))) ;; Memory access is never overridden by target ;; implementation. FIXME: why is this? (@ ((w) (1 (access-bank t@) sim))) (! ((w) (2 (access-bank t!) sim))) ;; FIXME: x >x x> ) (named-parser-clones (live) ;; In case the target does not contain the compiled forms of the ;; following words, they will be simulated. This is to interact ;; with a 'clean' target. ;; FIXME: u* u** (2sim + - * / and or xor min max swap) (1sim not 2/ >> << rot<< rot>> dup drop) ;; Some commands will perform host actions, but might take ;; arguments from the target stack. To limit surprises this list ;; is exhaustive: there are no automaticly delegated (prj:) ;; words. (0cmd mark dtc sync ts tss tsx _ts _tss _tsx pa ppa ping revert commit cold scrap pdict pforth clear empty more bin macros words install adump fdump hub tnop revert-macros ;; FIXME: make sure 'empty' does this ) (1cmd ablock fblock kb a! f! abd fbd p px ps ;; one byte unsinged, hex, signed erase-block client ) (_1cmd _p _px _ps)) ;; Entry point for (syntax-only!) live interaction -> prj code ;; transformation. (define (live->prj code) (define default (predicates->parsers (number? ((n) (n tlit))) (symbol? ((w) ('w tinterpret))))) (apply-parsers-ns/default '(live) default code)) ;; Append a line to a log of lines. (define (log-line str stack) (if (or (null? stack) (not (equal? str (car stack)))) (cons str stack) stack)) )