Problem compiling method source - genPushLiteral: out of range

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem compiling method source - genPushLiteral: out of range

PatrickScherer
Hello everyone,

I'm trying to move some of our code from VA Smalltalk over to Pharo using a self-made importer and have encountered the following issue I need help with:

A few of our methods are very large in size. For example, we have a method that creates a huge Dictionary with specific keys and values on startup and stores it in a class variable for immediate access. 
This method works fine in VA Smalltalk, but if I attempt to compile the same source code in Pharo (programmatically or via copy paste using the interface) I'm getting 'Error: genPushLiteral: index index 256 is out of range 0 to 255' in OpalEncoderForV3PlusClosures. I'm getting the same error for some other methods.

If I understand this correctly, the method simply exceeds the maximum number of literals, but it works fine in VA Smalltalk. Is there a way to increase this limit or bypass this issue without having to rework our implementation?


Offtopic: Does anybody if there is a package which adds a support layer for imported VA Smalltalk code? I know there is one for Pharo->VA on VASTGoodies but I couldn't find one for the other way around.

Kind regards,
Patrick Scherer
Reply | Threaded
Open this post in threaded view
|

Re: Problem compiling method source - genPushLiteral: out of range

Henrik Sperre Johansen
The limitation is inherit in the object format/ instruction set, you can find some previous discussions at
http://forum.world.st/Max-source-method-length-Max-string-length-Max-change-set-size-td3531169.html#a3535281 and
http://forum.world.st/More-than-256-literals-referenced-td4676669.html#a4676972

One alternative is to change the compiler to create a literal array to hold all literals > 255 and rewrite accesses to indexes above 254 as something like
genPushLiteral: 255
pushLiteral #at:
pushConst: X
messageSend
, but as long as we're talking about a single digit number of cases, and not translating 200+ UI specs, it is probably a lot easier (albeit, maybe a little slower) to rewrite the code in a way which works in both dialects without using a large number of literals, say:

MyClass class >> #initializeStaticVals
dict := Dictionary new.
initializerPairs := #(
Key1 2
Key2 4
).
1 to: initializerPairs size by: 2 do: [:ix | dict at: (initializerPairs at: ix) put: (initializerPairs at: ix +1)].
MyClassVar := dict.

(Haven't seen a support layer package for VA, sorry)

Cheers,
Henry
Reply | Threaded
Open this post in threaded view
|

Re: Problem compiling method source - genPushLiteral: out of range

Marcus Denker-4
In reply to this post by PatrickScherer

On 18 Aug 2017, at 11:34, Patrick Scherer <[hidden email]> wrote:

Hello everyone,

I'm trying to move some of our code from VA Smalltalk over to Pharo using a self-made importer and have encountered the following issue I need help with:

A few of our methods are very large in size. For example, we have a method that creates a huge Dictionary with specific keys and values on startup and stores it in a class variable for immediate access. 
This method works fine in VA Smalltalk, but if I attempt to compile the same source code in Pharo (programmatically or via copy paste using the interface) I'm getting 'Error: genPushLiteral: index index 256 is out of range 0 to 255' in OpalEncoderForV3PlusClosures. I'm getting the same error for some other methods.

If I understand this correctly, the method simply exceeds the maximum number of literals, but it works fine in VA Smalltalk. Is there a way to increase this limit or bypass this issue without having to rework our implementation?

Hello,

Can you try to change (in the preferences) the Bytecode Backend to “SistaV1” (this is the new byte code set that will be the default at some point in the future).

Marcus