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.
beautiful-racket/beautiful-racket-demo/basic-demo-3/expander.rkt

33 lines
1.1 KiB
Racket

7 years ago
#lang br/quicklang
7 years ago
(require "struct.rkt" "run.rkt" "elements.rkt")
7 years ago
(provide (rename-out [b-module-begin #%module-begin])
(all-from-out "elements.rkt"))
(define-macro (b-module-begin (b-program LINE ...))
(with-pattern
([((b-line NUM STMT ...) ...) #'(LINE ...)]
[(LINE-FUNC ...) (prefix-id "line-" #'(NUM ...))]
7 years ago
[(VAR-ID ...) (find-unique-var-ids #'(LINE ...))])
7 years ago
#'(#%module-begin
(module configure-runtime br
7 years ago
(require basic-demo-3/runtime)
7 years ago
(current-basic-port (current-output-port)))
7 years ago
(define VAR-ID 0) ...
(provide VAR-ID ...)
7 years ago
LINE ...
(define line-table
(apply hasheqv (append (list NUM LINE-FUNC) ...)))
(void (parameterize ([current-output-port
(or (current-basic-port) (open-output-nowhere))])
7 years ago
(void (run line-table)))))))
7 years ago
(begin-for-syntax
(require racket/list)
7 years ago
(define (find-unique-var-ids line-stxs)
7 years ago
(remove-duplicates
7 years ago
(for/list ([stx (in-list (stx-flatten line-stxs))]
#:when (syntax-property stx 'b-id))
stx)
7 years ago
#:key syntax->datum)))