From 13ccea10e43eb8b68dd49f6f97d407a7f9a69526 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Thu, 21 Jun 2018 14:25:11 -0700 Subject: [PATCH] Add scope to internal functions. --- include/custom.h | 2 +- src/interactive.c | 10 +++++----- src/interpreter.c | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/custom.h b/include/custom.h index ee078eb..60ef731 100644 --- a/include/custom.h +++ b/include/custom.h @@ -11,7 +11,7 @@ struct libab_s; * A function pointer that is called * to execute a certain type of function. */ -typedef libab_result (*libab_function_ptr)(struct libab_s*, libab_ref_vec*, libab_ref*); +typedef libab_result (*libab_function_ptr)(struct libab_s*, libab_ref*, libab_ref_vec*, libab_ref*); /** * The variant of the operator that diff --git a/src/interactive.c b/src/interactive.c index 1f57453..332aec5 100644 --- a/src/interactive.c +++ b/src/interactive.c @@ -38,34 +38,34 @@ libab_result create_double_value(libab* ab, double val, libab_ref* into) { return result; } -libab_result function_atan(libab* ab, libab_ref_vec* params, libab_ref* into) { +libab_result function_atan(libab* ab, libab_ref* scope, libab_ref_vec* params, libab_ref* into) { printf("atan called\n"); double* val = libab_unwrap_param(params, 0); return create_double_value(ab, atan(*val), into); } -libab_result function_atan2(libab* ab, libab_ref_vec* params, libab_ref* into) { +libab_result function_atan2(libab* ab, libab_ref* scope, libab_ref_vec* params, libab_ref* into) { printf("atan2 called\n"); double* left = libab_unwrap_param(params, 0); double* right = libab_unwrap_param(params, 1); return create_double_value(ab, atan2(*left, *right), into); } -libab_result function_print_num(libab* ab, libab_ref_vec* params, libab_ref* into) { +libab_result function_print_num(libab* ab, libab_ref* scope, libab_ref_vec* params, libab_ref* into) { double* param = libab_unwrap_param(params, 0); printf("%f\n", *param); libab_get_unit_value(ab, into); return LIBAB_SUCCESS; } -libab_result function_print_unit(libab* ab, libab_ref_vec* params, libab_ref* into) { +libab_result function_print_unit(libab* ab, libab_ref* scope, libab_ref_vec* params, libab_ref* into) { printf("()\n"); libab_get_unit_value(ab, into); return LIBAB_SUCCESS; } #define OP_FUNCTION(name, expression) \ - libab_result name(libab* ab, libab_ref_vec* params, libab_ref* into) { \ + libab_result name(libab* ab, libab_ref* scope, libab_ref_vec* params, libab_ref* into) { \ libab_result result = LIBAB_SUCCESS; \ double right; \ double left; \ diff --git a/src/interpreter.c b/src/interpreter.c index 0be737e..30de29b 100644 --- a/src/interpreter.c +++ b/src/interpreter.c @@ -530,7 +530,7 @@ libab_result _interpreter_call_behavior(struct interpreter_state* state, libab_ref* into) { libab_result result = LIBAB_SUCCESS; if (behavior->variant == BIMPL_INTERNAL) { - result = behavior->data_u.internal(state->ab, params, into); + result = behavior->data_u.internal(state->ab, scope, params, into); } else { result = _interpreter_call_tree(state, behavior->data_u.tree, params, scope, into); }