From d95d74104f7e2e61fd5dcaa03b4c18aa3a7e7431 Mon Sep 17 00:00:00 2001 From: Karol Stasiak Date: Thu, 7 Dec 2017 00:55:44 +0100 Subject: [PATCH] Removal of some unused old code --- .../scala/millfork/CompilationOptions.scala | 19 -- .../millfork/parser/MinimalTestCase.scala | 24 --- .../scala/millfork/parser/ParserBase.scala | 169 ------------------ .../millfork/parser/SourceLoadingQueue.scala | 8 - .../scala/millfork/test/MinimalTest.scala | 23 --- .../scala/millfork/test/StackVarSuite.scala | 5 +- .../millfork/test/emu/EmuBenchmarkRun.scala | 14 +- 7 files changed, 5 insertions(+), 257 deletions(-) delete mode 100644 src/main/scala/millfork/parser/MinimalTestCase.scala delete mode 100644 src/main/scala/millfork/parser/ParserBase.scala delete mode 100644 src/test/scala/millfork/test/MinimalTest.scala diff --git a/src/main/scala/millfork/CompilationOptions.scala b/src/main/scala/millfork/CompilationOptions.scala index 1e7db997..bcfcb6b4 100644 --- a/src/main/scala/millfork/CompilationOptions.scala +++ b/src/main/scala/millfork/CompilationOptions.scala @@ -5,25 +5,6 @@ import millfork.error.ErrorReporting /** * @author Karol Stasiak */ -// -//object CompilationOptions { -// -// -// private var instance = new CompilationOptions(Platform.C64, Map()) -// -// // TODO: ugly! -// def change(o: CompilationOptions): Unit = { -// instance = o -// } -// -// def current: CompilationOptions= instance -// -// def platform: Platform = instance.platform -// -// def flag(flag: CompilationFlag.Value):Boolean = instance.flags(flag) -// -// def flags: Map[CompilationFlag.Value, Boolean] = instance.flags -//} class CompilationOptions(val platform: Platform, val commandLineFlags: Map[CompilationFlag.Value, Boolean]) { import CompilationFlag._ diff --git a/src/main/scala/millfork/parser/MinimalTestCase.scala b/src/main/scala/millfork/parser/MinimalTestCase.scala deleted file mode 100644 index 2f5852d6..00000000 --- a/src/main/scala/millfork/parser/MinimalTestCase.scala +++ /dev/null @@ -1,24 +0,0 @@ -package millfork.parser - -import fastparse.all._ -import fastparse.core - -object MinimalTestCase { - def AWS: P[Unit] = "\n".rep(min = 0).opaque("").log() - - def EOL: P[Unit] = "\n".rep(min = 1).opaque("").log() - - def identifier: P[String] = CharPred(_.isLetter).rep(min = 1).!.opaque("").log() - - def identifierWithSpace: P[String] = (identifier ~/ AWS ~/ Pass).opaque("").log() - - def separator: P[Unit] = ("," ~/ AWS ~/ Pass).opaque("").log() - - def identifiers: P[Seq[String]] = identifierWithSpace.rep(min = 0, sep = separator)//.opaque("").log() - - def array: P[Seq[String]] = ("[" ~/ AWS ~/ identifiers ~/ "]" ~/ Pass)//.opaque("").log() - - def arrays: Parser[Seq[Seq[String]]] = (array ~/ EOL).rep(min = 0, sep = !End ~/ Pass)//.opaque("").log() - - def program: Parser[Seq[Seq[String]]] = Start ~/ AWS ~/ arrays ~/ End -} diff --git a/src/main/scala/millfork/parser/ParserBase.scala b/src/main/scala/millfork/parser/ParserBase.scala deleted file mode 100644 index 4836d700..00000000 --- a/src/main/scala/millfork/parser/ParserBase.scala +++ /dev/null @@ -1,169 +0,0 @@ -package millfork.parser - -import millfork.node.Position - -/** - * @author Karol Stasiak - */ -case class ParseException(msg: String, position: Option[Position]) extends Exception - -class ParserBase(filename: String, input: String) { - - def reset(): Unit = { - cursor = 0 - line = 1 - column = FirstColumn - } - - private val FirstColumn = 0 - private val length = input.length - private var cursor = 0 - private var line = 1 - private var column = FirstColumn - - def position = Position(filename, line, column, cursor) - - def restorePosition(p: Position): Unit = { - cursor = p.cursor - column = p.column - line = p.line - } - - def error(msg: String, pos: Option[Position]): Nothing = throw ParseException(msg, pos) - - def error(msg: String, pos: Position): Nothing = throw ParseException(msg, Some(pos)) - - def error(msg: String): Nothing = throw ParseException(msg, Some(position)) - - def error() = throw ParseException("Syntax error", Some(position)) - - def nextChar() = { - if (cursor >= length) error("Unexpected end of input") - val c = input(cursor) - cursor += 1 - if (c == '\n') { - line += 1 - column = FirstColumn - } else { - column += 1 - } - c - } - - def peekChar(): Char = { - if (cursor >= length) '\0' else input(cursor) - } - - def require(char: Char): Char = { - val pos = position - val c = nextChar() - if (c != char) error(s"Expected `$char`", pos) - c - } - def require(p: Char=>Boolean, errorMsg: String = "Unexpected character"): Char = { - val pos = position - val c = nextChar() - if (!p(c)) error(errorMsg, pos) - c - } - - def require(s: String): String = { - val c = peekChars(s.length) - if (c != s) error(s"Expected `$s`") - 1 to s.length foreach (_=>nextChar()) - s - } - - def requireAny(s: String, errorMsg: String = "Unexpected character"): Char = { - val c = nextChar() - if (s.contains(c)) c - else error(errorMsg) - } - - def peek2Chars(): String = { - peekChars(2) - } - - def peekChars(n: Int): String = { - if (cursor > length - n) input.substring(cursor) else input.substring(cursor, cursor + n) - } - - def charsWhile(pred: Char => Boolean, min: Int = 0, errorMsg: String = "Unexpected character"): String = { - val sb = new StringBuilder() - while (pred(peekChar())) { - sb += nextChar() - } - val s = sb.toString - if (s.length < min) error(errorMsg) - else s - } - - def skipNextIfMatches(c: Char): Boolean = { - if (peekChar() == c) { - nextChar() - true - } else { - false - } - } - - def either(c: Char, s: String): Unit = { - if (peekChar() == c) { - nextChar() - } else if (peekChars(s.length) == s) { - require(s) - } else { - error(s"Expected either `$c` or `$s`") - } - } - - def sepOrEnd(sep: Char, end: Char): Boolean = { - val p = position - val c = nextChar() - if (c == sep) true - else if (c==end) false - else error(s"Expected `$sep` or `$end`", p) - } - - def anyOf[T](errorMsg: String, alternatives: (()=> T)*): T = { - alternatives.foreach { t => - val p = position - try { - return t() - } catch { - case _: ParseException => restorePosition(p) - } - } - error(errorMsg) - } - - def surrounded[T](left: => Any, content: => T, right: => Any): T = { - left - val result = content - right - content - } - - def followed[T](content: => T, right: => Any): T = { - val result = content - right - content - } - - def attempt[T](content: => T): Option[T] = { - val p = position - try { - Some(content) - } catch { - case _: ParseException => None - } - } - - def opaque[T](errorMsg: String)(block: =>T) :T={ - try { - block - } catch{ - case p:ParseException => error(errorMsg, p.position) - } - } -} diff --git a/src/main/scala/millfork/parser/SourceLoadingQueue.scala b/src/main/scala/millfork/parser/SourceLoadingQueue.scala index cba2df00..4c8c21b9 100644 --- a/src/main/scala/millfork/parser/SourceLoadingQueue.scala +++ b/src/main/scala/millfork/parser/SourceLoadingQueue.scala @@ -65,14 +65,6 @@ class SourceLoadingQueue(val initialFilenames: List[String], val includePath: Li } case f@Failure(a, b, d) => ErrorReporting.error(s"Failed to parse the module `$moduleName` in $filename", Some(parser.indexToPosition(f.index, parser.lastLabel))) -// ErrorReporting.error(a.toString) -// ErrorReporting.error(b.toString) -// ErrorReporting.error(d.toString) -// ErrorReporting.error(d.traced.expected) -// ErrorReporting.error(d.traced.stack.toString) -// ErrorReporting.error(d.traced.traceParsers.toString) -// ErrorReporting.error(d.traced.fullStack.toString) -// ErrorReporting.error(f.toString) if (parser.lastLabel != "") { ErrorReporting.error(s"Syntax error: ${parser.lastLabel} expected", Some(parser.lastPosition)) } else { diff --git a/src/test/scala/millfork/test/MinimalTest.scala b/src/test/scala/millfork/test/MinimalTest.scala deleted file mode 100644 index e82c1346..00000000 --- a/src/test/scala/millfork/test/MinimalTest.scala +++ /dev/null @@ -1,23 +0,0 @@ -package millfork.test - -import fastparse.core.Mutable.Failure -import fastparse.core.Parsed.Success -import millfork.parser.MinimalTestCase -import org.scalatest.{FunSuite, Matchers} - -/** - * @author Karol Stasiak - */ -class MinimalTest extends FunSuite with Matchers { -// ignore("a") { -// MinimalTestCase.program.parse("[]\n[a,g,%h]\n") match { -// case Success(unoptimized, _) => -// println(unoptimized) -// case f:Failure[_,_] => -// val g =f -// println(f) -// println(f.originalParser) -// fail() -// } -// } -} diff --git a/src/test/scala/millfork/test/StackVarSuite.scala b/src/test/scala/millfork/test/StackVarSuite.scala index 8e5051f0..f9e65503 100644 --- a/src/test/scala/millfork/test/StackVarSuite.scala +++ b/src/test/scala/millfork/test/StackVarSuite.scala @@ -1,6 +1,6 @@ package millfork.test -import millfork.test.emu.EmuBenchmarkRun +import millfork.test.emu.{EmuBenchmarkRun, EmuUnoptimizedRun} import org.scalatest.{FunSuite, Matchers} /** @@ -54,8 +54,9 @@ class StackVarSuite extends FunSuite with Matchers { """.stripMargin)(_.readWord(0xc000) should equal(21)) } + // ERROR: (8:9) Right-hand-side expression is too complex // test("Stack byte subtraction") { -// SymonUnoptimizedRun(""" +// EmuUnoptimizedRun(""" // | byte output @$c000 // | void main () { // | stack byte a diff --git a/src/test/scala/millfork/test/emu/EmuBenchmarkRun.scala b/src/test/scala/millfork/test/emu/EmuBenchmarkRun.scala index 9188abaf..e0dea4ca 100644 --- a/src/test/scala/millfork/test/emu/EmuBenchmarkRun.scala +++ b/src/test/scala/millfork/test/emu/EmuBenchmarkRun.scala @@ -6,25 +6,15 @@ import millfork.output.MemoryBank * @author Karol Stasiak */ object EmuBenchmarkRun { - def apply(source:String)(verifier: MemoryBank=>Unit) = { + def apply(source: String)(verifier: MemoryBank => Unit) = { val (Timings(t0, _), m0) = EmuUnoptimizedRun.apply2(source) val (Timings(t1, _), m1) = EmuOptimizedRun.apply2(source) -// val (Timings(t2, _), m2) = SymonSuperOptimizedRun.apply2(source) -//val (Timings(t3, _), m3) = SymonQuantumOptimizedRun.apply2(source) println(f"Before optimization: $t0%7d") println(f"After optimization: $t1%7d") -// println(f"After quantum: $t3%7d") -// println(f"After superopt.: $t2%7d") - println(f"Gain: ${(100L*(t0-t1)/t0.toDouble).round}%7d%%") -// println(f"Quantum gain: ${(100L*(t0-t3)/t0.toDouble).round}%7d%%") -// println(f"Superopt. gain: ${(100L*(t0-t2)/t0.toDouble).round}%7d%%") + println(f"Gain: ${(100L * (t0 - t1) / t0.toDouble).round}%7d%%") println(f"Running unoptimized") verifier(m0) println(f"Running optimized") verifier(m1) -// println(f"Running quantum optimized") -// verifier(m3) -// println(f"Running superoptimized") -// verifier(m2) } }