Skip to content

Commit

Permalink
Fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
elimirks committed Jan 24, 2021
1 parent a5bd695 commit b28ea01
Show file tree
Hide file tree
Showing 31 changed files with 112 additions and 114 deletions.
12 changes: 6 additions & 6 deletions src/CallableUtils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ evaluateTf (DefSignature tname fname args retSelf) impls params = do
(HM.lookup cname impls)
funRet <- evaluateImpl impl inferredParams
case (funRet, retSelf) of
(v@(VInferred _ _ _), True) -> applyInferredType cname v
(v@VInferred {}, True) -> applyInferredType cname v
(v, _) -> pure v
Nothing -> pure $ VInferred fname tname params
where
Expand All @@ -44,8 +44,8 @@ evaluateTf (DefSignature tname fname args retSelf) impls params = do

inferredType :: Maybe Id
inferredType = listToMaybe $
(maybeToList . classForValue . (view _2)) =<<
(filter ((== SelfArg) . (view _1)) argVals)
(maybeToList . classForValue . view _2) =<<
filter ((== SelfArg) . view _1) argVals

inferSelfArg :: Id -> (Arg, Value) -> Scoper Value
inferSelfArg cname (SelfArg, value) = applyInferredType cname value
Expand Down Expand Up @@ -80,7 +80,7 @@ fitValueToType name t v =

evaluateImpl :: FunctionImpl -> [Value] -> Scoper Value
evaluateImpl (FunctionImpl name cases typeSig) values = do
inferred <- sequence $ (uncurry $ fitValueToType name) <$> zip typeSig values
inferred <- sequence $ uncurry (fitValueToType name) <$> zip typeSig values
evaluateCases cases inferred

evaluateCases :: [FunctionCase] -> [Value] -> Scoper Value
Expand All @@ -93,7 +93,7 @@ evaluateCases cases params = runWithTempScope $ do
where
prepare :: FunctionCase -> Either String (FunctionCase, [(Id, Value)])
prepare fcase =
if (length (fcaseArgs fcase) == length params) then do
if length (fcaseArgs fcase) == length params then do
inside <- zipArgsToValues (fcaseArgs fcase) params
pure (fcase, inside)
else Left $
Expand All @@ -120,7 +120,7 @@ handleCurrying expectedLen params thingToCurry =
] newTypes
where
actualLen = length params
newArgs = (IdArg . (<> "#") . show) <$> [1..diff]
newArgs = IdArg . (<> "#") . show <$> [1..diff]
diff = expectedLen - actualLen
newParams = take (diff + 1) params
newTypes = drop actualLen $ extractTypeSig thingToCurry
Expand Down
8 changes: 4 additions & 4 deletions src/Evaluators/Assignment.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ data RAssignment a where
} -> RAssignment a

rAssPos :: Lens' (RAssignment a) SourcePos
rAssPos f ass@(RAssignment {_rAssPos}) =
rAssPos f ass@RAssignment {_rAssPos} =
(\rAssPos' -> ass {_rAssPos = rAssPos'}) <$> f _rAssPos

rAssArg :: Lens' (RAssignment a) Arg
rAssArg f ass@(RAssignment {_rAssArg}) =
rAssArg f ass@RAssignment {_rAssArg} =
(\rAssArg' -> ass {_rAssArg = rAssArg'}) <$> f _rAssArg

rAssValue :: Lens' (RAssignment a) a
rAssValue f ass@(RAssignment {_rAssValue}) =
rAssValue f ass@RAssignment {_rAssValue} =
(\rAssValue' -> ass {_rAssValue = rAssValue'}) <$> f _rAssValue

instance Evaluatable (RAssignment a) where
Expand Down Expand Up @@ -63,7 +63,7 @@ evalAssignment arg rhs = do
evaled <- eval rhs

case zipArgToValue arg evaled of
Right res -> (sequence $ uncurry addToScope <$> res) *> pure evaled
Right res -> evaled <$ sequence (uncurry addToScope <$> res)
Left err -> stackTrace err

