#lang scheme/base

;; An attempt to find a standard mechanism for parameterizable
;; modules.  This consists of:

;;  * Find a way to build instantiated code from scheme.  Currently it
;;    only uses macros.

;;  * Create instantiation macros for parameterizable code.

;;  * Possibly write the Forth instantiation on top of this Scheme
;;    code.  Somehow unify ``data parameterization'' usable from
;;    macros with ``name parameterization'' usable from prefix macros.

;;  * Should this use higher order macros or just Forth control words?


;; The example is parameterized code for a synchronous read operation.

(define-syntax-rule (sync-reader clock data read write)
  (begin
    (compositions
     (macro) macro:

     (wait   clock low? if
               begin clock high? until
             then
             begin clock low? until)

     (read   0 (wait data @ 1 and or <<)  8 times)
     (write    (wait dup 1 and data ! >>) 8 times drop)

    (instantiate
        read write)))

;; This creates two instantiated words parameterized by two macros.
;; The 'clock and 'data arguments could possibly be passed as macro
;; arguments, but the 'read and 'write NAMES are identifiers; the
;; macro language doesn't know identifiers.

     
                  




;; Original Forth syntax:

;; \ Instantiate 'read and 'write procedures for slave mode synchronous
;; \ communication.

;; macro
;; : wait-falling | reg bit |
;;     reg bit low? if begin reg bit high? until then
;;     begin reg bit low? until ;
;; forth

;; : read 8 for clock wait-falling ... next
