dev-srcloc
Matthew Butterick 8 years ago
parent ea28427d86
commit f021c09f25

@ -24,18 +24,12 @@
num-or-wire num-or-wire
(hash-ref! wire-cache num-or-wire num-or-wire))))) (hash-ref! wire-cache num-or-wire num-or-wire)))))
(define (mod-16bit x) (define 16bit-max (expt 2 16))
(define max-16bit (expt 2 16))
(define remainder (modulo x max-16bit))
(if (not (negative? remainder))
remainder
(mod-16bit (+ max-16bit remainder))))
(define-macro (define-16bit ID+ARGS BODY) (define-macro (define-16bit ID+ARGS BODY)
#'(define ID+ARGS (mod-16bit BODY))) #'(define ID+ARGS (modulo BODY 16bit-max)))
(define-16bit (AND arg1 arg2) (bitwise-and arg1 arg2)) (define-16bit (AND x y) (bitwise-and x y))
(define-16bit (OR arg1 arg2) (bitwise-ior arg1 arg2)) (define-16bit (OR x y) (bitwise-ior x y))
(define-16bit (LSHIFT arg1 arg2) (arithmetic-shift arg1 arg2)) (define-16bit (LSHIFT x y) (arithmetic-shift x y))
(define-16bit (RSHIFT arg1 arg2) (arithmetic-shift arg1 (- arg2))) (define-16bit (RSHIFT x y) (LSHIFT x (- y)))
(define-16bit (NOT arg) (bitwise-not arg)) (define-16bit (NOT arg) (bitwise-not arg))

@ -3,8 +3,9 @@
(provide read-syntax)) (provide read-syntax))
(define (read-syntax path port) (define (read-syntax path port)
(define wire-strs (port->lines port)) (define wire-datums
(define wire-datums (format-datums '(wire ~a) wire-strs)) (for/list ([wire-str (in-lines port)])
(format-datum '(wire ~a) wire-str)))
(strip-context (strip-context
#`(module wires-mod br/demo/wires/expander #`(module wires-mod br/demo/wires/expander
#,@wire-datums))) #,@wire-datums)))
Loading…
Cancel
Save