|
|
@ -104,28 +104,30 @@ base bus:
|
|
|
|
(define-values (bus bus? bus-get)
|
|
|
|
(define-values (bus bus? bus-get)
|
|
|
|
(make-impersonator-property 'bus))
|
|
|
|
(make-impersonator-property 'bus))
|
|
|
|
|
|
|
|
|
|
|
|
(define-cases #'define-base-bus
|
|
|
|
(define-macro-cases define-base-bus
|
|
|
|
[#'(_macro-name _id _thunk) #'(_macro-name _id _thunk default-bus-width)]
|
|
|
|
[#'(_macro-name ID THUNK) #'(_macro-name ID THUNK default-bus-width)]
|
|
|
|
[#'(_macro-name _id _thunk _bus-width-in)
|
|
|
|
[#'(_macro-name ID THUNK _bus-width-in)
|
|
|
|
(inject-syntax ([#'_id-thunk (suffix-id #'_id "-val")]
|
|
|
|
(with-pattern
|
|
|
|
[#'_bus-type (or (syntax-property caller-stx 'impersonate) #'bus)])
|
|
|
|
([_id-thunk (suffix-id #'ID "-val")]
|
|
|
|
#`(splicing-let ([_id-thunk _thunk]
|
|
|
|
[_bus-type (or (syntax-property caller-stx 'impersonate) #'bus)])
|
|
|
|
[bus-width _bus-width-in])
|
|
|
|
#`(splicing-let ([_id-thunk THUNK]
|
|
|
|
(define _id
|
|
|
|
[bus-width _bus-width-in])
|
|
|
|
(begin
|
|
|
|
(define ID
|
|
|
|
(unless (<= bus-width max-bus-width)
|
|
|
|
(begin
|
|
|
|
(raise-argument-error 'id (format "bus width <= max width ~a" max-bus-width) bus-width))
|
|
|
|
(unless (<= bus-width max-bus-width)
|
|
|
|
(impersonate-procedure
|
|
|
|
(raise-argument-error 'id (format "bus width <= max width ~a" max-bus-width) bus-width))
|
|
|
|
(let ([reader (make-bus-reader 'id bus-width)])
|
|
|
|
(impersonate-procedure
|
|
|
|
(procedure-rename (λ args (apply reader (_id-thunk) args)) (string->symbol (format "~a, a bus of width ~a" '_id bus-width))))
|
|
|
|
(let ([reader (make-bus-reader 'id bus-width)])
|
|
|
|
#f _bus-type #t)))
|
|
|
|
(procedure-rename (λ args (apply reader (_id-thunk) args)) (string->symbol (format "~a, a bus of width ~a" 'ID bus-width))))
|
|
|
|
#,(when (syntax-property caller-stx 'writer)
|
|
|
|
#f _bus-type #t)))
|
|
|
|
(inject-syntax ([#'_id-write (suffix-id #'_id "-write")])
|
|
|
|
#,(when (syntax-property caller-stx 'writer)
|
|
|
|
#'(define _id-write
|
|
|
|
(with-pattern
|
|
|
|
(let ([writer (make-bus-writer 'id-write bus-width)])
|
|
|
|
([_id-write (suffix-id #'ID "-write")])
|
|
|
|
(λ args
|
|
|
|
#'(define _id-write
|
|
|
|
(define result (apply writer (_id-thunk) args))
|
|
|
|
(let ([writer (make-bus-writer 'id-write bus-width)])
|
|
|
|
(set! _id-thunk (λ () result)))))))))])
|
|
|
|
(λ args
|
|
|
|
|
|
|
|
(define result (apply writer (_id-thunk) args))
|
|
|
|
|
|
|
|
(set! _id-thunk (λ () result)))))))))])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(module+ test
|
|
|
|
(module+ test
|
|
|
@ -157,7 +159,7 @@ output bus:
|
|
|
|
(define-values (output-bus output-bus? output-bus-get)
|
|
|
|
(define-values (output-bus output-bus? output-bus-get)
|
|
|
|
(make-impersonator-property 'output-bus))
|
|
|
|
(make-impersonator-property 'output-bus))
|
|
|
|
|
|
|
|
|
|
|
|
(define #'(define-output-bus . _args)
|
|
|
|
(define-macro (define-output-bus . _args)
|
|
|
|
(syntax-property #'(define-base-bus . _args) 'impersonate #'output-bus))
|
|
|
|
(syntax-property #'(define-base-bus . _args) 'impersonate #'output-bus))
|
|
|
|
|
|
|
|
|
|
|
|
(module+ test
|
|
|
|
(module+ test
|
|
|
@ -189,7 +191,7 @@ input bus:
|
|
|
|
(define-values (input-bus input-bus? input-bus-get)
|
|
|
|
(define-values (input-bus input-bus? input-bus-get)
|
|
|
|
(make-impersonator-property 'input-bus))
|
|
|
|
(make-impersonator-property 'input-bus))
|
|
|
|
|
|
|
|
|
|
|
|
(define-cases #'define-input-bus
|
|
|
|
(define-macro-cases define-input-bus
|
|
|
|
[#'(_macro-name _id)
|
|
|
|
[#'(_macro-name _id)
|
|
|
|
#'(_macro-name _id default-bus-width)]
|
|
|
|
#'(_macro-name _id default-bus-width)]
|
|
|
|
[#'(_macro-name _id _bus-width)
|
|
|
|
[#'(_macro-name _id _bus-width)
|
|
|
|