summaryrefslogtreecommitdiff
path: root/pit/src/runtime/eval.c
diff options
context:
space:
mode:
Diffstat (limited to 'pit/src/runtime/eval.c')
-rw-r--r--pit/src/runtime/eval.c42
1 files changed, 21 insertions, 21 deletions
diff --git a/pit/src/runtime/eval.c b/pit/src/runtime/eval.c
index f5eba97..301d8d0 100644
--- a/pit/src/runtime/eval.c
+++ b/pit/src/runtime/eval.c
@@ -3,11 +3,11 @@
pit_value pit_eval(pit_runtime *rt, pit_value top) {
i64 expr_stack_reset = rt->expr_stack->next;
i64 result_stack_reset = rt->result_stack->next;
- i64 program_reset = rt->program->next;
+ i64 traversal_reset = rt->traversal->next;
// pit_vec_reset(pit_annotated_ref)(rt->backtrace);
if (pit_vec_push(pit_value)(rt->expr_stack, top) < 0)
pit_error(rt, "evaluation stack overflow");
- /* first, convert the expression tree into "polish notation" in program */
+ /* first, convert the expression tree into "polish notation" in traversal */
while (rt->expr_stack->next > expr_stack_reset) {
pit_value cur = PIT_NIL;
if (rt->error != PIT_NIL) goto end;
@@ -42,56 +42,56 @@ pit_value pit_eval(pit_runtime *rt, pit_value top) {
if (pit_vec_push(pit_value)(rt->expr_stack, fsym) < 0)
pit_error(rt, "evaluation stack overflow");
}
- pit_runtime_eval_program_push_apply(rt, rt->program, argcount, ann);
+ pit_traversal_push_application(rt, rt->traversal, argcount, ann);
if (is_symbol) {
pit_value f = pit_symtab_fget(rt, fsym);
- pit_runtime_eval_program_push_literal(rt, rt->program, f);
+ pit_traversal_push_value(rt, rt->traversal, f);
}
}
} else if (pit_value_is_symbol(rt, cur)) { /* unquoted symbols: variable lookup */
pit_symtab_entry *ent = pit_symtab_lookup(rt, cur);
if (ent->is_keyword) {
- pit_runtime_eval_program_push_literal(rt, rt->program, cur);
+ pit_traversal_push_value(rt, rt->traversal, cur);
} else {
- pit_runtime_eval_program_push_literal(rt, rt->program, pit_symtab_get(rt, cur));
+ pit_traversal_push_value(rt, rt->traversal, pit_symtab_get(rt, cur));
}
} else { /* other expressions evaluate to themselves! */
- pit_runtime_eval_program_push_literal(rt, rt->program, cur);
+ pit_traversal_push_value(rt, rt->traversal, cur);
}
}
- /* then, execute the polish notation program from right to left
+ /* then, execute the polish notation traversal from right to left
this has the nice consequence of putting the arguments in the right order */
- for (i64 idx = rt->program->next - 1; idx >= program_reset; --idx) {
- pit_runtime_eval_ins *ent = pit_vec_get(pit_runtime_eval_ins)(rt->program, idx);
- if (ent == NULL) pit_error(rt, "evaluation program invalid");
+ for (i64 idx = rt->traversal->next - 1; idx >= traversal_reset; --idx) {
+ pit_traversal_entry *ent = pit_vec_get(pit_traversal_entry)(rt->traversal, idx);
+ if (ent == NULL) pit_error(rt, "evaluation traversal invalid");
if (rt->error != PIT_NIL) goto end;
switch (ent->sort) {
- case PIT_RUNTIME_EVAL_INS_LITERAL:
- if (pit_vec_push(pit_value)(rt->result_stack, ent->in.literal) < 0)
+ case PIT_TRAVERSAL_ENTRY_VALUE:
+ if (pit_vec_push(pit_value)(rt->result_stack, ent->in.value) < 0)
pit_error(rt, "evaluation result stack overflow");
break;
- case PIT_RUNTIME_EVAL_INS_APPLY: {
+ case PIT_TRAVERSAL_ENTRY_APPLICATION: {
pit_value f = PIT_NIL;
pit_value args = PIT_NIL;
if (pit_vec_pop(pit_value)(rt->result_stack, &f) < 0)
pit_error(rt, "evaluation result stack underflow");
- for (i64 i = 0; i < ent->in.apply.arity; ++i) {
+ for (i64 i = 0; i < ent->in.application.arity; ++i) {
pit_value a = PIT_NIL;
if (pit_vec_pop(pit_value)(rt->result_stack, &a) < 0)
pit_error(rt, "evaluation result stack underflow");
args = pit_value_cons(rt, a, args);
}
- if (ent->in.apply.annotation != NULL) {
- rt->source_line = ent->in.apply.annotation->annotation.line;
- rt->source_column = ent->in.apply.annotation->annotation.column;
- pit_vec_push(pit_annotated_ref)(rt->backtrace, *ent->in.apply.annotation);
+ if (ent->in.application.annotation != NULL) {
+ rt->source_line = ent->in.application.annotation->annotation.line;
+ rt->source_column = ent->in.application.annotation->annotation.column;
+ pit_vec_push(pit_annotated_ref)(rt->backtrace, *ent->in.application.annotation);
}
if (pit_vec_push(pit_value)(rt->result_stack, pit_value_apply(rt, f, args)) < 0)
pit_error(rt, "evaluation result stack underflow");
break;
}
default:
- pit_error(rt, "unknown program entry");
+ pit_error(rt, "unknown traversal entry");
goto end;
}
}
@@ -101,7 +101,7 @@ end: {
pit_error(rt, "evaluation result stack underflow");
rt->expr_stack->next = expr_stack_reset;
rt->result_stack->next = result_stack_reset;
- rt->program->next = program_reset;
+ rt->traversal->next = traversal_reset;
return ret;
}
}