gccjit-ravi534
Dibyendu Majumdar 7 years ago
parent 2923ac78f6
commit 654013698f

@ -1,5 +1,5 @@
/*
** $Id: lauxlib.h,v 1.129 2015/11/23 11:29:43 roberto Exp $
** $Id: lauxlib.h,v 1.131 2016/12/06 14:54:31 roberto Exp $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/

@ -36,7 +36,7 @@ typedef enum BinOpr {
OPR_NOBINOPR
} BinOpr;
/** RAVI change */
typedef enum UnOpr { OPR_MINUS, OPR_BNOT, OPR_NOT, OPR_LEN, OPR_TO_INTEGER,
OPR_TO_NUMBER, OPR_TO_INTARRAY, OPR_TO_NUMARRAY, OPR_TO_TABLE, OPR_NOUNOPR } UnOpr;

@ -34,6 +34,7 @@ enum RESERVED {
TK_SHL, TK_SHR,
TK_DBCOLON, TK_EOS,
TK_FLT, TK_INT, TK_NAME, TK_STRING,
/** RAVI extensions */
TK_TO_INTEGER, TK_TO_NUMBER, TK_TO_INTARRAY, TK_TO_NUMARRAY,
TK_TO_TABLE
};

@ -82,6 +82,7 @@ typedef LUAI_UACINT l_uacInt;
/* internal assertions for in-house debugging */
#if defined(lua_assert)
/** RAVI changes */
#if !defined(RAVI_OPTION_STRING1)
#define RAVI_OPTION_STRING1 " assertions"
#endif
@ -95,6 +96,7 @@ typedef LUAI_UACINT l_uacInt;
#define lua_assert(c) ((void)0)
#define check_exp(c,e) (e)
#define lua_longassert(c) ((void)0)
/** RVAI changes */
#define RAVI_OPTION_STRING1
#define RAVI_OPTION_STRING2
#endif

