1
0
mirror of https://github.com/KarolS/millfork.git synced 2024-05-31 18:41:30 +00:00

Removal of some unused old code

This commit is contained in:
Karol Stasiak 2017-12-07 00:55:44 +01:00
parent 300dee4319
commit d95d74104f
7 changed files with 5 additions and 257 deletions

View File

@ -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._

View File

@ -1,24 +0,0 @@
package millfork.parser
import fastparse.all._
import fastparse.core
object MinimalTestCase {
def AWS: P[Unit] = "\n".rep(min = 0).opaque("<any whitespace>").log()
def EOL: P[Unit] = "\n".rep(min = 1).opaque("<line break>").log()
def identifier: P[String] = CharPred(_.isLetter).rep(min = 1).!.opaque("<identifier>").log()
def identifierWithSpace: P[String] = (identifier ~/ AWS ~/ Pass).opaque("<identifier with space>").log()
def separator: P[Unit] = ("," ~/ AWS ~/ Pass).opaque("<comma>").log()
def identifiers: P[Seq[String]] = identifierWithSpace.rep(min = 0, sep = separator)//.opaque("<separated identifiers>").log()
def array: P[Seq[String]] = ("[" ~/ AWS ~/ identifiers ~/ "]" ~/ Pass)//.opaque("<array>").log()
def arrays: Parser[Seq[Seq[String]]] = (array ~/ EOL).rep(min = 0, sep = !End ~/ Pass)//.opaque("<arrays>").log()
def program: Parser[Seq[Seq[String]]] = Start ~/ AWS ~/ arrays ~/ End
}

View File

@ -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)
}
}
}

View File

@ -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 {

View File

@ -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()
// }
// }
}

View File

@ -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

View File

@ -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)
}
}