Type errors
This commit is contained in:
+26
-1
@@ -3,6 +3,7 @@
|
||||
#include "hashtable.h"
|
||||
#include "lisp.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
const char *LISP_TYPE_NAMES[N_LISP_TYPES] = {
|
||||
@@ -27,6 +28,18 @@ void *lisp_alloc_object(size_t size, LispValType type) {
|
||||
return obj;
|
||||
}
|
||||
|
||||
void signal_type_error(LispVal *obj, size_t count,
|
||||
const LispValType types[count]) {
|
||||
// TODO actually throw an error
|
||||
fprintf(stderr, "Type error! Got: %s | Expected: (or ",
|
||||
LISP_TYPE_NAMES[TYPE_OF(obj)]);
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
fprintf(stderr, "%s%s", LISP_TYPE_NAMES[i],
|
||||
i < count - 1 ? " " : ")\n");
|
||||
}
|
||||
abort();
|
||||
}
|
||||
|
||||
DEFINE_SYMBOL(nil, "nil");
|
||||
DEFINE_SYMBOL(t, "t");
|
||||
DEFINE_SYMBOL(unbound, "unbound");
|
||||
@@ -71,7 +84,7 @@ DEFUN(make_symbol, "make-symbol", (LispVal * name), "(name)",
|
||||
}
|
||||
|
||||
DEFUN(intern, "intern", (LispVal * name), "(name)", "") {
|
||||
// TODO type checking
|
||||
CHECK_TYPE(name, TYPE_STRING);
|
||||
LispVal *res = Fgethash(obarray, name, Qunbound);
|
||||
if (res != Qunbound) {
|
||||
return res;
|
||||
@@ -80,3 +93,15 @@ DEFUN(intern, "intern", (LispVal * name), "(name)", "") {
|
||||
Fputhash(obarray, name, newsym);
|
||||
return newsym;
|
||||
}
|
||||
|
||||
DEFUN(symbol_function, "symbol-function", (LispVal * sym, LispVal *resolve),
|
||||
"(sym &optional resolve)", "") {
|
||||
CHECK_TYPE(sym, TYPE_SYMBOL);
|
||||
if (NILP(resolve)) {
|
||||
return ((LispSymbol *) sym)->function;
|
||||
}
|
||||
while (!NILP(sym) && SYMBOLP(sym)) {
|
||||
sym = ((LispSymbol *) sym)->function;
|
||||
}
|
||||
return sym;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user