This repository has been archived by the owner on Jul 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
load.rkt
52 lines (43 loc) · 1.77 KB
/
load.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
48
49
50
51
52
#lang racket/base
;;;
;;; Used to keep the dynamic/loadable style of current arc code
;;; Ripped straight out of racket/load
;;;
(require syntax/strip-context)
(provide (rename-out [module-begin #%module-begin]
[top-interaction #%top-interaction]))
(define-syntax-rule (module-begin form ...)
(#%plain-module-begin
(top-interaction . (#%top-interaction . (require (planet kogir/rark/rark))))
(top-interaction . (#%top-interaction . (compile-allow-set!-undefined #t)))
(top-interaction . (#%top-interaction . form)) ...))
(define-syntax-rule (top-interaction . form)
(strip-context-and-eval (quote-syntax form)))
;; Make a new namespace to run user code. All evaluation has to start
;; with `module-begin' or `top-interaction', and we wrap such
;; evaluations to swap the namespace in and out.
;; One way in which this differs from Arc is that
;; `#reader'-loaded modules see a different top-level namespace,
;; though it's the same module registry.
(define-namespace-anchor a)
(define namespace (namespace-anchor->empty-namespace a))
(parameterize ([current-namespace namespace])
(namespace-require '(planet kogir/rark/language)))
(define (strip-context-and-eval e)
(let ([ns (current-namespace)])
(dynamic-wind
(lambda ()
(current-namespace namespace))
(lambda ()
(call-with-continuation-prompt
(lambda ()
(eval-syntax (namespace-syntax-introduce
(strip-context e))))
(default-continuation-prompt-tag)
(lambda args
(apply abort-current-continuation
(default-continuation-prompt-tag)
args))))
(lambda ()
(set! namespace (current-namespace))
(current-namespace ns)))))