Add libabacus parameter to function calls.

This commit is contained in:
Danila Fedorin 2018-05-27 00:02:20 -07:00
parent f4de244c41
commit 1f7294ce29
3 changed files with 26 additions and 22 deletions

View File

@ -5,11 +5,13 @@
#include "ref_trie.h"
#include "tree.h"
struct libab_s;
/**
* A function pointer that is called
* to execute a certain type of function.
*/
typedef libab_result (*libab_function_ptr)(libab_ref_vec*, libab_ref*);
typedef libab_result (*libab_function_ptr)(struct libab_s*, libab_ref_vec*, libab_ref*);
/**
* The variant of the operator that

View File

@ -18,19 +18,19 @@ void* impl_parse(const char* string) {
void impl_free(void* data) { free(data); }
libab_result function_atan(libab_ref_vec* params, libab_ref* into) {
libab_result function_atan(libab* ab, libab_ref_vec* params, libab_ref* into) {
printf("atan called\n");
libab_ref_null(into);
return LIBAB_SUCCESS;
}
libab_result function_atan2(libab_ref_vec* params, libab_ref* into) {
libab_result function_atan2(libab* ab, libab_ref_vec* params, libab_ref* into) {
printf("atan2 called\n");
libab_ref_null(into);
return LIBAB_SUCCESS;
}
libab_result function_operator(libab_ref_vec* params, libab_ref* into) {
libab_result function_operator(libab* ab, libab_ref_vec* params, libab_ref* into) {
libab_result result = LIBAB_SUCCESS;
libab_ref left_ref;
libab_value* left_value;

View File

@ -205,8 +205,7 @@ libab_result _interpreter_resolve_type_params(libab_ref* type,
return result;
}
libab_result _interpreter_check_types(struct interpreter_state* state,
libab_ref_vec* reference_types,
libab_result _interpreter_check_types(libab_ref_vec* reference_types,
libab_ref_vec* params,
libab_ref_vec* types) {
libab_result result = LIBAB_SUCCESS;
@ -260,8 +259,7 @@ libab_result _interpreter_check_types(struct interpreter_state* state,
return result;
}
libab_result _interpreter_find_match(struct interpreter_state* state,
libab_function_list* function_values,
libab_result _interpreter_find_match(libab_function_list* function_values,
libab_ref_vec* params,
libab_ref_vec* new_types, libab_ref* match,
int partial) {
@ -287,7 +285,7 @@ libab_result _interpreter_find_match(struct interpreter_state* state,
partial)) {
/* We found a function that has the correct number of parameters. */
result = _interpreter_check_types(
state, &temp_function_type->children, params, &temp_new_types);
&temp_function_type->children, params, &temp_new_types);
if (result == LIBAB_MISMATCHED_TYPE) {
/* Mismatch is OK. */
result = LIBAB_SUCCESS;
@ -377,19 +375,21 @@ libab_result _interpreter_call_tree(libab_tree* tree, libab_ref_vec* params,
return result;
}
libab_result _interpreter_call_behavior(libab_behavior* behavior,
libab_result _interpreter_call_behavior(struct interpreter_state* state,
libab_behavior* behavior,
libab_ref_vec* params,
libab_ref* into) {
libab_result result = LIBAB_SUCCESS;
if (behavior->variant == BIMPL_INTERNAL) {
result = behavior->data_u.internal(params, into);
result = behavior->data_u.internal(state->ab, params, into);
} else {
result = _interpreter_call_tree(behavior->data_u.tree, params, into);
}
return result;
}
libab_result _interpreter_perform_function_call(libab_value* to_call,
libab_result _interpreter_perform_function_call(struct interpreter_state* state,
libab_value* to_call,
libab_ref_vec* params,
libab_ref* into) {
libab_result result = LIBAB_SUCCESS;
@ -400,12 +400,13 @@ libab_result _interpreter_perform_function_call(libab_value* to_call,
function_type = libab_ref_get(&to_call->type);
new_params = params->size - function->params.size;
if (function_type->children.size - new_params == 1) {
_interpreter_call_behavior(&function->behavior, params, into);
_interpreter_call_behavior(state, &function->behavior, params, into);
}
return result;
}
libab_result _interpreter_cast_and_perform_function_call(
struct interpreter_state* state,
libab_ref* to_call, libab_ref_vec* params, libab_ref_vec* new_types,
libab_ref* into) {
libab_result result;
@ -420,7 +421,7 @@ libab_result _interpreter_cast_and_perform_function_call(
result = _interpreter_cast_params(params, new_types, &new_params);
if (result == LIBAB_SUCCESS) {
result = _interpreter_perform_function_call(function_value,
result = _interpreter_perform_function_call(state, function_value,
&new_params, into);
}
@ -439,10 +440,10 @@ libab_result _interpreter_call_function_list(struct interpreter_state* state,
libab_ref_null(into);
result =
_interpreter_find_match(state, list, params, &new_types, &to_call, 0);
_interpreter_find_match(list, params, &new_types, &to_call, 0);
if (result == LIBAB_SUCCESS) {
if (libab_ref_get(&to_call) == NULL) {
result = _interpreter_find_match(state, list, params, &new_types,
result = _interpreter_find_match(list, params, &new_types,
&to_call, 1);
}
}
@ -453,7 +454,7 @@ libab_result _interpreter_call_function_list(struct interpreter_state* state,
if (result == LIBAB_SUCCESS) {
libab_ref_free(into);
result = _interpreter_cast_and_perform_function_call(&to_call, params,
result = _interpreter_cast_and_perform_function_call(state, &to_call, params,
&new_types, into);
libab_ref_vec_free(&new_types);
}
@ -478,13 +479,13 @@ libab_result _interpreter_call_function(struct interpreter_state* state,
result = libab_ref_vec_init(&temp_new_types);
if (result == LIBAB_SUCCESS) {
result = _interpreter_check_types(state, &function_type->children,
result = _interpreter_check_types(&function_type->children,
params, &temp_new_types);
if (result == LIBAB_SUCCESS) {
libab_ref_free(into);
result = _interpreter_cast_and_perform_function_call(
function, params, &temp_new_types, into);
state, function, params, &temp_new_types, into);
}
libab_ref_vec_free(&temp_new_types);
@ -518,6 +519,7 @@ libab_result _interpreter_try_call(struct interpreter_state* state,
}
libab_result _interpreter_cast_and_perform_operator_call(
struct interpreter_state* state,
libab_operator* to_call, libab_ref_vec* params, libab_ref_vec* new_types,
libab_ref* into) {
libab_result result = LIBAB_SUCCESS;
@ -531,7 +533,7 @@ libab_result _interpreter_cast_and_perform_operator_call(
if (result == LIBAB_SUCCESS) {
libab_ref_free(into);
result =
_interpreter_call_behavior(&to_call->behavior, params, into);
_interpreter_call_behavior(state, &to_call->behavior, params, into);
}
libab_ref_vec_free(&new_params);
@ -588,13 +590,13 @@ libab_result _interpreter_call_operator(struct interpreter_state* state,
}
if (result == LIBAB_SUCCESS) {
result = _interpreter_check_types(state, &operator_type->children,
result = _interpreter_check_types(&operator_type->children,
&params, &new_types);
}
if (result == LIBAB_SUCCESS) {
result = _interpreter_cast_and_perform_operator_call(
to_call, &params, &new_types, into);
state, to_call, &params, &new_types, into);
}
libab_ref_vec_free(&params);