Skip to content

Commit c3952fb

Browse files
committed
Update nix flake, README, formatting.
1 parent 47faca3 commit c3952fb

File tree

11 files changed

+122
-68
lines changed

11 files changed

+122
-68
lines changed

README.md

+44-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,58 @@
11
# Purescript Backend for Lua
22

3-
Status: (2023-07-05) the project is in the "*ready to be experimented with*" state (read: it likely contains bugs but is already usable).
3+
Status: (2023-07-05) the project is in the "_ready to be experimented with_" state (read: it likely contains bugs but is already usable).
44

55
## Features
66

77
- [x] Lua code bundling: emits either a Lua module or "App".
8-
- [X] FFI with Lua.
8+
- [x] FFI with Lua.
99
- [x] Dead Code Elimination (DCE).
1010
- [x] Code inlining.
1111
- [x] [Package Set](https://github.com/Unisay/purescript-lua-package-sets) for PureScript/Lua libs.
1212
- [x] All core libs added to the package set.
1313

1414
## Quick Start
1515

16-
For the moment the best way to start is to use `nix` to intall `pslua`.
16+
For the moment the best way to start is to use `nix` to intall `pslua`.
17+
1718
Here is an [example](https://github.com/Unisay/purescript-lua-example) project.
19+
20+
If you use [Spago](https://github.com/purescript/spago) to build your PureScript project, then you can configure `pslua` as a custom backend like this:
21+
22+
<details> <summary>spago.dhall</summary>
23+
24+
Assuming that `pslua` executable is already available on your PATH
25+
26+
```dhall
27+
{ name = "acme-project"
28+
, dependencies = [ "effect", "prelude" ]
29+
, packages = ./packages.dhall
30+
, sources = [ "src/**/*.purs" ]
31+
, backend =
32+
''
33+
pslua \
34+
--foreign-path . \
35+
--ps-output output \
36+
--lua-output-file dist/acme.lua \
37+
--entry Acme.Main
38+
''
39+
}
40+
```
41+
42+
</details>
43+
44+
### Using nix with flakes
45+
46+
```
47+
nix run 'github:Unisay/purescript-lua' -- --help
48+
```
49+
50+
## Installation
51+
52+
### Using nix with flakes
53+
54+
```
55+
nix profile install 'github:Unisay/purescript-lua'
56+
```
57+
58+
will make `pslua` executable available for use.

cabal.project

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
packages: *.cabal
2-
index-state: 2023-06-29T00:00:00Z
2+
index-state: 2023-07-04T00:00:00Z

flake.lock

+9-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

+10-10
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,22 @@
2525
src = ./.;
2626
evalSystem = "x86_64-linux";
2727
# index-state = "2023-06-28T00:00:00Z";
28-
modules =
29-
let prof = false;
30-
in [{
31-
doHaddock = false;
32-
doHoogle = false;
33-
enableProfiling = prof;
34-
enableLibraryProfiling = prof;
35-
}];
28+
modules = let prof = false;
29+
in [{
30+
doHaddock = false;
31+
doHoogle = false;
32+
enableProfiling = prof;
33+
enableLibraryProfiling = prof;
34+
}];
3635
};
3736
})
3837
];
3938
flake = pkgs.hixProject.flake { };
40-
in
41-
flake // {
39+
in flake // {
4240
legacyPackages = pkgs;
4341
packages.default = flake.packages."pslua:exe:pslua";
42+
packages.static =
43+
flake.ciJobs.x86_64-unknown-linux-musl.packages."pslua:exe:pslua";
4444
});
4545

4646
# --- Flake Local Nix Configuration ----------------------------

fourmolu.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
comma-style: leading
2+
column-limit: 80
23
diff-friendly-import-export: true
34
function-arrows: leading
45
haddock-style: multi-line

lib/Language/PureScript/Backend/IR.hs

+14-10
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,27 @@ module Language.PureScript.Backend.IR
55

66
import Control.Monad.Error.Class (MonadError (throwError))
77
import Control.Monad.Writer.Class (MonadWriter (..))
8-
import Data.Char qualified as Char
8+
import qualified Data.Char as Char
99
import Data.Foldable (foldrM)
10-
import Data.List qualified as List
10+
import qualified Data.List as List
1111
import Data.List.NonEmpty ((<|))
12-
import Data.List.NonEmpty qualified as NE
13-
import Data.Map.Lazy qualified as Map
12+
import qualified Data.List.NonEmpty as NE
13+
import qualified Data.Map.Lazy as Map
1414
import Data.Tagged (Tagged (Tagged))
15-
import Data.Text qualified as Text
15+
import qualified Data.Text as Text
1616
import Data.Traversable (for)
1717
import Language.PureScript.Backend.IR.Types
18-
import Language.PureScript.CoreFn qualified as Cfn
18+
import qualified Language.PureScript.CoreFn as Cfn
1919
import Language.PureScript.CoreFn.Laziness (applyLazinessTransform)
2020
import Language.PureScript.Names (ModuleName)
21-
import Language.PureScript.Names qualified as PS
22-
import Language.PureScript.PSString (PSString, decodeStringEither)
21+
import qualified Language.PureScript.Names as PS
22+
import Language.PureScript.PSString
23+
( PSString
24+
, decodeStringEither
25+
)
2326
import Numeric (showHex)
2427
import Relude.Extra (toFst)
25-
import Relude.Unsafe qualified as Unsafe
28+
import qualified Relude.Unsafe as Unsafe
2629
import Prelude hiding (identity)
2730

