diff --git a/beautiful-racket/br/demo/hdl/Nand.hdl.rkt b/beautiful-racket/br/demo/hdl/Nand.hdl.rkt index ce89334..c777a99 100644 --- a/beautiful-racket/br/demo/hdl/Nand.hdl.rkt +++ b/beautiful-racket/br/demo/hdl/Nand.hdl.rkt @@ -1,6 +1,6 @@ #lang br (provide (prefix-out Nand- (all-defined-out))) -(require "helper.rkt") +(require "bus.rkt") (define-input-bus a) (define-input-bus b) diff --git a/beautiful-racket/br/demo/hdl/bus-properties.rkt b/beautiful-racket/br/demo/hdl/bus-properties.rkt new file mode 100644 index 0000000..e322198 --- /dev/null +++ b/beautiful-racket/br/demo/hdl/bus-properties.rkt @@ -0,0 +1,11 @@ +#lang br +(provide (all-defined-out)) + +(define-values (bus bus? bus-get) + (make-impersonator-property 'bus)) + +(define-values (output-bus output-bus? output-bus-get) + (make-impersonator-property 'output-bus)) + +(define-values (input-bus input-bus? input-bus-get) + (make-impersonator-property 'input-bus)) \ No newline at end of file diff --git a/beautiful-racket/br/demo/hdl/helper.rkt b/beautiful-racket/br/demo/hdl/bus.rkt similarity index 96% rename from beautiful-racket/br/demo/hdl/helper.rkt rename to beautiful-racket/br/demo/hdl/bus.rkt index 152d0e0..2882ee8 100644 --- a/beautiful-racket/br/demo/hdl/helper.rkt +++ b/beautiful-racket/br/demo/hdl/bus.rkt @@ -1,5 +1,5 @@ #lang br -(require racket/list (for-syntax br/syntax) racket/splicing) +(require racket/list (for-syntax br/syntax) racket/splicing "bus-properties.rkt") (provide (all-defined-out)) (module+ test @@ -101,8 +101,6 @@ base bus: |# -(define-values (bus bus? bus-get) - (make-impersonator-property 'bus)) (define-macro-cases define-base-bus [#'(_macro-name ID THUNK) #'(_macro-name ID THUNK default-bus-width)] @@ -156,8 +154,8 @@ output bus: + cannot write |# -(define-values (output-bus output-bus? output-bus-get) - (make-impersonator-property 'output-bus)) + + (define-macro (define-output-bus . _args) (syntax-property #'(define-base-bus . _args) 'impersonate #'output-bus)) @@ -188,8 +186,6 @@ input bus: + can write all, or bits |# -(define-values (input-bus input-bus? input-bus-get) - (make-impersonator-property 'input-bus)) (define-macro-cases define-input-bus [#'(_macro-name _id) diff --git a/beautiful-racket/br/demo/hdl/expander.rkt b/beautiful-racket/br/demo/hdl/expander.rkt index 9f2bbed..f8edb24 100644 --- a/beautiful-racket/br/demo/hdl/expander.rkt +++ b/beautiful-racket/br/demo/hdl/expander.rkt @@ -1,5 +1,5 @@ #lang br -(require "helper.rkt" (for-syntax racket/syntax racket/require-transform br/syntax "helper.rkt")) +(require "bus.rkt" (for-syntax racket/syntax racket/require-transform br/syntax "bus-properties.rkt")) (provide #%top-interaction #%module-begin #%app #%datum (all-defined-out)) (define-macro (chip-program CHIPNAME @@ -21,13 +21,13 @@ (define-macro (part PARTNAME ((BUS-LEFT . BUS-LEFT-ARGS) BUS-RIGHT-EXPR) ...) (with-pattern ([(PARTNAME-BUS-LEFT ...) (prefix-id #'PARTNAME "-" #'(BUS-LEFT ...))] - [CHIP-MODULE-PATH (format-string "~a.hdl.rkt" #'PARTNAME)]) + [PARTNAME-MODULE-PATH (format-string "~a.hdl.rkt" #'PARTNAME)]) #'(begin - (require (import-chip CHIP-MODULE-PATH) + (require (import-chip PARTNAME-MODULE-PATH) ;; need for-syntax to make phase 1 binding available ;; so we can determine during expansion which buses are `input-bus?` ;; because the pin-spec syntax is inherently ambiguous - (for-syntax (import-chip CHIP-MODULE-PATH))) + (for-syntax (import-chip PARTNAME-MODULE-PATH))) (handle-buses ((PARTNAME-BUS-LEFT . BUS-LEFT-ARGS) BUS-RIGHT-EXPR) ...)))) @@ -46,7 +46,7 @@ [((PREFIXED-WIRE . _) _) ;; we "pre-evaluate" #'PREFIXED-WIRE so we can set up the program correctly. ;; This is not ideal: usually we want evaluate runtime expressions only at runtime. - ;; But in this case, it controls which identifiers we `define` + ;; But in this case, it controls which identifiers we `define` as output buses ;; so there's no way around it. Runtime would be too late. (input-bus? (syntax-local-eval #'PREFIXED-WIRE))])]) (with-pattern