Type errors
This commit is contained in:
+26
@@ -1,10 +1,12 @@
|
||||
#ifndef INCLUDED_TYPES_H
|
||||
#define INCLUDED_TYPES_H
|
||||
|
||||
#include "argcountmacro.h"
|
||||
#include "gc.h"
|
||||
#include "memory.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdnoreturn.h>
|
||||
|
||||
// ###################
|
||||
// # Base value type #
|
||||
@@ -119,6 +121,29 @@ static ALWAYS_INLINE bool LISP_TYPEP(LispVal *val, LispValType type) {
|
||||
}
|
||||
}
|
||||
|
||||
noreturn void signal_type_error(LispVal *obj, size_t count,
|
||||
const LispValType types[count]);
|
||||
static ALWAYS_INLINE void internal_CHECK_TYPE(LispVal *obj, size_t count,
|
||||
LispValType v1, LispValType v2,
|
||||
LispValType v3, LispValType v4,
|
||||
LispValType v5, LispValType v6) {
|
||||
const LispValType types[] = {v1, v2, v3, v4, v5, v6};
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
if (LISP_TYPEP(obj, types[i])) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Failed
|
||||
signal_type_error(obj, count, types);
|
||||
}
|
||||
#define internal_CHECK_TYPE1(obj, type) internal_CHECK_TYPE(obj, v1, )
|
||||
#define internal_CHECK_TYPE_SUB(obj, count, a1, a2, a3, a4, a5, a6, ...) \
|
||||
internal_CHECK_TYPE((obj), count, a1, a2, a3, a4, a5, a6)
|
||||
#define CHECK_TYPE(obj, ...) \
|
||||
internal_CHECK_TYPE_SUB((obj), COUNT_ARGS(__VA_ARGS__), __VA_ARGS__, \
|
||||
TYPE_FIXNUM, TYPE_FIXNUM, TYPE_FIXNUM, \
|
||||
TYPE_FIXNUM, TYPE_FIXNUM, TYPE_FIXNUM)
|
||||
|
||||
#define DEFOBJTYPE(Name, NAME, NAME_P, body) \
|
||||
typedef struct { \
|
||||
LispObject header; \
|
||||
@@ -186,6 +211,7 @@ DECLARE_FUNCTION(eq, (LispVal * obj1, LispVal *obj2));
|
||||
LispVal *make_vector(LispVal **data, size_t length, bool take);
|
||||
DECLARE_FUNCTION(make_symbol, (LispVal * name));
|
||||
DECLARE_FUNCTION(intern, (LispVal * name));
|
||||
DECLARE_FUNCTION(symbol_function, (LispVal * sym, LispVal *resolve));
|
||||
|
||||
// TODO these are actually special-forms
|
||||
DECLARE_SYMBOL(quote);
|
||||
|
||||
Reference in New Issue
Block a user