diff options
Diffstat (limited to 'php')
| -rw-r--r-- | php/readline.php | 2 | ||||
| -rw-r--r-- | php/step0_repl.php | 3 | ||||
| -rw-r--r-- | php/step1_read_print.php | 3 | ||||
| -rw-r--r-- | php/step2_eval.php | 3 | ||||
| -rw-r--r-- | php/step3_env.php | 3 | ||||
| -rw-r--r-- | php/step4_if_fn_do.php | 3 | ||||
| -rw-r--r-- | php/step5_tco.php | 3 | ||||
| -rw-r--r-- | php/step6_file.php | 12 | ||||
| -rw-r--r-- | php/step7_quote.php | 12 | ||||
| -rw-r--r-- | php/step8_macros.php | 12 | ||||
| -rw-r--r-- | php/step9_interop.php | 12 | ||||
| -rw-r--r-- | php/stepA_more.php | 13 |
12 files changed, 54 insertions, 27 deletions
diff --git a/php/readline.php b/php/readline.php index d4b3ad7..5e33501 100644 --- a/php/readline.php +++ b/php/readline.php @@ -31,4 +31,4 @@ function mal_readline($prompt) { return $line; } -?> +?> diff --git a/php/step0_repl.php b/php/step0_repl.php index 64b086b..eecb052 100644 --- a/php/step0_repl.php +++ b/php/step0_repl.php @@ -22,6 +22,7 @@ function rep($str) { return MAL_PRINT(MAL_EVAL(READ($str), array())); } +// repl loop do { $line = mal_readline("user> "); if ($line === NULL) { break; } @@ -30,4 +31,4 @@ do { } } while (true); -?> +?> diff --git a/php/step1_read_print.php b/php/step1_read_print.php index 808ea09..c9c5267 100644 --- a/php/step1_read_print.php +++ b/php/step1_read_print.php @@ -25,6 +25,7 @@ function rep($str) { return MAL_PRINT(MAL_EVAL(READ($str), array())); } +// repl loop do { try { $line = mal_readline("user> "); @@ -40,4 +41,4 @@ do { } } while (true); -?> +?> diff --git a/php/step2_eval.php b/php/step2_eval.php index 1cec7f7..b9d2e8e 100644 --- a/php/step2_eval.php +++ b/php/step2_eval.php @@ -61,6 +61,7 @@ $repl_env['-'] = function ($a, $b) { return intval($a - $b,10); }; $repl_env['*'] = function ($a, $b) { return intval($a * $b,10); }; $repl_env['/'] = function ($a, $b) { return intval($a / $b,10); }; +// repl loop do { try { $line = mal_readline("user> "); @@ -76,4 +77,4 @@ do { } } while (true); -?> +?> diff --git a/php/step3_env.php b/php/step3_env.php index 3c46b04..6585fe7 100644 --- a/php/step3_env.php +++ b/php/step3_env.php @@ -78,6 +78,7 @@ $repl_env->set('-', function ($a, $b) { return intval($a - $b,10); }); $repl_env->set('*', function ($a, $b) { return intval($a * $b,10); }); $repl_env->set('/', function ($a, $b) { return intval($a / $b,10); }); +// repl loop do { try { $line = mal_readline("user> "); @@ -93,4 +94,4 @@ do { } } while (true); -?> +?> diff --git a/php/step4_if_fn_do.php b/php/step4_if_fn_do.php index 83734b1..1e88c6a 100644 --- a/php/step4_if_fn_do.php +++ b/php/step4_if_fn_do.php @@ -99,6 +99,7 @@ foreach ($core_ns as $k=>$v) { // core.mal: defined using the language itself rep("(def! not (fn* (a) (if a false true)))"); +// repl loop do { try { $line = mal_readline("user> "); @@ -114,4 +115,4 @@ do { } } while (true); -?> +?> diff --git a/php/step5_tco.php b/php/step5_tco.php index 31e2980..5ae29a7 100644 --- a/php/step5_tco.php +++ b/php/step5_tco.php @@ -108,6 +108,7 @@ foreach ($core_ns as $k=>$v) { // core.mal: defined using the language itself rep("(def! not (fn* (a) (if a false true)))"); +// repl loop do { try { $line = mal_readline("user> "); @@ -123,4 +124,4 @@ do { } } while (true); -?> +?> diff --git a/php/step6_file.php b/php/step6_file.php index 0a632c0..b7cdcc3 100644 --- a/php/step6_file.php +++ b/php/step6_file.php @@ -107,18 +107,22 @@ foreach ($core_ns as $k=>$v) { $repl_env->set('eval', _function(function($ast) { global $repl_env; return MAL_EVAL($ast, $repl_env); })); +$_argv = _list(); +for ($i=2; $i < count($argv); $i++) { + $_argv->append($argv[$i]); +} +$repl_env->set('*ARGV*', $_argv); // core.mal: defined using the language itself rep("(def! not (fn* (a) (if a false true)))"); rep("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))"); if (count($argv) > 1) { - for ($i=1; $i < count($argv); $i++) { - rep('(load-file "' . $argv[$i] . '")'); - } + rep('(load-file "' . $argv[1] . '")'); exit(0); } +// repl loop do { try { $line = mal_readline("user> "); @@ -134,4 +138,4 @@ do { } } while (true); -?> +?> diff --git a/php/step7_quote.php b/php/step7_quote.php index 8296c1a..fd1c922 100644 --- a/php/step7_quote.php +++ b/php/step7_quote.php @@ -130,18 +130,22 @@ foreach ($core_ns as $k=>$v) { $repl_env->set('eval', _function(function($ast) { global $repl_env; return MAL_EVAL($ast, $repl_env); })); +$_argv = _list(); +for ($i=2; $i < count($argv); $i++) { + $_argv->append($argv[$i]); +} +$repl_env->set('*ARGV*', $_argv); // core.mal: defined using the language itself rep("(def! not (fn* (a) (if a false true)))"); rep("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))"); if (count($argv) > 1) { - for ($i=1; $i < count($argv); $i++) { - rep('(load-file "' . $argv[$i] . '")'); - } + rep('(load-file "' . $argv[1] . '")'); exit(0); } +// repl loop do { try { $line = mal_readline("user> "); @@ -157,4 +161,4 @@ do { } } while (true); -?> +?> diff --git a/php/step8_macros.php b/php/step8_macros.php index 4723ffd..b33111d 100644 --- a/php/step8_macros.php +++ b/php/step8_macros.php @@ -155,6 +155,11 @@ foreach ($core_ns as $k=>$v) { $repl_env->set('eval', _function(function($ast) { global $repl_env; return MAL_EVAL($ast, $repl_env); })); +$_argv = _list(); +for ($i=2; $i < count($argv); $i++) { + $_argv->append($argv[$i]); +} +$repl_env->set('*ARGV*', $_argv); // core.mal: defined using the language itself rep("(def! not (fn* (a) (if a false true)))"); @@ -163,12 +168,11 @@ rep("(defmacro! cond (fn* (& xs) (if (> (count xs) 0) (list 'if (first xs) (if ( rep("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) `(let* (or_FIXME ~(first xs)) (if or_FIXME or_FIXME (or ~@(rest xs))))))))"); if (count($argv) > 1) { - for ($i=1; $i < count($argv); $i++) { - rep('(load-file "' . $argv[$i] . '")'); - } + rep('(load-file "' . $argv[1] . '")'); exit(0); } +// repl loop do { try { $line = mal_readline("user> "); @@ -184,4 +188,4 @@ do { } } while (true); -?> +?> diff --git a/php/step9_interop.php b/php/step9_interop.php index a46864c..f35244c 100644 --- a/php/step9_interop.php +++ b/php/step9_interop.php @@ -157,6 +157,11 @@ foreach ($core_ns as $k=>$v) { $repl_env->set('eval', _function(function($ast) { global $repl_env; return MAL_EVAL($ast, $repl_env); })); +$_argv = _list(); +for ($i=2; $i < count($argv); $i++) { + $_argv->append($argv[$i]); +} +$repl_env->set('*ARGV*', $_argv); // core.mal: defined using the language itself rep("(def! not (fn* (a) (if a false true)))"); @@ -165,12 +170,11 @@ rep("(defmacro! cond (fn* (& xs) (if (> (count xs) 0) (list 'if (first xs) (if ( rep("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) `(let* (or_FIXME ~(first xs)) (if or_FIXME or_FIXME (or ~@(rest xs))))))))"); if (count($argv) > 1) { - for ($i=1; $i < count($argv); $i++) { - rep('(load-file "' . $argv[$i] . '")'); - } + rep('(load-file "' . $argv[1] . '")'); exit(0); } +// repl loop do { try { $line = mal_readline("user> "); @@ -186,4 +190,4 @@ do { } } while (true); -?> +?> diff --git a/php/stepA_more.php b/php/stepA_more.php index 2eae095..0f4c8ae 100644 --- a/php/stepA_more.php +++ b/php/stepA_more.php @@ -175,6 +175,11 @@ foreach ($core_ns as $k=>$v) { $repl_env->set('eval', _function(function($ast) { global $repl_env; return MAL_EVAL($ast, $repl_env); })); +$_argv = _list(); +for ($i=2; $i < count($argv); $i++) { + $_argv->append($argv[$i]); +} +$repl_env->set('*ARGV*', $_argv); // core.mal: defined using the language itself rep("(def! *host-language* \"php\")"); @@ -184,12 +189,12 @@ rep("(defmacro! cond (fn* (& xs) (if (> (count xs) 0) (list 'if (first xs) (if ( rep("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) `(let* (or_FIXME ~(first xs)) (if or_FIXME or_FIXME (or ~@(rest xs))))))))"); if (count($argv) > 1) { - for ($i=1; $i < count($argv); $i++) { - rep('(load-file "' . $argv[$i] . '")'); - } + rep('(load-file "' . $argv[1] . '")'); exit(0); } +// repl loop +rep("(println (str \"Mal [\" *host-language* \"]\"))"); do { try { $line = mal_readline("user> "); @@ -205,4 +210,4 @@ do { } } while (true); -?> +?> |
