Skip to content

Commit

Permalink
Well
Browse files Browse the repository at this point in the history
  • Loading branch information
danieljharvey committed Nov 18, 2023
1 parent dd22fdf commit 0c11caa
Show file tree
Hide file tree
Showing 57 changed files with 1,304 additions and 269 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ ghcid-smol:
ghcid-smol-test:
ghcid -c "cabal repl smol-core:test:smol-core-tests" --test "main"

.PHONY: ghcid-smol-modules-test
ghcid-smol-modules-test:
ghcid -c "cabal repl smol-modules:test:smol-modules-tests" --test "main"

.PHONY: ghcid-smol-backend-test
ghcid-smol-backend-test:
ghcid -c "cabal repl smol-backend:test:smol-backend-tests" --test "main"
Expand Down
1 change: 1 addition & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ packages:
builder/builder.cabal,
smol-backend/smol-backend.cabal,
smol-core/smol-core.cabal,
smol-modules/smol-modules.cabal,
smol-repl/smol-repl.cabal,
smol-wasm/smol-wasm.cabal,
vendored/**/*.cabal
Expand Down
27 changes: 0 additions & 27 deletions smol-core/smol-core.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -70,27 +70,6 @@ library
Smol.Core.Interpreter.Types
Smol.Core.Interpreter.Types.InterpreterError
Smol.Core.Interpreter.Types.Stack
Smol.Core.Modules.Check
Smol.Core.Modules.Dependencies
Smol.Core.Modules.FromParts
Smol.Core.Modules.Helpers
Smol.Core.Modules.Interpret
Smol.Core.Modules.Parser
Smol.Core.Modules.PrettyPrint
Smol.Core.Modules.ResolveDeps
Smol.Core.Modules.RunTests
Smol.Core.Modules.Typecheck
Smol.Core.Modules.Types
Smol.Core.Modules.Types.DefIdentifier
Smol.Core.Modules.Types.DepType
Smol.Core.Modules.Types.Entity
Smol.Core.Modules.Types.Module
Smol.Core.Modules.Types.ModuleError
Smol.Core.Modules.Types.ModuleItem
Smol.Core.Modules.Types.Test
Smol.Core.Modules.Types.TestName
Smol.Core.Modules.Types.TopLevelExpression
Smol.Core.Modules.Uses
Smol.Core.Parser
Smol.Core.Parser.DataType
Smol.Core.Parser.Expr
Expand Down Expand Up @@ -173,12 +152,6 @@ test-suite smol-core-tests
other-modules:
Test.BuiltInTypes
Test.Helpers
Test.Modules.FromPartsSpec
Test.Modules.InterpreterSpec
Test.Modules.ParserSpec
Test.Modules.ResolveDepsSpec
Test.Modules.RunTestsSpec
Test.Modules.TypecheckSpec
Test.ParserSpec
Test.Typecheck.ExhaustivenessSpec
Test.Typecheck.NestingMonadSpec
Expand Down
18 changes: 0 additions & 18 deletions smol-core/src/Smol/Core/Modules/Types.hs

This file was deleted.

1 change: 0 additions & 1 deletion smol-core/src/Smol/Core/Parser/Identifiers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import Data.Void
import Smol.Core.Parser.Shared
import Smol.Core.Typecheck.Typeclass.Types
import Smol.Core.Types
import Smol.Core.Types.ModuleName
import Text.Megaparsec

type Parser = Parsec Void Text
Expand Down
49 changes: 0 additions & 49 deletions smol-core/src/Smol/Core/Typecheck/Typeclass/Helpers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

module Smol.Core.Typecheck.Typeclass.Helpers
( recoverTypeclassUses,
constraintsFromTLE,
lookupTypeclassInstance,
matchType,
lookupTypeclass,
Expand All @@ -12,12 +11,10 @@ module Smol.Core.Typecheck.Typeclass.Helpers
recoverInstance,
specialiseConstraint,
substituteConstraint,
envFromTypecheckedModule,
addTypesToConstraint,
removeTypesFromConstraint,
applyConstraintTypes,
getTypeclassMethodNames,
getVarsInScope,
)
where

