pull/10/head
Matthew Butterick 8 years ago
parent c43a486f9d
commit 42d14dec74

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

@ -0,0 +1,4 @@
#lang info
(define compile-omit-paths 'all)
(define test-omit-paths 'all)
Loading…
Cancel
Save