Skip to content
Merged
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
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@ jobs:
run: if [ -f scripts/test ]; then nix develop -c bash ./scripts/test; fi

- name: Luacheck
run: nix develop -c luacheck --quiet --std lua51 --no-unused-args src/
run: nix develop -c luacheck --quiet --std lua51 --no-unused-args --max-line-length 130 src/

- name: Format check
run: nix fmt && git diff --exit-code
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/.*
!/.gitignore
!/.github/
!/.tidyrc.json
!/.lua-format
/output/
10 changes: 10 additions & 0 deletions .lua-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# LuaFormatter config for the hand-written FFI under src/.
# 2-space indent. Keep simple functions on one line; column_limit sits a few
# columns under luacheck's 130 limit because lua-format under-counts the leading
# indent and trailing comma, so this keeps every emitted line within 130.
indent_width: 2
use_tab: false
column_limit: 126
continuation_indent_width: 2
keep_simple_function_one_line: true
keep_simple_control_block_one_line: true
10 changes: 10 additions & 0 deletions .tidyrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"importSort": "source",
"importWrap": "source",
"indent": 2,
"operatorsFile": null,
"ribbon": 1,
"typeArrowPlacement": "first",
"unicode": "source",
"width": 80
}
16 changes: 13 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,21 @@ A PureScript→Lua FFI fork in the [`purescript-lua`](https://github.com/purescr

## Commands

All commands run inside the nix dev shell:

- Build: `nix develop -c ./scripts/build`
- Test (only if the fork has `scripts/test`): `nix develop -c bash ./scripts/test`
- Lint: `nix develop -c luacheck --quiet --std lua51 --no-unused-args src/`
- Lint: `nix develop -c luacheck --quiet --std lua51 --no-unused-args --max-line-length 130 src/`
- Format: `nix fmt` (check: `nix fmt && git diff --exit-code`)

## Formatting

`nix fmt` runs treefmt (`treefmt.nix`): nixfmt for Nix, `dhall format`, purs-tidy
for `*.purs` (config in `.tidyrc.json`), and LuaFormatter for the `*.lua` FFI
(config in `.lua-format`). LuaFormatter is used over StyLua because it keeps the
parentheses pslua's foreign-file parser requires. The Lua line budget is 130
columns, matching the `luacheck --max-line-length` above. The check is
content-based (`nix fmt && git diff --exit-code`) rather than `treefmt --ci`,
since the in-place formatters bump mtime even when content is unchanged, which
trips treefmt's `--fail-on-change`. CI and the pre-commit hook use it.

## Lua 5.1 target

Expand Down
23 changes: 22 additions & 1 deletion flake.lock

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

43 changes: 39 additions & 4 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,33 @@
inputs.nixpkgs.follows = "nixpkgs";
};
pslua.url = "github:purescript-lua/purescript-lua";
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs = { self, nixpkgs, flake-utils, purescript-overlay, pslua }:
flake-utils.lib.eachDefaultSystem (system:
outputs =
{
self,
nixpkgs,
flake-utils,
purescript-overlay,
pslua,
treefmt-nix,
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ purescript-overlay.overlays.default ];
};
in {
treefmtEval = treefmt-nix.lib.evalModule pkgs ./treefmt.nix;
in
{
formatter = treefmtEval.config.build.wrapper;
checks.formatting = treefmtEval.config.build.check self;
devShell = pkgs.mkShell {
buildInputs = with pkgs; [
dhall
Expand All @@ -31,8 +48,26 @@
spago-bin.spago-0_21_0
treefmt
];
# Install a content-based pre-commit hook. It compares the working
# tree diff before and after `nix fmt`, so it only objects to changes
# the formatter itself introduces (not the developer's existing
# unstaged work) and is not fooled by formatters that only bump mtime.
# Rewritten each shell entry to stay in sync with this flake.
shellHook = ''
hook=.git/hooks/pre-commit
if [ -d .git ]; then
printf '%s\n' \
'#!/usr/bin/env bash' \
'before=$(git diff)' \
'nix fmt >/dev/null 2>&1 || exit 0' \
'[ "$before" = "$(git diff)" ] || { echo "nix fmt changed files; re-stage them, then commit." >&2; exit 1; }' \
> "$hook"
chmod +x "$hook"
fi
'';
Comment thread
Unisay marked this conversation as resolved.
};
});
}
);