@ -1,5 +1,5 @@
/*
** $Id: lobject.h,v 2.116 2015/11/03 18:33:10 roberto Exp roberto $
** $Id: lobject.h,v 2.117 2016/08/01 19:51:24 roberto Exp $
** Type definitions for Lua objects
** See Copyright Notice in lua.h
*/
@ -57,7 +57,7 @@
/* Variant tags for numbers */
#define LUA_TNUMFLT (LUA_TNUMBER | (0 << 4)) /* float numbers */
#define LUA_TNUMINT (LUA_TNUMBER | (1 << 4)) /* integer numbers */
/** RAVI table sunbtypes **/
#define RAVI_TIARRAY (LUA_TTABLE | (1 << 4)) /* Ravi int array */
#define RAVI_TFARRAY (LUA_TTABLE | (2 << 4)) /* Ravi float array */
@ -151,7 +151,7 @@ typedef struct lua_TValue {
#define ttisstring(o) checktype((o), LUA_TSTRING)
#define ttisshrstring(o) checktag((o), ctb(LUA_TSHRSTR))
#define ttislngstring(o) checktag((o), ctb(LUA_TLNGSTR))
/* Ravi change: we support two sub types of table type
/* RAVI change: we support two sub types of table type
and hence need to distinguish between the types.
ttistable() returns true for all table types
ttisLtable() only returns true if the value is a Lua table
@ -265,17 +265,18 @@ typedef struct lua_TValue {
val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TTABLE)); \
checkliveness(L,io); }
/** RAVI extension **/
#define setiarrayvalue(L,obj,x) \
{ TValue *io = (obj); Table *x_ = (x); \
val_(io).gc = obj2gco(x_); settt_(io, ctb(RAVI_TIARRAY)); \
checkliveness(L,io); }
/** RAVI extension **/
#define setfarrayvalue(L,obj,x) \
{ TValue *io = (obj); Table *x_ = (x); \
val_(io).gc = obj2gco(x_); settt_(io, ctb(RAVI_TFARRAY)); \
checkliveness(L,io); }
#define setdeadvalue(obj) settt_(obj, LUA_TDEADKEY)
@ -403,7 +404,7 @@ typedef union UUdata {
io->value_ = iu->user_; settt_(io, iu->ttuv_); \
checkliveness(L,io); }
/* Following are the types we will use
/* RAVI: Following are the types we will use
** use in parsing. The rationale for types is
** performance - as of now these are the only types that
** we care about from a performance point of view - if any
@ -445,6 +446,7 @@ typedef struct LocVar {
ravitype_t ravi_type; /* RAVI type of the variable - RAVI_TANY if unknown */
} LocVar;
/** RAVI changes start */
typedef enum {
RAVI_JIT_NOT_COMPILED = 0,
RAVI_JIT_CANT_COMPILE = 1,
@ -463,6 +465,7 @@ typedef struct RaviJITProto {
void *jit_data;
lua_CFunction jit_function;
} RaviJITProto;
/** RAVI changes end */
/*
** Function Prototypes
@ -489,7 +492,7 @@ typedef struct Proto {
struct LClosure *cache; /* last-created closure with this prototype */
TString *source; /* used for debug information */
GCObject *gclist;
/* RAVI */
/* RAVI extension */
RaviJITProto ravi_jit;
} Proto;
@ -558,12 +561,13 @@ typedef struct Node {
TKey i_key;
} Node;
/** RAVI extension */
typedef enum RaviArrayModifer {
RAVI_ARRAY_SLICE = 1,
RAVI_ARRAY_FIXEDSIZE = 2
} RaviArrayModifier;
/** RAVI extension */
typedef struct RaviArray {
char *data;
unsigned int len; /* RAVI len specialization */
@ -582,6 +586,7 @@ typedef struct Table {
Node *lastfree; /* any free position is before this position */
struct Table *metatable;
GCObject *gclist;
/** RAVI extension */
RaviArray ravi_array;
} Table;

@ -1,5 +1,5 @@
/*
** $Id: lopcodes.h,v 1.148 2014/10/25 11:50:46 roberto Exp roberto $
** $Id: lopcodes.h,v 1.149 2016/07/19 17:12:21 roberto Exp $
** Opcodes for Lua virtual machine
** See Copyright Notice in lua.h
*/
@ -35,6 +35,7 @@ enum OpMode {iABC, iABx, iAsBx, iAx}; /* basic instruction format */
/*
** size and position of opcode arguments.
*/
/** RAVI changes **/
#define SIZE_C 8
#define SIZE_B 8
#define SIZE_Bx (SIZE_C + SIZE_B)

@ -66,7 +66,7 @@ typedef struct expdesc {
short idx; /* index (R/K) */
lu_byte t; /* table (register or upvalue) */
lu_byte vt; /* whether 't' is register (VLOCAL) or upvalue (VUPVAL) */
ravitype_t key_type; /* key type */
ravitype_t key_type; /* RAVI change: key type */
} ind;
} u;
int t; /* patch list of 'exit when true' */
@ -238,7 +238,7 @@ typedef struct FuncState {
LUAI_FUNC LClosure *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff,
Dyndata *dyd, const char *name, int firstchar);
/** RAVI extensions **/
LUAI_FUNC const char *raviY_typename(ravitype_t tt);
/* Special printf that recognises following conversions:

@ -1,5 +1,5 @@
/*
** $Id: lstate.h,v 2.130 2015/12/16 16:39:38 roberto Exp $
** $Id: lstate.h,v 2.133 2016/12/22 13:08:50 roberto Exp $
** Global State
** See Copyright Notice in lua.h
*/
@ -89,8 +89,8 @@ typedef struct CallInfo {
ptrdiff_t extra;
short nresults; /* expected number of results from this function */
unsigned short callstatus;
unsigned short stacklevel; /* Ravi extension - stack level, bottom level is 0 */
lu_byte jitstatus; /* Only valid if Lua function - if 1 means JITed - RAVI extension */
unsigned short stacklevel; /* RAVI extension - stack level, bottom level is 0 */
lu_byte jitstatus; /* RAVI extension: Only valid if Lua function - if 1 means JITed - RAVI extension */
} CallInfo;
@ -109,12 +109,14 @@ typedef struct CallInfo {
#define CIST_FIN (1<<8) /* call is running a finalizer */
#define isLua(ci) ((ci)->callstatus & CIST_LUA)
/** RAVI extension **/
#define isJITed(ci) ((ci)->jitstatus)
/* assume that CIST_OAH has offset 0 and that 'v' is strictly 0/1 */
#define setoah(st,v) ((st) = ((st) & ~CIST_OAH) | (v))
#define getoah(st) ((st) & CIST_OAH)
/** RAVI extension **/
typedef struct ravi_State ravi_State;
/*
@ -155,7 +157,7 @@ typedef struct global_State {
TString *tmname[TM_N]; /* array with tag-method names */
struct Table *mt[LUA_NUMTAGS]; /* metatables for basic types */
TString *strcache[STRCACHE_N][STRCACHE_M]; /* cache for strings in API */
/* RAVI */
/* RAVI additions */
ravi_State *ravi_state;
ravi_Writeline ravi_writeline;
ravi_Writestring ravi_writestring;
@ -193,8 +195,16 @@ struct lua_State {
int hookcount;
unsigned short nny; /* number of non-yieldable calls in stack */
unsigned short nCcalls; /* number of nested C calls */
/** RAVI difference - changing type of hookmask
** changes to JIT definitions and possibly code. This is
** pending
*/
lu_byte hookmask;
lu_byte allowhook;
/** RAVI difference - movig nci requires
** changes to JIT definitions and possibly code. This is
** pending
*/
unsigned short nci; /* number of items in 'ci' list */
};
@ -226,6 +236,7 @@ union GCUnion {
#define gco2ccl(o) check_exp((o)->tt == LUA_TCCL, &((cast_u(o))->cl.c))
#define gco2cl(o) \
check_exp(novariant((o)->tt) == LUA_TFUNCTION, &((cast_u(o))->cl))
/** RAVI change - we have table sub types in RAVI **/
#define gco2t(o) check_exp(novariant((o)->tt) == LUA_TTABLE, &((cast_u(o))->h))
#define gco2p(o) check_exp((o)->tt == LUA_TPROTO, &((cast_u(o))->p))
#define gco2th(o) check_exp((o)->tt == LUA_TTHREAD, &((cast_u(o))->th))
@ -245,7 +256,7 @@ LUAI_FUNC CallInfo *luaE_extendCI (lua_State *L);
LUAI_FUNC void luaE_freeCI (lua_State *L);
LUAI_FUNC void luaE_shrinkCI (lua_State *L);
/* Ravi addition - this is the default implementation behind writing to stderr */
/* RAVI addition - this is the default implementation behind writing to stderr */
LUAI_FUNC void raviE_default_writestringerror(const char *fmt, const char *p);

@ -1,5 +1,5 @@
/*
** $Id: ltable.h,v 2.21 2015/11/03 15:47:30 roberto Exp $
** $Id: ltable.h,v 2.23 2016/12/22 13:08:50 roberto Exp $
** Lua tables (hash)
** See Copyright Notice in lua.h
*/
@ -39,30 +39,22 @@
#define keyfromval(v) \
(gkey(cast(Node *, cast(char *, (v)) - offsetof(Node, i_val))))
LUAI_FUNC const TValue *luaH_getint (Table *t, lua_Integer key);
LUAI_FUNC void luaH_setint (lua_State *L, Table *t, lua_Integer key,
TValue *value);
/** RAVI change start - attempt to inline some functions **/
#if defined(RAVI_ENABLED)
#define hashpow2(t,n) (gnode(t, lmod((n), sizenode(t))))
#define hashstr(t,str) hashpow2(t, (str)->hash)
#define hashboolean(t,p) hashpow2(t, p)
#define hashint(t,i) hashpow2(t, i)
/*
** for some types, it is better to avoid modulus by power of 2, as
** they tend to have many 2 factors.
*/
#define hashmod(t,n) (gnode(t, ((n) % ((sizenode(t)-1)|1))))
#define hashpointer(t,p) hashmod(t, point2uint(p))
#endif
LUAI_FUNC const TValue *luaH_getint (Table *t, lua_Integer key);
LUAI_FUNC void luaH_setint (lua_State *L, Table *t, lua_Integer key,
TValue *value);
#if defined(RAVI_ENABLED)
/*
** search function for short strings
*/

@ -43,7 +43,7 @@ typedef enum {
TM_N /* number of elements in the enum */
} TMS;
/* The macro metamethod absent tests whether it is known that a metatable
/* RAVI change: the macro metamethod absent tests whether it is known that a metatable
* lacks a metamethod. This is true if a) metatable is NULL, or b) the bit
* related to the metamethod is set in t->flags
*/
@ -60,7 +60,7 @@ LUAI_DDEC const char *const luaT_typenames_[LUA_TOTALTAGS];
LUAI_FUNC const char *luaT_objtypename (lua_State *L, const TValue *o);
/* Extended version that distinguishes between table subtypes*/
/* RAVI change: extended version that distinguishes between table subtypes*/
LUAI_FUNC const char *raviT_objtypename(lua_State *L, const TValue *o);
LUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename);

@ -1,5 +1,5 @@
/*
** $Id: lua.h,v 1.331 2016/05/30 15:53:28 roberto Exp $
** $Id: lua.h,v 1.332 2016/12/22 15:51:20 roberto Exp $
** Lua - A Scripting Language
** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
** See Copyright Notice at the end of this file
@ -123,9 +123,11 @@ typedef int (*lua_Writer) (lua_State *L, const void *p, size_t sz, void *ud);
*/
typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize);
/** RAVI change start **/
typedef void(*ravi_Writestring)(const char *s, size_t len);
typedef void(*ravi_Writeline)(void);
typedef void(*ravi_Writestringerror)(const char *fmt, const char *p);
/** RAVI change end **/
/*
** generic extra include file
@ -179,9 +181,11 @@ LUA_API int (lua_isinteger) (lua_State *L, int idx);
LUA_API int (lua_isuserdata) (lua_State *L, int idx);
LUA_API int (lua_type) (lua_State *L, int idx);
LUA_API const char *(lua_typename) (lua_State *L, int tp);
/* This is a Ravi extension - it is similar to lua_typename() except
that it provides more granular type information, and also uses
metamethod __name() if available for userdata and table types */
/* RAVI change:
** This is a Ravi extension - it is similar to lua_typename() except
** that it provides more granular type information, and also uses
** metamethod __name() if available for userdata and table types
*/
LUA_API const char * (ravi_typename) (lua_State *L, int idx);
LUA_API lua_Number (lua_tonumberx) (lua_State *L, int idx, int *isnum);
@ -458,7 +462,7 @@ struct lua_Debug {
char isvararg; /* (u) */
char istailcall; /* (t) */
char short_src[LUA_IDSIZE]; /* (S) */
short stacklevel; /* Ravi: Current stack level within the Lua State - base level is 0 */
short stacklevel; /* RAVI change: Current stack level within the Lua State - base level is 0 */
/* private part */
struct CallInfo *i_ci; /* active function */
};

