]> gitweb.factorcode.org Git - factor.git/commitdiff
More tuple declaration work
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Mon, 30 Jun 2008 02:37:57 +0000 (21:37 -0500)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Mon, 30 Jun 2008 02:37:57 +0000 (21:37 -0500)
24 files changed:
core/bootstrap/primitives.factor
core/byte-vectors/byte-vectors.factor
core/classes/tuple/parser/parser-tests.factor
core/classes/tuple/parser/parser.factor
core/generic/generic.factor
core/grouping/grouping.factor
core/hashtables/hashtables.factor
core/inference/class/class-tests.factor
core/inspector/inspector.factor
core/mirrors/mirrors-tests.factor
core/optimizer/inlining/inlining.factor
core/prettyprint/prettyprint-tests.factor
core/prettyprint/prettyprint.factor
core/sbufs/sbufs.factor
core/sequences/sequences.factor
core/slots/deprecated/deprecated.factor
core/slots/slots-docs.factor
core/slots/slots-tests.factor
core/slots/slots.factor
core/vectors/vectors.factor
extra/bit-vectors/bit-vectors.factor
extra/float-vectors/float-vectors.factor
extra/io/buffers/buffers.factor
extra/math/ranges/ranges.factor

index 7a8c8a02c4cec60824dd3656e415626b406c4bb0..07f02491c644b22194ea6bbd44410ec446fd8ad7 100755 (executable)
@@ -67,6 +67,7 @@ bootstrapping? on
     "classes.private"
     "classes.tuple"
     "classes.tuple.private"
+    "classes.predicate"
     "compiler.units"
     "continuations.private"
     "float-arrays"
@@ -117,7 +118,7 @@ bootstrapping? on
     tri ;
 
 : prepare-slots ( slots -- slots' )
-    [ [ dup array? [ first2 create ] when ] map ] map ;
+    [ [ dup pair? [ first2 create ] when ] map ] map ;
 
 : define-builtin-slots ( class slots -- )
     prepare-slots 1 make-slots
@@ -147,6 +148,9 @@ bootstrapping? on
 "byte-array" "byte-arrays" create register-builtin
 "tuple-layout" "classes.tuple.private" create register-builtin
 
+! For predicate classes
+"predicate-instance?" "classes.predicate" create drop
+
 ! We need this before defining c-ptr below
 "f" "syntax" lookup { } define-builtin
 
@@ -256,7 +260,7 @@ define-builtin
     { "hashcode" { "fixnum" "math" } }
     "name"
     "vocabulary"
-    { "def" { "quotation" "quotations" } }
+    { "def" { "quotation" "quotations" } initial: [ ] }
     "props"
     { "compiled" read-only: t }
     { "counter" { "fixnum" "math" } }
@@ -272,9 +276,9 @@ define-builtin
 
 "tuple-layout" "classes.tuple.private" create {
     { "hashcode" { "fixnum" "math" } read-only: t }
-    { "class" { "word" "words" } read-only: t }
+    { "class" { "word" "words" } initial: t read-only: t }
     { "size" { "fixnum" "math" } read-only: t }
-    { "superclasses" { "array" "arrays" } read-only: t }
+    { "superclasses" { "array" "arrays" } initial: { } read-only: t }
     { "echelon" { "fixnum" "math" } read-only: t }
 } define-builtin
 
index 5560454b3a279c10964d2022db970abae643062f..4fb51f133d5181e2ba25b9e6a1a86d25e99316be 100755 (executable)
@@ -5,8 +5,8 @@ sequences.private growable byte-arrays ;
 IN: byte-vectors\r
 \r
 TUPLE: byte-vector\r
-{ "underlying" byte-array }\r
-{ "length" array-capacity } ;\r
+{ underlying byte-array }\r
+{ length array-capacity } ;\r
 \r
 <PRIVATE\r
 \r
index b5bfd5c29384cec09456fe220bae7a7aaa893626..b54c1501fb09e6d90ba0953258cb290f03da9ea7 100644 (file)
@@ -21,21 +21,21 @@ TUPLE: test-4 < test-3 b ;
 
 [ { "b" } ] [ test-4 "slot-names" word-prop ] unit-test
 
-TUPLE: test-5 { "a" integer } ;
+TUPLE: test-5 { a integer } ;
 
 [ { { "a" integer } } ] [ test-5 "slot-names" word-prop ] unit-test
 
-TUPLE: test-6 < test-5 { "b" integer } ;
+TUPLE: test-6 < test-5 { b integer } ;
 
 [ integer ] [ "b" test-6 "slots" word-prop slot-named class>> ] unit-test
 
 [ { { "b" integer } } ] [ test-6 "slot-names" word-prop ] unit-test
 
-TUPLE: test-7 { "b" integer initial: 3 } ;
+TUPLE: test-7 { b integer initial: 3 } ;
 
 [ 3 ] [ "b" test-7 "slots" word-prop slot-named initial>> ] unit-test
 
-TUPLE: test-8 { "b" integer read-only: t } ;
+TUPLE: test-8 { b integer read-only: t } ;
 
 [ t ] [ "b" test-8 "slots" word-prop slot-named read-only>> ] unit-test
 
@@ -51,11 +51,11 @@ must-fail-with
 [ error>> unexpected-eof? ]
 must-fail-with
 
-[ "IN: classes.tuple.parser.tests USE: alien TUPLE: foo { \"slot\" alien } ;" eval ]
+[ "IN: classes.tuple.parser.tests USE: alien TUPLE: foo { slot alien } ;" eval ]
 [ error>> no-initial-value? ]
 must-fail-with
 
-[ "IN: classes.tuple.parser.tests USE: arrays TUPLE: foo { \"slot\" array initial: 5 } ;" eval ]
+[ "IN: classes.tuple.parser.tests USE: arrays TUPLE: foo { slot array initial: 5 } ;" eval ]
 [ error>> bad-initial-value? ]
 must-fail-with
 
index a4bea6fed2e69c282c03d948e35d134451ac5c9f..260730383b978b78a62631b1a65fce6d1720d70b 100644 (file)
@@ -24,6 +24,9 @@ M: invalid-slot-name summary
     drop
     "Invalid slot name" ;
 
+: parse-long-slot-name ( -- )
+    [ scan , \ } parse-until % ] { } make ;
+
 : parse-slot-name ( string/f -- ? )
     #! This isn't meant to enforce any kind of policy, just
     #! to check for mistakes of this form:
