modularize run

pull/10/head
Matthew Butterick 8 years ago
parent 26dd72cb7a
commit 1f770220b7

@ -1,6 +1,5 @@
#lang br/quicklang
(require "struct.rkt"
"elements.rkt")
(require "struct.rkt" "run.rkt" "elements.rkt")
(provide (rename-out [b-module-begin #%module-begin])
(all-from-out "elements.rkt"))
@ -25,24 +24,3 @@
var-stx)
#:key syntax->datum)))
(define (run line-table)
(define line-vec
(list->vector (sort (hash-keys line-table) <)))
(with-handlers ([end-program-signal? (λ (exn-val) (void))])
(for/fold ([line-idx 0])
([i (in-naturals)]
#:break (>= line-idx (vector-length line-vec)))
(define line-num (vector-ref line-vec line-idx))
(define line-func (hash-ref line-table line-num))
(with-handlers
([change-line-signal?
(λ (cls)
(define clsv (change-line-signal-val cls))
(or
(and (exact-positive-integer? clsv)
(vector-member clsv line-vec))
(line-func #:error (format "line ~a not found" clsv))))])
(line-func)
(add1 line-idx)))))

@ -20,4 +20,4 @@
(vector-member clsv line-vec))
(line-func #:error (format "line ~a not found" clsv))))])
(line-func)
(add1 line-idx)))))
(add1 line-idx)))))

@ -1,5 +1,5 @@
#lang br/quicklang
(require "struct.rkt" "elements.rkt")
(require "struct.rkt" "run.rkt" "elements.rkt")
(provide (rename-out [b-module-begin #%module-begin])
(all-from-out "elements.rkt"))
@ -13,25 +13,4 @@
(apply hasheqv (append (list NUM LINE-FUNC) ...)))
(void (run line-table)))))
(define (run line-table)
(define line-vec
(list->vector (sort (hash-keys line-table) <)))
(with-handlers ([end-program-signal? (λ (exn-val) (void))])
(for/fold ([line-idx 0])
([i (in-naturals)]
#:break (>= line-idx (vector-length line-vec)))
(define line-num (vector-ref line-vec line-idx))
(define line-func (hash-ref line-table line-num))
(with-handlers
([change-line-signal?
(λ (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-func)
(add1 line-idx)))))

@ -0,0 +1,24 @@
#lang br
(require "line.rkt" "struct.rkt")
(provide run)
(define (run line-table)
(define line-vec
(list->vector (sort (hash-keys line-table) <)))
(with-handlers ([end-program-signal? (λ (exn-val) (void))])
(for/fold ([line-idx 0])
([i (in-naturals)]
#:break (>= line-idx (vector-length line-vec)))
(define line-num (vector-ref line-vec line-idx))
(define line-func (hash-ref line-table line-num))
(with-handlers
([change-line-signal?
(λ (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-func)
(add1 line-idx)))))
Loading…
Cancel
Save