@ -1,5 +1,5 @@
/*
** $Id: luaconf.h,v 1.256 2016/07/18 17:55:59 roberto Exp roberto $
** $Id: luaconf.h,v 1.259 2016/12/22 13:08:50 roberto Exp $
** Configuration file for Lua
** See Copyright Notice in lua.h
*/
@ -277,6 +277,7 @@
*/
#if defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \
defined(__ELF__) /* { */
/** RAVI change **/
#define LUAI_FUNC /* __attribute__((visibility("hidden")))*/ extern
#else /* }{ */
#define LUAI_FUNC extern
@ -775,7 +776,7 @@
** without modifying the main part of the file.
*/
/** RAVI additions below **/
#if _WIN32 && _MSC_VER < 1900
#define snprintf _snprintf
#endif

@ -44,6 +44,7 @@ LUAMOD_API int (luaopen_debug) (lua_State *L);
#define LUA_LOADLIBNAME "package"
LUAMOD_API int (luaopen_package) (lua_State *L);
/** RAVI change start **/
#define LUA_RAVILIBNAME "ravi"
LUAMOD_API int (raviopen_llvmjit)(lua_State *L);
@ -51,7 +52,7 @@ LUAMOD_API int (raviopen_llvmjit)(lua_State *L);
#define LUA_LLVMLIBNAME "llvm"
LUAMOD_API int (raviopen_llvmluaapi)(lua_State *L);
#endif
/** RAVI change end */
/* open all previous libraries */
LUALIB_API void (luaL_openlibs) (lua_State *L);
@ -59,8 +60,10 @@ LUALIB_API void (luaL_openlibs) (lua_State *L);
#if !defined(lua_assert)
#define lua_assert(x) ((void)0)
/** RAVI change start **/
#define RAVI_OPTION_STRING1
#define RAVI_OPTION_STRING2
/** RAVI change end **/
#endif

