[gambit-list] set! of local var in compiled code behavior, box-var / var->box

Marc Feeley feeley at iro.umontreal.ca
Mon Nov 14 13:01:23 EST 2011


On 2011-11-14, at 12:36 PM, Mikael wrote:

> Dear Marc,
> 
> Noted that set! of local variables in compiled code returns a box object with as slot, the variable slot of the mutated variable. While this is a great feature, i'd really want to disable this as a bundled behavior in set!, as I use set! for mutation solely, and this box object generation thus takes resources unnecessarily.

In compiled code, the box object *is* necessary due to the use of assignment conversion for the correct implementation of closures.  I think you dislike that (set! local-var val) returns the box object associated with the local-var, but I am not sure why?  Is the issue that you didn't expect this or that you think it uses up resources?  Note that in Scheme the value returned by (set! var val) is unspecified, so Gambit's behaviour conforms to the spec.

> How is this box generation disabled?

You can't disable it.  The value returned is the one returned by (##set-box! local-var's-box val) which currently returns local-var's-box.  Note that (set! local-var val) does not allocate a new box, it just returns the one that is associated with the local-var.

> It would be great to have this feature as a separate primitive instead, like box-var or var->box or sth, that'd work for both in interpreted and compiled code, and both for local and global vars. If there's anything like this, please let me/the ml know.

The interpreter uses another representation for local variables.  They are part of a frame which is represented with a vector.

Marc



More information about the Gambit-list mailing list