change syntax from int to integer, and double to number

Dibyendu Majumdar 9 years ago
parent 5755551881
commit 684cad6f9f

@ -23,16 +23,16 @@ The project was kicked off in January 2015.
Right now (as of Feb 2015) I am working on the JIT implementation. Please see `Ravi Documentation <http://the-ravi-programming-language.readthedocs.org/en/latest/index.html>`_ for details of this effort.
As of end Jan 2015, the Ravi interpreter allows you to declare local variables as ``int`` or ``double``. This triggers following behaviour:
As of end Jan 2015, the Ravi interpreter allows you to declare local variables as ``integer`` or ``number``. This triggers following behaviour:
* ``int`` and ``double`` variables are initialized to 0
* ``integer`` and ``number`` variables are initialized to 0
* arithmetic operations trigger type specific bytecodes
* values assigned to these variables are checked statically unless the values are results from a function call in which case the there is an attempt to convert values at runtime.
Also initial implementation of arrays is available. So you can declare arrays of integers or doubles.
* The type of an array of integers is denoted as ``int[]``.
* The type of an array of doubles is denoted as ``double[]``.
* The type of an array of integers is denoted as ``integer[]``.
* The type of an array of doubles is denoted as ``number[]``.
* Arrays are implemented using a mix of runtime and compile time checks.
* Specialised operators to get/set from arrays are implemented.
* The standard table operations on arrays are checked to ensure that the type is not subverted.
@ -45,12 +45,12 @@ Example of code that works - you can copy this to the command line input::
local i,j = 5,6
return i,j
end
local i:int, j:int = tryme(); print(i+j)
local i:integer, j:integer = tryme(); print(i+j)
Another::
function tryme()
local j:double
local j:number
for i=1,1000000000 do
j = j+1
end
@ -61,7 +61,7 @@ Another::
An example with arrays::
function tryme()
local a : double[], j:double = {}
local a : number[], j:number = {}
for i=1,10 do
a[i] = i
j = j + a[i]
@ -154,8 +154,8 @@ I hope to enhance the language to variables to be optionally decorated with type
So as of now the only types that seem worth specializing are:
* int (64-bit)
* double
* integer (64-bit)
* number
* array of ints
* array of doubles
@ -190,11 +190,11 @@ If no type is specified then then type will be dynamic - exactly what the Lua de
When a typed function is called the inputs and return value can be validated. Consider the function below::
local function foo(a, b: int, c: string)
local function foo(a, b: integer, c: string)
return
end
When this function is called the compiler can validate that ``b`` is an int and ``c`` is a string. ``a`` on the other hand is dynamic so will behave as regular Lua value. The compiler can also ensure that the types of ``b`` and ``c`` are respected within the function.
When this function is called the compiler can validate that ``b`` is an integer and ``c`` is a string. ``a`` on the other hand is dynamic so will behave as regular Lua value. The compiler can also ensure that the types of ``b`` and ``c`` are respected within the function.
Return statements in typed functions can also be validated.
@ -203,12 +203,12 @@ Array Types
When it comes to complex types such as arrays, tables and functions, at this point in time, I think that Ravi only needs to support explicit specialization for arrays of integers and doubles::
function foo(p1: {}, p2: int[])
function foo(p1: {}, p2: integer[])
-- p1 is a table
-- p2 is an array of integers
local t1 = {} -- t1 is a table
local a1 : int[] = {} -- a1 is an array of integers, specialization of table
local d1 : double[] = {} -- d1 is an array of doubles, specialization of table
local a1 : integer[] = {} -- a1 is an array of integers, specialization of table
local d1 : number[] = {} -- d1 is an array of doubles, specialization of table
end
@ -251,7 +251,7 @@ For now however I am just amending the bit mapping in the 32-bit instruction to
New OpCodes
-----------
The new instructions are specialised for types, and also for register/versus constant. So for example ``OP_RAVI_ADDFI`` means add ``float`` and ``int``. And ``OP_RAVI_ADDFF`` means add ``float`` and ``float``. The existing Lua opcodes that these are based on define which operands are used.
The new instructions are specialised for types, and also for register/versus constant. So for example ``OP_RAVI_ADDFI`` means add ``float`` and ``integer``. And ``OP_RAVI_ADDFF`` means add ``float`` and ``float``. The existing Lua opcodes that these are based on define which operands are used.
Example::
@ -265,7 +265,7 @@ Above standard Lua code compiles to::
We add type info using Ravi extensions::
local i:int=0; i=i+1
local i:integer=0; i=i+1
Now the code compiles to::

