Actually, I can satisfy my requirements with lightning as it stands without hacks. My generated code _would_ become a bit faster if lightning had the following possibility:
ref = jit_movi(REGISTER, 0)
jit_relative_patch_at(ref, label1, label2, const)
this would cause the movi instruction to be patched to jit_address(label2) - jit_address(label 1) + const. This would effectively allow me put in the register the address of label 2 relative to the address of label 1, and add a constant on top of that. Even without the constant that would already improve my code.
Currently I am simulating the above by doing the following:
ref = jit_movi(REGISTER, 0)
jit_subr(REGISTER, REGISTER, V1)
jit_patch_at(ref, label2)
And the main function that is emitted accepts an argument which it immediately puts in V1. Then I call this function with that argument set to jit_address(label1) + const. This works because label1 is always the same on every instance where I want to apply the trick above (actually label1 = jit_address(first_line_of_code)).
alternatively, some instruction like
ref = jit_movi(REGISTER, 0)
...
jit_emit()
jit_repatch_abs(ref, abs_value)
which would be called *after* jit_emit and would change the code of the movi instruction to have some absolute value instead of 0. I really do not know how the immediate of the movi instruction is stored (you told me it was in the code, not in the data buffer), but maybe this is not hard to change even after the code emission?
It seems a bit over the top to implement all of the things you mentioned just to fix this small problem. I would suggest that you don't do that unless someone else also asks for it.