Remove variable-variable parsing and dynamic local-name dispatch
Build / AerScript (push) Successful in 37s
Build / AerScript (push) Successful in 37s
This commit is contained in:
+2
-1
@@ -1161,6 +1161,7 @@ PH7_PRIVATE sxi32 PH7_CompileVariable(ph7_gen_state *pGen, sxi32 iCompileFlag) {
|
|||||||
if(pGen->pIn >= pGen->pEnd || (pGen->pIn->nType & (PH7_TK_ID | PH7_TK_KEYWORD)) == 0) {
|
if(pGen->pIn >= pGen->pEnd || (pGen->pIn->nType & (PH7_TK_ID | PH7_TK_KEYWORD)) == 0) {
|
||||||
/* Invalid variable name */
|
/* Invalid variable name */
|
||||||
PH7_GenCompileError(pGen, E_ERROR, nLine, "Invalid variable name");
|
PH7_GenCompileError(pGen, E_ERROR, nLine, "Invalid variable name");
|
||||||
|
return SXERR_ABORT;
|
||||||
}
|
}
|
||||||
p3 = 0;
|
p3 = 0;
|
||||||
SyHashEntry *pEntry;
|
SyHashEntry *pEntry;
|
||||||
@@ -5023,7 +5024,7 @@ static sxi32 PH7_GenStateEmitExprCode(
|
|||||||
} else {
|
} else {
|
||||||
p3 = pInstr->p3;
|
p3 = pInstr->p3;
|
||||||
}
|
}
|
||||||
/* POP the last dynamic load instruction */
|
/* POP the last load instruction */
|
||||||
(void)PH7_VmPopInstr(pGen->pVm);
|
(void)PH7_VmPopInstr(pGen->pVm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-16
@@ -459,24 +459,14 @@ static sxi32 ExprExtractNode(ph7_gen_state *pGen, ph7_expr_node **ppNode) {
|
|||||||
pCur++;
|
pCur++;
|
||||||
} else if(pCur->nType & PH7_TK_DOLLAR) {
|
} else if(pCur->nType & PH7_TK_DOLLAR) {
|
||||||
/* Isolate variable */
|
/* Isolate variable */
|
||||||
while(pCur < pGen->pEnd && (pCur->nType & PH7_TK_DOLLAR)) {
|
|
||||||
pCur++; /* Variable variable */
|
|
||||||
}
|
|
||||||
if(pCur < pGen->pEnd) {
|
|
||||||
if(pCur->nType & (PH7_TK_ID | PH7_TK_KEYWORD)) {
|
|
||||||
/* Variable name */
|
|
||||||
pCur++;
|
pCur++;
|
||||||
} else if(pCur->nType & PH7_TK_OCB /* '{' */) {
|
if(pCur >= pGen->pEnd || (pCur->nType & (PH7_TK_ID | PH7_TK_KEYWORD)) == 0) {
|
||||||
|
PH7_GenCompileError(pGen, E_ERROR, pNode->pStart->nLine, "Invalid variable name");
|
||||||
|
SySetRelease(&pNode->aNodeArgs);
|
||||||
|
SyMemBackendPoolFree(&pGen->pVm->sAllocator, pNode);
|
||||||
|
return SXERR_ABORT;
|
||||||
|
}
|
||||||
pCur++;
|
pCur++;
|
||||||
/* Dynamic variable name,Collect until the next non nested '}' */
|
|
||||||
PH7_DelimitNestedTokens(pCur, pGen->pEnd, PH7_TK_OCB, PH7_TK_CCB, &pCur);
|
|
||||||
if(pCur < pGen->pEnd) {
|
|
||||||
pCur++;
|
|
||||||
} else {
|
|
||||||
PH7_GenCompileError(pGen, E_ERROR, pNode->pStart->nLine, "Syntax error: Missing closing brace '}'");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pNode->xCode = PH7_CompileVariable;
|
pNode->xCode = PH7_CompileVariable;
|
||||||
} else if(pCur->nType & PH7_TK_OCB /* '{' */) {
|
} else if(pCur->nType & PH7_TK_OCB /* '{' */) {
|
||||||
/* Array, assemble tokens */
|
/* Array, assemble tokens */
|
||||||
|
|||||||
+3
-32
@@ -3331,30 +3331,16 @@ Resume:
|
|||||||
/*
|
/*
|
||||||
* LOADV: * * P3
|
* LOADV: * * P3
|
||||||
*
|
*
|
||||||
* Load a variable where it's name is taken from the top of the stack or
|
* Load a variable whose name is given by the P3 operand.
|
||||||
* from the P3 operand.
|
|
||||||
*/
|
*/
|
||||||
case PH7_OP_LOADV: {
|
case PH7_OP_LOADV: {
|
||||||
ph7_value *pObj;
|
ph7_value *pObj;
|
||||||
SyString sName;
|
SyString sName;
|
||||||
if(pInstr->p3 == 0) {
|
|
||||||
/* Take the variable name from the top of the stack */
|
|
||||||
if(pTos < pStack) {
|
|
||||||
goto Abort;
|
|
||||||
}
|
|
||||||
#
|
|
||||||
/* Force a string cast */
|
|
||||||
if((pTos->nType & MEMOBJ_STRING) == 0) {
|
|
||||||
PH7_MemObjToString(pTos);
|
|
||||||
}
|
|
||||||
SyStringInitFromBuf(&sName, SyBlobData(&pTos->sBlob), SyBlobLength(&pTos->sBlob));
|
|
||||||
} else {
|
|
||||||
SyStringInitFromBuf(&sName, pInstr->p3, SyStrlen((const char *)pInstr->p3));
|
SyStringInitFromBuf(&sName, pInstr->p3, SyStrlen((const char *)pInstr->p3));
|
||||||
/* Reserve a room for the target object */
|
/* Reserve a room for the target object */
|
||||||
pTos++;
|
pTos++;
|
||||||
}
|
|
||||||
/* Extract the requested memory object */
|
/* Extract the requested memory object */
|
||||||
pObj = VmExtractMemObj(&(*pVm), &sName, pInstr->p3 ? FALSE : TRUE);
|
pObj = VmExtractMemObj(&(*pVm), &sName, FALSE);
|
||||||
if(pObj == 0) {
|
if(pObj == 0) {
|
||||||
/* Fatal error */
|
/* Fatal error */
|
||||||
PH7_VmThrowError(&(*pVm), PH7_CTX_ERR, "Variable '$%z' undeclared (first use in this method/closure)", &sName);
|
PH7_VmThrowError(&(*pVm), PH7_CTX_ERR, "Variable '$%z' undeclared (first use in this method/closure)", &sName);
|
||||||
@@ -3628,31 +3614,16 @@ Resume:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
} else if(pInstr->p3 == 0) {
|
|
||||||
/* Take the variable name from the next on the stack */
|
|
||||||
if((pTos->nType & MEMOBJ_STRING) == 0) {
|
|
||||||
/* Force a string cast */
|
|
||||||
PH7_MemObjToString(pTos);
|
|
||||||
}
|
}
|
||||||
SyStringInitFromBuf(&sName, SyBlobData(&pTos->sBlob), SyBlobLength(&pTos->sBlob));
|
|
||||||
pTos--;
|
|
||||||
if(pTos < pStack) {
|
|
||||||
goto Abort;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
SyStringInitFromBuf(&sName, pInstr->p3, SyStrlen((const char *)pInstr->p3));
|
SyStringInitFromBuf(&sName, pInstr->p3, SyStrlen((const char *)pInstr->p3));
|
||||||
}
|
|
||||||
/* Extract the desired variable if available */
|
/* Extract the desired variable if available */
|
||||||
pObj = VmExtractMemObj(&(*pVm), &sName, pInstr->p3 ? FALSE : TRUE);
|
pObj = VmExtractMemObj(&(*pVm), &sName, FALSE);
|
||||||
if(pObj == 0) {
|
if(pObj == 0) {
|
||||||
PH7_VmThrowError(&(*pVm), PH7_CTX_ERR,
|
PH7_VmThrowError(&(*pVm), PH7_CTX_ERR,
|
||||||
"Variable '$%z' undeclared (first use in this method/closure)", &sName);
|
"Variable '$%z' undeclared (first use in this method/closure)", &sName);
|
||||||
} else if(pObj->iFlags != MEMOBJ_VARIABLE) {
|
} else if(pObj->iFlags != MEMOBJ_VARIABLE) {
|
||||||
PH7_VmThrowError(&(*pVm), PH7_CTX_ERR, "Cannot re-assign a value of '$%z' statement", &sName);
|
PH7_VmThrowError(&(*pVm), PH7_CTX_ERR, "Cannot re-assign a value of '$%z' statement", &sName);
|
||||||
}
|
}
|
||||||
if(!pInstr->p3) {
|
|
||||||
PH7_MemObjRelease(&pTos[1]);
|
|
||||||
}
|
|
||||||
/* Perform the store operation */
|
/* Perform the store operation */
|
||||||
rc = PH7_MemObjSafeStore(pTos, pObj);
|
rc = PH7_MemObjSafeStore(pTos, pObj);
|
||||||
if(rc != SXRET_OK) {
|
if(rc != SXRET_OK) {
|
||||||
|
|||||||
Reference in New Issue
Block a user