Skip to content

Commit

Permalink
Updated deps, removed Prim.undefined, no unused arguments.
Browse files Browse the repository at this point in the history
  • Loading branch information
Unisay committed Apr 21, 2024
1 parent e562d22 commit 9409776
Show file tree
Hide file tree
Showing 27 changed files with 238 additions and 272 deletions.
18 changes: 9 additions & 9 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 41 additions & 21 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,19 @@
flake-utils.url = "github:numtide/flake-utils";
easy-purescript-nix.url = "github:justinwoo/easy-purescript-nix";
};
outputs = { self, nixpkgs, flake-utils, haskellNix, easy-purescript-nix }:
let supportedSystems = [ "x86_64-linux" ];
in flake-utils.lib.eachSystem supportedSystems (system:
outputs =
{
self,
nixpkgs,
flake-utils,
haskellNix,
easy-purescript-nix,
}:
let
supportedSystems = [ "x86_64-linux" ];
in
flake-utils.lib.eachSystem supportedSystems (
system:
let
easy-ps = easy-purescript-nix.packages.${system};
pkgs = import nixpkgs {
Expand All @@ -21,49 +31,59 @@
src = ./.;
compiler-nix-name = "ghc98";
evalSystem = "x86_64-linux";
modules = let prof = false;
in [{
doHaddock = false;
doHoogle = false;
enableProfiling = prof;
enableLibraryProfiling = prof;
}];
modules =
let
prof = false;
in
[
{
doHaddock = false;
doHoogle = false;
enableProfiling = prof;
enableLibraryProfiling = prof;
}
];

name = "purescript-lua";

shell = {
tools = {
cabal = {};
fourmolu = {};
hlint = {};
haskell-language-server = {};
cabal = { };
fourmolu = { };
hlint = { };
haskell-language-server = { };
};
buildInputs = with pkgs; [
cachix
lua51Packages.lua
lua51Packages.luacheck
easy-ps.purs-0_15_15
easy-ps.spago
lua51Packages.lua
lua51Packages.luacheck
nil
treefmt
upx
yamlfmt
];
};

};
})
];
flake = pkgs.psluaProject.flake { };
in flake // {
in
flake
// {
legacyPackages = pkgs;
packages.default = flake.packages."pslua:exe:pslua";
packages.static = flake.ciJobs.x86_64-unknown-linux-musl.packages."pslua:exe:pslua";
});
}
);

