You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1000 B
Racket
40 lines
1000 B
Racket
8 years ago
|
#lang br/quicklang
|
||
|
|
||
8 years ago
|
(define-macro (bf-module-begin PARSE-TREE)
|
||
|
#'(#%module-begin
|
||
|
PARSE-TREE))
|
||
|
(provide (rename-out [bf-module-begin #%module-begin]))
|
||
8 years ago
|
|
||
8 years ago
|
(define-macro (bf-program OP-OR-LOOP-ARG ...)
|
||
|
#'(void OP-OR-LOOP-ARG ...))
|
||
8 years ago
|
(provide bf-program)
|
||
|
|
||
8 years ago
|
(define-macro (loop "[" OP-OR-LOOP-ARG ... "]")
|
||
|
#'(until (zero? (current-byte))
|
||
|
OP-OR-LOOP-ARG ...))
|
||
|
(provide loop)
|
||
|
|
||
8 years ago
|
(define-macro-cases op
|
||
|
[(op ">") #'(gt)]
|
||
|
[(op "<") #'(lt)]
|
||
|
[(op "+") #'(plus)]
|
||
|
[(op "-") #'(minus)]
|
||
|
[(op ".") #'(period)]
|
||
|
[(op ",") #'(comma)])
|
||
|
(provide op)
|
||
|
|
||
8 years ago
|
(define arr (make-vector 30000 0))
|
||
|
(define ptr 0)
|
||
|
|
||
|
(define (current-byte) (vector-ref arr ptr))
|
||
8 years ago
|
|
||
8 years ago
|
(define (set-current-byte! val) (vector-set! arr ptr val))
|
||
8 years ago
|
|
||
8 years ago
|
(define (gt) (set! ptr (add1 ptr)))
|
||
|
(define (lt) (set! ptr (sub1 ptr)))
|
||
|
(define (plus) (set-current-byte! (add1 (current-byte))))
|
||
|
(define (minus) (set-current-byte! (sub1 (current-byte))))
|
||
|
(define (period) (write-byte (current-byte)))
|
||
|
(define (comma) (set-current-byte! (read-byte)))
|
||
8 years ago
|
|