Browse Source

Do not count compilation errors.

Interpreter will abort script execution on first error found.
release/v0.1
Rafal Kupiec 1 year ago
parent
commit
c443a38fec
Signed by: belliash GPG Key ID: 4E829243E0CFE6B4
4 changed files with 23 additions and 49 deletions
  1. +3
    -4
      engine/api.c
  2. +0
    -17
      engine/compiler.c
  3. +20
    -27
      engine/vm.c
  4. +0
    -1
      include/ph7int.h

+ 3
- 4
engine/api.c View File

@ -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);

+ 0
- 17
engine/compiler.c View File

@ -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;

+ 20
- 27
engine/vm.c View File

@ -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(SXRET_OK != PH7_VmEmitInstr(pVm, 0, PH7_OP_DONE, 0, 0, 0, 0)) {
/* Out of memory */
if(pCtx) {
/* Set the execution result */
ph7_result_value(pCtx, &sResult);
ph7_result_bool(pCtx, 0);
}
PH7_MemObjRelease(&sResult);
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;

+ 0
- 1
include/ph7int.h View File

@ -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 */

Loading…
Cancel
Save