[racket] top-level-rename

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Fri Aug 8 01:07:02 EDT 2014

At Wed, 6 Aug 2014 22:03:17 +0200, Jens Axel Søgaard wrote:
> The program below produce bytecodes for the program that returns a
> syntax-object representing 42.
> 
> The syntax-object looks like this:
> 
>     (#s((stx zo 0)
>            #s((wrapped zo 0)
>               42
>               (#s((top-level-rename wrap 0 zo 0) #f)
>                #s((top-level-rename wrap 0 zo 0) #f)
>                #s((top-level-rename wrap 0 zo 0) #t)
>                #s((phase-shift wrap 0 zo 0) 0 #f #f #f))
>               clean))))
> 
> Two questions:
>    1) Why three top-level-renames and not just one?
>
>    2) What is the meaning of the boolean flag?

The boolean apparently indicates whether the rename is for phase 0. It
should instead be the phase of the rename, where using a boolean for
the phase is probably a leftover from an original implementation where
imports were either phase 0 or phase 1.

The three renames are from phases 0, 1, and #f.

I think this mismatch has gone unnoticed because we generally don't try
to use non-module code in bytecode form --- especially non-module code
that would involve syntax objects.


> #lang racket
> (require compiler/zo-structs compiler/zo-parse)
> 
> (define (bytecode->zo bytecode)
>   (zo-parse
>    (open-input-bytes
>     (with-output-to-bytes
>         (λ () (write bytecode))))))
> 
> (define (stx->zo x)
>   (parameterize ([current-namespace (make-base-empty-namespace)])
>     (namespace-require 'racket/base)
>     (bytecode->zo (compile x))))
> 
> (stx->zo '(syntax 42))
> 
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users


Posted on the users mailing list.