Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions src/Turnip/Eval/Eval.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Turnip.Eval.Util
import Turnip.Eval.Metatables
import Turnip.Eval.Closure

import Control.Monad.Except
import Control.Monad (forM_)
import Control.Monad.State
import qualified Data.Map as Map
import Data.Maybe (isJust)
Expand Down Expand Up @@ -142,7 +142,7 @@ eval (AST.Call fn args) = do
fnV <- evalHead fn
argVs <- evalArgsWithSpill args

case fnV of
case fnV of
Function ref -> callRef ref argVs
Table tref -> callMeta tref argVs
x -> throwErrorStr $ "Trying to call something that doesn't eval to a function! (" ++ show x ++ ")"
Expand Down Expand Up @@ -172,7 +172,7 @@ eval (AST.FieldRef t k) = do

where
getTableFieldWithMetatable :: TableRef -> Value -> LuaM [Value]
getTableFieldWithMetatable tr tk =
getTableFieldWithMetatable tr tk =
rawGetTableField tr tk >>= \mv -> case mv of
Just v -> return [v]
Nothing -> do
Expand Down Expand Up @@ -218,7 +218,7 @@ eval (AST.TableCons entries) = do

lift $ do
v <- evalHead ev
setTableField tr (Number (fromIntegral ix), v)
setTableField tr (Number (fromIntegral ix), v)

-- TODO - should a comma-separated expression list have a dedicated AST node
evalForExpressionList :: [AST.Expr] -> LuaM (Value, Value, Value)
Expand Down Expand Up @@ -356,7 +356,7 @@ opEqual a b

opNotEqual :: BinaryOperatorImpl
opNotEqual Nil Nil = return [Boolean False]
opNotEqual a b
opNotEqual a b
| a == b = return [Boolean False]
| otherwise = (:[]) . Boolean . not <$> eqHelper a b

Expand Down Expand Up @@ -401,7 +401,7 @@ opAnd a rhs = do
if not $ coerceToBool [a] then
return [a]
else
(:[]) <$> evalHead rhs
(:[]) <$> evalHead rhs

--------------

Expand All @@ -414,7 +414,7 @@ runUntil (h:t) f = do
EmptyBubble -> runUntil t f
-- if there was, return that bubble
x -> return x

runUntil [] _ = return EmptyBubble

execBlock :: AST.Block -> LuaM Bubble
Expand Down Expand Up @@ -482,8 +482,8 @@ execStmt (AST.For names (AST.ForIter explist) b) = do
-- A function reference is (hopefully )returned after evaluating
-- the explist
fv <- case f of
Function fref -> getFunctionData fref
_ -> throwErrorStr "The iterator is not a function"
Function fref -> getFunctionData fref
_ -> throwErrorStr "The iterator is not a function"

newCls <- makeNewTableWith . Map.fromList $ map (\n -> (Str n, Nil)) names

Expand Down Expand Up @@ -518,7 +518,7 @@ execStmt (AST.While e b) = do
-- While 'contains' the break bubble and turns it into
-- an empty one, closing the statement.
BreakBubble -> return EmptyBubble
-- Any other bubble (like return) can't be handled,
-- Any other bubble (like return) can't be handled,
-- and is forwarded.
x -> return x
else
Expand Down Expand Up @@ -616,7 +616,7 @@ assignLValue (AST.LFieldRef t k) v = do
_ -> throwErrorStr "Trying to assign to a field of non-table"
where
setTableFieldWithNewindex :: TableRef -> (Value,Value) -> LuaM ()
setTableFieldWithNewindex tr (tk, tv) =
setTableFieldWithNewindex tr (tk, tv) =
rawGetTableField tr tk >>= \mv -> case mv of
-- if key is already present, do regular insert
Just _ -> regularSet
Expand All @@ -633,5 +633,3 @@ assignLValue (AST.LFieldRef t k) v = do
Nothing -> regularSet
where
regularSet = setTableField tr (tk, tv)


8 changes: 4 additions & 4 deletions src/Turnip/Eval/TH.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ typeToName t = case t of
BooleanT -> 'Eval.Boolean

-- |Transforms a constructor Name into a pattern match for a newly introduced name
toPatName :: Name -> Q (Pat, Name)
toPatName :: Name -> Q (Pat, Name)
toPatName p = do
name <- newName "x"
liftM2 (,) (conP p [varP name]) (pure name)

typeToMatch :: TypeT -> Q (Pat, Name)
typeToMatch :: TypeT -> Q (Pat, Name)
typeToMatch = toPatName . typeToName

type Entry = (Sig, String, Name, Name)
Expand All @@ -39,7 +39,7 @@ entry sig luaName origName = do
return (sig, luaName, tempName, origName)
where
toSafeSuffix = concat . map (show . ord)

genDecls :: [Entry] -> Q [Dec]
genDecls es = concat <$> mapM (\(sig, _, tempName, origName) -> genDec sig tempName origName) es

Expand Down Expand Up @@ -67,7 +67,7 @@ genDec (Sig paramTs returnT) tempName origName = do
-- the generated function accepts one param, with a pattern of (t1 : t2 : t3 : ... : _),
-- where t1..tn are the types in its signature
inputPattern :: Q Pat
inputPattern = return $ foldr (\par pat -> ConP '(:) [par, pat]) WildP listOfPatterns
inputPattern = return $ foldr (\par pat -> ConP '(:) [] [par, pat]) WildP listOfPatterns

let
params :: Q [Exp]
Expand Down
4 changes: 2 additions & 2 deletions src/Turnip/Repl.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Text.ParserCombinators.Parsec (Parser, ParseError, parse, (<|>), try, eof
import Paths_Turnip (version)
import Data.Version (showVersion)

import Control.Monad (when, forever)
import Control.Monad.State
import System.IO
import Control.Monad.Except (catchError)
Expand Down Expand Up @@ -44,7 +45,7 @@ disableBuffering = hSetBuffering stdout NoBuffering

repl :: ReplConfig -> IO ()
repl cfg = do
disableBuffering
disableBuffering
putStrLn $ "Turnip REPL v" ++ showVersion version ++ "\n"

_ <- flip runLuaMT defaultCtx $ do
Expand Down Expand Up @@ -72,4 +73,3 @@ printError err = liftIO . putStrLn $ "Lua error " ++ show err

printParseError :: MonadIO m => ParseError -> LuaMT m ()
printParseError err = liftIO . putStrLn $ "Parse error " ++ show err

2 changes: 1 addition & 1 deletion stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# For more information, see: http://docs.haskellstack.org/en/stable/yaml_configuration/

# Specifies the GHC version and set of packages available (e.g., lts-3.5, nightly-2015-09-21, ghc-7.10.2)
resolver: lts-18.5
resolver: lts-23.22

# Local packages, usually specified by relative directory name
packages:
Expand Down
12 changes: 12 additions & 0 deletions stack.yaml.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This file was autogenerated by Stack.
# You should not edit this file by hand.
# For more information, please see the documentation at:
# https://docs.haskellstack.org/en/stable/lock_files

packages: []
snapshots:
- completed:
sha256: f8c8f95e57e436cee7c053b6f424e2c07a1020304a5583f3568cd9521443c340
size: 683838
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/23/22.yaml
original: lts-23.22