adds and changes

dev-elider-3
Matthew Butterick 9 years ago
parent 63a88ee103
commit d03ff769e2

@ -231,18 +231,35 @@
-1 -1 2 1 #"\0"
0 75 1 #"\0"
0 4 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 1.0 1.0 1.0 1.0 1.0 1.0 0 0 0 0 0 0 -1
-1 0 14 0 26 3 28 #"#lang reader \"bf-reader.rkt\""
-1 0 31 0 26 3 28 #"#lang reader \"bf-reader.rkt\""
0 0 24 29 1 #"\n"
0 0 14 3 8 #"Greatest"
0 0 24 3 1 #" "
0 0 14 3 8 #"language"
0 0 24 3 1 #" "
0 0 14 3 5 #"ever!"
0 0 14 3 6 #"++++++"
0 0 24 3 1 #"["
0 0 14 3 15 #">++++++++++++<-"
0 0 24 3 1 #"]"
0 0 14 3 2 #">."
0 0 24 29 1 #"\n"
0 0 14 3 11 #">++++++++++"
0 0 24 3 1 #"["
0 0 14 3 13 #">++++++++++<-"
0 0 24 3 1 #"]"
0 0 14 3 3 #">+."
0 0 24 29 1 #"\n"
0 0 14 3 8 #"++++++++"
0 0 14 3 18 #"+++++++..+++.>++++"
0 0 24 3 1 #"["
0 0 14 3 11 #">++++++++<-"
0 0 14 3 14 #">+++++++++++<-"
0 0 24 3 1 #"]"
0 0 14 3 2 #">."
0 0 24 29 1 #"\n"
0 0 14 3 4 #"<+++"
0 0 24 3 1 #"["
0 0 14 3 7 #">----<-"
0 0 24 3 1 #"]"
0 0 14 3 10 #">.<<<<<+++"
0 0 24 3 1 #"["
0 0 14 3 8 #">+++++<-"
0 0 24 3 1 #"]"
0 0 14 3 2 #">."
0 0 24 29 1 #"\n"
0 0 14 3 27 #">>.+++.------.--------.>>+."
0 0

@ -1,2 +1,3 @@
#lang reader "bf-reader.rkt"
+++++++[>+++++<-]>.
Greatest language ever!
++++++++[>++++++++<-]>.

@ -1,44 +1,36 @@
#lang br
(provide (rename-out [bf-module-begin #%module-begin])
#%top-interaction)
(define #'(bf-module-begin BF-PARSE-TREE ...)
(define #'(bf-module-begin PARSE-TREE ...)
#'(#%module-begin
BF-PARSE-TREE ...))
;; macros to expand our parse tree into local functions
(provide bf-program op loop)
PARSE-TREE ...))
(provide (rename-out [bf-module-begin #%module-begin])
#%top-interaction)
;; bf-program doesn't do anything
(define #'(bf-program <op-or-loop> ...)
#'(begin <op-or-loop> ...))
(define #'(bf-program OP-OR-LOOP ...)
#'(begin OP-OR-LOOP ...))
(provide bf-program)
;; op branches. Note that string & number literals are
;; matched literally in syntax patterns.
(define-cases #'op
[#'(_ ">") #'(move-pointer 1)]
[#'(_ "<") #'(move-pointer -1)]
[#'(_ "+") #'(set-pointer-byte! (add1 (get-pointer-byte)))]
[#'(_ "-") #'(set-pointer-byte! (sub1 (get-pointer-byte)))]
[#'(_ ".") #'(write-byte (get-pointer-byte))]
[#'(_ ",") #'(set-pointer-byte! (read-byte))])
(define #'(loop "[" <op-or-loop> ... "]")
#'(until (zero? (get-pointer-byte))
<op-or-loop> ...))
[#'(op ">") #'(move-pointer 1)]
[#'(op "<") #'(move-pointer -1)]
[#'(op "+") #'(set-current-byte! (add1 (get-current-byte)))]
[#'(op "-") #'(set-current-byte! (sub1 (get-current-byte)))]
[#'(op ".") #'(write-byte (get-current-byte))]
[#'(op ",") #'(set-current-byte! (read-byte))])
(provide op)
;; bf implementation
;; state: one vector, one pointer
(define bf-vector (make-vector 30000 0))
(define bf-pointer 0)
;; gets and sets
(define (get-pointer-byte) (vector-ref bf-vector bf-pointer))
(define (set-pointer-byte! val) (vector-set! bf-vector bf-pointer val))
(define (move-pointer how-far)
(set! bf-pointer (+ bf-pointer how-far)))
(define (get-current-byte)
(vector-ref bf-vector bf-pointer))
(define (set-current-byte! val)
(vector-set! bf-vector bf-pointer val))
;; pointer mover
(define (move-pointer how-far) (set! bf-pointer (+ bf-pointer how-far)))
(define #'(loop "[" OP-OR-LOOP ... "]")
#'(until (zero? (get-current-byte))
OP-OR-LOOP ...))
(provide loop)

@ -0,0 +1,7 @@
#lang reader "bf-reader.rkt"
>++++++++++>>>+>+[>>>+[-[<<<<<[+<<<<<]>>[[-]>[<<+>+>-]
<[>+<-]<[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-
[>[-]>>>>+>+<<<<<<-[>+<-]]]]]]]]]]]>[<+>-]+>>>>>]<<<<<
[<<<<<]>>>>>>>[>>>>>]++[-<<<<<]>>>>>>-]+>>>>>]<[>++<-]
<<<<[<[>+<-]<<<<]>>[->[-]++++++[<++++++++>-]>>>>]<<<<<
[<[>+>+<<-]>.<<<<<]>.>>>>]
Loading…
Cancel
Save