More exception stuff
This commit is contained in:
+11
-5
@@ -1,5 +1,6 @@
|
||||
#include "hashtable.h"
|
||||
|
||||
#include "lisp.h"
|
||||
#include "lisp_string.h"
|
||||
|
||||
#define INITIAL_SIZE 32
|
||||
@@ -49,9 +50,11 @@ static uintptr_t hash_key_for_table(LispHashTable *ht, LispVal *key) {
|
||||
return (uintptr_t) key;
|
||||
} else if (ht->hash_fn == Qhash_string) { // needed for initialization
|
||||
return XFIXNUM(Fhash_string(key));
|
||||
} else {
|
||||
LispVal *hash = CALL(ht->hash_fn, key);
|
||||
CHECK_TYPE(hash, TYPE_FIXNUM);
|
||||
return XFIXNUM(hash);
|
||||
}
|
||||
// TODO change
|
||||
abort();
|
||||
}
|
||||
|
||||
static bool compare_keys(LispHashTable *ht, LispVal *key1, LispVal *key2) {
|
||||
@@ -59,9 +62,9 @@ static bool compare_keys(LispHashTable *ht, LispVal *key1, LispVal *key2) {
|
||||
return EQ(key1, key2);
|
||||
} else if (ht->eq_fn == Qstrings_equal) { // needed for initialization
|
||||
return !NILP(Fstrings_equal(key1, key2));
|
||||
} else {
|
||||
return !NILP(CALL(ht->eq_fn, key1, key2));
|
||||
}
|
||||
// TODO change
|
||||
abort();
|
||||
}
|
||||
|
||||
static struct HashTableBucket *
|
||||
@@ -101,9 +104,9 @@ static void maybe_rehash(LispHashTable *ht) {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO type checking
|
||||
DEFUN(gethash, "gethash", (LispVal * ht, LispVal *key, LispVal *def),
|
||||
"(ht key &optional def)", "") {
|
||||
CHECK_TYPE(ht, TYPE_HASH_TABLE);
|
||||
LispHashTable *obj = ht;
|
||||
if (obj->cache_bucket && key == obj->cache_bucket->key) {
|
||||
return obj->cache_bucket->value;
|
||||
@@ -116,6 +119,7 @@ DEFUN(gethash, "gethash", (LispVal * ht, LispVal *key, LispVal *def),
|
||||
|
||||
DEFUN(puthash, "puthash", (LispVal * ht, LispVal *key, LispVal *val),
|
||||
"(ht key val)", "") {
|
||||
CHECK_TYPE(ht, TYPE_HASH_TABLE);
|
||||
LispHashTable *obj = ht;
|
||||
if (obj->cache_bucket && key == obj->cache_bucket->key) {
|
||||
obj->cache_bucket->value = val;
|
||||
@@ -138,6 +142,7 @@ DEFUN(puthash, "puthash", (LispVal * ht, LispVal *key, LispVal *val),
|
||||
}
|
||||
|
||||
DEFUN(remhash, "remhash", (LispVal * ht, LispVal *key), "(ht key)", "") {
|
||||
CHECK_TYPE(ht, TYPE_HASH_TABLE);
|
||||
LispHashTable *obj = ht;
|
||||
uintptr_t hash = hash_key_for_table(ht, key);
|
||||
struct HashTableBucket *b;
|
||||
@@ -170,5 +175,6 @@ DEFUN(remhash, "remhash", (LispVal * ht, LispVal *key), "(ht key)", "") {
|
||||
}
|
||||
|
||||
DEFUN(hash_table_count, "hash-table-count", (LispVal * ht), "(ht)", "") {
|
||||
CHECK_TYPE(ht, TYPE_HASH_TABLE);
|
||||
return MAKE_FIXNUM(((LispHashTable *) ht)->count);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user