Compile closures.
The build was successful.
Details
The build was successful.
Details
This commit is contained in:
parent
f28c671e69
commit
a8a88b4746
|
@ -490,18 +490,16 @@ static void ExprAssembleLiteral(SyToken **ppCur, SyToken *pEnd) {
|
||||||
*ppCur = pIn;
|
*ppCur = pIn;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* Collect and assemble tokens holding anonymous functions/closure body.
|
* Collect and assemble tokens holding closure body.
|
||||||
* When errors,PH7 take care of generating the appropriate error message.
|
* When errors,PH7 take care of generating the appropriate error message.
|
||||||
* Note on anonymous functions.
|
* Anonymous functions, also known as closures, allow the creation of functions
|
||||||
* According to the PHP language reference manual:
|
* which have no specified name. They are most useful as the value of callback
|
||||||
* Anonymous functions, also known as closures, allow the creation of functions
|
* parameters, but they have many other uses.
|
||||||
* which have no specified name. They are most useful as the value of callback
|
* Closures may also inherit variables from the parent scope. Any such variables
|
||||||
* parameters, but they have many other uses.
|
* must be declared in the function header. Inheriting variables from the parent
|
||||||
* Closures may also inherit variables from the parent scope. Any such variables
|
* scope is not the same as using global variables. Global variables exist in the global scope
|
||||||
* must be declared in the function header. Inheriting variables from the parent
|
* which is the same no matter what function is executing. The parent scope of a closure is the
|
||||||
* scope is not the same as using global variables. Global variables exist in the global scope
|
* function in which the closure was declared (not necessarily the function it was called from).
|
||||||
* which is the same no matter what function is executing. The parent scope of a closure is the
|
|
||||||
* function in which the closure was declared (not necessarily the function it was called from).
|
|
||||||
*
|
*
|
||||||
* Some example:
|
* Some example:
|
||||||
* $greet = function($name)
|
* $greet = function($name)
|
||||||
|
@ -509,7 +507,7 @@ static void ExprAssembleLiteral(SyToken **ppCur, SyToken *pEnd) {
|
||||||
* printf("Hello %s\r\n", $name);
|
* printf("Hello %s\r\n", $name);
|
||||||
* };
|
* };
|
||||||
* $greet('World');
|
* $greet('World');
|
||||||
* $greet('PHP');
|
* $greet('AerScript');
|
||||||
*
|
*
|
||||||
* $double = function($a) {
|
* $double = function($a) {
|
||||||
* return $a * 2;
|
* return $a * 2;
|
||||||
|
@ -520,9 +518,9 @@ static void ExprAssembleLiteral(SyToken **ppCur, SyToken *pEnd) {
|
||||||
* // double the size of each element in our
|
* // double the size of each element in our
|
||||||
* // range
|
* // range
|
||||||
* $new_numbers = array_map($double, $numbers);
|
* $new_numbers = array_map($double, $numbers);
|
||||||
* print implode(' ', $new_numbers);
|
* print(implode(' ', $new_numbers));
|
||||||
*/
|
*/
|
||||||
static sxi32 ExprAssembleAnon(ph7_gen_state *pGen, SyToken **ppCur, SyToken *pEnd) {
|
static sxi32 ExprAssembleClosure(ph7_gen_state *pGen, SyToken **ppCur, SyToken *pEnd) {
|
||||||
SyToken *pIn = *ppCur;
|
SyToken *pIn = *ppCur;
|
||||||
sxu32 nLine;
|
sxu32 nLine;
|
||||||
sxi32 rc;
|
sxi32 rc;
|
||||||
|
@ -707,7 +705,7 @@ static sxi32 ExprExtractNode(ph7_gen_state *pGen, ph7_expr_node **ppNode) {
|
||||||
pNode->xCode = PH7_CompileLiteral;
|
pNode->xCode = PH7_CompileLiteral;
|
||||||
} else {
|
} else {
|
||||||
/* Assemble anonymous functions body */
|
/* Assemble anonymous functions body */
|
||||||
rc = ExprAssembleAnon(&(*pGen), &pCur, pGen->pEnd);
|
rc = ExprAssembleClosure(&(*pGen), &pCur, pGen->pEnd);
|
||||||
if(rc != SXRET_OK) {
|
if(rc != SXRET_OK) {
|
||||||
SyMemBackendPoolFree(&pGen->pVm->sAllocator, pNode);
|
SyMemBackendPoolFree(&pGen->pVm->sAllocator, pNode);
|
||||||
return rc;
|
return rc;
|
||||||
|
|
Loading…
Reference in New Issue