[racket] compiling interactions?

From: Carl Eastlund (cce at ccs.neu.edu)
Date: Fri Jan 14 15:59:05 EST 2011

Danny,

It looks like you've constructed your namespace with
"module->namespace".  The provides the bindings from inside the
module, not the ones it provides.  I think you want to use
namespace-require or something similar.

Carl Eastlund

On Fri, Jan 14, 2011 at 3:51 PM, Danny Yoo <dyoo at cs.wpi.edu> wrote:
> Hi everyone,
>
>
> I'm trying to use the following to get the bytecodes for a non-module
> interaction:
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> #lang racket/base
> (define (get-interaction-bytecode x #:language-module
>                                  (language-module 'racket/base))
>  (let ([module-namespace
>         (parameterize ([current-namespace (make-base-empty-namespace)])
>           (dynamic-require language-module #f)
>           (module->namespace language-module))])
>    (parameterize ([current-namespace module-namespace])
>      (serialize-compiled-code
>       (compile (namespace-syntax-introduce
>                 (datum->syntax #f (cons '#%top-interaction x))))))))
>
> ;; serialize-compiled-code: compiled-code -> bytes
> (define (serialize-compiled-code a-compiled-code)
>  (let ([op (open-output-bytes)])
>    (write a-compiled-code op)
>    (get-output-bytes op)))
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>
>
>
> I have a separate, restricted language called wescheme-interaction.rkt
> that doesn't provide a 'require' special form:
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> #lang s-exp "base.rkt"
> (require "wescheme.rkt")
> (provide (except-out (all-from-out "wescheme.rkt")
>                     require))
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>
>
> When I compile simple interactions, I get the expected bytecode:
>
>> (get-interaction-bytecode '(printf "hello world\n") #:language-module '(file "/home/dyoo/work/js-vm/lang/wescheme-interaction.rkt"))
> #"#~\0055.0.1\1\0\0\0\1\0\0\0\0\332\0\0\0\237%\24i\237$\20\1\36\35\6\n\nkernel.rkt\35\6\b\bbase.rkt\35\6\f\fwescheme.rkt\35^@file\00633/home/dyoo/work/js-vm/lang/wescheme-interaction.rkt\vBprintf\224\3\20\0\24\16\237\1'moby-stack-record-continuation-mark-key\25\20\6^BsyntaxDoperator\6\2\2#f\v\v\v$\370P\237%$&\6\f\fhello
> world\n"
>
>
> This actually looks ok.  However, when I try to get the system to
> properly error out when the user tries to pass in a 'require',
>
>    (get-interaction-bytecode '(require racket) #:language-module
> '(file "/home/dyoo/work/js-vm/lang/wescheme-interaction.rkt"))
>
>
> then I don't get the expected error: it looks like it just uses
> require, even though I've excluded it from my language.


Posted on the users mailing list.