diff options
| author | Joel Martin <github@martintribe.org> | 2014-04-23 21:59:50 -0500 |
|---|---|---|
| committer | Joel Martin <github@martintribe.org> | 2014-04-23 21:59:50 -0500 |
| commit | 6301e0b6374cecc5599665be14d6ddc6a31ce1e8 (patch) | |
| tree | dbf1dc2ff6c682fd87c72a7907e7f6e59c8d4c03 /php | |
| parent | 89bd4de1e2704c1bc562788b2c5e4fc08b71a538 (diff) | |
| download | mal-6301e0b6374cecc5599665be14d6ddc6a31ce1e8.tar.gz mal-6301e0b6374cecc5599665be14d6ddc6a31ce1e8.zip | |
All: TCO let* and quasiquote.
Diffstat (limited to 'php')
| -rw-r--r-- | php/step5_tco.php | 9 | ||||
| -rw-r--r-- | php/step6_file.php | 9 | ||||
| -rw-r--r-- | php/step7_quote.php | 12 | ||||
| -rw-r--r-- | php/step8_macros.php | 12 | ||||
| -rw-r--r-- | php/step9_interop.php | 12 | ||||
| -rw-r--r-- | php/stepA_more.php | 12 |
6 files changed, 44 insertions, 22 deletions
diff --git a/php/step5_tco.php b/php/step5_tco.php index 5ae29a7..88557b5 100644 --- a/php/step5_tco.php +++ b/php/step5_tco.php @@ -56,11 +56,13 @@ function MAL_EVAL($ast, $env) { for ($i=0; $i < count($a1); $i+=2) { $let_env->set($a1[$i]->value, MAL_EVAL($a1[$i+1], $let_env)); } - return MAL_EVAL($ast[2], $let_env); + $ast = $ast[2]; + $env = $let_env; + break; // Continue loop (TCO) case "do": eval_ast($ast->slice(1, -1), $env); $ast = $ast[count($ast)-1]; - break; + break; // Continue loop (TCO) case "if": $cond = MAL_EVAL($ast[1], $env); if ($cond === NULL || $cond === false) { @@ -69,7 +71,7 @@ function MAL_EVAL($ast, $env) { } else { $ast = $ast[2]; } - break; + break; // Continue loop (TCO) case "fn*": return _function('MAL_EVAL', 'native', $ast[2], $env, $ast[1]); @@ -80,6 +82,7 @@ function MAL_EVAL($ast, $env) { if ($f->type === 'native') { $ast = $f->ast; $env = $f->gen_env($args); + // Continue loop (TCO) } else { return $f->apply($args); } diff --git a/php/step6_file.php b/php/step6_file.php index b7cdcc3..1e83c28 100644 --- a/php/step6_file.php +++ b/php/step6_file.php @@ -56,11 +56,13 @@ function MAL_EVAL($ast, $env) { for ($i=0; $i < count($a1); $i+=2) { $let_env->set($a1[$i]->value, MAL_EVAL($a1[$i+1], $let_env)); } - return MAL_EVAL($ast[2], $let_env); + $ast = $ast[2]; + $env = $let_env; + break; // Continue loop (TCO) case "do": eval_ast($ast->slice(1, -1), $env); $ast = $ast[count($ast)-1]; - break; + break; // Continue loop (TCO) case "if": $cond = MAL_EVAL($ast[1], $env); if ($cond === NULL || $cond === false) { @@ -69,7 +71,7 @@ function MAL_EVAL($ast, $env) { } else { $ast = $ast[2]; } - break; + break; // Continue loop (TCO) case "fn*": return _function('MAL_EVAL', 'native', $ast[2], $env, $ast[1]); @@ -80,6 +82,7 @@ function MAL_EVAL($ast, $env) { if ($f->type === 'native') { $ast = $f->ast; $env = $f->gen_env($args); + // Continue loop (TCO) } else { return $f->apply($args); } diff --git a/php/step7_quote.php b/php/step7_quote.php index fd1c922..07d3d2a 100644 --- a/php/step7_quote.php +++ b/php/step7_quote.php @@ -75,15 +75,18 @@ function MAL_EVAL($ast, $env) { for ($i=0; $i < count($a1); $i+=2) { $let_env->set($a1[$i]->value, MAL_EVAL($a1[$i+1], $let_env)); } - return MAL_EVAL($ast[2], $let_env); + $ast = $ast[2]; + $env = $let_env; + break; // Continue loop (TCO) case "quote": return $ast[1]; case "quasiquote": - return MAL_EVAL(quasiquote($ast[1]), $env); + $ast = quasiquote($ast[1]); + break; // Continue loop (TCO) case "do": eval_ast($ast->slice(1, -1), $env); $ast = $ast[count($ast)-1]; - break; + break; // Continue loop (TCO) case "if": $cond = MAL_EVAL($ast[1], $env); if ($cond === NULL || $cond === false) { @@ -92,7 +95,7 @@ function MAL_EVAL($ast, $env) { } else { $ast = $ast[2]; } - break; + break; // Continue loop (TCO) case "fn*": return _function('MAL_EVAL', 'native', $ast[2], $env, $ast[1]); @@ -103,6 +106,7 @@ function MAL_EVAL($ast, $env) { if ($f->type === 'native') { $ast = $f->ast; $env = $f->gen_env($args); + // Continue loop (TCO) } else { return $f->apply($args); } diff --git a/php/step8_macros.php b/php/step8_macros.php index b33111d..aacf33e 100644 --- a/php/step8_macros.php +++ b/php/step8_macros.php @@ -94,11 +94,14 @@ function MAL_EVAL($ast, $env) { for ($i=0; $i < count($a1); $i+=2) { $let_env->set($a1[$i]->value, MAL_EVAL($a1[$i+1], $let_env)); } - return MAL_EVAL($ast[2], $let_env); + $ast = $ast[2]; + $env = $let_env; + break; // Continue loop (TCO) case "quote": return $ast[1]; case "quasiquote": - return MAL_EVAL(quasiquote($ast[1]), $env); + $ast = quasiquote($ast[1]); + break; // Continue loop (TCO) case "defmacro!": $func = MAL_EVAL($ast[2], $env); $func->ismacro = true; @@ -108,7 +111,7 @@ function MAL_EVAL($ast, $env) { case "do": eval_ast($ast->slice(1, -1), $env); $ast = $ast[count($ast)-1]; - break; + break; // Continue loop (TCO) case "if": $cond = MAL_EVAL($ast[1], $env); if ($cond === NULL || $cond === false) { @@ -117,7 +120,7 @@ function MAL_EVAL($ast, $env) { } else { $ast = $ast[2]; } - break; + break; // Continue loop (TCO) case "fn*": return _function('MAL_EVAL', 'native', $ast[2], $env, $ast[1]); @@ -128,6 +131,7 @@ function MAL_EVAL($ast, $env) { if ($f->type === 'native') { $ast = $f->ast; $env = $f->gen_env($args); + // Continue loop (TCO) } else { return $f->apply($args); } diff --git a/php/step9_interop.php b/php/step9_interop.php index f35244c..d4a59c7 100644 --- a/php/step9_interop.php +++ b/php/step9_interop.php @@ -94,11 +94,14 @@ function MAL_EVAL($ast, $env) { for ($i=0; $i < count($a1); $i+=2) { $let_env->set($a1[$i]->value, MAL_EVAL($a1[$i+1], $let_env)); } - return MAL_EVAL($ast[2], $let_env); + $ast = $ast[2]; + $env = $let_env; + break; // Continue loop (TCO) case "quote": return $ast[1]; case "quasiquote": - return MAL_EVAL(quasiquote($ast[1]), $env); + $ast = quasiquote($ast[1]); + break; // Continue loop (TCO) case "defmacro!": $func = MAL_EVAL($ast[2], $env); $func->ismacro = true; @@ -110,7 +113,7 @@ function MAL_EVAL($ast, $env) { case "do": eval_ast($ast->slice(1, -1), $env); $ast = $ast[count($ast)-1]; - break; + break; // Continue loop (TCO) case "if": $cond = MAL_EVAL($ast[1], $env); if ($cond === NULL || $cond === false) { @@ -119,7 +122,7 @@ function MAL_EVAL($ast, $env) { } else { $ast = $ast[2]; } - break; + break; // Continue loop (TCO) case "fn*": return _function('MAL_EVAL', 'native', $ast[2], $env, $ast[1]); @@ -130,6 +133,7 @@ function MAL_EVAL($ast, $env) { if ($f->type === 'native') { $ast = $f->ast; $env = $f->gen_env($args); + // Continue loop (TCO) } else { return $f->apply($args); } diff --git a/php/stepA_more.php b/php/stepA_more.php index 0f4c8ae..f38656f 100644 --- a/php/stepA_more.php +++ b/php/stepA_more.php @@ -94,11 +94,14 @@ function MAL_EVAL($ast, $env) { for ($i=0; $i < count($a1); $i+=2) { $let_env->set($a1[$i]->value, MAL_EVAL($a1[$i+1], $let_env)); } - return MAL_EVAL($ast[2], $let_env); + $ast = $ast[2]; + $env = $let_env; + break; // Continue loop (TCO) case "quote": return $ast[1]; case "quasiquote": - return MAL_EVAL(quasiquote($ast[1]), $env); + $ast = quasiquote($ast[1]); + break; // Continue loop (TCO) case "defmacro!": $func = MAL_EVAL($ast[2], $env); $func->ismacro = true; @@ -128,7 +131,7 @@ function MAL_EVAL($ast, $env) { case "do": eval_ast($ast->slice(1, -1), $env); $ast = $ast[count($ast)-1]; - break; + break; // Continue loop (TCO) case "if": $cond = MAL_EVAL($ast[1], $env); if ($cond === NULL || $cond === false) { @@ -137,7 +140,7 @@ function MAL_EVAL($ast, $env) { } else { $ast = $ast[2]; } - break; + break; // Continue loop (TCO) case "fn*": return _function('MAL_EVAL', 'native', $ast[2], $env, $ast[1]); @@ -148,6 +151,7 @@ function MAL_EVAL($ast, $env) { if ($f->type === 'native') { $ast = $f->ast; $env = $f->gen_env($args); + // Continue loop (TCO) } else { return $f->apply($args); } |
