diff --git a/stage1/object.h b/stage1/object.h index 68e576e..ac09de6 100644 --- a/stage1/object.h +++ b/stage1/object.h @@ -13,6 +13,7 @@ struct lisp_cons { struct lisp_symbol { char *buf; unsigned long len; // cap = len for symbols (they must be allocated with exact size) + char hash; // for hashtables }; struct lisp_string { diff --git a/stage1/object.h.s b/stage1/object.h.s index 665d1fe..a82ed8d 100644 --- a/stage1/object.h.s +++ b/stage1/object.h.s @@ -6,6 +6,7 @@ .set LISP_SYMBOL_BUF, 8 .set LISP_SYMBOL_LEN, 16 +.set LISP_SYMBOL_HASH, 24 .set LISP_CONS_HEAD, 8 .set LISP_CONS_TAIL, 16 diff --git a/stage1/symbol.s b/stage1/symbol.s index dad9b14..6ac1453 100644 --- a/stage1/symbol.s +++ b/stage1/symbol.s @@ -107,8 +107,12 @@ symbol_intern: mv a1, s1 mv a2, s4 call mem_copy + # get symbol hash + mv a0, s4 + mv a1, s2 + call symbol_hash # create a new object for the symbol - mv a3, zero + andi a3, a0, 0xff # LISP_SYMBOL_HASH mv a2, s2 # LISP_SYMBOL_LEN mv a1, s4 # LISP_SYMBOL_BUF li a0, LISP_OBJECT_TYPE_SYMBOL diff --git a/stage1/words.s b/stage1/words.s index 17cecc9..2976a8c 100644 --- a/stage1/words.s +++ b/stage1/words.s @@ -463,9 +463,7 @@ get_words_ptr: lwu t2, LISP_OBJECT_TYPE(t1) li t3, LISP_OBJECT_TYPE_SYMBOL bne t2, t3, .Lget_words_ptr_error # not symbol => error - ld a0, LISP_SYMBOL_BUF(t1) - ld a1, LISP_SYMBOL_LEN(t1) - call symbol_hash + lb a0, LISP_SYMBOL_HASH(t1) # mask the hash to number of bits andi a0, a0, (1 << WORDS_HASH_BITS) - 1 # times 8 (double word)