From eca20beec0956d0e8d1576e5e67b2b0b71414d81 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Fri, 25 Nov 2005 00:02:20 +0000 Subject: [PATCH] about to bootstrap hashstable --- TODO.FACTOR.txt | 4 +++- library/bootstrap/boot-stage1.factor | 9 +------- library/bootstrap/image.factor | 3 +-- library/generic/generic.factor | 23 ++++++++++----------- library/generic/math-combination.factor | 2 +- library/generic/standard-combination.factor | 4 ++-- library/generic/tuple.factor | 2 +- library/test/benchmark/hashtables.factor | 16 +++++++------- library/vocabularies.factor | 5 ++++- native/factor.c | 2 +- native/hashtable.c | 4 ++++ 11 files changed, 38 insertions(+), 36 deletions(-) diff --git a/TODO.FACTOR.txt b/TODO.FACTOR.txt index 94639ce4bd..d4c52868db 100644 --- a/TODO.FACTOR.txt +++ b/TODO.FACTOR.txt @@ -7,7 +7,6 @@ f f G:110887 } } } - intrinsic char-slot set-char-slot for x86 -- fix remaining GL issues - closing ui does not stop timers - adding/removing timers automatically for animated gadgets - saving image with UI open @@ -18,6 +17,9 @@ - remove word transfer hack in bootstrap - the invalid recursion form case needs to be fixed, for inlines too - what about tasks and timers between image restarts +- new hashtable + - bootstrap it in + - double hash + ui: diff --git a/library/bootstrap/boot-stage1.factor b/library/bootstrap/boot-stage1.factor index ad11853443..3d1540c93b 100644 --- a/library/bootstrap/boot-stage1.factor +++ b/library/bootstrap/boot-stage1.factor @@ -11,14 +11,7 @@ vectors words ; ! The [ ] make form creates a boot quotation [ - [ - ! initialize it twice so that we get a catchstack - ! early on for each-object. - init-error-handler - [ hashtable? ] instances - [ dup hash-size 1 max swap set-bucket-count ] each - boot - ] % + \ boot , { "/version.factor" diff --git a/library/bootstrap/image.factor b/library/bootstrap/image.factor index 5b472b226f..1e9462b796 100644 --- a/library/bootstrap/image.factor +++ b/library/bootstrap/image.factor @@ -188,8 +188,7 @@ M: f ' ( obj -- ptr ) : transfer-word ( word -- word ) #! This is a hack. See doc/bootstrap.txt. - dup dup word-name swap word-vocabulary lookup - [ ] [ dup "Missing DEFER: " word-error ] ?if ; + dup target-word [ ] [ dup "Missing DEFER: " word-error ] ?if ; : pooled-object ( object -- ptr ) objects get hash ; diff --git a/library/generic/generic.factor b/library/generic/generic.factor index f76e790a4f..5d53c6354f 100644 --- a/library/generic/generic.factor +++ b/library/generic/generic.factor @@ -96,12 +96,18 @@ M: generic definer drop \ G: ; over word-name " is not a class" append throw ] unless 2drop ; +: with-methods ( word quot -- | quot: methods -- ) + #! Applies a quotation to the method hash and regenerates + #! the generic. + swap [ "methods" word-prop swap call ] keep make-generic ; + inline + : define-method ( definition class generic -- ) - >r reintern r> 2dup check-method - [ "methods" word-prop set-hash ] keep make-generic ; + >r bootstrap-word r> 2dup check-method + [ set-hash ] with-methods ; : forget-method ( class generic -- ) - [ "methods" word-prop remove-hash ] keep make-generic ; + [ remove-hash ] with-methods ; : init-methods ( word -- ) dup "methods" word-prop @@ -111,13 +117,7 @@ M: generic definer drop \ G: ; : bootstrap-combination ( quot -- quot ) #! Bootstrap hack. - global [ - [ - dup word? [ - dup word-name swap word-vocabulary lookup - ] when - ] map - ] bind ; + global [ [ dup word? [ target-word ] when ] map ] bind ; : define-generic* ( word combination -- ) bootstrap-combination @@ -196,10 +196,9 @@ PREDICATE: word predicate "definition" word-prop ; ] map [ drop f ] swap alist>quot ; : set-members ( class members -- ) - [ reintern ] map "members" set-word-prop ; + [ bootstrap-word ] map "members" set-word-prop ; : define-union ( class predicate members -- ) - #! We have to turn the f object into the f word, same for t. 3dup nip set-members pick define-class union-predicate define-predicate ; diff --git a/library/generic/math-combination.factor b/library/generic/math-combination.factor index 69756e2c67..35b86d065e 100644 --- a/library/generic/math-combination.factor +++ b/library/generic/math-combination.factor @@ -38,7 +38,7 @@ TUPLE: no-math-method left right generic ; [ ] [ [ no-math-method ] curry ] ?if ; : object-method ( generic -- quot ) - object reintern applicable-method ; + object bootstrap-word applicable-method ; : math-method ( word left right -- quot ) [ type>class ] 2apply 2dup and [ diff --git a/library/generic/standard-combination.factor b/library/generic/standard-combination.factor index a52f77a53a..656a47f253 100644 --- a/library/generic/standard-combination.factor +++ b/library/generic/standard-combination.factor @@ -20,7 +20,7 @@ namespaces sequences vectors words ; : sort-methods ( assoc n -- vtable ) #! Input is a predicate -> method association. [ - type>class [ object reintern ] unless* + type>class [ object bootstrap-word ] unless* swap [ car classes-intersect? ] subset-with ] map-with ; @@ -43,7 +43,7 @@ namespaces sequences vectors words ; : ( picker word n -- vtable ) #! n is vtable size; either num-types or num-tags. - >r 2dup empty-method \ object reintern + >r 2dup empty-method \ object bootstrap-word swons >r methods r> swons r> sort-methods vtable-methods ; : small-generic ( picker word -- def ) diff --git a/library/generic/tuple.factor b/library/generic/tuple.factor index 18e2dcb52e..64c51a5cf9 100644 --- a/library/generic/tuple.factor +++ b/library/generic/tuple.factor @@ -72,7 +72,7 @@ PREDICATE: word tuple-class "tuple-size" word-prop ; >r create-in dup intern-symbol dup tuple-predicate - dup \ tuple reintern "superclass" set-word-prop + dup \ tuple bootstrap-word "superclass" set-word-prop dup define-class dup r> tuple-slots default-constructor ; diff --git a/library/test/benchmark/hashtables.factor b/library/test/benchmark/hashtables.factor index f65965a71c..742972ee81 100644 --- a/library/test/benchmark/hashtables.factor +++ b/library/test/benchmark/hashtables.factor @@ -1,15 +1,17 @@ -USING: compiler hashtables kernel math namespaces sequences test ; +IN: temporary +USING: compiler hashtables kernel math memory namespaces +sequences strings test ; -: store-hash ( hashtable n -- ) +: store-hash ( hashtable seq -- ) [ dup pick set-hash ] each drop ; -: lookup-hash ( hashtable n -- ) +: lookup-hash ( hashtable seq -- ) [ over hash drop ] each drop ; -: hashtable-benchmark ( -- ) +: hashtable-benchmark ( seq -- ) 100 [ drop - 80000 100000 swap 2dup store-hash lookup-hash - ] each ; compiled + 100000 swap 2dup store-hash lookup-hash + ] each-with ; compiled -[ ] [ hashtable-benchmark ] unit-test +[ ] [ [ string? ] instances hashtable-benchmark ] unit-test diff --git a/library/vocabularies.factor b/library/vocabularies.factor index 0c8a0c54ac..b9887835d4 100644 --- a/library/vocabularies.factor +++ b/library/vocabularies.factor @@ -79,12 +79,15 @@ SYMBOL: vocabularies #! Test if the word is a member of its vocabulary. dup word-name over word-vocabulary lookup eq? ; -: reintern ( word -- word ) +: bootstrap-word ( word -- word ) dup word-name swap word-vocabulary bootstrapping? get [ dup "syntax" = [ drop "!syntax" ] when ] when lookup ; +: target-word ( word -- word ) + dup word-name swap word-vocabulary lookup ; + "scratchpad" "in" set [ "scratchpad" diff --git a/native/factor.c b/native/factor.c index ee281c3292..eef65405a8 100644 --- a/native/factor.c +++ b/native/factor.c @@ -42,7 +42,7 @@ int main(int argc, char** argv) CELL generations = 2; CELL young_size = 8; CELL aging_size = 16; - CELL code_size = 2; + CELL code_size = 4; CELL literal_size = 128; CELL args; CELL i; diff --git a/native/hashtable.c b/native/hashtable.c index d9d1bb55e1..16ddcf658d 100644 --- a/native/hashtable.c +++ b/native/hashtable.c @@ -19,10 +19,14 @@ void primitive_hashtable(void) void fixup_hashtable(F_HASHTABLE* hashtable) { + data_fixup(&hashtable->count); + data_fixup(&hashtable->deleted); data_fixup(&hashtable->array); } void collect_hashtable(F_HASHTABLE* hashtable) { + copy_handle(&hashtable->count); + copy_handle(&hashtable->deleted); copy_handle(&hashtable->array); }