more
parent
cb0c24c293
commit
6a5e7a8366
@ -1,7 +1,7 @@
|
|||||||
#lang br
|
#lang br
|
||||||
|
|
||||||
(module reader br
|
(module reader br
|
||||||
(require br/reader-utils "tst/parser.rkt" "tst/tokenizer.rkt")
|
(require br/reader-utils "hdl-tst/parser.rkt" "hdl-tst/tokenizer.rkt")
|
||||||
(define-read-and-read-syntax (source-path input-port)
|
(define-read-and-read-syntax (source-path input-port)
|
||||||
#`(module hdl-mod br/demo/hdl/tst/expander
|
#`(module hdl-mod br/demo/hdl-tst/expander
|
||||||
#,(parse source-path (tokenize input-port)))))
|
#,(parse source-path (tokenize input-port)))))
|
@ -0,0 +1,19 @@
|
|||||||
|
#lang racket
|
||||||
|
|
||||||
|
|
||||||
|
(define (hdlprint val fmt)
|
||||||
|
(match-define (list _ radix-letter number-strings) (regexp-match #px"^%(.)(.*)$" fmt)) ; like %B1.16.1
|
||||||
|
(match-define (list left-margin width right-margin) (map string->number (string-split number-strings ".")))
|
||||||
|
(define radix (case radix-letter
|
||||||
|
[("B") 2]))
|
||||||
|
(string-append (make-string left-margin #\space)
|
||||||
|
(if (number? val)
|
||||||
|
(~r val #:min-width width #:pad-string "0" #:base radix)
|
||||||
|
(~a val #:min-width width #:pad-string " " #:align 'center))
|
||||||
|
(make-string right-margin #\space)))
|
||||||
|
|
||||||
|
(module+ test
|
||||||
|
(require rackunit)
|
||||||
|
(define a 123)
|
||||||
|
(check-equal? (hdlprint a "%B1.16.1") " 0000000001111011 ")
|
||||||
|
(check-equal? (hdlprint "out" "%B1.16.1") " out "))
|
Loading…
Reference in New Issue