-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from lemastero/more-modular-tested
More modular tested
- Loading branch information
Showing
12 changed files
with
201 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
module Agda.Compiler.Scala.AgdaToScalaExpr ( | ||
compileDefn | ||
) where | ||
|
||
import Agda.Compiler.Backend ( funCompiled, funClauses, Defn(..), RecordData(..)) | ||
import Agda.Syntax.Abstract.Name ( QName ) | ||
import Agda.Syntax.Common.Pretty ( prettyShow ) | ||
import Agda.Syntax.Common ( Arg(..), ArgName, Named(..) ) | ||
import Agda.Syntax.Internal ( | ||
Clause(..), DeBruijnPattern, DBPatVar(..), Dom(..), unDom, PatternInfo(..), Pattern'(..), | ||
qnameName, qnameModule, Telescope, Tele(..), Term(..), Type, Type''(..) ) | ||
import Agda.TypeChecking.Monad.Base ( Definition(..) ) | ||
import Agda.TypeChecking.Monad | ||
import Agda.TypeChecking.CompiledClause ( CompiledClauses(..), CompiledClauses'(..) ) | ||
|
||
import Agda.Compiler.Scala.ScalaExpr ( ScalaName, ScalaExpr(..) ) | ||
|
||
compileDefn :: QName -> Defn -> ScalaExpr | ||
compileDefn defName theDef = case theDef of | ||
Datatype{dataCons = dataCons} -> | ||
compileDataType defName dataCons | ||
Function{funCompiled = funDef, funClauses = fc} -> | ||
Unhandled "compileDefn Function" (show defName ++ "\n = \n" ++ show theDef) | ||
RecordDefn(RecordData{_recFields = recFields, _recTel = recTel}) -> | ||
Unhandled "compileDefn RecordDefn" (show defName ++ "\n = \n" ++ show theDef) | ||
other -> | ||
Unhandled "compileDefn other" (show defName ++ "\n = \n" ++ show theDef) | ||
|
||
compileDataType :: QName -> [QName] -> ScalaExpr | ||
compileDataType defName fields = SeAdt (showName defName) (map showName fields) | ||
|
||
showName :: QName -> ScalaName | ||
showName = prettyShow . qnameName |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
module Agda.Compiler.Scala.PrintScalaExpr ( printScalaExpr | ||
, printCaseObject | ||
, printSealedTrait | ||
, printPackage | ||
) where | ||
|
||
import Agda.Compiler.Scala.ScalaExpr ( ScalaName, ScalaExpr(..) ) | ||
|
||
printScalaExpr :: ScalaExpr -> String | ||
printScalaExpr def = case def of | ||
(SePackage pName defs) -> | ||
printPackage pName <> defsSeparator | ||
<> ( | ||
blankLine -- between package declaration and first definition | ||
<> combineLines (map printScalaExpr defs) | ||
) | ||
<> defsSeparator | ||
(SeAdt adtName adtCases) -> | ||
printSealedTrait adtName | ||
<> defsSeparator | ||
<> unlines (map (printCaseObject adtName) adtCases) | ||
(Unhandled name payload) -> "" -- for development comment out this and uncomment below | ||
-- (Unhandled name payload) -> "TODO " ++ (show name) ++ " " ++ (show payload) | ||
-- other -> "unsupported printScalaExpr " ++ (show other) | ||
|
||
printSealedTrait :: ScalaName -> String | ||
printSealedTrait adtName = "sealed trait" <> exprSeparator <> adtName | ||
|
||
printCaseObject :: ScalaName -> ScalaName -> String | ||
printCaseObject superName caseName = | ||
"case object" <> exprSeparator <> caseName <> exprSeparator <> "extends" <> exprSeparator <> superName | ||
|
||
printPackage :: ScalaName -> String | ||
printPackage pName = "package" <> exprSeparator <> pName | ||
|
||
bracket :: String -> String | ||
bracket str = "{\n" <> str <> "\n}" | ||
|
||
defsSeparator :: String | ||
defsSeparator = "\n" | ||
|
||
blankLine :: String | ||
blankLine = "\n" | ||
|
||
exprSeparator :: String | ||
exprSeparator = " " | ||
|
||
combineLines :: [String] -> String | ||
combineLines xs = unlines (filter (not . null) xs) |
Oops, something went wrong.