Expand All @@ -31,7 +28,6 @@ import Data.Maybe (listToMaybe, mapMaybe)
import Data.Monoid
import qualified Data.Set as S
import Smol.Core.Helpers
import Smol.Core.Modules.Types
import Smol.Core.TypeUtils
import Smol.Core.Typecheck.Shared
import Smol.Core.Typecheck.Substitute
Expand Down Expand Up @@ -227,51 +223,6 @@ specialiseConstraint classes ty (Constraint tcn _tys) = do
-- apply types
applyTypeToConstraint tc ty

constraintsFromTLE ::
TopLevelExpression ResolvedDep (Type ResolvedDep ann) ->
[Constraint ResolvedDep ann]
constraintsFromTLE tle =
(fmap . fmap) getTypeAnnotation (tleConstraints tle)

-- get input for typechecker from module
getVarsInScope ::
Module ResolvedDep (Type ResolvedDep ann) ->
M.Map (ResolvedDep Identifier) ([Constraint ResolvedDep ann], ResolvedType ann)
getVarsInScope =
M.fromList
. fmap go
. M.toList
. moExpressions
where
go (ident, tle) =
( LocalDefinition ident,
(constraintsFromTLE tle, getExprAnnotation (tleExpr tle))
)

-- make a typechecking env from a module
-- this means throwing away all the types which seems silly
envFromTypecheckedModule :: (Ord ann, Monoid ann) => Module ResolvedDep (Type ResolvedDep ann) -> TCEnv ann
envFromTypecheckedModule inputModule =
let instances =
mapKey (fmap (const mempty))
. (fmap . fmap) getTypeAnnotation
. moInstances
$ inputModule

classes = (fmap . fmap) getTypeAnnotation (moClasses inputModule)

dataTypes =
(fmap . fmap)
getTypeAnnotation
(M.mapKeys LocalDefinition (moDataTypes inputModule))
in TCEnv
{ tceVars = getVarsInScope inputModule,
tceDataTypes = dataTypes,
tceInstances = instances,
tceClasses = classes,
tceConstraints = mempty
}

addTypesToConstraint :: Constraint dep ann -> Constraint dep (Type dep ann)
addTypesToConstraint (Constraint tcn tys) =
Constraint tcn (f <$> tys)
Expand Down
18 changes: 0 additions & 18 deletions smol-core/test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,12 @@ module Main (main) where

import Test.Hspec
import qualified Test.Interpreter.InterpreterSpec
import qualified Test.Modules.CheckSpec
import qualified Test.Modules.FromPartsSpec
import qualified Test.Modules.InterpreterSpec
import qualified Test.Modules.ParserSpec
import qualified Test.Modules.PrettyPrintSpec
import qualified Test.Modules.ResolveDepsSpec
import qualified Test.Modules.RunTestsSpec
import qualified Test.Modules.TypecheckSpec
import qualified Test.ParserSpec
import qualified Test.TransformSpec
import qualified Test.Typecheck.ExhaustivenessSpec
import qualified Test.Typecheck.NestingMonadSpec
import qualified Test.Typecheck.PatternSpec
import qualified Test.Typecheck.SubtypeSpec
import qualified Test.Typecheck.ToDictionaryPassingSpec
import qualified Test.Typecheck.TypeclassSpec
import qualified Test.TypecheckSpec

Expand All @@ -28,15 +19,6 @@ main = hspec $ parallel $ do
Test.Typecheck.ExhaustivenessSpec.spec
Test.Typecheck.PatternSpec.spec
Test.Typecheck.TypeclassSpec.spec
Test.Typecheck.ToDictionaryPassingSpec.spec
Test.ParserSpec.spec
Test.Modules.CheckSpec.spec
Test.Modules.FromPartsSpec.spec
Test.Modules.InterpreterSpec.spec
Test.Modules.PrettyPrintSpec.spec
Test.Modules.ResolveDepsSpec.spec
Test.Modules.RunTestsSpec.spec
Test.Modules.TypecheckSpec.spec
Test.Modules.ParserSpec.spec
Test.TransformSpec.spec
Test.Interpreter.InterpreterSpec.spec
57 changes: 0 additions & 57 deletions smol-core/test/Test/Helpers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ module Test.Helpers
patternMatch,
getRight,
unsafeParseExpr,
unsafeParseModule,
unsafeParseModuleItems,
unsafeParseType,
unsafeParseTypedExpr,
joinText,
Expand All @@ -39,11 +37,9 @@ module Test.Helpers
unsafeParseInstanceExpr,
tcVar,
typeForComparison,
testModule,
)
where

