From a34b02006527d28db5df5c6553be804770b81f79 Mon Sep 17 00:00:00 2001 From: Joel Martin Date: Wed, 9 Apr 2014 23:58:27 -0500 Subject: Fix metadata on functions. - Don't use metadata to store ast, env, params data. - In Clojure, store metadata on the :meta key of the real metadata. This also allows using any datatype as metadata. --- php/types.php | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'php/types.php') 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; } -- cgit v1.2.3