@@ -35,7 +38,7 @@ M: invalid-slot-name summary
         { [ dup not ] [ unexpected-eof ] }
         { [ dup { ":" "(" "<" "\"" } member? ] [ invalid-slot-name ] }
         { [ dup ";" = ] [ drop f ] }
-        [ dup "{" = [ drop \ } parse-until >array ] when , t ]
+        [ dup "{" = [ drop parse-long-slot-name ] when , t ]
     } cond ;
 
 : parse-tuple-slots ( -- )
index b9ef634a9ecbd47c29c069d33b730f977a5d10e5..3aecd4825e344b272174290fe136c7305910dfc1 100755 (executable)
@@ -33,7 +33,7 @@ PREDICATE: method-spec < pair
 : specific-method ( class generic -- method/f )
     tuck order min-class dup [ swap method ] [ 2drop f ] if ;
 
-GENERIC: effective-method ( ... generic -- method )
+GENERIC: effective-method ( generic -- method )
 
 : next-method-class ( class generic -- class/f )
     order [ class<= ] with filter reverse dup length 1 =
index caf46e5480f8671d8d29bc62bac4c05cf33bca5d..cc307bd387daf51cdcca5183812c81650ce51509 100644 (file)
@@ -4,7 +4,7 @@ USING: kernel math math.order strings arrays vectors sequences
 accessors ;
 IN: grouping
 
-TUPLE: abstract-groups seq n ;
+TUPLE: abstract-groups { seq read-only: t } { n read-only: t } ;
 
 : check-groups dup 0 <= [ "Invalid group count" throw ] when ; inline
 
index e991be5ab3a73c5f86960104c0bc6893f87708d2..3b794d1715c10528a0f63aac586229901b3cd278 100755 (executable)
@@ -5,9 +5,9 @@ assocs math.private sequences sequences.private vectors grouping ;
 IN: hashtables
 
 TUPLE: hashtable
-{ "count" array-capacity }
-{ "deleted" array-capacity }
-{ "array" array } ;
+{ count array-capacity }
+{ deleted array-capacity }
+{ array array } ;
 
 <PRIVATE
 
