mirror of
https://github.com/kanaka/mal.git
synced 2024-09-19 09:38:28 +03:00
cpp, racket: Support catchless try*
This commit is contained in:
parent
dc191336f8
commit
5d99181284
@ -184,8 +184,13 @@ malValuePtr EVAL(malValuePtr ast, malEnvPtr env)
|
||||
}
|
||||
|
||||
if (special == "try*") {
|
||||
checkArgsIs("try*", 2, argCount);
|
||||
malValuePtr tryBody = list->item(1);
|
||||
|
||||
if (argCount == 1) {
|
||||
ast = EVAL(tryBody, env);
|
||||
continue; // TCO
|
||||
}
|
||||
checkArgsIs("try*", 2, argCount);
|
||||
const malList* catchBlock = VALUE_CAST(malList, list->item(2));
|
||||
|
||||
checkArgsIs("catch*", 2, catchBlock->count() - 1);
|
||||
|
@ -185,8 +185,13 @@ malValuePtr EVAL(malValuePtr ast, malEnvPtr env)
|
||||
}
|
||||
|
||||
if (special == "try*") {
|
||||
checkArgsIs("try*", 2, argCount);
|
||||
malValuePtr tryBody = list->item(1);
|
||||
|
||||
if (argCount == 1) {
|
||||
ast = EVAL(tryBody, env);
|
||||
continue; // TCO
|
||||
}
|
||||
checkArgsIs("try*", 2, argCount);
|
||||
const malList* catchBlock = VALUE_CAST(malList, list->item(2));
|
||||
|
||||
checkArgsIs("catch*", 2, catchBlock->count() - 1);
|
||||
@ -336,15 +341,6 @@ static void installMacros(malEnvPtr env)
|
||||
}
|
||||
}
|
||||
|
||||
malValuePtr readline(const String& prompt)
|
||||
{
|
||||
String input;
|
||||
if (s_readLine.get(prompt, input)) {
|
||||
return mal::string(input);
|
||||
}
|
||||
return mal::nilValue();
|
||||
}
|
||||
|
||||
static const char* malFunctionTable[] = {
|
||||
"(def! list (fn* (& items) items))",
|
||||
"(def! not (fn* (cond) (if cond false true)))",
|
||||
@ -365,3 +361,14 @@ static void installFunctions(malEnvPtr env) {
|
||||
rep(function, env);
|
||||
}
|
||||
}
|
||||
|
||||
// Added to keep the linker happy at step A
|
||||
malValuePtr readline(const String& prompt)
|
||||
{
|
||||
String input;
|
||||
if (s_readLine.get(prompt, input)) {
|
||||
return mal::string(input);
|
||||
}
|
||||
return mal::nilValue();
|
||||
}
|
||||
|
||||
|
@ -79,7 +79,9 @@
|
||||
[(eq? 'macroexpand a0)
|
||||
(macroexpand (_nth ast 1) env)]
|
||||
[(eq? 'try* a0)
|
||||
(if (eq? 'catch* (_nth (_nth ast 2) 0))
|
||||
(if (or (< (length ast) 3)
|
||||
(not (eq? 'catch* (_nth (_nth ast 2) 0))))
|
||||
(EVAL (_nth ast 1) env)
|
||||
(let ([efn (lambda (exc)
|
||||
(EVAL (_nth (_nth ast 2) 2)
|
||||
(new Env%
|
||||
@ -90,8 +92,7 @@
|
||||
([mal-exn? (lambda (exc) (efn (mal-exn-val exc)))]
|
||||
[string? (lambda (exc) (efn exc))]
|
||||
[exn:fail? (lambda (exc) (efn (format "~a" exc)))])
|
||||
(EVAL (_nth ast 1) env)))
|
||||
(EVAL (_nth ast 1)))]
|
||||
(EVAL (_nth ast 1) env))))]
|
||||
[(eq? 'do a0)
|
||||
(eval-ast (drop (drop-right ast 1) 1) env)
|
||||
(EVAL (last ast) env)]
|
||||
|
@ -79,7 +79,9 @@
|
||||
[(eq? 'macroexpand a0)
|
||||
(macroexpand (_nth ast 1) env)]
|
||||
[(eq? 'try* a0)
|
||||
(if (eq? 'catch* (_nth (_nth ast 2) 0))
|
||||
(if (or (< (length ast) 3)
|
||||
(not (eq? 'catch* (_nth (_nth ast 2) 0))))
|
||||
(EVAL (_nth ast 1) env)
|
||||
(let ([efn (lambda (exc)
|
||||
(EVAL (_nth (_nth ast 2) 2)
|
||||
(new Env%
|
||||
@ -90,8 +92,7 @@
|
||||
([mal-exn? (lambda (exc) (efn (mal-exn-val exc)))]
|
||||
[string? (lambda (exc) (efn exc))]
|
||||
[exn:fail? (lambda (exc) (efn (format "~a" exc)))])
|
||||
(EVAL (_nth ast 1) env)))
|
||||
(EVAL (_nth ast 1)))]
|
||||
(EVAL (_nth ast 1) env))))]
|
||||
[(eq? 'do a0)
|
||||
(eval-ast (drop (drop-right ast 1) 1) env)
|
||||
(EVAL (last ast) env)]
|
||||
|
Loading…
Reference in New Issue
Block a user