functionCaseFits :: FunctionCase -> FunctionCase -> Bool
Expand Down
2 changes: 1 addition & 1 deletion src/Evaluators/Block.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ data RBlock = RBlock

instance Evaluatable RBlock where
getPos RBlock {rBlockPos} = rBlockPos
evaluate rcall@(RBlock {rBlockBody}) = runWithTempScope $ runBody rBlockBody
evaluate rcall@RBlock {rBlockBody} = runWithTempScope $ runBody rBlockBody

instance PrettyPrint RBlock where
prettyPrint _ = "<Shhhh this isn't a real thing>"
6 changes: 3 additions & 3 deletions src/Evaluators/Call.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ data RCall = RCall

instance Evaluatable RCall where
getPos RCall {rCallPos} = rCallPos
evaluate rcall@(RCall {rCallFun, rCallParams}) = do
evaluate rcall@RCall {rCallFun, rCallParams} = do
pushToCallStack
fun <- eval rCallFun
evaledArgs <- sequence $ eval <$> rCallParams
runFun fun evaledArgs <* popFromCallStack
where
pushToCallStack :: Scoper ()
pushToCallStack = callStack %= ((rCallPos rcall):)
pushToCallStack = callStack %= (rCallPos rcall:)

popFromCallStack :: Scoper ()
popFromCallStack = callStack %= (drop 1)
popFromCallStack = callStack %= drop 1

instance PrettyPrint RCall where
prettyPrint _ = "<function call>"
9 changes: 4 additions & 5 deletions src/Evaluators/Case.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,17 @@ runCaseBody exprs = do
sequence_ $ eval <$> beginning
eval lastExpr
where
(beginning, [lastExpr]) = splitAt ((length exprs) - 1) exprs
(beginning, [lastExpr]) = splitAt (length exprs - 1) exprs

prepare :: Value -> CaseBlock ET -> Either String ([ET], [(Id, Value)])
prepare input (CaseBlock _ arg body) = do
zipped <- zipArgToValue arg input
pure $ (body, zipped)
pure (body, zipped)

assertCbsType :: [CaseBlock ET] -> Scoper ()
assertCbsType blocks = do
(x:xs) <- sequence $ cbType <$> blocks
_ <- foldM combineType x xs
pure ()
x:xs <- sequence $ cbType <$> blocks
foldM_ combineType x xs

cbType :: CaseBlock ET -> Scoper Type
cbType (CaseBlock _ arg _) = argToType arg
2 changes: 1 addition & 1 deletion src/Evaluators/Class.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ instance Evaluatable RClass where
getPos RClass {rClassPos} = rClassPos
evaluate RClass {rClassName, rClassTypeCons} = do
addToTypeScope rClassName (VClass consNames)
unionTopScope $ convert <$> getPosValue <$> rClassTypeCons
unionTopScope $ convert . getPosValue <$> rClassTypeCons
pure unitValue
where
convert :: TypeCons -> (Id, Value)
Expand Down
2 changes: 1 addition & 1 deletion src/Evaluators/Condition.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ instance Evaluatable RCondition where
evaluate RCondition {rConditionIf, rConditionElifs, rConditionElseBody} =
evalCondition rConditionIf rConditionElifs rConditionElseBody

evalCondition :: (CondBlock ET)
evalCondition :: CondBlock ET
-> [CondBlock ET]
-> [ET]
-> Scoper Value
Expand Down
4 changes: 2 additions & 2 deletions src/Evaluators/Def.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ data RDef = RDef
_rDefBody :: [ET]
}

(makeLenses ''RDef)
makeLenses ''RDef

instance Evaluatable RDef where
getPos def = def ^. rDefPos
Expand All @@ -29,7 +29,7 @@ instance Evaluatable RDef where

instance PrettyPrint RDef where
prettyPrint (RDef _ name args body) =
"def " <> show name <> "(" <> (intercalate ", " $ prettyPrint <$> args) <> ")"
"def " <> show name <> "(" <> intercalate ", " (prettyPrint <$> args) <> ")"

runBody :: [ET] -> Scoper Value
runBody [b] = eval b
Expand Down
8 changes: 4 additions & 4 deletions src/Evaluators/Infix.hs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ evalInfix first op second = do

