Skip to content

Commit

Permalink
Merge pull request #520 from pallene-lang/trailing-whitespace
Browse files Browse the repository at this point in the history
Remove trailing whitespace and add a lint check against it.
  • Loading branch information
hugomg authored Apr 22, 2022
2 parents 292ebcd + 6403d1f commit 9315ecb
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
6 changes: 3 additions & 3 deletions pallene/coder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1452,15 +1452,15 @@ gen_cmd["BuiltinMathCeil"] = function(self, cmd, _func)
local dst = self:c_var(cmd.dsts[1])
local v = self:c_value(cmd.srcs[1])
local line = cmd.loc.line
return util.render([[ $dst = pallene_math_ceil(L, PALLENE_SOURCE_FILE, $line, $v); ]], {
return util.render([[ $dst = pallene_math_ceil(L, PALLENE_SOURCE_FILE, $line, $v); ]], {
dst = dst, v = v, line = C.integer(line) })
end

gen_cmd["BuiltinMathFloor"] = function(self, cmd, _func)
local dst = self:c_var(cmd.dsts[1])
local v = self:c_value(cmd.srcs[1])
local line = cmd.loc.line
return util.render([[ $dst = pallene_math_floor(L, PALLENE_SOURCE_FILE, $line, $v); ]], {
return util.render([[ $dst = pallene_math_floor(L, PALLENE_SOURCE_FILE, $line, $v); ]], {
dst = dst, v = v, line = C.integer(line) })
end

Expand Down Expand Up @@ -1502,7 +1502,7 @@ gen_cmd["BuiltinMathModf"] = function(self, cmd, _func)
local dst2 = self:c_var(cmd.dsts[2])
local v = self:c_value(cmd.srcs[1])
local line = cmd.loc.line
return util.render([[ $dst1 = pallene_math_modf(L, PALLENE_SOURCE_FILE, $line, $v, &$dst2); ]], {
return util.render([[ $dst1 = pallene_math_modf(L, PALLENE_SOURCE_FILE, $line, $v, &$dst2); ]], {
dst1 = dst1, dst2 = dst2, v = v, line = C.integer(line) })
end

Expand Down
2 changes: 1 addition & 1 deletion pallene/translator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function translator.translate(input, prog_ast)
-- Whatever characters that were not included in the partials should be added.
instance:add_previous(#input)

-- This prepends any compatibility shims we need.
-- This prepends any compatibility shims we need.
instance:prepend_compatibility_code()

return table.concat(instance.partials)
Expand Down
13 changes: 11 additions & 2 deletions run-lint
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/sh

space=' '
tab=' '
ok=yes

Expand All @@ -22,11 +23,19 @@ for file in \
examples/*/*.lua examples/*/*.pln \
vm/src/pallene_core.c vm/src/pallene_core.h
do
if grep "^$tab" "$file"; then
if grep --line-number "[$space$tab]$" "$file"; then
# Forbid trailing whitespace because some editors like to automatically delete it.
# Such whitespace can cause spurious diffs later down the road, when someone is working on
# an unrelated pull request and their editor "helpfully" deletes the trailing whitespace.
error "File $file has a line that ends in whitespace"
fi

if grep --line-number "^$tab" "$file"; then
# Standardize on spaces because mixing tabs and spaces is endless pain.
error "File $file has tab-based indentation"
fi

if ! grep --quiet 'SPDX-License-Identifier' "$file"; then
if ! grep --line-number --quiet 'SPDX-License-Identifier' "$file"; then
error "File $file is missing a copyright header"
fi
done
Expand Down
4 changes: 2 additions & 2 deletions vm/src/pallene_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,9 @@ lua_Integer pallene_shiftR(lua_Integer x, lua_Integer y)
}

/* Some Lua math functions return integer if the result fits in integer, or float if it doesn't.
* In Pallene, we can't return different types, so we instead raise an error if it doesn't fit
* In Pallene, we can't return different types, so we instead raise an error if it doesn't fit
* See also: pushnumint in lmathlib */
static inline
static inline
lua_Integer pallene_checked_float_to_int(lua_State *L, const char* file, int line, lua_Number d)
{
lua_Integer n;
Expand Down

0 comments on commit 9315ecb

Please sign in to comment.