(define (parse-instruction form forms early? environment)
(assert (not early?))
(receive (expansion bits) (process* form forms environment)
- bits
+ (assert (or (not bits) (zero? (remainder bits 32))) bits (cons form forms))
expansion))
(define (process* form forms environment)
(let recur ((form form) (forms forms))
(receive (expansion bits) (process form environment)
+ (assert (or (not bits) (zero? (remainder bits 32)) bits form))
(if (pair? forms)
(receive (tail bits*) (recur (car forms) (cdr forms))
+ (assert (or (not bits*) (zero? (remainder bits* 32))) bits* forms)
(values `(,(close-syntax 'APPEND environment) ,expansion ,tail)
- (+ bits bits*)))
+ (and bits bits* (+ bits bits*))))
(values expansion bits)))))
(define (process form environment)
(consequent (caddr form))
(alternative (cadddr form)))
(receive (con-exp con-bits) (process consequent environment)
+ (assert con-bits consequent)
+ (assert (zero? (remainder con-bits 32)) con-bits consequent)
(receive (alt-exp alt-bits) (process alternative environment)
- (assert (eqv? con-bits alt-bits))
+ (assert (eqv? con-bits alt-bits) con-bits alt-bits alternative)
(values `(,(close-syntax 'IF environment) ,condition ,con-exp ,alt-exp)
con-bits)))))
(define (process-fixed form environment)
(receive (expansion bits) (expand-fields (cdr form) environment)
+ (assert (zero? (remainder bits 32)) bits form)
(values `(,(close-syntax 'LIST environment)
,(optimize-group-syntax expansion #f environment))
bits)))
(hi (cadr range)))
(receive (expansion bits) (process* (car forms) (cdr forms) environment)
(assert bits "Variable within variable prohibited!")
- (assert (zero? (remainder bits 32)) "Wrong number of bits!")
+ (assert (zero? (remainder bits 32)) bits forms)
`(,expansion ,bits ,lo ,hi)))))
(define (process-macro form environment)
,expansion)))
width)))
-(define (expand-fields fields environment)
- (let loop ((fields fields) (elements '()) (bits 0))
+(define (expand-fields all-fields environment)
+ (let loop ((fields all-fields) (elements '()) (bits 0))
(if (pair? fields)
(receive (element1 bits1) (expand-field (car fields) environment)
(loop (cdr fields) (cons element1 elements) (+ bits1 bits)))
- (values (reverse! elements) bits))))
+ (begin
+ (assert (zero? (remainder bits 32)) bits all-fields)
+ (values elements bits)))))
(define (expand-field field environment)
(let ((bits (car field))