From c443a38fecbfbfe9b323f42c535899f75c5cb868 Mon Sep 17 00:00:00 2001 From: belliash Date: Wed, 24 Apr 2019 23:22:06 +0200 Subject: [PATCH] Do not count compilation errors. Interpreter will abort script execution on first error found. --- engine/api.c | 7 +++---- engine/compiler.c | 17 ---------------- engine/vm.c | 51 ++++++++++++++++++++--------------------------- include/ph7int.h | 1 - 4 files changed, 25 insertions(+), 51 deletions(-) diff --git a/engine/api.c b/engine/api.c index 618574c..43d84ea 100644 --- a/engine/api.c +++ b/engine/api.c @@ -695,15 +695,14 @@ static sxi32 ProcessSourceFile( } /* Compile the script */ PH7_CompileAerScript(pVm, &(*pScript), PH7_AERSCRIPT_CODE); - if(pVm->sCodeGen.nErr > 0 || pVm == 0) { - sxu32 nErr = pVm->sCodeGen.nErr; - /* Compilation error or null ppVm pointer,release this VM */ + if(pVm == 0) { + /* Null ppVm pointer,release this VM */ SyMemBackendRelease(&pVm->sAllocator); SyMemBackendPoolFree(&pEngine->sAllocator, pVm); if(ppVm) { *ppVm = 0; } - return nErr > 0 ? PH7_COMPILE_ERR : PH7_OK; + return PH7_OK; } /* Prepare the virtual machine for bytecode execution */ rc = PH7_VmMakeReady(pVm); diff --git a/engine/compiler.c b/engine/compiler.c index b857ad4..7ada30b 100644 --- a/engine/compiler.c +++ b/engine/compiler.c @@ -4953,7 +4953,6 @@ PH7_PRIVATE sxi32 PH7_ResetCodeGenerator( pGen->pCurrent = &pGen->sGlobal; pGen->pRawIn = pGen->pRawEnd = 0; pGen->pIn = pGen->pEnd = 0; - pGen->nErr = 0; return SXRET_OK; } /* @@ -4972,22 +4971,6 @@ PH7_PRIVATE sxi32 PH7_GenCompileError(ph7_gen_state *pGen, sxi32 nErrType, sxu32 SyBlobReset(pWorker); /* Peek the processed file path if available */ pFile = (SyString *)SySetPeek(&pGen->pVm->aFiles); - if(nErrType == E_ERROR) { - /* Increment the error counter */ - pGen->nErr++; - if(pGen->nErr > 15) { - /* Error count limit reached */ - if(pGen->xErr) { - SyBlobFormat(pWorker, "%u Error count limit reached,PH7 is aborting compilation\n", nLine); - if(SyBlobLength(pWorker) > 0) { - /* Consume the generated error message */ - pGen->xErr(SyBlobData(pWorker), SyBlobLength(pWorker), pGen->pErrData); - } - } - /* Abort immediately */ - return SXERR_ABORT; - } - } if(pGen->xErr == 0) { /* No available error consumer,return immediately */ return SXRET_OK; diff --git a/engine/vm.c b/engine/vm.c index ac78244..dd372a1 100644 --- a/engine/vm.c +++ b/engine/vm.c @@ -9479,41 +9479,34 @@ static sxi32 VmEvalChunk( } /* Compile the chunk */ PH7_CompileAerScript(pVm, pChunk, iFlags); - if(pVm->sCodeGen.nErr > 0) { - /* Compilation error,return false */ - if(pCtx) { - ph7_result_bool(pCtx, 0); - } - } else { - ph7_value sResult; /* Return value */ - SyHashEntry *pEntry; - /* Initialize and install static and constants class attributes */ - SyHashResetLoopCursor(&pVm->hClass); - while((pEntry = SyHashGetNextEntry(&pVm->hClass)) != 0) { - if(VmMountUserClass(&(*pVm), (ph7_class *)pEntry->pUserData) != SXRET_OK) { - if(pCtx) { - ph7_result_bool(pCtx, 0); - } - goto Cleanup; - } - } - if(SXRET_OK != PH7_VmEmitInstr(pVm, 0, PH7_OP_DONE, 0, 0, 0, 0)) { - /* Out of memory */ + ph7_value sResult; /* Return value */ + SyHashEntry *pEntry; + /* Initialize and install static and constants class attributes */ + SyHashResetLoopCursor(&pVm->hClass); + while((pEntry = SyHashGetNextEntry(&pVm->hClass)) != 0) { + if(VmMountUserClass(&(*pVm), (ph7_class *)pEntry->pUserData) != SXRET_OK) { if(pCtx) { ph7_result_bool(pCtx, 0); } goto Cleanup; } - /* Assume a boolean true return value */ - PH7_MemObjInitFromBool(pVm, &sResult, 1); - /* Execute the compiled chunk */ - VmLocalExec(pVm, &aByteCode, &sResult); - if(pCtx) { - /* Set the execution result */ - ph7_result_value(pCtx, &sResult); - } - PH7_MemObjRelease(&sResult); } + if(SXRET_OK != PH7_VmEmitInstr(pVm, 0, PH7_OP_DONE, 0, 0, 0, 0)) { + /* Out of memory */ + if(pCtx) { + ph7_result_bool(pCtx, 0); + } + goto Cleanup; + } + /* Assume a boolean true return value */ + PH7_MemObjInitFromBool(pVm, &sResult, 1); + /* Execute the compiled chunk */ + VmLocalExec(pVm, &aByteCode, &sResult); + if(pCtx) { + /* Set the execution result */ + ph7_result_value(pCtx, &sResult); + } + PH7_MemObjRelease(&sResult); Cleanup: /* Cleanup the mess left behind */ pVm->pByteContainer = pByteCode; diff --git a/include/ph7int.h b/include/ph7int.h index ba8a724..6f6260c 100644 --- a/include/ph7int.h +++ b/include/ph7int.h @@ -904,7 +904,6 @@ struct ph7_gen_state { SyBlob sErrBuf; /* Error buffer */ SyToken *pIn; /* Current processed token */ SyToken *pEnd; /* Last token in the stream */ - sxu32 nErr; /* Total number of compilation error */ SyToken *pRawIn; /* Current processed raw token */ SyToken *pRawEnd; /* Last raw token in the stream */ SySet *pTokenSet; /* Token containers */