.is_error = false,
.expr = expr,
.scope = scope,
- .error = NULL
};
return result;
}
-struct EvalResult eval_failure(const char *error, struct Expr expr, struct Expr scope)
+struct EvalResult eval_failure(struct Expr error, struct Expr scope)
{
struct EvalResult result = {
.is_error = true,
- .error = error,
- .scope = scope,
- .expr = expr
+ .expr = error,
+ .scope = scope
};
return result;
return eval_success(atom_as_expr(atom), scope);
}
- return eval_failure("Unexpected expression", atom_as_expr(atom), scope);
+ return eval_failure(CONS(gc,
+ SYMBOL(gc, "unexpected-expression"),
+ atom_as_expr(atom)),
+ scope);
}
static struct EvalResult eval_args(Gc *gc, struct Expr scope, struct Expr args)
default: {}
}
- return eval_failure("Unexpected expression", args, scope);
+ return eval_failure(CONS(gc,
+ SYMBOL(gc, "unexpected-expression"),
+ args),
+ scope);
}
static struct EvalResult plus_op(Gc *gc, struct Expr args, struct Expr scope)
while (!nil_p(args)) {
if (args.type != EXPR_CONS) {
- return eval_failure("Expected cons", args, scope);
+ return eval_failure(CONS(gc,
+ SYMBOL(gc, "expected-cons"),
+ args),
+ scope);
}
if (args.cons->car.type != EXPR_ATOM ||
args.cons->car.atom->type != ATOM_NUMBER) {
- return eval_failure("Expected number", args.cons->car, scope);
+ return eval_failure(CONS(gc,
+ SYMBOL(gc, "expected-number"),
+ args.cons->car),
+ scope);
}
result += args.cons->car.atom->num;
(void) scope;
if (!symbol_p(cons->car)) {
- return eval_failure("Expected symbol", cons->car, scope);
+ return eval_failure(CONS(gc,
+ SYMBOL(gc, "expected-symbol"),
+ cons->car),
+ scope);
}
/* TODO(#323): set builtin function is not implemented */
return plus_op(gc, args.expr, scope);
}
- return eval_failure("Unknown function", cons->car, scope);
+ return eval_failure(CONS(gc,
+ SYMBOL(gc, "unknown-function"),
+ cons->car),
+ scope);
}
struct EvalResult eval(Gc *gc, struct Expr scope, struct Expr expr)
default: {}
}
- return eval_failure("Unexpected expression", expr, scope);
-}
-
-void print_eval_error(FILE *stream, struct EvalResult result)
-{
- if (!result.is_error) {
- return;
- }
-
- fprintf(stream, "%s\n", result.error);
- print_expr_as_sexpr(result.expr);
+ return eval_failure(CONS(gc,
+ SYMBOL(gc, "unexpected-expression"),
+ expr),
+ scope);
}