core: Use exceptions instead of asserts. WIP
* src/lib.c (assert_num, assert_struct): New function. * src/struct.c (struct_ref_): Use them.
This commit is contained in:
parent
5e17a0bcbe
commit
022666a8ff
43
src/lib.c
43
src/lib.c
|
@ -173,3 +173,46 @@ integer_to_char (struct scm *x)
|
|||
{
|
||||
return make_char (x->value);
|
||||
}
|
||||
|
||||
/*
|
||||
void
|
||||
assert_type (long type, char const *name_name, struct scm *x)
|
||||
{
|
||||
if (x->type != type)
|
||||
{
|
||||
eputs (name);
|
||||
eputs (": ");
|
||||
error (cell_wrong_type_arg, cons (x, cell_nil));
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
void
|
||||
assert_num (long pos, struct scm *x)
|
||||
{
|
||||
if (x->type != TNUMBER)
|
||||
error (cell_symbol_wrong_type_arg, cons (cell_type_number, cons (make_number (pos), x)));
|
||||
}
|
||||
|
||||
void
|
||||
assert_struct (long pos, struct scm *x)
|
||||
{
|
||||
if (x->type != TSTRUCT)
|
||||
error (cell_symbol_wrong_type_arg, cons (cell_type_struct, cons (make_number (pos), x)));
|
||||
}
|
||||
|
||||
void
|
||||
assert_range (int assert, long i)
|
||||
{
|
||||
if (assert == 0)
|
||||
{
|
||||
eputs ("value out of range: ");
|
||||
eputs (ltoa (i));
|
||||
eputs (": ");
|
||||
assert_msg (assert, "value out of range");
|
||||
}
|
||||
/*
|
||||
if (assert != 0)
|
||||
error (cell_symbol_out_of_range, cons (cell_type_struct, cons (make_number (pos), cons (x, cell_nil))));
|
||||
*/
|
||||
}
|
||||
|
|
|
@ -54,11 +54,15 @@ struct_length (struct scm *x)
|
|||
return make_number (x->length);
|
||||
}
|
||||
|
||||
void assert_num (long pos, struct scm *x);
|
||||
void assert_struct (long pos, struct scm *x);
|
||||
void assert_range (int assert, long x);
|
||||
|
||||
struct scm *
|
||||
struct_ref_ (struct scm *x, long i)
|
||||
{
|
||||
assert_msg (x->type == TSTRUCT, "x->type == TSTRUCT");
|
||||
assert_msg (i < x->length, "i < x->length");
|
||||
assert_struct (1, x);
|
||||
assert_range (i < x->length, i);
|
||||
struct scm *e = cell_ref (x->structure, i);
|
||||
if (e->type == TREF)
|
||||
e = e->ref;
|
||||
|
|
Loading…
Reference in New Issue