import Control.Monad.Except
import Control.Monad.Reader
import Control.Monad.State
import Control.Monad.Writer
Expand All @@ -52,60 +48,18 @@ import Data.Functor
import qualified Data.List.NonEmpty as NE
import qualified Data.Map.Strict as M
import qualified Data.Sequence as Seq
import qualified Data.Set as S
import qualified Data.Set.NonEmpty as NES
import Data.Text (Text)
import qualified Data.Text as T
import Smol.Core
import Smol.Core.Modules.FromParts
import Smol.Core.Modules.Parser
import Smol.Core.Modules.ResolveDeps
import Smol.Core.Modules.Typecheck
import Smol.Core.Modules.Types.Module
import Smol.Core.Modules.Types.ModuleError
import Smol.Core.Modules.Types.ModuleItem
import Smol.Core.Typecheck.FromParsedExpr
import Test.BuiltInTypes (builtInTypes)

typedModule ::
(MonadError (ModuleError Annotation) m) =>
T.Text ->
m (Module ResolvedDep (Type ResolvedDep Annotation))
typedModule input = do
let moduleItems = case parseModuleAndFormatError input of
Right a -> a
_ -> error "parsing module for typeclass spec"
myModule <- moduleFromModuleParts moduleItems

let typeClasses = resolveTypeclass <$> moClasses myModule
typeclassMethods = S.fromList . M.elems . fmap tcFuncName $ typeClasses

(resolvedModule, deps) <-
modifyError ErrorInResolveDeps (resolveModuleDeps typeclassMethods myModule)

typecheckModule input resolvedModule deps

getRight :: (Show e) => Either e a -> a
getRight (Right a) = a
getRight (Left e) = error (show e)

testModule :: Module ResolvedDep (Type ResolvedDep Annotation)
testModule =
getRight $
typedModule $
joinText
[ "class Eq a { equals: a -> a -> Bool }",
"instance Eq Int { \\a -> \\b -> a == b }",
"instance Eq Bool { \\a -> \\b -> a == b }",
"instance Eq String { \\a -> \\b -> a == b }",
"instance (Eq a, Eq b) => Eq (a,b) { ",
"\\pairA -> \\pairB -> case (pairA, pairB) {((a1, b1), (a2, b2)) -> ",
"if equals a1 a2 then equals b1 b2 else False} }",
"type Natural = Suc Natural | Zero",
"class Show a { show: a -> String }",
"instance Show Natural { \\nat -> case nat { Suc n -> \"S \" + show n , _ -> \"\"} }"
]

tyBool :: (Monoid ann) => Type dep ann
tyBool = TPrim mempty TPBool

Expand Down Expand Up @@ -205,17 +159,6 @@ unsafeParseType input = case parseTypeAndFormatError input of
Right ty -> ty $> ()
Left e -> error (show e)

unsafeParseModule :: Text -> Module ParseDep ()
unsafeParseModule input =
case moduleFromModuleParts (unsafeParseModuleItems input) of
Right a -> a $> ()
Left e -> error (show e)

unsafeParseModuleItems :: Text -> [ModuleItem ()]
unsafeParseModuleItems input = case parseModuleAndFormatError input of
Right parts -> fmap void parts
Left e -> error (show e)

-- | parse a typed expr, ie parse it and fill the type with crap
unsafeParseTypedExpr :: Text -> ResolvedExpr (Type ResolvedDep Annotation)
unsafeParseTypedExpr input = case parseExprAndFormatError input of
Expand Down
2 changes: 2 additions & 0 deletions smol-modules/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist-newstyle
.direnv
5 changes: 5 additions & 0 deletions smol-modules/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Revision history for nix-basic

## 0.1.0.0 -- YYYY-mm-dd

* First version. Released on an unsuspecting world.
Loading

0 comments on commit 0c11caa

Please sign in to comment.