From e631c39bf2885cf8a7a0213d7e025cc21e0e8885 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Mon, 16 May 2016 16:47:38 -0700 Subject: [PATCH] renames --- beautiful-racket/br/demo/hdl-tst/expander.rkt | 39 ++++++++++--------- .../br/demo/hdl/{And.tst => And.tst.rkt} | 0 .../br/demo/hdl/{DMux.hdl => DMux.hdl.rkt} | 0 beautiful-racket/br/demo/hdl/Dmux.tst.rkt | 2 +- beautiful-racket/br/demo/hdl/Nand.hdl | 13 ------- beautiful-racket/br/demo/hdl/Nand.hdl.rkt | 28 +++++++++++++ .../br/demo/hdl/{Nand.tst => Nand.tst.rkt} | 2 +- .../br/demo/hdl/{Not.hdl => Not.hdl.rkt} | 0 .../br/demo/hdl/{Not.tst => Not.tst.rkt} | 2 +- .../br/demo/hdl/{Or.hdl => Or.hdl.rkt} | 0 .../br/demo/hdl/{Or.tst => Or.tst.rkt} | 2 +- beautiful-racket/br/demo/hdl/Toffoli.hdl.rkt | 13 +++++++ .../br/demo/hdl/{Xor.hdl => Xor.hdl.rkt} | 0 .../br/demo/hdl/{Xor.tst => Xor.tst.rkt} | 2 +- 14 files changed, 67 insertions(+), 36 deletions(-) rename beautiful-racket/br/demo/hdl/{And.tst => And.tst.rkt} (100%) rename beautiful-racket/br/demo/hdl/{DMux.hdl => DMux.hdl.rkt} (100%) delete mode 100644 beautiful-racket/br/demo/hdl/Nand.hdl create mode 100644 beautiful-racket/br/demo/hdl/Nand.hdl.rkt rename beautiful-racket/br/demo/hdl/{Nand.tst => Nand.tst.rkt} (89%) rename beautiful-racket/br/demo/hdl/{Not.hdl => Not.hdl.rkt} (100%) rename beautiful-racket/br/demo/hdl/{Not.tst => Not.tst.rkt} (69%) rename beautiful-racket/br/demo/hdl/{Or.hdl => Or.hdl.rkt} (100%) rename beautiful-racket/br/demo/hdl/{Or.tst => Or.tst.rkt} (88%) create mode 100644 beautiful-racket/br/demo/hdl/Toffoli.hdl.rkt rename beautiful-racket/br/demo/hdl/{Xor.hdl => Xor.hdl.rkt} (100%) rename beautiful-racket/br/demo/hdl/{Xor.tst => Xor.tst.rkt} (88%) diff --git a/beautiful-racket/br/demo/hdl-tst/expander.rkt b/beautiful-racket/br/demo/hdl-tst/expander.rkt index 49b0998..b6cc053 100644 --- a/beautiful-racket/br/demo/hdl-tst/expander.rkt +++ b/beautiful-racket/br/demo/hdl-tst/expander.rkt @@ -1,4 +1,5 @@ #lang br +(require (for-syntax br/syntax)) (provide #%top-interaction #%module-begin #%datum (rename-out [my-top #%top]) #%app (all-defined-out)) @@ -10,25 +11,27 @@ (define #'(tst-program _arg ...) #'(begin _arg ...)) +(begin-for-syntax + (define-scope blue)) (define #'(header-expr _filename (_colid ... _outid)) (with-syntax* ([filename-string (symbol->string (syntax->datum #'_filename))] - [procname (string->symbol (cadr (regexp-match #rx"^(.*)\\.hdl$"(symbol->string (syntax->datum #'_filename)))))] - [output (syntax-local-introduce (datum->syntax #f 'output))]) - #'(begin - (provide (all-defined-out)) - (define procname - (dynamic-require (findf file-exists? - (list filename-string (format "~a.rkt" filename-string))) 'procname)) - (display-header '_colid ... '_outid) - (define _colid (make-parameter 0)) ... - (define (_outid) - (keyword-apply procname - (map (compose1 string->keyword symbol->string) (list '_colid ...)) - (list (_colid) ...) null)) - - (define (output) - (display-values (_colid) ... (_outid)))))) + [procname (string->symbol (cadr (regexp-match #rx"^(.*)\\.hdl$"(symbol->string (syntax->datum #'_filename)))))]) + (with-blue-binding-form (output) + #'(begin + (provide (all-defined-out)) + (define procname + (dynamic-require (findf file-exists? + (list filename-string (format "~a.rkt" filename-string))) 'procname)) + (display-header '_colid ... '_outid) + (define _colid (make-parameter 0)) ... + (define (_outid) + (keyword-apply procname + (map (compose1 string->keyword symbol->string) (list '_colid ...)) + (list (_colid) ...) null)) + + (define (output) + (display-values (_colid) ... (_outid))))))) (define #'(display-header _sym ...) #'(begin @@ -47,5 +50,5 @@ (define #'eval-expr #'void) (define #'(output-expr) - (inject-syntax ([#'output 'output]) - #'(output))) + (with-blue-identifiers (output) + #'(output))) diff --git a/beautiful-racket/br/demo/hdl/And.tst b/beautiful-racket/br/demo/hdl/And.tst.rkt similarity index 100% rename from beautiful-racket/br/demo/hdl/And.tst rename to beautiful-racket/br/demo/hdl/And.tst.rkt diff --git a/beautiful-racket/br/demo/hdl/DMux.hdl b/beautiful-racket/br/demo/hdl/DMux.hdl.rkt similarity index 100% rename from beautiful-racket/br/demo/hdl/DMux.hdl rename to beautiful-racket/br/demo/hdl/DMux.hdl.rkt diff --git a/beautiful-racket/br/demo/hdl/Dmux.tst.rkt b/beautiful-racket/br/demo/hdl/Dmux.tst.rkt index efaf4bd..261390f 100644 --- a/beautiful-racket/br/demo/hdl/Dmux.tst.rkt +++ b/beautiful-racket/br/demo/hdl/Dmux.tst.rkt @@ -1,4 +1,4 @@ -#lang br/demo/hdl/tst +#lang br/demo/hdl-tst // This file is part of www.nand2tetris.org // and the book "The Elements of Computing Systems" diff --git a/beautiful-racket/br/demo/hdl/Nand.hdl b/beautiful-racket/br/demo/hdl/Nand.hdl deleted file mode 100644 index 8655fa2..0000000 --- a/beautiful-racket/br/demo/hdl/Nand.hdl +++ /dev/null @@ -1,13 +0,0 @@ -#lang br - -(define+provide (Nand #:a a #:b b) - (if (< (+ a b) 2) - 1 - 0)) - -(module+ test - (require rackunit) - (check-equal? (Nand #:a 0 #:b 0) 1) - (check-equal? (Nand #:a 0 #:b 1) 1) - (check-equal? (Nand #:a 1 #:b 0) 1) - (check-equal? (Nand #:a 1 #:b 1) 0)) diff --git a/beautiful-racket/br/demo/hdl/Nand.hdl.rkt b/beautiful-racket/br/demo/hdl/Nand.hdl.rkt new file mode 100644 index 0000000..40b2504 --- /dev/null +++ b/beautiful-racket/br/demo/hdl/Nand.hdl.rkt @@ -0,0 +1,28 @@ +#lang br + +(define Nand-a + (let ([Nand-a-val 0]) + (λ ([val #f]) + (if val + (set! Nand-a-val val) + Nand-a-val)))) + +(define Nand-b + (let ([Nand-b-val 0]) + (λ ([val #f]) + (if val + (set! Nand-b-val val) + Nand-b-val)))) + + +(define (Nand-out) + (if (< (+ (Nand-a) (Nand-b)) 2) + 1 + 0)) + +(module+ test + (require rackunit) + (check-equal? (begin (Nand-a 0) (Nand-b 0) (Nand-out)) 1) + (check-equal? (begin (Nand-a 0) (Nand-b 1) (Nand-out)) 1) + (check-equal? (begin (Nand-a 1) (Nand-b 0) (Nand-out)) 1) + (check-equal? (begin (Nand-a 1) (Nand-b 1) (Nand-out)) 0)) diff --git a/beautiful-racket/br/demo/hdl/Nand.tst b/beautiful-racket/br/demo/hdl/Nand.tst.rkt similarity index 89% rename from beautiful-racket/br/demo/hdl/Nand.tst rename to beautiful-racket/br/demo/hdl/Nand.tst.rkt index 8d5914b..3ada897 100644 --- a/beautiful-racket/br/demo/hdl/Nand.tst +++ b/beautiful-racket/br/demo/hdl/Nand.tst.rkt @@ -1,4 +1,4 @@ -#lang br/demo/hdl/tst +#lang br/demo/hdl-tst /* nand */ diff --git a/beautiful-racket/br/demo/hdl/Not.hdl b/beautiful-racket/br/demo/hdl/Not.hdl.rkt similarity index 100% rename from beautiful-racket/br/demo/hdl/Not.hdl rename to beautiful-racket/br/demo/hdl/Not.hdl.rkt diff --git a/beautiful-racket/br/demo/hdl/Not.tst b/beautiful-racket/br/demo/hdl/Not.tst.rkt similarity index 69% rename from beautiful-racket/br/demo/hdl/Not.tst rename to beautiful-racket/br/demo/hdl/Not.tst.rkt index cf9f044..3aa9734 100644 --- a/beautiful-racket/br/demo/hdl/Not.tst +++ b/beautiful-racket/br/demo/hdl/Not.tst.rkt @@ -1,4 +1,4 @@ -#lang br/demo/hdl/tst +#lang br/demo/hdl-tst /* Not */ diff --git a/beautiful-racket/br/demo/hdl/Or.hdl b/beautiful-racket/br/demo/hdl/Or.hdl.rkt similarity index 100% rename from beautiful-racket/br/demo/hdl/Or.hdl rename to beautiful-racket/br/demo/hdl/Or.hdl.rkt diff --git a/beautiful-racket/br/demo/hdl/Or.tst b/beautiful-racket/br/demo/hdl/Or.tst.rkt similarity index 88% rename from beautiful-racket/br/demo/hdl/Or.tst rename to beautiful-racket/br/demo/hdl/Or.tst.rkt index 477b357..4dd873e 100644 --- a/beautiful-racket/br/demo/hdl/Or.tst +++ b/beautiful-racket/br/demo/hdl/Or.tst.rkt @@ -1,4 +1,4 @@ -#lang br/demo/hdl/tst +#lang br/demo/hdl-tst /* or */ diff --git a/beautiful-racket/br/demo/hdl/Toffoli.hdl.rkt b/beautiful-racket/br/demo/hdl/Toffoli.hdl.rkt new file mode 100644 index 0000000..b519f67 --- /dev/null +++ b/beautiful-racket/br/demo/hdl/Toffoli.hdl.rkt @@ -0,0 +1,13 @@ +#lang br/demo/hdl + +CHIP And { + IN a, b; + OUT out; + + PARTS: + Nand(a=a, b=b, out=nandout); + Not(in=nandout, out=out); + } + + + diff --git a/beautiful-racket/br/demo/hdl/Xor.hdl b/beautiful-racket/br/demo/hdl/Xor.hdl.rkt similarity index 100% rename from beautiful-racket/br/demo/hdl/Xor.hdl rename to beautiful-racket/br/demo/hdl/Xor.hdl.rkt diff --git a/beautiful-racket/br/demo/hdl/Xor.tst b/beautiful-racket/br/demo/hdl/Xor.tst.rkt similarity index 88% rename from beautiful-racket/br/demo/hdl/Xor.tst rename to beautiful-racket/br/demo/hdl/Xor.tst.rkt index d342aa9..b4cc445 100644 --- a/beautiful-racket/br/demo/hdl/Xor.tst +++ b/beautiful-racket/br/demo/hdl/Xor.tst.rkt @@ -1,4 +1,4 @@ -#lang br/demo/hdl/tst +#lang br/demo/hdl-tst load Xor.hdl, output-list a, b, out;