# --- Flake Local Nix Configuration ----------------------------
nixConfig = {
Expand Down
15 changes: 6 additions & 9 deletions src/Data/Function/Uncurried.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,16 @@ return {
end),
runFn5 = (function(fn)
return function(a)
return function(b)
return function(c) return function(d) return function(e) return fn(a, b, c, d, e) end end end
end
return function(b) return function(c) return function(d) return function(e) return fn(a, b, c, d, e) end end end end
end
end),
runFn6 = (function(fn)
return function(a)
return function(b)
return function(c)
return function(d) return function(e) return function(f) return fn(a, b, c, d, e, f) end end end
end
return
function(c)
return function(d) return function(e) return function(f) return fn(a, b, c, d, e, f) end end end
end
end
end
end),
Expand All @@ -48,9 +47,7 @@ return {
return function(c)
return function(d)
return function(e)
return function(f)
return function(g) return function(h) return fn(a, b, c, d, e, f, g, h) end end
end
return function(f) return function(g) return function(h) return fn(a, b, c, d, e, f, g, h) end end end
end
end
end
Expand Down
139 changes: 120 additions & 19 deletions src/Data/Function/Uncurried.purs
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,62 @@ foreign import data Fn5 :: Type -> Type -> Type -> Type -> Type -> Type -> Type
type role Fn5 representational representational representational representational representational representational

-- | A function of six arguments
foreign import data Fn6 :: Type -> Type -> Type -> Type -> Type -> Type -> Type -> Type
foreign import data Fn6
:: Type -> Type -> Type -> Type -> Type -> Type -> Type -> Type

type role Fn6 representational representational representational representational representational representational representational

-- | A function of seven arguments
foreign import data Fn7 :: Type -> Type -> Type -> Type -> Type -> Type -> Type -> Type -> Type
foreign import data Fn7
:: Type -> Type -> Type -> Type -> Type -> Type -> Type -> Type -> Type

type role Fn7 representational representational representational representational representational representational representational representational

-- | A function of eight arguments
foreign import data Fn8 :: Type -> Type -> Type -> Type -> Type -> Type -> Type -> Type -> Type -> Type
foreign import data Fn8
:: Type
-> Type
-> Type
-> Type
-> Type
-> Type
-> Type
-> Type
-> Type
-> Type

type role Fn8 representational representational representational representational representational representational representational representational representational

-- | A function of nine arguments
foreign import data Fn9 :: Type -> Type -> Type -> Type -> Type -> Type -> Type -> Type -> Type -> Type -> Type
foreign import data Fn9
:: Type
-> Type
-> Type
-> Type
-> Type
-> Type
-> Type
-> Type
-> Type
-> Type
-> Type

type role Fn9 representational representational representational representational representational representational representational representational representational representational

-- | A function of ten arguments
foreign import data Fn10 :: Type -> Type -> Type -> Type -> Type -> Type -> Type -> Type -> Type -> Type -> Type -> Type
foreign import data Fn10
:: Type
-> Type
-> Type
-> Type
-> Type
-> Type
-> Type
-> Type
-> Type
-> Type
-> Type
-> Type

type role Fn10 representational representational representational representational representational representational representational representational representational representational representational

Expand All @@ -69,25 +104,42 @@ foreign import mkFn2 :: forall a b c. (a -> b -> c) -> Fn2 a b c
foreign import mkFn3 :: forall a b c d. (a -> b -> c -> d) -> Fn3 a b c d

-- | Create a function of four arguments from a curried function
foreign import mkFn4 :: forall a b c d e. (a -> b -> c -> d -> e) -> Fn4 a b c d e
foreign import mkFn4
:: forall a b c d e. (a -> b -> c -> d -> e) -> Fn4 a b c d e

-- | Create a function of five arguments from a curried function
foreign import mkFn5 :: forall a b c d e f. (a -> b -> c -> d -> e -> f) -> Fn5 a b c d e f
foreign import mkFn5
:: forall a b c d e f. (a -> b -> c -> d -> e -> f) -> Fn5 a b c d e f

-- | Create a function of six arguments from a curried function
foreign import mkFn6 :: forall a b c d e f g. (a -> b -> c -> d -> e -> f -> g) -> Fn6 a b c d e f g
foreign import mkFn6
:: forall a b c d e f g
. (a -> b -> c -> d -> e -> f -> g)
-> Fn6 a b c d e f g

-- | Create a function of seven arguments from a curried function
foreign import mkFn7 :: forall a b c d e f g h. (a -> b -> c -> d -> e -> f -> g -> h) -> Fn7 a b c d e f g h
foreign import mkFn7
:: forall a b c d e f g h
. (a -> b -> c -> d -> e -> f -> g -> h)
-> Fn7 a b c d e f g h

-- | Create a function of eight arguments from a curried function
foreign import mkFn8 :: forall a b c d e f g h i. (a -> b -> c -> d -> e -> f -> g -> h -> i) -> Fn8 a b c d e f g h i
foreign import mkFn8
:: forall a b c d e f g h i
. (a -> b -> c -> d -> e -> f -> g -> h -> i)
-> Fn8 a b c d e f g h i

-- | Create a function of nine arguments from a curried function
foreign import mkFn9 :: forall a b c d e f g h i j. (a -> b -> c -> d -> e -> f -> g -> h -> i -> j) -> Fn9 a b c d e f g h i j
foreign import mkFn9
:: forall a b c d e f g h i j
. (a -> b -> c -> d -> e -> f -> g -> h -> i -> j)
-> Fn9 a b c d e f g h i j

-- | Create a function of ten arguments from a curried function
foreign import mkFn10 :: forall a b c d e f g h i j k. (a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> k) -> Fn10 a b c d e f g h i j k
foreign import mkFn10
:: forall a b c d e f g h i j k
. (a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> k)
-> Fn10 a b c d e f g h i j k

-- | Apply a function of no arguments
foreign import runFn0 :: forall a. Fn0 a -> a
Expand All @@ -103,22 +155,71 @@ foreign import runFn2 :: forall a b c. Fn2 a b c -> a -> b -> c
foreign import runFn3 :: forall a b c d. Fn3 a b c d -> a -> b -> c -> d

-- | Apply a function of four arguments
foreign import runFn4 :: forall a b c d e. Fn4 a b c d e -> a -> b -> c -> d -> e
foreign import runFn4
:: forall a b c d e. Fn4 a b c d e -> a -> b -> c -> d -> e

-- | Apply a function of five arguments
foreign import runFn5 :: forall a b c d e f. Fn5 a b c d e f -> a -> b -> c -> d -> e -> f
foreign import runFn5
:: forall a b c d e f. Fn5 a b c d e f -> a -> b -> c -> d -> e -> f

-- | Apply a function of six arguments
foreign import runFn6 :: forall a b c d e f g. Fn6 a b c d e f g -> a -> b -> c -> d -> e -> f -> g
foreign import runFn6
:: forall a b c d e f g. Fn6 a b c d e f g -> a -> b -> c -> d -> e -> f -> g

-- | Apply a function of seven arguments
foreign import runFn7 :: forall a b c d e f g h. Fn7 a b c d e f g h -> a -> b -> c -> d -> e -> f -> g -> h
foreign import runFn7
:: forall a b c d e f g h
. Fn7 a b c d e f g h
-> a
-> b
-> c
-> d
-> e
-> f
-> g
-> h

-- | Apply a function of eight arguments
foreign import runFn8 :: forall a b c d e f g h i. Fn8 a b c d e f g h i -> a -> b -> c -> d -> e -> f -> g -> h -> i
foreign import runFn8
:: forall a b c d e f g h i
. Fn8 a b c d e f g h i
-> a
-> b
-> c
-> d
-> e
-> f
-> g
-> h
-> i

-- | Apply a function of nine arguments
foreign import runFn9 :: forall a b c d e f g h i j. Fn9 a b c d e f g h i j -> a -> b -> c -> d -> e -> f -> g -> h -> i -> j
foreign import runFn9
:: forall a b c d e f g h i j
. Fn9 a b c d e f g h i j
-> a
-> b
-> c
-> d
-> e
-> f
-> g
-> h
-> i
-> j

-- | Apply a function of ten arguments
foreign import runFn10 :: forall a b c d e f g h i j k. Fn10 a b c d e f g h i j k -> a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> k
foreign import runFn10
:: forall a b c d e f g h i j k
. Fn10 a b c d e f g h i j k
-> a
-> b
-> c
-> d
-> e
-> f
-> g
-> h
-> i
-> j
-> k
Loading
Loading