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) {
|
||||
/* Invalid variable name */
|
||||
PH7_GenCompileError(pGen, E_ERROR, nLine, "Invalid variable name");
|
||||
return SXERR_ABORT;
|
||||
}
|
||||
p3 = 0;
|
||||
SyHashEntry *pEntry;
|
||||
@@ -5023,7 +5024,7 @@ static sxi32 PH7_GenStateEmitExprCode(
|
||||
} else {
|
||||
p3 = pInstr->p3;
|
||||
}
|
||||
/* POP the last dynamic load instruction */
|
||||
/* POP the last load instruction */
|
||||
(void)PH7_VmPopInstr(pGen->pVm);
|
||||
}
|
||||
}
|
||||
|
||||
+7
-17
@@ -459,24 +459,14 @@ static sxi32 ExprExtractNode(ph7_gen_state *pGen, ph7_expr_node **ppNode) {
|
||||
pCur++;
|
||||
} else if(pCur->nType & PH7_TK_DOLLAR) {
|
||||
/* 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++;
|
||||
} else if(pCur->nType & PH7_TK_OCB /* '{' */) {
|
||||
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 '}'");
|
||||
}
|
||||
}
|
||||
pCur++;
|
||||
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++;
|
||||
pNode->xCode = PH7_CompileVariable;
|
||||
} else if(pCur->nType & PH7_TK_OCB /* '{' */) {
|
||||
/* Array, assemble tokens */
|
||||
|
||||
+7
-36
@@ -3331,30 +3331,16 @@ Resume:
|
||||
/*
|
||||
* LOADV: * * P3
|
||||
*
|
||||
* Load a variable where it's name is taken from the top of the stack or
|
||||
* from the P3 operand.
|
||||
* Load a variable whose name is given by the P3 operand.
|
||||
*/
|
||||
case PH7_OP_LOADV: {
|
||||
ph7_value *pObj;
|
||||
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));
|
||||
/* Reserve a room for the target object */
|
||||
pTos++;
|
||||
}
|
||||
SyStringInitFromBuf(&sName, pInstr->p3, SyStrlen((const char *)pInstr->p3));
|
||||
/* Reserve a room for the target object */
|
||||
pTos++;
|
||||
/* Extract the requested memory object */
|
||||
pObj = VmExtractMemObj(&(*pVm), &sName, pInstr->p3 ? FALSE : TRUE);
|
||||
pObj = VmExtractMemObj(&(*pVm), &sName, FALSE);
|
||||
if(pObj == 0) {
|
||||
/* Fatal error */
|
||||
PH7_VmThrowError(&(*pVm), PH7_CTX_ERR, "Variable '$%z' undeclared (first use in this method/closure)", &sName);
|
||||
@@ -3628,31 +3614,16 @@ Resume:
|
||||
}
|
||||
}
|
||||
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 */
|
||||
pObj = VmExtractMemObj(&(*pVm), &sName, pInstr->p3 ? FALSE : TRUE);
|
||||
pObj = VmExtractMemObj(&(*pVm), &sName, FALSE);
|
||||
if(pObj == 0) {
|
||||
PH7_VmThrowError(&(*pVm), PH7_CTX_ERR,
|
||||
"Variable '$%z' undeclared (first use in this method/closure)", &sName);
|
||||
} else if(pObj->iFlags != MEMOBJ_VARIABLE) {
|
||||
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 */
|
||||
rc = PH7_MemObjSafeStore(pTos, pObj);
|
||||
if(rc != SXRET_OK) {
|
||||
|
||||
Reference in New Issue
Block a user