From cda3685c4dcd632b4b73412a6d36f22192a75f1e Mon Sep 17 00:00:00 2001 From: Slava Pestov <slava@slava-pestovs-macbook-pro.local> Date: Sat, 9 May 2009 20:24:17 -0500 Subject: [PATCH 1/2] Eliminate prettyprinter dependency from UI --- basis/math/rectangles/prettyprint/authors.txt | 1 + basis/math/rectangles/prettyprint/prettyprint.factor | 7 +++++++ basis/math/rectangles/rectangles.factor | 9 +++++---- basis/ui/gadgets/gadgets.factor | 10 +++++----- basis/ui/gadgets/prettyprint/authors.txt | 1 + basis/ui/gadgets/prettyprint/prettyprint.factor | 7 +++++++ 6 files changed, 26 insertions(+), 9 deletions(-) create mode 100644 basis/math/rectangles/prettyprint/authors.txt create mode 100644 basis/math/rectangles/prettyprint/prettyprint.factor create mode 100644 basis/ui/gadgets/prettyprint/authors.txt create mode 100644 basis/ui/gadgets/prettyprint/prettyprint.factor diff --git a/basis/math/rectangles/prettyprint/authors.txt b/basis/math/rectangles/prettyprint/authors.txt new file mode 100644 index 0000000000..d4f5d6b3ae --- /dev/null +++ b/basis/math/rectangles/prettyprint/authors.txt @@ -0,0 +1 @@ +Slava Pestov \ No newline at end of file diff --git a/basis/math/rectangles/prettyprint/prettyprint.factor b/basis/math/rectangles/prettyprint/prettyprint.factor new file mode 100644 index 0000000000..c23be50029 --- /dev/null +++ b/basis/math/rectangles/prettyprint/prettyprint.factor @@ -0,0 +1,7 @@ +! Copyright (C) 2009 Slava Pestov. +! See http://factorcode.org/license.txt for BSD license. +USING: accessors math.rectangles kernel prettyprint.custom prettyprint.backend ; +IN: math.rectangles.prettyprint + +M: rect pprint* + \ RECT: [ [ loc>> ] [ dim>> ] bi [ pprint* ] bi@ ] pprint-prefix ; diff --git a/basis/math/rectangles/rectangles.factor b/basis/math/rectangles/rectangles.factor index 340eafa37d..c8569dfdb9 100644 --- a/basis/math/rectangles/rectangles.factor +++ b/basis/math/rectangles/rectangles.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2008, 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: kernel arrays sequences math math.vectors accessors -parser prettyprint.custom prettyprint.backend ; +parser ; IN: math.rectangles TUPLE: rect { loc initial: { 0 0 } } { dim initial: { 0 0 } } ; @@ -10,9 +10,6 @@ TUPLE: rect { loc initial: { 0 0 } } { dim initial: { 0 0 } } ; SYNTAX: RECT: scan-object scan-object <rect> parsed ; -M: rect pprint* - \ RECT: [ [ loc>> ] [ dim>> ] bi [ pprint* ] bi@ ] pprint-prefix ; - : <zero-rect> ( -- rect ) rect new ; inline : point>rect ( loc -- rect ) { 0 0 } <rect> ; inline @@ -64,3 +61,7 @@ M: rect contains-point? [ [ loc>> ] dip (>>loc) ] [ [ dim>> ] dip (>>dim) ] 2bi ; inline + +USING: vocabs vocabs.loader ; + +"prettyprint" vocab [ "math.rectangles.prettyprint" require ] when \ No newline at end of file diff --git a/basis/ui/gadgets/gadgets.factor b/basis/ui/gadgets/gadgets.factor index f9f397d46f..5dd1710cdd 100644 --- a/basis/ui/gadgets/gadgets.factor +++ b/basis/ui/gadgets/gadgets.factor @@ -3,8 +3,7 @@ USING: accessors arrays hashtables kernel models math namespaces make sequences quotations math.vectors combinators sorting binary-search vectors dlists deques models threads -concurrency.flags math.order math.rectangles fry locals -prettyprint.backend prettyprint.custom ; +concurrency.flags math.order math.rectangles fry locals ; IN: ui.gadgets ! Values for orientation slot @@ -28,9 +27,6 @@ interior boundary model ; -! Don't print gadgets with RECT: syntax -M: gadget pprint* pprint-tuple ; - M: gadget equal? 2drop f ; M: gadget hashcode* nip [ [ \ gadget counter ] unless* ] change-id id>> ; @@ -397,3 +393,7 @@ M: f request-focus-on 2drop ; : focus-path ( gadget -- seq ) [ focus>> ] follow ; + +USING: vocabs vocabs.loader ; + +"prettyprint" vocab [ "ui.gadgets.prettyprint" require ] when \ No newline at end of file diff --git a/basis/ui/gadgets/prettyprint/authors.txt b/basis/ui/gadgets/prettyprint/authors.txt new file mode 100644 index 0000000000..d4f5d6b3ae --- /dev/null +++ b/basis/ui/gadgets/prettyprint/authors.txt @@ -0,0 +1 @@ +Slava Pestov \ No newline at end of file diff --git a/basis/ui/gadgets/prettyprint/prettyprint.factor b/basis/ui/gadgets/prettyprint/prettyprint.factor new file mode 100644 index 0000000000..82a89eda11 --- /dev/null +++ b/basis/ui/gadgets/prettyprint/prettyprint.factor @@ -0,0 +1,7 @@ +! Copyright (C) 2009 Slava Pestov. +! See http://factorcode.org/license.txt for BSD license. +USING: ui.gadgets prettyprint.backend prettyprint.custom ; +IN: ui.gadgets.prettyprint + +! Don't print gadgets with RECT: syntax +M: gadget pprint* pprint-tuple ; \ No newline at end of file From aa3aa715beac977f8f207e5d090f7b0a03780a0b Mon Sep 17 00:00:00 2001 From: Slava Pestov <slava@slava-pestovs-macbook-pro.local> Date: Sat, 9 May 2009 20:24:32 -0500 Subject: [PATCH 2/2] Slightly more space-efficient dispatch table representation --- core/generic/single/single.factor | 2 +- vm/dispatch.cpp | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/core/generic/single/single.factor b/core/generic/single/single.factor index 36a76153f9..8d84b21bf7 100644 --- a/core/generic/single/single.factor +++ b/core/generic/single/single.factor @@ -163,7 +163,7 @@ M: hi-tag-dispatch-engine compile-engine : build-fast-hash ( methods -- buckets ) >alist V{ } clone [ hashcode 1array ] distribute-buckets - [ compile-engines* >alist >array ] map ; + [ compile-engines* >alist { } join ] map ; M: echelon-dispatch-engine compile-engine dup n>> 0 = [ diff --git a/vm/dispatch.cpp b/vm/dispatch.cpp index 847a19d738..4a1411733e 100755 --- a/vm/dispatch.cpp +++ b/vm/dispatch.cpp @@ -8,15 +8,14 @@ cell megamorphic_cache_misses; static cell search_lookup_alist(cell table, cell klass) { - array *pairs = untag<array>(table); - fixnum index = array_capacity(pairs) - 1; + array *elements = untag<array>(table); + fixnum index = array_capacity(elements) - 2; while(index >= 0) { - array *pair = untag<array>(array_nth(pairs,index)); - if(array_nth(pair,0) == klass) - return array_nth(pair,1); + if(array_nth(elements,index) == klass) + return array_nth(elements,index + 1); else - index--; + index -= 2; } return F;