cs: repair prompt around top-level evaluation

This commit is contained in:
Matthew Flatt 2019-01-08 15:20:38 -07:00
parent 593be62896
commit eb3ba2052e
2 changed files with 34 additions and 20 deletions

View File

@ -120,7 +120,7 @@ otherwise.}
[name any/c #f] [name any/c #f]
[import-keys #f #f] [import-keys #f #f]
[get-import #f #f] [get-import #f #f]
[options (listof (or/c 'serializable 'unsafe 'static 'no-prompt)) [options (listof (or/c 'serializable 'unsafe 'static 'use-prompt))
'(serializable)]) '(serializable)])
linklet?] linklet?]
[(compile-linklet [form (or/c correlated? any/c)] [(compile-linklet [form (or/c correlated? any/c)]
@ -129,7 +129,7 @@ otherwise.}
[get-import (or/c #f (any/c . -> . (values (or/c linklet? instance? #f) [get-import (or/c #f (any/c . -> . (values (or/c linklet? instance? #f)
(or/c vector? #f)))) (or/c vector? #f))))
#f] #f]
[options (listof (or/c 'serializable 'unsafe 'static 'no-prompt)) [options (listof (or/c 'serializable 'unsafe 'static 'use-prompt))
'(serializable)]) '(serializable)])
(values linklet? vector?)])]{ (values linklet? vector?)])]{
@ -192,9 +192,12 @@ at most once. Compilation with @racket['static] is intended to improve
the performance of references within the linklet to defined and the performance of references within the linklet to defined and
imported variables. imported variables.
If @racket['no-prompt] is included in @racket[options], then when the If @racket['use-prompt] is included in @racket[options], then
resulting linklet is instantiated, the @racket[_use-prompt?] argument instantiating resulting linklet always wraps a prompt around each
to @racket[instantiate-linklet] may be treated as @racket[#f]. definition and immediate expression in the linklet. Otherwise,
supplying @racket[#t] as the @racket[_use-prompt?] argument to
@racket[instantiate-linklet] may only wrap a prompt around the entire
instantiation.
The symbols in @racket[options] must be distinct, otherwise The symbols in @racket[options] must be distinct, otherwise
@exnraise[exn:fail:contract]. @exnraise[exn:fail:contract].
@ -267,9 +270,13 @@ each export. If @racket[target-instance] is provided as
non-@racket[#f], its existing variables remain intact if they are not non-@racket[#f], its existing variables remain intact if they are not
modified by a linklet definition. modified by a linklet definition.
If @racket[use-prompt?] is true, then the evaluation each definition If @racket[use-prompt?] is true, then a a @tech{prompt} is wrapped
and expression in the linklet is wrapped in a @tech{prompt} in the around the linklet instantiation in same ways as an expression in a
same ways as an expression in a module body.} module body. If the linklet contains multiple definitions or immediate
expressions, then a prompt may or may not be wrapped around each
definition or expression; supply @racket['use-prompt] to
@racket[compile-linklet] to ensure that a prompt is used around each
definition and expression.}
@defproc[(linklet-import-variables [linklet linklet?]) @defproc[(linklet-import-variables [linklet linklet?])

View File

@ -563,6 +563,13 @@
;; Call the linklet: ;; Call the linklet:
(performance-region (performance-region
'instantiate 'instantiate
((if use-prompt?
;; For per-form prompts with in a module linklet,
;; rely on 'use-prompt provided at compile time.
;; But this one is useful for top-level forms.
call-with-module-prompt
(lambda (thunk) (thunk)))
(lambda ()
(apply (apply
(if (eq? 'callable (linklet-preparation linklet)) (if (eq? 'callable (linklet-preparation linklet))
(linklet-code linklet) (linklet-code linklet)
@ -574,7 +581,7 @@
(linklet-importss linklet) (linklet-importss linklet)
(linklet-importss-abi linklet))) (linklet-importss-abi linklet)))
(create-variables target-instance (create-variables target-instance
(linklet-exports linklet)))))))] (linklet-exports linklet)))))))))]
[else [else
;; Make a fresh instance, recur, and return the instance ;; Make a fresh instance, recur, and return the instance
(let ([i (make-instance (linklet-name linklet))]) (let ([i (make-instance (linklet-name linklet))])