2831
data Context = Context
@@ -460,7 +463,8 @@ mkCaseClauses = mkClauses mempty
460463
let qctor =
461464
constructor
462465
& fmap renderCtorName
463-
& literalString . \case
466+
& literalString
467+
. \case
464468
Local name name
465469
Imported modname c
466470
PS.runModuleName modname <> "." <> c

nix/hix.nix

+29-24
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,41 @@
11
{ pkgs, easy-ps, ... }: {
22
name = "purescript-lua";
33
compiler-nix-name = "ghc928";
4-
# crossPlatforms = p:
5-
# pkgs.lib.optionals pkgs.stdenv.hostPlatform.isx86_64 ([ p.mingwW64 ]
6-
# ++ pkgs.lib.optionals pkgs.stdenv.hostPlatform.isLinux [ p.musl64 ]);
4+
crossPlatforms = p:
5+
pkgs.lib.optionals pkgs.stdenv.hostPlatform.isx86_64 ([ p.mingwW64 ]
6+
++ pkgs.lib.optionals pkgs.stdenv.hostPlatform.isLinux [ p.musl64 ]);
77

88
shell = {
9-
tools =
10-
let index-state = "2023-06-29T00:00:00Z";
11-
in {
12-
cabal = {
13-
inherit index-state;
14-
version = "latest";
15-
};
16-
cabal-fmt = {
17-
inherit index-state;
18-
version = "latest";
19-
};
20-
hlint = {
21-
inherit index-state;
22-
version = "latest";
23-
};
24-
haskell-language-server = {
25-
inherit index-state;
26-
version = "latest";
27-
};
9+
tools = let index-state = "2023-07-04T00:00:00Z";
10+
in {
11+
cabal = {
12+
inherit index-state;
13+
version = "latest";
2814
};
15+
cabal-fmt = {
16+
inherit index-state;
17+
version = "latest";
18+
};
19+
fourmolu = {
20+
inherit index-state;
21+
version = "0.13.0.0";
22+
};
23+
hlint = {
24+
inherit index-state;
25+
version = "latest";
26+
};
27+
haskell-language-server = {
28+
inherit index-state;
29+
version = "latest";
30+
};
31+
nixfmt = {
32+
inherit index-state;
33+
version = "latest";
34+
};
35+
};
2936
buildInputs = with pkgs; [
30-
haskellPackages.fourmolu_0_12_0_0
3137
lua53Packages.lua
3238
lua53Packages.luacheck
33-
nixpkgs-fmt
3439
purescript
3540
spago
3641
treefmt

shell.nix

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
(builtins.getFlake ("git+file://" + toString ./.)).devShells.${builtins.currentSystem}.default
1+
(builtins.getFlake
2+
("git+file://" + toString ./.)).devShells.${builtins.currentSystem}.default

test/Language/PureScript/Backend/Lua/GoldenSpec.hs

+4-2
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,10 @@ spec = do
9090
let moduleName =
9191
parent corefn
9292
& dirname
93-
& FilePath.dropTrailingPathSeparator . toFilePath
94-
& PS.ModuleName . toText
93+
& FilePath.dropTrailingPathSeparator
94+
. toFilePath
95+
& PS.ModuleName
96+
. toText
9597

9698
modulePath = parent corefn
9799
-- IR golden

test/Test/Hspec/Expectations/Pretty.hs

+7-7
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ assertEqual
3030
Assertion
3131
assertEqual preface expected actual =
3232
unless (actual == expected) do
33-
prefaceMsg `deepseq`
34-
expectedMsg `deepseq`
35-
actualMsg `deepseq`
36-
throwIO
37-
( HUnitFailure location $
38-
ExpectedButGot prefaceMsg expectedMsg actualMsg
39-
)
33+
prefaceMsg
34+
`deepseq` expectedMsg
35+
`deepseq` actualMsg
36+
`deepseq` throwIO
37+
( HUnitFailure location $
38+
ExpectedButGot prefaceMsg expectedMsg actualMsg
39+
)
4040
where
4141
prefaceMsg
4242
| null preface = Nothing

treefmt.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ options = ["--inplace"]
2020
includes = ["*.cabal"]
2121

2222
[formatter.nix]
23-
command = "nixpkgs-fmt"
23+
command = "nixfmt"
2424
includes = ["*.nix"]

0 commit comments

Comments
 (0)