diff --git a/include/mes/lib.h b/include/mes/lib.h index 6b66107b..b8c70534 100644 --- a/include/mes/lib.h +++ b/include/mes/lib.h @@ -52,6 +52,7 @@ int oputc (int c); int oputs (char const *s); char *search_path (char const *file_name); ssize_t _read (int fd, void *buffer, size_t size); +void assert_msg (int check, char *msg); extern char *__brk; extern void (*__call_at_exit) (void); diff --git a/simple.make b/simple.make index 193d7836..87f3fd4c 100644 --- a/simple.make +++ b/simple.make @@ -60,6 +60,7 @@ MES_SOURCES = \ LIB_SOURCES = \ lib/mes/eputs.c \ + lib/mes/assert_msg.c \ lib/mes/itoa.c M2_SOURCES = \ diff --git a/src/gc.c b/src/gc.c index 06e7eb46..3c2fe7c4 100644 --- a/src/gc.c +++ b/src/gc.c @@ -21,7 +21,6 @@ #include "mes/lib.h" #include "mes/mes.h" -#include #include #include #include @@ -109,7 +108,7 @@ gc_up_arena () /*:((internal)) */ eputs (":"); eputs (itoa (ARENA_SIZE - g_free)); eputs ("\n"); - assert (0); + assert_msg (0, "0"); exit (1); } g_cells = p; @@ -308,7 +307,7 @@ SCM gc_push_frame () /*:((internal)) */ { if (g_stack < 5) - assert (!"STACK FULL"); + assert_msg (0, "STACK FULL"); g_stack_array[g_stack - 1] = cell_f; g_stack_array[g_stack - 2] = r0; g_stack_array[g_stack - 3] = r1; diff --git a/src/hash.c b/src/hash.c index 56a8bae4..87b8c5d3 100644 --- a/src/hash.c +++ b/src/hash.c @@ -21,7 +21,6 @@ #include "mes/lib.h" #include "mes/mes.h" -#include #include int @@ -30,7 +29,7 @@ hash_cstring (char const *s, long size) int hash = s[0] * 37; if (s[0] != 0 && s[1] != 0) hash = hash + s[1] * 43; - assert (size); + assert_msg (size, "size"); hash = hash % size; return hash; } @@ -48,21 +47,21 @@ hash_ (SCM x, long size) { if (TYPE (x) == TSTRING) return hash_cstring (CSTRING (x), size); - assert (0); + assert_msg (0, "0"); return hashq_ (x, size); } SCM hashq (SCM x, SCM size) { - assert (0); + assert_msg (0, "0"); return MAKE_NUMBER (hashq_ (x, VALUE (size))); } SCM hash (SCM x, SCM size) { - assert (0); + assert_msg (0, "0"); return MAKE_NUMBER (hash_ (x, VALUE (size))); } @@ -237,7 +236,7 @@ make_hash_table (SCM x) long size = 0; if (TYPE (x) == TPAIR) { - assert (TYPE (x) == TNUMBER); + assert_msg (TYPE (x) == TNUMBER, "TYPE (x) == TNUMBER"); size = VALUE (x); } return make_hash_table_ (size); diff --git a/src/lib.c b/src/lib.c index 257a526e..638101fa 100644 --- a/src/lib.c +++ b/src/lib.c @@ -21,7 +21,6 @@ #include "mes/lib.h" #include "mes/mes.h" -#include #include int g_depth; @@ -256,7 +255,7 @@ display_error_ (SCM x) SCM display_port_ (SCM x, SCM p) { - assert (TYPE (p) == TNUMBER); + assert_msg (TYPE (p) == TNUMBER, "TYPE (p) == TNUMBER"); return fdisplay_ (x, VALUE (p), 0); } @@ -277,7 +276,7 @@ write_error_ (SCM x) SCM write_port_ (SCM x, SCM p) { - assert (TYPE (p) == TNUMBER); + assert_msg (TYPE (p) == TNUMBER, "TYPE (p) == TNUMBER"); return fdisplay_ (x, VALUE (p), 1); } @@ -291,7 +290,7 @@ fdisplay_ (SCM x, int fd, int write_p) /*:((internal)) */ SCM exit_ (SCM x) /*:((name . "exit")) */ { - assert (TYPE (x) == TNUMBER); + assert_msg (TYPE (x) == TNUMBER, "TYPE (x) == TNUMBER"); exit (VALUE (x)); } diff --git a/src/math.c b/src/math.c index 8018bdf5..ade8b53e 100644 --- a/src/math.c +++ b/src/math.c @@ -21,7 +21,6 @@ #include "mes/lib.h" #include "mes/mes.h" -#include #include #include #include diff --git a/src/mes.c b/src/mes.c index 90be5a22..3461824f 100644 --- a/src/mes.c +++ b/src/mes.c @@ -21,7 +21,6 @@ #include "mes/lib.h" #include "mes/mes.h" -#include #include #include #include @@ -36,7 +35,7 @@ alloc (long n) SCM x = g_free; g_free = g_free + n; if (g_free > ARENA_SIZE) - assert (!"alloc: out of memory"); + assert_msg (0, "alloc: out of memory"); return x; } @@ -53,7 +52,7 @@ make_cell__ (long type, SCM car, SCM cdr) SCM make_cell_ (SCM type, SCM car, SCM cdr) { - assert (TYPE (type) == TNUMBER); + assert_msg (TYPE (type) == TNUMBER, "TYPE (type) == TNUMBER"); long t = VALUE (type); if (t == TCHAR || t == TNUMBER) { @@ -233,7 +232,7 @@ error (SCM key, SCM x) eputs (": "); write_error_ (x); eputs ("\n"); - assert (0); + assert_msg (0, "0"); exit (1); } @@ -1108,7 +1107,7 @@ begin_expand: else if (TYPE (r1) == TPORT) input = set_current_input_port (r1); else - assert (0); + assert_msg (0, "0"); push_cc (input, r2, r0, cell_vm_return); x = read_input_file_env (r0); diff --git a/src/module.c b/src/module.c index 683e255a..9e13c478 100644 --- a/src/module.c +++ b/src/module.c @@ -21,8 +21,6 @@ #include "mes/lib.h" #include "mes/mes.h" -#include - SCM make_module_type () /*:(internal)) */ { diff --git a/src/posix.c b/src/posix.c index 9ec54ea9..4366ed06 100644 --- a/src/posix.c +++ b/src/posix.c @@ -21,7 +21,6 @@ #include "mes/lib.h" #include "mes/mes.h" -#include #include #include #include @@ -147,7 +146,7 @@ write_byte (SCM x) /*:((arity . n)) */ char cc = VALUE (c); write (fd, &cc, 1); #if !__MESC__ - assert (TYPE (c) == TNUMBER || TYPE (c) == TCHAR); + assert_msg (TYPE (c) == TNUMBER || TYPE (c) == TCHAR, "TYPE (c) == TNUMBER || TYPE (c) == TCHAR"); #endif return c; } @@ -298,7 +297,7 @@ execl_ (SCM file_name, SCM args) /*:((name . "execl")) */ i = i + 1; while (args != cell_nil) { - assert (TYPE (CAR (args)) == TSTRING); + assert_msg (TYPE (CAR (args)) == TSTRING, "TYPE (CAR (args)) == TSTRING"); c_argv[i] = CSTRING (CAR (args)); i = i + 1; args = CDR (args); diff --git a/src/reader.c b/src/reader.c index aa1768be..60112bb4 100644 --- a/src/reader.c +++ b/src/reader.c @@ -22,7 +22,6 @@ #include "mes/lib.h" #include "mes/mes.h" -#include #include #include #include diff --git a/src/string.c b/src/string.c index 4fdc1885..4e886902 100644 --- a/src/string.c +++ b/src/string.c @@ -21,8 +21,6 @@ #include "mes/lib.h" #include "mes/mes.h" -#include - #include #include @@ -115,7 +113,7 @@ string_equal_p (SCM a, SCM b) /*:((name . "string=?")) */ eputs ("b= "); write_error_ (b); eputs ("\n"); - assert ((TYPE (a) == TSTRING && TYPE (b) == TSTRING) || (TYPE (a) == TKEYWORD || TYPE (b) == TKEYWORD)); + assert_msg ((TYPE (a) == TSTRING && TYPE (b) == TSTRING) || (TYPE (a) == TKEYWORD || TYPE (b) == TKEYWORD), "(TYPE (a) == TSTRING && TYPE (b) == TSTRING) || (TYPE (a) == TKEYWORD || TYPE (b) == TKEYWORD)"); } if (a == b || STRING (a) == STRING (b) @@ -231,7 +229,7 @@ string_append (SCM x) /*:((arity . n)) */ while (x != cell_nil) { SCM string = CAR (x); - assert (TYPE (string) == TSTRING); + assert_msg (TYPE (string) == TSTRING, "TYPE (string) == TSTRING"); memcpy (p, CSTRING (string), LENGTH (string) + 1); p = p + LENGTH (string); size = size + LENGTH (string); @@ -245,15 +243,15 @@ string_append (SCM x) /*:((arity . n)) */ SCM string_length (SCM string) { - assert (TYPE (string) == TSTRING); + assert_msg (TYPE (string) == TSTRING, "TYPE (string) == TSTRING"); return MAKE_NUMBER (LENGTH (string)); } SCM string_ref (SCM str, SCM k) { - assert (TYPE (str) == TSTRING); - assert (TYPE (k) == TNUMBER); + assert_msg (TYPE (str) == TSTRING, "TYPE (str) == TSTRING"); + assert_msg (TYPE (k) == TNUMBER, "TYPE (k) == TNUMBER"); size_t size = LENGTH (str); size_t i = VALUE (k); if (i > size) diff --git a/src/struct.c b/src/struct.c index 16f94e75..522328b4 100644 --- a/src/struct.c +++ b/src/struct.c @@ -21,8 +21,6 @@ #include "mes/lib.h" #include "mes/mes.h" -#include - SCM make_struct (SCM type, SCM fields, SCM printer) { @@ -57,15 +55,15 @@ make_struct (SCM type, SCM fields, SCM printer) SCM struct_length (SCM x) { - assert (TYPE (x) == TSTRUCT); + assert_msg (TYPE (x) == TSTRUCT, "TYPE (x) == TSTRUCT"); return MAKE_NUMBER (LENGTH (x)); } SCM struct_ref_ (SCM x, long i) { - assert (TYPE (x) == TSTRUCT); - assert (i < LENGTH (x)); + assert_msg (TYPE (x) == TSTRUCT, "TYPE (x) == TSTRUCT"); + assert_msg (i < LENGTH (x), "i < LENGTH (x)"); SCM e = STRUCT (x) + i; if (TYPE (e) == TREF) e = REF (e); @@ -79,8 +77,8 @@ struct_ref_ (SCM x, long i) SCM struct_set_x_ (SCM x, long i, SCM e) { - assert (TYPE (x) == TSTRUCT); - assert (i < LENGTH (x)); + assert_msg (TYPE (x) == TSTRUCT, "TYPE (x) == TSTRUCT"); + assert_msg (i < LENGTH (x), "i < LENGTH (x)"); g_cells[STRUCT (x) + i] = g_cells[vector_entry (e)]; return cell_unspecified; } diff --git a/src/vector.c b/src/vector.c index d3ee94fc..ab206ab4 100644 --- a/src/vector.c +++ b/src/vector.c @@ -21,8 +21,6 @@ #include "mes/lib.h" #include "mes/mes.h" -#include - SCM make_vector__ (long k) { @@ -43,15 +41,15 @@ make_vector_ (SCM n) SCM vector_length (SCM x) { - assert (TYPE (x) == TVECTOR); + assert_msg (TYPE (x) == TVECTOR, "TYPE (x) == TVECTOR"); return MAKE_NUMBER (LENGTH (x)); } SCM vector_ref_ (SCM x, long i) { - assert (TYPE (x) == TVECTOR); - assert (i < LENGTH (x)); + assert_msg (TYPE (x) == TVECTOR, "TYPE (x) == TVECTOR"); + assert_msg (i < LENGTH (x), "i < LENGTH (x)"); SCM e = VECTOR (x) + i; if (TYPE (e) == TREF) e = REF (e); @@ -79,8 +77,8 @@ vector_entry (SCM x) SCM vector_set_x_ (SCM x, long i, SCM e) { - assert (TYPE (x) == TVECTOR); - assert (i < LENGTH (x)); + assert_msg (TYPE (x) == TVECTOR, "TYPE (x) == TVECTOR"); + assert_msg (i < LENGTH (x), "i < LENGTH (x)"); g_cells[VECTOR (x) + i] = g_cells[vector_entry (e)]; return cell_unspecified; }