]> git.unchartedbackwaters.co.uk Git - francis/ofc.git/commitdiff
Initial work on experimental Haskell implementation.
authorFrancis Russell <francis@unchartedbackwaters.co.uk>
Wed, 12 Sep 2012 08:41:38 +0000 (09:41 +0100)
committerFrancis Russell <francis@unchartedbackwaters.co.uk>
Wed, 12 Sep 2012 08:58:03 +0000 (09:58 +0100)
65 files changed:
.gitignore
Setup.hs [new file with mode: 0644]
build.xml [deleted file]
ofc
ofc.cabal [new file with mode: 0644]
old/ofc/OFC.scala [moved from src/ofc/OFC.scala with 100% similarity]
old/ofc/codegen/AllocateStatement.scala [moved from src/ofc/codegen/AllocateStatement.scala with 100% similarity]
old/ofc/codegen/AssignStatement.scala [moved from src/ofc/codegen/AssignStatement.scala with 100% similarity]
old/ofc/codegen/Comment.scala [moved from src/ofc/codegen/Comment.scala with 100% similarity]
old/ofc/codegen/ConditionalValue.scala [moved from src/ofc/codegen/ConditionalValue.scala with 100% similarity]
old/ofc/codegen/DeallocateStatement.scala [moved from src/ofc/codegen/DeallocateStatement.scala with 100% similarity]
old/ofc/codegen/Expression.scala [moved from src/ofc/codegen/Expression.scala with 100% similarity]
old/ofc/codegen/ForLoop.scala [moved from src/ofc/codegen/ForLoop.scala with 100% similarity]
old/ofc/codegen/FortranGenerator.scala [moved from src/ofc/codegen/FortranGenerator.scala with 100% similarity]
old/ofc/codegen/FortranProperty.scala [moved from src/ofc/codegen/FortranProperty.scala with 100% similarity]
old/ofc/codegen/Function.scala [moved from src/ofc/codegen/Function.scala with 100% similarity]
old/ofc/codegen/FunctionCall.scala [moved from src/ofc/codegen/FunctionCall.scala with 100% similarity]
old/ofc/codegen/FunctionCallStatement.scala [moved from src/ofc/codegen/FunctionCallStatement.scala with 100% similarity]
old/ofc/codegen/FunctionSignature.scala [moved from src/ofc/codegen/FunctionSignature.scala with 100% similarity]
old/ofc/codegen/IfStatement.scala [moved from src/ofc/codegen/IfStatement.scala with 100% similarity]
old/ofc/codegen/Intrinsic.scala [moved from src/ofc/codegen/Intrinsic.scala with 100% similarity]
old/ofc/codegen/IterationContext.scala [moved from src/ofc/codegen/IterationContext.scala with 100% similarity]
old/ofc/codegen/NumericOperator.scala [moved from src/ofc/codegen/NumericOperator.scala with 100% similarity]
old/ofc/codegen/ScopeStatement.scala [moved from src/ofc/codegen/ScopeStatement.scala with 100% similarity]
old/ofc/codegen/Statement.scala [moved from src/ofc/codegen/Statement.scala with 100% similarity]
old/ofc/codegen/Symbol.scala [moved from src/ofc/codegen/Symbol.scala with 100% similarity]
old/ofc/codegen/Type.scala [moved from src/ofc/codegen/Type.scala with 100% similarity]
old/ofc/expression/Assignment.scala [moved from src/ofc/expression/Assignment.scala with 100% similarity]
old/ofc/expression/Dictionary.scala [moved from src/ofc/expression/Dictionary.scala with 100% similarity]
old/ofc/expression/Expression.scala [moved from src/ofc/expression/Expression.scala with 100% similarity]
old/ofc/expression/TreeBuilder.scala [moved from src/ofc/expression/TreeBuilder.scala with 100% similarity]
old/ofc/generators/Generator.scala [moved from src/ofc/generators/Generator.scala with 100% similarity]
old/ofc/generators/Onetep.scala [moved from src/ofc/generators/Onetep.scala with 100% similarity]
old/ofc/generators/onetep/Assignment.scala [moved from src/ofc/generators/onetep/Assignment.scala with 100% similarity]
old/ofc/generators/onetep/CodeGenerator.scala [moved from src/ofc/generators/onetep/CodeGenerator.scala with 100% similarity]
old/ofc/generators/onetep/DensePsincToReciprocal.scala [moved from src/ofc/generators/onetep/DensePsincToReciprocal.scala with 100% similarity]
old/ofc/generators/onetep/Dictionary.scala [moved from src/ofc/generators/onetep/Dictionary.scala with 100% similarity]
old/ofc/generators/onetep/Field.scala [moved from src/ofc/generators/onetep/Field.scala with 100% similarity]
old/ofc/generators/onetep/FieldFragment.scala [moved from src/ofc/generators/onetep/FieldFragment.scala with 100% similarity]
old/ofc/generators/onetep/Fragment.scala [moved from src/ofc/generators/onetep/Fragment.scala with 100% similarity]
old/ofc/generators/onetep/GenerationContext.scala [moved from src/ofc/generators/onetep/GenerationContext.scala with 100% similarity]
old/ofc/generators/onetep/InnerProduct.scala [moved from src/ofc/generators/onetep/InnerProduct.scala with 100% similarity]
old/ofc/generators/onetep/Laplacian.scala [moved from src/ofc/generators/onetep/Laplacian.scala with 100% similarity]
old/ofc/generators/onetep/NamedIndex.scala [moved from src/ofc/generators/onetep/NamedIndex.scala with 100% similarity]
old/ofc/generators/onetep/OnetepFunctions.scala [moved from src/ofc/generators/onetep/OnetepFunctions.scala with 100% similarity]
old/ofc/generators/onetep/OnetepTypes.scala [moved from src/ofc/generators/onetep/OnetepTypes.scala with 100% similarity]
old/ofc/generators/onetep/OnetepVariables.scala [moved from src/ofc/generators/onetep/OnetepVariables.scala with 100% similarity]
old/ofc/generators/onetep/Operand.scala [moved from src/ofc/generators/onetep/Operand.scala with 100% similarity]
old/ofc/generators/onetep/PPDFunctionSet.scala [moved from src/ofc/generators/onetep/PPDFunctionSet.scala with 100% similarity]
old/ofc/generators/onetep/ReciprocalToPsinc.scala [moved from src/ofc/generators/onetep/ReciprocalToPsinc.scala with 100% similarity]
old/ofc/generators/onetep/SPAM3.scala [moved from src/ofc/generators/onetep/SPAM3.scala with 100% similarity]
old/ofc/generators/onetep/Scalar.scala [moved from src/ofc/generators/onetep/Scalar.scala with 100% similarity]
old/ofc/generators/onetep/ScalarFragment.scala [moved from src/ofc/generators/onetep/ScalarFragment.scala with 100% similarity]
old/ofc/generators/onetep/ScalarLiteral.scala [moved from src/ofc/generators/onetep/ScalarLiteral.scala with 100% similarity]
old/ofc/generators/onetep/ScaledField.scala [moved from src/ofc/generators/onetep/ScaledField.scala with 100% similarity]
old/ofc/parser/Parser.scala [moved from src/ofc/parser/Parser.scala with 100% similarity]
old/ofc/parser/Statement.scala [moved from src/ofc/parser/Statement.scala with 100% similarity]
old/ofc/util/DirectedGraph.scala [moved from src/ofc/util/DirectedGraph.scala with 100% similarity]
old/ofc/util/Graph.scala [moved from src/ofc/util/Graph.scala with 100% similarity]
old/ofc/util/GraphBase.scala [moved from src/ofc/util/GraphBase.scala with 100% similarity]
old/ofc/util/Ordering.scala [moved from src/ofc/util/Ordering.scala with 100% similarity]
old/ofc/util/Queue.scala [moved from src/ofc/util/Queue.scala with 100% similarity]
old/ofc/util/UndirectedGraph.scala [moved from src/ofc/util/UndirectedGraph.scala with 100% similarity]
src/Main.hs [new file with mode: 0644]
src/Parsing.hs [new file with mode: 0644]

