Skip to content

Commit d3f01ed

Browse files
committed
Improve LLIR testing and fix a problem in paths
1 parent 4334c67 commit d3f01ed

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

hkmc2DiffTests/src/test/scala/hkmc2/LlirDiffMaker.scala

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,14 @@ abstract class LlirDiffMaker extends BbmlDiffMaker:
4141
try { op(p) } finally { p.close() }
4242

4343
given Elaborator.Ctx = curCtx
44-
45-
var freshId = FreshInt()
46-
var ctx = codegen.llir.Ctx.empty
47-
val scope = Scope.empty
48-
val wholeProg = ListBuffer.empty[Program]
49-
44+
45+
object Llir: // Avoid polluting the namespace
46+
val freshId = FreshInt()
47+
var ctx = codegen.llir.Ctx.empty
48+
val scope = Scope.empty
49+
val wholeProg = ListBuffer.empty[Program]
50+
import Llir.*
51+
5052
def mkWholeProgram: Program =
5153
if wholeProg.length == 0 then
5254
throw new Exception("No program to make")
@@ -81,11 +83,7 @@ abstract class LlirDiffMaker extends BbmlDiffMaker:
8183
output(s"\n$name:")
8284
output(cpp.toDocument.toString)
8385
val rPath = os.Path(rootPath)
84-
val auxPath =
85-
if rPath.last =/= "shared" then
86-
rPath/"hkmc2"/"shared"/"src"/"test"/"mlscript-compile"/"cpp"
87-
else
88-
rPath/"src"/"test"/"mlscript-compile"/"cpp"
86+
val auxPath = rPath/"hkmc2"/"shared"/"src"/"test"/"mlscript-compile"/"cpp"
8987
if write.isDefined then
9088
printToFile(java.io.File((auxPath / s"${write.get}").toString)):
9189
p => p.println(cpp.toDocument.toString)

hkmc2DiffTests/src/test/scala/hkmc2/Watcher.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,16 @@ class Watcher(dirs: Ls[File]):
8989
val path = os.Path(file.pathAsString)
9090
val basePath = path.segments.drop(dirPaths.head.segmentCount).toList.init
9191
val relativeName = basePath.map(_ + "/").mkString + path.baseName
92-
val preludePath = os.pwd/os.up/"hkmc2"/"shared"/"src"/"test"/"mlscript"/"decls"/"Prelude.mls"
93-
val predefPath = os.pwd/os.up/"hkmc2"/"shared"/"src"/"test"/"mlscript-compile"/"Predef.mls"
92+
val rootPath = os.pwd/os.up
93+
val preludePath = rootPath/"hkmc2"/"shared"/"src"/"test"/"mlscript"/"decls"/"Prelude.mls"
94+
val predefPath = rootPath/"hkmc2"/"shared"/"src"/"test"/"mlscript-compile"/"Predef.mls"
9495
val isModuleFile = path.segments.contains("mlscript-compile")
9596
if isModuleFile
9697
then
9798
given Config = Config.default
9899
MLsCompiler(preludePath, outputConsumer => outputConsumer(System.out.println)).compileModule(path)
99100
else
100-
val dm = new MainDiffMaker((dirPaths.head/os.up).toString, path, preludePath, predefPath, relativeName):
101+
val dm = new MainDiffMaker(rootPath.toString, path, preludePath, predefPath, relativeName):
101102
override def unhandled(blockLineNum: Int, exc: Throwable): Unit =
102103
exc.printStackTrace()
103104
super.unhandled(blockLineNum, exc)

0 commit comments

Comments
 (0)