pic18/demo.ss
#lang scheme/base
(require "../tools.ss")
(require/provide "../pic18.ss")
(provide (all-defined-out))
;; PIC18 compiler demo.


(target-print-word-bytes 2) 
(target-print-address-bits 16)

;; Code generator demonstration used in the documentation.
(define (optimize-state optimizer state)
  (macro-list->state
   (for/list ((macro (state->macro-list state)))
     (macro: ,macro ,optimizer))
   state:stack))

(define (optimize state . optimizers)
  (foldl optimize-state state optimizers))

(define-syntax-rule (code> . code)
  (state-print-code
   ((macro: . code) (state:stack))))

(define-syntax-rule (pic18> . code)
  (state-print-code
   (optimize ((macro: . code) (state:stack))
             (macro: pseudo)
             (macro: opti-save))))



;; Full forth demonstration
(define-syntax-rule (forth> str)
  (begin
    (forth-compile str)
    (code-print)
    (code-clear!)))