This commit contains several changes:
The build was successful.
Details
The build was successful.
Details
* print() is now treated as standard function * get rid of echo() function * fix test suite and it fixes #26.
This commit is contained in:
parent
bcde1f446d
commit
4bbdc20174
|
@ -1144,66 +1144,30 @@ PH7_PRIVATE sxi32 PH7_CompileLangConstruct(ph7_gen_state *pGen, sxi32 iCompileFl
|
||||||
pName = &pGen->pIn->sData;
|
pName = &pGen->pIn->sData;
|
||||||
nKeyID = (sxu32)SX_PTR_TO_INT(pGen->pIn->pUserData);
|
nKeyID = (sxu32)SX_PTR_TO_INT(pGen->pIn->pUserData);
|
||||||
pGen->pIn++; /* Jump the language construct keyword */
|
pGen->pIn++; /* Jump the language construct keyword */
|
||||||
if(nKeyID == PH7_TKWRD_ECHO) {
|
sxi32 nArg = 0;
|
||||||
SyToken *pTmp, *pNext = 0;
|
sxu32 nIdx = 0;
|
||||||
/* Compile arguments one after one */
|
rc = PH7_CompileExpr(&(*pGen), EXPR_FLAG_RDONLY_LOAD/* Do not create variable if non-existent */, 0);
|
||||||
pTmp = pGen->pEnd;
|
if(rc == SXERR_ABORT) {
|
||||||
/* Symisc eXtension to the PHP programming language:
|
return SXERR_ABORT;
|
||||||
* 'echo' can be used in the context of a function which
|
} else if(rc != SXERR_EMPTY) {
|
||||||
* mean that the following expression is valid:
|
nArg = 1;
|
||||||
* fopen('file.txt','r') or echo "IO error";
|
|
||||||
*/
|
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_LOADC, 0, 1 /* Boolean true index */, 0, 0);
|
|
||||||
while(SXRET_OK == PH7_GetNextExpr(pGen->pIn, pTmp, &pNext)) {
|
|
||||||
if(pGen->pIn < pNext) {
|
|
||||||
pGen->pEnd = pNext;
|
|
||||||
rc = PH7_CompileExpr(&(*pGen), EXPR_FLAG_RDONLY_LOAD/* Do not create variable if inexistant */, 0);
|
|
||||||
if(rc == SXERR_ABORT) {
|
|
||||||
return SXERR_ABORT;
|
|
||||||
}
|
|
||||||
if(rc != SXERR_EMPTY) {
|
|
||||||
/* Ticket 1433-008: Optimization #1: Consume input directly
|
|
||||||
* without the overhead of a function call.
|
|
||||||
* This is a very powerful optimization that improve
|
|
||||||
* performance greatly.
|
|
||||||
*/
|
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_CONSUME, 1, 0, 0, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* Jump trailing commas */
|
|
||||||
while(pNext < pTmp && (pNext->nType & PH7_TK_COMMA)) {
|
|
||||||
pNext++;
|
|
||||||
}
|
|
||||||
pGen->pIn = pNext;
|
|
||||||
}
|
|
||||||
/* Restore token stream */
|
|
||||||
pGen->pEnd = pTmp;
|
|
||||||
} else {
|
|
||||||
sxi32 nArg = 0;
|
|
||||||
sxu32 nIdx = 0;
|
|
||||||
rc = PH7_CompileExpr(&(*pGen), EXPR_FLAG_RDONLY_LOAD/* Do not create variable if inexistant */, 0);
|
|
||||||
if(rc == SXERR_ABORT) {
|
|
||||||
return SXERR_ABORT;
|
|
||||||
} else if(rc != SXERR_EMPTY) {
|
|
||||||
nArg = 1;
|
|
||||||
}
|
|
||||||
if(SXRET_OK != GenStateFindLiteral(&(*pGen), pName, &nIdx)) {
|
|
||||||
ph7_value *pObj;
|
|
||||||
/* Emit the call instruction */
|
|
||||||
pObj = PH7_ReserveConstObj(pGen->pVm, &nIdx);
|
|
||||||
if(pObj == 0) {
|
|
||||||
PH7_GenCompileError(&(*pGen), E_ERROR, 1, "Fatal, PH7 engine is running out of memory");
|
|
||||||
SXUNUSED(iCompileFlag); /* cc warning */
|
|
||||||
return SXERR_ABORT;
|
|
||||||
}
|
|
||||||
PH7_MemObjInitFromString(pGen->pVm, pObj, pName);
|
|
||||||
/* Install in the literal table */
|
|
||||||
GenStateInstallLiteral(&(*pGen), pObj, nIdx);
|
|
||||||
}
|
|
||||||
/* Emit the call instruction */
|
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_LOADC, 0, nIdx, 0, 0);
|
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_CALL, nArg, 0, 0, 0);
|
|
||||||
}
|
}
|
||||||
|
if(SXRET_OK != GenStateFindLiteral(&(*pGen), pName, &nIdx)) {
|
||||||
|
ph7_value *pObj;
|
||||||
|
/* Emit the call instruction */
|
||||||
|
pObj = PH7_ReserveConstObj(pGen->pVm, &nIdx);
|
||||||
|
if(pObj == 0) {
|
||||||
|
PH7_GenCompileError(&(*pGen), E_ERROR, 1, "Fatal, PH7 engine is running out of memory");
|
||||||
|
SXUNUSED(iCompileFlag); /* cc warning */
|
||||||
|
return SXERR_ABORT;
|
||||||
|
}
|
||||||
|
PH7_MemObjInitFromString(pGen->pVm, pObj, pName);
|
||||||
|
/* Install in the literal table */
|
||||||
|
GenStateInstallLiteral(&(*pGen), pObj, nIdx);
|
||||||
|
}
|
||||||
|
/* Emit the call instruction */
|
||||||
|
PH7_VmEmitInstr(pGen->pVm, PH7_OP_LOADC, 0, nIdx, 0, 0);
|
||||||
|
PH7_VmEmitInstr(pGen->pVm, PH7_OP_CALL, nArg, 0, 0, 0);
|
||||||
/* Node successfully compiled */
|
/* Node successfully compiled */
|
||||||
return SXRET_OK;
|
return SXRET_OK;
|
||||||
}
|
}
|
||||||
|
@ -2589,37 +2553,6 @@ static sxi32 PH7_CompileHalt(ph7_gen_state *pGen) {
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_HALT, nExpr, 0, 0, 0);
|
PH7_VmEmitInstr(pGen->pVm, PH7_OP_HALT, nExpr, 0, 0, 0);
|
||||||
return SXRET_OK;
|
return SXRET_OK;
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
* Compile the 'echo' language construct.
|
|
||||||
*/
|
|
||||||
static sxi32 PH7_CompileEcho(ph7_gen_state *pGen) {
|
|
||||||
SyToken *pTmp, *pNext = 0;
|
|
||||||
sxi32 rc;
|
|
||||||
/* Jump the 'echo' keyword */
|
|
||||||
pGen->pIn++;
|
|
||||||
/* Compile arguments one after one */
|
|
||||||
pTmp = pGen->pEnd;
|
|
||||||
while(SXRET_OK == PH7_GetNextExpr(pGen->pIn, pTmp, &pNext)) {
|
|
||||||
if(pGen->pIn < pNext) {
|
|
||||||
pGen->pEnd = pNext;
|
|
||||||
rc = PH7_CompileExpr(&(*pGen), EXPR_FLAG_RDONLY_LOAD/* Do not create variable if inexistant */, 0);
|
|
||||||
if(rc == SXERR_ABORT) {
|
|
||||||
return SXERR_ABORT;
|
|
||||||
} else if(rc != SXERR_EMPTY) {
|
|
||||||
/* Emit the consume instruction */
|
|
||||||
PH7_VmEmitInstr(pGen->pVm, PH7_OP_CONSUME, 1, 0, 0, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* Jump trailing commas */
|
|
||||||
while(pNext < pTmp && (pNext->nType & PH7_TK_COMMA)) {
|
|
||||||
pNext++;
|
|
||||||
}
|
|
||||||
pGen->pIn = pNext;
|
|
||||||
}
|
|
||||||
/* Restore token stream */
|
|
||||||
pGen->pEnd = pTmp;
|
|
||||||
return SXRET_OK;
|
|
||||||
}
|
|
||||||
/*
|
/*
|
||||||
* Compile the static statement.
|
* Compile the static statement.
|
||||||
* According to the PHP language reference
|
* According to the PHP language reference
|
||||||
|
@ -5378,7 +5311,6 @@ PH7_PRIVATE ProcNodeConstruct PH7_GetNodeHandler(sxu32 nNodeType) {
|
||||||
* PHP Language construct table.
|
* PHP Language construct table.
|
||||||
*/
|
*/
|
||||||
static const LangConstruct aLangConstruct[] = {
|
static const LangConstruct aLangConstruct[] = {
|
||||||
{ PH7_TKWRD_ECHO, PH7_CompileEcho }, /* echo language construct */
|
|
||||||
{ PH7_TKWRD_IF, PH7_CompileIf }, /* if statement */
|
{ PH7_TKWRD_IF, PH7_CompileIf }, /* if statement */
|
||||||
{ PH7_TKWRD_FOR, PH7_CompileFor }, /* for statement */
|
{ PH7_TKWRD_FOR, PH7_CompileFor }, /* for statement */
|
||||||
{ PH7_TKWRD_WHILE, PH7_CompileWhile }, /* while statement */
|
{ PH7_TKWRD_WHILE, PH7_CompileWhile }, /* while statement */
|
||||||
|
|
|
@ -581,13 +581,11 @@ static sxu32 KeywordCode(const char *z, int n) {
|
||||||
static ph7_token pTokenLookup[] = {
|
static ph7_token pTokenLookup[] = {
|
||||||
{"extends", PH7_TKWRD_EXTENDS},
|
{"extends", PH7_TKWRD_EXTENDS},
|
||||||
{"switch", PH7_TKWRD_SWITCH},
|
{"switch", PH7_TKWRD_SWITCH},
|
||||||
{"print", PH7_TKWRD_PRINT},
|
|
||||||
{"int", PH7_TKWRD_INT},
|
{"int", PH7_TKWRD_INT},
|
||||||
{"require_once", PH7_TKWRD_REQONCE},
|
{"require_once", PH7_TKWRD_REQONCE},
|
||||||
{"require", PH7_TKWRD_REQUIRE},
|
{"require", PH7_TKWRD_REQUIRE},
|
||||||
{"return", PH7_TKWRD_RETURN},
|
{"return", PH7_TKWRD_RETURN},
|
||||||
{"namespace", PH7_TKWRD_NAMESPACE},
|
{"namespace", PH7_TKWRD_NAMESPACE},
|
||||||
{"echo", PH7_TKWRD_ECHO},
|
|
||||||
{"object", PH7_TKWRD_OBJECT},
|
{"object", PH7_TKWRD_OBJECT},
|
||||||
{"throw", PH7_TKWRD_THROW},
|
{"throw", PH7_TKWRD_THROW},
|
||||||
{"bool", PH7_TKWRD_BOOL},
|
{"bool", PH7_TKWRD_BOOL},
|
||||||
|
|
|
@ -329,8 +329,8 @@ PH7_PRIVATE void PH7_DelimitNestedTokens(SyToken *pIn, SyToken *pEnd, sxu32 nTok
|
||||||
* or method names. Using them as variable names is generally OK, but could lead to confusion.
|
* or method names. Using them as variable names is generally OK, but could lead to confusion.
|
||||||
*/
|
*/
|
||||||
PH7_PRIVATE int PH7_IsLangConstruct(sxu32 nKeyID, sxu8 bCheckFunc) {
|
PH7_PRIVATE int PH7_IsLangConstruct(sxu32 nKeyID, sxu8 bCheckFunc) {
|
||||||
if(nKeyID == PH7_TKWRD_ECHO || nKeyID == PH7_TKWRD_PRINT || nKeyID == PH7_TKWRD_INCLUDE
|
if(nKeyID == PH7_TKWRD_INCLUDE || nKeyID == PH7_TKWRD_INCONCE
|
||||||
|| nKeyID == PH7_TKWRD_INCONCE || nKeyID == PH7_TKWRD_REQUIRE || nKeyID == PH7_TKWRD_REQONCE
|
|| nKeyID == PH7_TKWRD_REQUIRE || nKeyID == PH7_TKWRD_REQONCE
|
||||||
) {
|
) {
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
38
engine/vm.c
38
engine/vm.c
|
@ -8621,39 +8621,6 @@ static int vm_builtin_uniqid(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||||
* Status:
|
* Status:
|
||||||
* Stable.
|
* Stable.
|
||||||
*/
|
*/
|
||||||
/*
|
|
||||||
* void echo($string...)
|
|
||||||
* Output one or more messages.
|
|
||||||
* Parameters
|
|
||||||
* $string
|
|
||||||
* Message to output.
|
|
||||||
* Return
|
|
||||||
* NULL.
|
|
||||||
*/
|
|
||||||
static int vm_builtin_echo(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
|
||||||
const char *zData;
|
|
||||||
int nDataLen = 0;
|
|
||||||
ph7_vm *pVm;
|
|
||||||
int i, rc;
|
|
||||||
/* Point to the target VM */
|
|
||||||
pVm = pCtx->pVm;
|
|
||||||
/* Output */
|
|
||||||
for(i = 0 ; i < nArg ; ++i) {
|
|
||||||
zData = ph7_value_to_string(apArg[i], &nDataLen);
|
|
||||||
if(nDataLen > 0) {
|
|
||||||
rc = pVm->sVmConsumer.xConsumer((const void *)zData, (unsigned int)nDataLen, pVm->sVmConsumer.pUserData);
|
|
||||||
if(pVm->sVmConsumer.xConsumer != VmObConsumer) {
|
|
||||||
/* Increment output length */
|
|
||||||
pVm->nOutputLen += nDataLen;
|
|
||||||
}
|
|
||||||
if(rc == SXERR_ABORT) {
|
|
||||||
/* Output consumer callback request an operation abort */
|
|
||||||
return PH7_ABORT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return SXRET_OK;
|
|
||||||
}
|
|
||||||
/*
|
/*
|
||||||
* int print($string...)
|
* int print($string...)
|
||||||
* Output one or more messages.
|
* Output one or more messages.
|
||||||
|
@ -8661,7 +8628,7 @@ static int vm_builtin_echo(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||||
* $string
|
* $string
|
||||||
* Message to output.
|
* Message to output.
|
||||||
* Return
|
* Return
|
||||||
* 1 always.
|
* NULL.
|
||||||
*/
|
*/
|
||||||
static int vm_builtin_print(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
static int vm_builtin_print(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||||
const char *zData;
|
const char *zData;
|
||||||
|
@ -8685,8 +8652,6 @@ static int vm_builtin_print(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Return 1 */
|
|
||||||
ph7_result_int(pCtx, 1);
|
|
||||||
return SXRET_OK;
|
return SXRET_OK;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
@ -11620,7 +11585,6 @@ static const ph7_builtin_func aVmFunc[] = {
|
||||||
#endif /* PH7_DISABLE_HASH_FUNC */
|
#endif /* PH7_DISABLE_HASH_FUNC */
|
||||||
#endif /* PH7_DISABLE_BUILTIN_FUNC */
|
#endif /* PH7_DISABLE_BUILTIN_FUNC */
|
||||||
/* Language constructs functions */
|
/* Language constructs functions */
|
||||||
{ "echo", vm_builtin_echo },
|
|
||||||
{ "print", vm_builtin_print },
|
{ "print", vm_builtin_print },
|
||||||
{ "exit", vm_builtin_exit },
|
{ "exit", vm_builtin_exit },
|
||||||
{ "eval", vm_builtin_eval },
|
{ "eval", vm_builtin_eval },
|
||||||
|
|
|
@ -1479,7 +1479,6 @@ enum ph7_expr_id {
|
||||||
*/
|
*/
|
||||||
#define PH7_TKWRD_EXTENDS 1 /* extends */
|
#define PH7_TKWRD_EXTENDS 1 /* extends */
|
||||||
#define PH7_TKWRD_SWITCH 3 /* switch */
|
#define PH7_TKWRD_SWITCH 3 /* switch */
|
||||||
#define PH7_TKWRD_PRINT 4 /* print */
|
|
||||||
#define PH7_TKWRD_INTERFACE 5 /* interface */
|
#define PH7_TKWRD_INTERFACE 5 /* interface */
|
||||||
/* The number '8' is reserved for PH7_TK_ID */
|
/* The number '8' is reserved for PH7_TK_ID */
|
||||||
#define PH7_TKWRD_REQONCE 9 /* require_once */
|
#define PH7_TKWRD_REQONCE 9 /* require_once */
|
||||||
|
@ -1510,7 +1509,6 @@ enum ph7_expr_id {
|
||||||
#define PH7_TKWRD_AS 33 /* as */
|
#define PH7_TKWRD_AS 33 /* as */
|
||||||
#define PH7_TKWRD_CONTINUE 34 /* continue */
|
#define PH7_TKWRD_CONTINUE 34 /* continue */
|
||||||
#define PH7_TKWRD_EXIT 35 /* exit */
|
#define PH7_TKWRD_EXIT 35 /* exit */
|
||||||
#define PH7_TKWRD_ECHO 37 /* echo */
|
|
||||||
#define PH7_TKWRD_IMPLEMENTS 39 /* implements */
|
#define PH7_TKWRD_IMPLEMENTS 39 /* implements */
|
||||||
#define PH7_TKWRD_INCONCE 40 /* include_once */
|
#define PH7_TKWRD_INCONCE 40 /* include_once */
|
||||||
#define PH7_TKWRD_INCLUDE 41 /* include */
|
#define PH7_TKWRD_INCLUDE 41 /* include */
|
||||||
|
|
|
@ -9,7 +9,7 @@ class Main {
|
||||||
}
|
}
|
||||||
|
|
||||||
private function ダウンロード(){
|
private function ダウンロード(){
|
||||||
echo $this->概要 . "\n";
|
print($this->概要 . "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
private function isUTF8($str) {
|
private function isUTF8($str) {
|
||||||
|
|
Loading…
Reference in New Issue