core: Use assert_msg.

* src/mes.c: Use assert_msg instead of assert.
* src/gc.c: Likewise.
* src/hash.c: Likewise.
* src/lib.c: Likewise.
* src/math.c: Likewise.
* src/module.c: Likewise.
* src/posix.c: Likewise.
* src/reader.c: Likewise.
* src/string.c: Likewise.
* src/struct.c: Likewise.
* src/vector.c: Likewise.
* simple.make (LIB_SOURCES): Add lib/mes/assert_msg.c.
This commit is contained in:
Jan (janneke) Nieuwenhuizen 2020-05-17 16:07:04 +02:00
parent cf22ba44ce
commit 6a96134eba
No known key found for this signature in database
GPG Key ID: F3C1A0D9C1D65273
13 changed files with 33 additions and 46 deletions

View File

@ -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);

View File

@ -62,6 +62,7 @@ MES_SOURCES = \
LIB_SOURCES = \
lib/mes/eputs.c \
lib/mes/assert_msg.c \
lib/mes/itoa.c
M2_SOURCES = \

View File

@ -21,7 +21,6 @@
#include "mes/lib.h"
#include "mes/mes.h"
#include <assert.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
@ -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;

View File

@ -21,7 +21,6 @@
#include "mes/lib.h"
#include "mes/mes.h"
#include <assert.h>
#include <string.h>
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);

View File

@ -22,7 +22,6 @@
#include "mes/lib.h"
#include "mes/mes.h"
#include <assert.h>
#include <stdlib.h>
int g_depth;
@ -257,7 +256,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);
}
@ -278,7 +277,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);
}
@ -292,7 +291,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));
}

View File

@ -22,7 +22,6 @@
#include "mes/lib.h"
#include "mes/mes.h"
#include <assert.h>
#include <ctype.h>
#include <limits.h>
#include <stdio.h>

View File

@ -21,7 +21,6 @@
#include "mes/lib.h"
#include "mes/mes.h"
#include <assert.h>
#include <fcntl.h>
#include <limits.h>
#include <stdlib.h>
@ -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);

View File

@ -21,8 +21,6 @@
#include "mes/lib.h"
#include "mes/mes.h"
#include <assert.h>
SCM
make_module_type () /*:(internal)) */
{

View File

@ -21,7 +21,6 @@
#include "mes/lib.h"
#include "mes/mes.h"
#include <assert.h>
#include <fcntl.h>
#include <limits.h>
#include <stdio.h>
@ -151,7 +150,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;
}
@ -305,7 +304,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);

View File

@ -22,7 +22,6 @@
#include "mes/lib.h"
#include "mes/mes.h"
#include <assert.h>
#include <ctype.h>
#include <stdio.h>
#include <string.h>

View File

@ -21,8 +21,6 @@
#include "mes/lib.h"
#include "mes/mes.h"
#include <assert.h>
#include <limits.h>
#include <string.h>
@ -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)

View File

@ -21,8 +21,6 @@
#include "mes/lib.h"
#include "mes/mes.h"
#include <assert.h>
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;
}

View File

@ -21,8 +21,6 @@
#include "mes/lib.h"
#include "mes/mes.h"
#include <assert.h>
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;
}