;; -*- scheme -*-
;; load this file with load/cd

(define *staapl-dir* (current-directory))

(define (init-staapl [code '(begin)])
  (parameterize
      ((current-directory *staapl-dir*)
       (current-load-relative-directory *staapl-dir*))
    (printf "toplevel in ~a\n" *staapl-dir*)
    (box-toplevel code)))

;; Generic purrr language (compiles to cw,qw)
(define (purrr)  (init-staapl '(require "purrr.ss")))
(define (purrr18) (init-staapl '(require "pic18.ss")))

(define (p18)
  (purrr18)
  (box-eval '(begin
               (forth-load/compile "pic18/monitor-p18f1220.f")
               (save-ihex "/tmp/test.hex")
               ;; (piklab-prog "/tmp/test.hex")
               ;; (print-all-code)
               )))

;; REPLS

(define ((not-implemented tag) . args)
  (error 'not-implemented "~a ~a" tag args))

(register-language
 'compile "compile> "
 (not-implemented 'compile-eval)
 (lambda (str) (box-eval `(forth-compile ,str)))
 #f)

(register-language
 'command "command> "
 (not-implemented 'command-eval)
 (lambda (str) (box-eval `(forth-command ,str)))
 #f)



;; PIC18 purrr language + namespace management.
;; (define (badnop) (init-staapl '(require "badnop.ss")))

(init-staapl)
