pull/2/head
Matthew Butterick 9 years ago
parent 3af79f911f
commit e631c39bf2

@ -1,4 +1,5 @@
#lang br #lang br
(require (for-syntax br/syntax))
(provide #%top-interaction #%module-begin #%datum (rename-out [my-top #%top]) #%app (provide #%top-interaction #%module-begin #%datum (rename-out [my-top #%top]) #%app
(all-defined-out)) (all-defined-out))
@ -10,11 +11,13 @@
(define #'(tst-program _arg ...) #'(begin _arg ...)) (define #'(tst-program _arg ...) #'(begin _arg ...))
(begin-for-syntax
(define-scope blue))
(define #'(header-expr _filename (_colid ... _outid)) (define #'(header-expr _filename (_colid ... _outid))
(with-syntax* ([filename-string (symbol->string (syntax->datum #'_filename))] (with-syntax* ([filename-string (symbol->string (syntax->datum #'_filename))]
[procname (string->symbol (cadr (regexp-match #rx"^(.*)\\.hdl$"(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))]) (with-blue-binding-form (output)
#'(begin #'(begin
(provide (all-defined-out)) (provide (all-defined-out))
(define procname (define procname
@ -28,7 +31,7 @@
(list (_colid) ...) null)) (list (_colid) ...) null))
(define (output) (define (output)
(display-values (_colid) ... (_outid)))))) (display-values (_colid) ... (_outid)))))))
(define #'(display-header _sym ...) (define #'(display-header _sym ...)
#'(begin #'(begin
@ -47,5 +50,5 @@
(define #'eval-expr #'void) (define #'eval-expr #'void)
(define #'(output-expr) (define #'(output-expr)
(inject-syntax ([#'output 'output]) (with-blue-identifiers (output)
#'(output))) #'(output)))

@ -1,4 +1,4 @@
#lang br/demo/hdl/tst #lang br/demo/hdl-tst
// This file is part of www.nand2tetris.org // This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems" // and the book "The Elements of Computing Systems"

@ -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))

@ -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))

@ -1,4 +1,4 @@
#lang br/demo/hdl/tst #lang br/demo/hdl-tst
/* nand */ /* nand */

@ -1,4 +1,4 @@
#lang br/demo/hdl/tst #lang br/demo/hdl-tst
/* Not */ /* Not */

@ -1,4 +1,4 @@
#lang br/demo/hdl/tst #lang br/demo/hdl-tst
/* or */ /* or */

@ -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);
}

@ -1,4 +1,4 @@
#lang br/demo/hdl/tst #lang br/demo/hdl-tst
load Xor.hdl, load Xor.hdl,
output-list a, b, out; output-list a, b, out;
Loading…
Cancel
Save