]> gitweb.factorcode.org Git - factor.git/blob - extra/smalltalk/printer/printer.factor
Switch to https urls
[factor.git] / extra / smalltalk / printer / printer.factor
1 ! Copyright (C) 2009 Slava Pestov.
2 ! See https://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 splitting ;
6 IN: smalltalk.printer
7
8 GENERIC: smalltalk>string ( object -- string )
9
10 M: real smalltalk>string number>string ;
11
12 M: string smalltalk>string
13     [
14         "'" %
15         [ dup CHAR: ' = [ dup , , ] [ , ] if ] each
16         "'" %
17     ] "" make ;
18
19 GENERIC: array-element>string ( object -- string )
20
21 M: object array-element>string smalltalk>string ;
22
23 M: array array-element>string
24     [ array-element>string ] map join-words "(" ")" surround ;
25
26 M: array smalltalk>string
27     array-element>string "#" prepend ;
28
29 M: byte-array smalltalk>string
30     [ number>string ] { } map-as join-words "#[" "]" surround ;
31
32 M: symbol smalltalk>string
33     name>> smalltalk>string "#" prepend ;
34
35 M: object smalltalk>string unparse-short ;