From ea81a8087bcd7953b083a2be9db447f75e7ebf56 Mon Sep 17 00:00:00 2001 From: Joel Martin Date: Wed, 2 Apr 2014 22:23:37 -0500 Subject: All: split types into types, env, printer, core. - types: low-level mapping to the implementation language. - core: functions on types that are exposed directly to mal. - printer: implementation called by pr-str, str, prn, println. - env: the environment implementation - Also, unindent all TCO while loops so that the diff of step4 and step5 are minimized. --- php/step3_env.php | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'php/step3_env.php') diff --git a/php/step3_env.php b/php/step3_env.php index 15d7c5c..83ced32 100644 --- a/php/step3_env.php +++ b/php/step3_env.php @@ -3,6 +3,8 @@ require_once 'readline.php'; require_once 'types.php'; require_once 'reader.php'; +require_once 'printer.php'; +require_once 'env.php'; // read function READ($str) { @@ -11,18 +13,18 @@ function READ($str) { // eval function eval_ast($ast, $env) { - if (symbol_Q($ast)) { + if (_symbol_Q($ast)) { return $env->get($ast->value); - } elseif (list_Q($ast) || vector_Q($ast)) { - if (list_Q($ast)) { - $el = new_list(); + } elseif (_sequential_Q($ast)) { + if (_list_Q($ast)) { + $el = _list(); } else { - $el = new_vector(); + $el = _vector(); } foreach ($ast as $a) { $el[] = MAL_EVAL($a, $env); } return $el; - } elseif (hash_map_Q($ast)) { - $new_hm = new_hash_map(); + } elseif (_hash_map_Q($ast)) { + $new_hm = _hash_map(); foreach (array_keys($ast->getArrayCopy()) as $key) { $new_hm[$key] = MAL_EVAL($ast[$key], $env); } @@ -33,13 +35,14 @@ function eval_ast($ast, $env) { } function MAL_EVAL($ast, $env) { - if (!list_Q($ast)) { + #echo "MAL_EVAL: " . _pr_str($ast) . "\n"; + if (!_list_Q($ast)) { return eval_ast($ast, $env); } // apply list $a0 = $ast[0]; - $a0v = (symbol_Q($a0) ? $a0->value : $a0); + $a0v = (_symbol_Q($a0) ? $a0->value : $a0); switch ($a0v) { case "def!": $res = MAL_EVAL($ast[2], $env); -- cgit v1.2.3