Merge branch 'master' of git://factorcode.org/git/factor
commit
d7b2612c40
|
@ -529,3 +529,12 @@ TUPLE: another-forget-accessors-test ;
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
[ t ] [ \ another-forget-accessors-test class? ] unit-test
|
[ t ] [ \ another-forget-accessors-test class? ] unit-test
|
||||||
|
|
||||||
|
! Shadowing test
|
||||||
|
[ f ] [
|
||||||
|
t parser-notes? [
|
||||||
|
[
|
||||||
|
"IN: classes.tuple.tests TUPLE: shadow-1 a b ; TUPLE: shadow-2 < shadow-1 a b ;" eval
|
||||||
|
] with-string-writer empty?
|
||||||
|
] with-variable
|
||||||
|
] unit-test
|
||||||
|
|
|
@ -55,6 +55,9 @@ PRIVATE>
|
||||||
"slot-names" word-prop
|
"slot-names" word-prop
|
||||||
[ dup array? [ second ] when ] map ;
|
[ dup array? [ second ] when ] map ;
|
||||||
|
|
||||||
|
: all-slot-names ( class -- slots )
|
||||||
|
superclasses [ slot-names ] map concat \ class prefix ;
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
: tuple= ( tuple1 tuple2 -- ? )
|
: tuple= ( tuple1 tuple2 -- ? )
|
||||||
|
@ -119,9 +122,6 @@ PRIVATE>
|
||||||
: define-tuple-layout ( class -- )
|
: define-tuple-layout ( class -- )
|
||||||
dup make-tuple-layout "layout" set-word-prop ;
|
dup make-tuple-layout "layout" set-word-prop ;
|
||||||
|
|
||||||
: all-slot-names ( class -- slots )
|
|
||||||
superclasses [ slot-names ] map concat \ class prefix ;
|
|
||||||
|
|
||||||
: compute-slot-permutation ( class old-slot-names -- permutation )
|
: compute-slot-permutation ( class old-slot-names -- permutation )
|
||||||
>r all-slot-names r> [ index ] curry map ;
|
>r all-slot-names r> [ index ] curry map ;
|
||||||
|
|
||||||
|
|
|
@ -59,6 +59,10 @@ ERROR: no-case ;
|
||||||
M: sequence hashcode*
|
M: sequence hashcode*
|
||||||
[ sequence-hashcode ] recursive-hashcode ;
|
[ sequence-hashcode ] recursive-hashcode ;
|
||||||
|
|
||||||
|
M: reversed hashcode* [ sequence-hashcode ] recursive-hashcode ;
|
||||||
|
|
||||||
|
M: slice hashcode* [ sequence-hashcode ] recursive-hashcode ;
|
||||||
|
|
||||||
M: hashtable hashcode*
|
M: hashtable hashcode*
|
||||||
[
|
[
|
||||||
dup assoc-size 1 number=
|
dup assoc-size 1 number=
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
! Copyright (C) 2004, 2008 Slava Pestov.
|
! Copyright (C) 2004, 2008 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: kernel namespaces arrays sequences io inference.backend
|
USING: kernel namespaces arrays sequences io inference.backend
|
||||||
inference.state generator debugger math.parser prettyprint words
|
inference.state generator debugger words compiler.units
|
||||||
compiler.units continuations vocabs assocs alien.compiler dlists
|
continuations vocabs assocs alien.compiler dlists optimizer
|
||||||
optimizer definitions math compiler.errors threads graphs
|
definitions math compiler.errors threads graphs generic
|
||||||
generic inference ;
|
inference ;
|
||||||
IN: compiler
|
IN: compiler
|
||||||
|
|
||||||
: ripple-up ( word -- )
|
: ripple-up ( word -- )
|
||||||
|
|
|
@ -370,4 +370,7 @@ HINTS: recursive-inline-hang-2 array ;
|
||||||
|
|
||||||
HINTS: recursive-inline-hang-3 array ;
|
HINTS: recursive-inline-hang-3 array ;
|
||||||
|
|
||||||
|
! Regression
|
||||||
|
USE: sequences.private
|
||||||
|
|
||||||
|
[ ] [ { (3append) } compile ] unit-test
|
||||||
|
|
|
@ -153,6 +153,8 @@ ARTICLE: "parser-files" "Parsing source files"
|
||||||
{ $subsection parse-file }
|
{ $subsection parse-file }
|
||||||
{ $subsection bootstrap-file }
|
{ $subsection bootstrap-file }
|
||||||
"The parser cross-references source files and definitions. This allows it to keep track of removed definitions, and prevent forward references and accidental redefinitions."
|
"The parser cross-references source files and definitions. This allows it to keep track of removed definitions, and prevent forward references and accidental redefinitions."
|
||||||
|
$nl
|
||||||
|
"While the above words are useful for one-off experiments, real programs should be written to use the vocabulary system instead; see " { $link "vocabs.loader" } "."
|
||||||
{ $see-also "source-files" } ;
|
{ $see-also "source-files" } ;
|
||||||
|
|
||||||
ARTICLE: "parser-usage" "Reflective parser usage"
|
ARTICLE: "parser-usage" "Reflective parser usage"
|
||||||
|
@ -161,6 +163,13 @@ ARTICLE: "parser-usage" "Reflective parser usage"
|
||||||
"The parser can also parse from a stream:"
|
"The parser can also parse from a stream:"
|
||||||
{ $subsection parse-stream } ;
|
{ $subsection parse-stream } ;
|
||||||
|
|
||||||
|
ARTICLE: "top-level-forms" "Top level forms"
|
||||||
|
"Any code outside of a definition is known as a " { $emphasis "top-level form" } "; top-level forms are run after the entire source file has been parsed, regardless of their position in the file."
|
||||||
|
$nl
|
||||||
|
"Top-level forms do not have access to the " { $link in } " and " { $link use } " variables that were set at parse time, nor do they run inside " { $link with-compilation-unit } "; so meta-programming might require extra work in a top-level form compared with a parsing word."
|
||||||
|
$nl
|
||||||
|
"Also, top-level forms run in a new dynamic scope, so using " { $link set } " to store values is almost always wrong, since the values will be lost after the top-level form completes. To save values computed by a top-level form, either use " { $link set-global } " or define a new word with the value." ;
|
||||||
|
|
||||||
ARTICLE: "parser" "The parser"
|
ARTICLE: "parser" "The parser"
|
||||||
"This parser is a general facility for reading textual representations of objects and definitions. The parser is implemented in the " { $vocab-link "parser" } " and " { $vocab-link "syntax" } " vocabularies."
|
"This parser is a general facility for reading textual representations of objects and definitions. The parser is implemented in the " { $vocab-link "parser" } " and " { $vocab-link "syntax" } " vocabularies."
|
||||||
$nl
|
$nl
|
||||||
|
@ -168,6 +177,7 @@ $nl
|
||||||
{ $subsection "vocabulary-search" }
|
{ $subsection "vocabulary-search" }
|
||||||
{ $subsection "parser-files" }
|
{ $subsection "parser-files" }
|
||||||
{ $subsection "parser-usage" }
|
{ $subsection "parser-usage" }
|
||||||
|
{ $subsection "top-level-forms" }
|
||||||
"The parser can be extended."
|
"The parser can be extended."
|
||||||
{ $subsection "parsing-words" }
|
{ $subsection "parsing-words" }
|
||||||
{ $subsection "parser-lexer" }
|
{ $subsection "parser-lexer" }
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
! Copyright (C) 2005, 2008 Slava Pestov.
|
! Copyright (C) 2005, 2008 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: arrays definitions generic assocs kernel math
|
USING: arrays definitions generic assocs kernel math namespaces
|
||||||
namespaces prettyprint sequences strings vectors words
|
prettyprint sequences strings vectors words quotations inspector
|
||||||
quotations inspector io.styles io combinators sorting
|
io.styles io combinators sorting splitting math.parser effects
|
||||||
splitting math.parser effects continuations debugger
|
continuations debugger io.files io.streams.string vocabs
|
||||||
io.files io.streams.string vocabs io.encodings.utf8
|
io.encodings.utf8 source-files classes classes.tuple hashtables
|
||||||
source-files classes hashtables compiler.errors compiler.units
|
compiler.errors compiler.units accessors ;
|
||||||
accessors ;
|
|
||||||
IN: parser
|
IN: parser
|
||||||
|
|
||||||
TUPLE: lexer text line line-text line-length column ;
|
TUPLE: lexer text line line-text line-length column ;
|
||||||
|
@ -285,13 +284,27 @@ M: no-word-error summary
|
||||||
: CREATE-METHOD ( -- method )
|
: CREATE-METHOD ( -- method )
|
||||||
scan-word bootstrap-word scan-word create-method-in ;
|
scan-word bootstrap-word scan-word create-method-in ;
|
||||||
|
|
||||||
|
: shadowed-slots ( superclass slots -- shadowed )
|
||||||
|
>r all-slot-names r> seq-intersect ;
|
||||||
|
|
||||||
|
: check-slot-shadowing ( class superclass slots -- )
|
||||||
|
shadowed-slots [
|
||||||
|
[
|
||||||
|
"Definition of slot ``" %
|
||||||
|
%
|
||||||
|
"'' in class ``" %
|
||||||
|
word-name %
|
||||||
|
"'' shadows a superclass slot" %
|
||||||
|
] "" make note.
|
||||||
|
] with each ;
|
||||||
|
|
||||||
: parse-tuple-definition ( -- class superclass slots )
|
: parse-tuple-definition ( -- class superclass slots )
|
||||||
CREATE-CLASS
|
CREATE-CLASS
|
||||||
scan {
|
scan {
|
||||||
{ ";" [ tuple f ] }
|
{ ";" [ tuple f ] }
|
||||||
{ "<" [ scan-word ";" parse-tokens ] }
|
{ "<" [ scan-word ";" parse-tokens ] }
|
||||||
[ >r tuple ";" parse-tokens r> prefix ]
|
[ >r tuple ";" parse-tokens r> prefix ]
|
||||||
} case ;
|
} case 3dup check-slot-shadowing ;
|
||||||
|
|
||||||
ERROR: staging-violation word ;
|
ERROR: staging-violation word ;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
USING: arrays kernel math namespaces sequences kernel.private
|
USING: arrays kernel math namespaces sequences kernel.private
|
||||||
sequences.private strings sbufs tools.test vectors bit-arrays
|
sequences.private strings sbufs tools.test vectors bit-arrays
|
||||||
generic ;
|
generic vocabs.loader ;
|
||||||
IN: sequences.tests
|
IN: sequences.tests
|
||||||
|
|
||||||
[ V{ 1 2 3 4 } ] [ 1 5 dup <slice> >vector ] unit-test
|
[ V{ 1 2 3 4 } ] [ 1 5 dup <slice> >vector ] unit-test
|
||||||
|
@ -100,6 +100,16 @@ unit-test
|
||||||
[ [ ] ] [ [ 1 2 3 ] 3 tail ] unit-test
|
[ [ ] ] [ [ 1 2 3 ] 3 tail ] unit-test
|
||||||
[ [ 3 ] ] [ [ 1 2 3 ] 2 tail ] unit-test
|
[ [ 3 ] ] [ [ 1 2 3 ] 2 tail ] unit-test
|
||||||
|
|
||||||
|
[ "blah" ] [ "blahxx" 2 head* ] unit-test
|
||||||
|
|
||||||
|
[ "xx" ] [ "blahxx" 2 tail* ] unit-test
|
||||||
|
|
||||||
|
[ t ] [ "xxfoo" 2 head-slice "xxbar" 2 head-slice = ] unit-test
|
||||||
|
[ t ] [ "xxfoo" 2 head-slice "xxbar" 2 head-slice [ hashcode ] bi@ = ] unit-test
|
||||||
|
|
||||||
|
[ t ] [ "xxfoo" 2 head-slice SBUF" barxx" 2 tail-slice* = ] unit-test
|
||||||
|
[ t ] [ "xxfoo" 2 head-slice SBUF" barxx" 2 tail-slice* [ hashcode ] bi@ = ] unit-test
|
||||||
|
|
||||||
[ t ] [ [ 1 2 3 ] [ 1 2 3 ] sequence= ] unit-test
|
[ t ] [ [ 1 2 3 ] [ 1 2 3 ] sequence= ] unit-test
|
||||||
[ t ] [ [ 1 2 3 ] { 1 2 3 } sequence= ] unit-test
|
[ t ] [ [ 1 2 3 ] { 1 2 3 } sequence= ] unit-test
|
||||||
[ t ] [ { 1 2 3 } [ 1 2 3 ] sequence= ] unit-test
|
[ t ] [ { 1 2 3 } [ 1 2 3 ] sequence= ] unit-test
|
||||||
|
@ -195,6 +205,12 @@ unit-test
|
||||||
! Pathological case
|
! Pathological case
|
||||||
[ "ihbye" ] [ "hi" <reversed> "bye" append ] unit-test
|
[ "ihbye" ] [ "hi" <reversed> "bye" append ] unit-test
|
||||||
|
|
||||||
|
[ t ] [ "hi" <reversed> SBUF" hi" <reversed> = ] unit-test
|
||||||
|
|
||||||
|
[ t ] [ "hi" <reversed> SBUF" hi" <reversed> = ] unit-test
|
||||||
|
|
||||||
|
[ t ] [ "hi" <reversed> SBUF" hi" <reversed> [ hashcode ] bi@ = ] unit-test
|
||||||
|
|
||||||
[ -10 "hi" "bye" copy ] must-fail
|
[ -10 "hi" "bye" copy ] must-fail
|
||||||
[ 10 "hi" "bye" copy ] must-fail
|
[ 10 "hi" "bye" copy ] must-fail
|
||||||
|
|
||||||
|
@ -244,3 +260,5 @@ unit-test
|
||||||
[ "asdf " ] [ " asdf " [ CHAR: \s = ] left-trim ] unit-test
|
[ "asdf " ] [ " asdf " [ CHAR: \s = ] left-trim ] unit-test
|
||||||
[ " asdf" ] [ " asdf " [ CHAR: \s = ] right-trim ] unit-test
|
[ " asdf" ] [ " asdf " [ CHAR: \s = ] right-trim ] unit-test
|
||||||
|
|
||||||
|
! Hardcore
|
||||||
|
[ ] [ "sequences" reload ] unit-test
|
||||||
|
|
|
@ -172,7 +172,9 @@ TUPLE: reversed seq ;
|
||||||
C: <reversed> reversed
|
C: <reversed> reversed
|
||||||
|
|
||||||
M: reversed virtual-seq reversed-seq ;
|
M: reversed virtual-seq reversed-seq ;
|
||||||
|
|
||||||
M: reversed virtual@ reversed-seq [ length swap - 1- ] keep ;
|
M: reversed virtual@ reversed-seq [ length swap - 1- ] keep ;
|
||||||
|
|
||||||
M: reversed length reversed-seq length ;
|
M: reversed length reversed-seq length ;
|
||||||
|
|
||||||
INSTANCE: reversed virtual-sequence
|
INSTANCE: reversed virtual-sequence
|
||||||
|
@ -198,7 +200,9 @@ ERROR: slice-error reason ;
|
||||||
slice construct-boa ; inline
|
slice construct-boa ; inline
|
||||||
|
|
||||||
M: slice virtual-seq slice-seq ;
|
M: slice virtual-seq slice-seq ;
|
||||||
|
|
||||||
M: slice virtual@ [ slice-from + ] keep slice-seq ;
|
M: slice virtual@ [ slice-from + ] keep slice-seq ;
|
||||||
|
|
||||||
M: slice length dup slice-to swap slice-from - ;
|
M: slice length dup slice-to swap slice-from - ;
|
||||||
|
|
||||||
: head-slice ( seq n -- slice ) (head) <slice> ;
|
: head-slice ( seq n -- slice ) (head) <slice> ;
|
||||||
|
@ -466,6 +470,21 @@ M: sequence <=>
|
||||||
2dup [ length ] bi@ number=
|
2dup [ length ] bi@ number=
|
||||||
[ mismatch not ] [ 2drop f ] if ; inline
|
[ mismatch not ] [ 2drop f ] if ; inline
|
||||||
|
|
||||||
|
: sequence-hashcode-step ( oldhash newpart -- newhash )
|
||||||
|
swap [
|
||||||
|
dup -2 fixnum-shift-fast swap 5 fixnum-shift-fast
|
||||||
|
fixnum+fast fixnum+fast
|
||||||
|
] keep fixnum-bitxor ; inline
|
||||||
|
|
||||||
|
: sequence-hashcode ( n seq -- x )
|
||||||
|
0 -rot [
|
||||||
|
hashcode* >fixnum sequence-hashcode-step
|
||||||
|
] with each ; inline
|
||||||
|
|
||||||
|
M: reversed equal? over reversed? [ sequence= ] [ 2drop f ] if ;
|
||||||
|
|
||||||
|
M: slice equal? over slice? [ sequence= ] [ 2drop f ] if ;
|
||||||
|
|
||||||
: move ( to from seq -- )
|
: move ( to from seq -- )
|
||||||
2over number=
|
2over number=
|
||||||
[ 3drop ] [ [ nth swap ] keep set-nth ] if ; inline
|
[ 3drop ] [ [ nth swap ] keep set-nth ] if ; inline
|
||||||
|
@ -692,14 +711,3 @@ PRIVATE>
|
||||||
dup [ length ] map infimum
|
dup [ length ] map infimum
|
||||||
[ <column> dup like ] with map
|
[ <column> dup like ] with map
|
||||||
] unless ;
|
] unless ;
|
||||||
|
|
||||||
: sequence-hashcode-step ( oldhash newpart -- newhash )
|
|
||||||
swap [
|
|
||||||
dup -2 fixnum-shift-fast swap 5 fixnum-shift-fast
|
|
||||||
fixnum+fast fixnum+fast
|
|
||||||
] keep fixnum-bitxor ; inline
|
|
||||||
|
|
||||||
: sequence-hashcode ( n seq -- x )
|
|
||||||
0 -rot [
|
|
||||||
hashcode* >fixnum sequence-hashcode-step
|
|
||||||
] with each ; inline
|
|
||||||
|
|
Loading…
Reference in New Issue