From 6a5e7a8366b2d3b1e9b9c93553be06adfc56dea3 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Sat, 30 Apr 2016 22:10:43 -0400 Subject: [PATCH] more --- .../br/demo/{hdl/tst.rkt => hdl-tst.rkt} | 4 ++-- .../br/demo/{hdl/tst => hdl-tst}/expander.rkt | 2 +- beautiful-racket/br/demo/hdl-tst/hdlprint.rkt | 19 +++++++++++++++++++ .../br/demo/{hdl/tst => hdl-tst}/parser.rkt | 0 .../demo/{hdl/tst => hdl-tst}/tokenizer.rkt | 0 .../br/demo/hdl/{And.hdl => And.hdl.rkt} | 0 beautiful-racket/br/demo/hdl/And.tst | 2 +- 7 files changed, 23 insertions(+), 4 deletions(-) rename beautiful-racket/br/demo/{hdl/tst.rkt => hdl-tst.rkt} (53%) rename beautiful-racket/br/demo/{hdl/tst => hdl-tst}/expander.rkt (94%) create mode 100644 beautiful-racket/br/demo/hdl-tst/hdlprint.rkt rename beautiful-racket/br/demo/{hdl/tst => hdl-tst}/parser.rkt (100%) rename beautiful-racket/br/demo/{hdl/tst => hdl-tst}/tokenizer.rkt (100%) rename beautiful-racket/br/demo/hdl/{And.hdl => And.hdl.rkt} (100%) diff --git a/beautiful-racket/br/demo/hdl/tst.rkt b/beautiful-racket/br/demo/hdl-tst.rkt similarity index 53% rename from beautiful-racket/br/demo/hdl/tst.rkt rename to beautiful-racket/br/demo/hdl-tst.rkt index 3afdaf3..eeca7a3 100644 --- a/beautiful-racket/br/demo/hdl/tst.rkt +++ b/beautiful-racket/br/demo/hdl-tst.rkt @@ -1,7 +1,7 @@ #lang 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) - #`(module hdl-mod br/demo/hdl/tst/expander + #`(module hdl-mod br/demo/hdl-tst/expander #,(parse source-path (tokenize input-port))))) diff --git a/beautiful-racket/br/demo/hdl/tst/expander.rkt b/beautiful-racket/br/demo/hdl-tst/expander.rkt similarity index 94% rename from beautiful-racket/br/demo/hdl/tst/expander.rkt rename to beautiful-racket/br/demo/hdl-tst/expander.rkt index 17e189d..3639879 100644 --- a/beautiful-racket/br/demo/hdl/tst/expander.rkt +++ b/beautiful-racket/br/demo/hdl-tst/expander.rkt @@ -19,7 +19,7 @@ [#'output (shared-syntax 'output)]) #'(begin (provide (all-defined-out)) - (define shared-procname (dynamic-require _filename-string 'shared-procname)) + (define shared-procname (dynamic-require (findf file-exists? (list _filename-string (format "~a.rkt" _filename-string))) 'shared-procname)) (display-header '_colid ... '_outid) (define _colid (make-parameter 0)) ... (define (_outid) diff --git a/beautiful-racket/br/demo/hdl-tst/hdlprint.rkt b/beautiful-racket/br/demo/hdl-tst/hdlprint.rkt new file mode 100644 index 0000000..cf1c527 --- /dev/null +++ b/beautiful-racket/br/demo/hdl-tst/hdlprint.rkt @@ -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 ")) diff --git a/beautiful-racket/br/demo/hdl/tst/parser.rkt b/beautiful-racket/br/demo/hdl-tst/parser.rkt similarity index 100% rename from beautiful-racket/br/demo/hdl/tst/parser.rkt rename to beautiful-racket/br/demo/hdl-tst/parser.rkt diff --git a/beautiful-racket/br/demo/hdl/tst/tokenizer.rkt b/beautiful-racket/br/demo/hdl-tst/tokenizer.rkt similarity index 100% rename from beautiful-racket/br/demo/hdl/tst/tokenizer.rkt rename to beautiful-racket/br/demo/hdl-tst/tokenizer.rkt diff --git a/beautiful-racket/br/demo/hdl/And.hdl b/beautiful-racket/br/demo/hdl/And.hdl.rkt similarity index 100% rename from beautiful-racket/br/demo/hdl/And.hdl rename to beautiful-racket/br/demo/hdl/And.hdl.rkt diff --git a/beautiful-racket/br/demo/hdl/And.tst b/beautiful-racket/br/demo/hdl/And.tst index 9e35d74..0eed34b 100644 --- a/beautiful-racket/br/demo/hdl/And.tst +++ b/beautiful-racket/br/demo/hdl/And.tst @@ -1,4 +1,4 @@ -#lang br/demo/hdl/tst +#lang br/demo/hdl-tst /* and */