|
|
|
@ -18,34 +18,34 @@
|
|
|
|
|
(run line-table))))
|
|
|
|
|
(provide (rename-out [b-module-begin #%module-begin]))
|
|
|
|
|
|
|
|
|
|
(struct $program-end-signal ())
|
|
|
|
|
(define (b-end) (raise ($program-end-signal)))
|
|
|
|
|
(struct end-program-signal ())
|
|
|
|
|
(struct change-line-signal (val))
|
|
|
|
|
|
|
|
|
|
(struct $change-line-signal (val))
|
|
|
|
|
(define (b-goto expr) (raise ($change-line-signal expr)))
|
|
|
|
|
(define (b-end) (raise (end-program-signal)))
|
|
|
|
|
(define (b-goto num-expr) (raise (change-line-signal num-expr)))
|
|
|
|
|
|
|
|
|
|
(define (run line-table)
|
|
|
|
|
(define line-vec
|
|
|
|
|
(list->vector (sort (hash-keys line-table) <)))
|
|
|
|
|
(with-handlers ([$program-end-signal? void])
|
|
|
|
|
(with-handlers ([end-program-signal? (λ (exn-val) (void))])
|
|
|
|
|
(for/fold ([line-idx 0])
|
|
|
|
|
([i (in-naturals)])
|
|
|
|
|
(unless (< line-idx (vector-length line-vec)) (b-end))
|
|
|
|
|
([i (in-naturals)]
|
|
|
|
|
#:break (>= line-idx (vector-length line-vec)))
|
|
|
|
|
(define line-num (vector-ref line-vec line-idx))
|
|
|
|
|
(define line-proc (hash-ref line-table line-num))
|
|
|
|
|
(define line-func (hash-ref line-table line-num))
|
|
|
|
|
(with-handlers
|
|
|
|
|
([$change-line-signal?
|
|
|
|
|
([change-line-signal?
|
|
|
|
|
(λ (cls)
|
|
|
|
|
(define clsv ($change-line-signal-val cls))
|
|
|
|
|
(define clsv (change-line-signal-val cls))
|
|
|
|
|
(or
|
|
|
|
|
(and (exact-positive-integer? clsv)
|
|
|
|
|
(vector-member clsv line-vec))
|
|
|
|
|
(error (format "error in line ~a: line ~a not found"
|
|
|
|
|
line-num clsv))))])
|
|
|
|
|
(line-proc)
|
|
|
|
|
(line-func)
|
|
|
|
|
(add1 line-idx)))))
|
|
|
|
|
|
|
|
|
|
(define b-rem void)
|
|
|
|
|
(define (b-rem val) (void))
|
|
|
|
|
(define (b-print [val ""]) (displayln val))
|
|
|
|
|
(define (b-sum . nums) (apply + nums))
|
|
|
|
|
(define (b-num-expr expr)
|
|
|
|
|