Browse Source

Get rid of some annoying compiler warnings.

release/v0.1
Rafal Kupiec 2 years ago
parent
commit
bffd44a7b4
Signed by: belliash GPG Key ID: 4E829243E0CFE6B4
8 changed files with 29 additions and 22 deletions
  1. +2
    -3
      engine/api.c
  2. +0
    -2
      engine/builtin.c
  3. +18
    -7
      engine/compiler.c
  4. +4
    -2
      engine/vm.c
  5. +0
    -6
      include/compiler.h
  6. +1
    -0
      include/ph7.h
  7. +3
    -1
      include/ph7int.h
  8. +1
    -1
      sapi/cli/main.c

+ 2
- 3
engine/api.c View File

@ -42,7 +42,7 @@ static struct Global_Data {
ph7 *pEngines; /* List of active engine */
sxu32 nMagic; /* Sanity check against library misuse */
} sMPGlobal = {
{0, 0, 0, 0, 0, 0, 0, 0, {0}},
{0, 0, 0, 0, 0, 0, 0, 0, 0, {0}},
#if defined(PH7_ENABLE_THREADS)
0,
0,
@ -1829,14 +1829,13 @@ int ph7_value_string(ph7_value *pVal, const char *zString, int nLen) {
*/
int ph7_value_string_format(ph7_value *pVal, const char *zFormat, ...) {
va_list ap;
int rc;
if((pVal->nType & MEMOBJ_STRING) == 0) {
/* Invalidate any prior representation */
PH7_MemObjRelease(pVal);
MemObjSetType(pVal, MEMOBJ_STRING);
}
va_start(ap, zFormat);
rc = SyBlobFormatAp(&pVal->sBlob, zFormat, ap);
SyBlobFormatAp(&pVal->sBlob, zFormat, ap);
va_end(ap);
return PH7_OK;
}


+ 0
- 2
engine/builtin.c View File

@ -3279,7 +3279,6 @@ PH7_PRIVATE sxi32 PH7_InputFormat(
ph7_value *pArg; /* Current processed argument */
ph7_int64 iVal;
int precision; /* Precision of the current field */
char *zExtra;
int c, rc, n;
int length; /* Length of the field */
int prefix;
@ -3404,7 +3403,6 @@ PH7_PRIVATE sxi32 PH7_InputFormat(
}
zBuf = zWorker; /* Point to the working buffer */
length = 0;
zExtra = 0;
/*
** At this point, variables are initialized as follows:
**


+ 18
- 7
engine/compiler.c View File

@ -902,7 +902,7 @@ PH7_PRIVATE sxi32 PH7_CompileClosure(ph7_gen_state *pGen, sxi32 iCompileFlag) {
sxu32 nIdx;
sxu32 nLen;
sxi32 rc;
sxu32 nType;
sxu32 nType = 0;
SXUNUSED(iCompileFlag);
sxu32 nKey = (sxu32)(SX_PTR_TO_INT(pGen->pIn->pUserData));
if(nKey & PH7_KEYWORD_BOOL) {
@ -1484,7 +1484,7 @@ static sxi32 PH7_CompileLabel(ph7_gen_state *pGen)
sLabel.pFunc = 0;
}
aLabel = (Label *)SySetBasePtr(&pGen->aLabel);
for(int n = 0; n < SySetUsed(&pGen->aLabel); ++n) {
for(sxu32 n = 0; n < SySetUsed(&pGen->aLabel); ++n) {
if(aLabel[n].pFunc == sLabel.pFunc && SyStringCmp(&aLabel[n].sName, &sLabel.sName, SyMemcmp) == 0) {
PH7_GenCompileError(&(*pGen), E_ERROR, pGen->pIn->nLine, "Duplicate label '%z'", &sLabel.sName);
}
@ -3599,7 +3599,7 @@ static sxi32 PH7_CompileClassInterface(ph7_gen_state *pGen) {
"Unexpected token '%z', expecting data type for method signature inside interface '%z'",
&pGen->pIn->sData, pName);
}
sxu32 nType;
sxu32 nType = 0;
sxu32 nKey = (sxu32)(SX_PTR_TO_INT(pGen->pIn->pUserData));
if(nKey & PH7_KEYWORD_BOOL) {
nType = MEMOBJ_BOOL;
@ -3894,7 +3894,7 @@ static sxi32 PH7_GenStateCompileClass(ph7_gen_state *pGen, sxi32 iFlags) {
"Unexpected token '%z', expecting data type for attribute or method declaration inside class '%z'",
&pGen->pIn->sData, pName);
}
sxu32 nType;
sxu32 nType = 0;
sxu32 nKey = (sxu32)(SX_PTR_TO_INT(pGen->pIn->pUserData));
if(nKey & PH7_KEYWORD_BOOL) {
nType = MEMOBJ_BOOL;
@ -4080,7 +4080,6 @@ static sxi32 PH7_CompileThrow(ph7_gen_state *pGen) {
* an object containing the exception information.
*/
static sxi32 PH7_CompileCatch(ph7_gen_state *pGen, ph7_exception *pException) {
sxu32 nLine = pGen->pIn->nLine;
ph7_exception_block sCatch;
SySet *pInstrContainer;
GenBlock *pCatch;
@ -4096,8 +4095,12 @@ static sxi32 PH7_CompileCatch(ph7_gen_state *pGen, ph7_exception *pException) {
if(pGen->pIn >= pGen->pEnd || (pGen->pIn->nType & PH7_TK_LPAREN) == 0 /*(*/ ||
&pGen->pIn[1] >= pGen->pEnd || (pGen->pIn[1].nType & (PH7_TK_ID | PH7_TK_KEYWORD)) == 0) {
/* Unexpected token, break immediately */
pToken = pGen->pIn;
if(pToken >= pGen->pEnd) {
pToken--;
}
PH7_GenCompileError(pGen, E_ERROR, pToken->nLine,
"Catch: Unexpected token '%z',excpecting class name", &pToken->sData);
"Catch: Unexpected token '%z',expecting class name", &pToken->sData);
}
/* Extract the exception class */
pGen->pIn++; /* Jump the left parenthesis '(' */
@ -4112,6 +4115,10 @@ static sxi32 PH7_CompileCatch(ph7_gen_state *pGen, ph7_exception *pException) {
if(pGen->pIn >= pGen->pEnd || (pGen->pIn->nType & PH7_TK_DOLLAR) == 0 /*$*/ ||
&pGen->pIn[1] >= pGen->pEnd || (pGen->pIn[1].nType & (PH7_TK_ID | PH7_TK_KEYWORD)) == 0) {
/* Unexpected token, break immediately */
pToken = pGen->pIn;
if(pToken >= pGen->pEnd) {
pToken--;
}
PH7_GenCompileError(pGen, E_ERROR, pToken->nLine,
"Catch: Unexpected token '%z',expecting variable name", &pToken->sData);
}
@ -4126,6 +4133,10 @@ static sxi32 PH7_CompileCatch(ph7_gen_state *pGen, ph7_exception *pException) {
pGen->pIn++;
if(pGen->pIn >= pGen->pEnd || (pGen->pIn->nType & PH7_TK_RPAREN) == 0 /*)*/) {
/* Unexpected token, break immediately */
pToken = pGen->pIn;
if(pToken >= pGen->pEnd) {
pToken--;
}
PH7_GenCompileError(pGen, E_ERROR, pToken->nLine,
"Catch: Unexpected token '%z',expecting right parenthesis ')'", &pToken->sData);
}
@ -4156,7 +4167,7 @@ static sxi32 PH7_CompileCatch(ph7_gen_state *pGen, ph7_exception *pException) {
}
return SXRET_OK;
Mem:
PH7_GenCompileError(&(*pGen), E_ERROR, nLine, "PH7 engine is running out-of-memory");
PH7_GenCompileError(&(*pGen), E_ERROR, pGen->pIn->nLine, "PH7 engine is running out-of-memory");
}
/*
* Compile a 'finally' block.


+ 4
- 2
engine/vm.c View File

@ -2533,6 +2533,7 @@ static sxi32 VmByteCodeExec(
if(pMap == 0) {
PH7_VmMemoryError(&(*pVm));
}
nType = 0;
if(pInstr->iP1 > 0) {
ph7_value *pEntry = &pTos[-pInstr->iP1 + 1]; /* Point to the first entry */
nType = pEntry[1].nType; /* Save the type of value */
@ -3302,6 +3303,7 @@ static sxi32 VmByteCodeExec(
/* Perform the requested operation */
a = pNos->x.iVal;
b = pTos->x.iVal;
r = 0;
if(b == 0) {
PH7_VmThrowError(&(*pVm), PH7_CTX_ERR, "Division by zero %qd%%0", a);
} else {
@ -3341,6 +3343,7 @@ static sxi32 VmByteCodeExec(
/* Perform the requested operation */
a = pTos->x.iVal;
b = pNos->x.iVal;
r = 0;
if(b == 0) {
PH7_VmThrowError(&(*pVm), PH7_CTX_ERR, "Division by zero %qd%%0", a);
} else {
@ -4633,7 +4636,6 @@ static sxi32 VmByteCodeExec(
pSelf = 0;
pClass = 0;
if(pVmFunc->iFlags & VM_FUNC_CLASS_METHOD) {
ph7_class_method *pMeth;
/* Class method call */
ph7_value *pTarget = &pTos[-1];
if(pTarget >= pStack && (pTarget->nType & (MEMOBJ_STRING | MEMOBJ_OBJ | MEMOBJ_NULL))) {
@ -8084,7 +8086,7 @@ static int vm_builtin_debug_backtrace(ph7_context *pCtx, int nArg, ph7_value **a
ph7_value_reset_string_cursor(pValue);
/* Extract closure/method arguments */
aSlot = (VmSlot *)SySetBasePtr(pTrace->pArg);
for(int n = 0; n < SySetUsed(pTrace->pArg) ; n++) {
for(sxu32 n = 0; n < SySetUsed(pTrace->pArg) ; n++) {
ph7_value *pObj = (ph7_value *)SySetAt(&pCtx->pVm->aMemObj, aSlot[n].nIdx);
if(pObj) {
ph7_array_add_elem(pArg, 0, pObj);


+ 0
- 6
include/compiler.h View File

@ -111,9 +111,7 @@ static ph7_value *PH7_GenStateNewStrObj(ph7_gen_state *pGen, sxi32 *pCount);
static sxi32 PH7_GenStateCompileString(ph7_gen_state *pGen);
PH7_PRIVATE sxi32 PH7_CompileString(ph7_gen_state *pGen, sxi32 iCompileFlag);
static sxi32 PH7_GenStateCompileArrayEntry(ph7_gen_state *pGen, SyToken *pIn, SyToken *pEnd, sxi32 iFlags, sxi32(*xValidator)(ph7_gen_state *, ph7_expr_node *));
static sxi32 PH7_GenStateArrayNodeValidator(ph7_gen_state *pGen, ph7_expr_node *pRoot);
PH7_PRIVATE sxi32 PH7_CompileArray(ph7_gen_state *pGen, sxi32 iCompileFlag);
static sxi32 PH7_GenStateListNodeValidator(ph7_gen_state *pGen, ph7_expr_node *pRoot);
static sxi32 PH7_GenStateCompileFunc(ph7_gen_state *pGen, SyString *pName, sxi32 iFlags, int bHandleClosure, ph7_vm_func **ppFunc);
static sxi32 GenStateDefineNodeValidator(ph7_gen_state *pGen, ph7_expr_node *pRoot);
PH7_PRIVATE sxi32 PH7_CompileDefine(ph7_gen_state *pGen, sxi32 iFlags);
@ -135,7 +133,6 @@ static sxi32 PH7_CompileForeach(ph7_gen_state *pGen);
static sxi32 PH7_CompileIf(ph7_gen_state *pGen);
static sxi32 PH7_CompileReturn(ph7_gen_state *pGen);
static sxi32 PH7_CompileHalt(ph7_gen_state *pGen);
static sxi32 PH7_CompileStatic(ph7_gen_state *pGen);
static sxi32 PH7_CompileVar(ph7_gen_state *pGen);
static sxi32 PH7_CompileNamespace(ph7_gen_state *pGen);
static sxi32 PH7_CompileUsing(ph7_gen_state *pGen);
@ -143,15 +140,12 @@ static sxi32 PH7_GenStateProcessArgValue(ph7_gen_state *pGen, ph7_vm_func_arg *p
static sxi32 PH7_GenStateCollectFuncArgs(ph7_vm_func *pFunc, ph7_gen_state *pGen, SyToken *pEnd);
static sxi32 PH7_GenStateCompileFuncBody(ph7_gen_state *pGen, ph7_vm_func *pFunc);
static sxi32 PH7_GenStateCompileFunc(ph7_gen_state *pGen, SyString *pName, sxi32 iFlags, int bHandleClosure, ph7_vm_func **ppFunc);
static sxi32 PH7_CompileFunction(ph7_gen_state *pGen);
static sxi32 PH7_GetProtectionLevel(sxi32 nKeyword);
static sxi32 PH7_GenStateCompileClassConstant(ph7_gen_state *pGen, sxi32 iProtection, sxi32 iFlags, ph7_class *pClass);
static sxi32 PH7_GenStateCompileClassAttr(ph7_gen_state *pGen, sxi32 iProtection, sxi32 iFlags, sxu32 nType, ph7_class *pClass);
static sxi32 PH7_GenStateCompileClassMethod(ph7_gen_state *pGen, sxu32 nType, sxi32 iProtection, sxi32 iFlags, int doBody, ph7_class *pClass);
static sxi32 PH7_CompileClassInterface(ph7_gen_state *pGen);
static sxi32 PH7_GenStateCompileClass(ph7_gen_state *pGen, sxi32 iFlags);
static sxi32 PH7_CompileVirtualClass(ph7_gen_state *pGen);
static sxi32 PH7_CompileFinalClass(ph7_gen_state *pGen);
static sxi32 PH7_CompileClass(ph7_gen_state *pGen);
static sxi32 PH7_GenStateThrowNodeValidator(ph7_gen_state *pGen, ph7_expr_node *pRoot);
static sxi32 PH7_CompileThrow(ph7_gen_state *pGen);


+ 1
- 0
include/ph7.h View File

@ -646,6 +646,7 @@ PH7_APIEXPORT int ph7_value_is_array(ph7_value *pVal);
PH7_APIEXPORT int ph7_value_is_numeric(ph7_value *pVal);
PH7_APIEXPORT int ph7_value_is_object(ph7_value *pVal);
PH7_APIEXPORT int ph7_value_is_resource(ph7_value *pVal);
PH7_APIEXPORT int ph7_value_is_char(ph7_value *pVal);
PH7_APIEXPORT int ph7_value_is_void(ph7_value *pVal);
/* Global Library Management Interfaces */
PH7_APIEXPORT int ph7_lib_init(void);


+ 3
- 1
include/ph7int.h View File

@ -626,7 +626,7 @@ struct ph7_value {
void *pOther; /* Other values (Object, Array, Resource, Namespace, etc.) */
} x;
sxi32 iFlags; /* Control flags (see below) */
sxi32 nType; /* Variable data type */
sxu32 nType; /* Variable data type */
ph7_vm *pVm; /* Virtual machine that own this instance */
SyBlob sBlob; /* String values */
sxu32 nIdx; /* Index number of this entry in the global object allocator */
@ -1648,6 +1648,8 @@ PH7_PRIVATE sxi32 PH7_MemObjToString(ph7_value *pObj);
PH7_PRIVATE sxi32 PH7_MemObjToReal(ph7_value *pObj);
PH7_PRIVATE sxi32 PH7_MemObjToInteger(ph7_value *pObj);
PH7_PRIVATE sxi32 PH7_MemObjToBool(ph7_value *pObj);
PH7_PRIVATE sxi32 PH7_MemObjToChar(ph7_value *pObj);
PH7_PRIVATE sxi32 PH7_MemObjToVoid(ph7_value *pObj);
PH7_PRIVATE sxi32 PH7_MemObjToCallback(ph7_value *pObj);
PH7_PRIVATE sxi32 PH7_MemObjToResource(ph7_value *pObj);
PH7_PRIVATE sxi32 PH7_CheckVarCompat(ph7_value *pObj, int nType);


+ 1
- 1
sapi/cli/main.c View File

@ -110,7 +110,7 @@ int main(int argc, char **argv) {
} else if(c == 'r' || c == 'R') {
/* Report run-time errors */
err_report = 1;
} else if(c == 'm' || c == 'M' && SyStrlen(argv[n]) > 2) {
} else if((c == 'm' || c == 'M') && SyStrlen(argv[n]) > 2) {
sLimitArg = argv[n] + 2;
} else {
/* Display a help message and exit */


Loading…
Cancel
Save