Hi,

On Sun 05 Sep 2010 02:25, "Jose A. Ortega Ruiz" <j...@gnu.org> writes:

>   (define cp (module-ref (current-module) 'cons))
>
>   (program? cp) => #t
>   (program-module cp) => #<pointer 0xb77ccbb0>
>   (module? (program-module cp)) => #f
>
> Since `cp' above is a program, i was expecting the return value to be
> always a module: is that a wrong expectation or is this a bug?

It's a bug.

When Guile compiles a Scheme function, it doesn't emit a constants table
unless it has to. It has to if there is a quoted constant in the
function body. The constants table is also used as a cache for toplevel
variable access.

If there is a constants table, index 0 of that table will contain the
procedure's module. 

However since primitives, full continuations, partial continuations, and
foreign functions all hand-craft their bytecode trampolines, the Scheme
compiler isn't involved, so it's not there to ensure that the 0th
element of the object table is a module. It's not even clear what it
means for a primitive procedure to have a module.

There could be many solutions -- for example, flagging programs loaded
via the load-program opcode as being "module-blessed" -- but I think for
now the simple heuristic of rejecting non-module returns from
program-module will suffice. I have committed that locally and will push
soon.

Thanks for the report,

Andy
-- 
http://wingolog.org/

Reply via email to