Skip to content

Commit

Permalink
fix: run ormolu and clang-format (#1312)
Browse files Browse the repository at this point in the history
  • Loading branch information
hellerve authored Sep 15, 2021
1 parent 6a0af38 commit a4f8041
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 27 deletions.
2 changes: 1 addition & 1 deletion core/carp_float.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,5 @@ float Float_mod(float x, float y) {
}

int Float_round(float x) {
return roundf(x);
return roundf(x);
}
13 changes: 7 additions & 6 deletions core/carp_pattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -474,13 +474,14 @@ Array Pattern_match_MINUS_groups(Pattern *p, String *s) {
return a;
}

typedef struct PatternMatchResult {
int start; // negative start or end indicates a non-match
typedef struct PatternMatchResult {
int start; // negative start or end indicates a non-match
int end;
} PatternMatchResult;

PatternMatchResult Pattern_match_MINUS_from(Pattern *p, String *s, int startpos) {
PatternMatchResult result = { .start=-1, .end=-1 };
PatternMatchResult Pattern_match_MINUS_from(Pattern *p, String *s,
int startpos) {
PatternMatchResult result = {.start = -1, .end = -1};
String str = *s + startpos;
Pattern pat = *p;
int lstr = strlen(str);
Expand All @@ -494,11 +495,11 @@ PatternMatchResult Pattern_match_MINUS_from(Pattern *p, String *s, int startpos)
}
Pattern_internal_prepstate(&ms, str, lstr, pat, lpat);
do {
String res;
String res;
Pattern_internal_reprepstate(&ms);
if ((res = Pattern_internal_match(&ms, s1, pat))) {
result.start = startpos + (s1 - str);
result.end = startpos + res - str;
result.end = startpos + res - str;
break;
}
} while (s1++ < ms.src_end && !anchor);
Expand Down
2 changes: 1 addition & 1 deletion src/Commands.hs
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ commandSymPrefix :: BinaryCommandCallback
commandSymPrefix ctx (XObj (Sym (SymPath [] prefix) _) _ _) (XObj (Sym (SymPath [] suffix) st) i t) =
pure (ctx, Right (XObj (Sym (SymPath [prefix] suffix) st) i t))
commandSymPrefix ctx (XObj (Sym (SymPath ps prefix) _) _ _) (XObj (Sym (SymPath [] suffix) st) i t) =
pure (ctx, Right (XObj (Sym (SymPath (ps++[prefix]) suffix) st) i t))
pure (ctx, Right (XObj (Sym (SymPath (ps ++ [prefix]) suffix) st) i t))
commandSymPrefix ctx x (XObj (Sym (SymPath [] _) _) _ _) =
pure $ evalError ctx ("Can’t call `prefix` with " ++ pretty x) (xobjInfo x)
commandSymPrefix ctx _ x =
Expand Down
14 changes: 8 additions & 6 deletions src/Env.hs
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,14 @@ getTypeBinder = getBinder
-- Restricts the final step of a search to binders in a module's *type* environment.
findType :: Environment e => e -> SymPath -> Either EnvironmentError (TypeEnv, Binder)
findType e path = go $ find' (inj (prj e)) path
-- Make sure the binder is actually a type.
where go :: Either EnvironmentError (TypeEnv, Binder) -> Either EnvironmentError (TypeEnv, Binder)
go (Right (t, b)) = if isType (binderXObj b)
then Right (t, b)
else Left (BindingNotFound (show path) (prj e))
go x = x
where
-- Make sure the binder is actually a type.
go :: Either EnvironmentError (TypeEnv, Binder) -> Either EnvironmentError (TypeEnv, Binder)
go (Right (t, b)) =
if isType (binderXObj b)
then Right (t, b)
else Left (BindingNotFound (show path) (prj e))
go x = x

findTypeBinder :: Environment e => e -> SymPath -> Either EnvironmentError Binder
findTypeBinder e path = fmap snd (findType e path)
Expand Down
2 changes: 1 addition & 1 deletion src/InitialTypes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ initialTypes typeEnv rootEnv root = evalState (visit rootEnv root) 0
okArgs <- sequence visitedArgs
let final = XObj (Lst [fn, XObj (Arr okArgs) argsi argst, okBody]) i funcTy
pure final --(trace ("FINAL: " ++ show final) final)
-- Let bindings
-- Let bindings
[XObj LocalDef _ _, _, value] ->
visit env value
-- Unbound anonymous Fn
Expand Down
9 changes: 0 additions & 9 deletions src/Memory.hs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ manageMemory typeEnv globalEnv root =
addToLifetimesMappingsIfRef True ok -- (***)
pure r'
Left err -> pure (Left err)

visitArray :: XObj -> State MemState (Either TypeError XObj)
visitArray xobj@(ArrPat arr) =
do
Expand All @@ -86,7 +85,6 @@ manageMemory typeEnv globalEnv root =
_ <- manage typeEnv globalEnv xobj -- TODO: result is discarded here, is that OK?
pure (Right xobj)
visitArray _ = error "Must visit array."

visitStaticArray :: XObj -> State MemState (Either TypeError XObj)
visitStaticArray xobj@(StaticArrPat arr) =
do
Expand All @@ -108,7 +106,6 @@ manageMemory typeEnv globalEnv root =
put newState --(trace (show newState) newState)
pure (Right xobj)
visitStaticArray _ = error "Must visit static array."

visitList :: XObj -> State MemState (Either TypeError XObj)
visitList xobj@(XObj (Lst lst) i t) =
case lst of
Expand Down Expand Up @@ -387,7 +384,6 @@ manageMemory typeEnv globalEnv root =
in ( XObj (Lst ([matchExpr, okVisitedExpr] ++ concat okVisitedCasesWithAllDeleters)) i t,
deletersAfterTheMatch
)

-- Deref (only works in function application)
XObj (Lst [deref@(XObj Deref _ _), f]) xi xt : uargs ->
do
Expand Down Expand Up @@ -419,7 +415,6 @@ manageMemory typeEnv globalEnv root =
Right (XObj (Lst (okF : okArgs)) i t)
[] -> pure (Right xobj)
visitList _ = error "Must visit list."

visitMatchCase :: (XObj, XObj) -> State MemState (Either TypeError ((Set.Set Deleter, (XObj, XObj)), Set.Set Ty))
visitMatchCase (lhs@XObj {}, rhs@XObj {}) =
do
Expand All @@ -432,7 +427,6 @@ manageMemory typeEnv globalEnv root =
pure $ do
okVisitedRhs <- visitedRhs
pure ((postDeleters, (lhs, okVisitedRhs)), postDeps)

visitCaseLhs :: XObj -> State MemState (Either TypeError [()])
visitCaseLhs (XObj (Lst vars) _ _) =
do
Expand All @@ -448,7 +442,6 @@ manageMemory typeEnv globalEnv root =
pure (Right [])
visitCaseLhs x =
error ("Unhandled: " ++ show x)

visitLetBinding :: (XObj, XObj) -> State MemState (Either TypeError (XObj, XObj))
visitLetBinding (name, expr) =
do
Expand All @@ -458,7 +451,6 @@ manageMemory typeEnv globalEnv root =
whenRightReturn result $ do
okExpr <- visitedExpr
pure (name, okExpr)

visitArg :: XObj -> State MemState (Either TypeError XObj)
visitArg xobj@(XObj _ _ (Just _)) =
do
Expand All @@ -470,7 +462,6 @@ manageMemory typeEnv globalEnv root =
Left err -> pure (Left err)
visitArg xobj@XObj {} =
visit xobj

unmanageArg :: XObj -> State MemState (Either TypeError XObj)
unmanageArg xobj@(XObj _ _ (Just t)) =
if isManaged typeEnv globalEnv t
Expand Down
4 changes: 2 additions & 2 deletions src/Polymorphism.hs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ allImplementations typeEnv env functionName functionType =
-- just a regular function; look for it
_ -> fromRight [] ((fmap (: []) (Env.getValue env functionName)) <> pure (lookupEverywhere env functionName))
getPoly = case findPoly env functionName functionType of
Right r -> [r]
Left _ -> (lookupEverywhere env functionName)
Right r -> [r]
Left _ -> (lookupEverywhere env functionName)

-- | The various results when trying to find a function using 'findFunctionForMember'.
data FunctionFinderResult
Expand Down
2 changes: 1 addition & 1 deletion src/Scoring.hs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ depthOfType typeEnv visited selfName theType =
-- trace ("Depth of args of " ++ show argTys ++ ": " ++ show (map (visitType . Just) argTys))
--
-- The `+ 1` in the function clause below is an important band-aid.
-- Here's the issue:
-- Here's the issue:
-- When we resolve declarations, some types may reference other types
-- that have not been scored yet. When that happens, we add 500 to the
-- binder to ensure it appears later than the types we'll resolve later
Expand Down

0 comments on commit a4f8041

Please sign in to comment.