Because I have not yet figured out how to start executing at somewhere other than the beginning of the generated code, and because I don’t store generated code in any intermediate buffers, and because we don’t know the sizes of any code in advance, I do this funky thing where I emit a jmp to the body code.
If you, dear reader, have a better solution, please let me know.
Assuming you know the byte offset into the code buffer, of your "main" equivalent label, you should be able to use the following:
byte* start_address = buf->address + offset;
JitFunction function = *(JitFunction*)(&start_address);
return function(heap);
I'm guessing you were running into the issue that you can't do this in one line while also suppressing the warning about the data pointer to function pointer.The "normal" way to do this would be the following, but it has the downside of the compiler warning:
JitFunction function = (JitFunction)(buf->address + offset);
return function(heap);