[<<][staapl][>>][..]
Wed Nov 9 15:08:55 EST 2011

Wow

I'm loosing it..  going too creative with inventing new syntax...
What I want to do is:

- make `make-target-label' available to Scheme code to make it easier
  to construct control flow abstractions in Scheme using lexical
  scope, instead of using m stack juggling.

- make some syntax for local binding of the compiler state variable to
  make extended compiler state available as lexical bindings.  The
  reason is that the following is too verbose:

  (compositions (macro) macro:
   (word ,(lambda (state)
            ((macro:  ......) state))))

- singleton coroutine or multiple instances?  (where to bind state var?)



;; The SCR state is accessible through a compiler state extension tag.
(define scr-tag (state-tag-label 'scr))

;; STATE REP
(define-struct scr-context (var yield))
(define-struct scr (ctx labels))

;; ACCESSORS
(define (ref s)     (state-tag-ref s scr-tag))
(define (ctx s)     (scr-ctx tag (ref s)))
(define (yield s)   (scr-context-yield (ctx s)))
(define (var s)     (scr-context-var (ctx s)))
(define (labels s)  (scr-labels (ref s)))
(define (next-id s) (length (labels s)))

;; MUTATORS, all curried to produce state transformers.

;; Add label to SCR jump table state.
(define (set v)
  (state-tag-set scr-tag v))
(define (update label)
  (lambda (s)
    (match (scr-ref s)
           ((struct scr (ctx labels))
            ((set (make-scr ctx (cons label labels))) s)))))

(define (init-state var)
  (set (make-scr (make-scr-context var (make-target-label)) '())))

;; Convenience: bring state in lexical context of macro, and apply
;; macro to state.
(define-syntax-rule (let/state state macro)
  (lambda (state) (macro state)))

;; Bound to macro: This has a semicolon as ad-hoc separator to
;; indicate that state is a binder.
(define-syntax macs
  (syntax-rules (:)
    ((_ state : . words)
     (let/s state (macro: . words)))))



[Reply][About]
[<<][staapl][>>][..]