]> gitweb.factorcode.org Git - factor.git/commitdiff
mirrors on structs again, add summary method for structs
authorDoug Coleman <doug.coleman@gmail.com>
Tue, 1 Sep 2009 00:27:29 +0000 (19:27 -0500)
committerDoug Coleman <doug.coleman@gmail.com>
Tue, 1 Sep 2009 00:27:29 +0000 (19:27 -0500)
basis/mirrors/mirrors.factor
basis/summary/summary.factor

index 7190d612409a5e9a04553671669f3954a956a938..d9120da9dc8e215bacfc81998e62fe04e0d830d8 100644 (file)
@@ -56,3 +56,13 @@ M: array make-mirror <enum> ;
 M: vector make-mirror <enum> ;
 M: quotation make-mirror <enum> ;
 M: object make-mirror <mirror> ;
+
+M: struct make-mirror
+    [
+        [ drop "underlying" ] [ (underlying)>> ] bi 2array 1array
+    ] [
+        '[
+            _ struct>assoc
+            [ [ [ name>> ] [ c-type>> ] bi 2array ] dip ] assoc-map
+        ] [ drop { } ] recover
+    ] bi append ;
index 44e5374dc52d7a6cd53f2ebddc25aaa4ca1eb899..d8542c7f83019901b7eb5cf63616aa264e31cb69 100644 (file)
@@ -1,7 +1,8 @@
 ! Copyright (C) 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors classes sequences kernel namespaces
-make words math math.parser assocs ;
+make words math math.parser assocs classes.struct
+alien.c-types ;
 IN: summary
 
 GENERIC: summary ( object -- string )
@@ -31,3 +32,11 @@ M: assoc summary
 M: f summary object-summary ;
 
 M: integer summary object-summary ;
+
+M: struct summary
+    [
+        dup class name>> %
+        " struct of " %
+        byte-length #
+        " bytes " %
+    ] "" make ;