]> gitweb.factorcode.org Git - factor.git/commitdiff
disassemble method for byte-arrays. HEX{ abcd } syntax for byte-arrays
authorJoe Groff <arcata@gmail.com>
Tue, 28 Jul 2009 03:14:26 +0000 (22:14 -0500)
committerJoe Groff <arcata@gmail.com>
Tue, 28 Jul 2009 03:14:26 +0000 (22:14 -0500)
basis/tools/disassembler/disassembler.factor
core/byte-arrays/byte-arrays-docs.factor
core/byte-arrays/byte-arrays.factor

index 744318a0a435c580d670e3c89a37f1aa1e371c43..0a8ab0b1169b47e8c6f87988fb1b5962f1525c34 100755 (executable)
@@ -1,7 +1,8 @@
 ! Copyright (C) 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: tr arrays sequences io words generic system combinators
-vocabs.loader kernel ;
+USING: alien alien.c-types arrays byte-arrays combinators
+destructors generic io kernel libc math sequences system tr
+vocabs.loader words ;
 IN: tools.disassembler
 
 GENERIC: disassemble ( obj -- )
@@ -12,6 +13,13 @@ HOOK: disassemble* disassembler-backend ( from to -- lines )
 
 TR: tabs>spaces "\t" "\s" ;
 
+M: byte-array disassemble 
+    [
+        [ malloc-byte-array &free alien-address dup ]
+        [ length + ] bi
+        2array disassemble
+    ] with-destructors ;
+
 M: pair disassemble first2 disassemble* [ tabs>spaces print ] each ;
 
 M: word disassemble word-xt 2array disassemble ;
index f1d94a46f70bc6009af6f88c0024edb6976a1cce..56832a56e5deee634af389a59256c5afff05a31a 100644 (file)
@@ -23,6 +23,10 @@ $nl
 
 ABOUT: "byte-arrays"
 
+HELP: HEX{
+{ $syntax "HEX{ 0123 45 67 89abcdef }" }
+{ $description "Constructs a " { $link byte-array } " from data specified in hexadecimal format. Whitespace between the curly braces is ignored." } ;
+
 HELP: byte-array
 { $description "The class of byte arrays. See " { $link "syntax-byte-arrays" } " for syntax and " { $link "byte-arrays" } " for general information." } ;
 
index 72989ac447069d04fd48c9460b1136010589bca4..b32060ec993390bea49a1b93ac073676704ba2cb 100644 (file)
@@ -1,9 +1,16 @@
 ! Copyright (C) 2007, 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors kernel kernel.private alien.accessors sequences
-sequences.private math ;
+USING: accessors alien.accessors ascii grouping kernel
+kernel.private lexer math math.parser parser sequences
+sequences.private ;
 IN: byte-arrays
 
+SYNTAX: HEX{
+    "}" parse-tokens "" join
+    [ blank? not ] filter
+    2 group [ hex> ] B{ } map-as
+    parsed ;
+
 M: byte-array clone (clone) ;
 M: byte-array length length>> ;
 M: byte-array nth-unsafe swap >fixnum alien-unsigned-1 ;