# --- Flake Local Nix Configuration ----------------------------
nixConfig = {
extra-substituters =
[ "https://cache.iog.io" "https://purescript-lua.cachix.org" ];
extra-substituters = [
"https://cache.iog.io"
"https://purescript-lua.cachix.org"
];
extra-trusted-public-keys = [
"hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ="
"purescript-lua.cachix.org-1:yLs4ei2HtnuPtzLekOrW3xdfm95+Etw15gwgyIGTayA="
Expand Down
8 changes: 5 additions & 3 deletions lib/Language/PureScript/Backend/IR.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import Language.PureScript.PSString
, decodeStringEscaping
)
import Relude.Extra (toFst)
import Relude.Unsafe qualified as Unsafe
import Text.Megaparsec qualified as Megaparsec
import Text.Pretty.Simple (pShow)
import Text.Show (Show (..))
Expand Down Expand Up @@ -135,7 +134,10 @@ useAnnotation name = do
mkImports RepM [ModuleName]
mkImports = do
Cfn.Module {moduleName, moduleImports} gets contextModule
pure $ filter (isIncluded moduleName) (snd <$> moduleImports)
pure $
-- it's ok to always add prim as an explicit import:
-- DCE removes it if it's not used.
ModuleName "Prim" : [i | (_ann, i) moduleImports, isIncluded moduleName i]
where
isIncluded PS.ModuleName ModuleName Bool
isIncluded currentModule modname = modname /= currentModule
Expand Down Expand Up @@ -170,7 +172,7 @@ collectDataDeclarations cfnModules = Map.unions do
| bind Cfn.moduleBindings cfnModule
, Cfn.Constructor _ann tyName ctorName fields boundExp bind
]
, let ty = fst (Unsafe.head ctors) -- groupBy never makes an empty group
, let ty = fst (head (NE.fromList ctors)) -- groupBy never makes an empty group
, let algebraicType = if length ctors == 1 then ProductType else SumType
]
where
Expand Down
2 changes: 1 addition & 1 deletion lib/Language/PureScript/Backend/IR/Linker.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Data.Graph (graphFromEdges', reverseTopSort)
import Data.Map qualified as Map
import Language.PureScript.Backend.IR.Inliner qualified as Inline
import Language.PureScript.Backend.IR.Names
( ModuleName
( ModuleName (..)
, Name (..)
, PropName (PropName)
, QName (QName)
Expand Down
60 changes: 23 additions & 37 deletions lib/Language/PureScript/Backend/Lua.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ module Language.PureScript.Backend.Lua
( fromUberModule
, fromIR
, fromName
-- , qualifyName
, qualifyName
, Error (..)
) where
Expand All @@ -23,7 +22,7 @@ import Data.Traversable (for)
import Language.PureScript.Backend.IR qualified as IR
import Language.PureScript.Backend.IR.Linker (UberModule (..))
import Language.PureScript.Backend.IR.Linker qualified as Linker
import Language.PureScript.Backend.IR.Query (usesPrimModule, usesRuntimeLazy)
import Language.PureScript.Backend.IR.Query (usesRuntimeLazy)
import Language.PureScript.Backend.Lua.Fixture qualified as Fixture
import Language.PureScript.Backend.Lua.Key qualified as Key
import Language.PureScript.Backend.Lua.Linker.Foreign qualified as Foreign
Expand All @@ -32,7 +31,7 @@ import Language.PureScript.Backend.Lua.Name qualified as Name
import Language.PureScript.Backend.Lua.Types (ParamF (..))
import Language.PureScript.Backend.Lua.Types qualified as Lua
import Language.PureScript.Backend.Types (AppOrModule (..))
import Language.PureScript.Names (ModuleName, runModuleName)
import Language.PureScript.Names (ModuleName (..), runModuleName)
import Language.PureScript.Names qualified as PS
import Path (Abs, Dir, Path)
import Prelude hiding (exp, local)
Expand Down Expand Up @@ -82,13 +81,9 @@ fromUberModule foreigns needsRuntimeLazy appOrModule uber = (`evalStateT` 0) do
recBinds forM (toList recGroup) \(IR.QName modname name, irExp)
(modname,name,) . asExpression
<$> fromIR foreigns Set.empty modname irExp
let declarations = DList.fromList do
(modname, name, _exp) recBinds
pure $ mkBinding modname (fromName name) Lua.Nil
assignments = DList.fromList do
(modname, name, exp) recBinds
pure $ mkBinding modname (fromName name) exp
pure $ declarations <> assignments
pure $ DList.fromList do
(modname, name, exp) recBinds
pure $ mkBinding modname (fromName name) exp

returnExp
case appOrModule of
Expand All @@ -111,25 +106,19 @@ fromUberModule foreigns needsRuntimeLazy appOrModule uber = (`evalStateT` 0) do
)

pure . mconcat $
[ [Lua.assign moduleVar (Lua.table []) | not (null bindings)]
, [ mkBinding Fixture.primModule Fixture.undefined Lua.Nil
| usesPrimModule uber
]
, [Fixture.runtimeLazy | untag needsRuntimeLazy && usesRuntimeLazy uber]
[ [Fixture.runtimeLazy | untag needsRuntimeLazy && usesRuntimeLazy uber]
, [Fixture.objectUpdate | UsesObjectUpdate [usesObjectUpdate]]
, [Lua.local1 Fixture.moduleName (Lua.table []) | not (null bindings)]
, toList (DList.snoc bindings returnStat)
]

mkBinding ModuleName Lua.Name Lua.Exp Lua.Statement
mkBinding modname name =
Lua.assign $
Lua.VarField
(Lua.ann (Lua.var moduleVar))
(Lua.ann (Lua.varName Fixture.moduleName))
(qualifyName modname name)

moduleVar Lua.Var
moduleVar = Lua.VarName [Lua.name|M|]

asExpression Either Lua.Chunk Lua.Exp Lua.Exp
asExpression = \case
Left chunk Lua.chunkToExpression chunk
Expand Down Expand Up @@ -206,26 +195,29 @@ fromIR foreigns topLevelNames modname ir = case ir of
Lua.functionCall (Lua.varName Fixture.objectUpdateName) [obj, vals]
IR.Abs _ann param expr do
e goExp expr
luaParam
Lua.ParamNamed
<$> case param of
IR.ParamUnused _ann uniqueName "unused"
IR.ParamNamed _ann name pure (fromName name)
pure . Right $ Lua.functionDef [luaParam] [Lua.return e]
IR.App _ann expr param do
let luaParams = case param of
IR.ParamUnused _ann []
IR.ParamNamed _ann name [ParamNamed (fromName name)]
pure . Right $ Lua.functionDef luaParams [Lua.return e]
IR.App _ann expr arg do
e goExp expr
a goExp param
pure . Right $ Lua.functionCall e [a]
Right . Lua.functionCall e <$> case arg of
-- PS sometimes inserts syntetic unused argument "Prim.undefined"
IR.Ref _ann (IR.Imported (IR.ModuleName "Prim") (IR.Name "undefined")) _
pure []
_ goExp arg <&> \a [a]
IR.Ref _ann qualifiedName index
pure . Right $ case qualifiedName of
IR.Local name
| topLevelName qualifyName modname (fromName name)
, Set.member topLevelName topLevelNames
Lua.varField (Lua.var moduleVar) topLevelName
Lua.varField (Lua.varName Fixture.moduleName) topLevelName
IR.Local name
Lua.varName (fromNameWithIndex name index)
IR.Imported modname' name
Lua.varField (Lua.var moduleVar) (qualifyName modname' (fromName name))
Lua.varField
(Lua.varName Fixture.moduleName)
(qualifyName modname' (fromName name))
IR.Let _ann bindings bodyExp do
body go bodyExp
recs
Expand Down Expand Up @@ -294,11 +286,5 @@ keyCtor = Lua.String "$ctor"
--------------------------------------------------------------------------------
-- Helpers ---------------------------------------------------------------------

uniqueName MonadState Natural m Text m Lua.Name
uniqueName prefix = do
index get
modify' (+ 1)
pure $ Lua.unsafeName (prefix <> show index)

qualifyName ModuleName Lua.Name Lua.Name
qualifyName modname = Fixture.psluaName . Name.join2 (fromModuleName modname)
qualifyName modname = Name.join2 (fromModuleName modname)
Loading

0 comments on commit 9409776

Please sign in to comment.