index c2c69ddbd73fc30e3b20606733d7bb6ee36dfcb0..ba1e3d89a3edb4dac29baa0f126b8cbd59af7c0e 100755 (executable)
@@ -579,13 +579,18 @@ M: integer detect-integer ;
     [ hashtable instance? ] \ instance? inlined?
 ] unit-test
 
-TUPLE: declared-fixnum { "x" fixnum } ;
+TUPLE: declared-fixnum { x fixnum } ;
 
 [ t ] [
     [ { declared-fixnum } declare [ 1 + ] change-x ]
     { + fixnum+ >fixnum } inlined?
 ] unit-test
 
+[ t ] [
+    [ { declared-fixnum } declare x>> drop ]
+    { slot } inlined?
+] unit-test
+
 ! Later
 
 ! [ t ] [
index 07c189cea0f3f075577387904cb03a5c059dd70f..51d3cb319d613b0635e9f8bbcecaac6fd8d07892 100755 (executable)
@@ -79,11 +79,11 @@ SYMBOL: +editable+
 : summary. ( obj -- ) [ summary ] keep write-object nl ;
 
 : sorted-keys ( assoc -- alist )
-    dup mirror? [ keys ] [
+    dup hashtable? [
         keys
         [ [ unparse-short ] keep ] { } map>assoc
         sort-keys values
-    ] if ;
+    ] [ keys ] if ;
 
 : describe* ( obj flags -- )
     clone [
index 3145ce8b9ff98cc50e6a3a9eb0da341c503e5f14..0a30392281061161b5b3fad9c71f387a87088437 100755 (executable)
@@ -31,7 +31,7 @@ C: <foo> foo
 [ gensym <mirror> [ "compiled" off ] bind ] must-fail
 
 TUPLE: declared-mirror-test
-{ "a" integer initial: 0 } ;
+{ a integer initial: 0 } ;
 
 [ 5 ] [
     3 declared-mirror-test boa <mirror> [
@@ -43,9 +43,9 @@ TUPLE: declared-mirror-test
 [ 3 declared-mirror-test boa <mirror> [ t "a" set ] bind ] must-fail
 
 TUPLE: color
-{ "red" integer }
-{ "green" integer }
-{ "blue" integer } ;
+{ red integer }
+{ green integer }
+{ blue integer } ;
 
 [ T{ color f 0 0 0 } ] [
     1 2 3 color boa [ <mirror> clear-assoc ] keep
index c2a59f639e8320e814770446fbdcf943e58c58bc..e741f2d17188ef4e61e53678755ecb55818d91ee 100755 (executable)
@@ -54,11 +54,15 @@ DEFER: (flat-length)
     [ def>> (flat-length) ] with-scope ;
 
 ! Single dispatch method inlining optimization
+! : dispatching-class ( node generic -- method/f )
+!     tuck dispatch# over in-d>> <reversed> ?nth 2dup node-literal?
+!     [ node-literal swap single-effective-method ]
+!     [ node-class swap specific-method ]
+!     if ;
+
 : dispatching-class ( node generic -- method/f )
-    tuck dispatch# over in-d>> <reversed> ?nth 2dup node-literal?
-    [ node-literal swap single-effective-method ]
-    [ node-class swap specific-method ]
-    if ;
+    tuck dispatch# over in-d>> <reversed> ?nth
+    node-class swap specific-method ;
 
 : inline-standard-method ( node generic -- node )
     dupd dispatching-class dup
index 9e11611f5b53407cc6702c31129f829624d82876..fd76b87dbb216cdd6d427340c672f7abe1f74c5a 100755 (executable)
@@ -101,11 +101,20 @@ unit-test
         ] keep =
     ] with-scope ;
 
-: method-test
+GENERIC: method-layout
+
+M: complex method-layout
+    "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+    ;
+
+M: fixnum method-layout ;
+
+M: integer method-layout ;
+
+M: object method-layout ;
+
+[
     {
-        "IN: prettyprint.tests"
-        "GENERIC: method-layout"
-        ""
         "USING: math prettyprint.tests ;"
         "M: complex method-layout"
         "    \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\""
@@ -119,10 +128,10 @@ unit-test
         ""
         "USING: kernel prettyprint.tests ;"
         "M: object method-layout ;"
-    } ;
-
-[ t ] [
-    "method-layout" method-test check-see
+        ""
+    }
+] [
+    [ \ method-layout see-methods ] with-string-writer "\n" split
 ] unit-test
 
 : retain-stack-test
@@ -255,7 +264,16 @@ DEFER: parse-error-file
     "another-narrow-layout" another-narrow-test check-see
 ] unit-test
 
-: class-see-test
+IN: prettyprint.tests
+TUPLE: class-see-layout ;
+
+IN: prettyprint.tests
+GENERIC: class-see-layout ( x -- y )
+
+USING: prettyprint.tests ;
+M: class-see-layout class-see-layout ;
+
+[
     {
         "IN: prettyprint.tests"
         "TUPLE: class-see-layout ;"
@@ -263,12 +281,19 @@ DEFER: parse-error-file
         "IN: prettyprint.tests"
         "GENERIC: class-see-layout ( x -- y )"
         ""
+    }
+] [
+    [ \ class-see-layout see ] with-string-writer "\n" split
+] unit-test
+
+[
+    {
         "USING: prettyprint.tests ;"
         "M: class-see-layout class-see-layout ;"
-    } ;
-
-[ t ] [
-    "class-see-layout" class-see-test check-see
+        ""
+    }
+] [
+    [ \ class-see-layout see-methods ] with-string-writer "\n" split
 ] unit-test
 
 [ ] [ \ effect-in synopsis drop ] unit-test
index 6006d9d19f3d319448b849095461ba0245457e80..f15106d78b7784eb7306d320719b35767fa42ac9 100755 (executable)
@@ -268,13 +268,22 @@ M: predicate-class see-class*
 M: singleton-class see-class* ( class -- )
     \ SINGLETON: pprint-word pprint-word ;
 
+GENERIC: pprint-slot-name ( object -- )
+
+M: string pprint-slot-name text ;
+
+M: array pprint-slot-name
+    <flow \ { pprint-word
+    f <inset unclip text pprint-elements block>
+    \ } pprint-word block> ;
+
 M: tuple-class see-class*
     <colon \ TUPLE: pprint-word
     dup pprint-word
     dup superclass tuple eq? [
         "<" text dup superclass pprint-word
     ] unless
-    slot-names [ dup string? [ text ] [ pprint* ] if ] each
+    <block slot-names [ pprint-slot-name ] each block>
     pprint-; block> ;
 
 M: word see-class* drop ;
@@ -282,14 +291,6 @@ M: word see-class* drop ;
 M: builtin-class see-class*
     drop "! Built-in class" comment. ;
 
-: see-all ( seq -- )
-    natural-sort [ nl see ] each ;
-
-: see-implementors ( class -- seq )
-    dup implementors
-    [ method ] with map
-    natural-sort ;
-
 : see-class ( class -- )
     dup class? [
         [
@@ -297,9 +298,6 @@ M: builtin-class see-class*
         ] with-use nl
     ] when drop ;
 
-: see-methods ( generic -- seq )
-    "methods" word-prop values natural-sort ;
-
 M: word see
     dup see-class
     dup class? over symbol? not and [
@@ -308,8 +306,20 @@ M: word see
     dup class? over symbol? and not [
         [ dup (see) ] with-use nl
     ] when
+    drop ;
+
+: see-all ( seq -- )
+    natural-sort [ nl ] [ see ] interleave ;
+
+: (see-implementors) ( class -- seq )
+    dup implementors [ method ] with map natural-sort ;
+
+: (see-methods) ( generic -- seq )
+    "methods" word-prop values natural-sort ;
+
+: see-methods ( word -- )
     [
-        dup class? [ dup see-implementors % ] when
-        dup generic? [ dup see-methods % ] when
+        dup class? [ dup (see-implementors) % ] when
+        dup generic? [ dup (see-methods) % ] when
         drop
     ] { } make prune see-all ;
index 113d5eabe40d401bffed503919dcc3e13daeaab4..1bef47e7594174a0d8595de661a0d346c9a128bb 100755 (executable)
@@ -5,8 +5,8 @@ strings growable strings.private ;
 IN: sbufs
 
 TUPLE: sbuf
-{ "underlying" string }
-{ "length" array-capacity } ;
+{ underlying string }
+{ length array-capacity } ;
 
 <PRIVATE
 
index a610cda59a4ce19f1d4ada32f512e30b27755a7e..16d409741636325dc203c310901812d2ad2e1346 100755 (executable)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2005, 2008 Slava Pestov, Daniel Ehrenberg.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel kernel.private slots.private math math.private
-math.order ;
+USING: accessors kernel kernel.private slots.private math
+math.private math.order ;
 IN: sequences
 
 MIXIN: sequence
@@ -161,25 +161,28 @@ M: virtual-sequence new-sequence virtual-seq new-sequence ;
 INSTANCE: virtual-sequence sequence
 
 ! A reversal of an underlying sequence.
-TUPLE: reversed seq ;
+TUPLE: reversed { seq read-only: t } ;
 
 C: <reversed> reversed
 
-M: reversed virtual-seq reversed-seq ;
+M: reversed virtual-seq seq>> ;
 
-M: reversed virtual@ reversed-seq [ length swap - 1- ] keep ;
+M: reversed virtual@ seq>> [ length swap - 1- ] keep ;
 
-M: reversed length reversed-seq length ;
+M: reversed length seq>> length ;
 
 INSTANCE: reversed virtual-sequence
 
 : reverse ( seq -- newseq ) [ <reversed> ] [ like ] bi ;
 
 ! A slice of another sequence.
-TUPLE: slice from to seq ;
+TUPLE: slice
+{ from read-only: t }
+{ to read-only: t }
+{ seq read-only: t } ;
 
 : collapse-slice ( m n slice -- m' n' seq )
-    dup slice-from swap slice-seq >r tuck + >r + r> r> ; inline
+    [ from>> ] [ seq>> ] bi >r tuck + >r + r> r> ; inline
 
 ERROR: slice-error reason ;
 
@@ -193,11 +196,11 @@ ERROR: slice-error reason ;
     check-slice
     slice boa ; inline
 
-M: slice virtual-seq slice-seq ;
+M: slice virtual-seq seq>> ;
 
-M: slice virtual@ [ slice-from + ] [ slice-seq ] bi ;
+M: slice virtual@ [ from>> + ] [ seq>> ] bi ;
 
-M: slice length dup slice-to swap slice-from - ;
+M: slice length [ to>> ] [ from>> ] bi - ;
 
 : short ( seq n -- seq n' ) over length min ; inline
 
@@ -216,12 +219,12 @@ M: slice length dup slice-to swap slice-from - ;
 INSTANCE: slice virtual-sequence
 
 ! One element repeated many times
-TUPLE: repetition len elt ;
+TUPLE: repetition { len read-only: t } { elt read-only: t } ;
 
 C: <repetition> repetition
 
-M: repetition length repetition-len ;
-M: repetition nth-unsafe nip repetition-elt ;
+M: repetition length len>> ;
+M: repetition nth-unsafe nip elt>> ;
 
 INSTANCE: repetition immutable-sequence
 
index d47ef7b9bbe66016fa141a0167effc18af3ec8fb..fd9796e664122c0169536051a4e69f53c222b687 100755 (executable)
@@ -16,12 +16,17 @@ PREDICATE: slot-reader < word "reading" word-prop >boolean ;
     swap "declared-effect" set-word-prop\r
     slot-spec-reader swap "reading" set-word-prop ;\r
 \r
+: define-slot-word ( class word quot -- )\r
+    [\r
+        dup define-simple-generic\r
+        create-method\r
+    ] dip define ;\r
+\r
 : define-reader ( class spec -- )\r
     dup slot-spec-reader [\r
         [ set-reader-props ] 2keep\r
-        dup slot-spec-offset\r
-        over slot-spec-reader\r
-        rot slot-spec-class reader-quot\r
+        dup slot-spec-reader\r
+        swap reader-quot\r
         define-slot-word\r
     ] [\r
         2drop\r
@@ -41,9 +46,8 @@ PREDICATE: slot-writer < word "writing" word-prop >boolean ;
 : define-writer ( class spec -- )\r
     dup slot-spec-writer [\r
         [ set-writer-props ] 2keep\r
-        dup slot-spec-offset\r
-        swap slot-spec-writer\r
-        [ set-slot ]\r
+        dup slot-spec-writer\r
+        swap writer-quot\r
         define-slot-word\r
     ] [\r
         2drop\r
index 2b9631695af851b49c81af80136ec652b13aa90d..32b3bc2ecb6706157e6e000912acd597823db305 100755 (executable)
@@ -113,11 +113,6 @@ HELP: define-typecheck
 }
 { $notes "This word is used internally to wrap unsafe low-level code in a type-checking stub." } ;
 
-HELP: define-slot-word
-{ $values { "class" class } { "slot" "a positive integer" } { "word" word } { "quot" quotation } }
-{ $description "Defines " { $snippet "word" } " to be a simple type-checking generic word that receives the slot number on the stack as a fixnum." }
-$low-level-note ;
-
 HELP: define-reader
 { $values { "class" class } { "name" string } { "slot" integer } }
 { $description "Defines a reader word to read a slot from instances of " { $snippet "class" } "." }
index 16196bf844696ec0baa7972db006e8897d4a4176..61cec47c94d52db749348776fa432e92f3450b85 100644 (file)
@@ -1,13 +1,14 @@
 IN: slots.tests
-USING: math accessors slots strings generic.standard kernel tools.test ;
+USING: math accessors slots strings generic.standard kernel
+tools.test generic words parser ;
 
 TUPLE: r/w-test foo ;
 
-TUPLE: r/o-test { "foo" read-only: t } ;
+TUPLE: r/o-test { foo read-only: t } ;
 
 [ r/o-test new 123 >>foo ] [ no-method? ] must-fail-with
 
-TUPLE: decl-test { "foo" integer } ;
+TUPLE: decl-test { foo integer } ;
 
 [ decl-test new 1.0 >>foo ] [ bad-slot-value? ] must-fail-with
 
@@ -16,3 +17,20 @@ TUPLE: hello length ;
 [ 3 ] [ "xyz" length>> ] unit-test
 
 [ "xyz" 4 >>length ] [ no-method? ] must-fail-with
+
+[ t ] [ r/o-test \ foo>> method "foldable" word-prop ] unit-test
+[ t ] [ r/o-test \ foo>> method "flushable" word-prop ] unit-test
+
+[ f ] [ r/w-test \ foo>> method "foldable" word-prop ] unit-test
+[ t ] [ r/w-test \ foo>> method "flushable" word-prop ] unit-test
+
+! See if declarations are cleared on redefinition
+[ ] [ "IN: slots.tests TUPLE: r/w-test { foo read-only: t } ;" eval ] unit-test
+
+[ t ] [ r/w-test \ foo>> method "foldable" word-prop ] unit-test
+[ t ] [ r/w-test \ foo>> method "flushable" word-prop ] unit-test
+
+[ ] [ "IN: slots.tests TUPLE: r/w-test { foo read-only: f } ;" eval ] unit-test
+
+[ f ] [ r/w-test \ foo>> method "foldable" word-prop ] unit-test
+[ t ] [ r/w-test \ foo>> method "flushable" word-prop ] unit-test
index f033c18646c9f9636cfd81400d0fb7e994dcf1f5..86f9cba9fed4a854eb7955363b8b55b3a3354273 100755 (executable)
@@ -3,7 +3,7 @@
 USING: arrays bit-arrays byte-arrays float-arrays kernel
 kernel.private math namespaces sequences strings words effects
 generic generic.standard classes classes.algebra slots.private
-combinators accessors words ;
+combinators accessors words sequences.private assocs ;
 IN: slots
 
 TUPLE: slot-spec name offset class initial read-only reader writer ;
@@ -12,69 +12,71 @@ TUPLE: slot-spec name offset class initial read-only reader writer ;
     slot-spec new
         object bootstrap-word >>class ;
 
-: define-typecheck ( class generic quot -- )
-    [
-        dup define-simple-generic
-        create-method
-    ] dip define ;
-
-: define-slot-word ( class offset word quot -- )
-    rot >fixnum prefix define-typecheck ;
+: define-typecheck ( class generic quot props -- )
+    [ dup define-simple-generic create-method ] 2dip
+    [ [ props>> ] [ drop ] [ [ t ] H{ } map>assoc ] tri* update ]
+    [ drop define ]
+    3bi ;
 
 : create-accessor ( name effect -- word )
     >r "accessors" create dup r>
     "declared-effect" set-word-prop ;
 
-: reader-quot ( decl -- quot )
+: reader-quot ( slot-spec -- quot )
     [
+        dup offset>> ,
         \ slot ,
-        dup object bootstrap-word eq?
-        [ drop ] [ 1array , \ declare , ] if
+        dup class>> object bootstrap-word eq?
+        [ drop ] [ class>> 1array , \ declare , ] if
     ] [ ] make ;
 
 : reader-word ( name -- word )
     ">>" append (( object -- value )) create-accessor ;
 
+: reader-props ( slot-spec -- seq )
+    read-only>> { "foldable" "flushable" } { "flushable" } ? ;
+
 : define-reader ( class slot-spec -- )
-    [ offset>> ]
-    [ name>> reader-word ]
-    [ class>> reader-quot ]
-    tri define-slot-word ;
+    [ name>> reader-word ] [ reader-quot ] [ reader-props ] tri
+    define-typecheck ;
 
 : writer-word ( name -- word )
     "(>>" swap ")" 3append (( value object -- )) create-accessor ;
 
 ERROR: bad-slot-value value object index ;
 
-: writer-quot/object ( decl -- )
-    drop \ set-slot , ;
+: writer-quot/object ( slot-spec -- )
+    offset>> , \ set-slot , ;
 
-: writer-quot/coerce ( decl -- )
-    [ rot ] % "coercer" word-prop % [ -rot set-slot ] % ;
+: writer-quot/coerce ( slot-spec -- )
+    [ \ >r , class>> "coercer" word-prop % \ r> , ]
+    [ offset>> , \ set-slot , ]
+    bi ;
 
-: writer-quot/check ( decl -- )
-    \ pick ,
-    "predicate" word-prop %
-    [ [ set-slot ] [ bad-slot-value ] if ] % ;
+: writer-quot/check ( slot-spec -- )
+    [ offset>> , ]
+    [
+        \ pick ,
+        class>> "predicate" word-prop %
+        [ [ set-slot ] [ bad-slot-value ] if ] %
+    ]
+    bi ;
 
-: writer-quot/fixnum ( decl -- )
-    [ rot >fixnum -rot ] % writer-quot/check ;
+: writer-quot/fixnum ( slot-spec -- )
+    [ >r >fixnum r> ] % writer-quot/check ;
 
-: writer-quot ( decl -- quot )
+: writer-quot ( slot-spec -- quot )
     [
         {
-            { [ dup object bootstrap-word eq? ] [ writer-quot/object ] }
-            { [ dup "coercer" word-prop ] [ writer-quot/coerce ] }
-            { [ dup fixnum class<= ] [ writer-quot/fixnum ] }
+            { [ dup class>> object bootstrap-word eq? ] [ writer-quot/object ] }
+            { [ dup class>> "coercer" word-prop ] [ writer-quot/coerce ] }
+            { [ dup class>> fixnum bootstrap-word class<= ] [ writer-quot/fixnum ] }
             [ writer-quot/check ]
         } cond
     ] [ ] make ;
 
 : define-writer ( class slot-spec -- )
-    [ offset>> ]
-    [ name>> writer-word ]
-    [ class>> writer-quot ]
-    tri define-slot-word ;
+    [ name>> writer-word ] [ writer-quot ] bi { } define-typecheck ;
 
 : setter-word ( name -- word )
     ">>" prepend (( object value -- object )) create-accessor ;
@@ -123,13 +125,14 @@ ERROR: no-initial-value class ;
 
 : initial-value ( class -- object )
     {
-        { [ \ f over class<= ] [ f ] }
-        { [ fixnum over class<= ] [ 0 ] }
-        { [ float over class<= ] [ 0.0 ] }
-        { [ array over class<= ] [ { } ] }
-        { [ bit-array over class<= ] [ ?{ } ] }
-        { [ byte-array over class<= ] [ B{ } ] }
-        { [ float-array over class<= ] [ F{ } ] }
+        { [ \ f bootstrap-word over class<= ] [ f ] }
+        { [ \ array-capacity bootstrap-word over class<= ] [ 0 ] }
+        { [ float bootstrap-word over class<= ] [ 0.0 ] }
+        { [ string bootstrap-word over class<= ] [ "" ] }
+        { [ array bootstrap-word over class<= ] [ { } ] }
+        { [ bit-array bootstrap-word over class<= ] [ ?{ } ] }
+        { [ byte-array bootstrap-word over class<= ] [ B{ } ] }
+        { [ float-array bootstrap-word over class<= ] [ F{ } ] }
         [ no-initial-value ]
     } cond nip ;
 
@@ -164,8 +167,10 @@ ERROR: bad-initial-value name ;
 
 : check-initial-value ( slot-spec -- slot-spec )
     dup initial>> [
-        dup [ initial>> ] [ class>> ] bi instance?
-        [ name>> bad-initial-value ] unless
+        [ ] [
+            dup [ initial>> ] [ class>> ] bi instance?
+            [ name>> bad-initial-value ] unless
+        ] if-bootstrapping
     ] [
         dup class>> initial-value >>initial
     ] if ;
index b54b2bc91a8cacf3a4e9674bc0faa99f76478bd9..fa900af69a5bd54ebdcd9b8f507cc4501bc75b84 100755 (executable)
@@ -4,8 +4,8 @@ USING: arrays kernel math sequences sequences.private growable ;
 IN: vectors
 
 TUPLE: vector
-{ "underlying" array }
-{ "length" array-capacity } ;
+{ underlying array }
+{ length array-capacity } ;
 
 <PRIVATE
 
index a9bee0c2acb6ba6799a948194bea9176ea9d53b1..77c1b4574898c1a717afc028fe401a81e34c51f6 100755 (executable)
@@ -6,8 +6,8 @@ parser accessors ;
 IN: bit-vectors\r
 \r
 TUPLE: bit-vector\r
-{ "underlying" bit-array }\r
-{ "length" array-capacity } ;\r
+{ underlying bit-array }\r
+{ length array-capacity } ;\r
 \r
 <PRIVATE\r
 \r
index 293c20c8b5220e50d8374118c208ebd300b98425..fee897e9a46f84cea5aac90c7560aa0e91c14c51 100755 (executable)
@@ -6,8 +6,8 @@ parser accessors ;
 IN: float-vectors\r
 \r
 TUPLE: float-vector\r
-{ "underlying" float-array }\r
-{ "length" array-capacity } ;\r
+{ underlying float-array }\r
+{ length array-capacity } ;\r
 \r
 <PRIVATE\r
 \r
index 3627a764ba5d659713809a673f0d7ab285ca4138..2683c314d8584ddb29f0db489f3aef783bcecf59 100755 (executable)
@@ -7,10 +7,10 @@ hints accessors math.order destructors combinators ;
 IN: io.buffers
 
 TUPLE: buffer
-{ "size" fixnum }
-{ "ptr" simple-alien }
-{ "fill" fixnum }
-{ "pos" fixnum }
+{ size fixnum }
+{ ptr simple-alien initial: ALIEN: -1 }
+{ fill fixnum }
+{ pos fixnum }
 disposed ;
 
 : <buffer> ( n -- buffer )
index eb2623296916bd6bfa0e8c41fc770ea7b405a078..955d1b259691f5b7393228a2e9f15272546cd525 100755 (executable)
@@ -2,7 +2,10 @@ USING: kernel layouts math math.order namespaces sequences
 sequences.private accessors ;
 IN: math.ranges
 
-TUPLE: range from length step ;
+TUPLE: range
+{ from read-only: t }
+{ length read-only: t }
+{ step read-only: t } ;
 
 : <range> ( a b step -- range )
     >r over - r>
@@ -23,19 +26,19 @@ INSTANCE: range immutable-sequence
 
 : ,b) dup neg rot + swap ; inline
 
-: [a,b] ( a b -- range ) twiddle <range> ;
+: [a,b] ( a b -- range ) twiddle <range> ; foldable
 
-: (a,b] ( a b -- range ) twiddle (a, <range> ;
+: (a,b] ( a b -- range ) twiddle (a, <range> ; foldable
 
-: [a,b) ( a b -- range ) twiddle ,b) <range> ;
+: [a,b) ( a b -- range ) twiddle ,b) <range> ; foldable
 
-: (a,b) ( a b -- range ) twiddle (a, ,b) <range> ;
+: (a,b) ( a b -- range ) twiddle (a, ,b) <range> ; foldable
 
-: [0,b] ( b -- range ) 0 swap [a,b] ;
+: [0,b] ( b -- range ) 0 swap [a,b] ; foldable
 
-: [1,b] ( b -- range ) 1 swap [a,b] ;
+: [1,b] ( b -- range ) 1 swap [a,b] ; foldable
 
-: [0,b) ( b -- range ) 0 swap [a,b) ;
+: [0,b) ( b -- range ) 0 swap [a,b) ; foldable
 
 : range-increasing? ( range -- ? )
     step>> 0 > ;