aboutsummaryrefslogtreecommitdiff
path: root/php/types.php
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2014-04-09 23:58:27 -0500
committerJoel Martin <github@martintribe.org>2014-04-09 23:58:27 -0500
commita34b02006527d28db5df5c6553be804770b81f79 (patch)
tree526fe400e5a8c34b32a3d93439197db09c7f84ad /php/types.php
parentedc3b0640f1b773e185550448e2086279f7b1a7f (diff)
downloadmal-a34b02006527d28db5df5c6553be804770b81f79.tar.gz
mal-a34b02006527d28db5df5c6553be804770b81f79.zip
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.
Diffstat (limited to 'php/types.php')
-rw-r--r--php/types.php25
1 files changed, 18 insertions, 7 deletions
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; }