]> git.unchartedbackwaters.co.uk Git - francis/ofc.git/commitdiff
Work on expression representation.
authorFrancis Russell <francis@unchartedbackwaters.co.uk>
Thu, 29 Mar 2012 19:13:37 +0000 (20:13 +0100)
committerFrancis Russell <francis@unchartedbackwaters.co.uk>
Thu, 29 Mar 2012 19:13:37 +0000 (20:13 +0100)
src/ofc/codegen/ArrayRange.scala [new file with mode: 0644]
src/ofc/codegen/Expression.scala
src/ofc/codegen/LoopRange.scala [deleted file]
src/ofc/codegen/Record.scala [deleted file]
src/ofc/codegen/Symbol.scala
src/ofc/codegen/Type.scala [deleted file]
src/ofc/generators/onetep/PPDFunctionSet.scala

diff --git a/src/ofc/codegen/ArrayRange.scala b/src/ofc/codegen/ArrayRange.scala
new file mode 100644 (file)
index 0000000..070e394
--- /dev/null
@@ -0,0 +1,9 @@
+package ofc.codegen
+
+class ArrayRange private(name: String, count: Expression, statements: List[Statement]) extends Statement {
+  val index = UniqueUnboundVarSymbol(name)
+
+  def getIndex = index
+  def this(name: String, start: Expression, count: Expression) = this(name, start, count, List.empty)
+  def +(stat: Statement) = new ArrayRange(name, start, count, statements :+ stat)
+}
index ab49031de98244e3e464bc2ba118462f50cff9c2..303631832e8ae6924a5aae74f46904f99d2cfbe7 100644 (file)
@@ -1,3 +1,22 @@
 package ofc.codegen
 
-trait Expression
+class Expression {
+  def %(field: FieldSymbol) : Expression = new FieldAccess(this, field)
+  def readAt(index: List[Expression]) : Expression = new ArrayRead(this, index)
+  def apply(index: Expression*) : Expression = this.readAt(index.toList)
+
+  implicit def fromInt(value: Int) : Expression = new IntegerLiteral(value)
+}
+
+// Variable references
+class VarRef(symbol: VarSymbol) extends Expression
+
+// Struct and array accesses
+class FieldAccess(expression: Expression, field: FieldSymbol) extends Expression
+class ArrayRead(expression: Expression, index: List[Expression]) extends Expression
+
+// Literals
+class IntegerLiteral(value: Int) extends Expression
+object IntegerLiteral {
+  implicit def fromInt(value: Int) : Expression = new IntegerLiteral(value)
+}
diff --git a/src/ofc/codegen/LoopRange.scala b/src/ofc/codegen/LoopRange.scala
deleted file mode 100644 (file)
index 985b09e..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-package ofc.codegen
-
-class LoopRange(index: VariableSymbol, start: Expression, count: Expression, statement: Statement) extends Statement {
-}
diff --git a/src/ofc/codegen/Record.scala b/src/ofc/codegen/Record.scala
deleted file mode 100644 (file)
index c8341a1..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-package ofc.codegen
-
-class RecordType extends Type
index 5993e1997172a204509c316e1816dab86e7b1253..af5fedb8c9bfcc235e54918143d64f0d55ec8388 100644 (file)
@@ -1,4 +1,22 @@
 package ofc.codegen
 
-class Symbol(name: String)
-class VariableSymbol(name: String) extends Symbol(name)
+trait Symbol {
+  def getName : String
+}
+
+case class FieldSymbol(name: String) extends Symbol {
+  def getName = name
+}
+
+abstract class VarSymbol(name: String) extends Symbol {
+  def getName = name
+}
+
+object VarSymbol {
+  implicit def toRef(symbol: VarSymbol) = new VarRef(symbol)
+}
+
+case class DeclaredVarSymbol(name: String) extends VarSymbol(name)
+abstract class UnboundVarSymbol(name: String) extends VarSymbol(name)
+case class NamedUnboundVarSymbol(name: String) extends UnboundVarSymbol(name)
+case class UniqueUnboundVarSymbol(name: String) extends UnboundVarSymbol(name)
diff --git a/src/ofc/codegen/Type.scala b/src/ofc/codegen/Type.scala
deleted file mode 100644 (file)
index 0094ef0..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-package ofc.codegen
-
-trait Type
index 37a771d915cf7ade148614a4745bdc84fcdf1aa6..7d90ebaebb1fa1368fdf42e56220874eaa0e7d39 100644 (file)
@@ -1,10 +1,20 @@
 package ofc.generators.onetep
 import ofc.codegen._
 
-class PPDFunctionSet(val basis : String, data : String) extends FunctionSet {
+class PPDFunctionSet(val basisName: String, dataName: String) extends FunctionSet {
+  val basis = NamedUnboundVarSymbol(basisName)
+  val data =  NamedUnboundVarSymbol(dataName)
+  val numSpheres = basis % FieldSymbol("num");
+
   def getReader = {
-    new IterationTemplate(new NullStatement())
+    var sphereLoop = new ArrayRange("sphere_index", 1, numSpheres)
+    val sphereIndex = sphereLoop.getIndex
+
+    var numPPDs = (basis % FieldSymbol("n_ppds_sphere"))(sphereIndex)
+    var ppdLoop = new ArrayRange("ppd_index", 1, numPPDs)
+    new IterationTemplate(sphereLoop)
   }
+
   def getDiscreteIndices = List.empty
   def getSpatialIndices = List.empty
 /*