where
inferTypes :: Value -> Value -> Scoper (Value, Value)
inferTypes v@(VInferred _ _ _) other = inferFromOther v other
inferTypes other v@(VInferred _ _ _) = swap <$> inferFromOther v other
inferTypes v@VInferred {} other = inferFromOther v other
inferTypes other v@VInferred {} = swap <$> inferFromOther v other
inferTypes (VInt v1) (VDouble v2) =
pure (VDouble $ fromIntegral v1, VDouble v2)
inferTypes (VDouble v1) (VInt v2) =
Expand Down Expand Up @@ -88,7 +88,7 @@ genericInfixEval _ op _ = stackTrace ("Unimplemented generic infix " <> show op)

compareOrderable :: Value -> InfixOp -> Value -> Scoper Value
compareOrderable f op s =
(toBoolValue . opToComp op) <$> applyBinaryFun "compare" f s
toBoolValue . opToComp op <$> applyBinaryFun "compare" f s

applyBinaryFun :: Id -> Value -> Value -> Scoper Value
applyBinaryFun fname f s = do
Expand All @@ -101,7 +101,7 @@ intInfixEval (VInt x) InfixSub (VInt y) = pure $ VInt $ x - y
intInfixEval (VInt x) InfixMul (VInt y) = pure $ VInt $ x * y
intInfixEval (VInt x) InfixMod (VInt y) = pure $ VInt $ mod x y
intInfixEval (VInt x) InfixDiv (VInt y) =
pure $ VDouble $ (fromIntegral x) / (fromIntegral y)
pure $ VDouble $ fromIntegral x / fromIntegral y
intInfixEval (VInt x) InfixEq (VInt y) = pure $ toBoolValue $ x == y
intInfixEval (VInt x) InfixGt (VInt y) = pure $ toBoolValue $ x > y
intInfixEval (VInt x) InfixLt (VInt y) = pure $ toBoolValue $ x < y
Expand Down
16 changes: 8 additions & 8 deletions src/Evaluators/InstanceOf.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ instance Evaluatable RInstanceOf where

addAllImplementations :: [Id] -> [DefSignature] -> Scoper Value
addAllImplementations consNames defSigs = do
sequence_ $ (addImplementation className consNames defSigs)
sequence_ $ addImplementation className consNames defSigs
<$> implementations
pure unitValue

Expand All @@ -64,7 +64,7 @@ evalInstanceOf className typeName implementations = do

addAllImplementations :: [Id] -> [DefSignature] -> Scoper Value
addAllImplementations consNames defSigs = do
sequence_ $ (addImplementation className consNames defSigs)
sequence_ $ addImplementation className consNames defSigs
<$> implementations
pure unitValue

Expand All @@ -82,25 +82,25 @@ getSigArgs cname cavailable =
case find ((cname ==) . getDefSigFunName) cavailable of
Just sig -> pure $ getDefSigArgs sig
Nothing -> stackTrace $
cname <> " is not part of type " <> (getDefSigTypeName $ head cavailable)
cname <> " is not part of type " <> getDefSigTypeName (head cavailable)

markArgs :: Id -> [Id] -> [Arg] -> [Arg] -> Scoper [Arg]
markArgs cname classes argsA dargs =
sequence $ (uncurry (validateArgs cname classes)) <$> zip dargs argsA
sequence $ uncurry (validateArgs cname classes) <$> zip dargs argsA

validateArgs :: Id -> [Id] -> Arg -> Arg -> Scoper Arg
validateArgs cname _ SelfArg (IdArg argName) = pure $ TypedIdArg argName cname
validateArgs cname classes SelfArg (PatternArg pname _) | not $ elem pname classes =
validateArgs cname classes SelfArg (PatternArg pname _) | notElem pname classes =
stackTrace $ "Type constructor " <> pname <> " is not an " <> cname
validateArgs _ _ _ arg = pure arg

