;; Code for running a Brood console with target state separated from ;; host state. This does not depend on any Brood code directly. ;; This is mainly to support on--the--fly core reloading of compiler ;; (host) code without having to save the target state image to disk. (module console mzscheme (provide (all-defined)) ;; strip! ;; update! ;; interpret ;; make-target ;; make-host ;; ) (define (init-target) '(( (forth) ;; (macro) (dict) (port) ;; empty args list means port not connected ))) ;; Clean state: remove all abstract objects. (define (strip target) (let strip ((e target)) (cond ((null? e) e) ((pair? e) (cons (strip (car e)) (strip (cdr e)))) ((or (symbol? e) (string? e) (boolean? e) (number? e)) e) (else (printf "stripping: ~s\n" e) '--stripped--)))) ;; Ask host to update target state using an expression in a ;; specified language. (define (update target host language expr) (host `(apply (rpn-compile ',expr ',language) ',target))) ;; Ask host to evaluate an expression in a specified language, ;; without touching target state. (define (interpret host language expr) (host `(apply (rpn-compile ',expr ',language) '()))) ;; stack is empty: pass all arguments in expr. (define (wordlist host namespaces) (lambda () (host `(ns-wordlist ',namespaces)))) ;; BASE (define (base-eval host expr) (apply values (interpret host 'base: expr))) (define (base-update target host expr) (update target host 'base: expr)) ;; base does the lexing through 'lex-line' (define (forth-string->syntax host str) (base-eval host `(,str lex-line))) (define (base-rep target host str) (update target host 'base: (forth-string->syntax host str))) (define (base-wordlist host) (wordlist host '((base)))) ;; PRJ ;; prj console will be able to talk to target using the IO ;; connection declared in the project state. (define (with-io expr) `((prj: ,@expr) with-io/s)) (define (prj-eval host expr) (apply values (interpret host 'prj: (with-io expr)))) (define (prj-rep target host str) (let ((expr (forth-string->syntax host str))) (update target host 'prj: (with-io expr)))) (define (prj-wordlist host) (wordlist host '((prj) (store) (state) (badnop) (base)))) ;; MACRO (define (macro-rep target host str) (update target host 'prj: `(,str rep-compile))) (define (macro-wordlist host) (wordlist host '((macro)))) ;; LIVE (define (live-rep target host str) (update target host 'prj: `(,str rep-live))) (define (live-wordlist host) (wordlist host '((macro)))) ;; LIVE/VM (define (live/vm-rep target host str) (update target host 'prj: `(,str rep-live/vm))) (define (live/vm-wordlist host) (wordlist host '((macro)))) ;; FIXME ;; MACRO/VM (define (macro/vm-rep target host str) (update target host 'prj: `(,str rep-compile/vm))) (define (macro/vm-wordlist host) (wordlist host '((macro)))) ;; FIXME )