summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--com.c1
-rw-r--r--ht.c8
-rw-r--r--val.c4
3 files changed, 8 insertions, 5 deletions
diff --git a/com.c b/com.c
index cfe4df5..fbc93ac 100644
--- a/com.c
+++ b/com.c
@@ -175,6 +175,7 @@ int main() {
chunk_wbc(S, &ch, OP_PRINT);
chunk_wbc(S, &ch, OP_RET);
+ puts("compile done");
return runvm(S);
}
diff --git a/ht.c b/ht.c
index 09eec3e..a2845f0 100644
--- a/ht.c
+++ b/ht.c
@@ -24,15 +24,17 @@ Ht ht_new() {
}
static HtEntry *find(HtEntry *b, size_t cap, ObjString *k) {
- size_t ix = k->hash % cap;
+ // cap is guaranteed to be power of 2
+ size_t mask = cap - 1;
+ size_t ix = k->hash & mask;
if (cap == 0) return NULL;
for (;;) {
HtEntry *ent = &b[ix];
// XXX tombstones
- if (ent->k == k || ent->k == NULL) {
+ if (ent->k == NULL || ent->k == k) {
return ent;
}
- ix = (ix+1)%cap;
+ ix = (ix+1) & mask;
}
}
diff --git a/val.c b/val.c
index 5a20d09..18d0ffa 100644
--- a/val.c
+++ b/val.c
@@ -76,8 +76,8 @@ void println_val(Val v) {
}
bool is_truthy(Val v) {
- if (IS_NIL(v) || ( IS_BOOL(v) && AS_BOOL(v) == false))
- return false;
+ if (IS_BOOL(v)) return AS_BOOL(v);
+ if (IS_NIL(v)) return false;
return true;
}