Skip to content

Commit 01cafb4

Browse files
committed
Improve code style
1 parent 6eb0eb1 commit 01cafb4

File tree

8 files changed

+108
-106
lines changed

8 files changed

+108
-106
lines changed

compiler/shared/main/scala/mlscript/compiler/Document.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ enum Document:
1010
def <:>(other: Document) = line(List(this, other))
1111
def <#>(other: Document) = line(List(this, other), sep = "")
1212

13-
override def toString(): String = print
13+
override def toString: String = print
1414

1515
def print: String = {
1616
val sb = StringBuffer()

compiler/shared/main/scala/mlscript/compiler/codegen/CppAst.scala

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,30 @@ enum Specifier:
1010
case Static
1111
case Inline
1212

13-
def toDocument = this match
14-
case Extern => "extern" |> raw
15-
case Static => "static" |> raw
16-
case Inline => "inline" |> raw
13+
def toDocument = raw(
14+
this match
15+
case Extern => "extern"
16+
case Static => "static"
17+
case Inline => "inline"
18+
)
1719

18-
override def toString(): Str = toDocument.print
20+
override def toString: Str = toDocument.print
1921

2022
object Type:
2123
def toDocuments(args: Ls[Type], sep: Document, extraTypename: Bool = false): Document =
22-
args.zipWithIndex.map {
23-
case (x, i) =>
24-
if i == 0 then
25-
x.toDocument(extraTypename)
26-
else
27-
sep <#> x.toDocument(extraTypename)
24+
args.iterator.zipWithIndex.map {
25+
case (x, 0) =>
26+
x.toDocument(extraTypename)
27+
case (x, _) =>
28+
sep <#> x.toDocument(extraTypename)
2829
}.fold(raw(""))(_ <#> _)
2930

3031
def toDocuments(args: Ls[(Str, Type)], sep: Document): Document =
31-
args.zipWithIndex.map {
32-
case (x, i) =>
33-
if i == 0 then
34-
x._2.toDocument() <:> raw(x._1)
35-
else
36-
sep <#> x._2.toDocument() <:> raw(x._1)
32+
args.iterator.zipWithIndex.map {
33+
case (x, 0) =>
34+
x._2.toDocument() <:> raw(x._1)
35+
case (x, _) =>
36+
sep <#> x._2.toDocument() <:> raw(x._1)
3737
}.fold(raw(""))(_ <#> _)
3838

3939
enum Type:
@@ -62,7 +62,7 @@ enum Type:
6262
case Qualifier(inner, qual) => aux(inner) <:> raw(qual)
6363
aux(this)
6464

65-
override def toString(): Str = toDocument().print
65+
override def toString: Str = toDocument().print
6666

6767
object Stmt:
6868
def toDocuments(decl: Ls[Decl], stmts: Ls[Stmt]): Document =
@@ -122,7 +122,7 @@ object Expr:
122122
enum Expr:
123123
case Var(name: Str)
124124
case IntLit(value: BigInt)
125-
case FloatLit(value: Float)
125+
case DoubleLit(value: Double)
126126
case StrLit(value: Str)
127127
case CharLit(value: Char)
128128
case Call(func: Expr, args: Ls[Expr])
@@ -137,7 +137,7 @@ enum Expr:
137137
def aux(x: Expr): Document = x match
138138
case Var(name) => name |> raw
139139
case IntLit(value) => value.toString |> raw
140-
case FloatLit(value) => value.toString |> raw
140+
case DoubleLit(value) => value.toString |> raw
141141
case StrLit(value) => s"\"$value\"" |> raw // need more reliable escape utils
142142
case CharLit(value) => value.toInt.toString |> raw
143143
case Call(func, args) => aux(func) <#> raw("(") <#> Expr.toDocuments(args, sep = raw(", ")) <#> raw(")")

compiler/shared/main/scala/mlscript/compiler/codegen/CppCodeGen.scala

Lines changed: 64 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -4,67 +4,68 @@ import mlscript.compiler.ir.{Expr => IExpr, _}
44
import mlscript.compiler.utils._
55
import mlscript.utils._
66
import mlscript.utils.shorthands._
7+
import scala.collection.mutable.ListBuffer
78

9+
def codegen(prog: Program): CompilationUnit =
10+
val codegen = CppCodeGen()
11+
codegen.codegen(prog)
812

9-
class CppCodeGen:
10-
private def mapName(name: Name): Str = "_mls_" + name.str.replace('$', '_').replace('\'', '_')
11-
private def mapName(name: Str): Str = "_mls_" + name.replace('$', '_').replace('\'', '_')
12-
private val freshName = Fresh(div = '_');
13-
private val mlsValType = Type.Prim("_mlsValue")
14-
private val mlsUnitValue = Expr.Call(Expr.Var("_mlsValue::create<_mls_Unit>"), Ls());
15-
private val mlsRetValue = "_mls_retval"
16-
private val mlsRetValueDecl = Decl.VarDecl(mlsRetValue, mlsValType)
17-
private val mlsMainName = "_mlsMain"
18-
private val mlsPrelude = "#include \"mlsprelude.h\""
19-
private val mlsPreludeImpl = "#include \"mlsprelude.cpp\""
20-
private val mlsInternalClass = Set("True", "False", "Boolean", "Callable")
21-
private val mlsObject = "_mlsObject"
22-
private val mlsBuiltin = "builtin"
23-
private val mlsEntryPoint = s"int main() { return _mlsLargeStack(_mlsMainWrapper); }";
24-
private def mlsIntLit(x: BigInt) = Expr.Call(Expr.Var("_mlsValue::fromIntLit"), Ls(Expr.IntLit(x)))
25-
private def mlsStrLit(x: Str) = Expr.Call(Expr.Var("_mlsValue::fromStrLit"), Ls(Expr.StrLit(x)))
26-
private def mlsCharLit(x: Char) = Expr.Call(Expr.Var("_mlsValue::fromIntLit"), Ls(Expr.CharLit(x)))
27-
private def mlsNewValue(cls: Str, args: Ls[Expr]) = Expr.Call(Expr.Var(s"_mlsValue::create<$cls>"), args)
28-
private def mlsIsValueOf(cls: Str, scrut: Expr) = Expr.Call(Expr.Var(s"_mlsValue::isValueOf<$cls>"), Ls(scrut))
29-
private def mlsIsIntLit(scrut: Expr, lit: mlscript.IntLit) = Expr.Call(Expr.Var("_mlsValue::isIntLit"), Ls(scrut, Expr.IntLit(lit.value)))
30-
private def mlsIsCharLit(scrut: Expr, lit: mlscript.CharLit) = Expr.Call(Expr.Var("_mlsValue::isCharLit"), Ls(scrut, Expr.CharLit(lit.value)))
31-
private def mlsDebugPrint(x: Expr) = Expr.Call(Expr.Var("_mlsValue::print"), Ls(x))
32-
private def mlsTupleValue(init: Expr) = Expr.Constructor("_mlsValue::tuple", init)
33-
private def mlsAs(name: Str, cls: Str) = Expr.Var(s"_mlsValue::as<$cls>($name)")
34-
private def mlsAsUnchecked(name: Str, cls: Str) = Expr.Var(s"_mlsValue::cast<$cls>($name)")
35-
private def mlsObjectNameMethod(name: Str) = s"constexpr static inline const char *typeName = \"${name}\";"
36-
private def mlsTypeTag() = s"constexpr static inline uint32_t typeTag = nextTypeTag();"
37-
private def mlsTypeTag(n: Int) = s"constexpr static inline uint32_t typeTag = $n;"
38-
private def mlsCommonCreateMethod(cls: Str, fields: Ls[Str], id: Int) =
13+
private class CppCodeGen:
14+
def mapName(name: Name): Str = "_mls_" + name.str.replace('$', '_').replace('\'', '_')
15+
def mapName(name: Str): Str = "_mls_" + name.replace('$', '_').replace('\'', '_')
16+
val freshName = Fresh(div = '_');
17+
val mlsValType = Type.Prim("_mlsValue")
18+
val mlsUnitValue = Expr.Call(Expr.Var("_mlsValue::create<_mls_Unit>"), Ls());
19+
val mlsRetValue = "_mls_retval"
20+
val mlsRetValueDecl = Decl.VarDecl(mlsRetValue, mlsValType)
21+
val mlsMainName = "_mlsMain"
22+
val mlsPrelude = "#include \"mlsprelude.h\""
23+
val mlsPreludeImpl = "#include \"mlsprelude.cpp\""
24+
val mlsInternalClass = Set("True", "False", "Boolean", "Callable")
25+
val mlsObject = "_mlsObject"
26+
val mlsBuiltin = "builtin"
27+
val mlsEntryPoint = s"int main() { return _mlsLargeStack(_mlsMainWrapper); }";
28+
def mlsIntLit(x: BigInt) = Expr.Call(Expr.Var("_mlsValue::fromIntLit"), Ls(Expr.IntLit(x)))
29+
def mlsStrLit(x: Str) = Expr.Call(Expr.Var("_mlsValue::fromStrLit"), Ls(Expr.StrLit(x)))
30+
def mlsCharLit(x: Char) = Expr.Call(Expr.Var("_mlsValue::fromIntLit"), Ls(Expr.CharLit(x)))
31+
def mlsNewValue(cls: Str, args: Ls[Expr]) = Expr.Call(Expr.Var(s"_mlsValue::create<$cls>"), args)
32+
def mlsIsValueOf(cls: Str, scrut: Expr) = Expr.Call(Expr.Var(s"_mlsValue::isValueOf<$cls>"), Ls(scrut))
33+
def mlsIsIntLit(scrut: Expr, lit: mlscript.IntLit) = Expr.Call(Expr.Var("_mlsValue::isIntLit"), Ls(scrut, Expr.IntLit(lit.value)))
34+
def mlsIsCharLit(scrut: Expr, lit: mlscript.CharLit) = Expr.Call(Expr.Var("_mlsValue::isCharLit"), Ls(scrut, Expr.CharLit(lit.value)))
35+
def mlsDebugPrint(x: Expr) = Expr.Call(Expr.Var("_mlsValue::print"), Ls(x))
36+
def mlsTupleValue(init: Expr) = Expr.Constructor("_mlsValue::tuple", init)
37+
def mlsAs(name: Str, cls: Str) = Expr.Var(s"_mlsValue::as<$cls>($name)")
38+
def mlsAsUnchecked(name: Str, cls: Str) = Expr.Var(s"_mlsValue::cast<$cls>($name)")
39+
def mlsObjectNameMethod(name: Str) = s"constexpr static inline const char *typeName = \"${name}\";"
40+
def mlsTypeTag() = s"constexpr static inline uint32_t typeTag = nextTypeTag();"
41+
def mlsTypeTag(n: Int) = s"constexpr static inline uint32_t typeTag = $n;"
42+
def mlsCommonCreateMethod(cls: Str, fields: Ls[Str], id: Int) =
3943
val parameters = fields.map{x => s"_mlsValue $x"}.mkString(", ")
4044
val fieldsAssignment = fields.map{x => s"_mlsVal->$x = $x; "}.mkString
4145
s"static _mlsValue create($parameters) { auto _mlsVal = new (std::align_val_t(_mlsAlignment)) $cls; _mlsVal->refCount = 1; _mlsVal->tag = typeTag; $fieldsAssignment return _mlsValue(_mlsVal); }"
42-
private def mlsCommonPrintMethod(fields: Ls[Str]) =
46+
def mlsCommonPrintMethod(fields: Ls[Str]) =
4347
if fields.isEmpty then s"virtual void print() const override { std::printf(\"%s\", typeName); }"
4448
else
4549
val fieldsPrint = fields.map{x => s"this->$x.print(); "}.mkString("std::printf(\", \"); ")
4650
s"virtual void print() const override { std::printf(\"%s\", typeName); std::printf(\"(\"); $fieldsPrint std::printf(\")\"); }"
47-
private def mlsCommonDestructorMethod(cls: Str, fields: Ls[Str]) =
51+
def mlsCommonDestructorMethod(cls: Str, fields: Ls[Str]) =
4852
val fieldsDeletion = fields.map{x => s"_mlsValue::destroy(this->$x); "}.mkString
4953
s"virtual void destroy() override { $fieldsDeletion operator delete (this, std::align_val_t(_mlsAlignment)); }"
50-
private def mlsThrowNonExhaustiveMatch = Stmt.Raw("_mlsNonExhaustiveMatch();");
51-
private def mlsCall(fn: Str, args: Ls[Expr]) = Expr.Call(Expr.Var("_mlsCall"), Expr.Var(fn) :: args)
52-
private def mlsMethodCall(cls: ClassRef, method: Str, args: Ls[Expr]) =
54+
def mlsThrowNonExhaustiveMatch = Stmt.Raw("_mlsNonExhaustiveMatch();");
55+
def mlsCall(fn: Str, args: Ls[Expr]) = Expr.Call(Expr.Var("_mlsCall"), Expr.Var(fn) :: args)
56+
def mlsMethodCall(cls: ClassRef, method: Str, args: Ls[Expr]) =
5357
Expr.Call(Expr.Member(Expr.Call(Expr.Var(s"_mlsMethodCall<${cls.name |> mapName}>"), Ls(args.head)), method), args.tail)
54-
private def mlsFnWrapperName(fn: Str) = s"_mlsFn_$fn"
55-
private def mlsFnCreateMethod(fn: Str) = s"static _mlsValue create() { static _mlsFn_$fn mlsFn alignas(_mlsAlignment); mlsFn.refCount = stickyRefCount; mlsFn.tag = typeTag; return _mlsValue(&mlsFn); }"
56-
private def mlsFnApplyNMethod(fn: Str, n: Int) =
57-
Def.FuncDef(Type.Qualifier(mlsValType, "virtual"), s"apply$n", (0 until n).map{x => (s"arg$x", mlsValType)}.toList,
58-
Stmt.Block(Ls(), Ls(Stmt.Return(Expr.Call(Expr.Var(fn), (0 until n).map{x => Expr.Var(s"arg$x")}.toList)))), true)
59-
private def mlsNeverValue(n: Int) = if (n <= 1) then Expr.Call(Expr.Var(s"_mlsValue::never"), Ls()) else Expr.Call(Expr.Var(s"_mlsValue::never<$n>"), Ls())
58+
def mlsFnWrapperName(fn: Str) = s"_mlsFn_$fn"
59+
def mlsFnCreateMethod(fn: Str) = s"static _mlsValue create() { static _mlsFn_$fn mlsFn alignas(_mlsAlignment); mlsFn.refCount = stickyRefCount; mlsFn.tag = typeTag; return _mlsValue(&mlsFn); }"
60+
def mlsNeverValue(n: Int) = if (n <= 1) then Expr.Call(Expr.Var(s"_mlsValue::never"), Ls()) else Expr.Call(Expr.Var(s"_mlsValue::never<$n>"), Ls())
6061

61-
private case class Ctx(
62-
val defnCtx: Set[Str],
62+
case class Ctx(
63+
defnCtx: Set[Str],
6364
)
6465

65-
private def codegenClassInfo(using ctx: Ctx)(cls: ClassInfo): (Opt[Def], Decl) =
66+
def codegenClassInfo(using ctx: Ctx)(cls: ClassInfo): (Opt[Def], Decl) =
6667
val fields = cls.fields.map{x => (x |> mapName, mlsValType)}
67-
val parents = if cls.parents.nonEmpty then cls.parents.toList.map{x => x |> mapName} else mlsObject :: Nil
68+
val parents = if cls.parents.nonEmpty then cls.parents.toList.map(mapName) else mlsObject :: Nil
6869
val decl = Decl.StructDecl(cls.name |> mapName)
6970
if mlsInternalClass.contains(cls.name) then return (None, decl)
7071
val theDef = Def.StructDef(
@@ -84,15 +85,15 @@ class CppCodeGen:
8485
)
8586
(S(theDef), decl)
8687

87-
private def toExpr(texpr: TrivialExpr, reifyUnit: Bool = false)(using ctx: Ctx): Opt[Expr] = texpr match
88+
def toExpr(texpr: TrivialExpr, reifyUnit: Bool = false)(using ctx: Ctx): Opt[Expr] = texpr match
8889
case IExpr.Ref(name) => S(Expr.Var(name |> mapName))
8990
case IExpr.Literal(mlscript.IntLit(x)) => S(mlsIntLit(x))
9091
case IExpr.Literal(mlscript.DecLit(x)) => S(mlsIntLit(x.toBigInt))
9192
case IExpr.Literal(mlscript.StrLit(x)) => S(mlsStrLit(x))
9293
case IExpr.Literal(mlscript.CharLit(x)) => S(mlsCharLit(x))
9394
case IExpr.Literal(mlscript.UnitLit(_)) => if reifyUnit then S(mlsUnitValue) else None
9495

95-
private def toExpr(texpr: TrivialExpr)(using ctx: Ctx): Expr = texpr match
96+
def toExpr(texpr: TrivialExpr)(using ctx: Ctx): Expr = texpr match
9697
case IExpr.Ref(name) => Expr.Var(name |> mapName)
9798
case IExpr.Literal(mlscript.IntLit(x)) => mlsIntLit(x)
9899
case IExpr.Literal(mlscript.DecLit(x)) => mlsIntLit(x.toBigInt)
@@ -101,13 +102,13 @@ class CppCodeGen:
101102
case IExpr.Literal(mlscript.UnitLit(_)) => mlsUnitValue
102103

103104

104-
private def wrapMultiValues(exprs: Ls[TrivialExpr])(using ctx: Ctx): Expr = exprs match
105+
def wrapMultiValues(exprs: Ls[TrivialExpr])(using ctx: Ctx): Expr = exprs match
105106
case x :: Nil => toExpr(x, reifyUnit = true).get
106107
case _ =>
107108
val init = Expr.Initializer(exprs.map{x => toExpr(x)})
108109
mlsTupleValue(init)
109110

110-
private def codegenCaseWithIfs(scrut: Name, cases: Ls[(Pat, Node)], default: Opt[Node], storeInto: Str)(using decls: Ls[Decl], stmts: Ls[Stmt])(using ctx: Ctx): (Ls[Decl], Ls[Stmt]) =
111+
def codegenCaseWithIfs(scrut: Name, cases: Ls[(Pat, Node)], default: Opt[Node], storeInto: Str)(using decls: Ls[Decl], stmts: Ls[Stmt])(using ctx: Ctx): (Ls[Decl], Ls[Stmt]) =
111112
val scrutName = mapName(scrut)
112113
val init: Stmt =
113114
default.fold(mlsThrowNonExhaustiveMatch)(x => {
@@ -131,12 +132,12 @@ class CppCodeGen:
131132
}
132133
(decls, stmt.fold(stmts)(x => stmts :+ x))
133134

134-
private def codegenJumpWithCall(defn: DefnRef, args: Ls[TrivialExpr], storeInto: Opt[Str])(using decls: Ls[Decl], stmts: Ls[Stmt])(using ctx: Ctx): (Ls[Decl], Ls[Stmt]) =
135+
def codegenJumpWithCall(defn: DefnRef, args: Ls[TrivialExpr], storeInto: Opt[Str])(using decls: Ls[Decl], stmts: Ls[Stmt])(using ctx: Ctx): (Ls[Decl], Ls[Stmt]) =
135136
val call = Expr.Call(Expr.Var(defn.name |> mapName), args.map(toExpr))
136137
val stmts2 = stmts ++ Ls(storeInto.fold(Stmt.Return(call))(x => Stmt.Assign(x, call)))
137138
(decls, stmts2)
138139

139-
private def codegenOps(op: Str, args: Ls[TrivialExpr])(using ctx: Ctx) = op match
140+
def codegenOps(op: Str, args: Ls[TrivialExpr])(using ctx: Ctx) = op match
140141
case "+" => Expr.Binary("+", toExpr(args(0)), toExpr(args(1)))
141142
case "-" => Expr.Binary("-", toExpr(args(0)), toExpr(args(1)))
142143
case "*" => Expr.Binary("*", toExpr(args(0)), toExpr(args(1)))
@@ -151,20 +152,20 @@ class CppCodeGen:
151152
case "&&" => Expr.Binary("&&", toExpr(args(0)), toExpr(args(1)))
152153
case "||" => Expr.Binary("||", toExpr(args(0)), toExpr(args(1)))
153154
case "!" => Expr.Unary("!", toExpr(args(0)))
154-
case _ => ???
155+
case _ => mlscript.utils.TODO("codegenOps")
155156

156157

157-
private def codegen(expr: IExpr)(using ctx: Ctx): Expr = expr match
158+
def codegen(expr: IExpr)(using ctx: Ctx): Expr = expr match
158159
case x @ (IExpr.Ref(_) | IExpr.Literal(_)) => toExpr(x, reifyUnit = true).get
159160
case IExpr.CtorApp(cls, args) => mlsNewValue(cls.name |> mapName, args.map(toExpr))
160161
case IExpr.Select(name, cls, field) => Expr.Member(mlsAsUnchecked(name |> mapName, cls.name |> mapName), field |> mapName)
161162
case IExpr.BasicOp(name, args) => codegenOps(name, args)
162163

163-
private def codegenBuiltin(names: Ls[Name], builtin: Str, args: Ls[TrivialExpr])(using ctx: Ctx): Ls[Stmt] = builtin match
164+
def codegenBuiltin(names: Ls[Name], builtin: Str, args: Ls[TrivialExpr])(using ctx: Ctx): Ls[Stmt] = builtin match
164165
case "error" => Ls(Stmt.Raw("throw std::runtime_error(\"Error\");"), Stmt.AutoBind(names.map(mapName), mlsNeverValue(names.size)))
165166
case _ => Ls(Stmt.AutoBind(names.map(mapName), Expr.Call(Expr.Var("_mls_builtin_" + builtin), args.map(toExpr))))
166167

167-
private def codegen(body: Node, storeInto: Str)(using decls: Ls[Decl], stmts: Ls[Stmt])(using ctx: Ctx): (Ls[Decl], Ls[Stmt]) = body match
168+
def codegen(body: Node, storeInto: Str)(using decls: Ls[Decl], stmts: Ls[Stmt])(using ctx: Ctx): (Ls[Decl], Ls[Stmt]) = body match
168169
case Node.Result(res) =>
169170
val expr = wrapMultiValues(res)
170171
val stmts2 = stmts ++ Ls(Stmt.Assign(storeInto, expr))
@@ -197,7 +198,7 @@ class CppCodeGen:
197198
case Node.Case(scrut, cases, default) =>
198199
codegenCaseWithIfs(scrut, cases, default, storeInto)
199200

200-
private def codegenDefn(using ctx: Ctx)(defn: Defn): (Def, Decl) = defn match
201+
def codegenDefn(using ctx: Ctx)(defn: Defn): (Def, Decl) = defn match
201202
case Defn(id, name, params, resultNum, specialized, body) =>
202203
val decls = Ls(mlsRetValueDecl)
203204
val stmts = Ls.empty[Stmt]
@@ -207,7 +208,7 @@ class CppCodeGen:
207208
val decl = Decl.FuncDecl(mlsValType, name |> mapName, params.map(x => mlsValType))
208209
(theDef, decl)
209210

210-
private def codegenTopNode(node: Node)(using ctx: Ctx): (Def, Decl) =
211+
def codegenTopNode(node: Node)(using ctx: Ctx): (Def, Decl) =
211212
val decls = Ls(mlsRetValueDecl)
212213
val stmts = Ls.empty[Stmt]
213214
val (decls2, stmts2) = codegen(node, mlsRetValue)(using decls, stmts)
@@ -216,27 +217,28 @@ class CppCodeGen:
216217
val decl = Decl.FuncDecl(mlsValType, mlsMainName, Ls())
217218
(theDef, decl)
218219

219-
private def sortClasses(prog: Program): Ls[ClassInfo] =
220+
// Topological sort of classes based on inheritance relationships
221+
def sortClasses(prog: Program): Ls[ClassInfo] =
220222
var depgraph = prog.classes.map(x => (x.name, x.parents)).toMap
221223
var degree = depgraph.view.mapValues(_.size).toMap
222224
def removeNode(node: Str) =
223225
degree -= node
224226
depgraph -= node
225227
depgraph = depgraph.view.mapValues(_.filter(_ != node)).toMap
226228
degree = depgraph.view.mapValues(_.size).toMap
227-
var sorted = Ls.empty[ClassInfo]
229+
val sorted = ListBuffer.empty[ClassInfo]
228230
var work = degree.filter(_._2 == 0).keys.toSet
229231
while work.nonEmpty do
230232
val node = work.head
231233
work -= node
232-
sorted = sorted :+ prog.classes.find(_.name == node).get
234+
sorted.addOne(prog.classes.find(_.name == node).get)
233235
removeNode(node)
234236
val next = degree.filter(_._2 == 0).keys
235-
work = work ++ next
237+
work ++= next
236238
if depgraph.nonEmpty then
237239
val cycle = depgraph.keys.mkString(", ")
238240
throw new Exception(s"Cycle detected in class hierarchy: $cycle")
239-
sorted
241+
sorted.toList
240242

241243
def codegen(prog: Program): CompilationUnit =
242244
val sortedClasses = sortClasses(prog)

compiler/shared/main/scala/mlscript/compiler/codegen/CppCompilerHost.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ final class CppCompilerHost(val auxPath: Str):
3232

3333
stdout.clear()
3434
stderr.clear()
35-
val runCmd = Seq(binPath.toString())
35+
val runCmd = Seq(binPath.toString)
3636
val runResult = runCmd ! buildLogger
3737
if runResult != 0 then
3838
output("Execution failed: ")

0 commit comments

Comments
 (0)