]> gitweb.factorcode.org Git - factor.git/commitdiff
hashtables: Enforce shape on hashtable literals. Fixes #568.
authorDoug Coleman <doug.coleman@gmail.com>
Fri, 24 Aug 2012 22:00:33 +0000 (15:00 -0700)
committerDoug Coleman <doug.coleman@gmail.com>
Fri, 24 Aug 2012 22:11:03 +0000 (15:11 -0700)
core/hashtables/hashtables.factor
core/syntax/syntax.factor

index d6fa375dd278f7110ae476aee1ac84b97b5d02dd..ee1fcdefa77445e6a58899891ca3908d82943329 100644 (file)
@@ -181,4 +181,12 @@ M: hashtable assoc-like
     [ hashcode 0x13c6ef37 + ] dip
     [ 6 shift ] [ -2 shift ] bi + + ;
 
+ERROR: malformed-hashtable-pair seq pair ;
+
+: check-hashtable ( seq -- seq )
+    dup [ dup length 2 = [ drop ] [ malformed-hashtable-pair ] if ] each ;
+
+: parse-hashtable ( seq -- hashtable )
+    check-hashtable H{ } assoc-clone-like ;
+
 INSTANCE: hashtable assoc
index e356f8d88e7b7cb3e2bf14c9678322ec0148740c..441a4dfb7dff6895f8576feed0d9f14ef2888237 100644 (file)
@@ -97,7 +97,7 @@ IN: bootstrap.syntax
     "V{" [ \ } [ >vector ] parse-literal ] define-core-syntax
     "B{" [ \ } [ >byte-array ] parse-literal ] define-core-syntax
     "BV{" [ \ } [ >byte-vector ] parse-literal ] define-core-syntax
-    "H{" [ \ } [ >hashtable ] parse-literal ] define-core-syntax
+    "H{" [ \ } [ parse-hashtable ] parse-literal ] define-core-syntax
     "T{" [ parse-tuple-literal suffix! ] define-core-syntax
     "W{" [ \ } [ first <wrapper> ] parse-literal ] define-core-syntax
     "HS{" [ \ } [ >hash-set ] parse-literal ] define-core-syntax