From 9ec8d7d723ec1c412fe2c538af7401d127d5a1d9 Mon Sep 17 00:00:00 2001 From: russoul Date: Sun, 14 Aug 2022 20:10:00 +0400 Subject: [PATCH] Update --- src/LuaCommon.idr | 2 -- src/LuaGen.idr | 45 +++++++++++++++++---------------------------- 2 files changed, 17 insertions(+), 30 deletions(-) diff --git a/src/LuaCommon.idr b/src/LuaCommon.idr index e455ecf..6f8ccdd 100644 --- a/src/LuaCommon.idr +++ b/src/LuaCommon.idr @@ -14,8 +14,6 @@ import Data.String import Data.Vect import Data.Zippable -import Libraries.Utils.Hex - infixl 100 |> ||| Flipped tightly bound function application diff --git a/src/LuaGen.idr b/src/LuaGen.idr index 0d9c214..0966410 100644 --- a/src/LuaGen.idr +++ b/src/LuaGen.idr @@ -6,7 +6,6 @@ import Compiler.CompileExpr import Core.Context import Core.Directory -import Libraries.Utils.Hex import Libraries.Utils.Path import Idris.Driver @@ -511,9 +510,9 @@ pushFrame = s <- get Stack let frame = nextFrame s let index = nextIndex s - put Stack (record{ nextFrame $= (+1) - , nextIndex = indexLowest - , stack $= (index ::) } s) + put Stack ({ nextFrame $= (+1) + , nextIndex := indexLowest + , stack $= (index ::) } s) pure (MkStackFrame frame) pushLocal : @@ -524,7 +523,7 @@ pushLocal = do s <- get Stack let i = nextIndex s - put Stack (record{nextIndex $= (+1)} s) + put Stack ({nextIndex $= (+1)} s) pure (LIndex (LLVar (frameName frame)) (LNumber (show i))) ||| Returns the number of local variables in the popped frame @@ -536,7 +535,7 @@ popFrame = let v = nextIndex s case (i <= frameLowest, stack s) of (False, (nextIndex :: other)) => do - put Stack (record{nextFrame $= (\i => i - 1), nextIndex = nextIndex, stack = other} s) + put Stack ({nextFrame $= (\i => i - 1), nextIndex := nextIndex, stack := other} s) pure (v - 1) (_, _) => throw (UserError "Attempt to pop from an empty stack") @@ -549,7 +548,7 @@ popName = if i <= indexLowest then throw (UserError "attempt to pop from an empty stack frame") else - put Stack (record{nextIndex $= (\i => i - 1)} s) + put Stack ({nextIndex $= (\i => i - 1)} s) getPreamble : @@ -581,20 +580,18 @@ addDefToPreamble name def okIfDefined = do else pure () - constantTy : Constant -> Maybe Constant -constantTy (I _) = Just IntType -constantTy (BI _) = Just IntegerType -constantTy (B8 _) = Just Bits8Type -constantTy (B16 _) = Just Bits16Type -constantTy (B32 _) = Just Bits32Type -constantTy (B64 _) = Just Bits64Type -constantTy (Str _) = Just StringType -constantTy (Ch _) = Just CharType -constantTy (Db _) = Just DoubleType +constantTy (I _) = Just (PrT IntType) +constantTy (BI _) = Just (PrT IntegerType) +constantTy (B8 _) = Just (PrT Bits8Type) +constantTy (B16 _) = Just (PrT Bits16Type) +constantTy (B32 _) = Just (PrT Bits32Type) +constantTy (B64 _) = Just (PrT Bits64Type) +constantTy (Str _) = Just (PrT StringType) +constantTy (Ch _) = Just (PrT CharType) +constantTy (Db _) = Just (PrT DoubleType) constantTy _ = Nothing - processConstant : Constant -> Core LuaExpr processConstant (I x) = pure $ LNumber (show x) processConstant (BI x) = pure $ LBigInt (show x) @@ -628,7 +625,6 @@ mkCaseImpl retn [] (Just (blockA, els)) = mkCaseImpl retn [] Nothing = pure $ mkErrorAst "Impossible else branch" - mkCase : {auto stack : Ref Stack StackSt} -> {auto frame : StackFrame} @@ -934,10 +930,6 @@ mutual -- TODO try remove in favour of forward declarions ? -- notDefined = throw $ InternalError $ "external primitive not implemented: " ++ show name processExtCall name args = processCustomExtCall name args - - - - readCCPart : String -> (String, String) readCCPart x = let (cc, def) = break (== ':') x @@ -1045,7 +1037,7 @@ mutual -- TODO try remove in favour of forward declarions ? constCaseIndex : NamedConstAlt -> LuaExpr -> Core LuaExpr constCaseIndex (MkNConstAlt const _) index = case constantTy const of - (Just IntegerType) => pure $ LPrimFn (Cast IntegerType StringType) [index] + (Just (PrT IntegerType)) => pure $ LPrimFn (Cast IntegerType StringType) [index] (Just other) => pure index Nothing => throw $ UserError ("Cannot match on " ++ show const) @@ -1210,7 +1202,6 @@ mutual -- TODO try remove in favour of forward declarions ? <+> blockA {-blockA uses those bindings-} <+> LReturn res) - processConstAlt : {auto stack : Ref Stack StackSt} -> {auto frame : StackFrame} @@ -1231,11 +1222,9 @@ mutual -- TODO try remove in favour of forward declarions ? <+> blockA <+> LReturn res) - indexConstructorArg : Nat -> LuaExpr indexConstructorArg i = LString $ "arg" ++ (show i) - processTag : Name -> Maybe Int -> String processTag n Nothing = stringifyName Global n processTag _ (Just i) = show i @@ -1413,7 +1402,7 @@ build defs outputDir term file = do strbuf <- translate defs term let luaFile = file ++ ".lua" Right () <- coreLift $ writeBufferToFile (outputDir luaFile) strbuf.get strbuf.offset - | Left err => throw $ FileErr (outputDir luaFile) err + | Left err => throw $ FileErr (outputDir luaFile) (fst err) luaExe <- coreLift getLuaExe