@ -1,5 +1,5 @@
/*
** $Id: lvm.h,v 2.40 2016/01/05 16:07:21 roberto Exp $
** $Id: lvm.h,v 2.41 2016/12/22 13:08:50 roberto Exp $
** Lua virtual machine
** See Copyright Notice in lua.h
*/
@ -63,6 +63,8 @@
/*
** standard implementation for 'gettable'
** RAVI change - renamed as we need luaV_gettable to be
** an exported function
*/
#define luaV_fastgettable(L,t,k,v) { const TValue *slot; \
if (luaV_fastget(L,t,k,slot,luaH_get)) { setobj2s(L, v, slot); } \
@ -86,7 +88,10 @@
setobj2t(L, cast(TValue *,slot), v), \
1)))
/*
** RAVI change - renamed as we need luaV_settable to be
** an exported function
*/
#define luaV_fastsettable(L,t,k,v) { const TValue *slot; \
if (!luaV_fastset(L,t,k,slot,luaH_get,v)) \
luaV_finishset(L,t,k,v,slot); }
@ -98,17 +103,19 @@ LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r);
LUAI_FUNC int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r);
LUAI_FUNC int luaV_tonumber_ (const TValue *obj, lua_Number *n);
LUAI_FUNC int luaV_tointeger (const TValue *obj, lua_Integer *p, int mode);
/** RAVI changes start **/
LUAI_FUNC int luaV_tointeger_(const TValue *obj, lua_Integer *p);
LUAI_FUNC void luaV_gettable (lua_State *L, const TValue *t, TValue *key,
StkId val);
LUAI_FUNC void luaV_settable (lua_State *L, const TValue *t, TValue *key,
StkId val);
/** RAVI changed end **/
LUAI_FUNC void luaV_finishget (lua_State *L, const TValue *t, TValue *key,
StkId val, const TValue *slot);
LUAI_FUNC void luaV_finishset (lua_State *L, const TValue *t, TValue *key,
StkId val, const TValue *slot);
LUAI_FUNC void luaV_finishOp (lua_State *L);
/* The int return value is a Ravi extension */
/* RAVI change: the int return value is a Ravi extension */
LUAI_FUNC int luaV_execute (lua_State *L);
LUAI_FUNC void luaV_concat (lua_State *L, int total);
LUAI_FUNC lua_Integer luaV_div (lua_State *L, lua_Integer x, lua_Integer y);
@ -116,7 +123,7 @@ LUAI_FUNC lua_Integer luaV_mod (lua_State *L, lua_Integer x, lua_Integer y);
LUAI_FUNC lua_Integer luaV_shiftl (lua_Integer x, lua_Integer y);
LUAI_FUNC void luaV_objlen (lua_State *L, StkId ra, const TValue *rb);
/* RAVI changes for JIT */
/* RAVI changes start for JIT */
/* The following expose some of the VM opcodes for the JIT compiler */
LUAI_FUNC int luaV_forlimit(const TValue *obj, lua_Integer *p, lua_Integer step,
int *stopnow);

@ -1,5 +1,6 @@
#!../lua
-- $Id: all.lua,v 1.94 2015/09/17 16:45:19 roberto Exp $
-- $Id: all.lua,v 1.95 2016/11/07 13:11:28 roberto Exp $
-- See Copyright Notice at the end of this file
local version = "Ravi 5.3"
if _VERSION ~= version then
@ -265,3 +266,30 @@ end
print("final OK !!!")
--[[
*****************************************************************************
* Copyright (C) 1994-2016 Lua.org, PUC-Rio.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*****************************************************************************
]]

