From 92be23571da5921790dafa2d8e9a65d5a6e79ee3 Mon Sep 17 00:00:00 2001 From: rexim Date: Mon, 3 Sep 2018 01:03:53 +0700 Subject: [PATCH] (#311) Implement eval_atom --- src/script/interpreter.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/script/interpreter.c b/src/script/interpreter.c index 990df360..e598ac77 100644 --- a/src/script/interpreter.c +++ b/src/script/interpreter.c @@ -30,10 +30,20 @@ struct EvalResult eval_failure(const char *error, struct Expr expr) static struct EvalResult eval_atom(struct Expr scope, struct Atom *atom) { - /* TODO: eval_atom is not implemented */ - assert(atom); (void) scope; - return eval_failure("not implemented", void_expr()); + + switch (atom->type) { + case ATOM_NUMBER: + case ATOM_STRING: + return eval_success(atom_as_expr(atom)); + + case ATOM_SYMBOL: + /* TODO: Evaluating symbols is not implemented */ + return eval_failure("Evaluating symbols is not implemented", + atom_as_expr(atom)); + } + + return eval_failure("Unexpected expression", atom_as_expr(atom)); } static struct EvalResult eval_args(struct Expr scope, struct Expr args) -- 2.44.0