Everyone here is likely already on the shakti mailing list; but if you are not like myself, reddit.com/r/apljk/comments/fjdefh/… , you'll find this interesting
@ngn i meant to create a global list for int and float constants, every time a int/float constant is declared, it's found/allocated in that global list instead of allocate and free it using the memory management. hopefully this way will be faster and save some memory. but ofc, in a real world use case, there aren't that many numeral constants after all. so, maybe save some byte code for the most common constants?
i know that q/k4 have special byte code for constant 0 and 1, but others like 0n 0w -0w maybe useful too
@ksi constants are already stored in a list - not globally, just per function. see the last element of .{1+x} for example. i like the idea to use bytecode instructions for common constants.
@ksi i don't know. i thought it might be fixed-point (as opposed to floating-)
@ngn yeah, but the last element of .{1+x} is a general list right? to allocate a constant 1, you have to call the ma() again. oh, fixed point, must be it.
@ksi yes, it's always a generic list. what do you mean by allocate a constant 1? there's an instruction that gets the existing object from that list, puts it on the stack, and increments its refcount. there are no new allocations if you're just using a constant from your k code.
that's for 64-bit longs. as for 32-bit ints - they don't need to bother the memory manager at all. the 32-bit value is stored as part of the "tagged pointer" (which isn't really a "pointer" in this case..)
@ngn right, for a function, the constant list have the same life span as the function itself. so, we do not expect a defined function to die any soon. i was thinking about the expression evaluated in the repl
@ksi yeah.. and i thought -1 would be closer to the top
@ksi there's a more lucrative optimization - "constant folding". any subexpression involving only constants and operations on small enough constants could be pre-evaluated by the bytecode compiler. @ktye already did this