@ -1,4 +1,5 @@
-- $Id: api.lua,v 1.146 2016/01/07 16:45:45 roberto Exp $
-- $Id: api.lua,v 1.147 2016/11/07 13:06:25 roberto Exp $
-- See Copyright Notice in file all.lua
if T==nil then
(Message or print)('\n >>> testC not active: skipping API tests <<<\n')

@ -1,4 +1,5 @@
-- $Id: attrib.lua,v 1.64 2016/01/07 16:46:37 roberto Exp $
-- $Id: attrib.lua,v 1.65 2016/11/07 13:11:28 roberto Exp $
-- See Copyright Notice in file all.lua
print "testing require"

@ -1,4 +1,5 @@
-- $Id: big.lua,v 1.31 2014/12/26 17:20:53 roberto Exp $
-- $Id: big.lua,v 1.32 2016/11/07 13:11:28 roberto Exp $
-- See Copyright Notice in file all.lua
if _soft then
return 'a'

@ -1,4 +1,5 @@
-- $Id: bitwise.lua,v 1.25 2015/04/30 14:15:57 roberto Exp $
-- $Id: bitwise.lua,v 1.26 2016/11/07 13:11:28 roberto Exp $
-- See Copyright Notice in file all.lua
print("testing bitwise operations")

@ -1,4 +1,5 @@
-- $Id: calls.lua,v 1.59 2015/11/13 13:46:31 roberto Exp $
-- $Id: calls.lua,v 1.60 2016/11/07 13:11:28 roberto Exp $
-- See Copyright Notice in file all.lua
print("testing functions and calls")

@ -1,4 +1,5 @@
-- $Id: closure.lua,v 1.58 2014/12/26 17:20:53 roberto Exp $
-- $Id: closure.lua,v 1.59 2016/11/07 13:11:28 roberto Exp $
-- See Copyright Notice in file all.lua
print "testing closures"

