]> gitweb.factorcode.org Git - factor.git/commitdiff
words are now hashed
authorSlava Pestov <slava@factorcode.org>
Sun, 29 Aug 2004 08:03:16 +0000 (08:03 +0000)
committerSlava Pestov <slava@factorcode.org>
Sun, 29 Aug 2004 08:03:16 +0000 (08:03 +0000)
TODO.FACTOR.txt
library/cross-compiler.factor
library/image.factor
library/platform/native/kernel.factor
native/primitives.c
native/primitives.h
native/word.c
native/word.h

index 673606eb1375cb5081213b5357a632dba81be4d1..bbd9d6c13218e28e1c244d9096f0ac9cb6f59374 100644 (file)
@@ -6,6 +6,7 @@
   - index.html\r
   - if a directory is requested and URL does not end with /, redirect\r
 - minimize stage2 initialization code, just move it to source files\r
+_ push call/allot counts as ulong bignums\r
 \r
 + bignums:\r
 \r
index 9f2d8dac114c2198a5d9628a9dca2bc61f04a5e9..9701b319b2600602e013924def335e1b1114f733 100644 (file)
@@ -98,6 +98,7 @@ DEFER: (random-int)
 
 IN: words
 DEFER: <word>
+DEFER: word-hashcode
 DEFER: word-primitive
 DEFER: set-word-primitive
 DEFER: word-parameter
@@ -196,6 +197,7 @@ IN: cross-compiler
         fsqrt
         word?
         <word>
+        word-hashcode
         word-primitive
         set-word-primitive
         word-parameter
index 5465e42678987df222bb0f87bc0376d3cec9f5b4..bb830ea1b6aebc1da9811f7d7a54bce9d8f79f2a 100644 (file)
@@ -36,6 +36,7 @@ USE: logic
 USE: math
 USE: namespaces
 USE: prettyprint
+USE: random
 USE: stack
 USE: stdio
 USE: streams
@@ -168,7 +169,9 @@ USE: words
 ( Words )
 
 : word, ( -- pointer )
-    word-tag here-as word-tag >header emit 0 emit ;
+    word-tag here-as word-tag >header emit
+    0 HEX: fffffff random-int emit ( hashcode )
+    0 emit ;
 
 ! This is to handle mutually recursive words
 ! It is a hack. A recursive word in the cdr of a
@@ -295,7 +298,6 @@ IN: cross-compiler
     r> ( parameter -- ) emit
     ( plist -- ) emit
     0 emit ( padding )
-    0 emit
     0 emit ;
 
 : primitive, ( word primitive -- ) f (worddef,) ;
index f2ac8606058af4a646105b5320d9168160705399..e6563ad71ec957e7bab32455f9b7662f8a3b8441 100644 (file)
@@ -47,6 +47,7 @@ USE: vectors
 : hashcode ( obj -- hash )
     #! If two objects are =, they must have equal hashcodes.
     [
+        [ word? ] [ word-hashcode ]
         [ cons? ] [ 4 cons-hashcode ]
         [ string? ] [ str-hashcode ]
         [ number? ] [ >fixnum ]
index 6fc8020b0b46b591a6fe79abd86dc147fbdaa7e7..b71913d848f8b5c1e041f79c0060109aae214eda 100644 (file)
@@ -87,6 +87,7 @@ XT primitives[] = {
         primitive_fsqrt,
        primitive_wordp,
        primitive_word,
+       primitive_word_hashcode,
        primitive_word_primitive,
        primitive_set_word_primitive,
        primitive_word_parameter,
index 7304689766756b974de95ff7eee25f969589f59e..8f29a1d387ca0cd8a17700b2d2aadd076bf0692e 100644 (file)
@@ -1,4 +1,4 @@
 extern XT primitives[];
-#define PRIMITIVE_COUNT 144
+#define PRIMITIVE_COUNT 145
 
 CELL primitive_to_xt(CELL primitive);
index 90a05a85b68739aec8522b28ff33371d6723c712..f304ffe688224b4b84ec49d7c1b802f4f9dbc3da 100644 (file)
@@ -3,11 +3,13 @@
 WORD* word(CELL primitive, CELL parameter, CELL plist)
 {
        WORD* word = allot_object(WORD_TYPE,sizeof(WORD));
+       word->hashcode = (CELL)word; /* initial address */
        word->xt = primitive_to_xt(primitive);
        word->primitive = primitive;
        word->parameter = parameter;
        word->plist = plist;
        word->call_count = 0;
+       word->allot_count = 0;
 
        return word;
 }
@@ -35,6 +37,11 @@ void primitive_word(void)
        dpush(tag_word(word(primitive,parameter,plist)));
 }
 
+void primitive_word_hashcode(void)
+{
+       drepl(tag_fixnum(untag_word(dpeek())->hashcode));
+}
+
 void primitive_word_primitive(void)
 {
        drepl(tag_fixnum(untag_word(dpeek())->primitive));
index eece411c3203c7d6005e710b98c47eedae50f0ee..d4623c94ddcc5a1d7b58a3f3359a280cf93389fc 100644 (file)
@@ -3,6 +3,8 @@ typedef void (*XT)(void);
 typedef struct {
        /* TAGGED header */
        CELL header;
+       /* untagged hashcode */
+       CELL hashcode;
        /* untagged execution token: jump here to execute word */
        CELL xt;
        /* untagged on-disk primitive number */
@@ -15,7 +17,6 @@ typedef struct {
        CELL call_count;
        /* UNTAGGED amount of memory allocated in word */
        CELL allot_count;
-       CELL padding;
 } WORD;
 
 INLINE WORD* untag_word(CELL tagged)
@@ -33,6 +34,7 @@ WORD* word(CELL primitive, CELL parameter, CELL plist);
 void update_xt(WORD* word);
 void primitive_wordp(void);
 void primitive_word(void);
+void primitive_word_hashcode(void);
 void primitive_word_primitive(void);
 void primitive_set_word_primitive(void);
 void primitive_word_parameter(void);