@ -3,8 +3,8 @@
-- contributed by Mike Pall
local function fannkuch(n1)
local n:int = 11
local p: int[], q :int[], s: int[], sign: int, maxflips: int, sum: int = {}, {}, {}, 1, 0, 0
local n:integer = 11
local p: integer[], q :integer[], s: integer[], sign: integer, maxflips: integer, sum: integer = {}, {}, {}, 1, 0, 0
for i=1,n do
p[i] = i;
q[i] = i;
@ -12,14 +12,14 @@ local function fannkuch(n1)
end
repeat
-- Copy and flip.
local q1: int = p[1] -- Cache 1st element.
local q1: integer = p[1] -- Cache 1st element.
if q1 ~= 1 then
for i=2,n do
q[i] = p[i]
end -- Work on a copy.
local flips: int = 1
local flips: integer = 1
repeat
local qq: int = q[q1]
local qq: integer = q[q1]
if qq == 1 then -- ... until 1st element is 1.
sum = sum + sign*flips
if flips > maxflips then
@ -29,7 +29,7 @@ local function fannkuch(n1)
end
q[q1] = q1
if q1 >= 4 then
local i: int, j: int = 2, q1 - 1
local i: integer, j: integer = 2, q1 - 1
repeat
q[i], q[j] = q[j], q[i];
i = i + 1;
@ -46,7 +46,7 @@ local function fannkuch(n1)
else
p[2], p[3] = p[3], p[2]; sign = 1 -- Rotate 1<-2 and 1<-2<-3.
for i=3,n do
local sx: int = s[i]
local sx: integer = s[i]
if sx ~= 1 then
s[i] = sx-1;
break
@ -56,7 +56,7 @@ local function fannkuch(n1)
end -- Out of permutations.
s[i] = i
-- Rotate 1<-...<-i+1.
local t: int = p[1];
local t: integer = p[1];
for j=1,i do
p[j] = p[j+1]
end;

@ -1,5 +1,5 @@
local function x()
local j:double
local j:number
for i=1,1000000000 do
j = j+1
end

@ -3,19 +3,19 @@
-- contributed by Mike Pall
local arg1 = arg and arg[1] or 100
local width :int = tonumber(arg1)
local height :int, wscale :double = width, 2.0/width
local m:int, limit2 :double = 50, 4.0
local width :integer = tonumber(arg1)
local height :integer, wscale :number = width, 2.0/width
local m:integer, limit2 :number = 50, 4.0
local write, char = io.write, string.char
--write("P4\n", width, " ", height, "\n")
t1 = os.time()
for y=0,height-1 do
local Ci :double = 2.0*y / height - 1
local Ci :number = 2.0*y / height - 1
for xb=0,width-1,8 do
local bits :int = 0
local xbb :int = xb+7
local xblimit :int
local bits :integer = 0
local xbb :integer = xb+7
local xblimit :integer
if xbb < width then
xblimit = xbb
else
@ -23,10 +23,10 @@ for y=0,height-1 do
end
for x=xb,xblimit do
bits = bits + bits
local Zr :double, Zi :double, Zrq :double, Ziq :double = 0.0, 0.0, 0.0, 0.0
local Cr :double = x * wscale - 1.5
local Zr :number, Zi :number, Zrq :number, Ziq :number = 0.0, 0.0, 0.0, 0.0
local Cr :number = x * wscale - 1.5
for i=1,m do
local Zri :double = Zr*Zi
local Zri :number = Zr*Zi
Zr = Zrq - Ziq + Cr
Zi = Zri + Zri + Ci
Zrq = Zr*Zr

