Closed Yevano closed 9 years ago
I tried to implement Enums today, and I'm running into a problem that Enums use loads of code to initialize everything, and it's going over the constant limit... This needs to be resolved... I'll look into it.
Cool. I was actually thinking about this while in the shower this morning. One way to do it would be to just keep a count of how many constants are used, and call a function call asmUseConst(inst) to add an instruction which uses constants. If you can make the constant inline, then just output one instruction. If not, output the loadk instruction and use the relevant register instead.
That's actually exactly the solution I had considered =P I just haven't tried to implement it. You want to do it or should I?
I don't mind you implementing it. If you need any help though, I'll be glad to help.
I actually kind of want to work on getting some Java side stuff done so that ComputerCraft APIs are usable, so if I handle this it won't be for a little while.
Maybe I'll take a look after a bit.
Currently working on a solution to this.
Have you got anything on this yet? I just realized that the reason enums don't work if you've got more than a few cases is because they have to load their cases' names as string, and we currently have one constant per character per string, which loads a huge number of constants. We could just create a new jString at compile time and use asmGetRTI to load it. If you've got anything done on this I don't want to commit something that'll conflict with that, but I'd like to replace the un-looped string constant loading code with this idea. Doesn't fix this issue but it makes enums usable.
Yeah go ahead and do whatever you need to on that front. I have some code written but it's just playing with ideas at this point.
You may have already thought of a similar idea for this, but here's a little code I cam up with.
emit("add %i %i %i", r1, r2, const("k(1)"))
So basically const
would check if the constant index is less than 256 and if so it will just return the index. Otherwise, it will emit a loadk instruction to load the constant into a register and const
will return the register instead.
In the end, the code would either be something like this
add 4 5 k(1)
or this
loadk 6 k(1)
add 4 5 6
Yea that's exactly what I have. But it's giving me issues where the system hangs and just completely stops. Doesn't crash to a "too long without yielding" or anything. Just stops the whole computer. This is getting nuts
I've had the same issue pretty much any time I accidentally create an infinite loop with raw bytecode. I don't really know why it kills the computer.
I added you as a collaborator to the LAT fork so you can make any changes if you need to.
Hm good to know. I can't imagine what would be causing that though.... This rabbit hole is so deep...
And cool. I'll push when I like my changes
Many Lua instructions (like
add
) are only able to reference constants below 256. Usingloadk
, we can index 2^18 constants, but this requires one extra instruction. A good system would be situational and only use the extraloadk
instruction when the index is too high.