Replace runner script to allow for globbing
[jackhill/mal.git] / chuck / printer.ck
CommitLineData
e83d6df7
VS
1public class Printer
2{
3 fun static string pr_str(MalObject m, int print_readably)
4 {
5 m.type => string type;
6
7 if( type == "true" || type == "false" || type == "nil" )
8 {
9 return type;
10 }
11 else if( type == "int" )
12 {
13 return Std.itoa((m$MalInt).value());
14 }
15 else if( type == "string" )
16 {
17 (m$MalString).value() => string value;
18 if( print_readably )
19 {
20 return String.repr(value);
21 }
22 else
23 {
24 return value;
25 }
26 }
27 else if( type == "symbol" )
28 {
29 return (m$MalSymbol).value();
30 }
31 else if( type == "keyword" )
32 {
33 return ":" + (m$MalKeyword).value();
34 }
35 else if( type == "atom" )
36 {
37 return "(atom " + pr_str((m$MalAtom).value(), print_readably) + ")";
38 }
80a2a738
VS
39 else if( type == "subr" )
40 {
41 return "#<Subr>";
42 }
e83d6df7
VS
43 else if( type == "list" )
44 {
45 return pr_list((m$MalList).value(), print_readably, "(", ")");
46 }
47 else if( type == "vector" )
48 {
49 return pr_list((m$MalVector).value(), print_readably, "[", "]");
50 }
51 else if( type == "hashmap" )
52 {
53 return pr_list((m$MalHashMap).value(), print_readably, "{", "}");
54 }
80a2a738
VS
55 else
56 {
57 return "Unknown type";
58 }
e83d6df7
VS
59 }
60
61 fun static string pr_list(MalObject m[], int print_readably, string start, string end)
62 {
63 string parts[m.size()];
64
65 for( 0 => int i; i < m.size(); i++ )
66 {
67 pr_str(m[i], print_readably) => parts[i];
68 }
69
70 return start + String.join(parts, " ") + end;
71 }
72}