@ -1,4 +1,5 @@
-- $Id: code.lua,v 1.41 2014/12/26 17:18:43 roberto Exp $
-- $Id: code.lua,v 1.42 2016/11/07 13:04:32 roberto Exp $
-- See Copyright Notice in file all.lua
if T==nil then
(Message or print)('\n >>> testC not active: skipping opcode tests <<<\n')
@ -116,7 +117,7 @@ check(function () return not not 1 end, 'LOADBOOL', 'RETURN')
check(function ()
local a,b,c,d
a = b*2
c[4], a[b] = -((a + d/-20.5 - a[b]) ^ a.x), b
c[2], a[b] = -((a + d/2 - a[b]) ^ a.x), b
end,
'LOADNIL',
'MUL',
@ -127,17 +128,25 @@ end,
-- direct access to constants
check(function ()
local a,b
a.x = 0
a.x = 3.2
a.x = b
a[b] = 'y'
a[b] = 'x'
end,
'LOADNIL', 'SETTABLE', 'SETTABLE', 'SETTABLE', 'RETURN')
check(function ()
local a,b
a = 1 - a
b = 1/a
b = 5+4
b = 5-4
end,
'LOADNIL', 'SUB', 'DIV', 'LOADK', 'RETURN')
check(function ()
local a,b
a[true] = false
end,
'LOADNIL',
'SETTABLE', 'SETTABLE', 'SETTABLE', 'SUB', 'DIV', 'LOADK',
'SETTABLE', 'RETURN')
'LOADNIL', 'SETTABLE', 'RETURN')
-- constant folding
@ -165,7 +174,7 @@ checkK(function () return ((100 << 6) << -4) >> 2 end, 100)
-- no foldings
check(function () return -0.0 end, 'LOADK', 'UNM', 'RETURN')
--check(function () return 3/0 end, 'DIV', 'RETURN')
check(function () return 3/0 end, 'DIVII', 'RETURN')
check(function () return 0%0 end, 'MOD', 'RETURN')
check(function () return -4//0 end, 'IDIV', 'RETURN')
@ -192,7 +201,7 @@ end,
checkequal(function () if (a==nil) then a=1 end; if a~=nil then a=1 end end,
function () if (a==9) then a=1 end; if a~=9 then a=1 end end)
check(function () if a==nil then a=1 end end,
check(function () if a==nil then a='a' end end,
'GETTABUP', 'EQ', 'JMP', 'SETTABUP', 'RETURN')
-- de morgan
@ -204,11 +213,11 @@ checkequal(function (l) local a; return 0 <= a and a <= l end,
-- if-goto optimizations
check(function (a)
if a == 1 then goto l1
elseif a == 2 then goto l2
elseif a == 3 then goto l2
else if a == 4 then goto l3
check(function (a, b, c, d, e)
if a == b then goto l1
elseif a == c then goto l2
elseif a == d then goto l2
else if a == e then goto l3
else goto l3
end
end

@ -1,4 +1,5 @@
-- $Id: constructs.lua,v 1.40 2015/10/08 15:58:10 roberto Exp $
-- $Id: constructs.lua,v 1.41 2016/11/07 13:11:28 roberto Exp $
-- See Copyright Notice in file all.lua
;;print "testing syntax";;

@ -1,4 +1,5 @@
-- $Id: coroutine.lua,v 1.40 2015/10/12 16:38:57 roberto Exp $
-- $Id: coroutine.lua,v 1.42 2016/11/07 13:03:20 roberto Exp $
-- See Copyright Notice in file all.lua
print "testing coroutines"
@ -260,6 +261,20 @@ assert(coroutine.resume(co, co) == false)
assert(coroutine.resume(co, co) == false)
-- other old bug when attempting to resume itself
-- (trigger C-code assertions)
do
local A = coroutine.running()
local B = coroutine.create(function() return coroutine.resume(A) end)
local st, res = coroutine.resume(B)
assert(st == true and res == false)
A = coroutine.wrap(function() return pcall(A, 1) end)
st, res = A()
assert(not st and string.find(res, "non%-suspended"))
end
-- attempt to resume 'normal' coroutine
local co1, co2
co1 = coroutine.create(function () return co2() end)
@ -351,7 +366,7 @@ else
_G.XX = nil;
local c = 0
repeat c = c + 1; local a = co() until a == 10
assert(_G.XX == 20 and c == 10)
assert(_G.XX == 20 and c >= 5)
co = coroutine.wrap(function ()
T.sethook("yield 0", "", 2); foo(); return 10 end)
@ -359,7 +374,7 @@ else
_G.XX = nil;
local c = 0
repeat c = c + 1; local a = co() until a == 10
assert(_G.XX == 20 and c == 5)
assert(_G.XX == 20 and c >= 5)
_G.X = nil; _G.XX = nil
do

@ -1,4 +1,5 @@
-- $Id: db.lua,v 1.78 2015/10/02 15:47:27 roberto Exp $
-- $Id: db.lua,v 1.79 2016/11/07 13:02:34 roberto Exp $
-- See Copyright Notice in file all.lua
-- testing debug library
@ -14,7 +15,8 @@ end
assert(not debug.gethook())
function test (s, l, p)
local testline = 19 -- line where 'test' is defined
function test (s, l, p) -- this must be line 19
collectgarbage() -- avoid gc during trace
local function f (event, line)
assert(event == 'line')
@ -36,7 +38,7 @@ do
a = debug.getinfo(print, "L")
assert(a.activelines == nil)
local b = debug.getinfo(test, "SfL")
assert(b.name == nil and b.what == "Lua" and b.linedefined == 17 and
assert(b.name == nil and b.what == "Lua" and b.linedefined == testline and
b.lastlinedefined == b.linedefined + 10 and
b.func == test and not string.find(b.short_src, "%["))
assert(b.activelines[b.linedefined + 1] and
@ -719,6 +721,22 @@ do -- testing for-iterator name
end
do -- testing debug info for finalizers
local name = nil
-- create a piece of garbage with a finalizer
setmetatable({}, {__gc = function ()
local t = debug.getinfo(2) -- get callee information
assert(t.namewhat == "metamethod")
name = t.name
end})
-- repeat until previous finalizer runs (setting 'name')
repeat local a = {} until name
assert(name == "__gc")
end
do
print("testing traceback sizes")

@ -1,4 +1,5 @@
-- $Id: errors.lua,v 1.92 2016/03/07 19:27:08 roberto Exp $
-- $Id: errors.lua,v 1.94 2016/12/21 19:23:02 roberto Exp $
-- See Copyright Notice in file all.lua
print("testing errors")
@ -147,6 +148,7 @@ _G.D = nil
do -- named objects (field '__name')
checkmessage("math.sin(io.input())", "(number expected, got FILE*)")
_G.XX = setmetatable({}, {__name = "My Type"})
assert(string.find(tostring(XX), "^My Type"))
checkmessage("io.input(XX)", "(FILE* expected, got My Type)")
checkmessage("return XX + 1", "on a My Type value")
checkmessage("return ~io.stdin", "on a FILE* value")

@ -1,4 +1,5 @@
-- $Id: events.lua,v 1.43 2016/01/14 16:27:25 roberto Exp $
-- $Id: events.lua,v 1.45 2016/12/21 19:23:02 roberto Exp $
-- See Copyright Notice in file all.lua
print('testing metatables')
@ -20,10 +21,10 @@ assert(B == 30)
assert(getmetatable{} == nil)
assert(getmetatable(4) == nil)
assert(getmetatable(nil) == nil)
a={}; setmetatable(a, {__metatable = "xuxu",
a={name = "NAME"}; setmetatable(a, {__metatable = "xuxu",
__tostring=function(x) return x.name end})
assert(getmetatable(a) == "xuxu")
--assert(tostring(a) == nil)
assert(tostring(a) == "NAME")
-- cannot change a protected metatable
assert(pcall(setmetatable, a, {}) == false)
a.name = "gororoba"

@ -1,4 +1,5 @@
-- $Id: files.lua,v 1.93 2016/04/13 16:25:31 roberto Exp $
-- $Id: files.lua,v 1.95 2016/11/07 13:11:28 roberto Exp $
-- See Copyright Notice in file all.lua
local debug = require "debug"
@ -677,6 +678,8 @@ print("testing date/time")
assert(os.date("") == "")
assert(os.date("!") == "")
assert(os.date("\0\0") == "\0\0")
assert(os.date("!\0\0") == "\0\0")
local x = string.rep("a", 10000)
assert(os.date(x) == x)
local t = os.time()
@ -701,6 +704,8 @@ checkerr("invalid conversion specifier", os.date, "%Ea")
checkerr("not an integer", os.time, {year=1000, month=1, day=1, hour='x'})
checkerr("not an integer", os.time, {year=1000, month=1, day=1, hour=1.5})
checkerr("missing", os.time, {hour = 12}) -- missing date
if not _port then
-- test Posix-specific modifiers
assert(type(os.date("%Ex")) == 'string')
@ -734,11 +739,6 @@ if not _port then
end
-- assume that time has at least 1-second precision
assert(math.abs(os.difftime(os.time(D), t)) < 1)
assert(not pcall(os.time, {hour = 12})) -- missing date
D = os.date("!*t", t)
load(os.date([[!assert(D.year==%Y and D.month==%m and D.day==%d and
D.hour==%H and D.min==%M and D.sec==%S and
@ -759,11 +759,13 @@ local t1 = os.time(D)
-- allow for leap years
assert(math.abs(os.difftime(t,t1)/(24*3600) - 365) < 2)
-- should not take more than 2 second to execute these two lines
-- should not take more than 1 second to execute these two lines
t = os.time()
t1 = os.time(os.date("*t"))
t1 = os.difftime(t1,t)
assert(0 <= t1 and t1 <= 2)
local diff = os.difftime(t1,t)
assert(0 <= diff and diff <= 1)
diff = os.difftime(t,t1)
assert(-1 <= diff and diff <= 0)
local t1 = os.time{year=2000, month=10, day=1, hour=23, min=12}
local t2 = os.time{year=2000, month=10, day=1, hour=23, min=10, sec=19}

@ -1,4 +1,5 @@
-- $Id: gc.lua,v 1.71 2016/03/07 19:31:35 roberto Exp $
-- $Id: gc.lua,v 1.72 2016/11/07 13:11:28 roberto Exp $
-- See Copyright Notice in file all.lua
print('testing garbage collection')

@ -1,4 +1,5 @@
-- $Id: goto.lua,v 1.12 2016/03/07 19:26:18 roberto Exp $
-- $Id: goto.lua,v 1.13 2016/11/07 13:11:28 roberto Exp $
-- See Copyright Notice in file all.lua
collectgarbage()

@ -1,4 +1,5 @@
-- $Id: literals.lua,v 1.35 2016/05/03 15:35:29 roberto Exp $
-- $Id: literals.lua,v 1.36 2016/11/07 13:11:28 roberto Exp $
-- See Copyright Notice in file all.lua
print('testing scanner')

@ -1,4 +1,5 @@
-- $Id: locals.lua,v 1.36 2015/03/04 13:09:38 roberto Exp $
-- $Id: locals.lua,v 1.37 2016/11/07 13:11:28 roberto Exp $
-- See Copyright Notice in file all.lua
print('testing local variables and environments')

@ -1,5 +1,5 @@
/*
** $Id: ltests.c,v 2.205 2015/04/02 21:10:21 roberto Exp $
** $Id: ltests.c,v 2.211 2016/12/04 20:17:24 roberto Exp $
** Internal Module for Debugging of the Lua Implementation
** See Copyright Notice in lua.h
*/
@ -687,8 +687,8 @@ static int table_query (lua_State *L) {
t = hvalue(obj_at(L, 1));
if (i == -1) {
lua_pushinteger(L, t->sizearray);
lua_pushinteger(L, luaH_isdummy(t->node) ? 0 : sizenode(t));
lua_pushinteger(L, t->lastfree - t->node);
lua_pushinteger(L, allocsizenode(t));
lua_pushinteger(L, isdummy(t) ? 0 : t->lastfree - t->node);
}
else if ((unsigned int)i < t->sizearray) {
lua_pushinteger(L, i);
@ -869,7 +869,7 @@ static int loadlib (lua_State *L) {
luaL_requiref(L1, "package", NULL, 1); /* seg. fault if it reloads */
/* ...but should return the same module */
lua_assert(lua_compare(L1, -1, -2, LUA_OPEQ));
luaL_getsubtable(L1, LUA_REGISTRYINDEX, "_PRELOAD");
luaL_getsubtable(L1, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE);
for (i = 0; libs[i].name; i++) {
lua_pushcfunction(L1, libs[i].func);
lua_setfield(L1, -2, libs[i].name);

@ -1,5 +1,5 @@
/*
** $Id: ltests.h,v 2.49 2015/09/22 14:18:24 roberto Exp $
** $Id: ltests.h,v 2.50 2016/07/19 17:13:00 roberto Exp $
** Internal Header for Debugging of the Lua Implementation
** See Copyright Notice in lua.h
*/
@ -98,7 +98,9 @@ LUA_API void *debug_realloc (void *ud, void *block,
#if defined(lua_c)
#define luaL_newstate() lua_newstate(debug_realloc, &l_memcontrol)
#define luaL_openlibs(L) \
{ (luaL_openlibs)(L); luaL_requiref(L, "T", luaB_opentests, 1); }
{ (luaL_openlibs)(L); \
luaL_requiref(L, "T", luaB_opentests, 1); \
lua_pop(L, 1); }
#endif
@ -108,6 +110,7 @@ LUA_API void *debug_realloc (void *ud, void *block,
#undef LUAL_BUFFERSIZE
#define LUAL_BUFFERSIZE 23
#define MINSTRTABSIZE 2
#define MAXINDEXRK 1
/* make stack-overflow tests run faster */

@ -1,5 +1,6 @@
# testing special comment on first line
-- $Id: main.lua,v 1.64 2016/04/13 16:25:59 roberto Exp $
-- $Id: main.lua,v 1.65 2016/11/07 13:11:28 roberto Exp $
-- See Copyright Notice in file all.lua
-- most (all?) tests here assume a reasonable "Unix-like" shell
if _port then return end

@ -1,4 +1,5 @@
-- $Id: math.lua,v 1.76 2016/05/30 15:55:38 roberto Exp $
-- $Id: math.lua,v 1.78 2016/11/07 13:11:28 roberto Exp $
-- See Copyright Notice in file all.lua
print("testing numbers and math lib")
@ -23,9 +24,11 @@ end
local function isNaN (x)
return (x ~= x)
-- return true
end
assert(isNaN(0/0))
assert(not isNaN(1/0))
do
local x = 2.0^floatbits

@ -1,4 +1,5 @@
-- $Id: nextvar.lua,v 1.78 2015/09/08 17:21:27 roberto Exp $
-- $Id: nextvar.lua,v 1.79 2016/11/07 13:11:28 roberto Exp $
-- See Copyright Notice in file all.lua
print('testing tables, next, and for')

@ -1,4 +1,5 @@
-- $Id: pm.lua,v 1.47 2016/04/22 16:37:09 roberto Exp $
-- $Id: pm.lua,v 1.48 2016/11/07 13:11:28 roberto Exp $
-- See Copyright Notice in file all.lua
print('testing pattern matching')

@ -1,4 +1,5 @@
-- $Id: sort.lua,v 1.37 2016/03/07 19:27:51 roberto Exp $
-- $Id: sort.lua,v 1.38 2016/11/07 13:11:28 roberto Exp $
-- See Copyright Notice in file all.lua
print "testing (parts of) table library"

@ -1,4 +1,5 @@
-- $Id: strings.lua,v 1.85 2016/05/20 14:15:57 roberto Exp $
-- $Id: strings.lua,v 1.87 2016/12/21 19:23:02 roberto Exp $
-- See Copyright Notice in file all.lua
print('testing strings and string library')
@ -195,8 +196,14 @@ checkerror("contains zeros", string.format, "%10s", "\0")
assert(string.format("%s %s", nil, true) == "nil true")
assert(string.format("%s %.4s", false, true) == "false true")
assert(string.format("%.3s %.3s", false, true) == "fal tru")
local m = setmetatable({}, {__tostring = function () return "hello" end})
local m = setmetatable({}, {__tostring = function () return "hello" end,
__name = "hi"})
assert(string.format("%s %.10s", m, m) == "hello hello")
getmetatable(m).__tostring = nil -- will use '__name' from now on
assert(string.format("%.4s", m) == "hi: ")
getmetatable(m).__tostring = function () return {} end
checkerror("'__tostring' must return a string", tostring, m)
assert(string.format("%x", 0.0) == "0")

@ -1,4 +1,5 @@
-- $Id: tpack.lua,v 1.12 2016/05/18 18:22:45 roberto Exp $
-- $Id: tpack.lua,v 1.13 2016/11/07 13:11:28 roberto Exp $
-- See Copyright Notice in file all.lua
local pack = string.pack
local packsize = string.packsize

@ -1,4 +1,5 @@
-- $Id: utf8.lua,v 1.11 2014/12/26 17:20:53 roberto Exp $
-- $Id: utf8.lua,v 1.12 2016/11/07 13:11:28 roberto Exp $
-- See Copyright Notice in file all.lua
print "testing UTF-8 library"

@ -1,4 +1,5 @@
-- $Id: vararg.lua,v 1.24 2015/06/01 16:38:36 roberto Exp $
-- $Id: vararg.lua,v 1.25 2016/11/07 13:11:28 roberto Exp $
-- See Copyright Notice in file all.lua
print('testing vararg')

@ -1,4 +1,5 @@
-- $Id: verybig.lua,v 1.24 2014/12/26 17:20:53 roberto Exp $
-- $Id: verybig.lua,v 1.25 2016/11/07 13:11:28 roberto Exp $
-- See Copyright Notice in file all.lua
print "testing RK"

@ -1,5 +1,5 @@
/*
** $Id: ltests.c,v 2.208 2015/09/08 16:55:43 roberto Exp roberto $
** $Id: ltests.c,v 2.211 2016/12/04 20:17:24 roberto Exp $
** Internal Module for Debugging of the Lua Implementation
** See Copyright Notice in lua.h
*/

Loading…
Cancel
Save