Sign in to follow this  
gjl

CallSystemFunction signature change

Recommended Posts

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?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this