# HG changeset patch # User Christian Urban # Date 1576346263 0 # Node ID bfc8703b15278694bffa204824f29dcfcbb2d56f # Parent 6d9c960a2b26df4ad34c23664b88e4e1c8ea90c7 updated diff -r 6d9c960a2b26 -r bfc8703b1527 handouts/ho07.pdf Binary file handouts/ho07.pdf has changed diff -r 6d9c960a2b26 -r bfc8703b1527 handouts/ho07.tex --- a/handouts/ho07.tex Sat Dec 07 00:57:23 2019 +0000 +++ b/handouts/ho07.tex Sat Dec 14 17:57:43 2019 +0000 @@ -6,13 +6,14 @@ \usepackage{../graphics} +%% add safety check on references...whether it is above 0 and below the +%% index + \begin{document} \fnote{\copyright{} Christian Urban, King's College London, 2017, 2018, 2019} \section*{Handout 7 (Compilation)} - - The purpose of a compiler is to transform a program a human can read and write into code the machine can run as fast as possible. The fastest code would be machine code the CPU can run directly, but it is often diff -r 6d9c960a2b26 -r bfc8703b1527 hws/hw09.pdf Binary file hws/hw09.pdf has changed diff -r 6d9c960a2b26 -r bfc8703b1527 hws/hw09.tex --- a/hws/hw09.tex Sat Dec 07 00:57:23 2019 +0000 +++ b/hws/hw09.tex Sat Dec 14 17:57:43 2019 +0000 @@ -60,7 +60,8 @@ } \end{lstlisting} - +\item What is the difference between a parse tree and an abstract + syntax tree? Give some simple examples for each of them. diff -r 6d9c960a2b26 -r bfc8703b1527 progs/fun_llvm.scala --- a/progs/fun_llvm.scala Sat Dec 07 00:57:23 2019 +0000 +++ b/progs/fun_llvm.scala Sat Dec 14 17:57:43 2019 +0000 @@ -138,7 +138,7 @@ val e7 = Call("foo", List(Num(3))) CPSi(e7) -val e8 = Call("foo", List(Num(3), Num(4), Aop("+", Num(5), Num(6)))) +val e8 = Call("foo", List(Aop("*", Num(3), Num(1)), Num(4), Aop("+", Num(5), Num(6)))) CPSi(e8) val e9 = Sequence(Aop("*", Var("a"), Num(3)), Aop("+", Var("b"), Num(6))) @@ -239,6 +239,16 @@ (end - start)/(i * 1.0e9) } +// for Scala 2.12 +/* +def deserialise[T](file: String) : Try[T] = { + val in = new ObjectInputStream(new FileInputStream(new File(file))) + val obj = Try(in.readObject().asInstanceOf[T]) + in.close() + obj +} +*/ + def deserialise[T](fname: String) : Try[T] = { import scala.util.Using Using(new ObjectInputStream(new FileInputStream(fname))) {