array types cannot be used as metatables

pull/81/head
Dibyendu Majumdar 9 years ago
parent 107acf8f7f
commit 5cbc9b33eb

@ -164,7 +164,7 @@ endif ()
# Enable minimal required LLVM components so that the
# the size of the resulting binary is manageable
if (LLVM_JIT)
llvm_map_components_to_libnames(llvm_libs
llvm_map_components_to_libnames(LLVM_LIBS
Analysis
Core
CodeGen
@ -192,7 +192,7 @@ if (LLVM_JIT)
X86Info
X86Utils
)
message(STATUS "llvm_libs ${llvm_libs}")
message(STATUS "LLVM_LIBS ${LLVM_LIBS}")
endif ()
#Main library
@ -207,13 +207,11 @@ if (WIN32)
# enable DLL export
set_target_properties(ravi PROPERTIES DEFINE_SYMBOL "LUA_BUILD_AS_DLL")
endif ()
target_link_libraries(ravi ${EXTRA_LIBRARIES} ${llvm_libs} ${GCCJIT_LIBRARIES})
target_link_libraries(ravi ${EXTRA_LIBRARIES} ${LLVM_LIBS} ${GCCJIT_LIBRARIES})
add_executable(lua src/lua.c)
target_link_libraries(lua ravi)
#add_executable(luac src/luac.c)
#target_link_libraries(luac ravis)
add_executable(ravi-bin src/lua.c)
set_target_properties(ravi-bin PROPERTIES OUTPUT_NAME ravi)
target_link_libraries(ravi-bin ravi)
#VM test
add_executable(test_vm tests/test_vm.c)
@ -234,6 +232,8 @@ add_test(TestVM test_vm)
add_test(TestMisc test_misc)
install(FILES ${LUA_HEADERS}
DESTINATION include)
install(TARGETS ravi lua
DESTINATION bin)
DESTINATION include/ravi)
install(TARGETS ravi ravi-bin
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib)

@ -1,27 +1,32 @@
This folder contains various performance and unit tests.
Unit tests
----------
Language tests
--------------
* basics.lua - some simple tests
* ravi_tests1.ravi - contains some basic tests
* ravi_errors.ravi - contains tests for error conditions
* bitwise_tests.lua - modified Lua 5.3 tests to exercise JIT on bitwise operations
Performance tests
-----------------
Following are simple loop tests:
* fornum_test1.lua
* fornum_test2.lua
* fornum_test2.ravi - with optional types
* fornum_test3.lua
Matrix multiplication test:
* matmul1.lua - matrix multiplication (Lua compatible)
* matmul1.ravi - matrix multiplication (ravi version with static typing)
Following performance tests were obtained from the `The Computer Programming Language Benchmarks Game <http://benchmarksgame.alioth.debian.org/>`_. Original author is `Mike Pall <http://luajit.org/>`_.
* fannkuchen.lua
* fannkuchen.ravi - with optional types
* mandel.lua
* mandel.ravi - with optional types
* mandel1.ravi - modified so that it can be JIT compiled
* mandel1.lua - can be JIT compiled but also compatible with Lua
Example LLVM and Ravi bytecode listings
---------------------------------------
The files ending in ``.ll`` extension are LLVM IR dumps of some of the samples.
In the listings sub-folder you will also find some Ravi bytecode listings.
See ``run_tests.sh`` for how to run these tests.

@ -77,4 +77,4 @@ local t1 = os.clock()
local sum, flips = fannkuch(n)
local t2 = os.clock()
io.write(sum, "\nPfannkuchen(", n, ") = ", flips, "\n")
io.write("elapsed time in secs ", (t2-t1))
io.write("elapsed time in secs ", (t2-t1), "\n")

@ -6,9 +6,11 @@ local function x()
return j
end
if ravi then
ravi.optlevel(2)
assert(ravi.compile(x))
-- ravi.dumpllvmasm(x)
ravi.compile(x)
end
if jit then
-- LuaJIT - warmup
x()
end
local t1 = os.clock()

@ -8,8 +8,12 @@ end
if ravi then
ravi.optlevel(2)
assert(ravi.compile(x))
-- ravi.dumpllvmasm(x)
ravi.compile(x)
end
if jit then
-- LuaJIT warmup
x()
end
local t1 = os.clock()

@ -10,9 +10,11 @@ local function x()
end
if ravi then
ravi.optlevel(2)
assert(ravi.compile(x))
-- ravi.dumpllvmasm(x)
ravi.compile(x)
end
if jit then
-- LuaJIT - warmup
x()
end
local t1 = os.clock()

@ -44,11 +44,12 @@ local function domandel(pfunc)
end
end
local function dummy(x)
end
if ravi then
assert(ravi.compile(domandel))
ravi.compile(domandel)
end
if jit then
-- LuaJIT warmup
domandel(print)
end
t1 = os.clock()

@ -44,12 +44,10 @@ local function domandel(pfunc)
end
end
local function dummy(x)
if ravi.jit() then
assert(ravi.compile(domandel))
end
--ravi.dumplua(domandel)
assert(ravi.compile(domandel))
t1 = os.clock()
domandel(print)
t2 = os.clock()

