Skip to content

Commit

Permalink
Fix issue #188
Browse files Browse the repository at this point in the history
  • Loading branch information
edubart committed Apr 12, 2022
1 parent 09ce170 commit 19cf3a5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/span.nelua
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ require 'iterators'
self.size = values.size
## else
if #values > 0 then
self.data = (@*[0]T)(&values[#[values.type.subtype.is_sequence and 1 or 0]#])
self.data = (@*[0]T)(&values[#[values.type:implicit_deref_type().is_oneindexing and 1 or 0]#])
self.size = (@usize)(#values)
end
## end
Expand Down
4 changes: 1 addition & 3 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
This is the Lua 5.4.4 interpreter used by Nelua, with the following changes:

* Uses rpmalloc as the default memory allocator (usually much faster than the system's default memory allocator).
* Libraries "hasher", "sys" and "lfs" are built-in (they are required by Nelua compiler).
* Libraries "hasher", "lpeglabel", "sys" and "lfs" are bundled (they are required by Nelua compiler).
* Use a distribution friendly LUA_ROOT in luaconf.h
* Use -fno-crossjumping -fno-gcse in lua VM for a faster instruction execution.
* C compilation flags are tuned to squeeze more performance from the Lua interpreter.
* Execute `luainit.lua` code on startup, used to adjust `package.path`
to make Nelua compiler files available with `require`.

Patch for the changes are available in `lua-changes.patch` file.

It is recommended to use this interpreter to have the same behavior
and because it can be ~30% faster than the standard Lua.
15 changes: 14 additions & 1 deletion tests/span_test.nelua
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ do -- vector to span
end

require 'sequence'
do -- sequence to span

do -- sequence to span (by pointer)
local seq: sequence(integer) = {1,2,3,4}
local s: span(integer) = &seq
assert(s.size == 4 and s.data == &seq[1])
Expand All @@ -110,6 +111,18 @@ do -- sequence to span
seq:destroy()
end

do -- sequence to span (by value)
local seq: sequence(integer) = {1,2,3,4}
local s: span(integer) = seq
assert(s.size == 4 and s.data == &seq[1])
assert(#s == 4 and s[0] == 1 and s[1] == 2 and s[2] == 3 and s[3] == 4)
s[0] = 5
assert(seq[1] == 5)
s = {}
assert(#s == 0 and s.data == nilptr)
seq:destroy()
end

do
local Node = @record{
tag: string,
Expand Down

0 comments on commit 19cf3a5

Please sign in to comment.