#lang racket
(require "semantics.rkt")
(provide greater-than
less-than
plus
minus
period
comma
brackets
(rename-out [my-module-begin #%module-begin]))
(define current-state (make-parameter (new-state)))
(define-syntax-rule (my-module-begin body ...)
(#%plain-module-begin
(parameterize ([current-state (new-state)])
(begin body ... (void)))))
(define-syntax (greater-than stx)
(syntax-case stx ()
[(_)
(quasisyntax/loc stx
(increment-ptr (current-state) #'#,stx))]))
(define-syntax (less-than stx)
(syntax-case stx ()
[(_)
(quasisyntax/loc stx
(decrement-ptr (current-state) #'#,stx))]))
(define-syntax-rule (plus)
(increment-byte (current-state)))
(define-syntax-rule (minus)
(decrement-byte (current-state)))
(define-syntax-rule (period)
(write-byte-to-stdout (current-state)))
(define-syntax-rule (comma)
(read-byte-from-stdin (current-state)))
(define-syntax-rule (brackets body ...)
(loop (current-state) body ...))