Add scope to internal functions.

This commit is contained in:
Danila Fedorin 2018-06-21 14:25:11 -07:00
parent 82747eae6a
commit 13ccea10e4
3 changed files with 7 additions and 7 deletions

View File

@ -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

View File

@ -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; \

View File

@ -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);
}