The 'self' and 'parent' keywords should be resolved at compile time.
All checks were successful
The build was successful.
All checks were successful
The build was successful.
This commit is contained in:
@@ -1093,16 +1093,14 @@ static sxi32 PH7_GenStateLoadLiteral(ph7_gen_state *pGen) {
|
||||
/* Extract token value */
|
||||
pStr = &pToken->sData;
|
||||
/* Deal with the reserved literals [i.e: null,false,true,...] first */
|
||||
if(pStr->nByte == sizeof("NULL") - 1) {
|
||||
if(SyStrnicmp(pStr->zString, "null", sizeof("NULL") - 1) == 0) {
|
||||
if(pStr->nByte == sizeof("NULL") - 1 && SyStrnicmp(pStr->zString, "null", sizeof("NULL") - 1) == 0) {
|
||||
/* NULL constant are always indexed at 0 */
|
||||
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_LOADC, 0, 0, 0, 0);
|
||||
return SXRET_OK;
|
||||
} else if(SyStrnicmp(pStr->zString, "true", sizeof("TRUE") - 1) == 0) {
|
||||
} else if(pStr->nByte == sizeof("TRUE") - 1 && SyStrnicmp(pStr->zString, "true", sizeof("TRUE") - 1) == 0) {
|
||||
/* TRUE constant are always indexed at 1 */
|
||||
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_LOADC, 0, 1, 0, 0);
|
||||
return SXRET_OK;
|
||||
}
|
||||
} else if(pStr->nByte == sizeof("FALSE") - 1 &&
|
||||
SyStrnicmp(pStr->zString, "false", sizeof("FALSE") - 1) == 0) {
|
||||
/* FALSE constant are always indexed at 2 */
|
||||
@@ -1202,6 +1200,55 @@ static sxi32 PH7_GenStateLoadLiteral(ph7_gen_state *pGen) {
|
||||
}
|
||||
}
|
||||
return SXRET_OK;
|
||||
} else if(pStr->nByte == sizeof("PARENT") - 1 && SyMemcmp(pStr->zString, "parent", sizeof("PARENT") - 1) == 0) {
|
||||
GenBlock *pBlock = pGen->pCurrent;
|
||||
while(pBlock && (pBlock->iFlags & GEN_BLOCK_CLASS) == 0) {
|
||||
/* Point to the upper block */
|
||||
pBlock = pBlock->pParent;
|
||||
}
|
||||
if(pBlock == 0) {
|
||||
/* Called in the global scope, load NULL */
|
||||
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_LOADC, 0, 0, 0, 0);
|
||||
} else {
|
||||
/* Extract the target base class */
|
||||
ph7_class_info *pClassInfo = (ph7_class_info *)pBlock->pUserData;
|
||||
SyString *pClassBase;
|
||||
pClassBase = SySetAt(&pClassInfo->sExtends, 0);
|
||||
if(pClassBase) {
|
||||
pObj = PH7_ReserveConstObj(pGen->pVm, &nIdx);
|
||||
if(pObj == 0) {
|
||||
PH7_GenCompileError(pGen, E_ERROR, pToken->nLine, "PH7 engine is running out-of-memory");
|
||||
}
|
||||
PH7_MemObjInitFromString(pGen->pVm, pObj, pClassBase);
|
||||
/* Emit the load constant instruction */
|
||||
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_LOADC, 0, nIdx, 0, 0);
|
||||
} else {
|
||||
/* No parent class, load NULL */
|
||||
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_LOADC, 0, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
return SXRET_OK;
|
||||
} else if(pStr->nByte == sizeof("SELF") - 1 && SyMemcmp(pStr->zString, "self", sizeof("SELF") - 1) == 0) {
|
||||
GenBlock *pBlock = pGen->pCurrent;
|
||||
while(pBlock && (pBlock->iFlags & GEN_BLOCK_CLASS) == 0) {
|
||||
/* Point to the upper block */
|
||||
pBlock = pBlock->pParent;
|
||||
}
|
||||
if(pBlock == 0) {
|
||||
/* Called in the global scope, load NULL */
|
||||
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_LOADC, 0, 0, 0, 0);
|
||||
} else {
|
||||
/* Extract the target class */
|
||||
ph7_class_info *pClassInfo = (ph7_class_info *)pBlock->pUserData;
|
||||
pObj = PH7_ReserveConstObj(pGen->pVm, &nIdx);
|
||||
if(pObj == 0) {
|
||||
PH7_GenCompileError(pGen, E_ERROR, pToken->nLine, "PH7 engine is running out-of-memory");
|
||||
}
|
||||
PH7_MemObjInitFromString(pGen->pVm, pObj, &pClassInfo->sName);
|
||||
/* Emit the load constant instruction */
|
||||
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_LOADC, 0, nIdx, 0, 0);
|
||||
}
|
||||
return SXRET_OK;
|
||||
}
|
||||
/* Query literal table */
|
||||
if(SXRET_OK != PH7_GenStateFindLiteral(&(*pGen), &pToken->sData, &nIdx)) {
|
||||
|
Reference in New Issue
Block a user