@@ -87,13 +87,12 @@ trait Runner[Executable] {
87
87
/**
88
88
* Builds a given executable and returns the resulting path to the executable.
89
89
*/
90
- def build (executable : Executable )(using Context ): String
90
+ def build (executable : Executable )(using Context ): Option [ String ]
91
91
92
92
/**
93
93
* Runs the executable (e.g. the main file) by calling the build function.
94
94
*/
95
- def eval (executable : Executable )(using C : Context ): Unit = {
96
- val execFile = build(executable)
95
+ def eval (executable : Executable )(using C : Context ): Unit = build(executable).foreach { execFile =>
97
96
val valgrindArgs = Seq (" --leak-check=full" , " --undef-value-errors=no" , " --quiet" , " --log-file=valgrind.log" , " --error-exitcode=1" )
98
97
val process = if (C .config.valgrind())
99
98
Process (" valgrind" , valgrindArgs ++ (execFile +: Context .config.runArgs()))
@@ -165,7 +164,7 @@ object JSNodeRunner extends Runner[String] {
165
164
* Creates an executable `.js` file besides the given `.js` file ([[path ]])
166
165
* and then returns the absolute path of the created executable.
167
166
*/
168
- def build (path : String )(using C : Context ): String =
167
+ def build (path : String )(using C : Context ): Option [ String ] =
169
168
val out = C .config.outputPath().getAbsolutePath
170
169
val jsFilePath = (out / path).canonicalPath.escape
171
170
val jsFileName = path.unixPath.split(" /" ).last
@@ -177,14 +176,14 @@ object JSNodeRunner extends Runner[String] {
177
176
val shebang = " #!/usr/bin/env node"
178
177
val jsScriptFilePath = jsFilePath.stripSuffix(s " . $extension" )
179
178
IO .createFile(jsScriptFilePath, s " $shebang\n $jsScript" , true )
180
- jsScriptFilePath
179
+ Some ( jsScriptFilePath)
181
180
182
181
case OS .Windows =>
183
182
val jsMainFilePath = jsFilePath.stripSuffix(s " . $extension" ) + " __main.js"
184
183
val jsMainFileName = jsFileName.stripSuffix(s " . $extension" ) + " __main.js"
185
184
val exePath = jsFilePath.stripSuffix(s " . $extension" )
186
185
IO .createFile(jsMainFilePath, jsScript)
187
- createScript(exePath, " node" , " $SCRIPT_DIR/" + jsMainFileName)
186
+ Some ( createScript(exePath, " node" , " $SCRIPT_DIR/" + jsMainFileName) )
188
187
}
189
188
}
190
189
object JSWebRunner extends Runner [String ] {
@@ -202,7 +201,7 @@ object JSWebRunner extends Runner[String] {
202
201
* Creates an openable `.html` file besides the given `.js` file ([[path ]])
203
202
* and then errors out, printing it's path.
204
203
*/
205
- def build (path : String )(using C : Context ): String =
204
+ def build (path : String )(using C : Context ): Option [ String ] =
206
205
val out = C .config.outputPath().getAbsolutePath
207
206
val jsFilePath = (out / path).unixPath
208
207
val jsFileName = path.unixPath.split(" /" ).last
@@ -222,10 +221,8 @@ object JSWebRunner extends Runner[String] {
222
221
| """ .stripMargin
223
222
IO .createFile(htmlFilePath, htmlContent, false )
224
223
225
- // TODO: In ErrorReporter, add a way to terminate the program with a message, but not report a exit failure.
226
- // Workaround: print and then 'exit(0)'
227
- println(s " Open file:// ${htmlFilePath} in your browser or include ${jsFilePath}. " )
228
- scala.sys.exit(0 )
224
+ C .info(s " Open file:// ${htmlFilePath} in your browser or include ${jsFilePath}. " )
225
+ None
229
226
}
230
227
231
228
trait ChezRunner extends Runner [String ] {
@@ -241,12 +238,12 @@ trait ChezRunner extends Runner[String] {
241
238
* Creates an executable bash script besides the given `.ss` file ([[path ]])
242
239
* and returns the resulting absolute path.
243
240
*/
244
- def build (path : String )(using C : Context ): String =
241
+ def build (path : String )(using C : Context ): Option [ String ] =
245
242
val out = C .config.outputPath().getAbsolutePath
246
243
val schemeFilePath = (out / path).canonicalPath.escape
247
244
val exeScriptPath = schemeFilePath.stripSuffix(s " . $extension" )
248
245
val schemeFileName = (" ./" + (path.unixPath.split('/' ).last)).escape
249
- createScript(exeScriptPath, " scheme" , " --script" , " $SCRIPT_DIR/" + schemeFileName)
246
+ Some ( createScript(exeScriptPath, " scheme" , " --script" , " $SCRIPT_DIR/" + schemeFileName) )
250
247
}
251
248
252
249
object ChezMonadicRunner extends ChezRunner {
@@ -310,7 +307,7 @@ object LLVMRunner extends Runner[String] {
310
307
* Requires LLVM and GCC to be installed on the machine.
311
308
* Assumes [[path ]] has the format "SOMEPATH.ll".
312
309
*/
313
- override def build (path : String )(using C : Context ): String =
310
+ override def build (path : String )(using C : Context ): Option [ String ] =
314
311
315
312
val out = C .config.outputPath()
316
313
val basePath = (out / path.stripSuffix(" .ll" )).unixPath
@@ -339,5 +336,5 @@ object LLVMRunner extends Runner[String] {
339
336
340
337
exec(gccArgs : _* )
341
338
342
- executableFile
339
+ Some ( executableFile)
343
340
}
0 commit comments