@ -47,9 +47,8 @@ end
local n = arg[1] or 1000;
n = math.floor(n/2) * 2;
-- warmup
if jit then
-- luajit
-- luajit warmup
matrix.mul(matgen(n), matgen(n))
end
local t1 = os.clock()

@ -44,6 +44,12 @@ end
local n = tonumber(arg[1]) or 100
n = math.floor(n/2) * 2
if jit then
-- LuaJIT - warmup
matrix.mul(matgen(n), matgen(n), n)
end
local t1 = os.clock()
local a = matrix.mul(matgen(n), matgen(n), n)
local t2 = os.clock()

@ -16,7 +16,7 @@ end
local function checkmessage (prog, msg)
local m = doit(prog)
-- print(m)
--print(m)
assert(string.find(m, msg, 1, true))
end
@ -64,6 +64,9 @@ checkmessage('local t: integer = 5; local x=function() return "string" end; loca
checkmessage('local t: integer = 5.5', 'Invalid local assignment')
checkmessage('local function f() local t: integer[] = {}; t[1] = 4; t[5] = 2; end; f()', 'array out of bounds')
checkmessage('local function f() local t: integer[] = {}; t[1] = 4; t[-5] = 2; end; f()', 'array out of bounds')
checkmessage('local mt: integer[] = {}; local t = {}; setmetatable(t, mt)', 'Lua table expected')
checkmessage('local mt: integer[] = {}; local t: table = {}; setmetatable(t, mt)', 'Lua table expected')
checkmessage('local t: number[] = {}; local t2: number[] = {1.0}; t=t2[1]', 'Invalid assignment: number[] expected')
checkmessage('local t: number[] = {}; t=1', 'Invalid assignment: number[] expected')
@ -87,6 +90,8 @@ checkmessage('local t: number = 5.5; local x=function() return "string" end; loc
checkmessage('local t: number = 5', 'Invalid local assignment')
checkmessage('local function f() local t: number[] = {}; t[1] = 4.2; t[5] = 2.4; end; f()', 'array out of bounds')
checkmessage('local function f() local t: number[] = {}; t[1] = 4.2; t[-5] = 2.4; end; f()', 'array out of bounds')
checkmessage('local mt: number[] = {}; local t = {}; setmetatable(t, mt)', 'Lua table expected')
checkmessage('local mt: number[] = {}; local t: table = {}; setmetatable(t, mt)', 'Lua table expected')
checkmessage('for i=1,10 do i="a" end', 'Invalid assignment: integer expected')
checkmessage('for i=1,10 do local f = function() i="a" end; f(); end', 'upvalue of integer type, cannot be set to non integer value')

@ -84,10 +84,11 @@ The array types (``number[]`` and ``integer[]``) are specializations of Lua tabl
local t5: number[] = {}
local t6 = t5 -- t6 treated as table
The reason for this discrepancy is that declared table types generate optimized JIT code which assumes that the keys are integers
or literal short strings. The generated code would be incorrect if this expectation was not met.
The reason for these restrictions is that declared table types generate optimized JIT code which assumes that the keys are integers
or literal short strings. Similarly declared array types result in specialized JIT code that assume integer keys and numeric values.
The generated JIT code would be incorrect if the types were not as expected.
* Indices >= 1 should be used when accessing array elements. Ravi arrays (and slices) have a hidden slot at index 0 for performance reasons, but this is not visible under ``pairs()`` or ``ipairs()``, or when initializing an array using a literal initializer; only direct access via the ``[]`` operator can see this slot.
* Indices >= 1 should be used when accessing array elements. Ravi arrays (and slices) have a hidden slot at index 0 for performance reasons, but this is not visible in ``pairs()`` or ``ipairs()``, or when initializing an array using a literal initializer; only direct access via the ``[]`` operator can see this slot.
* Arrays must always be initialized::
local t: number[] = {} -- okay
@ -128,7 +129,8 @@ The array types (``number[]`` and ``integer[]``) are specializations of Lua tabl
local t: number[] = f() -- type will be checked at runtime
* Operations on array types can be optimised to special bytecode and JIT only when the array type is statically known. Otherwise regular table access will be used subject to runtime checks.
* Array types may not have meta methods - this will be enforced at runtime (TODO).
* Array types ignore ``__index``, ``__newindex`` and ``__len`` metamethods.
* Array types cannot be set as metatables for other values.
* ``pairs()`` and ``ipairs()`` work on arrays as normal
* There is no way to delete an array element.
* The array data is stored in contiguous memory just like native C arrays; morever the garbage collector does not scan the array data
@ -282,6 +284,8 @@ Ravi should be able to run all Lua 5.3 programs in interpreted mode, but there a
+-----------------+-------------+-------------+
| MAXVARS | 200 | 125 |
+-----------------+-------------+-------------+
| MAXARGLINE | 250 | 120 |
+-----------------+-------------+-------------+
When JIT compilation is enabled some things will not work:

@ -1177,6 +1177,8 @@ LUA_API int lua_setmetatable (lua_State *L, int objindex) {
else {
api_check(L, ttistable(L->top - 1), "table expected");
mt = hvalue(L->top - 1);
if (mt->ravi_array.array_type != RAVI_TTABLE)
luaG_runerror(L, "Lua table expected");
}
switch (ttnov(obj)) {
case LUA_TTABLE: {

Loading…
Cancel
Save