@@ -27,6 +27,21 @@ case class Program(
27
27
Sorting .quickSort(t2)
28
28
s " Program({ ${t1.mkString(" ,\n " )}}, { \n ${t2.mkString(" \n " )}\n }, \n $main) "
29
29
30
+ def show = toDocument.print
31
+
32
+ def toDocument : Document =
33
+ val t1 = classes.toArray
34
+ val t2 = defs.toArray
35
+ Sorting .quickSort(t1)
36
+ Sorting .quickSort(t2)
37
+ given Conversion [String , Document ] = raw
38
+ stack(
39
+ " Program:" ,
40
+ stack_list(t1.map(_.toDocument).toList) |> indent,
41
+ stack_list(t2.map(_.toDocument).toList) |> indent,
42
+ main.toDocument |> indent
43
+ )
44
+
30
45
implicit object ClassInfoOrdering extends Ordering [ClassInfo ] {
31
46
def compare (a : ClassInfo , b : ClassInfo ) = a.id.compare(b.id)
32
47
}
@@ -42,6 +57,19 @@ case class ClassInfo(
42
57
override def toString : String =
43
58
s " ClassInfo( $id, $name, [ ${fields mkString " ," }], parents: ${parents mkString " ," }, methods: \n ${methods mkString " ,\n " }) "
44
59
60
+ def show = toDocument.print
61
+ def toDocument : Document =
62
+ given Conversion [String , Document ] = raw
63
+ val extension = if parents.isEmpty then " " else " extends " + parents.mkString(" , " )
64
+ if methods.isEmpty then
65
+ " class" <:> name <#> " (" <#> fields.mkString(" ," ) <#> " )" <#> extension
66
+ else
67
+ stack(
68
+ " class" <:> name <#> " (" <#> fields.mkString(" ," ) <#> " )" <#> extension <:> " {" ,
69
+ stack_list( methods.map { (_, defn) => defn.toDocument |> indent }.toList),
70
+ " }"
71
+ )
72
+
45
73
case class Name (val str : Str ):
46
74
private var intro : Opt [Intro ] = None
47
75
private var elim : Set [Elim ] = Set .empty
@@ -103,6 +131,15 @@ case class Defn(
103
131
val ars = activeResults.map(_.toString).mkString(" [" , " ," , " ]" )
104
132
s " Def( $id, $name, $ps, $naps, \n I: $ais, \n R: $ars, \n Rec: $recBoundary, \n $resultNum, \n $body\n ) "
105
133
134
+ def show = toDocument.print
135
+
136
+ def toDocument : Document =
137
+ given Conversion [String , Document ] = raw
138
+ stack(
139
+ " def" <:> name <#> " (" <#> params.map(_.toString).mkString(" ," ) <#> " )" <:> " =" ,
140
+ body.toDocument |> indent
141
+ )
142
+
106
143
sealed trait TrivialExpr :
107
144
import Expr ._
108
145
override def toString : String
@@ -224,7 +261,7 @@ enum Node:
224
261
val names_copy = names.map(_.copy)
225
262
LetCall (names_copy, defn, args.map(_.mapNameOfTrivialExpr(_.trySubst(ctx))), body.copy(ctx ++ names_copy.map(x => x.str -> x)))
226
263
227
- private def toDocument : Document =
264
+ def toDocument : Document =
228
265
given Conversion [String , Document ] = raw
229
266
this match
230
267
case Result (res) => (res |> showArguments) <:> s " -- $tag"
0 commit comments