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-2/expander.rkt

27 lines
842 B
Racket

#lang br/quicklang
8 years ago
(require "struct.rkt" "run.rkt" "elements.rkt")
(provide (rename-out [b-module-begin #%module-begin])
8 years ago
(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 ...))]
8 years ago
[(VAR-ID ...) (find-unique-var-ids #'(LINE ...))])
#'(#%module-begin
8 years ago
(define VAR-ID 0) ...
LINE ...
(define line-table
(apply hasheqv (append (list NUM LINE-FUNC) ...)))
8 years ago
(void (run line-table)))))
(begin-for-syntax
(require racket/list)
8 years ago
(define (find-unique-var-ids line-stxs)
(remove-duplicates
8 years ago
(for/list ([stx (in-list (syntax-flatten line-stxs))]
#:when (syntax-property stx 'b-id))
stx)
#:key syntax->datum)))