diff --git a/include/util.h b/include/util.h index 480373f..936c1cb 100644 --- a/include/util.h +++ b/include/util.h @@ -127,5 +127,23 @@ libab_result libab_create_function_list(libab_ref* into, libab_ref* type); */ libab_result libab_put_table_value(libab_table* table, const char* key, libab_ref* value); +/** + * Returns the data stored in the given reference to a libab_value. + * This is not the same as libab_ref_get: libab_ref_get will return directly + * the data pointed to by the ference. libab_unwrap_value assumes the reference + * it's given is that to a libab_value, extracts it, then extracts its data + * field. + * @param ref the reference to unwrap. + * @return the resulting data. + */ +void* libab_unwrap_value(libab_ref* ref); +/** + * Similar to unwrap_value; Assumes the vector is a vector of + * values, and unwraps the value at the given index. + * @param vec the vector to unwrap a value from. + * @param index the index to look up. + * @return the value at the given index. + */ +void* libab_unwrap_param(libab_ref_vec* vec, size_t index); #endif diff --git a/src/interpreter.c b/src/interpreter.c index 8369aee..70905b5 100644 --- a/src/interpreter.c +++ b/src/interpreter.c @@ -438,8 +438,6 @@ libab_result _interpreter_call_function(struct interpreter_state* state, libab_r 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); diff --git a/src/util.c b/src/util.c index 9a665d0..3ae56a9 100644 --- a/src/util.c +++ b/src/util.c @@ -309,3 +309,17 @@ libab_result libab_put_table_value(libab_table* table, const char* key, return result; } + +void* libab_unwrap_value(libab_ref* ref) { + libab_value* value = libab_ref_get(ref); + return libab_ref_get(&value->data); +} + +void* libab_unwrap_param(libab_ref_vec* vec, size_t index) { + libab_ref temp; + void* data; + libab_ref_vec_index(vec, index, &temp); + data = libab_unwrap_value(&temp); + libab_ref_free(&temp); + return data; +}