Allow compiler to specify line number, on which instruction has been generated.
The build was successful.
Details
The build was successful.
Details
This also fixes line number on OP_CLASS_INIT and OP_INTERFACE_INIT.
This commit is contained in:
parent
543176a2f4
commit
894dbe47d6
|
@ -269,7 +269,7 @@ static sxi32 PH7_CompileNumLiteral(ph7_gen_state *pGen, sxi32 iCompileFlag) {
|
||||||
PH7_MemObjToReal(pObj);
|
PH7_MemObjToReal(pObj);
|
||||||
}
|
}
|
||||||
/* Emit the load constant instruction */
|
/* Emit the load constant instruction */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_LOADC, 0, nIdx, 0, 0);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_LOADC, 0, nIdx, 0, 0);
|
||||||
/* Node successfully compiled */
|
/* Node successfully compiled */
|
||||||
return SXRET_OK;
|
return SXRET_OK;
|
||||||
}
|
}
|
||||||
|
@ -295,7 +295,7 @@ PH7_PRIVATE sxi32 PH7_CompileSimpleString(ph7_gen_state *pGen, sxi32 iCompileFla
|
||||||
/* Already processed,emit the load constant instruction
|
/* Already processed,emit the load constant instruction
|
||||||
* and return.
|
* and return.
|
||||||
*/
|
*/
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_LOADC, 0, nIdx, 0, 0);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_LOADC, 0, nIdx, 0, 0);
|
||||||
return SXRET_OK;
|
return SXRET_OK;
|
||||||
}
|
}
|
||||||
/* Reserve a new constant */
|
/* Reserve a new constant */
|
||||||
|
@ -339,7 +339,7 @@ PH7_PRIVATE sxi32 PH7_CompileSimpleString(ph7_gen_state *pGen, sxi32 iCompileFla
|
||||||
zIn++;
|
zIn++;
|
||||||
}
|
}
|
||||||
/* Emit the load constant instruction */
|
/* Emit the load constant instruction */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_LOADC, 0, nIdx, 0, 0);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_LOADC, 0, nIdx, 0, 0);
|
||||||
if(pStr->nByte < 1024) {
|
if(pStr->nByte < 1024) {
|
||||||
/* Install in the literal table */
|
/* Install in the literal table */
|
||||||
PH7_GenStateInstallLiteral(pGen, pObj, nIdx);
|
PH7_GenStateInstallLiteral(pGen, pObj, nIdx);
|
||||||
|
@ -413,7 +413,7 @@ static ph7_value *PH7_GenStateNewStrObj(ph7_gen_state *pGen, sxi32 *pCount) {
|
||||||
(*pCount)++;
|
(*pCount)++;
|
||||||
PH7_MemObjInitFromString(pGen->pVm, pConstObj, 0);
|
PH7_MemObjInitFromString(pGen->pVm, pConstObj, 0);
|
||||||
/* Emit the load constant instruction */
|
/* Emit the load constant instruction */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_LOADC, 0, nIdx, 0, 0);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_LOADC, 0, nIdx, 0, 0);
|
||||||
return pConstObj;
|
return pConstObj;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
@ -701,7 +701,7 @@ static sxi32 PH7_GenStateCompileString(ph7_gen_state *pGen) {
|
||||||
}/*for(;;)*/
|
}/*for(;;)*/
|
||||||
if(iCons > 1) {
|
if(iCons > 1) {
|
||||||
/* Concatenate all compiled constants */
|
/* Concatenate all compiled constants */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_ADD, iCons, 1, 0, 0);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_ADD, iCons, 1, 0, 0);
|
||||||
}
|
}
|
||||||
/* Node successfully compiled */
|
/* Node successfully compiled */
|
||||||
return SXRET_OK;
|
return SXRET_OK;
|
||||||
|
@ -861,7 +861,7 @@ PH7_PRIVATE sxi32 PH7_CompileArray(ph7_gen_state *pGen, sxi32 iCompileFlag) {
|
||||||
}
|
}
|
||||||
if(rc == SXERR_EMPTY) {
|
if(rc == SXERR_EMPTY) {
|
||||||
/* No available key,load NULL */
|
/* No available key,load NULL */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_LOADC, 0, 0 /* nil index */, 0, 0);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_LOADC, 0, 0 /* nil index */, 0, 0);
|
||||||
}
|
}
|
||||||
if(pCur->nType & PH7_TK_AMPER /*'&'*/) {
|
if(pCur->nType & PH7_TK_AMPER /*'&'*/) {
|
||||||
/* Insertion by reference, [i.e: $a = array(&$x);] */
|
/* Insertion by reference, [i.e: $a = array(&$x);] */
|
||||||
|
@ -884,14 +884,14 @@ PH7_PRIVATE sxi32 PH7_CompileArray(ph7_gen_state *pGen, sxi32 iCompileFlag) {
|
||||||
}
|
}
|
||||||
if(iEmitRef) {
|
if(iEmitRef) {
|
||||||
/* Emit the load reference instruction */
|
/* Emit the load reference instruction */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_LOAD_REF, 0, 0, 0, 0);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_LOAD_REF, 0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
xValidator = 0;
|
xValidator = 0;
|
||||||
iEmitRef = 0;
|
iEmitRef = 0;
|
||||||
nPair++;
|
nPair++;
|
||||||
}
|
}
|
||||||
/* Emit the load map instruction */
|
/* Emit the load map instruction */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_LOAD_MAP, nPair * 2, 0, 0, 0);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_LOAD_MAP, nPair * 2, 0, 0, 0);
|
||||||
/* Node successfully compiled */
|
/* Node successfully compiled */
|
||||||
return SXRET_OK;
|
return SXRET_OK;
|
||||||
}
|
}
|
||||||
|
@ -957,14 +957,14 @@ PH7_PRIVATE sxi32 PH7_CompileList(ph7_gen_state *pGen, sxi32 iCompileFlag) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* Empty entry,load NULL */
|
/* Empty entry,load NULL */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_LOADC, 0, 0/* NULL index */, 0, 0);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_LOADC, 0, 0/* NULL index */, 0, 0);
|
||||||
}
|
}
|
||||||
nExpr++;
|
nExpr++;
|
||||||
/* Advance the stream cursor */
|
/* Advance the stream cursor */
|
||||||
pGen->pIn = &pNext[1];
|
pGen->pIn = &pNext[1];
|
||||||
}
|
}
|
||||||
/* Emit the LOAD_LIST instruction */
|
/* Emit the LOAD_LIST instruction */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_LOAD_LIST, nExpr, 0, 0, 0);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_LOAD_LIST, nExpr, 0, 0, 0);
|
||||||
/* Node successfully compiled */
|
/* Node successfully compiled */
|
||||||
return SXRET_OK;
|
return SXRET_OK;
|
||||||
}
|
}
|
||||||
|
@ -1020,10 +1020,10 @@ PH7_PRIVATE sxi32 PH7_CompileClosure(ph7_gen_state *pGen, sxi32 iCompileFlag) {
|
||||||
}
|
}
|
||||||
if(pAnonFunc->iFlags & VM_FUNC_CLOSURE) {
|
if(pAnonFunc->iFlags & VM_FUNC_CLOSURE) {
|
||||||
/* Emit the load closure instruction */
|
/* Emit the load closure instruction */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_LOAD_CLOSURE, 0, 0, pAnonFunc, 0);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_LOAD_CLOSURE, 0, 0, pAnonFunc, 0);
|
||||||
} else {
|
} else {
|
||||||
/* Emit the load constant instruction */
|
/* Emit the load constant instruction */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_LOADC, 0, nIdx, 0, 0);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_LOADC, 0, nIdx, 0, 0);
|
||||||
}
|
}
|
||||||
/* Node successfully compiled */
|
/* Node successfully compiled */
|
||||||
return SXRET_OK;
|
return SXRET_OK;
|
||||||
|
@ -1062,8 +1062,8 @@ PH7_PRIVATE sxi32 PH7_CompileLangConstruct(ph7_gen_state *pGen, sxi32 iCompileFl
|
||||||
PH7_GenStateInstallLiteral(&(*pGen), pObj, nIdx);
|
PH7_GenStateInstallLiteral(&(*pGen), pObj, nIdx);
|
||||||
}
|
}
|
||||||
/* Emit the call instruction */
|
/* Emit the call instruction */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_LOADC, 0, nIdx, 0, 0);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_LOADC, 0, nIdx, 0, 0);
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_CALL, nArg, 0, 0, 0);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_CALL, nArg, 0, 0, 0);
|
||||||
/* Node successfully compiled */
|
/* Node successfully compiled */
|
||||||
return SXRET_OK;
|
return SXRET_OK;
|
||||||
}
|
}
|
||||||
|
@ -1157,9 +1157,9 @@ PH7_PRIVATE sxi32 PH7_CompileVariable(ph7_gen_state *pGen, sxi32 iCompileFlag) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Emit the load instruction */
|
/* Emit the load instruction */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_LOAD, iP1, 0, p3, 0);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_LOAD, iP1, 0, p3, 0);
|
||||||
while(iVv > 0) {
|
while(iVv > 0) {
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_LOAD, iP1, 0, 0, 0);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_LOAD, iP1, 0, 0, 0);
|
||||||
iVv--;
|
iVv--;
|
||||||
}
|
}
|
||||||
/* Node successfully compiled */
|
/* Node successfully compiled */
|
||||||
|
@ -1179,17 +1179,17 @@ static sxi32 PH7_GenStateLoadLiteral(ph7_gen_state *pGen) {
|
||||||
if(pStr->nByte == sizeof("NULL") - 1) {
|
if(pStr->nByte == sizeof("NULL") - 1) {
|
||||||
if(SyStrnicmp(pStr->zString, "null", sizeof("NULL") - 1) == 0) {
|
if(SyStrnicmp(pStr->zString, "null", sizeof("NULL") - 1) == 0) {
|
||||||
/* NULL constant are always indexed at 0 */
|
/* NULL constant are always indexed at 0 */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_LOADC, 0, 0, 0, 0);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_LOADC, 0, 0, 0, 0);
|
||||||
return SXRET_OK;
|
return SXRET_OK;
|
||||||
} else if(SyStrnicmp(pStr->zString, "true", sizeof("TRUE") - 1) == 0) {
|
} else if(SyStrnicmp(pStr->zString, "true", sizeof("TRUE") - 1) == 0) {
|
||||||
/* TRUE constant are always indexed at 1 */
|
/* TRUE constant are always indexed at 1 */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_LOADC, 0, 1, 0, 0);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_LOADC, 0, 1, 0, 0);
|
||||||
return SXRET_OK;
|
return SXRET_OK;
|
||||||
}
|
}
|
||||||
} else if(pStr->nByte == sizeof("FALSE") - 1 &&
|
} else if(pStr->nByte == sizeof("FALSE") - 1 &&
|
||||||
SyStrnicmp(pStr->zString, "false", sizeof("FALSE") - 1) == 0) {
|
SyStrnicmp(pStr->zString, "false", sizeof("FALSE") - 1) == 0) {
|
||||||
/* FALSE constant are always indexed at 2 */
|
/* FALSE constant are always indexed at 2 */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_LOADC, 0, 2, 0, 0);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_LOADC, 0, 2, 0, 0);
|
||||||
return SXRET_OK;
|
return SXRET_OK;
|
||||||
} else if(pStr->nByte == sizeof("__LINE__") - 1 &&
|
} else if(pStr->nByte == sizeof("__LINE__") - 1 &&
|
||||||
SyMemcmp(pStr->zString, "__LINE__", sizeof("__LINE__") - 1) == 0) {
|
SyMemcmp(pStr->zString, "__LINE__", sizeof("__LINE__") - 1) == 0) {
|
||||||
|
@ -1201,7 +1201,7 @@ static sxi32 PH7_GenStateLoadLiteral(ph7_gen_state *pGen) {
|
||||||
}
|
}
|
||||||
PH7_MemObjInitFromInt(pGen->pVm, pObj, pToken->nLine);
|
PH7_MemObjInitFromInt(pGen->pVm, pObj, pToken->nLine);
|
||||||
/* Emit the load constant instruction */
|
/* Emit the load constant instruction */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_LOADC, 0, nIdx, 0, 0);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_LOADC, 0, nIdx, 0, 0);
|
||||||
return SXRET_OK;
|
return SXRET_OK;
|
||||||
} else if((pStr->nByte == sizeof("__FILE__") - 1 &&
|
} else if((pStr->nByte == sizeof("__FILE__") - 1 &&
|
||||||
SyMemcmp(pStr->zString, "__FILE__", sizeof("__FILE__") - 1) == 0) ||
|
SyMemcmp(pStr->zString, "__FILE__", sizeof("__FILE__") - 1) == 0) ||
|
||||||
|
@ -1234,7 +1234,7 @@ static sxi32 PH7_GenStateLoadLiteral(ph7_gen_state *pGen) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Emit the load constant instruction */
|
/* Emit the load constant instruction */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_LOADC, 0, nIdx, 0, 0);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_LOADC, 0, nIdx, 0, 0);
|
||||||
return SXRET_OK;
|
return SXRET_OK;
|
||||||
} else if(pStr->nByte == sizeof("__CLASS__") - 1 && SyMemcmp(pStr->zString, "__CLASS__", sizeof("__CLASS__") - 1) == 0) {
|
} else if(pStr->nByte == sizeof("__CLASS__") - 1 && SyMemcmp(pStr->zString, "__CLASS__", sizeof("__CLASS__") - 1) == 0) {
|
||||||
GenBlock *pBlock = pGen->pCurrent;
|
GenBlock *pBlock = pGen->pCurrent;
|
||||||
|
@ -1244,7 +1244,7 @@ static sxi32 PH7_GenStateLoadLiteral(ph7_gen_state *pGen) {
|
||||||
}
|
}
|
||||||
if(pBlock == 0) {
|
if(pBlock == 0) {
|
||||||
/* Called in the global scope,load NULL */
|
/* Called in the global scope,load NULL */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_LOADC, 0, 0, 0, 0);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_LOADC, 0, 0, 0, 0);
|
||||||
} else {
|
} else {
|
||||||
/* Extract the target class */
|
/* Extract the target class */
|
||||||
ph7_class_info *pClassInfo = (ph7_class_info *)pBlock->pUserData;
|
ph7_class_info *pClassInfo = (ph7_class_info *)pBlock->pUserData;
|
||||||
|
@ -1255,7 +1255,7 @@ static sxi32 PH7_GenStateLoadLiteral(ph7_gen_state *pGen) {
|
||||||
}
|
}
|
||||||
PH7_MemObjInitFromString(pGen->pVm, pObj, &pClassInfo->sName);
|
PH7_MemObjInitFromString(pGen->pVm, pObj, &pClassInfo->sName);
|
||||||
/* Emit the load constant instruction */
|
/* Emit the load constant instruction */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_LOADC, 0, nIdx, 0, 0);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_LOADC, 0, nIdx, 0, 0);
|
||||||
}
|
}
|
||||||
return SXRET_OK;
|
return SXRET_OK;
|
||||||
} else if((pStr->nByte == sizeof("__FUNCTION__") - 1 &&
|
} else if((pStr->nByte == sizeof("__FUNCTION__") - 1 &&
|
||||||
|
@ -1270,13 +1270,13 @@ static sxi32 PH7_GenStateLoadLiteral(ph7_gen_state *pGen) {
|
||||||
}
|
}
|
||||||
if(pBlock == 0) {
|
if(pBlock == 0) {
|
||||||
/* Called in the global scope,load NULL */
|
/* Called in the global scope,load NULL */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_LOADC, 0, 0, 0, 0);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_LOADC, 0, 0, 0, 0);
|
||||||
} else {
|
} else {
|
||||||
/* Extract the target function/method */
|
/* Extract the target function/method */
|
||||||
ph7_vm_func *pFunc = (ph7_vm_func *)pBlock->pUserData;
|
ph7_vm_func *pFunc = (ph7_vm_func *)pBlock->pUserData;
|
||||||
if(pStr->zString[2] == 'M' /* METHOD */ && (pFunc->iFlags & VM_FUNC_CLASS_METHOD) == 0) {
|
if(pStr->zString[2] == 'M' /* METHOD */ && (pFunc->iFlags & VM_FUNC_CLASS_METHOD) == 0) {
|
||||||
/* Not a class method,Load null */
|
/* Not a class method,Load null */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_LOADC, 0, 0, 0, 0);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_LOADC, 0, 0, 0, 0);
|
||||||
} else {
|
} else {
|
||||||
pObj = PH7_ReserveConstObj(pGen->pVm, &nIdx);
|
pObj = PH7_ReserveConstObj(pGen->pVm, &nIdx);
|
||||||
if(pObj == 0) {
|
if(pObj == 0) {
|
||||||
|
@ -1285,7 +1285,7 @@ static sxi32 PH7_GenStateLoadLiteral(ph7_gen_state *pGen) {
|
||||||
}
|
}
|
||||||
PH7_MemObjInitFromString(pGen->pVm, pObj, &pFunc->sName);
|
PH7_MemObjInitFromString(pGen->pVm, pObj, &pFunc->sName);
|
||||||
/* Emit the load constant instruction */
|
/* Emit the load constant instruction */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_LOADC, 0, nIdx, 0, 0);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_LOADC, 0, nIdx, 0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return SXRET_OK;
|
return SXRET_OK;
|
||||||
|
@ -1303,7 +1303,7 @@ static sxi32 PH7_GenStateLoadLiteral(ph7_gen_state *pGen) {
|
||||||
PH7_GenStateInstallLiteral(&(*pGen), pObj, nIdx);
|
PH7_GenStateInstallLiteral(&(*pGen), pObj, nIdx);
|
||||||
}
|
}
|
||||||
/* Emit the load constant instruction */
|
/* Emit the load constant instruction */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_LOADC, 1, nIdx, 0, 0);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_LOADC, 1, nIdx, 0, 0);
|
||||||
return SXRET_OK;
|
return SXRET_OK;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
@ -1447,7 +1447,7 @@ static sxi32 PH7_CompileConstant(ph7_gen_state *pGen) {
|
||||||
/* Compile constant value */
|
/* Compile constant value */
|
||||||
rc = PH7_CompileExpr(&(*pGen), 0, 0);
|
rc = PH7_CompileExpr(&(*pGen), 0, 0);
|
||||||
/* Emit the done instruction */
|
/* Emit the done instruction */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_DONE, (rc != SXERR_EMPTY ? 1 : 0), 0, 0, 0);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_DONE, (rc != SXERR_EMPTY ? 1 : 0), 0, 0, 0);
|
||||||
PH7_VmSetByteCodeContainer(pGen->pVm, pInstrContainer);
|
PH7_VmSetByteCodeContainer(pGen->pVm, pInstrContainer);
|
||||||
if(rc == SXERR_ABORT) {
|
if(rc == SXERR_ABORT) {
|
||||||
/* Don't worry about freeing memory, everything will be released shortly */
|
/* Don't worry about freeing memory, everything will be released shortly */
|
||||||
|
@ -1516,13 +1516,13 @@ static sxi32 PH7_CompileContinue(ph7_gen_state *pGen) {
|
||||||
* and acts similar to break. If you have a switch inside a loop and wish to continue
|
* and acts similar to break. If you have a switch inside a loop and wish to continue
|
||||||
* to the next iteration of the outer loop, use continue 2.
|
* to the next iteration of the outer loop, use continue 2.
|
||||||
*/
|
*/
|
||||||
rc = PH7_VmEmitInstr(pGen->pVm, PH7_OP_JMP, 0, 0, 0, &nInstrIdx);
|
rc = PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_JMP, 0, 0, 0, &nInstrIdx);
|
||||||
if(rc == SXRET_OK) {
|
if(rc == SXRET_OK) {
|
||||||
PH7_GenStateNewJumpFixup(pLoop, PH7_OP_JMP, nInstrIdx);
|
PH7_GenStateNewJumpFixup(pLoop, PH7_OP_JMP, nInstrIdx);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* Emit the unconditional jump to the beginning of the target loop */
|
/* Emit the unconditional jump to the beginning of the target loop */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_JMP, 0, pLoop->nFirstInstr, 0, &nInstrIdx);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_JMP, 0, pLoop->nFirstInstr, 0, &nInstrIdx);
|
||||||
if(pLoop->bPostContinue == TRUE) {
|
if(pLoop->bPostContinue == TRUE) {
|
||||||
JumpFixup sJumpFix;
|
JumpFixup sJumpFix;
|
||||||
/* Post-continue */
|
/* Post-continue */
|
||||||
|
@ -1576,7 +1576,7 @@ static sxi32 PH7_CompileBreak(ph7_gen_state *pGen) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sxu32 nInstrIdx;
|
sxu32 nInstrIdx;
|
||||||
rc = PH7_VmEmitInstr(pGen->pVm, PH7_OP_JMP, 0, 0, 0, &nInstrIdx);
|
rc = PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_JMP, 0, 0, 0, &nInstrIdx);
|
||||||
if(rc == SXRET_OK) {
|
if(rc == SXRET_OK) {
|
||||||
/* Fix the jump later when the jump destination is resolved */
|
/* Fix the jump later when the jump destination is resolved */
|
||||||
PH7_GenStateNewJumpFixup(pLoop, PH7_OP_JMP, nInstrIdx);
|
PH7_GenStateNewJumpFixup(pLoop, PH7_OP_JMP, nInstrIdx);
|
||||||
|
@ -1739,7 +1739,7 @@ static sxi32 PH7_CompileWhile(ph7_gen_state *pGen) {
|
||||||
pGen->pIn = &pEnd[1];
|
pGen->pIn = &pEnd[1];
|
||||||
pGen->pEnd = pTmp;
|
pGen->pEnd = pTmp;
|
||||||
/* Emit the false jump */
|
/* Emit the false jump */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_JZ, 0, 0, 0, &nFalseJump);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_JZ, 0, 0, 0, &nFalseJump);
|
||||||
/* Save the instruction index so we can fix it later when the jump destination is resolved */
|
/* Save the instruction index so we can fix it later when the jump destination is resolved */
|
||||||
PH7_GenStateNewJumpFixup(pWhileBlock, PH7_OP_JZ, nFalseJump);
|
PH7_GenStateNewJumpFixup(pWhileBlock, PH7_OP_JZ, nFalseJump);
|
||||||
/* Compile the loop body */
|
/* Compile the loop body */
|
||||||
|
@ -1748,7 +1748,7 @@ static sxi32 PH7_CompileWhile(ph7_gen_state *pGen) {
|
||||||
return SXERR_ABORT;
|
return SXERR_ABORT;
|
||||||
}
|
}
|
||||||
/* Emit the unconditional jump to the start of the loop */
|
/* Emit the unconditional jump to the start of the loop */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_JMP, 0, pWhileBlock->nFirstInstr, 0, 0);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_JMP, 0, pWhileBlock->nFirstInstr, 0, 0);
|
||||||
/* Fix all jumps now the destination is resolved */
|
/* Fix all jumps now the destination is resolved */
|
||||||
PH7_GenStateFixJumps(pWhileBlock, -1, PH7_VmInstrLength(pGen->pVm));
|
PH7_GenStateFixJumps(pWhileBlock, -1, PH7_VmInstrLength(pGen->pVm));
|
||||||
/* Release the loop block */
|
/* Release the loop block */
|
||||||
|
@ -1871,7 +1871,7 @@ static sxi32 PH7_CompileDoWhile(ph7_gen_state *pGen) {
|
||||||
pGen->pIn = &pEnd[1];
|
pGen->pIn = &pEnd[1];
|
||||||
pGen->pEnd = pTmp;
|
pGen->pEnd = pTmp;
|
||||||
/* Emit the true jump to the beginning of the loop */
|
/* Emit the true jump to the beginning of the loop */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_JNZ, 0, pDoBlock->nFirstInstr, 0, 0);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_JNZ, 0, pDoBlock->nFirstInstr, 0, 0);
|
||||||
/* Fix all jumps now the destination is resolved */
|
/* Fix all jumps now the destination is resolved */
|
||||||
PH7_GenStateFixJumps(pDoBlock, -1, PH7_VmInstrLength(pGen->pVm));
|
PH7_GenStateFixJumps(pDoBlock, -1, PH7_VmInstrLength(pGen->pVm));
|
||||||
/* Release the loop block */
|
/* Release the loop block */
|
||||||
|
@ -1952,7 +1952,7 @@ static sxi32 PH7_CompileFor(ph7_gen_state *pGen) {
|
||||||
/* Expression handler request an operation abort [i.e: Out-of-memory] */
|
/* Expression handler request an operation abort [i.e: Out-of-memory] */
|
||||||
return SXERR_ABORT;
|
return SXERR_ABORT;
|
||||||
} else if(rc != SXERR_EMPTY) {
|
} else if(rc != SXERR_EMPTY) {
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_POP, 1, 0, 0, 0);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_POP, 1, 0, 0, 0);
|
||||||
}
|
}
|
||||||
if((pGen->pIn->nType & PH7_TK_SEMI) == 0) {
|
if((pGen->pIn->nType & PH7_TK_SEMI) == 0) {
|
||||||
/* Syntax error */
|
/* Syntax error */
|
||||||
|
@ -1980,7 +1980,7 @@ static sxi32 PH7_CompileFor(ph7_gen_state *pGen) {
|
||||||
return SXERR_ABORT;
|
return SXERR_ABORT;
|
||||||
} else if(rc != SXERR_EMPTY) {
|
} else if(rc != SXERR_EMPTY) {
|
||||||
/* Emit the false jump */
|
/* Emit the false jump */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_JZ, 0, 0, 0, &nFalseJump);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_JZ, 0, 0, 0, &nFalseJump);
|
||||||
/* Save the instruction index so we can fix it later when the jump destination is resolved */
|
/* Save the instruction index so we can fix it later when the jump destination is resolved */
|
||||||
PH7_GenStateNewJumpFixup(pForBlock, PH7_OP_JZ, nFalseJump);
|
PH7_GenStateNewJumpFixup(pForBlock, PH7_OP_JZ, nFalseJump);
|
||||||
}
|
}
|
||||||
|
@ -2044,11 +2044,11 @@ static sxi32 PH7_CompileFor(ph7_gen_state *pGen) {
|
||||||
return SXERR_ABORT;
|
return SXERR_ABORT;
|
||||||
} else if(rc != SXERR_EMPTY) {
|
} else if(rc != SXERR_EMPTY) {
|
||||||
/* Pop operand lvalue */
|
/* Pop operand lvalue */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_POP, 1, 0, 0, 0);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_POP, 1, 0, 0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Emit the unconditional jump to the start of the loop */
|
/* Emit the unconditional jump to the start of the loop */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_JMP, 0, pForBlock->nFirstInstr, 0, 0);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_JMP, 0, pForBlock->nFirstInstr, 0, 0);
|
||||||
/* Fix all jumps now the destination is resolved */
|
/* Fix all jumps now the destination is resolved */
|
||||||
PH7_GenStateFixJumps(pForBlock, -1, PH7_VmInstrLength(pGen->pVm));
|
PH7_GenStateFixJumps(pForBlock, -1, PH7_VmInstrLength(pGen->pVm));
|
||||||
/* Release the loop block */
|
/* Release the loop block */
|
||||||
|
@ -2251,13 +2251,13 @@ static sxi32 PH7_CompileForeach(ph7_gen_state *pGen) {
|
||||||
SyStringInitFromBuf(&pInfo->sValue, pInstr->p3, SyStrlen((const char *)pInstr->p3));
|
SyStringInitFromBuf(&pInfo->sValue, pInstr->p3, SyStrlen((const char *)pInstr->p3));
|
||||||
}
|
}
|
||||||
/* Emit the 'FOREACH_INIT' instruction */
|
/* Emit the 'FOREACH_INIT' instruction */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_FOREACH_INIT, 0, 0, pInfo, &nFalseJump);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_FOREACH_INIT, 0, 0, pInfo, &nFalseJump);
|
||||||
/* Save the instruction index so we can fix it later when the jump destination is resolved */
|
/* Save the instruction index so we can fix it later when the jump destination is resolved */
|
||||||
PH7_GenStateNewJumpFixup(pForeachBlock, PH7_OP_FOREACH_INIT, nFalseJump);
|
PH7_GenStateNewJumpFixup(pForeachBlock, PH7_OP_FOREACH_INIT, nFalseJump);
|
||||||
/* Record the first instruction to execute */
|
/* Record the first instruction to execute */
|
||||||
pForeachBlock->nFirstInstr = PH7_VmInstrLength(pGen->pVm);
|
pForeachBlock->nFirstInstr = PH7_VmInstrLength(pGen->pVm);
|
||||||
/* Emit the FOREACH_STEP instruction */
|
/* Emit the FOREACH_STEP instruction */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_FOREACH_STEP, 0, 0, pInfo, &nFalseJump);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_FOREACH_STEP, 0, 0, pInfo, &nFalseJump);
|
||||||
/* Save the instruction index so we can fix it later when the jump destination is resolved */
|
/* Save the instruction index so we can fix it later when the jump destination is resolved */
|
||||||
PH7_GenStateNewJumpFixup(pForeachBlock, PH7_OP_FOREACH_STEP, nFalseJump);
|
PH7_GenStateNewJumpFixup(pForeachBlock, PH7_OP_FOREACH_STEP, nFalseJump);
|
||||||
/* Compile the loop body */
|
/* Compile the loop body */
|
||||||
|
@ -2269,7 +2269,7 @@ static sxi32 PH7_CompileForeach(ph7_gen_state *pGen) {
|
||||||
return SXERR_ABORT;
|
return SXERR_ABORT;
|
||||||
}
|
}
|
||||||
/* Emit the unconditional jump to the start of the loop */
|
/* Emit the unconditional jump to the start of the loop */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_JMP, 0, pForeachBlock->nFirstInstr, 0, 0);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_JMP, 0, pForeachBlock->nFirstInstr, 0, 0);
|
||||||
/* Fix all jumps now the destination is resolved */
|
/* Fix all jumps now the destination is resolved */
|
||||||
PH7_GenStateFixJumps(pForeachBlock, -1, PH7_VmInstrLength(pGen->pVm));
|
PH7_GenStateFixJumps(pForeachBlock, -1, PH7_VmInstrLength(pGen->pVm));
|
||||||
/* Release the loop block */
|
/* Release the loop block */
|
||||||
|
@ -2374,7 +2374,7 @@ static sxi32 PH7_CompileIf(ph7_gen_state *pGen) {
|
||||||
return SXERR_ABORT;
|
return SXERR_ABORT;
|
||||||
}
|
}
|
||||||
/* Emit the false jump */
|
/* Emit the false jump */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_JZ, 0, 0, 0, &nJumpIdx);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_JZ, 0, 0, 0, &nJumpIdx);
|
||||||
/* Save the instruction index so we can fix it later when the jump destination is resolved */
|
/* Save the instruction index so we can fix it later when the jump destination is resolved */
|
||||||
PH7_GenStateNewJumpFixup(pCondBlock, PH7_OP_JZ, nJumpIdx);
|
PH7_GenStateNewJumpFixup(pCondBlock, PH7_OP_JZ, nJumpIdx);
|
||||||
/* Compile the body */
|
/* Compile the body */
|
||||||
|
@ -2391,7 +2391,7 @@ static sxi32 PH7_CompileIf(ph7_gen_state *pGen) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* Emit the unconditional jump */
|
/* Emit the unconditional jump */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_JMP, 0, 0, 0, &nJumpIdx);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_JMP, 0, 0, 0, &nJumpIdx);
|
||||||
/* Save the instruction index so we can fix it later when the jump destination is resolved */
|
/* Save the instruction index so we can fix it later when the jump destination is resolved */
|
||||||
PH7_GenStateNewJumpFixup(pCondBlock, PH7_OP_JMP, nJumpIdx);
|
PH7_GenStateNewJumpFixup(pCondBlock, PH7_OP_JMP, nJumpIdx);
|
||||||
if(nKeyID & PH7_KEYWORD_ELSE) {
|
if(nKeyID & PH7_KEYWORD_ELSE) {
|
||||||
|
@ -2464,7 +2464,7 @@ static sxi32 PH7_CompileReturn(ph7_gen_state *pGen) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Emit the done instruction */
|
/* Emit the done instruction */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_DONE, nRet, 0, 0, 0);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_DONE, nRet, 0, 0, 0);
|
||||||
return SXRET_OK;
|
return SXRET_OK;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
@ -2487,7 +2487,7 @@ static sxi32 PH7_CompileHalt(ph7_gen_state *pGen) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Emit the HALT instruction */
|
/* Emit the HALT instruction */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_HALT, nExpr, 0, 0, 0);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_HALT, nExpr, 0, 0, 0);
|
||||||
return SXRET_OK;
|
return SXRET_OK;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
@ -2538,7 +2538,7 @@ static sxi32 PH7_CompileStatic(ph7_gen_state *pGen) {
|
||||||
return SXERR_ABORT;
|
return SXERR_ABORT;
|
||||||
} else if(rc != SXERR_EMPTY) {
|
} else if(rc != SXERR_EMPTY) {
|
||||||
/* Emit the POP instruction */
|
/* Emit the POP instruction */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_POP, 1, 0, 0, 0);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_POP, 1, 0, 0, 0);
|
||||||
}
|
}
|
||||||
return SXRET_OK;
|
return SXRET_OK;
|
||||||
}
|
}
|
||||||
|
@ -2586,7 +2586,7 @@ static sxi32 PH7_CompileStatic(ph7_gen_state *pGen) {
|
||||||
/* Compile the expression */
|
/* Compile the expression */
|
||||||
rc = PH7_CompileExpr(&(*pGen), 0, 0);
|
rc = PH7_CompileExpr(&(*pGen), 0, 0);
|
||||||
/* Emit the done instruction */
|
/* Emit the done instruction */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_DONE, (rc != SXERR_EMPTY ? 1 : 0), 0, 0, 0);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_DONE, (rc != SXERR_EMPTY ? 1 : 0), 0, 0, 0);
|
||||||
/* Restore default bytecode container */
|
/* Restore default bytecode container */
|
||||||
PH7_VmSetByteCodeContainer(pGen->pVm, pInstrContainer);
|
PH7_VmSetByteCodeContainer(pGen->pVm, pInstrContainer);
|
||||||
}
|
}
|
||||||
|
@ -2627,7 +2627,7 @@ static sxi32 PH7_CompileVar(ph7_gen_state *pGen) {
|
||||||
if(rc == SXERR_ABORT) {
|
if(rc == SXERR_ABORT) {
|
||||||
return SXERR_ABORT;
|
return SXERR_ABORT;
|
||||||
} else if(rc != SXERR_EMPTY) {
|
} else if(rc != SXERR_EMPTY) {
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_POP, 1, 0, 0, 0);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_POP, 1, 0, 0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return SXRET_OK;
|
return SXRET_OK;
|
||||||
|
@ -2845,7 +2845,7 @@ static sxi32 PH7_GenStateProcessArgValue(ph7_gen_state *pGen, ph7_vm_func_arg *p
|
||||||
/* Compile the expression holding the argument value */
|
/* Compile the expression holding the argument value */
|
||||||
rc = PH7_CompileExpr(&(*pGen), 0, 0);
|
rc = PH7_CompileExpr(&(*pGen), 0, 0);
|
||||||
/* Emit the done instruction */
|
/* Emit the done instruction */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_DONE, (rc != SXERR_EMPTY ? 1 : 0), 0, 0, 0);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_DONE, (rc != SXERR_EMPTY ? 1 : 0), 0, 0, 0);
|
||||||
PH7_VmSetByteCodeContainer(pGen->pVm, pInstrContainer);
|
PH7_VmSetByteCodeContainer(pGen->pVm, pInstrContainer);
|
||||||
RE_SWAP_DELIMITER(pGen);
|
RE_SWAP_DELIMITER(pGen);
|
||||||
if(rc == SXERR_ABORT) {
|
if(rc == SXERR_ABORT) {
|
||||||
|
@ -3070,7 +3070,7 @@ static sxi32 PH7_GenStateCompileFuncBody(
|
||||||
/* Fix exception jumps now the destination is resolved */
|
/* Fix exception jumps now the destination is resolved */
|
||||||
PH7_GenStateFixJumps(pGen->pCurrent, PH7_OP_THROW, PH7_VmInstrLength(pGen->pVm));
|
PH7_GenStateFixJumps(pGen->pCurrent, PH7_OP_THROW, PH7_VmInstrLength(pGen->pVm));
|
||||||
/* Emit the final return if not yet done */
|
/* Emit the final return if not yet done */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_DONE, 0, 0, 0, 0);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_DONE, 0, 0, 0, 0);
|
||||||
/* Restore the default container */
|
/* Restore the default container */
|
||||||
PH7_VmSetByteCodeContainer(pGen->pVm, pInstrContainer);
|
PH7_VmSetByteCodeContainer(pGen->pVm, pInstrContainer);
|
||||||
/* Leave function block */
|
/* Leave function block */
|
||||||
|
@ -3368,7 +3368,7 @@ loop:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Emit the done instruction */
|
/* Emit the done instruction */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_DONE, 1, 0, 0, 0);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_DONE, 1, 0, 0, 0);
|
||||||
PH7_VmSetByteCodeContainer(pGen->pVm, pInstrContainer);
|
PH7_VmSetByteCodeContainer(pGen->pVm, pInstrContainer);
|
||||||
if(rc == SXERR_ABORT) {
|
if(rc == SXERR_ABORT) {
|
||||||
/* Don't worry about freeing memory, everything will be released shortly */
|
/* Don't worry about freeing memory, everything will be released shortly */
|
||||||
|
@ -3482,7 +3482,7 @@ loop:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Emit the done instruction */
|
/* Emit the done instruction */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_DONE, 1, 0, 0, 0);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_DONE, 1, 0, 0, 0);
|
||||||
PH7_VmSetByteCodeContainer(pGen->pVm, pInstrContainer);
|
PH7_VmSetByteCodeContainer(pGen->pVm, pInstrContainer);
|
||||||
}
|
}
|
||||||
/* All done,install the attribute */
|
/* All done,install the attribute */
|
||||||
|
@ -3890,7 +3890,7 @@ static sxi32 PH7_CompileClassInterface(ph7_gen_state *pGen) {
|
||||||
rc = PH7_VmInstallClass(pGen->pVm, pClass);
|
rc = PH7_VmInstallClass(pGen->pVm, pClass);
|
||||||
if(iP1) {
|
if(iP1) {
|
||||||
/* Emit the INTERFACE_INIT instruction only if there is such a need */
|
/* Emit the INTERFACE_INIT instruction only if there is such a need */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_INTERFACE_INIT, iP1, 0, pClassInfo, 0);
|
PH7_VmEmitInstr(pGen->pVm, nLine, PH7_OP_INTERFACE_INIT, iP1, 0, pClassInfo, 0);
|
||||||
}
|
}
|
||||||
if(rc != SXRET_OK) {
|
if(rc != SXRET_OK) {
|
||||||
PH7_GenCompileError(pGen, E_ERROR, nLine, "Fatal, PH7 is running out of memory");
|
PH7_GenCompileError(pGen, E_ERROR, nLine, "Fatal, PH7 is running out of memory");
|
||||||
|
@ -4268,7 +4268,7 @@ static sxi32 PH7_GenStateCompileClass(ph7_gen_state *pGen, sxi32 iFlags) {
|
||||||
rc = PH7_VmInstallClass(pGen->pVm, pClass);
|
rc = PH7_VmInstallClass(pGen->pVm, pClass);
|
||||||
if(iP1 || iP2) {
|
if(iP1 || iP2) {
|
||||||
/* Emit the CLASS_INIT instruction only if there is such a need */
|
/* Emit the CLASS_INIT instruction only if there is such a need */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_CLASS_INIT, iP1, iP2, pClassInfo, 0);
|
PH7_VmEmitInstr(pGen->pVm, nLine, PH7_OP_CLASS_INIT, iP1, iP2, pClassInfo, 0);
|
||||||
}
|
}
|
||||||
if(rc != SXRET_OK) {
|
if(rc != SXRET_OK) {
|
||||||
PH7_GenCompileError(pGen, E_ERROR, nLine, "Fatal, PH7 is running out of memory");
|
PH7_GenCompileError(pGen, E_ERROR, nLine, "Fatal, PH7 is running out of memory");
|
||||||
|
@ -4399,7 +4399,7 @@ static sxi32 PH7_CompileThrow(ph7_gen_state *pGen) {
|
||||||
pBlock = pBlock->pParent;
|
pBlock = pBlock->pParent;
|
||||||
}
|
}
|
||||||
/* Emit the throw instruction */
|
/* Emit the throw instruction */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_THROW, 0, 0, 0, &nIdx);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_THROW, 0, 0, 0, &nIdx);
|
||||||
/* Emit the jump */
|
/* Emit the jump */
|
||||||
PH7_GenStateNewJumpFixup(pBlock, PH7_OP_THROW, nIdx);
|
PH7_GenStateNewJumpFixup(pBlock, PH7_OP_THROW, nIdx);
|
||||||
return SXRET_OK;
|
return SXRET_OK;
|
||||||
|
@ -4498,7 +4498,7 @@ static sxi32 PH7_CompileCatch(ph7_gen_state *pGen, ph7_exception *pException) {
|
||||||
/* Fix forward jumps now the destination is resolved */
|
/* Fix forward jumps now the destination is resolved */
|
||||||
PH7_GenStateFixJumps(pCatch, -1, PH7_VmInstrLength(pGen->pVm));
|
PH7_GenStateFixJumps(pCatch, -1, PH7_VmInstrLength(pGen->pVm));
|
||||||
/* Emit the DONE instruction */
|
/* Emit the DONE instruction */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_DONE, 0, 0, 0, 0);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_DONE, 0, 0, 0, 0);
|
||||||
/* Leave the block */
|
/* Leave the block */
|
||||||
PH7_GenStateLeaveBlock(&(*pGen), 0);
|
PH7_GenStateLeaveBlock(&(*pGen), 0);
|
||||||
/* Restore the default container */
|
/* Restore the default container */
|
||||||
|
@ -4543,7 +4543,7 @@ static sxi32 PH7_CompileTry(ph7_gen_state *pGen) {
|
||||||
return SXERR_ABORT;
|
return SXERR_ABORT;
|
||||||
}
|
}
|
||||||
/* Emit the 'LOAD_EXCEPTION' instruction */
|
/* Emit the 'LOAD_EXCEPTION' instruction */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_LOAD_EXCEPTION, 0, 0, pException, &nJmpIdx);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_LOAD_EXCEPTION, 0, 0, pException, &nJmpIdx);
|
||||||
/* Fix the jump later when the destination is resolved */
|
/* Fix the jump later when the destination is resolved */
|
||||||
PH7_GenStateNewJumpFixup(pTry, PH7_OP_LOAD_EXCEPTION, nJmpIdx);
|
PH7_GenStateNewJumpFixup(pTry, PH7_OP_LOAD_EXCEPTION, nJmpIdx);
|
||||||
pGen->pIn++; /* Jump the 'try' keyword */
|
pGen->pIn++; /* Jump the 'try' keyword */
|
||||||
|
@ -4555,7 +4555,7 @@ static sxi32 PH7_CompileTry(ph7_gen_state *pGen) {
|
||||||
/* Fix forward jumps now the destination is resolved */
|
/* Fix forward jumps now the destination is resolved */
|
||||||
PH7_GenStateFixJumps(pTry, -1, PH7_VmInstrLength(pGen->pVm));
|
PH7_GenStateFixJumps(pTry, -1, PH7_VmInstrLength(pGen->pVm));
|
||||||
/* Emit the 'POP_EXCEPTION' instruction */
|
/* Emit the 'POP_EXCEPTION' instruction */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_POP_EXCEPTION, 0, 0, pException, 0);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_POP_EXCEPTION, 0, 0, pException, 0);
|
||||||
/* Leave the block */
|
/* Leave the block */
|
||||||
PH7_GenStateLeaveBlock(&(*pGen), 0);
|
PH7_GenStateLeaveBlock(&(*pGen), 0);
|
||||||
/* Compile the catch block */
|
/* Compile the catch block */
|
||||||
|
@ -4670,7 +4670,7 @@ static sxi32 PH7_GenStateCompileCaseExpr(ph7_gen_state *pGen, ph7_case_expr *pEx
|
||||||
PH7_VmSetByteCodeContainer(pGen->pVm, &pExpr->aByteCode);
|
PH7_VmSetByteCodeContainer(pGen->pVm, &pExpr->aByteCode);
|
||||||
rc = PH7_CompileExpr(&(*pGen), 0, 0);
|
rc = PH7_CompileExpr(&(*pGen), 0, 0);
|
||||||
/* Emit the done instruction */
|
/* Emit the done instruction */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_DONE, (rc != SXERR_EMPTY ? 1 : 0), 0, 0, 0);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_DONE, (rc != SXERR_EMPTY ? 1 : 0), 0, 0, 0);
|
||||||
PH7_VmSetByteCodeContainer(pGen->pVm, pInstrContainer);
|
PH7_VmSetByteCodeContainer(pGen->pVm, pInstrContainer);
|
||||||
/* Update token stream */
|
/* Update token stream */
|
||||||
pGen->pIn = pEnd;
|
pGen->pIn = pEnd;
|
||||||
|
@ -4787,7 +4787,7 @@ static sxi32 PH7_CompileSwitch(ph7_gen_state *pGen) {
|
||||||
/* Initialize fields */
|
/* Initialize fields */
|
||||||
SySetInit(&pSwitch->aCaseExpr, &pGen->pVm->sAllocator, sizeof(ph7_case_expr));
|
SySetInit(&pSwitch->aCaseExpr, &pGen->pVm->sAllocator, sizeof(ph7_case_expr));
|
||||||
/* Emit the switch instruction */
|
/* Emit the switch instruction */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_SWITCH, 0, 0, pSwitch, 0);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_SWITCH, 0, 0, pSwitch, 0);
|
||||||
/* Compile case blocks */
|
/* Compile case blocks */
|
||||||
for(;;) {
|
for(;;) {
|
||||||
sxu32 nKwrd;
|
sxu32 nKwrd;
|
||||||
|
@ -4916,7 +4916,7 @@ static sxi32 PH7_GenStateEmitExprCode(
|
||||||
}
|
}
|
||||||
nJz = nJmp = 0; /* cc -O6 warning */
|
nJz = nJmp = 0; /* cc -O6 warning */
|
||||||
/* Phase#2: Emit the false jump */
|
/* Phase#2: Emit the false jump */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_JZ, 0, 0, 0, &nJz);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_JZ, 0, 0, 0, &nJz);
|
||||||
if(pNode->pLeft) {
|
if(pNode->pLeft) {
|
||||||
/* Phase#3: Compile the 'then' expression */
|
/* Phase#3: Compile the 'then' expression */
|
||||||
rc = PH7_GenStateEmitExprCode(&(*pGen), pNode->pLeft, iFlags);
|
rc = PH7_GenStateEmitExprCode(&(*pGen), pNode->pLeft, iFlags);
|
||||||
|
@ -4925,7 +4925,7 @@ static sxi32 PH7_GenStateEmitExprCode(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Phase#4: Emit the unconditional jump */
|
/* Phase#4: Emit the unconditional jump */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_JMP, 0, 0, 0, &nJmp);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_JMP, 0, 0, 0, &nJmp);
|
||||||
/* Phase#5: Fix the false jump now the jump destination is resolved. */
|
/* Phase#5: Fix the false jump now the jump destination is resolved. */
|
||||||
pInstr = PH7_VmGetInstr(pGen->pVm, nJz);
|
pInstr = PH7_VmGetInstr(pGen->pVm, nJz);
|
||||||
if(pInstr) {
|
if(pInstr) {
|
||||||
|
@ -5003,7 +5003,7 @@ static sxi32 PH7_GenStateEmitExprCode(
|
||||||
}
|
}
|
||||||
} else if(pNode->pOp->iOp == EXPR_OP_COMMA) {
|
} else if(pNode->pOp->iOp == EXPR_OP_COMMA) {
|
||||||
/* POP the left node */
|
/* POP the left node */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_POP, 1, 0, 0, 0);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_POP, 1, 0, 0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rc = SXRET_OK;
|
rc = SXRET_OK;
|
||||||
|
@ -5012,10 +5012,10 @@ static sxi32 PH7_GenStateEmitExprCode(
|
||||||
if(pNode->pRight) {
|
if(pNode->pRight) {
|
||||||
if(iVmOp == PH7_OP_LAND) {
|
if(iVmOp == PH7_OP_LAND) {
|
||||||
/* Emit the false jump so we can short-circuit the logical and */
|
/* Emit the false jump so we can short-circuit the logical and */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_JZ, 1/* Keep the value on the stack */, 0, 0, &nJmpIdx);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_JZ, 1/* Keep the value on the stack */, 0, 0, &nJmpIdx);
|
||||||
} else if(iVmOp == PH7_OP_LOR) {
|
} else if(iVmOp == PH7_OP_LOR) {
|
||||||
/* Emit the true jump so we can short-circuit the logical or*/
|
/* Emit the true jump so we can short-circuit the logical or*/
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_JNZ, 1/* Keep the value on the stack */, 0, 0, &nJmpIdx);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_JNZ, 1/* Keep the value on the stack */, 0, 0, &nJmpIdx);
|
||||||
} else if(pNode->pOp->iPrec == 18 /* Combined binary operators [i.e: =,'.=','+=',*=' ...] precedence */) {
|
} else if(pNode->pOp->iPrec == 18 /* Combined binary operators [i.e: =,'.=','+=',*=' ...] precedence */) {
|
||||||
iFlags |= EXPR_FLAG_LOAD_IDX_STORE;
|
iFlags |= EXPR_FLAG_LOAD_IDX_STORE;
|
||||||
}
|
}
|
||||||
|
@ -5087,7 +5087,7 @@ static sxi32 PH7_GenStateEmitExprCode(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Finally,emit the VM instruction associated with this operator */
|
/* Finally,emit the VM instruction associated with this operator */
|
||||||
PH7_VmEmitInstr(pGen->pVm, iVmOp, iP1, iP2, p3, 0);
|
PH7_VmEmitInstr(pGen->pVm, 0, iVmOp, iP1, iP2, p3, 0);
|
||||||
if(nJmpIdx > 0) {
|
if(nJmpIdx > 0) {
|
||||||
/* Fix short-circuited jumps now the destination is resolved */
|
/* Fix short-circuited jumps now the destination is resolved */
|
||||||
pInstr = PH7_VmGetInstr(pGen->pVm, nJmpIdx);
|
pInstr = PH7_VmGetInstr(pGen->pVm, nJmpIdx);
|
||||||
|
@ -5347,7 +5347,7 @@ static sxi32 PH7_GenStateCompileChunk(
|
||||||
rc = PH7_CompileExpr(&(*pGen), 0, 0);
|
rc = PH7_CompileExpr(&(*pGen), 0, 0);
|
||||||
if(rc != SXERR_EMPTY) {
|
if(rc != SXERR_EMPTY) {
|
||||||
/* Pop l-value */
|
/* Pop l-value */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_POP, 1, 0, 0, 0);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_POP, 1, 0, 0, 0);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* Compile the statement */
|
/* Compile the statement */
|
||||||
|
@ -5441,7 +5441,7 @@ static sxi32 PH7_CompileScript(
|
||||||
rc = PH7_CompileExpr(pGen, 0, 0);
|
rc = PH7_CompileExpr(pGen, 0, 0);
|
||||||
}
|
}
|
||||||
/* Emit the DONE instruction */
|
/* Emit the DONE instruction */
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_DONE, (rc != SXERR_EMPTY ? 1 : 0), 0, 0, 0);
|
PH7_VmEmitInstr(pGen->pVm, 0, PH7_OP_DONE, (rc != SXERR_EMPTY ? 1 : 0), 0, 0, 0);
|
||||||
return SXRET_OK;
|
return SXRET_OK;
|
||||||
} else if(iFlags & PH7_AERSCRIPT_CHNK) {
|
} else if(iFlags & PH7_AERSCRIPT_CHNK) {
|
||||||
/* Compile a chunk of code */
|
/* Compile a chunk of code */
|
||||||
|
|
|
@ -298,6 +298,7 @@ PH7_PRIVATE sxi32 PH7_VmInstallClass(
|
||||||
*/
|
*/
|
||||||
PH7_PRIVATE sxi32 PH7_VmEmitInstr(
|
PH7_PRIVATE sxi32 PH7_VmEmitInstr(
|
||||||
ph7_vm *pVm, /* Target VM */
|
ph7_vm *pVm, /* Target VM */
|
||||||
|
sxu32 nLine, /* Line number, instruction was generated */
|
||||||
sxi32 iOp, /* Operation to perform */
|
sxi32 iOp, /* Operation to perform */
|
||||||
sxi32 iP1, /* First operand */
|
sxi32 iP1, /* First operand */
|
||||||
sxu32 iP2, /* Second operand */
|
sxu32 iP2, /* Second operand */
|
||||||
|
@ -320,7 +321,9 @@ PH7_PRIVATE sxi32 PH7_VmEmitInstr(
|
||||||
sInstr.bExec = FALSE;
|
sInstr.bExec = FALSE;
|
||||||
sInstr.pFile = pFile;
|
sInstr.pFile = pFile;
|
||||||
sInstr.iLine = 1;
|
sInstr.iLine = 1;
|
||||||
if(pVm->sCodeGen.pEnd && pVm->sCodeGen.pEnd->nLine > 0) {
|
if(nLine > 0) {
|
||||||
|
sInstr.iLine = nLine;
|
||||||
|
} else if(pVm->sCodeGen.pEnd && pVm->sCodeGen.pEnd->nLine > 0) {
|
||||||
sInstr.iLine = pVm->sCodeGen.pEnd->nLine;
|
sInstr.iLine = pVm->sCodeGen.pEnd->nLine;
|
||||||
}
|
}
|
||||||
if(pIndex) {
|
if(pIndex) {
|
||||||
|
@ -1071,7 +1074,7 @@ PH7_PRIVATE sxi32 PH7_VmMakeReady(
|
||||||
/* Release the code generator now we have compiled our program */
|
/* Release the code generator now we have compiled our program */
|
||||||
PH7_ResetCodeGenerator(pVm, 0, 0);
|
PH7_ResetCodeGenerator(pVm, 0, 0);
|
||||||
/* Emit the DONE instruction */
|
/* Emit the DONE instruction */
|
||||||
rc = PH7_VmEmitInstr(&(*pVm), PH7_OP_DONE, 0, 0, 0, 0);
|
rc = PH7_VmEmitInstr(&(*pVm), 0, PH7_OP_DONE, 0, 0, 0, 0);
|
||||||
if(rc != SXRET_OK) {
|
if(rc != SXRET_OK) {
|
||||||
return SXERR_MEM;
|
return SXERR_MEM;
|
||||||
}
|
}
|
||||||
|
@ -9998,7 +10001,7 @@ static sxi32 VmEvalChunk(
|
||||||
goto Cleanup;
|
goto Cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(SXRET_OK != PH7_VmEmitInstr(pVm, PH7_OP_DONE, 0, 0, 0, 0)) {
|
if(SXRET_OK != PH7_VmEmitInstr(pVm, 0, PH7_OP_DONE, 0, 0, 0, 0)) {
|
||||||
/* Out of memory */
|
/* Out of memory */
|
||||||
if(pCtx) {
|
if(pCtx) {
|
||||||
ph7_result_bool(pCtx, 0);
|
ph7_result_bool(pCtx, 0);
|
||||||
|
|
|
@ -1695,7 +1695,7 @@ PH7_PRIVATE VmInstr *PH7_VmPeekNextInstr(ph7_vm *pVm);
|
||||||
PH7_PRIVATE VmInstr *PH7_VmGetInstr(ph7_vm *pVm, sxu32 nIndex);
|
PH7_PRIVATE VmInstr *PH7_VmGetInstr(ph7_vm *pVm, sxu32 nIndex);
|
||||||
PH7_PRIVATE SySet *PH7_VmGetByteCodeContainer(ph7_vm *pVm);
|
PH7_PRIVATE SySet *PH7_VmGetByteCodeContainer(ph7_vm *pVm);
|
||||||
PH7_PRIVATE sxi32 PH7_VmSetByteCodeContainer(ph7_vm *pVm, SySet *pContainer);
|
PH7_PRIVATE sxi32 PH7_VmSetByteCodeContainer(ph7_vm *pVm, SySet *pContainer);
|
||||||
PH7_PRIVATE sxi32 PH7_VmEmitInstr(ph7_vm *pVm, sxi32 iOp, sxi32 iP1, sxu32 iP2, void *p3, sxu32 *pIndex);
|
PH7_PRIVATE sxi32 PH7_VmEmitInstr(ph7_vm *pVm, sxu32 nLine, sxi32 iOp, sxi32 iP1, sxu32 iP2, void *p3, sxu32 *pIndex);
|
||||||
PH7_PRIVATE sxu32 PH7_VmRandomNum(ph7_vm *pVm);
|
PH7_PRIVATE sxu32 PH7_VmRandomNum(ph7_vm *pVm);
|
||||||
PH7_PRIVATE sxi32 PH7_VmCallClassMethod(ph7_vm *pVm, ph7_class_instance *pThis, ph7_class_method *pMethod,
|
PH7_PRIVATE sxi32 PH7_VmCallClassMethod(ph7_vm *pVm, ph7_class_instance *pThis, ph7_class_method *pMethod,
|
||||||
ph7_value *pResult, int nArg, ph7_value **apArg);
|
ph7_value *pResult, int nArg, ph7_value **apArg);
|
||||||
|
|
Loading…
Reference in New Issue