addBodyToScope :: Id -> Id -> Scoper Value -> [Arg] -> Scoper ()
addBodyToScope cname fname body caseArgs = do
maybeStub <- findInScope fname
case maybeStub of
Just val -> (replaceInScope fname =<< updateStub fname cname val caseArgs body)
Just val -> replaceInScope fname =<< updateStub fname cname val caseArgs body
_ -> stackTrace $ fname <> " is not in scope"

updateStub :: Id -> Id -> Value -> [Arg] -> (Scoper Value) -> Scoper Value
updateStub :: Id -> Id -> Value -> [Arg] -> Scoper Value -> Scoper Value
updateStub fname cname stub caseArgs body =
addToStub fname cname (FunctionCase caseArgs $ body) stub
addToStub fname cname (FunctionCase caseArgs body) stub
2 changes: 1 addition & 1 deletion src/Evaluators/Primitive.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ instance Evaluatable RChar where

instance Evaluatable RTuple where
getPos RTuple {rTuplePos} = rTuplePos
evaluate RTuple {rTupleElements} = VTuple <$> (sequence $ eval <$> rTupleElements)
evaluate RTuple {rTupleElements} = VTuple <$> sequence (eval <$> rTupleElements)

instance Evaluatable RList where
getPos RList {rListPos} = rListPos
Expand Down
2 changes: 1 addition & 1 deletion src/Evaluators/Type.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ instance Evaluatable RType where
evalType :: Id -> [Pos DefSignature] -> Scoper Value
evalType typeName headers = do
addToTypeScope typeName typeDef
unionTopScope $ defSigToKeyValue <$> getPosValue <$> headers
unionTopScope $ defSigToKeyValue . getPosValue <$> headers
pure unitValue
where
typeDef = VTypeDef typeName $ getPosValue <$> headers
Expand Down
8 changes: 4 additions & 4 deletions src/Interop/Char.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ import CallableUtils
import Interop.Helpers

charCompareImpl :: [Value] -> Scoper Value
charCompareImpl [(VChar first), (VChar second)] =
charCompareImpl [VChar first, VChar second] =
pure $ ordToVal $ compare first second

charStrImpl :: [Value] -> Scoper Value
charStrImpl v@[(VChar _)] = pure $ VList v
charStrImpl v@[VChar _] = pure $ VList v

charEqualsImpl :: [Value] -> Scoper Value
charEqualsImpl [(VChar first), (VChar second)] =
charEqualsImpl [VChar first, VChar second] =
pure $ toBoolValue (first == second)

charOrdImpl :: [Value] -> Scoper Value
charOrdImpl [(VChar val)] = pure $ VInt $ ord val
charOrdImpl [VChar val] = pure $ VInt $ ord val

