From 5ccc94464fcff54186ce09a9ab7885a528b51f6e Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Thu, 5 May 2005 20:03:24 +0000 Subject: [PATCH] fix .factor-rc error reporting --- CHANGES.txt | 3 +++ TODO.FACTOR.txt | 4 ---- library/collections/sequences-epilogue.factor | 21 ++++++++++++------- library/collections/sequences.factor | 1 - library/collections/vectors.factor | 2 +- library/syntax/parse-stream.factor | 15 +++++++------ 6 files changed, 25 insertions(+), 21 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 7374dc4add..b75060a82d 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -6,6 +6,9 @@ data could fill up the buffer and cause a denial-of-service attack. The alien interface now supports "float" and "double" types. +Moved the 'skip' combinator from the 'parser' vocabulary to 'sequences', +since its generic now. Implemented 'index*' in terms of 'skip'. + Factor 0.74: ------------ diff --git a/TODO.FACTOR.txt b/TODO.FACTOR.txt index 2152f7886d..ae98f9fbdc 100644 --- a/TODO.FACTOR.txt +++ b/TODO.FACTOR.txt @@ -8,16 +8,12 @@ - 2map slow with lists - nappend: instead of using push, enlarge the sequence with set-length then add set the elements with set-nth -- ensure-capacity: don't be generic -- vector's ensure-capacity will crash if not given fixnums! - generic each some? all? member? memq? all=? index? subseq? map - index and index* are very slow with lists - unsafe-sbuf>string - generic subseq - GENERIC: map - list impl same as now -- generic parser::scan -- .factor-rc loading errors are not reported properly - code walker & exceptions - string sub-primitives - generational gc diff --git a/library/collections/sequences-epilogue.factor b/library/collections/sequences-epilogue.factor index 795f12f23c..bff8a4dd4a 100644 --- a/library/collections/sequences-epilogue.factor +++ b/library/collections/sequences-epilogue.factor @@ -10,7 +10,6 @@ vectors ; ! defined tuples that respond to the sequence protocol. UNION: sequence array string sbuf vector ; -M: object ensure-capacity 2drop ; M: object thaw clone ; M: object freeze drop ; @@ -93,14 +92,23 @@ M: sequence (tree-each) [ (tree-each) ] seq-each-with ; : seq-2map ( seq1 seq2 quot -- seq | quot: elt1 elt2 -- elt3 ) swap [ swap 2nmap ] immutable ; inline +: skip ( i seq quot -- n | quot: elt -- ? ) + #! Find the next element starting at i that satisfies the + #! quotation. + >r 2dup length < [ + 2dup nth r> dup >r call [ + r> 2drop + ] [ + >r 1 + r> r> skip + ] ifte + ] [ + r> drop nip length + ] ifte ; inline + ! Operations : index* ( obj i seq -- n ) #! The index of the object in the sequence, starting from i. - 2dup length >= [ - 3drop -1 - ] [ - 3dup nth = [ drop nip ] [ >r 1 + r> index* ] ifte - ] ifte ; + [ dupd = ] skip nip ; : index ( obj seq -- n ) #! The index of the object in the sequence. @@ -112,7 +120,6 @@ M: sequence (tree-each) [ (tree-each) ] seq-each-with ; : nappend ( s1 s2 -- ) #! Destructively append s2 to s1. - ! over length over ensure-capacity [ over push ] seq-each drop ; : append ( s1 s2 -- s1+s2 ) diff --git a/library/collections/sequences.factor b/library/collections/sequences.factor index 3f1be16ed2..780c0b241c 100644 --- a/library/collections/sequences.factor +++ b/library/collections/sequences.factor @@ -14,7 +14,6 @@ USING: generic kernel math strings vectors ; GENERIC: empty? ( sequence -- ? ) GENERIC: length ( sequence -- n ) GENERIC: set-length ( n sequence -- ) -GENERIC: ensure-capacity ( n sequence -- ) GENERIC: nth ( n sequence -- obj ) GENERIC: set-nth ( value n sequence -- obj ) GENERIC: thaw ( seq -- mutable-seq ) diff --git a/library/collections/vectors.factor b/library/collections/vectors.factor index db54220ea1..496c5dcc03 100644 --- a/library/collections/vectors.factor +++ b/library/collections/vectors.factor @@ -36,7 +36,7 @@ IN: kernel-internals #! to exactly len. [ vector-array grow-array ] keep set-vector-array ; -M: vector ensure-capacity ( n vec -- ) +: ensure-capacity ( n vec -- ) #! If n is beyond the vector's length, increase the length, #! growing the array if necessary, with an optimistic #! doubling of its size. diff --git a/library/syntax/parse-stream.factor b/library/syntax/parse-stream.factor index b9c3eb1ea9..35005a2b17 100644 --- a/library/syntax/parse-stream.factor +++ b/library/syntax/parse-stream.factor @@ -9,16 +9,15 @@ USING: kernel lists namespaces sequences streams strings ; : (parse-stream) ( name stream -- quot ) #! Uses the current namespace for temporary variables. - >r file set f ( initial parse tree ) r> - [ (parse) ] read-lines reverse - file off - line-number off ; + [ + >r file set f ( initial parse tree ) r> + [ (parse) ] read-lines reverse + file off + line-number off + ] with-parser ; : parse-stream ( name stream -- quot ) - [ - file-vocabs - [ (parse-stream) ] with-parser - ] with-scope ; + [ file-vocabs [ (parse-stream) ] with-parser ] with-scope ; : parse-file ( file -- quot ) dup parse-stream ;