@ -4,17 +4,17 @@
local function domandel(pfunc)
local width :int = 4000
local height :int, wscale :double = width, 2.0/width
local m:int, limit2 :double = 50, 4.0
local width :integer = 4000
local height :integer, wscale :number = width, 2.0/width
local m:integer, limit2 :number = 50, 4.0
--local write, char = io.write, string.char
for y=0,height-1 do
local Ci :double = 2.0*y / height - 1
local Ci :number = 2.0*y / height - 1
for xb=0,width-1,8 do
local bits :int = 0
local xbb :int = xb+7
local xblimit :int
local bits :integer = 0
local xbb :integer = xb+7
local xblimit :integer
if xbb < width then
xblimit = xbb
else
@ -22,10 +22,10 @@ local function domandel(pfunc)
end
for x=xb,xblimit do
bits = bits + bits
local Zr :double, Zi :double, Zrq :double, Ziq :double = 0.0, 0.0, 0.0, 0.0
local Cr :double = x * wscale - 1.5
local Zr :number, Zi :number, Zrq :number, Ziq :number = 0.0, 0.0, 0.0, 0.0
local Cr :number = x * wscale - 1.5
for i=1,m do
local Zri :double = Zr*Zi
local Zri :number = Zr*Zi
Zr = Zrq - Ziq + Cr
Zi = Zri + Zri + Ci
Zrq = Zr*Zr

@ -1,5 +1,5 @@
function pisum()
local sum : double
local sum : number
for j = 1,500 do
sum = 0.0
for k = 1,10000 do

@ -34,7 +34,7 @@ print("test 2 OK")
-- test 3
x = function ()
local i, j:int
local i, j:integer
j=0
for i=1,1000000000 do
j = j+1
@ -48,7 +48,7 @@ print("test 3 OK")
-- test 4
x = function ()
local j:double
local j:number
for i=1,1000000000 do
j = j+1
end
@ -151,12 +151,12 @@ function tryme()
return i,j
end
assert(ravi.compile(tryme))
local i:int, j:int = tryme(); assert(i+j == 11)
local i:integer, j:integer = tryme(); assert(i+j == 11)
print("test 11 OK")
-- test 12
function tryme()
local a : double[], j:double = {}
local a : number[], j:number = {}
for i=1,10 do
a[i] = i
j = j + a[i]
@ -169,7 +169,7 @@ print("test 12 OK")
-- test 13
function pisum()
local sum : double
local sum : number
for j = 1,500 do
sum = 0.0
for k = 1,10000 do
@ -188,7 +188,7 @@ function tryme()
return i,j
end
function x(f)
local i:int, j:int = f()
local i:integer, j:integer = f()
return i+j
end
assert(ravi.compile(tryme))
@ -202,7 +202,7 @@ function tryme()
return i,j
end
function x(f)
local i:double, j:double = f()
local i:number, j:number = f()
return i+j
end
assert(ravi.compile(tryme))

