convert to `define-inverting`
parent
8bbe358753
commit
2feaa1084d
@ -1,73 +1,49 @@
|
|||||||
#lang br
|
#lang br
|
||||||
(provide #%top-interaction #%module-begin #%datum #%top #%app)
|
(provide #%top-interaction #%module-begin (all-defined-out))
|
||||||
|
|
||||||
(provide chip-program)
|
(define-inverting #'(chip-program "CHIP" _arg ...)
|
||||||
(define #'(chip-program "CHIP" _arg ...)
|
|
||||||
#'(chip _arg ...))
|
#'(chip _arg ...))
|
||||||
|
|
||||||
(provide pin-spec)
|
(define-inverting #'(pin-spec _label _pin-list ";")
|
||||||
(define #'(pin-spec _label _pin-list ";")
|
|
||||||
#'_pin-list)
|
#'_pin-list)
|
||||||
|
|
||||||
(require (for-syntax sugar/debug))
|
(define-inverting #'(pin-list _id _comma-id ...)
|
||||||
|
#'(_id _comma-id ...))
|
||||||
|
|
||||||
|
(define-inverting #'(comma-id "," _id)
|
||||||
|
#'_id)
|
||||||
|
|
||||||
(define-for-syntax (remove-separators stx-or-list sep)
|
(define-inverting #'(part-spec "PARTS:" _part-list)
|
||||||
(for/list ([item (in-list (if (list? stx-or-list)
|
|
||||||
stx-or-list
|
|
||||||
(syntax->list stx-or-list)))]
|
|
||||||
#:when (not (equal? sep (syntax->datum item))))
|
|
||||||
item))
|
|
||||||
|
|
||||||
(provide pin-list)
|
|
||||||
(define #'(pin-list . _pin-or-commas)
|
|
||||||
(remove-separators #'_pin-or-commas ","))
|
|
||||||
|
|
||||||
(begin-for-syntax
|
|
||||||
(define (expand-macro mac)
|
|
||||||
(syntax-disarm (local-expand mac 'expression #f) #f)))
|
|
||||||
|
|
||||||
(provide part-spec)
|
|
||||||
(define #'(part-spec "PARTS:" _part-list)
|
|
||||||
#'_part-list)
|
#'_part-list)
|
||||||
|
|
||||||
(provide part-list)
|
(define-inverting #'(part-list _part ...)
|
||||||
(define #'(part-list . _part-or-semicolons)
|
#'(begin _part ...))
|
||||||
(inject-syntax ([#'(part ...) (remove-separators #'_part-or-semicolons "'")])
|
|
||||||
#'(begin part ...)))
|
|
||||||
|
|
||||||
(require (for-syntax sugar/list))
|
|
||||||
(define-for-syntax (ugly-processing stx)
|
|
||||||
(slice-at (remove-separators (remove-separators stx ",") "=") 2))
|
|
||||||
|
|
||||||
(provide part)
|
(define-inverting #'(part _partname "(" _firstpin "=" _firstval _commaidpair ... (_lastpin _pinout) ")" ";")
|
||||||
(define #'(part _partname "(" _pin-id-etc ... out "=" _pin-out ")" ";")
|
#'(begin
|
||||||
(with-syntax ([((_pin-in _val-id) ...) (ugly-processing #'(_pin-id-etc ...))])
|
(define _pinout (call-part _partname [_firstpin _firstval] _commaidpair ...))))
|
||||||
#'(begin
|
|
||||||
(define _pin-out (call-part _partname [_pin-in _val-id] ...)))))
|
|
||||||
|
|
||||||
(define #'(chip _chipname "{"
|
(define #'(comma-id-pair "," _firstid "=" _secondid)
|
||||||
_input-pins
|
#'(_firstid _secondid))
|
||||||
_output-pins
|
|
||||||
_part-spec "}")
|
|
||||||
(inject-syntax ([#'(_input-pin ...) (expand-macro #'_input-pins)]
|
|
||||||
[#'(_output-pin ...) (expand-macro #'_output-pins)]
|
|
||||||
[#'_part (expand-macro #'_part-spec)])
|
|
||||||
#'(begin
|
|
||||||
(provide _chipname)
|
|
||||||
(define _chipname
|
|
||||||
(procedure-rename
|
|
||||||
(make-keyword-procedure
|
|
||||||
(λ (kws kw-args . rest)
|
|
||||||
(define kw-pairs (map cons kws kw-args))
|
|
||||||
(let ([_input-pin (cdr (assq (string->keyword (format "~a" '_input-pin)) kw-pairs))] ...)
|
|
||||||
_part
|
|
||||||
(values _output-pin ...)))) '_chipname)))))
|
|
||||||
|
|
||||||
(provide call-part)
|
(define-inverting #'(call-part _Part [_pin-in _val-id] ...)
|
||||||
(define #'(call-part _Part [_pin-in _val-id] ...)
|
|
||||||
(with-syntax ([part-path (format "~a.hdl" (syntax->datum #'_Part))]
|
(with-syntax ([part-path (format "~a.hdl" (syntax->datum #'_Part))]
|
||||||
[(kw ...) (map (λ(pi) (string->keyword (format "~a" (syntax->datum pi)))) (syntax->list #'(_pin-in ...)))])
|
[(kw ...) (map (λ(pi) (string->keyword (format "~a" (syntax->datum pi)))) (syntax->list #'(_pin-in ...)))])
|
||||||
#'(let ()
|
#'(let ()
|
||||||
(local-require (rename-in part-path [_Part local-name]))
|
(local-require (rename-in part-path [_Part local-name]))
|
||||||
(keyword-apply local-name '(kw ...) (list _val-id ...) null))))
|
(keyword-apply local-name '(kw ...) (list _val-id ...) null))))
|
||||||
|
|
||||||
|
(define-inverting #'(chip _chipname "{"
|
||||||
|
(_input-pin ...)
|
||||||
|
(_output-pin ...)
|
||||||
|
_part-spec "}")
|
||||||
|
#'(begin
|
||||||
|
(provide _chipname)
|
||||||
|
(define _chipname
|
||||||
|
(procedure-rename
|
||||||
|
(make-keyword-procedure
|
||||||
|
(λ (kws kw-args . rest)
|
||||||
|
(define kw-pairs (map cons kws kw-args))
|
||||||
|
(let ([_input-pin (cdr (assq (string->keyword (format "~a" '_input-pin)) kw-pairs))] ...)
|
||||||
|
_part-spec
|
||||||
|
(values _output-pin ...)))) '_chipname))))
|
||||||
|
Loading…
Reference in New Issue