🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

CallSystemFunction signature change

Started by
5 comments, last by gjl 9 years, 1 month ago

Hi,

I am trying to migrate to the latest version of Angelscript, and the JIT by BlindMind Studios uses the CallSystemFunction method as a fallback to let the script engine call the function:


if(objPointer)
   cpu.call_cdecl((void*)CallSystemFunction,"cmr",func->GetId(),&ctxPtr,objPointer);
else
   cpu.call_cdecl((void*)CallSystemFunction,"cmp",func->GetId(),&ctxPtr,nullptr);

However the signature of the function has changed (the object pointer has been removed). So I guess the object pointer is supposed to be passed directly using the context, the stack or a register, but I have not been able to find out how as there seem to be many cases. Any idea?

If the new way of passing the pointer is really specific, would it maybe be possible to add a new function to the engine that restores this capability to make sure it is properly encapsulated?

Advertisement

The change in the internal CallSystemFunction was done in revision 2073 back in November last year. I was not aware the JIT is using the internal function as fallback.

I'm not certain in which situations the JIT would need to fallback to CallSystemFunction, doing so would lose a lot of the benefit that the JIT compilation provides in the first place.

Anyway, the only time the object pointer was previously passed in as argument to CallSystemFunction was for the asBC_ALLOC bytecode instruction. With the change the object pointer is instead pushed onto the context's stack before calling CallSystemFunction. If the JIT is using the CallSystemFunction in this scenario, then it will have to make the same change to push the object pointer on the context's stack.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Thanks for the reply. I think it is actually used in other scenarios as well, so it is maybe not straightforward. I will still try though! Do you think you have removed some other cases from the implementation or is it just the way the object pointer is passed (I am not sure when looking at the diff)?

Sorry for the newbie question: to push the pointer on the context stack, should I use the SetObject method on the context or is it not the right approach? Also, is there any cleanup to do after calling the function?

I'm not certain how you would do it from the JIT, but if you check the diff you can see that inside the VM (asCContext) I do it like this:

// Push the object pointer on the stack (it will be popped by the function)
l_sp -= AS_PTR_SIZE;
*(asPWORD*)l_sp = (asPWORD)mem;

l_sp is the stackpointer. This is also available to the JIT in the asSVMRegisters registers that the JIT compiled function receives.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Thanks. I'll have a deeper look at it. I think I that's what I have tried to do but it may have not done it the right way.I am not an expert of the JIT yet smile.png

FYI I posted a ticket on the JIT repo as well: https://github.com/BlindMindStudios/AngelScript-JIT-Compiler/issues/18

Maybe I too will try to make it work looking at the AS diff.

Yes i have noticed the ticket. I haven't had much time to work on it lately so I haven't made any progress on this topic.

This topic is closed to new replies.

Advertisement