Test and temporary version of compiler emiting PH7_OP_CLASS_INIT instruction.
However it works on ph7_class and thus passes whole class into the VM, what causes memory overhead, as finally we have to find this class on the VM's stack. Instead, we could pass some ph7_class_info structure containing a name of class to look for and information about its inheritances.
This commit is contained in:
41
engine/vm.c
41
engine/vm.c
@@ -4508,6 +4508,41 @@ static sxi32 VmByteCodeExec(
|
||||
pc = nJump - 1;
|
||||
break;
|
||||
}
|
||||
/*
|
||||
* OP_CLASS_INIT P1 P2 P3
|
||||
* Perform additional class initialization, by adding base classes
|
||||
* and interfaces to its definition.
|
||||
*/
|
||||
case PH7_OP_CLASS_INIT:
|
||||
{
|
||||
ph7_class *pClass = (ph7_class *)pInstr->p3;
|
||||
printf("Called by class: '%s'\n", pClass->sName);
|
||||
if(pInstr->iP1) {
|
||||
/* This class inherits from other classes */
|
||||
SyString *apExtends;
|
||||
while(SySetGetNextEntry(&pClass->sExtends, (void **)&apExtends) == SXRET_OK) {
|
||||
printf("Class '%s' inherits from '%s'\n", pClass->sName.zString, apExtends->zString);
|
||||
}
|
||||
}
|
||||
if(pInstr->iP2) {
|
||||
/* This class implements some interfaces */
|
||||
SyString *apImplements;
|
||||
while(SySetGetNextEntry(&pClass->sImplements, (void **)&apImplements) == SXRET_OK) {
|
||||
printf("Class '%s' implements '%s'\n", pClass->sName.zString, apImplements->zString);
|
||||
}
|
||||
}
|
||||
SyStringInitFromBuf(&pClass->sName, "DUPA", 4);
|
||||
break;
|
||||
}
|
||||
/*
|
||||
* OP_INTERFACE_INIT * * P3
|
||||
* Perform additional interface initialization, by adding base interfaces
|
||||
* to its definition.
|
||||
*/
|
||||
case PH7_OP_INTERFACE_INIT:
|
||||
{
|
||||
break;
|
||||
}
|
||||
/*
|
||||
* OP_FOREACH_INIT * P2 P3
|
||||
* Prepare a foreach step.
|
||||
@@ -6025,6 +6060,12 @@ static const char *VmInstrToString(sxi32 nOp) {
|
||||
case PH7_OP_THROW:
|
||||
zOp = "THROW ";
|
||||
break;
|
||||
case PH7_OP_CLASS_INIT:
|
||||
zOp = "CLASS_INIT ";
|
||||
break;
|
||||
case PH7_OP_INTERFACE_INIT:
|
||||
zOp = "INTER_INIT ";
|
||||
break;
|
||||
case PH7_OP_FOREACH_INIT:
|
||||
zOp = "4EACH_INIT ";
|
||||
break;
|
||||
|
Reference in New Issue
Block a user