@ -112,9 +112,9 @@ The entry point for parsing a local statement is ``localstat()`` in ``lparser.c`
if (testnext(ls, ':')) {
TString *typename = str_checkname(ls); /* we expect a type name */
const char *str = getaddrstr(typename);
if (strcmp(str, "int") == 0)
if (strcmp(str, "integer") == 0)
tt = RAVI_TNUMINT;
else if (strcmp(str, "double") == 0)
else if (strcmp(str, "number") == 0)
tt = RAVI_TNUMFLT;
if (tt == RAVI_TNUMFLT || tt == RAVI_TNUMINT) {
if (testnext(ls, '[')) {
@ -220,7 +220,7 @@ The main changes compared to ``explist()`` are the calls to ``ravi_typecheck()``
* We look for the last bytecode that is OP_NEWTABLE
* and that has the same destination
* register as v->u.info which is our variable
* local a:int[] = { 1 }
* local a:integer[] = { 1 }
* ^ We are just past this and
* about to assign to a
*/
@ -298,13 +298,13 @@ There are several parts to this function.
The simple case is when the type of the expression matches the variable.
Secondly if the expression is a table initializer then we need to generate specialized opcodes if the target variable is supposed to be ``int[]`` or ``double[]``. The specialized opcode sets up some information in the ``Table`` structure. The problem is that this requires us to modify ``OP_NEWTABLE`` instruction which has already been emitted. So we scan the generated instructions to find the last ``OP_NEWTABLE`` instruction that assigns to the register associated with the target variable.
Secondly if the expression is a table initializer then we need to generate specialized opcodes if the target variable is supposed to be ``integer[]`` or ``number[]``. The specialized opcode sets up some information in the ``Table`` structure. The problem is that this requires us to modify ``OP_NEWTABLE`` instruction which has already been emitted. So we scan the generated instructions to find the last ``OP_NEWTABLE`` instruction that assigns to the register associated with the target variable.
Next bit of special handling is for function calls. If the assignment makes a function call then we perform type coercion on return values where these values are being assigned to variables with defined types. This means that if the target variable is ``int`` or ``double`` we issue opcodes ``TOINT`` and ``TOFLT`` respectively. If the target variable is ``int[]`` or ``double[]`` then we issue ``TOARRAYI`` and ``TOARRAYF`` respectively. These opcodes ensure that the values are of required type or can be cast to the required type.
Next bit of special handling is for function calls. If the assignment makes a function call then we perform type coercion on return values where these values are being assigned to variables with defined types. This means that if the target variable is ``integer`` or ``number`` we issue opcodes ``TOINT`` and ``TOFLT`` respectively. If the target variable is ``integer[]`` or ``number[]`` then we issue ``TOARRAYI`` and ``TOARRAYF`` respectively. These opcodes ensure that the values are of required type or can be cast to the required type.
Note that any left over variables that are not assigned values, are set to 0 if they are of int or double type, else they are set to nil as per Lua's default behavior. This is handled in ``localvar_adjust_assign()`` which is described later on.
Note that any left over variables that are not assigned values, are set to 0 if they are of integer or number type, else they are set to nil as per Lua's default behavior. This is handled in ``localvar_adjust_assign()`` which is described later on.
Finally the last case is when the target variable is ``int`` or ``double`` and the expression is a table / array access. In this case we check that the table is of required type.
Finally the last case is when the target variable is ``integer`` or ``number`` and the expression is a table / array access. In this case we check that the table is of required type.
The ``localvar_adjust_assign()`` function referred to above is shown below.
@ -725,7 +725,7 @@ The Lua fornum statements create special variables. In order to allows the loop
/* The fornum sets up its own variables as above.
These are expected to hold numeric values - but from Ravi's
point of view we need to know if the variable is an integer or
double. So we need to check if this can be determined from the
number. So we need to check if this can be determined from the
fornum expressions. If we can then we will set the
fornum variables to the type we discover.
*/
@ -753,7 +753,7 @@ The Lua fornum statements create special variables. In order to allows the loop
}
if (tidx == tlimit && tlimit == tstep
&& (tidx == RAVI_TNUMFLT || tidx == RAVI_TNUMINT)) {
/* Ok so we have an integer or double */
/* Ok so we have an integer or number */
vidx->ravi_type = vlimit->ravi_type
= vstep->ravi_type
= vvar->ravi_type = tidx;

@ -23,16 +23,16 @@ The project was kicked off in January 2015.
Right now (as of Feb 2015) I am working on the JIT implementation. Please see `Ravi Documentation <http://the-ravi-programming-language.readthedocs.org/en/latest/index.html>`_ for details of this effort.
As of end Jan 2015, the Ravi interpreter allows you to declare local variables as ``int`` or ``double``. This triggers following behaviour:
As of end Jan 2015, the Ravi interpreter allows you to declare local variables as ``integer`` or ``number``. This triggers following behaviour:
* ``int`` and ``double`` variables are initialized to 0
* ``integer`` and ``number`` variables are initialized to 0
* arithmetic operations trigger type specific bytecodes
* values assigned to these variables are checked statically unless the values are results from a function call in which case the there is an attempt to convert values at runtime.
Also initial implementation of arrays is available. So you can declare arrays of integers or doubles.
* The type of an array of integers is denoted as ``int[]``.
* The type of an array of doubles is denoted as ``double[]``.
* The type of an array of integers is denoted as ``integer[]``.
* The type of an array of doubles is denoted as ``number[]``.
* Arrays are implemented using a mix of runtime and compile time checks.
* Specialised operators to get/set from arrays are implemented.
* The standard table operations on arrays are checked to ensure that the type is not subverted.
@ -45,12 +45,12 @@ Example of code that works - you can copy this to the command line input::
local i,j = 5,6
return i,j
end
local i:int, j:int = tryme(); print(i+j)
local i:integer, j:integer = tryme(); print(i+j)
Another::
function tryme()
local j:double
local j:number
for i=1,1000000000 do
j = j+1
end
@ -61,7 +61,7 @@ Another::
An example with arrays::
function tryme()
local a : double[], j:double = {}
local a : number[], j:number = {}
for i=1,10 do
a[i] = i
j = j + a[i]
@ -154,8 +154,8 @@ I hope to enhance the language to variables to be optionally decorated with type
So as of now the only types that seem worth specializing are:
* int (64-bit)
* double
* integer (64-bit)
* number
* array of ints
* array of doubles
@ -190,11 +190,11 @@ If no type is specified then then type will be dynamic - exactly what the Lua de
When a typed function is called the inputs and return value can be validated. Consider the function below::
local function foo(a, b: int, c: string)
local function foo(a, b: integer, c: string)
return
end
When this function is called the compiler can validate that ``b`` is an int and ``c`` is a string. ``a`` on the other hand is dynamic so will behave as regular Lua value. The compiler can also ensure that the types of ``b`` and ``c`` are respected within the function.
When this function is called the compiler can validate that ``b`` is an integer and ``c`` is a string. ``a`` on the other hand is dynamic so will behave as regular Lua value. The compiler can also ensure that the types of ``b`` and ``c`` are respected within the function.
Return statements in typed functions can also be validated.
@ -203,12 +203,12 @@ Array Types
When it comes to complex types such as arrays, tables and functions, at this point in time, I think that Ravi only needs to support explicit specialization for arrays of integers and doubles::
function foo(p1: {}, p2: int[])
function foo(p1: {}, p2: integer[])
-- p1 is a table
-- p2 is an array of integers
local t1 = {} -- t1 is a table
local a1 : int[] = {} -- a1 is an array of integers, specialization of table
local d1 : double[] = {} -- d1 is an array of doubles, specialization of table
local a1 : integer[] = {} -- a1 is an array of integers, specialization of table
local d1 : number[] = {} -- d1 is an array of doubles, specialization of table
end
@ -251,7 +251,7 @@ For now however I am just amending the bit mapping in the 32-bit instruction to
New OpCodes
-----------
The new instructions are specialised for types, and also for register/versus constant. So for example ``OP_RAVI_ADDFI`` means add ``float`` and ``int``. And ``OP_RAVI_ADDFF`` means add ``float`` and ``float``. The existing Lua opcodes that these are based on define which operands are used.
The new instructions are specialised for types, and also for register/versus constant. So for example ``OP_RAVI_ADDFI`` means add ``float`` and ``integer``. And ``OP_RAVI_ADDFF`` means add ``float`` and ``float``. The existing Lua opcodes that these are based on define which operands are used.
Example::
@ -265,7 +265,7 @@ Above standard Lua code compiles to::
We add type info using Ravi extensions::
local i:int=0; i=i+1
local i:integer=0; i=i+1
Now the code compiles to::

