mirror of
https://github.com/anoma/juvix.git
synced 2024-12-14 17:32:00 +03:00
60236e7b58
* [cbackend] Adds an AST for C This should cover enough C to implement the microjuvix backend. * [cbackend] Add C serializer using language-c library We may decide to write our own serializer for the C AST but this demonstrates that the C AST is sufficient at least. * [cbackend] Declarations will always be typed * [cbackend] Add CPP support to AST * [cbackend] Rename some names for clarity * [cbackend] Add translation of InductiveDef to C * [cbackend] Add CLI for C backend * [cbackend] Add stdbool.h to file header * [cbackend] Allow Cpp and Verbatim code inline * [cbackend] Add a newline after printing C * [cbackend] Support foreign blocks * [cbackend] Add support for axioms * [cbackend] Remove code examples * [cbackend] wip FunctionDef including Expressions * [parser] Support esacping '}' inside a foreign block * [cbackend] Add support for patterns in functions * [cbackend] Add foreign C support to HelloWorld.mjuvix * hlint fixes * More hlint fixes not picked up by pre-commit * [cbackend] Remove CompileStatement from MonoJuvix * [cbackend] Add support for compile blocks * [cbackend] Move compileInfo extraction to MonoJuvixResult * [minihaskell] Fix compile block support * [chore] Remove ununsed isBackendSupported function * [chore] Remove unused imports * [cbackend] Use a Reader for pattern bindings * [cbackend] Fix compiler warnings * [cbackend] Add support for nested patterns * [cbackend] Use functions to instantiate argument names * [cbackend] Add non-exhaustive pattern error message * [cbackend] Adds test for c to WASM compile and execution * [cbackend] Add links to test dependencies in quickstart * [cbackend] Add test with inductive types and patterns * [cbackend] Fix indentation * [cbackend] Remove ExpressionTyped case https://github.com/heliaxdev/minijuvix/issues/79 * [lexer] Fix lexing of \ inside a foreign block * [cbackend] PR review fixes * [chore] Remove unused import * [cbackend] Rename CJuvix to MiniC * [cbackend] Rename MonoJuvixToC to MonoJuvixToMiniC * [cbackend] Add test for polymorphic function * [cbackend] Add module for string literals
149 lines
4.2 KiB
Haskell
149 lines
4.2 KiB
Haskell
module Scope.Positive where
|
|
|
|
import Base
|
|
import Data.HashMap.Strict qualified as HashMap
|
|
import MiniJuvix.Internal.NameIdGen
|
|
import MiniJuvix.Pipeline
|
|
import MiniJuvix.Syntax.Concrete.Parser qualified as Parser
|
|
import MiniJuvix.Syntax.Concrete.Scoped.Pretty.Text qualified as M
|
|
import MiniJuvix.Syntax.Concrete.Scoped.Scoper qualified as Scoper
|
|
import MiniJuvix.Syntax.Concrete.Scoped.Utils
|
|
|
|
data PosTest = PosTest
|
|
{ _name :: String,
|
|
_relDir :: FilePath,
|
|
_file :: FilePath
|
|
}
|
|
|
|
makeLenses ''PosTest
|
|
|
|
root :: FilePath
|
|
root = "tests/positive"
|
|
|
|
testDescr :: PosTest -> TestDescr
|
|
testDescr PosTest {..} =
|
|
let tRoot = root </> _relDir
|
|
in TestDescr
|
|
{ _testName = _name,
|
|
_testRoot = tRoot,
|
|
_testAssertion = Steps $ \step -> do
|
|
let entryPoint = EntryPoint "." (pure _file)
|
|
|
|
step "Parsing"
|
|
p :: Parser.ParserResult <- runIO (upToParsing entryPoint)
|
|
|
|
let p2 = head (p ^. Parser.resultModules)
|
|
|
|
step "Scoping"
|
|
s :: Scoper.ScoperResult <- runIO (pipelineScoper p)
|
|
|
|
let s2 = head (s ^. Scoper.resultModules)
|
|
|
|
let fs :: HashMap FilePath Text
|
|
fs =
|
|
HashMap.fromList
|
|
[ (getModuleFilePath m, M.renderPrettyCodeDefault m)
|
|
| m <- toList (getAllModules s2)
|
|
]
|
|
|
|
let scopedPretty = M.renderPrettyCodeDefault s2
|
|
let parsedPretty = M.renderPrettyCodeDefault p2
|
|
|
|
step "Parsing pretty scoped"
|
|
let fs2 = HashMap.singleton _file scopedPretty
|
|
p' :: Parser.ParserResult <- (runM . runErrorIO @AJuvixError . runNameIdGen . runFilesPure fs2) (upToParsing entryPoint)
|
|
|
|
step "Parsing pretty parsed"
|
|
let fs3 = HashMap.singleton _file parsedPretty
|
|
parsedPretty' :: Parser.ParserResult <- (runM . runErrorIO @AJuvixError . runNameIdGen . runFilesPure fs3) (upToParsing entryPoint)
|
|
|
|
step "Scoping the scoped"
|
|
s' :: Scoper.ScoperResult <- (runM . runErrorIO @AJuvixError . runNameIdGen . runFilesPure fs) (upToScoping entryPoint)
|
|
|
|
step "Checks"
|
|
let smodules = s ^. Scoper.resultModules
|
|
let smodules' = s' ^. Scoper.resultModules
|
|
|
|
let pmodules = p ^. Parser.resultModules
|
|
let pmodules' = p' ^. Parser.resultModules
|
|
let parsedPrettyModules = parsedPretty' ^. Parser.resultModules
|
|
|
|
assertEqDiff "check: scope . parse . pretty . scope . parse = scope . parse" smodules smodules'
|
|
assertEqDiff "check: parse . pretty . scope . parse = parse" pmodules pmodules'
|
|
assertEqDiff "check: parse . pretty . parse = parse" pmodules parsedPrettyModules
|
|
}
|
|
|
|
allTests :: TestTree
|
|
allTests =
|
|
testGroup
|
|
"Scope positive tests"
|
|
(map (mkTest . testDescr) tests)
|
|
|
|
tests :: [PosTest]
|
|
tests =
|
|
[ PosTest
|
|
"Inductive"
|
|
"."
|
|
"Inductive.mjuvix",
|
|
PosTest
|
|
"Imports and qualified names"
|
|
"Imports"
|
|
"A.mjuvix",
|
|
PosTest
|
|
"Data.Bool from the stdlib"
|
|
"StdlibList"
|
|
"Data/Bool.mjuvix",
|
|
PosTest
|
|
"Data.Nat from the stdlib"
|
|
"StdlibList"
|
|
"Data/Nat.mjuvix",
|
|
PosTest
|
|
"Data.Ord from the stdlib"
|
|
"StdlibList"
|
|
"Data/Ord.mjuvix",
|
|
PosTest
|
|
"Data.Product from the stdlib"
|
|
"StdlibList"
|
|
"Data/Product.mjuvix",
|
|
PosTest
|
|
"Data.List and friends from the stdlib"
|
|
"StdlibList"
|
|
"Data/List.mjuvix",
|
|
PosTest
|
|
"Operators (+)"
|
|
"."
|
|
"Operators.mjuvix",
|
|
PosTest
|
|
"Literals"
|
|
"."
|
|
"Literals.mjuvix",
|
|
PosTest
|
|
"Hello World backends"
|
|
"."
|
|
"HelloWorld.mjuvix",
|
|
PosTest
|
|
"Axiom with backends"
|
|
"."
|
|
"Axiom.mjuvix",
|
|
PosTest
|
|
"Foreign block parsing"
|
|
"."
|
|
"Foreign.mjuvix",
|
|
PosTest
|
|
"Multiple modules non-ambiguous symbol - same file"
|
|
"QualifiedSymbol"
|
|
"M.mjuvix",
|
|
PosTest
|
|
"Multiple modules non-ambiguous symbol"
|
|
"QualifiedSymbol2"
|
|
"N.mjuvix",
|
|
PosTest
|
|
"Multiple modules constructor non-ambiguous symbol"
|
|
"QualifiedConstructor"
|
|
"M.mjuvix",
|
|
PosTest
|
|
"open overrides open public"
|
|
"."
|
|
"ShadowPublicOpen.mjuvix"
|
|
]
|