]> gitweb.factorcode.org Git - factor.git/commitdiff
add initial-quot: syntax for tuples
authorDoug Coleman <doug.coleman@gmail.com>
Fri, 12 Jun 2009 00:48:14 +0000 (19:48 -0500)
committerDoug Coleman <doug.coleman@gmail.com>
Fri, 12 Jun 2009 00:48:14 +0000 (19:48 -0500)
core/bootstrap/syntax.factor
core/classes/tuple/parser/parser-tests.factor
core/classes/tuple/tuple.factor
core/slots/slots.factor
core/syntax/syntax.factor

index f5182a02100b548208c4e4355870680eee642b51..24538229c69dc53b93f07133723c84604a74272f 100644 (file)
@@ -80,6 +80,7 @@ IN: bootstrap.syntax
     ">>"
     "call-next-method"
     "initial:"
+    "initial-quot:"
     "read-only"
     "call("
     "execute("
index b95507c78b346a794275b80375055bab7dab4620..88fca567f4abdcb960daa0aaf8b89d9792bb5aa5 100644 (file)
@@ -1,7 +1,7 @@
 IN: classes.tuple.parser.tests
 USING: accessors classes.tuple.parser lexer words classes
 sequences math kernel slots tools.test parser compiler.units
-arrays classes.tuple eval ;
+arrays classes.tuple eval multiline ;
 
 TUPLE: test-1 ;
 
@@ -142,3 +142,17 @@ TUPLE: parsing-corner-case x ;
         "    x 3 }"
     } "\n" join eval( -- tuple )
 ] [ error>> unexpected-eof? ] must-fail-with
+
+
+[ ] [
+    <" USE: sequences
+    IN: classes.tuple.tests
+    TUPLE: book { name initial-quot: [ "Lord of the " "Rings" append ] } ;">
+    eval( -- )
+] unit-test
+
+[ ] [
+    <" IN: classes.tuple.tests
+    TUPLE: monster { hp virtual } ;">
+    eval( -- )
+] unit-test
index 225176f4e5939dfaf10a629a2aa279f800935b40..9e0c0b7316e862ee3583dff0f471bf32fb0423c3 100755 (executable)
@@ -50,8 +50,19 @@ M: tuple class layout-of 2 slot { word } declare ;
 
 PRIVATE>
 
+: initial-value ( slot -- obj )
+    dup initial>> [
+        nip
+    ] [
+        dup initial-quot>> [
+            nip call( -- obj )
+        ] [
+            drop f
+        ] if*
+    ] if* ;
+
 : initial-values ( class -- slots )
-    all-slots [ initial>> ] map ;
+    all-slots [ initial-value ] map ;
 
 : pad-slots ( slots class -- slots' class )
     [ initial-values over length tail append ] keep ; inline
@@ -176,7 +187,7 @@ ERROR: bad-superclass class ;
 : compute-slot-permutation ( new-slots old-slots -- triples )
     [ [ [ name>> ] map ] bi@ [ index ] curry map ]
     [ drop [ class>> ] map ]
-    [ drop [ initial>> ] map ]
+    [ drop [ initial-value ] map ]
     2tri 3array flip ;
 
 : update-slot ( old-values n class initial -- value )
index 304ded0adbb5e836fb05732c9d5f4a8290735604..9db26846d0548d5a4fa6330722fdfcc2d2461b8f 100755 (executable)
@@ -3,10 +3,10 @@
 USING: arrays byte-arrays kernel kernel.private math namespaces
 make sequences strings effects generic generic.standard
 classes classes.algebra slots.private combinators accessors
-words sequences.private assocs alien quotations hashtables ;
+words sequences.private assocs alien quotations hashtables summary ;
 IN: slots
 
-TUPLE: slot-spec name offset class initial read-only ;
+TUPLE: slot-spec name offset class initial initial-quot read-only ;
 
 PREDICATE: reader < word "reader" word-prop ;
 
@@ -190,6 +190,7 @@ ERROR: bad-slot-attribute key ;
     dup empty? [
         unclip {
             { initial: [ [ first >>initial ] [ rest ] bi ] }
+            { initial-quot: [ [ first >>initial-quot ] [ rest ] bi ] }
             { read-only [ [ t >>read-only ] dip ] }
             [ bad-slot-attribute ]
         } case
@@ -197,7 +198,17 @@ ERROR: bad-slot-attribute key ;
 
 ERROR: bad-initial-value name ;
 
+ERROR: duplicate-initial-values slot ;
+
+M: duplicate-initial-values summary
+    drop "Slots can either define initial: or initial-quot:, but not both" ;
+
+: check-duplicate-initial-values ( slot-spec -- slot-spec )
+    dup [ initial>> ] [ initial-quot>> ] bi and
+    [ duplicate-initial-values ] when ;
+
 : check-initial-value ( slot-spec -- slot-spec )
+    check-duplicate-initial-values
     dup initial>> [
         [ ] [
             dup [ initial>> ] [ class>> ] bi instance?
index 56ac9fa36e1ba5880a11d359535a1dd5f8b949f0..8093b6345b6ccf0c53ab73c3140916737587dc62 100644 (file)
@@ -245,7 +245,9 @@ IN: bootstrap.syntax
     ] define-core-syntax
     
     "initial:" "syntax" lookup define-symbol
-    
+
+    "initial-quot:" "syntax" lookup define-symbol
+
     "read-only" "syntax" lookup define-symbol
 
     "call(" [ \ call-effect parse-call( ] define-core-syntax