|
|
@ -1,18 +1,17 @@
|
|
|
|
#lang br
|
|
|
|
#lang br
|
|
|
|
|
|
|
|
|
|
|
|
(define (read-syntax source-path input-port)
|
|
|
|
(define (read-syntax src-path in-port)
|
|
|
|
(define src-strs (remove-blank-lines (port->lines input-port)))
|
|
|
|
(define lines (remove-blank-lines (port->lines in-port)))
|
|
|
|
(define (make-datum str) (format-datum '(dispatch ~a) str))
|
|
|
|
(define (make-exec-datum line) (format-datum '(exec ~a) line))
|
|
|
|
(define src-exprs (map make-datum src-strs))
|
|
|
|
(define exec-exprs (map make-exec-datum lines))
|
|
|
|
(strip-context
|
|
|
|
(strip-context (with-pattern ([(EXEC-EXPR ...) exec-exprs])
|
|
|
|
(with-pattern ([(SRC-EXPR ...) (map make-datum src-strs)])
|
|
|
|
|
|
|
|
#'(module stacker-mod br/demo/stacker
|
|
|
|
#'(module stacker-mod br/demo/stacker
|
|
|
|
SRC-EXPR ...))))
|
|
|
|
EXEC-EXPR ...))))
|
|
|
|
(provide read-syntax)
|
|
|
|
(provide read-syntax)
|
|
|
|
|
|
|
|
|
|
|
|
(define-macro (stacker-module-begin READER-LINE ...)
|
|
|
|
(define-macro (stacker-module-begin SRC-LINE ...)
|
|
|
|
#'(#%module-begin
|
|
|
|
#'(#%module-begin
|
|
|
|
READER-LINE ...
|
|
|
|
SRC-LINE ...
|
|
|
|
(display (first stack))))
|
|
|
|
(display (first stack))))
|
|
|
|
(provide (rename-out [stacker-module-begin #%module-begin]))
|
|
|
|
(provide (rename-out [stacker-module-begin #%module-begin]))
|
|
|
|
|
|
|
|
|
|
|
@ -20,10 +19,14 @@
|
|
|
|
(define (push num) (set! stack (cons num stack)))
|
|
|
|
(define (push num) (set! stack (cons num stack)))
|
|
|
|
(provide push)
|
|
|
|
(provide push)
|
|
|
|
|
|
|
|
|
|
|
|
(define-cases dispatch
|
|
|
|
(define-cases exec
|
|
|
|
[(_ push num) (push num)]
|
|
|
|
[(_ func num) (func num)]
|
|
|
|
[(_ op) (define op-result (op (first stack) (second stack)))
|
|
|
|
[(_ op) (define result (op (first stack) (second stack)))
|
|
|
|
(set! stack (cons op-result (drop stack 2)))])
|
|
|
|
(set! stack (cons result (drop stack 2)))])
|
|
|
|
(provide dispatch)
|
|
|
|
(provide exec)
|
|
|
|
|
|
|
|
|
|
|
|
(provide + * #%app #%datum #%top-interaction)
|
|
|
|
(provide + * #%app #%datum #%top-interaction)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(module+ test
|
|
|
|
|
|
|
|
(require rackunit)
|
|
|
|
|
|
|
|
(check-equal? (with-output-to-string (λ () (dynamic-require "stacker-test.rkt" #f))) "36"))
|