adds and changes

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

@ -231,18 +231,35 @@
-1 -1 2 1 #"\0" -1 -1 2 1 #"\0"
0 75 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 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 24 29 1 #"\n"
0 0 14 3 8 #"Greatest" 0 0 14 3 6 #"++++++"
0 0 24 3 1 #" " 0 0 24 3 1 #"["
0 0 14 3 8 #"language" 0 0 14 3 15 #">++++++++++++<-"
0 0 24 3 1 #" " 0 0 24 3 1 #"]"
0 0 14 3 5 #"ever!" 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 24 29 1 #"\n"
0 0 14 3 8 #"++++++++" 0 0 14 3 18 #"+++++++..+++.>++++"
0 0 24 3 1 #"[" 0 0 24 3 1 #"["
0 0 14 3 11 #">++++++++<-" 0 0 14 3 14 #">+++++++++++<-"
0 0 24 3 1 #"]" 0 0 24 3 1 #"]"
0 0 14 3 2 #">." 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 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 0 0

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

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

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