#lang scheme/base
(define-syntax-rule (delegated-macros: name ...)
(begin
(provide name ...)
(define-syntax-rule (name . args)
(prj-eval '(name . args))) ...))
(define-syntax-rule (delegated-functions: name ...)
(begin
(provide name ...)
(define (name . args)
(prj-eval `(apply name ',args))) ...))
(define-syntax-rule (delegated-toplevel: name ...)
(begin
(provide name ...)
(define (name arg)
(prj-eval `(name ,arg))) ...))
(provide
make-prj-namespace current-prj prj-require prj-eval prj
forth-debug
make-prj
init-prj)
(delegated-toplevel:
forth-compile forth-load/compile forth-command
)
(delegated-functions:
tfind
prog
current-console
print-code save-ihex save-dict )
(delegated-macros:
live-scat> target>
)
(define make-prj (make-parameter (lambda () (error 'no-prj-registered))))
(define (init-prj)
(current-prj ((make-prj))))
(define (shared/initial-namespace src-ns shared private)
(let ((dst-ns (make-base-namespace)))
(define (load-shared mod)
(parameterize ((current-namespace src-ns)) (dynamic-require mod #f)
(namespace-require mod))
(namespace-attach-module src-ns mod dst-ns) (parameterize ((current-namespace dst-ns)) (namespace-require mod))
)
(define (load-private mod)
(parameterize ((current-namespace dst-ns))
(dynamic-require mod #f)
(namespace-require mod)))
(for-each load-shared shared)
(for-each load-private private)
dst-ns))
(define (make-prj-namespace [initial '()]
[src (current-namespace)])
(shared/initial-namespace
src
'(staapl/tools
staapl/scat/rep
staapl/target/rep)
`(staapl/target/incremental
,@initial)))
(define current-prj (make-parameter #f))
(define (prj-eval expr)
(parameterize
((current-namespace (current-prj)))
(eval expr)))
(define (prj-require spec)
(parameterize ((current-namespace (current-prj)))
(namespace-require spec)))
(define-syntax-rule (prj forms ...)
(prj-eval '(begin forms ...)))
(define (forth-debug str)
(prj-eval
`(begin
(asm-off!)
(forth-compile ,str)
(asm-on!))))