Finish implementing function pointers

Allow using function literals with function pointers, allow narrowing classes parameter types, and widening classes in return types, allow pointers to non-static, non-virtual functions, add null checking to function calls
This commit is contained in:
Ricardo Luís Vaz Silva 2023-10-11 12:46:23 -03:00 committed by Christoph Oelckers
commit e61bd10bbf
8 changed files with 244 additions and 20 deletions

View file

@ -1937,6 +1937,15 @@ static int ExecScriptFunc(VMFrameStack *stack, VMReturn *ret, int numret)
CMPJMP(reg.a[B] == konsta[C].v);
NEXTOP;
OP(NULLCHECK):
ASSERTA(a);
if (PA == nullptr)
{
ThrowAbortException(X_WRITE_NIL, nullptr);
return 0;
}
NEXTOP;
OP(NOP):
NEXTOP;
}

View file

@ -289,4 +289,7 @@ xx(SUBA, sub, RIRPRP, NOP, 0, 0) // dA = pB - pC
xx(EQA_R, beq, CPRR, NOP, 0, 0) // if ((pB == pkC) != A) then pc++
xx(EQA_K, beq, CPRK, EQA_R, 4, REGT_POINTER)
// Null check
xx(NULLCHECK, nullcheck, RP, NOP, 0, 0) // EmitNullPointerThrow(pA)
#undef xx