updated
authorChristian Urban <christian.urban@kcl.ac.uk>
Tue, 19 Sep 2023 12:56:10 +0100
changeset 921 bb54e7aa1a3f
parent 920 7af2eea19646
child 922 e86ea06e3b25
updated
solutions/build.sh
solutions/cw2/lexer.sc
solutions/cw3/parser.sc
solutions/cw4/compiler.sc
solutions/cw5/fun_llvm.sc
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/solutions/build.sh	Tue Sep 19 12:56:10 2023 +0100
@@ -0,0 +1,49 @@
+#!/usr/bin/env -S scala-cli shebang -no-indent
+//> using scala "3.3.1"
+//> using toolkit latest
+
+// course work directories
+val cws = List("cw1", "cw2", "cw3", "cw4", "cw5")
+
+// main files that need testing
+val files = Map("cw1" -> "cw1.sc", 
+                "cw2" -> "lexer.sc",
+		 		"cw3" -> "parser.sc",
+		 		"cw4" -> "compiler.sc",
+		 		"cw5" -> "fun_llvm.sc"
+		)
+
+// test files used as input
+val test_files = Map(
+    "cw1" -> Nil,
+    "cw2" -> List("collatz.while",
+		  "collatz2.while",
+		  "factors.while",
+		  "fib.while",
+		  "loops.while",
+		  "primes.while"),
+    "cw3" -> List("collatz.while",
+		  "collatz2.while",
+		  "factors.while",
+		  "fib.while",
+		  "loops.while",
+		  "primes.while"),
+    "cw4" -> List("collatz2.while",
+		  "fib.while",
+		  "forloop.while",
+		  "forloop2.while"),
+    "cw5" -> List("fact.fun",
+		  	"hanoi.fun",
+		    "mand.fun",
+			"mand2.fun")
+)   
+
+
+for (cw <- cws) {
+	val main_file = files(cw)
+	for (arg <- test_files(cw)) {
+		println(s"Testing $cw/$main_file with $arg")
+		val subdir = os.pwd / cw
+		os.proc("amm", main_file, "test", arg).call(cwd = subdir)
+	}
+}
--- a/solutions/cw2/lexer.sc	Tue Sep 19 09:54:41 2023 +0100
+++ b/solutions/cw2/lexer.sc	Tue Sep 19 12:56:10 2023 +0100
@@ -375,3 +375,20 @@
 println(size(ders_simp("r".toList, WHILE_REGS)))
 println(size(ID))
 println(size(ders_simp("read".toList, ID)))
+
+
+
+// for automated testing
+
+@main
+def main(file: String) = {
+  // empty - nothing to run
+}
+
+@main
+def test(file: String) = {
+  val contents = os.read(os.pwd / file)
+  tokenise(contents)
+}
+
+
--- a/solutions/cw3/parser.sc	Tue Sep 19 09:54:41 2023 +0100
+++ b/solutions/cw3/parser.sc	Tue Sep 19 12:56:10 2023 +0100
@@ -245,7 +245,7 @@
 def eval(bl: Block) : Env = eval_bl(bl, Map())
 
 @main
-def main(file: String) = {
+def run(file: String) = {
   val contents = os.read(os.pwd / file)
   println(s"Lex $file: ")
   println(tokenise(contents))
@@ -255,6 +255,15 @@
   println(eval(Stmts.parse_all(tokenise(contents)).head))
 }
 
+@main
+def test(file: String) = {
+  val contents = os.read(os.pwd / file)
+  println(s"Lex $file: ")
+  println(tokenise(contents))
+  println(s"Parse $file: ")
+  println(Stmts.parse_all(tokenise(contents)).head)
+}
+
 /*
 println("Loops eval")
 val start = System.nanoTime()
--- a/solutions/cw4/compiler.sc	Tue Sep 19 09:54:41 2023 +0100
+++ b/solutions/cw4/compiler.sc	Tue Sep 19 12:56:10 2023 +0100
@@ -280,4 +280,23 @@
 
 
 println(tokenise(os.read(os.pwd / "forloop.while")))
-compile_run(Stmts.parse_all(tokenise(os.read(os.pwd / "forloop.while"))).head, "forloop")
\ No newline at end of file
+compile_all(Stmts.parse_all(tokenise(os.read(os.pwd / "forloop.while"))).head, "forloop")
+
+
+
+// for automated testing
+
+@main
+def main(file: String) = {
+  // empty - nothing to run
+}
+
+@main
+def test(file: String) = {
+  val contents = os.read(os.pwd / file)
+  val class_name = file.stripSuffix(".")
+  compile_all(Stmts.parse_all(tokenise(os.read(os.pwd / file))).head, class_name)
+  tokenise(contents)
+}
+
+
--- a/solutions/cw5/fun_llvm.sc	Tue Sep 19 09:54:41 2023 +0100
+++ b/solutions/cw5/fun_llvm.sc	Tue Sep 19 12:56:10 2023 +0100
@@ -365,3 +365,7 @@
 }
 
 
+// for automated testing 
+
+@main
+def test(fname: String) = write(fname)