aboutsummaryrefslogtreecommitdiff
path: root/php/step3_env.php
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2014-04-02 22:23:37 -0500
committerJoel Martin <github@martintribe.org>2014-04-02 22:23:37 -0500
commitea81a8087bcd7953b083a2be9db447f75e7ebf56 (patch)
tree6cf47a2dbd55d42efc4a901eaabdec952f40ce89 /php/step3_env.php
parent1617910ad342a55762f3ddabb975849d843cff85 (diff)
downloadmal-ea81a8087bcd7953b083a2be9db447f75e7ebf56.tar.gz
mal-ea81a8087bcd7953b083a2be9db447f75e7ebf56.zip
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.
Diffstat (limited to 'php/step3_env.php')
-rw-r--r--php/step3_env.php21
1 files changed, 12 insertions, 9 deletions
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);