index 779e54e0939b9aaf6acb0c3f9cbfcbc801ef1165..7d33312aa21d6b225ec2b1a99f8772ab24fe5b1c 100644 (file)
@@ -1,3 +1,4 @@
 /build/
+/dist/
 ofc.jar
 .*.swp
diff --git a/Setup.hs b/Setup.hs
new file mode 100644 (file)
index 0000000..9a994af
--- /dev/null
+++ b/Setup.hs
@@ -0,0 +1,2 @@
+import Distribution.Simple
+main = defaultMain
diff --git a/build.xml b/build.xml
deleted file mode 100644 (file)
index 1da0b34..0000000
--- a/build.xml
+++ /dev/null
@@ -1,57 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-
-<project name="OFC" default="build">
-  <property name="project.dir" value="."/>
-  <property name="main.class" value="ofc.OFC"/>
-
-  <target name="init">
-    <!-- derived path names -->
-    <property name="source.dir" value="${project.dir}/src"/>
-    <property name="build.dir" value="${project.dir}/build"/>
-    <property name="scala-library.jar" location="/usr/share/java/scala-library.jar"/>
-    <property name="scala-compiler.jar" location="/usr/share/java/scala-compiler.jar"/>
-
-    <path id="build.classpath">
-      <pathelement location="${scala-library.jar}"/>
-      <pathelement location="${build.dir}"/>
-    </path>
-
-    <path id="scala.classpath">
-      <pathelement location="${scala-compiler.jar}"/>
-      <pathelement location="${scala-library.jar}"/>
-    </path>
-
-    <!-- definition for the "scalac" and "scaladoc" ant tasks -->
-    <taskdef resource="scala/tools/ant/antlib.xml" classpathref="scala.classpath">
-    </taskdef>
-  </target>
-
-  <target name="clean" depends="init" description="clean">
-    <delete dir="${build.dir}"/>
-    <delete file="ofc.jar"/>
-  </target>
-
-  <target name="build" depends="init" description="build">
-    <mkdir dir="${build.dir}"/>
-    <scalac 
-      classpathref="build.classpath"
-      srcdir="${source.dir}" 
-      destdir="${build.dir}" 
-      force="false"
-      deprecation="yes"
-      unchecked="yes"
-    >
-      <include name="**/*.scala"/>
-    </scalac>
-  </target>
-
-  <target name="jar" depends="build">
-    <jar jarfile="ofc.jar">
-      <fileset dir="${build.dir}"/>
-      <zipfileset includes="**/*.class" src="${scala-library.jar}"/>
-      <manifest>
-        <attribute name="Main-Class" value="${main.class}"/>
-      </manifest>
-    </jar>
-  </target>
-</project>
diff --git a/ofc b/ofc
index 7e8fe60e831b80795fbd92b02d7ba6265f42aa05..575df540fd7aee397ca2ef53bd6397faf2d5a201 100755 (executable)
--- a/ofc
+++ b/ofc
@@ -1,3 +1,3 @@
 #!/bin/sh
 
