]> git.lizzy.rs Git - nothing.git/commitdiff
(#311) Implement eval_atom
authorrexim <reximkut@gmail.com>
Sun, 2 Sep 2018 18:03:53 +0000 (01:03 +0700)
committerrexim <reximkut@gmail.com>
Sun, 2 Sep 2018 18:03:53 +0000 (01:03 +0700)
src/script/interpreter.c

index 990df360ce6188d1aa5ced1fb3bd36db477bd2af..e598ac77852f61e201be268961ca004b5aba11e5 100644 (file)
@@ -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)