]> gitweb.factorcode.org Git - factor.git/blob - extra/smalltalk/printer/printer.factor
core: Add words/unwords/unwords-as and use them.
[factor.git] / extra / smalltalk / printer / printer.factor
1 ! Copyright (C) 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors arrays byte-arrays kernel make math
4 math.parser prettyprint sequences smalltalk.ast strings ;
5 IN: smalltalk.printer
6
7 GENERIC: smalltalk>string ( object -- string )
8
9 M: real smalltalk>string number>string ;
10
11 M: string smalltalk>string
12     [
13         "'" %
14         [ dup CHAR: ' = [ dup , , ] [ , ] if ] each
15         "'" %
16     ] "" make ;
17
18 GENERIC: array-element>string ( object -- string )
19
20 M: object array-element>string smalltalk>string ;
21
22 M: array array-element>string
23     [ array-element>string ] map unwords "(" ")" surround ;
24
25 M: array smalltalk>string
26     array-element>string "#" prepend ;
27
28 M: byte-array smalltalk>string
29     [ number>string ] { } map-as unwords "#[" "]" surround ;
30
31 M: symbol smalltalk>string
32     name>> smalltalk>string "#" prepend ;
33
34 M: object smalltalk>string unparse-short ;