diff options
Diffstat (limited to 'php')
| -rw-r--r-- | php/step5_tco.php | 8 | ||||
| -rw-r--r-- | php/step6_file.php | 8 | ||||
| -rw-r--r-- | php/step7_quote.php | 8 | ||||
| -rw-r--r-- | php/step8_macros.php | 8 | ||||
| -rw-r--r-- | php/step9_interop.php | 8 | ||||
| -rw-r--r-- | php/stepA_more.php | 8 | ||||
| -rw-r--r-- | php/types.php | 25 |
7 files changed, 36 insertions, 37 deletions
diff --git a/php/step5_tco.php b/php/step5_tco.php index 0bf55ee..cd4787e 100644 --- a/php/step5_tco.php +++ b/php/step5_tco.php @@ -72,16 +72,14 @@ function MAL_EVAL($ast, $env) { break; case "fn*": return _function('MAL_EVAL', 'native', - _hash_map('exp', $ast[2], - 'env', $env, - 'params', $ast[1])); + $ast[2], $env, $ast[1]); default: $el = eval_ast($ast, $env); $f = $el[0]; $args = array_slice($el->getArrayCopy(), 1); if ($f->type === 'native') { - $ast = $f->meta['exp']; - $env = new Env($f->meta['env'], $f->meta['params'], $args); + $ast = $f->ast; + $env = $f->gen_env($args); } else { return $f->apply($args); } diff --git a/php/step6_file.php b/php/step6_file.php index 965ff88..95b3982 100644 --- a/php/step6_file.php +++ b/php/step6_file.php @@ -72,16 +72,14 @@ function MAL_EVAL($ast, $env) { break; case "fn*": return _function('MAL_EVAL', 'native', - _hash_map('exp', $ast[2], - 'env', $env, - 'params', $ast[1])); + $ast[2], $env, $ast[1]); default: $el = eval_ast($ast, $env); $f = $el[0]; $args = array_slice($el->getArrayCopy(), 1); if ($f->type === 'native') { - $ast = $f->meta['exp']; - $env = new Env($f->meta['env'], $f->meta['params'], $args); + $ast = $f->ast; + $env = $f->gen_env($args); } else { return $f->apply($args); } diff --git a/php/step7_quote.php b/php/step7_quote.php index 450f2b5..8c407c6 100644 --- a/php/step7_quote.php +++ b/php/step7_quote.php @@ -95,16 +95,14 @@ function MAL_EVAL($ast, $env) { break; case "fn*": return _function('MAL_EVAL', 'native', - _hash_map('exp', $ast[2], - 'env', $env, - 'params', $ast[1])); + $ast[2], $env, $ast[1]); default: $el = eval_ast($ast, $env); $f = $el[0]; $args = array_slice($el->getArrayCopy(), 1); if ($f->type === 'native') { - $ast = $f->meta['exp']; - $env = new Env($f->meta['env'], $f->meta['params'], $args); + $ast = $f->ast; + $env = $f->gen_env($args); } else { return $f->apply($args); } diff --git a/php/step8_macros.php b/php/step8_macros.php index 3dea855..c6c7173 100644 --- a/php/step8_macros.php +++ b/php/step8_macros.php @@ -120,16 +120,14 @@ function MAL_EVAL($ast, $env) { break; case "fn*": return _function('MAL_EVAL', 'native', - _hash_map('exp', $ast[2], - 'env', $env, - 'params', $ast[1])); + $ast[2], $env, $ast[1]); default: $el = eval_ast($ast, $env); $f = $el[0]; $args = array_slice($el->getArrayCopy(), 1); if ($f->type === 'native') { - $ast = $f->meta['exp']; - $env = new Env($f->meta['env'], $f->meta['params'], $args); + $ast = $f->ast; + $env = $f->gen_env($args); } else { return $f->apply($args); } diff --git a/php/step9_interop.php b/php/step9_interop.php index a699109..3debdc4 100644 --- a/php/step9_interop.php +++ b/php/step9_interop.php @@ -122,16 +122,14 @@ function MAL_EVAL($ast, $env) { break; case "fn*": return _function('MAL_EVAL', 'native', - _hash_map('exp', $ast[2], - 'env', $env, - 'params', $ast[1])); + $ast[2], $env, $ast[1]); default: $el = eval_ast($ast, $env); $f = $el[0]; $args = array_slice($el->getArrayCopy(), 1); if ($f->type === 'native') { - $ast = $f->meta['exp']; - $env = new Env($f->meta['env'], $f->meta['params'], $args); + $ast = $f->ast; + $env = $f->gen_env($args); } else { return $f->apply($args); } diff --git a/php/stepA_more.php b/php/stepA_more.php index 4b8a270..7478ee8 100644 --- a/php/stepA_more.php +++ b/php/stepA_more.php @@ -140,16 +140,14 @@ function MAL_EVAL($ast, $env) { break; case "fn*": return _function('MAL_EVAL', 'native', - _hash_map('exp', $ast[2], - 'env', $env, - 'params', $ast[1])); + $ast[2], $env, $ast[1]); default: $el = eval_ast($ast, $env); $f = $el[0]; $args = array_slice($el->getArrayCopy(), 1); if ($f->type === 'native') { - $ast = $f->meta['exp']; - $env = new Env($f->meta['env'], $f->meta['params'], $args); + $ast = $f->ast; + $env = $f->gen_env($args); } else { return $f->apply($args); } diff --git a/php/types.php b/php/types.php index fa57266..e3df3ac 100644 --- a/php/types.php +++ b/php/types.php @@ -59,31 +59,42 @@ class FunctionClass { public $func = NULL; public $type = 'native'; // 'native' or 'platform' public $meta = NULL; + public $ast = NULL; + public $env = NULL; + public $params = NULL; public $ismacro = False; - public function __construct($func, $type, $meta=NULL, $ismacro=False) { + public function __construct($func, $type, + $ast, $env, $params, $ismacro=False) { $this->func = $func; $this->type = $type; - $this->meta = $meta; + $this->ast = $ast; + #print_r($ast); + $this->env = $env; + $this->params = $params; $this->ismacro = $ismacro; } public function __invoke() { $args = func_get_args(); if ($this->type === 'native') { - $fn_env = new Env($this->meta['env'], - $this->meta['params'], $args); + $fn_env = new Env($this->env, + $this->params, $args); $evalf = $this->func; - return $evalf($this->meta['exp'], $fn_env); + return $evalf($this->ast, $fn_env); } else { return call_user_func_array($this->func, $args); } } + public function gen_env($args) { + return new Env($this->env, $this->params, $args); + } public function apply($args) { return call_user_func_array(array(&$this, '__invoke'),$args); } } -function _function($func, $type='platform', $meta=NULL, $ismacro=False) { - return new FunctionClass($func, $type, $meta, $ismacro); +function _function($func, $type='platform', + $ast=NULL, $env=NULL, $params=NULL, $ismacro=False) { + return new FunctionClass($func, $type, $ast, $env, $params, $ismacro); } function _function_Q($obj) { return $obj instanceof FunctionClass; } |
