resume in hdl-tst

pull/2/head
Matthew Butterick 8 years ago
parent f02e605a9c
commit c0a3020947

@ -1,27 +1,27 @@
#lang racket/base #lang racket/base
(require (for-syntax racket/base)) (require (for-syntax racket/base br/syntax)
br/define)
(provide (all-defined-out)) (provide (all-defined-out))
(define-syntax-rule (until COND EXPR ...) (define-macro (until COND EXPR ...)
(let loop () #'(let loop ()
(unless COND (unless COND
EXPR ... EXPR ...
(loop)))) (loop))))
(define-syntax-rule (while COND EXPR ...) (define-macro (while COND EXPR ...)
(let loop () #'(let loop ()
(when COND (when COND
EXPR ... EXPR ...
(loop)))) (loop))))
(define-syntax (forever stx) (define-macro (forever . EXPRS)
(syntax-case stx ()
[(_ . EXPRS)
;; todo: would be better with a syntax parameter ;; todo: would be better with a syntax parameter
(with-syntax ([stop (datum->syntax #'EXPRS 'stop)]) (with-pattern
([stop (datum->syntax #'EXPRS 'stop)])
#'(let/ec stop #'(let/ec stop
(while #t (while #t
. EXPRS)))])) . EXPRS))))
(module+ test (module+ test
(require rackunit) (require rackunit)

@ -1,27 +1,26 @@
#lang racket/base #lang racket/base
(require (for-syntax racket/base racket/syntax)) (require (for-syntax racket/base br/syntax)
br/define)
(provide (all-defined-out)) (provide (all-defined-out))
(define-syntax (report stx) (define-macro-cases report
(syntax-case stx ()
[(_ EXPR) #'(report EXPR EXPR)] [(_ EXPR) #'(report EXPR EXPR)]
[(_ EXPR NAME) [(_ EXPR NAME)
#'(let ([expr-result EXPR]) #'(let ([expr-result EXPR])
(eprintf "~a = ~v\n" 'NAME expr-result) (eprintf "~a = ~v\n" 'NAME expr-result)
expr-result)])) expr-result)])
(define-syntax (report-datum stx) (define-macro-cases report-datum
(syntax-case stx ()
[(_ STX-EXPR) [(_ STX-EXPR)
(with-syntax ([datum (syntax->datum #'STX-EXPR)]) (with-pattern ([datum (syntax->datum #'STX-EXPR)])
#'(report-datum STX-EXPR datum))] #'(report-datum STX-EXPR datum))]
[(_ STX-EXPR NAME) [(_ STX-EXPR NAME)
#'(let () #'(let ()
(eprintf "~a = ~v\n" 'NAME (syntax->datum STX-EXPR)) (eprintf "~a = ~v\n" 'NAME (syntax->datum STX-EXPR))
STX-EXPR)])) STX-EXPR)])
(define-syntax-rule (define-multi-version MULTI-NAME NAME) (define-macro (define-multi-version MULTI-NAME NAME)
(define-syntax-rule (MULTI-NAME x (... ...)) #'(define-macro (MULTI-NAME X (... ...))
(begin (NAME x) (... ...)))) #'(begin (NAME X) (... ...))))
(define-multi-version report* report) (define-multi-version report* report)

@ -1,17 +1,15 @@
#lang racket/base #lang racket/base
(require (for-syntax racket/base racket/syntax) syntax/strip-context) (require (for-syntax racket/base racket/syntax br/syntax) br/define syntax/strip-context)
(provide define-read-and-read-syntax) (provide define-read-and-read-syntax)
;; `define-read-functions` simplifies support for the standard reading API, ;; `define-read-functions` simplifies support for the standard reading API,
;; which asks for `read` and `read-syntax`. ;; which asks for `read` and `read-syntax`.
;; in general, `read` is just the datum from the result of `read-syntax`. ;; in general, `read` is just the datum from the result of `read-syntax`.
(define-syntax (define-read-and-read-syntax calling-site-stx) (define-macro (define-read-and-read-syntax (PATH PORT) BODY ...)
(syntax-case calling-site-stx ()
[(_ (PATH PORT) BODY ...)
(let ([internal-prefix (gensym)]) (let ([internal-prefix (gensym)])
(with-syntax ([READ (datum->syntax calling-site-stx 'read)] (with-syntax ([READ (datum->syntax caller-stx 'read)]
[READ-SYNTAX (datum->syntax calling-site-stx 'read-syntax)] [READ-SYNTAX (datum->syntax caller-stx 'read-syntax)]
;; use prefixed names to prevent namespace collisions with possibly existing `read` & `read-syntax` ;; use prefixed names to prevent namespace collisions with possibly existing `read` & `read-syntax`
[INTERNAL-READ (format-id #'here "~a-~a" internal-prefix 'read)] [INTERNAL-READ (format-id #'here "~a-~a" internal-prefix 'read)]
[INTERNAL-READ-SYNTAX (format-id #'here "~a-~a" internal-prefix 'read-syntax)]) [INTERNAL-READ-SYNTAX (format-id #'here "~a-~a" internal-prefix 'read-syntax)])
@ -40,4 +38,4 @@
(let ([output (calling-site-function #f port)]) (let ([output (calling-site-function #f port)])
(if (syntax? output) (if (syntax? output)
(syntax->datum output) (syntax->datum output)
output))) 'READ)))))])) output))) 'READ))))))
Loading…
Cancel
Save