Add function to call function, instead of function list.

This commit is contained in:
Danila Fedorin 2018-05-26 15:03:57 -07:00
parent bbe31be447
commit 88b32ef58d

View File

@ -373,6 +373,30 @@ libab_result _interpreter_perform_call(libab_value* to_call, libab_ref_vec* para
return result;
}
libab_result _interpreter_cast_and_perform_call(libab_ref* to_call,
libab_ref_vec* params,
libab_ref_vec* new_types,
libab_ref* into) {
libab_result result;
libab_ref_vec new_params;
libab_value* function_value;
libab_function* function;
function_value = libab_ref_get(to_call);
function = libab_ref_get(&function_value->data);
result = libab_ref_vec_init_copy(&new_params, &function->params);
if(result == LIBAB_SUCCESS) {
result = _interpreter_cast_params(params, new_types, &new_params);
if(result == LIBAB_SUCCESS) {
result = _interpreter_perform_call(function_value, &new_params, into);
}
libab_ref_vec_free(&new_params);
}
return result;
}
libab_result _interpreter_call_function_list(struct interpreter_state* state,
libab_function_list* list, libab_ref_vec* params, libab_ref* into) {
libab_result result = LIBAB_SUCCESS;
@ -391,24 +415,9 @@ libab_result _interpreter_call_function_list(struct interpreter_state* state,
result = LIBAB_BAD_CALL;
}
if(result == LIBAB_SUCCESS) {
libab_ref_vec new_params;
libab_value* value;
libab_function* function;
value = libab_ref_get(&to_call);
function = libab_ref_get(&value->data);
result = libab_ref_vec_init_copy(&new_params, &function->params);
if(result == LIBAB_SUCCESS) {
result = _interpreter_cast_params(params, &new_types, &new_params);
if(result == LIBAB_SUCCESS) {
libab_ref_free(into);
result = _interpreter_perform_call(libab_ref_get(&to_call), &new_params, into);
}
libab_ref_vec_free(&new_params);
}
result = _interpreter_cast_and_perform_call(&to_call, params, &new_types, into);
libab_ref_vec_free(&new_types);
}
@ -417,6 +426,28 @@ libab_result _interpreter_call_function_list(struct interpreter_state* state,
return result;
}
libab_result _interpreter_call_function(struct interpreter_state* state, libab_ref* function, libab_ref_vec* params, libab_ref* into) {
libab_result result = LIBAB_SUCCESS;
libab_ref_vec temp_new_types;
libab_ref_null(into);
result = libab_ref_vec_init(&temp_new_types);
if(result == LIBAB_SUCCESS) {
result = _interpreter_check_function(state, function, params, &temp_new_types);
if(result == LIBAB_SUCCESS) {
libab_ref_free(into);
result = _interpreter_cast_and_perform_call(function, params, &temp_new_types, into);
} else {
printf("Failed check. %d\n", result);
}
libab_ref_vec_free(&temp_new_types);
}
return result;
}
libab_result _interpreter_run(struct interpreter_state* state, libab_tree* tree,
libab_ref* into, libab_ref* scope,
int force_scope) {