package ofc.generators
import ofc.parser
+import ofc.generators.onetep._
import ofc.InvalidInputException
-import scala.collection.mutable.HashMap
import scala.reflect.Manifest
import scala.reflect.Manifest.singleType
-trait Matrix
-trait FunctionSet
-
-class SPAM3(name : String) extends Matrix
-class PPDFunctionSet(basis : String, data : String) extends FunctionSet
-class NamedIndex(name : String)
-
-class Dictionary {
- var matrices = new HashMap[parser.Identifier, Matrix]
- var functionSets = new HashMap[parser.Identifier, FunctionSet]
-
- var indices = new HashMap[parser.Identifier, NamedIndex]
-}
-
class Onetep extends Generator {
var dictionary = new Dictionary
def acceptInput(program : List[parser.Statement]) = {
println(program.mkString("\n") + "\n")
buildDictionary(program)
- buildDefinition(program)
+ buildDefinitions(program)
}
def filterStatements[T <: parser.Statement](statements : List[parser.Statement])(implicit m: Manifest[T]) =
}
}
- def buildNamedIndex(id: parser.Identifier, call : Option[parser.FunctionCall]) {
+ def buildBindingIndex(id: parser.Identifier, call : Option[parser.FunctionCall]) {
call match {
case Some(_) => throw new InvalidInputException("Index "+id.name+" cannot have concrete type.")
- case None => dictionary.indices += (id -> new NamedIndex(id.name))
+ case None => dictionary.indices += (id -> new BindingIndex(id.name))
}
}
val declarations = getDeclarations(statements)
for(d <- declarations) {
-
// Find corresponding target-specific declaration if it exists.
val targetDeclarationCall = targetDeclarations.filter(_.id == d._1) match {
case List(x) => Some(x.value)
d match {
case (id, parser.Matrix()) => buildMatrix(id, targetDeclarationCall)
case (id, parser.FunctionSet()) => buildFunctionSet(id, targetDeclarationCall)
- case (id, parser.Index()) => buildNamedIndex(id, targetDeclarationCall)
+ case (id, parser.Index()) => buildBindingIndex(id, targetDeclarationCall)
}
}
}
- def buildDefinition(statements : List[parser.Statement]) {
+ def buildDefinition(definition : parser.Definition) {
+ println(definition)
+ val builder = new TreeBuilder(dictionary)
+ builder(definition.term, definition.expr)
+ }
+
+ def buildDefinitions(statements : List[parser.Statement]) {
+ val definitions = filterStatements[parser.Definition](statements)
+ if (definitions.size != 1)
+ throw new InvalidInputException("Input file should only contain a single definition.")
+ else
+ buildDefinition(definitions.head)
}
}
--- /dev/null
+package ofc.generators.onetep
+
+import scala.collection.mutable.{HashMap,Set}
+import ofc.parser
+import ofc.parser.Identifier
+import ofc.InvalidInputException
+
+trait Index
+trait SpatialIndex
+trait DiscreteIndex
+
+trait DataSpace
+{
+ def getIndices() : Set[Index]
+}
+
+trait Matrix extends DataSpace
+trait FunctionSet extends DataSpace
+
+class SPAM3(name : String) extends Matrix {
+ def getIndices() = Set[Index]()
+}
+
+class PPDFunctionSet(basis : String, data : String) extends FunctionSet {
+ def getIndices() = Set[Index]()
+}
+
+class Restriction
+class Reciprocal
+class Pointwise
+class Summation
+
+class BindingIndex(name : String)
+
+class Dictionary {
+ var matrices = new HashMap[Identifier, Matrix]
+ var functionSets = new HashMap[Identifier, FunctionSet]
+ var indices = new HashMap[Identifier, BindingIndex]
+
+ def getData(id: Identifier) =
+ matrices.get(id) match {
+ case Some(mat) => mat
+ case None => functionSets.get(id) match {
+ case Some(functionSet) => functionSet
+ case None => throw new InvalidInputException("Unknown identifier "+id.name)
+ }
+ }
+
+ def getIndex(id: Identifier) =
+ indices.get(id) match {
+ case Some(index) => index
+ case None => throw new InvalidInputException("Unknown index "+id.name)
+ }
+}
+
+class Definition(lhs: DataSpace, rhs: DataSpace)
+
+class IndexBindings {
+ var bindings = new HashMap[BindingIndex, Set[Index]]
+
+ def add(binding: BindingIndex, index: Index) = bindings(binding) += index
+}
+
+class TreeBuilder(dictionary : Dictionary) {
+
+ val indexBindings = new IndexBindings
+
+ def apply(lhs: parser.IndexedTerm, rhs: parser.Expression) {
+ buildIndexedTerm(lhs)
+ }
+
+ def buildIndexedTerm(term: parser.IndexedTerm) {
+ val dataSpace = dictionary.getData(term.id)
+ val indices = for(bindingID <- term.indices) yield dictionary.getIndex(bindingID)
+ print(indices)
+ }
+}