-scala -cp build ofc.OFC "$@"
+dist/build/ofc/ofc "$@"
diff --git a/ofc.cabal b/ofc.cabal
new file mode 100644 (file)
index 0000000..aae9fec
--- /dev/null
+++ b/ofc.cabal
@@ -0,0 +1,12 @@
+Name:                ofc
+Version:             0.1
+Description:         ONTEP Form Compiler
+Author:              Francis Russell
+Maintainer:          fpr02@doc.ic.ac.uk
+Build-Type:          Simple
+Cabal-Version:       >=1.2
+
+Executable ofc
+  Main-is:           Main.hs
+  Hs-Source-Dirs:    src
+  Build-Depends:     base, parsec >= 3
similarity index 100%
rename from src/ofc/OFC.scala
rename to old/ofc/OFC.scala
diff --git a/src/Main.hs b/src/Main.hs
new file mode 100644 (file)
index 0000000..6f11f2d
--- /dev/null
@@ -0,0 +1,17 @@
+module Main where
+import System.IO (readFile)
+import System.Environment (getArgs)
+import Parsing
+
+main :: IO()
+main = do 
+  args <- getArgs
+  contents <- readFile $ getFileName args
+  processOFL contents
+
+getFileName :: [String] -> String
+getFileName [filename] = filename
+getFileName _ = error "Usage: ofc input_file"
+
+processOFL :: String -> IO()
+processOFL input = putStrLn $ show $ parseOFL input
diff --git a/src/Parsing.hs b/src/Parsing.hs
new file mode 100644 (file)
index 0000000..80c313e
--- /dev/null
@@ -0,0 +1,66 @@
+module Parsing where
+import Text.Parsec
+import Text.Parsec.Prim
+import Text.Parsec.Token
+import Text.Parsec.Language
+import Text.Parsec.Combinator
+
+data OFL = OFL [OFLDeclaration] deriving Show
+data OFLType = Real | Function | Integer deriving Show
+data OFLIndex = FunctionIndex | SpinIndex | SpatialIndex deriving Show
+data OFLDeclaration = Declaration OFLType [OFLIndex] [String] deriving Show
+data OFLAssignment = Assign OFLExpression OFLExpression deriving Show
+data OFLExpression = Identifier String | IndexedIdentifier String [String] deriving Show
+
+oflIndexTypes = ["FunctionIndex", "SpinIndex", "SpatialIndex"]
+oflOperandTypes = ["Real", "Function", "Integer"] 
+oflKeywords = oflIndexTypes ++ oflOperandTypes
+
+
+oflDef = emptyDef{ commentStart = ""
+                 , commentEnd = ""
+                 , commentLine = "#"
+                 , nestedComments = False
+                 , identStart = letter
+                 , identLetter = alphaNum <|> oneOf "_"
+                 , caseSensitive = True
+                 , reservedNames = oflKeywords
+  }
+
+TokenParser { reserved = oflReserved
+            , whiteSpace = oflWhiteSpace
+            , identifier = oflIdentifier
+            , commaSep = oflCommaSep
+            , brackets = oflBrackets
+            , symbol = oflSymbol
+} = makeTokenParser oflDef
+
+
+parseType = foldl1 (<|>) [do { oflReserved $ show t; return t} | t <- [Real, Function, Integer]]
+parseIndex = foldl1 (<|>) [do { oflReserved $ show t; return t} | t <- [FunctionIndex, SpinIndex, SpatialIndex]]
+parseDeclaration = do { valueType <- parseType;
+                        indices <- oflBrackets $ oflCommaSep parseIndex;
+                        names <- oflCommaSep parseIdentifier;
+                        return $ Declaration valueType indices names
+                      }
+
+parseIdentifier = do {identifier <- oflIdentifier; return identifier }
+
+parseAssignment = do { lhs <- parseExpression;
+                       oflSymbol "=";
+                       rhs <- parseExpression;
+                       return $ Assign lhs rhs
+                     }
+
+parseExpression = parseIndexedIdentifier <|> parseUnindexedIdentifier
+
+
+parseUnindexedIdentifier = do { identifier <- parseIdentifier; 
+                                return $ Identifier identifier
+                              }
+
+parseIndexedIdentifier = do { identifier <- parseIdentifier; 
+                              indices <- oflBrackets $ oflCommaSep parseIdentifier; 
+                              return $ IndexedIdentifier identifier indices
+                            }
+parseOFL string = parse (oflWhiteSpace >> many1 parseDeclaration >> many1 parseAssignment) "(unknown)" string