fix your soul
parent
283e74446b
commit
d46534dfdc
@ -0,0 +1,14 @@
|
||||
#lang br/demo/hdl/tst
|
||||
|
||||
/* and */
|
||||
|
||||
load And.hdl,
|
||||
output-list a, b, out;
|
||||
set a 0, set b 0,
|
||||
eval, output;
|
||||
set a 0, set b 1,
|
||||
eval, output;
|
||||
set a 1, set b 0,
|
||||
eval, output;
|
||||
set a 1, set b 1,
|
||||
eval, output;
|
@ -1 +0,0 @@
|
||||
#lang racket
|
@ -0,0 +1,14 @@
|
||||
#lang br/demo/hdl/tst
|
||||
|
||||
/* nand */
|
||||
|
||||
load Nand.hdl,
|
||||
output-list a, b, out;
|
||||
set a 0, set b 0,
|
||||
eval, output;
|
||||
set a 0, set b 1,
|
||||
eval, output;
|
||||
set a 1, set b 0,
|
||||
eval, output;
|
||||
set a 1, set b 1,
|
||||
eval, output;
|
@ -0,0 +1,10 @@
|
||||
#lang br/demo/hdl/tst
|
||||
|
||||
/* Not */
|
||||
|
||||
load Not.hdl,
|
||||
output-list in, out;
|
||||
set in 0,
|
||||
eval, output;
|
||||
set in 1,
|
||||
eval, output;
|
@ -1,13 +0,0 @@
|
||||
#lang br/demo/hdl
|
||||
|
||||
CHIP And {
|
||||
IN a, b;
|
||||
OUT out;
|
||||
|
||||
PARTS:
|
||||
Nand(a=a, b=b, out=nandout);
|
||||
Not(in=nandout, out=out);
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1,14 @@
|
||||
#lang br/demo/hdl/tst
|
||||
|
||||
/* or */
|
||||
|
||||
load Or.hdl,
|
||||
output-list a, b, out;
|
||||
set a 0, set b 0,
|
||||
eval, output;
|
||||
set a 0, set b 1,
|
||||
eval, output;
|
||||
set a 1, set b 0,
|
||||
eval, output;
|
||||
set a 1, set b 1,
|
||||
eval, output;
|
@ -1,56 +0,0 @@
|
||||
#lang br
|
||||
|
||||
#|
|
||||
load Xor.hdl,
|
||||
output-list a, b, out;
|
||||
set a 0, set b 0,
|
||||
eval, output;
|
||||
set a 0, set b 1,
|
||||
eval, output;
|
||||
set a 1, set b 0,
|
||||
eval, output;
|
||||
set a 1, set b 1,
|
||||
eval, output;
|
||||
|#
|
||||
|
||||
(define (vals->text vals)
|
||||
(string-join (map ~a vals) " | "))
|
||||
|
||||
(define (display-values . vals)
|
||||
(displayln (vals->text vals)))
|
||||
|
||||
(define (display-dashes . vals)
|
||||
(displayln (make-string (string-length (vals->text vals)) #\-)))
|
||||
|
||||
(define #'(display-header _val ...)
|
||||
#'(begin
|
||||
(apply display-values (list '_val ...))
|
||||
(apply display-dashes (list '_val ...))))
|
||||
|
||||
(define (display-status)
|
||||
(display-values a b (out)))
|
||||
|
||||
(define proc (dynamic-require "Xor.hdl" 'Xor))
|
||||
|
||||
(display-header a b out)
|
||||
(define a #f)
|
||||
(define b #f)
|
||||
(define (out)
|
||||
(keyword-apply proc '(#:a #:b) (list a b) null))
|
||||
|
||||
|
||||
(set! a 0)
|
||||
(set! b 0)
|
||||
(display-status)
|
||||
|
||||
(set! a 0)
|
||||
(set! b 1)
|
||||
(display-status)
|
||||
|
||||
(set! a 1)
|
||||
(set! b 0)
|
||||
(display-status)
|
||||
|
||||
(set! a 1)
|
||||
(set! b 1)
|
||||
(display-status)
|
@ -1,37 +0,0 @@
|
||||
#lang racket/base
|
||||
(provide Xor)
|
||||
|
||||
(define Xor
|
||||
(make-keyword-procedure
|
||||
(λ (kws kw-args . rest)
|
||||
(define kw-pairs (map cons kws kw-args))
|
||||
(let ([a (cdr (assq (string->keyword (format "~a" 'a)) kw-pairs))]
|
||||
[b (cdr (assq (string->keyword (format "~a" 'b)) kw-pairs))])
|
||||
(define nota
|
||||
(let ()
|
||||
(local-require "Not.hdl")
|
||||
(Not #:in a)))
|
||||
(define notb
|
||||
(let ()
|
||||
(local-require "Not.hdl")
|
||||
(Not #:in b)))
|
||||
(define w1
|
||||
(let ()
|
||||
(local-require "And.hdl")
|
||||
(And #:a a #:b notb)))
|
||||
(define w2
|
||||
(let ()
|
||||
(local-require "And.hdl")
|
||||
(And #:a nota #:b b)))
|
||||
(define out
|
||||
(let ()
|
||||
(local-require "Or.hdl")
|
||||
(Or #:a w1 #:b w2)))
|
||||
out))))
|
||||
|
||||
(module+ test
|
||||
(require rackunit)
|
||||
(check-equal? (Xor #:a 0 #:b 0) 0)
|
||||
(check-equal? (Xor #:a 0 #:b 1) 1)
|
||||
(check-equal? (Xor #:a 1 #:b 0) 1)
|
||||
(check-equal? (Xor #:a 1 #:b 1) 0))
|
@ -1,18 +0,0 @@
|
||||
#lang s-exp br/demo/hdl/expander
|
||||
|
||||
(chip Xor (IN a b)
|
||||
(OUT out)
|
||||
(PARTS
|
||||
(Not [in a] [out nota])
|
||||
(Not [in b] [out notb])
|
||||
(And [a a] [b notb] [out w1])
|
||||
(And [a nota] [b b] [out w2])
|
||||
(Or [a w1] [b w2] [out out])))
|
||||
|
||||
|
||||
(module+ test
|
||||
(require rackunit)
|
||||
(check-equal? (Xor #:a 0 #:b 0) 0)
|
||||
(check-equal? (Xor #:a 0 #:b 1) 1)
|
||||
(check-equal? (Xor #:a 1 #:b 0) 1)
|
||||
(check-equal? (Xor #:a 1 #:b 1) 0))
|
@ -1,15 +0,0 @@
|
||||
#lang br/demo/hdl
|
||||
|
||||
CHIP Xor {
|
||||
IN a, b;
|
||||
OUT out;
|
||||
PARTS:
|
||||
Not(in=a, out=nota);
|
||||
Not(in=b, out=notb);
|
||||
And(a=a, b=notb, out=w1);
|
||||
And(a=nota, b=b, out=w2);
|
||||
Or(a=w1, b=w2, out=out);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,32 +0,0 @@
|
||||
#lang br
|
||||
|
||||
(provide #%top-interaction (rename-out [mb #%module-begin]))
|
||||
|
||||
(define #'(mb _arg ...)
|
||||
#'(#%module-begin
|
||||
(module treemod br/demo/hdl/expander
|
||||
_arg ...)
|
||||
(require 'treemod)
|
||||
(chip parse-tree)))
|
||||
|
||||
|
||||
(define #'(chip _Chip
|
||||
(_input-pin ...)
|
||||
(_output-pin ...)
|
||||
((_Part [_pin-in _val-id] ... [out _pin-out]) ...))
|
||||
#'(begin
|
||||
(provide _Chip)
|
||||
(define _Chip
|
||||
(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))] ...)
|
||||
(define _pin-out (call-part _Part [_pin-in _val-id] ...)) ...
|
||||
(values _output-pin ...)))))))
|
||||
|
||||
(define #'(call-part _Part [_pin-in _val-id] ...)
|
||||
(with-syntax ([part-path (format "~a.hdl" (syntax->datum #'_Part))]
|
||||
[(kw ...) (map (λ(pi) (string->keyword (format "~a" (syntax->datum pi)))) (syntax->list #'(_pin-in ...)))])
|
||||
#'(let ()
|
||||
(local-require (rename-in part-path [_Part local-name]))
|
||||
(keyword-apply local-name '(kw ...) (list _val-id ...) null))))
|
@ -1,24 +0,0 @@
|
||||
#lang br
|
||||
(provide (all-from-out br) chip call-part)
|
||||
|
||||
|
||||
(define #'(chip _Chip
|
||||
(_input-pin ...)
|
||||
(_output-pin ...)
|
||||
((_Part [_pin-in _val-id] ... [out _pin-out]) ...))
|
||||
#'(begin
|
||||
(provide _Chip)
|
||||
(define _Chip
|
||||
(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))] ...)
|
||||
(define _pin-out (call-part _Part [_pin-in _val-id] ...)) ...
|
||||
(values _output-pin ...)))))))
|
||||
|
||||
(define #'(call-part _Part [_pin-in _val-id] ...)
|
||||
(with-syntax ([part-path (format "~a.hdl" (syntax->datum #'_Part))]
|
||||
[(kw ...) (map (λ(pi) (string->keyword (format "~a" (syntax->datum pi)))) (syntax->list #'(_pin-in ...)))])
|
||||
#'(let ()
|
||||
(local-require (rename-in part-path [_Part local-name]))
|
||||
(keyword-apply local-name '(kw ...) (list _val-id ...) null))))
|
Loading…
Reference in New Issue