@ -1939,9 +1939,9 @@ static void localstat (LexState *ls) {
if (testnext(ls, ':')) {
TString *typename = str_checkname(ls); /* we expect a type name */
const char *str = getaddrstr(typename);
if (strcmp(str, "int") == 0)
if (strcmp(str, "integer") == 0)
tt = RAVI_TNUMINT;
else if (strcmp(str, "double") == 0)
else if (strcmp(str, "number") == 0)
tt = RAVI_TNUMFLT;
if (tt == RAVI_TNUMFLT || tt == RAVI_TNUMINT) {
if (testnext(ls, '[')) {

@ -123,13 +123,13 @@ int main(int argc, const char *argv[])
int failures = 0;
//
failures += test_luacompexec1("function z(x,y) return x<y end; ravi.compile(z); return not z(2,1)", 1);
failures += test_luacompexec1("local function x(); local d:double = 5.0; return d+5 == 5+d and d-5 == 5-d and d*5 == 5*d; end; local y = x(); return y", 1);
failures += test_luacompexec1("function x(f); local i : int, j : int = f(); return i + j; end; return ravi.compile(x)", 1);
failures += test_luacompexec1("local function x(); local d:number = 5.0; return d+5 == 5+d and d-5 == 5-d and d*5 == 5*d; end; local y = x(); return y", 1);
failures += test_luacompexec1("function x(f); local i : integer, j : integer = f(); return i + j; end; return ravi.compile(x)", 1);
failures += test_luacompexec1("local function z(a); print(a); return a+1; end; local function x(yy); local j = 5; j = yy(j); return j; end; local y = x(z); return y", 6);
failures += test_luacompexec1("local function z(a,p); p(a); return 6; end; local function x(yy,p); local j = 5; j = yy(j,p); return j; end; local y = x(z,print); return y", 6);
failures += test_luacompexec1("local function x(yy); local j = 5; yy(j); return j; end; local y = x(print); return y", 5);
failures += test_luacompexec1("local function x(); local i, j:int; j=0; for i=1,1000000000 do; j = j+1; end; return j; end; local y = x(); print(y); return y", 1000000000);
failures += test_luacompexec1("local function x(); local j:double; for i=1,1000000000 do; j = j+1; end; return j; end; local y = x(); print(y); return y", 1000000000);
failures += test_luacompexec1("local function x(); local i, j:integer; j=0; for i=1,1000000000 do; j = j+1; end; return j; end; local y = x(); print(y); return y", 1000000000);
failures += test_luacompexec1("local function x(); local j:number; for i=1,1000000000 do; j = j+1; end; return j; end; local y = x(); print(y); return y", 1000000000);
failures += test_luacompexec1("local function x(); local j = 0; for i=2,6,3 do; j = i; end; return j; end; local y = x(); print(y); return y", 5);
failures += test_luacompexec1("local function x(); local j = 0; for i=2.0,6.0,3.0 do; j = i; end; return j; end; local y = x(); print(y); return y", 5);
@ -139,48 +139,48 @@ int main(int argc, const char *argv[])
failures += test_luacompexec1("local function x(y); if y == 1 then; return 1.0; elseif y == 5 then; return 2.0; else; return 3.0; end; end; local z = x(4); print(z); return z", 3);
failures += test_luacompexec1("local function x(y,z); if y == 1 then; if z == 1 then; return 99.0; else; return z; end; elseif y == 5 then; return 2.0; else; return 3.0; end; end; local z = x(1,1); print(z); return z", 99);
failures += test_luacompexec1("local x:int[] = {1}; local i:int = 1; local d:int = x[i]; x[i] = 5; return d*x[i];", 5);
failures += test_luacompexec1("local function x(); local a:double = 1.0; return a+127 == 128.0; end; local y = x(); return y", 1);
failures += test_luacompexec1("local function x(); local a:double = 1.0; return a+128 == 129.0; end; local y = x(); return y", 1);
failures += test_luacompexec1("local function x(); local a:double = 1.0; return 127+a == 128.0; end; local y = x(); return y", 1);
failures += test_luacompexec1("local function x(); local a:double = 1.0; return 128+a == 129.0; end; local y = x(); return y", 1);
failures += test_luacompexec1("local function x(); local a:double = 1.0; return a+1.0 == 1.0+a; end; local y = x(); return y", 1);
failures += test_luacompexec1("local function x(); local a:int = 1; return a+127 == 128; end; local y = x(); return y", 1);
failures += test_luacompexec1("local function x(); local a:int = 1; return a+128 == 129; end; local y = x(); return y", 1);
failures += test_luacompexec1("local function x(); local a:int = 1; return 127+a == 128; end; local y = x(); return y", 1);
failures += test_luacompexec1("local function x(); local a:int = 1; return 128+a == 129; end; local y = x(); return y", 1);
failures += test_luacompexec1("local function x(); local a:int = 1; return a+1 == 1+a; end; local y = x(); return y", 1);
failures += test_luacomp1("local t = {}; local da : double[] = {}; da=t[1];") == 1 ? 0 : 1;
failures += test_luacompexec1("local function tryme(x); print(#x); return x; end; local da: double[] = { 5, 6 }; da[1] = 42; da = tryme(da); return da[1];", 42);
/* following should fail as x is a double[] */
failures += test_luacompexec1("local function tryme(x); print(#x); x[1] = 'junk'; return x; end; local da: double[] = {}; da[1] = 42; da = tryme(da); return da[1];", 42) == 1 ? 0 : 1;
failures += test_luacompexec1("local x:integer[] = {1}; local i:integer = 1; local d:integer = x[i]; x[i] = 5; return d*x[i];", 5);
failures += test_luacompexec1("local function x(); local a:number = 1.0; return a+127 == 128.0; end; local y = x(); return y", 1);
failures += test_luacompexec1("local function x(); local a:number = 1.0; return a+128 == 129.0; end; local y = x(); return y", 1);
failures += test_luacompexec1("local function x(); local a:number = 1.0; return 127+a == 128.0; end; local y = x(); return y", 1);
failures += test_luacompexec1("local function x(); local a:number = 1.0; return 128+a == 129.0; end; local y = x(); return y", 1);
failures += test_luacompexec1("local function x(); local a:number = 1.0; return a+1.0 == 1.0+a; end; local y = x(); return y", 1);
failures += test_luacompexec1("local function x(); local a:integer = 1; return a+127 == 128; end; local y = x(); return y", 1);
failures += test_luacompexec1("local function x(); local a:integer = 1; return a+128 == 129; end; local y = x(); return y", 1);
failures += test_luacompexec1("local function x(); local a:integer = 1; return 127+a == 128; end; local y = x(); return y", 1);
failures += test_luacompexec1("local function x(); local a:integer = 1; return 128+a == 129; end; local y = x(); return y", 1);
failures += test_luacompexec1("local function x(); local a:integer = 1; return a+1 == 1+a; end; local y = x(); return y", 1);
failures += test_luacomp1("local t = {}; local da : number[] = {}; da=t[1];") == 1 ? 0 : 1;
failures += test_luacompexec1("local function tryme(x); print(#x); return x; end; local da: number[] = { 5, 6 }; da[1] = 42; da = tryme(da); return da[1];", 42);
/* following should fail as x is a number[] */
failures += test_luacompexec1("local function tryme(x); print(#x); x[1] = 'junk'; return x; end; local da: number[] = {}; da[1] = 42; da = tryme(da); return da[1];", 42) == 1 ? 0 : 1;
failures += test_luacompexec1("for i=1,10 do; end; return 0", 0);
failures += test_luacomp1("local a : int[] = {}");
failures += test_luacompexec1("local a : double[], j:double = {}; for i=1,10 do; a[i] = i; j = j + a[i]; end; return j", 55);
failures += test_luacompexec1("local a:int[] = {}; local i:int; a[1] = i+5; i = a[1]; return i", 5);
failures += test_luacompexec1("local function tryme(); local i,j = 5,6; return i,j; end; local i:int, j:int = tryme(); return i+j", 11);
failures += test_luacompexec1("local i:int,j:int = 1; j = i*j+i; return j", 1);
failures += test_luacompexec1("local i:int; for i=1,10 do; print(i); end; print(i); return i", 0);
failures += test_luacomp1("local i:int, j:double; i,j = f(); j = i*j+i");
failures += test_luacomp1("local a : integer[] = {}");
failures += test_luacompexec1("local a : number[], j:number = {}; for i=1,10 do; a[i] = i; j = j + a[i]; end; return j", 55);
failures += test_luacompexec1("local a:integer[] = {}; local i:integer; a[1] = i+5; i = a[1]; return i", 5);
failures += test_luacompexec1("local function tryme(); local i,j = 5,6; return i,j; end; local i:integer, j:integer = tryme(); return i+j", 11);
failures += test_luacompexec1("local i:integer,j:integer = 1; j = i*j+i; return j", 1);
failures += test_luacompexec1("local i:integer; for i=1,10 do; print(i); end; print(i); return i", 0);
failures += test_luacomp1("local i:integer, j:number; i,j = f(); j = i*j+i");
failures += test_luacomp1("local d; d = f()");
failures += test_luacomp1("local d, e; d, e = f(), g()");
failures += test_luacomp1("local i:int, d:double = f()");
failures += test_luacomp1("local i:int,j:double,k:int = f(), g()");
failures += test_luacomp1("local f = function(); return; end; local d:double, j:int = f(); return d");
failures += test_luacomp1("local i:integer, d:number = f()");
failures += test_luacomp1("local i:integer,j:number,k:integer = f(), g()");
failures += test_luacomp1("local f = function(); return; end; local d:number, j:integer = f(); return d");
failures += test_luacomp1("local d = f()");
failures += test_luacomp1("return (-1.25 or -4)+0");
failures += test_luacomp1("f = nil; local f; function f(a); end");
failures += test_luacomp1("local max, min = 0x7fffffff, -0x80000000; assert(string.format(\"%d\", min) == \"-2147483648\"); max, min = 0x7fffffffffffffff, -0x8000000000000000; if max > 2.0 ^ 53 then; end;");
failures += test_luacomp1("local function F (m); local function round(m); m = m + 0.04999; return format(\"%.1f\", m);end; end");
failures += test_luacomp1("local b:int = 6; local i:int = 5+b; return i");
failures += test_luacompexec1("local b:int = 6; local i:int = 5+b; return i", 11);
failures += test_luacomp1("local b:integer = 6; local i:integer = 5+b; return i");
failures += test_luacompexec1("local b:integer = 6; local i:integer = 5+b; return i", 11);
failures += test_luacomp1("local f = function(); end");
failures += test_luacomp1("local b:int = 6; b = nil; return i") == 0; /* should fail */
failures += test_luacomp1("local b:integer = 6; b = nil; return i") == 0; /* should fail */
failures += test_luacomp1("local f = function(); local function y() ; end; end");
failures += test_luacompexec1("return -(1 or 2)", -1);
failures += test_luacompexec1("return (1 and 2)+(-1.25 or -4) == 0.75", 1);
failures += test_luacomp1("local a=1; if a==0 then; a = 2; else a=3; end;");
failures += test_luacomp1("local f = function(); return; end; local d:double = 5.0; d = f(); return d");
failures += test_luacomp1("local f = function(); return; end; local d:number = 5.0; d = f(); return d");
failures += test_luacomp1("local f = function(); return; end; local d = 5.0; d = f(); return d");
return failures ? 1 : 0;
}

Loading…
Cancel
Save