Compile closures.
All checks were successful
The build was successful.

This commit is contained in:
Rafal Kupiec 2018-08-16 18:31:12 +02:00
parent 074edd11d3
commit f28c671e69
Signed by: belliash
GPG Key ID: 4E829243E0CFE6B4
4 changed files with 5 additions and 9 deletions

View File

@ -969,8 +969,8 @@ PH7_PRIVATE sxi32 PH7_CompileList(ph7_gen_state *pGen, sxi32 iCompileFlag) {
return SXRET_OK; return SXRET_OK;
} }
/* /*
* Compile an anonymous function or a closure. * Compile a closure (anonymous function).
* Anonymous functions, also known as closures, allow the creation of functions * Closures (also known as anonymous functions), allow the creation of functions
* which have no specified name. They are most useful as the value of callback * which have no specified name. They are most useful as the value of callback
* parameters, but they have many other uses. Closures can also be used as * parameters, but they have many other uses. Closures can also be used as
* the values of variables; Assigning a closure to a variable uses the same * the values of variables; Assigning a closure to a variable uses the same
@ -982,11 +982,8 @@ PH7_PRIVATE sxi32 PH7_CompileList(ph7_gen_state *pGen, sxi32 iCompileFlag) {
* }; * };
* $greet('World'); * $greet('World');
* $greet('AerScript'); * $greet('AerScript');
* ?>
* Note that the implementation of anonymous function and closure under
* PH7 is completely different from the one used by the zend engine.
*/ */
PH7_PRIVATE sxi32 PH7_CompileAnonFunc(ph7_gen_state *pGen, sxi32 iCompileFlag) { PH7_PRIVATE sxi32 PH7_CompileClosure(ph7_gen_state *pGen, sxi32 iCompileFlag) {
ph7_vm_func *pAnonFunc; /* Anonymous function body */ ph7_vm_func *pAnonFunc; /* Anonymous function body */
char zName[512]; /* Unique closure name */ char zName[512]; /* Unique closure name */
static int iCnt = 1; /* There is no worry about thread-safety here,because only static int iCnt = 1; /* There is no worry about thread-safety here,because only

View File

@ -712,7 +712,7 @@ static sxi32 ExprExtractNode(ph7_gen_state *pGen, ph7_expr_node **ppNode) {
SyMemBackendPoolFree(&pGen->pVm->sAllocator, pNode); SyMemBackendPoolFree(&pGen->pVm->sAllocator, pNode);
return rc; return rc;
} }
pNode->xCode = PH7_CompileAnonFunc; pNode->xCode = PH7_CompileClosure;
} }
} else { } else {
/* Assume a literal */ /* Assume a literal */

View File

@ -96,7 +96,6 @@ 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_GenStateListNodeValidator(ph7_gen_state *pGen, ph7_expr_node *pRoot);
PH7_PRIVATE sxi32 PH7_CompileList(ph7_gen_state *pGen, sxi32 iCompileFlag); PH7_PRIVATE sxi32 PH7_CompileList(ph7_gen_state *pGen, sxi32 iCompileFlag);
static sxi32 PH7_GenStateCompileFunc(ph7_gen_state *pGen, SyString *pName, sxi32 iFlags, int bHandleClosure, ph7_vm_func **ppFunc); static sxi32 PH7_GenStateCompileFunc(ph7_gen_state *pGen, SyString *pName, sxi32 iFlags, int bHandleClosure, ph7_vm_func **ppFunc);
PH7_PRIVATE sxi32 PH7_CompileAnonFunc(ph7_gen_state *pGen, sxi32 iCompileFlag);
PH7_PRIVATE sxi32 PH7_CompileLangConstruct(ph7_gen_state *pGen, sxi32 iCompileFlag); PH7_PRIVATE sxi32 PH7_CompileLangConstruct(ph7_gen_state *pGen, sxi32 iCompileFlag);
PH7_PRIVATE sxi32 PH7_CompileVariable(ph7_gen_state *pGen, sxi32 iCompileFlag); PH7_PRIVATE sxi32 PH7_CompileVariable(ph7_gen_state *pGen, sxi32 iCompileFlag);
static sxi32 PH7_GenStateLoadLiteral(ph7_gen_state *pGen); static sxi32 PH7_GenStateLoadLiteral(ph7_gen_state *pGen);

View File

@ -1620,7 +1620,7 @@ PH7_PRIVATE sxi32 PH7_CompileSimpleString(ph7_gen_state *pGen, sxi32 iCompileFla
PH7_PRIVATE sxi32 PH7_CompileString(ph7_gen_state *pGen, sxi32 iCompileFlag); PH7_PRIVATE sxi32 PH7_CompileString(ph7_gen_state *pGen, sxi32 iCompileFlag);
PH7_PRIVATE sxi32 PH7_CompileArray(ph7_gen_state *pGen, sxi32 iCompileFlag); PH7_PRIVATE sxi32 PH7_CompileArray(ph7_gen_state *pGen, sxi32 iCompileFlag);
PH7_PRIVATE sxi32 PH7_CompileList(ph7_gen_state *pGen, sxi32 iCompileFlag); PH7_PRIVATE sxi32 PH7_CompileList(ph7_gen_state *pGen, sxi32 iCompileFlag);
PH7_PRIVATE sxi32 PH7_CompileAnonFunc(ph7_gen_state *pGen, sxi32 iCompileFlag); PH7_PRIVATE sxi32 PH7_CompileClosure(ph7_gen_state *pGen, sxi32 iCompileFlag);
PH7_PRIVATE sxi32 PH7_InitCodeGenerator(ph7_vm *pVm, ProcConsumer xErr, void *pErrData); PH7_PRIVATE sxi32 PH7_InitCodeGenerator(ph7_vm *pVm, ProcConsumer xErr, void *pErrData);
PH7_PRIVATE sxi32 PH7_ResetCodeGenerator(ph7_vm *pVm, ProcConsumer xErr, void *pErrData); PH7_PRIVATE sxi32 PH7_ResetCodeGenerator(ph7_vm *pVm, ProcConsumer xErr, void *pErrData);
PH7_PRIVATE sxi32 PH7_GenCompileError(ph7_gen_state *pGen, sxi32 nErrType, sxu32 nLine, const char *zFormat, ...); PH7_PRIVATE sxi32 PH7_GenCompileError(ph7_gen_state *pGen, sxi32 nErrType, sxu32 nLine, const char *zFormat, ...);