Tue Apr 29 14:35:02 EDT 2008

structure types and inheritance

now i feel stupid

delimited control isn't necessary at all here.. simple inheritance
will do the trick just fine.

one thing i didn't get though is: inheritance works nice for read, but
what's needed is to construct the right output type, so the update
function needs to be abstracted somewhere..

-> all derived structs now have an 'update' function in the first
   field, and a direct constructor as in:

(define update-compilation-state
    ((state ctrl)
     (update-compilation-state state ctrl
                               (2stack-asm-list state)))
    ((state ctrl asm)
     (update-compilation-state state ctrl asm
                               (compilation-state-current state)
                               (compilation-state-words state)))
    ((state ctrl asm current words)
     (driver-make-compilation-state ctrl asm current words))))

(define (driver-make-compilation-state ctrl asm current words)
  (make-compilation-state update-compilation-state
                          ctrl asm current words))

ok.. done feeling stupid. works, and is a lot easier to understand.

this can be implemented more efficiently using lists: less copying,
more sharing. not important atm.

this abstraction makes it a bit easier to use:

;; state matcher which introduces 'update'
(define-syntax (state-lambda stx)
  (syntax-case stx ()
    ((_ type (var ...) . expr)
     #`(lambda (state)
         (match state
                ((struct type (update var ...))
                 (let ((#,(datum->syntax #'type 'update)
                        (lambda args
                          (apply update state args))))
                   . expr)))))))

maybe use syntax parameters instead of introducing a symbol?