Skip to content

Commit acc56b8

Browse files
authored
Merge pull request #654 from pallene-lang/emit-types
Emit the type declaration file
2 parents 3497a7e + c4c78e0 commit acc56b8

File tree

8 files changed

+751
-1
lines changed

8 files changed

+751
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
*.o
22
*.a
33
*.so
4+
*.d.pln
45

56
# lua
67
vm/src/lua

run-lint

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ for file in \
2525
examples/*/*.lua \
2626
examples/*/*.pln
2727
do
28+
case "$file" in
29+
*.d.pln) continue ;;
30+
esac
2831
if grep -n "[$space$tab]$" "$file"; then
2932
# Forbid trailing whitespace because some editors like to automatically delete it.
3033
# Such whitespace can cause spurious diffs later down the road, when someone is working on

spec/execution_tests.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ function execution_tests.run(compile_file, backend, _ENV, only_compile)
2525
local file_lua = modname..".lua"
2626
local file_script = modname.."script.lua"
2727
local file_output = modname.."output.txt"
28+
local file_d_pln = modname..".d.pln"
2829

2930
local function compile(body)
3031
local code = util.render([[
@@ -52,6 +53,7 @@ function execution_tests.run(compile_file, backend, _ENV, only_compile)
5253
os.remove(file_lua)
5354
os.remove(file_script)
5455
os.remove(file_output)
56+
os.remove(file_d_pln)
5557
end)
5658

5759
local assert_test_output = function (expected)

spec/pallenec_spec.lua

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55

66
local util = require "pallene.util"
77

8+
local function file_exists(name)
9+
local f = io.open(name, "r")
10+
return f ~= nil and io.close(f)
11+
end
12+
13+
814
describe("pallenec", function()
915
before_each(function()
1016
util.set_file_contents("__test__.pln", [[
@@ -29,7 +35,9 @@ describe("pallenec", function()
2935
os.remove("__test__.c")
3036
os.remove("__test__.s")
3137
os.remove("__test__.so")
38+
os.remove("__test__.d.pln")
3239
os.remove("__test__flag__.so")
40+
os.remove("__test__flag__.d.pln")
3341
os.remove("__test__script__.lua")
3442
os.remove("__test__script__flag__.lua")
3543
end)
@@ -61,4 +69,11 @@ describe("pallenec", function()
6169
assert.is_false(ok, err)
6270
assert(string.find(abort_msg, "Error: option '--emit-lua' can not be used together with option '--emit-c'", nil, true))
6371
end)
72+
73+
it("Can extract type declarations", function()
74+
assert(util.execute("pallenec __test__.pln"))
75+
assert(file_exists("__test__.d.pln"))
76+
local types = util.get_file_contents("__test__.d.pln")
77+
assert.equals("f: (integer) -> integer\n", types)
78+
end)
6479
end)

0 commit comments

Comments
 (0)