charDefinitions :: [(Id, Id, [FunctionCase])]
charDefinitions = [
Expand Down
4 changes: 2 additions & 2 deletions src/Interop/Double.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import CallableUtils
import Interop.Helpers

doubleCompareImpl :: [Value] -> Scoper Value
doubleCompareImpl [(VDouble first), (VDouble second)] =
doubleCompareImpl [VDouble first, VDouble second] =
pure $ ordToVal $ compare first second

doubleStrImpl :: [Value] -> Scoper Value
doubleStrImpl [(VDouble value)] = pure $ VList $ VChar <$> show value
doubleStrImpl [VDouble value] = pure $ VList $ VChar <$> show value

doubleDefinitions :: [(Id, Id, [FunctionCase])]
doubleDefinitions = [
Expand Down
2 changes: 1 addition & 1 deletion src/Interop/IO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import Interop.Helpers

ioPrintStrT :: [Value] -> Scoper Value
ioPrintStrT [VList str@((VChar _):_), token] = do
liftIO $ putStrLn $ (vChr <$> str)
liftIO $ putStrLn $ vChr <$> str
pure $ VTuple [unitValue, token]

ioReadStrT :: [Value] -> Scoper Value
Expand Down
10 changes: 5 additions & 5 deletions src/Interop/Int.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ import CallableUtils
import Interop.Helpers

intCompareImpl :: [Value] -> Scoper Value
intCompareImpl [(VInt first), (VInt second)] =
intCompareImpl [VInt first, VInt second] =
pure $ ordToVal $ compare first second

intStrImpl :: [Value] -> Scoper Value
intStrImpl [(VInt value)] = pure $ VList $ VChar <$> show value
intStrImpl [VInt value] = pure $ VList $ VChar <$> show value

intChrImpl :: [Value] -> Scoper Value
intChrImpl [(VInt val)] = pure $ VChar $ chr val
intChrImpl [VInt val] = pure $ VChar $ chr val

intStrIntImpl :: [Value] -> Scoper Value
intStrIntImpl [(VList vals)] = pure $ VInt $ read $ toStr vals
intStrIntImpl [VList vals] = pure $ VInt $ read $ toStr vals
where
toStr :: [Value] -> String
toStr vals = vChr <$> vals

intDoubleIntImpl :: [Value] -> Scoper Value
intDoubleIntImpl [(VDouble value)] = pure $ VInt $ floor value
intDoubleIntImpl [VDouble value] = pure $ VInt $ floor value

intDefinitions :: [(Id, Id, [FunctionCase])]
intDefinitions = [
Expand Down
12 changes: 6 additions & 6 deletions src/Interop/List.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Data.Char (ord, chr)
import Data.List

consMapImpl :: [Value] -> Scoper Value
consMapImpl [x, (VList xs), func] = do
consMapImpl [x, VList xs, func] = do
ranHead <- runFun func [x]
ranTail <- sequence $ ree ranHead <$> xs
pure $ VList (ranHead:ranTail)
Expand All @@ -31,7 +31,7 @@ nilMapImpl :: [Value] -> Scoper Value
nilMapImpl _ = pure $ VList []

consFoldlImpl :: [Value] -> Scoper Value
consFoldlImpl [x, (VList xs), initial, folder] =
consFoldlImpl [x, VList xs, initial, folder] =
foldM nativeFolder initial (x:xs)
where
nativeFolder :: Value -> Value -> Scoper Value
Expand All @@ -41,7 +41,7 @@ nilFoldlImpl :: [Value] -> Scoper Value
nilFoldlImpl [initial, _] = pure initial

consFoldrImpl :: [Value] -> Scoper Value
consFoldrImpl [x, (VList xs), initial, folder] =
consFoldrImpl [x, VList xs, initial, folder] =
foldrM nativeFolder initial (x:xs)
where
nativeFolder :: Value -> Value -> Scoper Value
Expand Down Expand Up @@ -74,7 +74,7 @@ listWrapImpl :: [Value] -> Scoper Value
listWrapImpl [value] = pure $ VList [value]

consImpl :: [Value] -> Scoper Value
consImpl [cHead, (VList cTail)] = pure $ VList (cHead:cTail)
consImpl [cHead, VList cTail] = pure $ VList (cHead:cTail)

listAppendImpl :: [Value] -> Scoper Value
listAppendImpl [first@(VList xs), second@(VList ys)] = do
Expand All @@ -90,9 +90,9 @@ consStrImpl [VChar x, VList xs] =
pure $ VList $ [VChar '"', VChar x] <> xs <> [VChar '"']
consStrImpl [x, VList xs] = do
impl <- findImplsInScope "str" x
inner <- sequence $ (evaluateImpl impl) . pure <$> x:xs
inner <- sequence $ evaluateImpl impl . pure <$> x:xs
pure $ VList $ [VChar '['] <>
(intercalate [VChar ',', VChar ' '] $ lElements <$> inner) <>
intercalate [VChar ',', VChar ' '] (lElements <$> inner) <>
[VChar ']']

nilStrImpl :: [Value] -> Scoper Value
Expand Down
2 changes: 1 addition & 1 deletion src/Interop/Tuple.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ tupleStrImpl [VTuple []] = do
tupleStrImpl [VTuple xs] = do
inner <- sequence $ strElement <$> xs
pure $ VList $ [VChar '('] <>
(intercalate [VChar ',', VChar ' '] $ lElements <$> inner)
intercalate [VChar ',', VChar ' '] (lElements <$> inner)
<> [VChar ')']
where
strElement :: Value -> Scoper Value
Expand Down
Loading

0 comments on commit b28ea01

Please sign in to comment.