remove some redundancy, make tiny style changes

This commit is contained in:
MarcelineVQ 2020-10-11 22:18:51 -07:00
parent 0972e69287
commit 50faacf69c

View File

@ -351,17 +351,12 @@ getNewVarThatWillNotBeFreedAtEndOfBlock = do
maxLineLengthForComment : Nat maxLineLengthForComment : Nat
maxLineLengthForComment = 60 maxLineLengthForComment = 60
repeat : {ty:Type} -> (x:ty) -> Nat -> List ty
repeat x Z = []
repeat x (S k) = x :: (repeat x k)
lJust : (line:String) -> (fillPos:Nat) -> (filler:Char) -> String lJust : (line:String) -> (fillPos:Nat) -> (filler:Char) -> String
lJust line fillPos filler = lJust line fillPos filler =
case isLTE (length line) fillPos of case isLTE (length line) fillPos of
(Yes prf) => (Yes prf) =>
let missing = minus fillPos (length line) let missing = minus fillPos (length line)
fillBlock = pack (repeat filler missing) fillBlock = pack (replicate missing filler)
in in
line ++ fillBlock line ++ fillBlock
(No _) => line (No _) => line
@ -384,7 +379,7 @@ decreaseIndentation = do
indentation : {auto il : Ref IndentLevel Nat} -> Core String indentation : {auto il : Ref IndentLevel Nat} -> Core String
indentation = do indentation = do
iLevel <- get IndentLevel iLevel <- get IndentLevel
pure $ pack $ repeat ' ' (4 * iLevel) pure $ pack $ replicate (4 * iLevel) ' '
emit : {auto oft : Ref OutfileText (List String)} -> {auto il : Ref IndentLevel Nat} -> FC -> String -> Core () emit : {auto oft : Ref OutfileText (List String)} -> {auto il : Ref IndentLevel Nat} -> FC -> String -> Core ()
@ -797,14 +792,14 @@ mutual
readCCPart : Char -> String -> (String, String) readCCPart : Char -> String -> (String, String)
readCCPart b x = readCCPart b x =
let (cc, def) = break (== b) x let (cc, def) = break (== b) x
in (cc, drop 1 def) in (cc, drop 1 def)
where where
drop : Int -> String -> String drop : Int -> String -> String
drop headLength s = drop headLength s =
let len = cast (length s) let len = cast (length s)
subStrLen = len - headLength in subStrLen = len - headLength in
strSubstr headLength subStrLen s strSubstr headLength subStrLen s
extractFFILocation : (lang:String) -> List String -> Maybe (String, String) extractFFILocation : (lang:String) -> List String -> Maybe (String, String)
extractFFILocation targetLang [] = Nothing extractFFILocation targetLang [] = Nothing
@ -814,22 +809,16 @@ extractFFILocation targetLang (def :: defs) =
True => Just (readCCPart ',' pos) True => Just (readCCPart ',' pos)
False => extractFFILocation targetLang defs False => extractFFILocation targetLang defs
addCommaToList : List String -> List String
addCommaToList : List String -> Core $ List String addCommaToList [] = []
addCommaToList [] = pure [] addCommaToList (x :: xs) = (" " ++ x) :: map (", " ++) xs
addCommaToList (x :: xs) = pure $ (" " ++ x) :: !(addCommaToList' xs)
where
addCommaToList' : List String -> Core $ List String
addCommaToList' [] = pure $ []
addCommaToList' (x :: xs) = pure $ (", " ++ x) :: !(addCommaToList' xs)
functionDefSignature : {auto c : Ref Ctxt Defs} -> Name -> (args:List Int) -> Core String functionDefSignature : {auto c : Ref Ctxt Defs} -> Name -> (args:List Int) -> Core String
functionDefSignature n [] = do functionDefSignature n [] = do
let fn = (cName !(getFullName n)) let fn = (cName !(getFullName n))
pure $ "\n\nValue *" ++ fn ++ "(void)" pure $ "\n\nValue *" ++ fn ++ "(void)"
functionDefSignature n args = do functionDefSignature n args = do
argsStringList <- addCommaToList (map (\i => " Value * var_" ++ (show i)) args) let argsStringList = addCommaToList (map (\i => " Value * var_" ++ (show i)) args)
let fn = (cName !(getFullName n)) let fn = (cName !(getFullName n))
pure $ "\n\nValue *" ++ fn ++ "\n(\n" ++ (showSep "\n" (argsStringList)) ++ "\n)" pure $ "\n\nValue *" ++ fn ++ "\n(\n" ++ (showSep "\n" (argsStringList)) ++ "\n)"
@ -837,31 +826,31 @@ functionDefSignatureArglist : {auto c : Ref Ctxt Defs} -> Name -> Core String
functionDefSignatureArglist n = pure $ "Value *" ++ (cName !(getFullName n)) ++ "_arglist(Value_Arglist* arglist)" functionDefSignatureArglist n = pure $ "Value *" ++ (cName !(getFullName n)) ++ "_arglist(Value_Arglist* arglist)"
getArgsNrList : {ty:Type} -> List ty -> Nat -> Core $ List Nat getArgsNrList : {0 ty:Type} -> List ty -> Nat -> Core $ List Nat
getArgsNrList [] _ = pure [] getArgsNrList [] _ = pure []
getArgsNrList (x :: xs) k = pure $ k :: !(getArgsNrList xs (S k)) getArgsNrList (x :: xs) k = pure $ k :: !(getArgsNrList xs (S k))
cTypeOfCFType : CFType -> Core $ String cTypeOfCFType : CFType -> Core $ String
cTypeOfCFType CFUnit = pure $ ("void") cTypeOfCFType CFUnit = pure $ "void"
cTypeOfCFType CFInt = pure $ ("int") cTypeOfCFType CFInt = pure $ "int"
cTypeOfCFType CFUnsigned8 = pure $ ("uint8_t") cTypeOfCFType CFUnsigned8 = pure $ "uint8_t"
cTypeOfCFType CFUnsigned16 = pure $ ("uint16_t") cTypeOfCFType CFUnsigned16 = pure $ "uint16_t"
cTypeOfCFType CFUnsigned32 = pure $ ("uint32_t") cTypeOfCFType CFUnsigned32 = pure $ "uint32_t"
cTypeOfCFType CFUnsigned64 = pure $ ("uint64_t") cTypeOfCFType CFUnsigned64 = pure $ "uint64_t"
cTypeOfCFType CFString = pure $ ("char *") cTypeOfCFType CFString = pure $ "char *"
cTypeOfCFType CFDouble = pure $ ("double") cTypeOfCFType CFDouble = pure $ "double"
cTypeOfCFType CFChar = pure $ ("char") cTypeOfCFType CFChar = pure $ "char"
cTypeOfCFType CFPtr = pure $ ("void *") cTypeOfCFType CFPtr = pure $ "void *"
cTypeOfCFType CFGCPtr = pure $ ("void *") cTypeOfCFType CFGCPtr = pure $ "void *"
cTypeOfCFType CFBuffer = pure $ ("void *") cTypeOfCFType CFBuffer = pure $ "void *"
cTypeOfCFType CFWorld = pure $ ("void *") cTypeOfCFType CFWorld = pure $ "void *"
cTypeOfCFType (CFFun x y) = pure $ ("void *") cTypeOfCFType (CFFun x y) = pure $ "void *"
cTypeOfCFType (CFIORes x) = pure $ ("void *") cTypeOfCFType (CFIORes x) = pure $ "void *"
cTypeOfCFType (CFStruct x ys) = pure $ ("void *") cTypeOfCFType (CFStruct x ys) = pure $ "void *"
cTypeOfCFType (CFUser x ys) = pure $ ("void *") cTypeOfCFType (CFUser x ys) = pure $ "void *"
varNamesFromList : {ty:Type} -> List ty -> Nat -> Core $ List String varNamesFromList : {0 ty : Type} -> List ty -> Nat -> Core (List String)
varNamesFromList [] _ = pure [] varNamesFromList [] _ = pure []
varNamesFromList (x :: xs) k = pure $ ("var_" ++ show k) :: !(varNamesFromList xs (S k)) varNamesFromList (x :: xs) k = pure $ ("var_" ++ show k) :: !(varNamesFromList xs (S k))
@ -926,7 +915,7 @@ packCFType (CFIORes x) varName = packCFType x varName
packCFType (CFStruct x xs) varName = "makeStruct(" ++ varName ++ ")" packCFType (CFStruct x xs) varName = "makeStruct(" ++ varName ++ ")"
packCFType (CFUser x xs) varName = "makeCustomUser(" ++ varName ++ ")" packCFType (CFUser x xs) varName = "makeCustomUser(" ++ varName ++ ")"
discardLastArgument : {ty:Type} -> List ty -> List ty discardLastArgument : {0 ty:Type} -> List ty -> List ty
discardLastArgument [] = [] discardLastArgument [] = []
discardLastArgument (x :: []) = [] discardLastArgument (x :: []) = []
discardLastArgument (x :: y :: ys) = x :: (discardLastArgument (y :: ys)) discardLastArgument (x :: y :: ys) = x :: (discardLastArgument (y :: ys))
@ -967,7 +956,7 @@ createCFunctions n (MkAFun args anf) = do
increaseIndentation increaseIndentation
emit EmptyFC $ "(" emit EmptyFC $ "("
increaseIndentation increaseIndentation
commaSepArglist <- addCommaToList (map (\a => "arglist->args["++ show a ++"]") argsNrs) let commaSepArglist = addCommaToList (map (\a => "arglist->args["++ show a ++"]") argsNrs)
traverse (emit EmptyFC) commaSepArglist traverse (emit EmptyFC) commaSepArglist
decreaseIndentation decreaseIndentation
emit EmptyFC ");" emit EmptyFC ");"
@ -991,7 +980,7 @@ createCFunctions n (MkAForeign ccs fargs (CFIORes ret)) = do
(Just (fctName, lib)) => do (Just (fctName, lib)) => do
addExternalLib lib addExternalLib lib
otherDefs <- get FunctionDefinitions otherDefs <- get FunctionDefinitions
let fnDef = "Value *" ++ (cName n) ++ "(" ++ showSep ", " (repeat "Value *" (length fargs)) ++ ");" let fnDef = "Value *" ++ (cName n) ++ "(" ++ showSep ", " (replicate (length fargs) "Value *") ++ ");"
fn_arglist <- functionDefSignatureArglist n fn_arglist <- functionDefSignatureArglist n
put FunctionDefinitions ((fnDef ++ "\n") :: (fn_arglist ++ ";\n") :: otherDefs) put FunctionDefinitions ((fnDef ++ "\n") :: (fn_arglist ++ ";\n") :: otherDefs)
typeVarNameArgList <- createFFIArgList fargs typeVarNameArgList <- createFFIArgList fargs
@ -1003,7 +992,7 @@ createCFunctions n (MkAForeign ccs fargs (CFIORes ret)) = do
increaseIndentation increaseIndentation
emit EmptyFC $ "(" emit EmptyFC $ "("
increaseIndentation increaseIndentation
commaSepArglist <- addCommaToList (map (\a => "arglist->args["++ show a ++"]") !(getArgsNrList fargs Z)) let commaSepArglist = addCommaToList (map (\a => "arglist->args["++ show a ++"]") !(getArgsNrList fargs Z))
traverse (emit EmptyFC) commaSepArglist traverse (emit EmptyFC) commaSepArglist
decreaseIndentation decreaseIndentation
emit EmptyFC ");" emit EmptyFC ");"