changeset 101:1e5a8a96753d

eval: Return builtin result expression and clarify invariants
author Lewin Bormann <lbo@spheniscida.de>
date Wed, 28 Aug 2019 10:28:34 +0200
parents 58553c702903
children da80a755723f
files src/eval.c src/eval.h
diffstat 2 files changed, 7 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/eval.c	Wed Aug 28 10:28:04 2019 +0200
+++ b/src/eval.c	Wed Aug 28 10:28:34 2019 +0200
@@ -58,7 +58,7 @@
                 assert(expr->value.list.size == state->call_stack.size);
                 // Builtins expect their call list on the stack.
                 YVEC_PUSH(&state->call_stack, expr);
-                ybuiltin_run(first->value.builtin, state);
+                return ybuiltin_run(first->value.builtin, state);
             }
             // Is function call?
             if (first->typ == YEXPR_REF) {
--- a/src/eval.h	Wed Aug 28 10:28:04 2019 +0200
+++ b/src/eval.h	Wed Aug 28 10:28:34 2019 +0200
@@ -1,8 +1,8 @@
 #ifndef src_eval_h
 #define src_eval_h
 
+#include <src/base/vec.h>
 #include <src/types.h>
-#include <src/base/vec.h>
 
 /**
  * @file eval.h
@@ -24,9 +24,9 @@
 } yeval_state_t;
 
 /**
- * @brief Evaluate a list of expressions starting at off, but only return the last one. Used to
- * run functions or other constructs that evaluate expressions for their
- * side-effects.
+ * @brief Evaluate a list of expressions starting at off, but only return the
+ * last one. Used to run functions or other constructs that evaluate expressions
+ * for their side-effects.
  */
 yexpr_t yeval_list_return_last(yeval_state_t* state, yvec_t* list, size_t off);
 
@@ -35,7 +35,8 @@
  * expression.
  *
  * The caller takes ownership of the returned expression. `yeval` does not take
- * ownership of the supplied expression.
+ * ownership of the supplied expression and does not modify or destroy any
+ * children of it (this is important for recursive evaluation).
  *
  * `yeval` calls itself recursively during program execution.
  *