From 90826e6e3b40a9686727f9e9a0b67a570ed3e762 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Mon, 27 Jul 2015 22:02:27 -0400 Subject: [PATCH] Added error checking defs to header file --- include/cyclone/runtime.h | 27 +++++++++++++++++++++++++++ runtime.c | 23 ----------------------- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/include/cyclone/runtime.h b/include/cyclone/runtime.h index 94cdf024..e90ef00b 100644 --- a/include/cyclone/runtime.h +++ b/include/cyclone/runtime.h @@ -9,6 +9,33 @@ #ifndef CYCLONE_RUNTIME_H #define CYCLONE_RUNTIME_H +/* Error checking definitions */ +#define Cyc_check_num_args(fnc_name, num_args, args) { \ + integer_type l = Cyc_length(args); \ + if (num_args > l.value) { \ + char buf[128]; \ + snprintf(buf, 127, "Expected %d arguments but received %d.", num_args, l.value); \ + Cyc_rt_raise_msg(buf); \ + } \ +} + +#define Cyc_check_type(fnc_test, tag, obj) { \ + if (eq(boolean_f, fnc_test(obj))) Cyc_invalid_type_error(tag, obj); } + +#define Cyc_check_cons_or_nil(obj) { if (!nullp(obj)) { Cyc_check_cons(obj); }} +#define Cyc_check_cons(obj) Cyc_check_type(Cyc_is_cons, cons_tag, obj); +#define Cyc_check_num(obj) Cyc_check_type(Cyc_is_number, integer_tag, obj); +#define Cyc_check_int(obj) Cyc_check_type(Cyc_is_integer, integer_tag, obj); +#define Cyc_check_str(obj) Cyc_check_type(Cyc_is_string, string_tag, obj); +#define Cyc_check_sym(obj) Cyc_check_type(Cyc_is_symbol, symbol_tag, obj); +#define Cyc_check_vec(obj) Cyc_check_type(Cyc_is_vector, vector_tag, obj); +#define Cyc_check_port(obj) Cyc_check_type(Cyc_is_port, port_tag, obj); +#define Cyc_check_fnc(obj) Cyc_check_type(Cyc_is_procedure, closure2_tag, obj); +void Cyc_invalid_type_error(int tag, object found); +void Cyc_check_obj(int tag, object obj); +void Cyc_check_bounds(const char *label, int len, int index); +/* END error checking */ + extern long global_stack_size; extern long global_heap_size; extern const object Cyc_EOF; diff --git a/runtime.c b/runtime.c index 15c428ab..959e180a 100644 --- a/runtime.c +++ b/runtime.c @@ -33,29 +33,6 @@ const char *tag_names[20] = { \ , "TODO: add missing type" \ , "TODO: add missing type" }; -/* Type checking section */ -#define Cyc_check_num_args(fnc_name, num_args, args) { \ - integer_type l = Cyc_length(args); \ - if (num_args > l.value) { \ - char buf[128]; \ - snprintf(buf, 127, "Expected %d arguments but received %d.", num_args, l.value); \ - Cyc_rt_raise_msg(buf); \ - } \ -} - -#define Cyc_check_type(fnc_test, tag, obj) { \ - if (eq(boolean_f, fnc_test(obj))) Cyc_invalid_type_error(tag, obj); } - -#define Cyc_check_cons_or_nil(obj) { if (!nullp(obj)) { Cyc_check_cons(obj); }} -#define Cyc_check_cons(obj) Cyc_check_type(Cyc_is_cons, cons_tag, obj); -#define Cyc_check_num(obj) Cyc_check_type(Cyc_is_number, integer_tag, obj); -#define Cyc_check_int(obj) Cyc_check_type(Cyc_is_integer, integer_tag, obj); -#define Cyc_check_str(obj) Cyc_check_type(Cyc_is_string, string_tag, obj); -#define Cyc_check_sym(obj) Cyc_check_type(Cyc_is_symbol, symbol_tag, obj); -#define Cyc_check_vec(obj) Cyc_check_type(Cyc_is_vector, vector_tag, obj); -#define Cyc_check_port(obj) Cyc_check_type(Cyc_is_port, port_tag, obj); -#define Cyc_check_fnc(obj) Cyc_check_type(Cyc_is_procedure, closure2_tag, obj); - void Cyc_invalid_type_error(int tag, object found) { char buf[256]; snprintf(buf, 255, "Invalid type: expected %s, found", tag_names[tag]);