-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlabel-unit.rkt
47 lines (36 loc) · 1.42 KB
/
label-unit.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#lang racket/unit
(require "sig.rkt"
"label-sig.rkt"
"ns.rkt"
"code.rkt")
;; Translate a bunch of interfaces into one that is used to implement
;; the macros.
(import jump^ ;; exit
ram^ ;; allot
org^ ;; org-begin, org-end
instantiate^) ;; wrap-word, wrap-variable
(export label^)
;; NOTE: you can't assign the value of an identifier to another one in
;; a module body, as it will be #<undefined>. I.e. this doesn't
;; always work:
;; (define label:register! code-append-postponed!)
;; I did manage to do this for other variables, so maybe it depends on
;; the order of the units when the variables are finally bound? In
;; any case, wrapping function variables in abstraction
(define-syntax-rule (wrap-functions (mf:x label:x) ...)
(begin (define (mf:x . args) (apply label:x args)) ...))
(wrap-functions
(label:append! code-append-postponed!)
(label:wrap-word wrap-word)
(label:wrap-variable wrap-variable)
(label:wrap-macro wrap-macro))
;; The signature macros will insert these words in the RPN code. They
;; implement access to the target code graph, which is essentially
;; built from a stream of RPN words.
(define-syntax-rule (wrap-macros (l:n n) ...)
(begin (define (l:n s) ((ns (macro) n) s)) ...))
(wrap-macros
(label:exit exit)
(label:allot allot)
(label:org-begin org-begin)
(label:org-end org-end))