Skip to content

Commit 366d252

Browse files
committed
Tweaks.
1 parent a492429 commit 366d252

File tree

2 files changed

+61
-17
lines changed

2 files changed

+61
-17
lines changed

src/main/scala/net/kogics/kojo/lite/Versions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package net.kogics.kojo.lite
33
object Versions {
44
val KojoMajorVersion = "2.9"
55
val KojoVersion = "2.9.25"
6-
val KojoRevision = "r7"
6+
val KojoRevision = "r8"
77
val KojoBuildDate = "30 July 2023"
88
val JavaVersion = {
99
val jrv = System.getProperty("java.runtime.version")

src/main/scala/net/kogics/kojo/xscala/CompilerAndRunner.scala

Lines changed: 60 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class CompilerAndRunner(
156156
}
157157
}
158158

159-
val reporter = new KojoReporter {
159+
val runReporter = new KojoReporter {
160160
def lineMod = prefixLines + 1 // we added an extra line after the prefix in the code template.
161161
def offsetMod = offsetDelta + 1 // we added an extra newline char after the prefix
162162
}
@@ -167,7 +167,51 @@ class CompilerAndRunner(
167167
}
168168

169169
val compiler = classLoader.asContext {
170-
new Global(runSettings, reporter)
170+
new Global(runSettings, runReporter)
171+
}
172+
173+
object SRSwitcher {
174+
val Run = 1
175+
val Exec = 2
176+
private var prevMode = Run
177+
178+
private var verbose = false
179+
private def debugPrintln(s: => String): Unit = {
180+
if (verbose) {
181+
println(s)
182+
}
183+
}
184+
185+
def adjust(currMode: Int): Unit = {
186+
if (prevMode == Exec && currMode == Run) {
187+
debugPrintln("Changing to compiler run settings/reporter")
188+
compiler.currentSettings = runSettings
189+
compiler.reporter = runReporter
190+
prevMode = Run
191+
}
192+
if (prevMode == Run && currMode == Exec) {
193+
debugPrintln("Changing to compiler exec settings/reporter")
194+
compiler.currentSettings = execSettings
195+
compiler.reporter = execReporter
196+
prevMode = Exec
197+
}
198+
}
199+
200+
def newRunSettings(setReporter: Boolean): Unit = {
201+
debugPrintln("Changing to *new* compiler run settings")
202+
compiler.currentSettings = makeRunSettings
203+
if (setReporter && prevMode == Exec) {
204+
debugPrintln("Changing to compiler run reporter")
205+
compiler.reporter = runReporter
206+
}
207+
prevMode = Run
208+
}
209+
210+
def restoreRunSettings(): Unit = {
211+
debugPrintln("Restoring compiler run settings")
212+
compiler.currentSettings = runSettings
213+
verbose = if (System.getProperty("kojo.compiler.sr.verbose") == "true") true else false
214+
}
171215
}
172216

173217
def pfxWithCounter = "%s%d%s".format(prefixHeader, counter, prefix)
@@ -202,30 +246,30 @@ class CompilerAndRunner(
202246
def compileForRunning(code0: String, stopPhase: List[String] = List("cleanup")): Results.Result = {
203247
codeForRunning(code0)
204248
.map { code =>
205-
compiler.currentSettings = runSettings
206-
compiler.reporter = reporter
249+
SRSwitcher.adjust(SRSwitcher.Run)
250+
var sChanged = false
207251
if (compiler.settings.stopAfter.value != stopPhase) {
208-
// There seems to be a bug in the PhasesSetting contains method
209-
// which makes the compiler not see the new stopAfter value
210-
// So we make a new Settings
211-
compiler.currentSettings = makeRunSettings
252+
SRSwitcher.newRunSettings(false)
253+
sChanged = true
212254
compiler.settings.stopAfter.value = stopPhase
213255
}
214256

215257
val run = new compiler.Run
216-
reporter.reset()
258+
runReporter.reset()
217259
run.compileSources(List(new BatchSourceFile("scripteditor", code)))
218260
// println(s"[Debug] Script checking done till phase: ${compiler.globalPhase.prev}")
219-
if (reporter.hasErrors) IR.Error else IR.Success
261+
if (sChanged) {
262+
SRSwitcher.restoreRunSettings()
263+
}
264+
if (runReporter.hasErrors) IR.Error else IR.Success
220265
}
221266
.getOrElse(IR.Error)
222267
}
223268

224269
def compileForExecing(code0: String): Results.Result = {
225270
codeForExecing(code0)
226271
.map { code =>
227-
compiler.currentSettings = execSettings
228-
compiler.reporter = execReporter
272+
SRSwitcher.adjust(SRSwitcher.Exec)
229273
val run = new compiler.Run
230274
execReporter.reset()
231275
run.compileSources(List(new BatchSourceFile("scripteditor", code)))
@@ -322,16 +366,16 @@ class CompilerAndRunner(
322366
def parse(code0: String, browseAst: Boolean) = {
323367
codeForRunning(code0)
324368
.map { code =>
325-
compiler.currentSettings = makeRunSettings
369+
SRSwitcher.newRunSettings(true)
326370
compiler.settings.stopAfter.value = stopPhase()
327371
if (browseAst) {
328372
compiler.settings.browse.value = stopPhase()
329373
}
330374
val run = new compiler.Run
331-
reporter.reset()
375+
runReporter.reset()
332376
run.compileSources(List(new BatchSourceFile("scripteditor", code)))
333-
334-
if (reporter.hasErrors) {
377+
SRSwitcher.restoreRunSettings()
378+
if (runReporter.hasErrors) {
335379
IR.Error
336380
}
337381
else {

0 commit comments

Comments
 (0)