Merge branch 'master' into ravi-distro

pull/167/head
Dibyendu Majumdar 6 years ago
commit 4a08e13f9b

@ -13,7 +13,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
option(LLVM_JIT "Controls whether LLVM JIT compilation will be enabled, default is OFF" OFF)
option(OMR_JIT "Controls whether NanoJIT compilation will be enabled, default is OFF" OFF)
option(STATIC_BUILD "Build static version of Ravi, default is OFF" OFF)
option(COMPUTED_GOTO "Controls whether the interpreter switch will use computed gotos on gcc/clang, default is OFF" ON)
option(COMPUTED_GOTO "Controls whether the interpreter switch will use computed gotos on gcc/clang, default is ON" ON)
option(ASM_VM "Controls whether to use the new VM (not ready yet! so don't turn on)" OFF)
option(LTESTS "Controls whether ltests are enabled in Debug mode" ON)
@ -182,7 +182,7 @@ if (LLVM_JIT)
src/ravi_llvmarith2.cpp src/ravi_llvmtforcall.cpp src/ravi_llvmrest.cpp
src/ravi_llvmluaapi.cpp)
elseif (OMR_JIT)
set(OMR_JIT_SRCS src/ravi_omrjit.c)
set(OMR_JIT_SRCS src/ravi_omrjit.c src/ravi_omrjitapi.c)
else()
set(NO_JIT_SRCS src/ravi_nojit.c)
endif()

@ -2020,44 +2020,49 @@ bool dmrC_llvmcompile(int argc, char **argv, LLVMModuleRef module,
add_intrinsics(module);
int rc = 0; /* 0 means OK, non-zero means error */
if (compile(C, module, symlist)) {
/* need ->phi_users */
/* This flag enables call to dmrC_track_pseudo_death() in
linearize.c which sets
phi_users list on PHISOURCE instructions */
C->dbg_dead = 1;
FOR_EACH_PTR(filelist, file)
{
symlist = dmrC_sparse(C, file);
if (C->die_if_error) {
rc = 1;
break;
}
if (!compile(C, module, symlist)) {
rc = 1;
break;
}
}
END_FOR_EACH_PTR(file);
if (inputbuffer && rc == 0) {
char *buffer = strdup(inputbuffer);
if (!buffer)
rc = 1;
else {
symlist = dmrC_sparse_buffer(C, "buffer", buffer, 0);
free(buffer);
if (C->die_if_error) {
if (!setjmp(C->jmpbuf)) {
if (compile(C, module, symlist)) {
/* need ->phi_users */
/* This flag enables call to dmrC_track_pseudo_death() in
linearize.c which sets
phi_users list on PHISOURCE instructions */
C->dbg_dead = 1;
FOR_EACH_PTR(filelist, file)
{
symlist = dmrC_sparse(C, file);
if (C->die_if_error || !symlist) {
rc = 1;
break;
}
if (!compile(C, module, symlist)) {
rc = 1;
break;
}
else if (!compile(C, module, symlist)) {
}
END_FOR_EACH_PTR(file);
if (inputbuffer && rc == 0) {
char *buffer = strdup(inputbuffer);
if (!buffer)
rc = 1;
else {
symlist = dmrC_sparse_buffer(C, "buffer", buffer, 0);
free(buffer);
if (C->die_if_error || !symlist) {
rc = 1;
}
else if (!compile(C, module, symlist)) {
rc = 1;
}
}
}
}
else
rc = 1;
}
else
else {
rc = 1;
}
char *error_message = NULL;
int dump_module = 0;
if (rc == 1) {

@ -25,7 +25,7 @@
/*
Define environment variable
TR_Options=traceIlGen,traceFull,log=trtrace.log
TR_Options=traceIlGen,traceFull,traceAliases,log=trtrace.log
To obtain a nice trace of codegen
*/
@ -780,6 +780,15 @@ static JIT_NodeRef output_op_store(struct dmr_C *C, struct function *fn, struct
}
}
/* Following causes test failures -- To be investgated */
//if (insn->src->type == PSEUDO_SYM) {
// JIT_SymbolRef symref = get_sym_value(C, fn, insn->src, true);
// if (symref && JIT_IsTemporary(fn->injector, symref)) {
// JIT_StoreToTemporary(fn->injector, symref, target_in);
// return target_in;
// }
//}
ptr = pseudo_to_value(C, fn, insn->type, insn->src);
if (!ptr)
return NULL;
@ -1471,11 +1480,20 @@ static JIT_NodeRef output_op_symaddr(struct dmr_C *C, struct function *fn, struc
{
JIT_NodeRef res, src;
struct OMRType *dtype;
JIT_SymbolRef sym;
src = pseudo_to_value(C, fn, insn->type, insn->symbol);
if (!src)
return NULL;
/* We need to tell the backend if a local var has had its
address taken */
if (insn->symbol->type == PSEUDO_SYM) {
sym = get_sym_value(C, fn, insn->symbol, true);
if (sym)
JIT_SetAutoAddressTaken(fn->injector, sym);
}
dtype = get_symnode_or_basetype(C, fn, insn->type);
if (!dtype)
return NULL;
@ -2192,45 +2210,48 @@ bool dmrC_omrcompile(int argc, char **argv, JIT_ContextRef module, const char *i
C->codegen = 1; /* Disables macros related to vararg processing */
C->Wdecl = 0;
symlist = dmrC_sparse_initialize(C, argc, argv, &filelist);
int rc = 0;
if (compile(C, module, symlist)) {
/* We need ->phi_users */
/* This flag enables call to dmrC_track_pseudo_death() in
linearize.c which sets
phi_users list on PHISOURCE instructions */
C->dbg_dead = 1;
FOR_EACH_PTR(filelist, file)
{
symlist = dmrC_sparse(C, file);
if (C->die_if_error) {
rc = 1;
break;
}
if (!compile(C, module, symlist)) {
rc = 1;
break;
}
}
END_FOR_EACH_PTR(file);
if (inputbuffer && rc == 0) {
char *buffer = strdup(inputbuffer);
if (!buffer)
rc = 1;
else {
symlist = dmrC_sparse_buffer(C, "buffer", buffer, 0);
free(buffer);
if (C->die_if_error) {
if (!setjmp(C->jmpbuf)) {
symlist = dmrC_sparse_initialize(C, argc, argv, &filelist);
if (compile(C, module, symlist)) {
/* We need ->phi_users */
/* This flag enables call to dmrC_track_pseudo_death() in
linearize.c which sets
phi_users list on PHISOURCE instructions */
C->dbg_dead = 1;
FOR_EACH_PTR(filelist, file)
{
symlist = dmrC_sparse(C, file);
if (C->die_if_error || !symlist) {
rc = 1;
break;
}
if (!compile(C, module, symlist)) {
rc = 1;
} else if (!compile(C, module, symlist)) {
break;
}
}
END_FOR_EACH_PTR(file);
if (inputbuffer && rc == 0) {
char *buffer = strdup(inputbuffer);
if (!buffer)
rc = 1;
else {
symlist = dmrC_sparse_buffer(C, "buffer", buffer, 0);
free(buffer);
if (C->die_if_error || !symlist) {
rc = 1;
} else if (!compile(C, module, symlist)) {
rc = 1;
}
}
}
}
} else
} else
rc = 1;
}
else {
rc = 1;
}
if (rc == 1) {
fprintf(stderr, "Failed to compile given inputs\n");
}

@ -35,6 +35,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <setjmp.h>
#include <sys/types.h>
@ -217,7 +218,7 @@ void dmrC_error_die(struct dmr_C *C, struct position pos, const char *fmt, ...)
va_start(args, fmt);
do_warn(C, "error: ", pos, fmt, args);
va_end(args);
exit(1);
longjmp(C->jmpbuf, 1);
}
void dmrC_die(struct dmr_C *C, const char *fmt, ...)
@ -231,7 +232,7 @@ void dmrC_die(struct dmr_C *C, const char *fmt, ...)
va_end(args);
fprintf(stderr, "%s\n", buffer);
exit(1);
longjmp(C->jmpbuf, 1);
}
#define ARCH_LP32 0
@ -1293,6 +1294,8 @@ static struct symbol_list *sparse_tokenstream(struct dmr_C *C, struct token *tok
// Preprocess the stream
token = dmrC_preprocess(C, token);
if (C->die_if_error)
return NULL;
if (C->dump_macro_defs && !builtin)
dmrC_dump_macro_definitions(C);
@ -1452,7 +1455,8 @@ struct symbol_list * dmrC_sparse(struct dmr_C *C, char *filename)
C->has_error = ERROR_PREV_PHASE;
/* Evaluate the complete symbol list */
dmrC_evaluate_symbol_list(C, res);
if (res)
dmrC_evaluate_symbol_list(C, res);
return res;
}
@ -1478,7 +1482,8 @@ struct symbol_list *dmrC_sparse_buffer(struct dmr_C *C, const char *name, char *
}
/* Evaluate the complete symbol list */
dmrC_evaluate_symbol_list(C, res);
if (res)
dmrC_evaluate_symbol_list(C, res);
/* And return it */
return res;

@ -6,6 +6,7 @@
#include <stddef.h>
#include <stdlib.h>
#include <time.h>
#include <setjmp.h>
/*
* Basic helper routine descriptions for 'sparse'.
@ -152,6 +153,8 @@ struct dmr_C {
int codegen;
int has_error;
jmp_buf jmpbuf;
const char *gcc_base_dir;
const char *multiarch_dir;

@ -1,5 +1,5 @@
/*
** $Id: lapi.h,v 2.9 2015/03/06 19:49:50 roberto Exp $
** $Id: lapi.h,v 2.9.1.1 2017/04/19 17:20:42 roberto Exp $
** Auxiliary functions from Lua API
** See Copyright Notice in lua.h
*/

@ -1,5 +1,5 @@
/*
** $Id: lauxlib.h,v 1.131 2016/12/06 14:54:31 roberto Exp $
** $Id: lauxlib.h,v 1.131.1.1 2017/04/19 17:20:42 roberto Exp $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
@ -271,44 +271,10 @@ LUALIB_API void (luaL_openlib) (lua_State *L, const char *libname,
#endif
/* }============================================================ */
/*
The normal Lua metatable functions in C use string
keys - these are expensive as the key needs to be
converted to Lua string, hash code computed etc.
Following implementations are taken from a post in
Lua mailing list (http://lua-users.org/lists/lua-l/2010-11/msg00151.html)
meta_key is the key assigned to the meta table of the userdata
IMPORTANT: Caller must ensure that supplied meta_key points to somewhere in
static storage as otherwise memory fault will occur.
*/
LUALIB_API int (luaL_newmetatable)(lua_State *L, const char *tname);
LUALIB_API void (luaL_setmetatable)(lua_State *L, const char *tname);
LUALIB_API void *(luaL_testudata)(lua_State *L, int ud, const char *tname);
LUALIB_API void *(luaL_checkudata)(lua_State *L, int ud, const char *tname);
#if 0
LUALIB_API int raviL_newmetatable(lua_State *L, const void *meta_key,
const char *tname);
/* meta_key is the key assigned to the meta table of the userdata */
LUALIB_API void raviL_getmetatable(lua_State *L, const void *meta_key);
/*
arg_index is the position of userdata argument on the stack
meta_key is the key assigned to the meta table of the userdata
*/
LUALIB_API void *raviL_testudata(lua_State *L, int arg_index, const void *meta_key);
/*
arg_index is the position of userdata argument on the stack
meta_key is the key assigned to the meta table of the userdata
*/
LUALIB_API void *raviL_checkudata(lua_State *L, int arg_index, const void *meta_key);
#else
#define raviL_newmetatable(L, meta_key, tname) luaL_newmetatable(L, meta_key)
#define raviL_getmetatable(L, meta_key) luaL_getmetatable(L, meta_key)
#define raviL_testudata(L, arg_index, meta_key) luaL_testudata(L, arg_index, meta_key)
#define raviL_checkudata(L, arg_index, meta_key) luaL_checkudata(L, arg_index, meta_key)
#endif
LUALIB_API int (raviL_build_ast_from_buffer) (lua_State *L, const char *buff, size_t size,
const char *name, const char *mode);

@ -1,5 +1,5 @@
/*
** $Id: lcode.h,v 1.64 2016/01/05 16:22:37 roberto Exp $
** $Id: lcode.h,v 1.64.1.1 2017/04/19 17:20:42 roberto Exp $
** Code generator for Lua
** See Copyright Notice in lua.h
*/

@ -1,5 +1,5 @@
/*
** $Id: lctype.h,v 1.12 2011/07/15 12:50:29 roberto Exp $
** $Id: lctype.h,v 1.12.1.1 2013/04/12 18:48:47 roberto Exp $
** 'ctype' functions for Lua
** See Copyright Notice in lua.h
*/

@ -1,5 +1,5 @@
/*
** $Id: ldebug.h,v 2.14 2015/05/22 17:45:56 roberto Exp $
** $Id: ldebug.h,v 2.14.1.1 2017/04/19 17:20:42 roberto Exp $
** Auxiliary functions from Debug Interface module
** See Copyright Notice in lua.h
*/

@ -1,5 +1,5 @@
/*
** $Id: ldo.h,v 2.29 2015/12/21 13:02:14 roberto Exp $
** $Id: ldo.h,v 2.29.1.1 2017/04/19 17:20:42 roberto Exp $
** Stack and Call structure of Lua
** See Copyright Notice in lua.h
*/

@ -1,5 +1,5 @@
/*
** $Id: lfunc.h,v 2.15 2015/01/13 15:49:11 roberto Exp $
** $Id: lfunc.h,v 2.15.1.1 2017/04/19 17:39:34 roberto Exp $
** Auxiliary functions to manipulate prototypes and closures
** See Copyright Notice in lua.h
*/

@ -1,5 +1,5 @@
/*
** $Id: lgc.h,v 2.91 2015/12/21 13:02:14 roberto Exp $
** $Id: lgc.h,v 2.91.1.1 2017/04/19 17:39:34 roberto Exp $
** Garbage Collector
** See Copyright Notice in lua.h
*/

@ -1,5 +1,5 @@
/*
** $Id: llex.h,v 1.79 2016/05/02 14:02:12 roberto Exp $
** $Id: llex.h,v 1.79.1.1 2017/04/19 17:20:42 roberto Exp $
** Lexical Analyzer
** See Copyright Notice in lua.h
*/

@ -1,5 +1,5 @@
/*
** $Id: llimits.h,v 1.141 2015/11/19 19:16:22 roberto Exp $
** $Id: llimits.h,v 1.141.1.1 2017/04/19 17:20:42 roberto Exp $
** Limits, basic types, and some other 'installation-dependent' definitions
** See Copyright Notice in lua.h
*/

@ -1,5 +1,5 @@
/*
** $Id: lmem.h,v 1.43 2014/12/19 17:26:14 roberto Exp $
** $Id: lmem.h,v 1.43.1.1 2017/04/19 17:20:42 roberto Exp $
** Interface to Memory Manager
** See Copyright Notice in lua.h
*/

@ -1,5 +1,5 @@
/*
** $Id: lobject.h,v 2.117 2016/08/01 19:51:24 roberto Exp $
** $Id: lobject.h,v 2.117.1.1 2017/04/19 17:39:34 roberto Exp $
** Type definitions for Lua objects
** See Copyright Notice in lua.h
*/
@ -75,7 +75,14 @@
*/
typedef struct GCObject GCObject;
/* Extended to 16-bits so that we can hold more info */
/*
** Value type extended to 16-bits so that we can hold more info.
** The actual type code is still 1 byte (least significant byte)
** and in particular all GC-able type codes must fit into 1 byte because
** the GC CommonHeader only allows 1 byte for the type code.
** The extra byte is for use by the type FCF (fast C function) to
** encode the C function's parameter and return types.
*/
typedef uint16_t LuaType;
/*

@ -1,5 +1,5 @@
/*
** $Id: lopcodes.h,v 1.149 2016/07/19 17:12:21 roberto Exp $
** $Id: lopcodes.h,v 1.149.1.1 2017/04/19 17:20:42 roberto Exp $
** Opcodes for Lua virtual machine
** See Copyright Notice in lua.h
*/
@ -190,8 +190,8 @@ OP_CLOSURE,/* A Bx R(A) := closure(KPROTO[Bx]) */
OP_VARARG,/* A B R(A), R(A+1), ..., R(A+B-2) = vararg */
OP_EXTRAARG,/* Ax extra (larger) argument for previous opcode */
OP_RAVI_NEWARRAYI, /* A R(A) := array of int */
OP_RAVI_NEWARRAYF, /* A R(A) := array of float */
OP_RAVI_NEW_IARRAY, /* A R(A) := array of int */
OP_RAVI_NEW_FARRAY, /* A R(A) := array of float */
OP_RAVI_LOADIZ, /* A R(A) := tointeger(0) */
OP_RAVI_LOADFZ, /* A R(A) := tonumber(0) */
@ -219,36 +219,36 @@ OP_RAVI_DIVII, /* A B C R(A) := RK(B) / RK(C) */
OP_RAVI_TOINT, /* A R(A) := toint(R(A)) */
OP_RAVI_TOFLT, /* A R(A) := tofloat(R(A)) */
OP_RAVI_TOARRAYI, /* A R(A) := to_arrayi(R(A)) */
OP_RAVI_TOARRAYF, /* A R(A) := to_arrayf(R(A)) */
OP_RAVI_TOIARRAY, /* A R(A) := to_arrayi(R(A)) */
OP_RAVI_TOFARRAY, /* A R(A) := to_arrayf(R(A)) */
OP_RAVI_TOTAB, /* A R(A) := to_table(R(A)) */
OP_RAVI_TOSTRING,
OP_RAVI_TOCLOSURE,
OP_RAVI_TOTYPE,
OP_RAVI_TOSTRING, /* A R(A) := assert_string(R(A)) */
OP_RAVI_TOCLOSURE, /* A R(A) := assert_closure(R(A)) */
OP_RAVI_TOTYPE, /* A R(A) := assert_usertype(R(A)), where usertype has metatable in Lua registry */
OP_RAVI_MOVEI, /* A B R(A) := R(B), check R(B) is int */
OP_RAVI_MOVEF, /* A B R(A) := R(B), check R(B) is float */
OP_RAVI_MOVEAI, /* A B R(A) := R(B), check R(B) is array of int */
OP_RAVI_MOVEAF, /* A B R(A) := R(B), check R(B) is array of floats */
OP_RAVI_MOVETAB, /* A B R(A) := R(B), check R(B) is a table */
OP_RAVI_MOVEI, /* A B R(A) := R(B), check R(B) is int */
OP_RAVI_MOVEF, /* A B R(A) := R(B), check R(B) is float */
OP_RAVI_MOVEIARRAY, /* A B R(A) := R(B), check R(B) is array of int */
OP_RAVI_MOVEFARRAY, /* A B R(A) := R(B), check R(B) is array of floats */
OP_RAVI_MOVETAB, /* A B R(A) := R(B), check R(B) is a table */
OP_RAVI_GETTABLE_AI,/* A B C R(A) := R(B)[RK(C)] where R(B) is array of integers and RK(C) is int */
OP_RAVI_GETTABLE_AF,/* A B C R(A) := R(B)[RK(C)] where R(B) is array of floats and RK(C) is int */
OP_RAVI_IARRAY_GET, /* A B C R(A) := R(B)[RK(C)] where R(B) is array of integers and RK(C) is int */
OP_RAVI_FARRAY_GET, /* A B C R(A) := R(B)[RK(C)] where R(B) is array of floats and RK(C) is int */
OP_RAVI_SETTABLE_AI,/* A B C R(A)[RK(B)] := RK(C) where RK(B) is an int, R(A) is array of ints */
OP_RAVI_SETTABLE_AF,/* A B C R(A)[RK(B)] := RK(C) where RK(B) is an int, R(A) is array of floats */
OP_RAVI_SETTABLE_AII,/* A B C R(A)[RK(B)] := RK(C) where RK(B) is an int, R(A) is array of ints, and RK(C) is an int */
OP_RAVI_SETTABLE_AFF,/* A B C R(A)[RK(B)] := RK(C) where RK(B) is an int, R(A) is array of floats, and RK(C) is an float */
OP_RAVI_IARRAY_SET, /* A B C R(A)[RK(B)] := RK(C) where RK(B) is an int, R(A) is array of ints */
OP_RAVI_FARRAY_SET, /* A B C R(A)[RK(B)] := RK(C) where RK(B) is an int, R(A) is array of floats */
OP_RAVI_IARRAY_SETI, /* A B C R(A)[RK(B)] := RK(C) where RK(B) is an int, R(A) is array of ints, and RK(C) is an int */
OP_RAVI_FARRAY_SETF, /* A B C R(A)[RK(B)] := RK(C) where RK(B) is an int, R(A) is array of floats, and RK(C) is an float */
OP_RAVI_FORLOOP_IP,
OP_RAVI_FORLOOP_I1,
OP_RAVI_FORPREP_IP,
OP_RAVI_FORPREP_I1,
OP_RAVI_FORLOOP_IP, /* As FORLOOP, but with integer index and positive integer step */
OP_RAVI_FORLOOP_I1, /* As FORLOOP, but with integer index 1 and step 1 */
OP_RAVI_FORPREP_IP, /* As FORPREP, but with integer index and positive integer step */
OP_RAVI_FORPREP_I1, /* As FORPREP, but with integer index 1 and step 1 */
OP_RAVI_SETUPVALI, /* A B UpValue[B] := tointeger(R(A)) */
OP_RAVI_SETUPVALF, /* A B UpValue[B] := tonumber(R(A)) */
OP_RAVI_SETUPVALAI, /* A B UpValue[B] := toarrayint(R(A)) */
OP_RAVI_SETUPVALAF, /* A B UpValue[B] := toarrayflt(R(A)) */
OP_RAVI_SETUPVAL_IARRAY, /* A B UpValue[B] := toarrayint(R(A)) */
OP_RAVI_SETUPVAL_FARRAY, /* A B UpValue[B] := toarrayflt(R(A)) */
OP_RAVI_SETUPVALT,/* A B UpValue[B] := to_table(R(A)) */
OP_RAVI_BAND_II,/* A B C R(A) := RK(B) & RK(C) */
@ -267,19 +267,19 @@ OP_RAVI_LE_FF,/* A B C if ((RK(B) <= RK(C)) ~= A) then pc++ */
/* Following op codes are specialised when it is known that indexing is being
done on a table and the key is known type */
OP_RAVI_GETTABLE_S,/* A B C R(A) := R(B)[RK(C)], string key, known table */
OP_RAVI_SETTABLE_S,/* A B C R(A)[RK(B)] := RK(C), string key, known table */
OP_RAVI_SELF_S,/* A B C R(A+1) := R(B); R(A) := R(B)[RK(C)], string key, known table */
OP_RAVI_TABLE_GETFIELD,/* A B C R(A) := R(B)[RK(C)], string key, R(B) references a table */
OP_RAVI_TABLE_SETFIELD,/* A B C R(A)[RK(B)] := RK(C), string key, R(A) references a table */
OP_RAVI_TABLE_SELF_SK, /* A B C R(A+1) := R(B); R(A) := R(B)[RK(C)], string key, R(B) references a table */
/* Following opcodes are specialized for indexing where the
key is known to be string but the variable may or may not be
key is known to be string or integer but the variable may or may not be
a table */
OP_RAVI_GETTABLE_I,/* A B C R(A) := R(B)[RK(C)], integer key, known table */
OP_RAVI_SETTABLE_I,/* A B C R(A)[RK(B)] := RK(C), integer key, known table */
OP_RAVI_GETTABLE_SK, /* A B C R(A) := R(B)[RK(C)], string key */
OP_RAVI_SELF_SK, /* A B C R(A+1) := R(B); R(A) := R(B)[RK(C)], string key */
OP_RAVI_SETTABLE_SK, /* A B C R(A)[RK(B)] := RK(C), string key */
OP_RAVI_GETTABUP_SK, /* A B C R(A) := UpValue[B][RK(C)], string key */
OP_RAVI_GETI, /* A B C R(A) := R(B)[RK(C)], integer key */
OP_RAVI_SETI, /* A B C R(A)[RK(B)] := RK(C), integer key */
OP_RAVI_GETFIELD, /* A B C R(A) := R(B)[RK(C)], string key */
OP_RAVI_SELF_SK, /* A B C R(A+1) := R(B); R(A) := R(B)[RK(C)], string key */
OP_RAVI_SETFIELD, /* A B C R(A)[RK(B)] := RK(C), string key */
OP_RAVI_GETTABUP_SK, /* A B C R(A) := UpValue[B][RK(C)], string key */
} OpCode;

@ -1,5 +1,5 @@
/*
** $Id: lparser.h,v 1.76 2015/12/30 18:16:13 roberto Exp $
** $Id: lparser.h,v 1.76.1.1 2017/04/19 17:20:42 roberto Exp $
** Lua Parser
** See Copyright Notice in lua.h
*/

@ -1,5 +1,5 @@
/*
** $Id: lprefix.h,v 1.2 2014/12/29 16:54:13 roberto Exp $
** $Id: lprefix.h,v 1.2.1.1 2017/04/19 17:20:42 roberto Exp $
** Definitions for Lua code that must come before any other header file
** See Copyright Notice in lua.h
*/

@ -1,5 +1,5 @@
/*
** $Id: lstate.h,v 2.133 2016/12/22 13:08:50 roberto Exp $
** $Id: lstate.h,v 2.133.1.1 2017/04/19 17:39:34 roberto Exp $
** Global State
** See Copyright Notice in lua.h
*/

@ -1,5 +1,5 @@
/*
** $Id: lstring.h,v 1.61 2015/11/03 15:36:01 roberto Exp $
** $Id: lstring.h,v 1.61.1.1 2017/04/19 17:20:42 roberto Exp $
** String table (keep all strings handled by Lua)
** See Copyright Notice in lua.h
*/

@ -1,5 +1,5 @@
/*
** $Id: ltable.h,v 2.23 2016/12/22 13:08:50 roberto Exp $
** $Id: ltable.h,v 2.23.1.2 2018/05/24 19:39:05 roberto Exp $
** Lua tables (hash)
** See Copyright Notice in lua.h
*/

@ -1,5 +1,5 @@
/*
** $Id: ltm.h,v 2.22 2016/02/26 19:20:15 roberto Exp $
** $Id: ltm.h,v 2.22.1.1 2017/04/19 17:20:42 roberto Exp $
** Tag methods
** See Copyright Notice in lua.h
*/

@ -1,5 +1,5 @@
/*
** $Id: lua.h,v 1.332 2016/12/22 15:51:20 roberto Exp $
** $Id: lua.h,v 1.332.1.2 2018/06/13 16:58:17 roberto Exp $
** Lua - A Scripting Language
** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
** See Copyright Notice at the end of this file
@ -19,11 +19,11 @@
#define LUA_VERSION_MAJOR "5"
#define LUA_VERSION_MINOR "3"
#define LUA_VERSION_NUM 503
#define LUA_VERSION_RELEASE "4"
#define LUA_VERSION_RELEASE "5"
#define LUA_VERSION "Ravi " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR
#define LUA_RELEASE LUA_VERSION "." LUA_VERSION_RELEASE
#define LUA_COPYRIGHT LUA_RELEASE "\nCopyright (C) 1994-2017 Lua.org, PUC-Rio\nPortions Copyright (C) 2015-2017 Dibyendu Majumdar"
#define LUA_COPYRIGHT LUA_RELEASE "\nCopyright (C) 1994-2018 Lua.org, PUC-Rio\nPortions Copyright (C) 2015-2018 Dibyendu Majumdar"
#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo, W. Celes, Dibyendu Majumdar"

@ -1,5 +1,5 @@
/*
** $Id: luaconf.h,v 1.259 2016/12/22 13:08:50 roberto Exp $
** $Id: luaconf.h,v 1.259.1.1 2017/04/19 17:29:57 roberto Exp $
** Configuration file for Lua
** See Copyright Notice in lua.h
*/
@ -621,6 +621,13 @@
#endif
/*
@@ lua_pointer2str converts a pointer to a readable string in a
** non-specified way.
*/
#define lua_pointer2str(buff,sz,p) l_sprintf(buff,sz,"%p",p)
/*
@@ lua_number2strx converts a float to an hexadecimal numeric string.
** In C99, 'sprintf' (with format specifiers '%a'/'%A') does that.

@ -1,5 +1,5 @@
/*
** $Id: lualib.h,v 1.45 2017/01/12 17:14:26 roberto Exp $
** $Id: lualib.h,v 1.45.1.1 2017/04/19 17:20:42 roberto Exp $
** Lua standard libraries
** See Copyright Notice in lua.h
*/

@ -1,5 +1,5 @@
/*
** $Id: lundump.h,v 1.45 2015/09/08 15:41:05 roberto Exp $
** $Id: lundump.h,v 1.45.1.1 2017/04/19 17:20:42 roberto Exp $
** load precompiled Lua chunks
** See Copyright Notice in lua.h
*/

@ -1,5 +1,5 @@
/*
** $Id: lvm.h,v 2.41 2016/12/22 13:08:50 roberto Exp $
** $Id: lvm.h,v 2.41.1.1 2017/04/19 17:20:42 roberto Exp $
** Lua virtual machine
** See Copyright Notice in lua.h
*/
@ -37,12 +37,28 @@
#endif
/* convert an object to a float (including string coercion) */
#define tonumber(o,n) \
(RAVI_LIKELY(ttisfloat(o)) ? (*(n) = fltvalue(o), 1) : luaV_tonumber_(o,n))
/* convert an object to a float (without string coercion) */
#define tonumberns(o,n) \
(ttisfloat(o) ? ((n) = fltvalue(o), 1) : \
(ttisinteger(o) ? ((n) = cast_num(ivalue(o)), 1) : 0))
/* convert an object to an integer (including string coercion) */
#define tointeger(o,i) \
(RAVI_LIKELY(ttisinteger(o)) ? (*(i) = ivalue(o), 1) : luaV_tointeger(o,i,LUA_FLOORN2I))
/* convert an object to an integer (without string coercion) */
#define tointegerns(o,i) \
(ttisinteger(o) ? (*(i) = ivalue(o), 1) \
: luaV_flttointeger(o,i,LUA_FLOORN2I))
#define intop(op,v1,v2) l_castU2S(l_castS2U(v1) op l_castS2U(v2))
#define luaV_rawequalobj(t1,t2) luaV_equalobj(NULL,t1,t2)
@ -91,6 +107,7 @@ 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_flttointeger (const TValue *obj, lua_Integer *p, int mode);
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);

@ -1,5 +1,5 @@
/*
** $Id: lzio.h,v 1.31 2015/09/08 15:41:05 roberto Exp $
** $Id: lzio.h,v 1.31.1.1 2017/04/19 17:20:42 roberto Exp $
** Buffered streams
** See Copyright Notice in lua.h
*/

@ -1242,19 +1242,19 @@ class RaviCodeGenerator {
void emit_SETTABLE(RaviFunctionDef *def, int A, int B, int C, int pc);
void emit_SETTABLE_I(RaviFunctionDef *def, int A, int B, int C, int pc);
void emit_SETI(RaviFunctionDef *def, int A, int B, int C, int pc);
void emit_SETTABLE_SK(RaviFunctionDef *def, int A, int B, int C, int pc);
void emit_SETFIELD(RaviFunctionDef *def, int A, int B, int C, int pc);
void emit_GETTABLE(RaviFunctionDef *def, int A, int B, int C, int pc);
void emit_GETTABLE_S(RaviFunctionDef *def, int A, int B, int C, int pc,
TString *key);
void emit_GETTABLE_SK(RaviFunctionDef *def, int A, int B, int C, int pc,
void emit_GETFIELD(RaviFunctionDef *def, int A, int B, int C, int pc,
TString *key);
void emit_GETTABLE_I(RaviFunctionDef *def, int A, int B, int C, int pc);
void emit_GETI(RaviFunctionDef *def, int A, int B, int C, int pc);
void emit_finish_GETTABLE(RaviFunctionDef *def, llvm::Value *phi,
llvm::Value *t, llvm::Value *ra, llvm::Value *rb,
@ -1262,7 +1262,7 @@ class RaviCodeGenerator {
void emit_SELF(RaviFunctionDef *def, int A, int B, int C, int pc);
void emit_SELF_S(RaviFunctionDef *def, int A, int B, int C, int pc,
void emit_TABLE_SELF_SK(RaviFunctionDef *def, int A, int B, int C, int pc,
TString *key);
void emit_SELF_SK(RaviFunctionDef *def, int A, int B, int C, int pc);
@ -1328,21 +1328,21 @@ class RaviCodeGenerator {
void emit_TFORLOOP(RaviFunctionDef *def, int A, int j, int pc);
void emit_GETTABLE_AF(RaviFunctionDef *def, int A, int B, int C,
void emit_FARRAY_GET(RaviFunctionDef *def, int A, int B, int C,
bool omitArrayGetRangeCheck, int pc);
void emit_GETTABLE_AI(RaviFunctionDef *def, int A, int B, int C,
void emit_IARRAY_GET(RaviFunctionDef *def, int A, int B, int C,
bool omitArrayGetRangeCheck, int pc);
void emit_SETTABLE_AF(RaviFunctionDef *def, int A, int B, int C,
void emit_FARRAY_SET(RaviFunctionDef *def, int A, int B, int C,
bool known_int, int pc);
void emit_SETTABLE_AI(RaviFunctionDef *def, int A, int B, int C,
void emit_IARRAY_SET(RaviFunctionDef *def, int A, int B, int C,
bool known_float, int pc);
void emit_MOVEAI(RaviFunctionDef *def, int A, int B, int pc);
void emit_MOVEIARRAY(RaviFunctionDef *def, int A, int B, int pc);
void emit_MOVEAF(RaviFunctionDef *def, int A, int B, int pc);
void emit_MOVEFARRAY(RaviFunctionDef *def, int A, int B, int pc);
void emit_MOVETAB(RaviFunctionDef *def, int A, int B, int pc);

@ -2,14 +2,14 @@ Lua 5.3.x Tests
===============
This folder contains a copy of the Lua 5.3 tests, amended slightly for Ravi. The changes are to skip some
tests that fail in Ravi due to lack of support for certain features of Lua - e.g. tail calls, or different
limits.
tests that fail in Ravi due to lack of support for certain features of Lua - e.g. recursion limit for tail calls,
or other limits such as number of variables.
Notes
-----
* The 'ltests' library is included in Ravi in Debug builds.
* The tests crash on Windows 64-bit environment when JIT mode is enabled; this appears to be due to lack of
support for Windows (64-bit) stack unwinding in LLVM. See issue #30. The 32-bit build does not have this
* The Lua 'ltests' library is included in Ravi in Debug builds.
* The tests may crash on Windows 64-bit environment when JIT mode is enabled; this appears to be due to lack of
support for Windows (64-bit) stack unwinding in the JIT backends. See issue #30. The 32-bit build does not have this
issue.
* In JIT mode the tests take much longer to run, especially if full JIT is switched on. This is because the tests
generate a lot of small Lua functions dynamically - in thousands - and all the time is spent in JIT compiling

@ -121,8 +121,8 @@ check(function ()
end,
'LOADNIL',
'MUL',
'DIV', 'ADD', 'GETTABLE', 'SUB', 'GETTABLE_SK', 'POW',
'UNM', 'SETTABLE', 'SETTABLE_I', 'RETURN')
'DIV', 'ADD', 'GETTABLE', 'SUB', 'GETFIELD', 'POW',
'UNM', 'SETTABLE', 'SETI', 'RETURN')
-- direct access to constants
@ -132,7 +132,7 @@ check(function ()
a.x = b
a[b] = 'x'
end,
'LOADNIL', 'SETTABLE_SK', 'SETTABLE_SK', 'SETTABLE', 'RETURN')
'LOADNIL', 'SETFIELD', 'SETFIELD', 'SETTABLE', 'RETURN')
check(function ()
local a,b

@ -97,9 +97,9 @@ checkmessage("local a,b,cc; (function () a.x = 1 end)()", "upvalue 'a'")
checkmessage("local _ENV = {x={}}; a = a + 1", "global 'a'")
checkmessage("b=1; local aaa='a'; x=aaa+b", "local 'aaa'")
-- checkmessage("b=1; local aaa='a'; x=aaa+b", "local 'aaa'")
checkmessage("aaa={}; x=3/aaa", "global 'aaa'")
checkmessage("aaa='2'; b=nil;x=aaa*b", "global 'b'")
-- checkmessage("aaa='2'; b=nil;x=aaa*b", "global 'b'")
checkmessage("aaa={}; x=-aaa", "global 'aaa'")
-- short circuit
@ -119,9 +119,9 @@ checkmessage("print(10 < '23')", "number with string")
-- float->integer conversions
checkmessage("local a = 2.0^100; x = a << 2", "local a")
checkmessage("local a = 1 >> 2.0^100", "has no integer representation")
checkmessage("local a = '10' << 2.0^100", "has no integer representation")
-- checkmessage("local a = '10' << 2.0^100", "has no integer representation")
checkmessage("local a = 2.0^100 & 1", "has no integer representation")
checkmessage("local a = 2.0^100 & '1'", "has no integer representation")
-- checkmessage("local a = 2.0^100 & '1'", "has no integer representation")
checkmessage("local a = 2.0 | 1e40", "has no integer representation")
checkmessage("local a = 2e100 ~ 1", "has no integer representation")
checkmessage("string.sub('a', 2.0^100)", "has no integer representation")

@ -279,7 +279,7 @@ checkcompt(msgf2i, "return 2.3 >> 0")
checkcompt(msgf2i, ("return 2.0^%d & 1"):format(intbits - 1))
checkcompt("field 'huge'", "return math.huge << 1")
checkcompt(msgf2i, ("return 1 | 2.0^%d"):format(intbits - 1))
checkcompt(msgf2i, "return 2.3 ~ '0.0'")
-- checkcompt(msgf2i, "return 2.3 ~ '0.0'")
-- testing overflow errors when converting from float to integer (runtime)

@ -3,7 +3,8 @@ This folder contains various performance and unit tests.
Language tests
--------------
* basics.lua - some simple tests
* ravi_tests1.ravi - contains some basic tests
* ravi_tests1.ravi - contains most of the Ravi specific tests
* ravi_tests3.ravi - additional tests
* ravi_errors.ravi - contains tests for error conditions
* bitwise_tests.lua - modified Lua 5.3 tests to exercise JIT on bitwise operations
@ -20,6 +21,7 @@ Matrix multiplication test:
* matmul1.lua - matrix multiplication (Lua compatible)
* matmul1.ravi - matrix multiplication (ravi version with static typing)
* matmul1_ravi.lua - 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/>`_.

@ -53,8 +53,8 @@ opcodes_coverage.SETLIST = 0
opcodes_coverage.CLOSURE = 0
opcodes_coverage.VARARG = 0
opcodes_coverage.EXTRAARG = 0
opcodes_coverage.NEWARRAYI = 0
opcodes_coverage.NEWARRAYF = 0
opcodes_coverage.NEW_IARRAY = 0
opcodes_coverage.NEW_FARRAY = 0
opcodes_coverage.LOADIZ = 0
opcodes_coverage.LOADFZ = 0
opcodes_coverage.UNMF = 0
@ -75,26 +75,26 @@ opcodes_coverage.DIVIF = 0
opcodes_coverage.DIVII = 0
opcodes_coverage.TOINT = 0
opcodes_coverage.TOFLT = 0
opcodes_coverage.TOARRAYI = 0
opcodes_coverage.TOARRAYF = 0
opcodes_coverage.TOIARRAY = 0
opcodes_coverage.TOFARRAY = 0
opcodes_coverage.MOVEI = 0
opcodes_coverage.MOVEF = 0
opcodes_coverage.MOVEAI = 0
opcodes_coverage.MOVEAF = 0
opcodes_coverage.GETTABLE_AI = 0
opcodes_coverage.GETTABLE_AF = 0
opcodes_coverage.SETTABLE_AI = 0
opcodes_coverage.SETTABLE_AF = 0
opcodes_coverage.MOVEIARRAY = 0
opcodes_coverage.MOVEFARRAY = 0
opcodes_coverage.IARRAY_GET = 0
opcodes_coverage.FARRAY_GET = 0
opcodes_coverage.IARRAY_SET = 0
opcodes_coverage.FARRAY_SET = 0
opcodes_coverage.FORLOOP_IP = 0
opcodes_coverage.FORLOOP_I1 = 0
opcodes_coverage.FORPREP_IP = 0
opcodes_coverage.FORPREP_I1 = 0
opcodes_coverage.SETUPVALI = 0
opcodes_coverage.SETUPVALF = 0
opcodes_coverage.SETUPVALAI = 0
opcodes_coverage.SETUPVALAF = 0
opcodes_coverage.SETTABLE_AII = 0
opcodes_coverage.SETTABLE_AFF = 0
opcodes_coverage.SETUPVAL_IARRAY = 0
opcodes_coverage.SETUPVAL_FARRAY = 0
opcodes_coverage.IARRAY_SETI = 0
opcodes_coverage.FARRAY_SETF = 0
opcodes_coverage.BAND_II = 0
opcodes_coverage.BOR_II = 0
opcodes_coverage.BXOR_II = 0
@ -107,16 +107,16 @@ opcodes_coverage.LT_II = 0
opcodes_coverage.LT_FF = 0
opcodes_coverage.LE_II = 0
opcodes_coverage.LE_FF = 0
opcodes_coverage.GETTABLE_I = 0
opcodes_coverage.GETTABLE_S = 0
opcodes_coverage.SETTABLE_I = 0
opcodes_coverage.SETTABLE_S = 0
opcodes_coverage.SETTABLE_SK = 0
opcodes_coverage.GETTABLE_SK = 0
opcodes_coverage.GETI = 0
opcodes_coverage.TABLE_GETFIELD = 0
opcodes_coverage.SETI = 0
opcodes_coverage.TABLE_SETFIELD = 0
opcodes_coverage.SETFIELD = 0
opcodes_coverage.GETFIELD = 0
opcodes_coverage.TOTAB = 0
opcodes_coverage.MOVETAB = 0
opcodes_coverage.SETUPVALT = 0
opcodes_coverage.SELF_S = 0
opcodes_coverage.TABLE_SELF_SK = 0
opcodes_coverage.TOTYPE = 0
opcodes_coverage.TOSTRING = 0
opcodes_coverage.TOCLOSURE = 0
@ -215,8 +215,8 @@ check(function ()
end,
'LOADNIL',
'MUL',
'DIV', 'ADD', 'GETTABLE', 'SUB', 'GETTABLE_SK', 'POW',
'UNM', 'SETTABLE', 'SETTABLE_I', 'RETURN')
'DIV', 'ADD', 'GETTABLE', 'SUB', 'GETFIELD', 'POW',
'UNM', 'SETTABLE', 'SETI', 'RETURN')
-- direct access to constants
check(function ()
@ -230,7 +230,7 @@ check(function ()
a[true] = false
end,
'LOADNIL',
'SETTABLE_SK', 'SETTABLE_SK', 'SETTABLE', 'SUB', 'DIV', 'LOADK',
'SETFIELD', 'SETFIELD', 'SETTABLE', 'SUB', 'DIV', 'LOADK',
'SETTABLE', 'RETURN')
@ -318,7 +318,7 @@ y = x(z)
compile(z)
compile(x)
assert(x(z) == 6 and y == 6)
print("test 1 OK")
print("Test 1 OK")
-- test 2
x = function ()
@ -334,7 +334,7 @@ check(x, 'LOADNIL', 'LOADIZ', 'LOADK', 'LOADK',
'RETURN', 'RETURN')
compile(x)
assert(x() == 1000000000)
print("test 2 OK")
print("Test 2 OK")
-- test 3
x = function ()
@ -349,7 +349,7 @@ check(x, 'LOADNIL', 'LOADFZ', 'LOADK', 'LOADK',
'RETURN', 'RETURN')
compile(x)
assert(x() == 10000000.0)
print("test 3 OK")
print("Test 3 OK")
-- test 4
x = function ()
@ -364,7 +364,7 @@ check(x, 'LOADK', 'LOADK',
'RETURN', 'RETURN')
compile(x)
assert(x() == 5)
print("test 4 OK")
print("Test 4 OK")
-- test 5
x = function ()
@ -377,7 +377,7 @@ check(x, 'EQ_II', 'JMP', 'LOADK',
'RETURN', 'LOADK', 'RETURN', 'RETURN')
compile(x)
assert(x() == 1.0)
print("test 5 OK")
print("Test 5 OK")
-- test 6
x = function (a: integer, b: integer)
@ -390,7 +390,7 @@ check(x, 'TOINT', 'TOINT', 'EQ_II', 'JMP', 'LOADK',
'RETURN', 'LOADK', 'RETURN', 'RETURN')
compile(x)
assert(x(1,2) == 1.0)
print("test 6 OK")
print("Test 6 OK")
-- test 7
x = function (y: integer)
@ -408,7 +408,7 @@ check(x, 'TOINT', 'LT_II', 'JMP', 'LOADK',
compile(x)
assert(x(5) == 2.0)
assert(x(4) == 3.0)
print("test 7 OK")
print("Test 7 OK")
-- test 8
x = function (y: number)
@ -426,7 +426,7 @@ check(x, 'TOFLT', 'LT_FF', 'JMP', 'LOADK',
compile(x)
assert(x(5.1) == 2.0)
assert(x(4.0) == 3.0)
print("test 8 OK")
print("Test 8 OK")
-- test 9
x = function (y: integer, z)
@ -452,7 +452,7 @@ assert(x(1,2) == 2)
assert(x(1,5.3) == 5.3)
assert(x(5) == 2.0)
assert(x(4) == 3.0)
print("test 9 OK")
print("Test 9 OK")
-- test 10
x = function()
@ -470,7 +470,7 @@ check(x, 'CLOSURE', 'GETTABUP_SK', 'GETUPVAL',
'GETTABUP_SK', 'ADDII', 'EQ_II', 'JMP', 'LOADBOOL', 'LOADBOOL',
'CALL', 'RETURN')
x()
print("test 10 OK")
print("Test 10 OK")
-- test 11
function x()
@ -482,13 +482,13 @@ function x()
return j
end
assert(x() == 55.0)
check(x, 'NEWARRAYF', 'LOADNIL', 'LOADFZ',
check(x, 'NEW_FARRAY', 'LOADNIL', 'LOADFZ',
'LOADK', 'LOADK', 'LOADK', 'FORPREP_I1',
'SETTABLE_AF', 'GETTABLE_AF', 'ADDFF',
'FARRAY_SET', 'FARRAY_GET', 'ADDFF',
'FORLOOP_I1', 'RETURN', 'RETURN')
compile(x)
assert(x() == 55.0)
print("test 11 OK")
print("Test 11 OK")
-- test 12
function pisum()
@ -509,7 +509,7 @@ check(pisum, 'LOADNIL', 'LOADFZ', 'LOADK', 'LOADK',
'RETURN', 'RETURN')
assert(compile(pisum))
assert(math.abs(pisum()-1.644834071848065) < 1e-12)
print("test 12 OK")
print("Test 12 OK")
-- test 13
function y()
@ -526,7 +526,7 @@ check(x, 'MOVE', 'CALL', 'TOFLT',
assert(compile(y))
assert(compile(x))
assert(math.abs(x(y) - 11.3) < 0.0001)
print("test 13 OK")
print("Test 13 OK")
-- test 14
function tryme(x,y)
@ -544,7 +544,7 @@ assert(tryme(2,1) == 0)
compile(tryme)
assert(tryme(1,2) == 1)
assert(tryme(2,1) == 0)
print("test 14 OK")
print("Test 14 OK")
-- test 15
function tryme(x,y)
@ -556,7 +556,7 @@ assert(tryme(1,2))
compile(tryme)
assert(tryme(1,2))
assert(not tryme(2,1))
print("test 15 OK")
print("Test 15 OK")
-- test 16
function tabtest(x)
@ -564,10 +564,10 @@ function tabtest(x)
return x[1]
end
assert(tabtest({}) == 5)
check(tabtest, 'SETTABLE_I', 'GETTABLE_I', 'RETURN', 'RETURN')
check(tabtest, 'SETI', 'GETI', 'RETURN', 'RETURN')
compile(tabtest)
assert(tabtest({}) == 5)
print("test 16 OK")
print("Test 16 OK")
-- test 17
function optest()
@ -580,7 +580,7 @@ check(optest, 'LOADK', 'LOADK', 'LOADNIL',
assert(optest() == 5)
compile(optest)
assert(optest() == 5)
print("test 17 OK")
print("Test 17 OK")
-- test 18
function optest()
@ -593,7 +593,7 @@ check(optest, 'LOADK', 'LOADK', 'LOADNIL',
assert(optest() == 1)
compile(optest)
assert(optest() == 1)
print("test 18 OK")
print("Test 18 OK")
-- test 19
function optest()
@ -608,7 +608,7 @@ check(optest, 'LOADK', 'LOADK', 'TEST', 'JMP',
assert(optest() == 5)
compile(optest)
assert(optest() == 5)
print("test 19 OK")
print("Test 19 OK")
-- test 20
function optest()
@ -623,7 +623,7 @@ check(optest, 'LOADNIL', 'LOADK', 'TEST', 'JMP',
assert(optest() == 5)
compile(optest)
assert(optest() == 5)
print("test 20 OK")
print("Test 20 OK")
-- test 21
z = function()
@ -644,7 +644,7 @@ check(z, 'CLOSURE', 'GETUPVAL', 'MOVE', 'CALL',
z()
compile(z)
z()
print("test 21 OK")
print("Test 21 OK")
-- test 22
z = function()
@ -665,17 +665,17 @@ z = function()
assert(x() == "SundayMondayTuesdayWednesdayThursdayFridaySaturday")
end
check(z, 'NEWTABLE', 'LOADK', 'LOADK', 'LOADK', 'LOADK',
'LOADK', 'LOADK', 'LOADK', 'SETLIST', 'GETTABUP_SK', 'GETTABLE_I',
'LOADK', 'LOADK', 'LOADK', 'SETLIST', 'GETTABUP_SK', 'GETI',
'EQ', 'JMP', 'LOADBOOL', 'LOADBOOL', 'CALL', 'GETTABUP_SK', 'LEN', 'TOINT',
'EQ_II', 'JMP', 'LOADBOOL', 'LOADBOOL', 'CALL', 'GETTABUP_SK', 'GETTABLE_I',
'EQ', 'JMP', 'LOADBOOL', 'LOADBOOL', 'CALL', 'GETTABLE_I', 'LOADK',
'CONCAT', 'SETTABLE_I', 'CLOSURE', 'SETUPVAL', 'GETTABUP_SK', 'GETUPVAL',
'EQ_II', 'JMP', 'LOADBOOL', 'LOADBOOL', 'CALL', 'GETTABUP_SK', 'GETI',
'EQ', 'JMP', 'LOADBOOL', 'LOADBOOL', 'CALL', 'GETI', 'LOADK',
'CONCAT', 'SETI', 'CLOSURE', 'SETUPVAL', 'GETTABUP_SK', 'GETUPVAL',
'GETUPVAL', 'CALL', 'CALL', 'GETTABUP_SK', 'GETUPVAL', 'CALL', 'EQ',
'JMP', 'LOADBOOL', 'LOADBOOL', 'CALL', 'RETURN')
z()
compile(z)
z()
print("test 22 OK")
print("Test 22 OK")
-- test 23
x = function(a)
@ -689,7 +689,7 @@ assert(compile(y))
assert(y(x()))
assert(y(x(false)))
assert(not y(x(true)))
print("test 23 OK")
print("Test 23 OK")
-- test 24
t = { name_ = "ravi" }
@ -702,7 +702,7 @@ end
assert(compile(t.name))
assert(compile(z))
assert(z(t) == "ravi")
print("test 24 OK")
print("Test 24 OK")
-- test 25
-- test ravi integer array
@ -717,7 +717,7 @@ function f()
end
assert(compile(f))
assert(f() == 6)
print("test 25 OK")
print("Test 25 OK")
-- test 26
function f()
@ -728,7 +728,7 @@ end
--ravi.dumplua(f)
assert(compile(f))
assert(math.abs(f()-11.1) < 1e-12)
print("test 26 OK")
print("Test 26 OK")
-- test 27
-- Ravi arrays support for ipairs()
@ -746,7 +746,7 @@ x = function()
end
assert(compile(x))
assert(x() == 28)
print("test 27 OK")
print("Test 27 OK")
-- test 28
-- Ravi arrays support for pairs()
@ -764,7 +764,7 @@ x = function()
end
assert(compile(x))
assert(x() == 28)
print("test 28 OK")
print("Test 28 OK")
-- test 29
-- test creation of arrays and slice
@ -788,7 +788,7 @@ x = function()
end
assert(compile(x))
assert(x() == true)
print("test 29 OK")
print("Test 29 OK")
-- test 30
matrix = {}
@ -836,7 +836,7 @@ assert(compile(matrix.getcol))
assert(compile(matrix.getdata))
assert(compile(x))
assert(x() == 65)
print("test 30 OK")
print("Test 30 OK")
-- test 31
function testadd(a,b)
@ -847,7 +847,7 @@ assert(testadd(1,1) == 2)
assert(testadd(1.5,1.6) == 3.1)
assert(testadd("1.5",1.6) == 3.1)
assert(testadd("1.5","1.6") == 3.1)
print("test 31 OK")
print("Test 31 OK")
-- test 32
function testsub(a,b)
@ -858,7 +858,7 @@ assert(testsub(1,1) == 0)
assert(math.abs(testsub(1.5,1.6)-(-0.1)) < 1e-6)
assert(math.abs(testsub("1.5",1.6)-(-0.1)) < 1e-6)
assert(math.abs(testsub("1.5","1.6")-(-0.1)) < 1e-6)
print("test 32 OK")
print("Test 32 OK")
-- test 33
function testmul(a,b)
@ -869,7 +869,7 @@ assert(testmul(2,2) == 4)
assert(math.abs(testmul(1.5,1.6)-2.4) < 1e-12)
assert(math.abs(testmul("1.5",1.6)-2.4) < 1e-12)
assert(math.abs(testmul("1.5","1.6")-2.4) < 1e-12)
print("test 33 OK")
print("Test 33 OK")
-- test 34
@ -881,7 +881,7 @@ assert(testdiv(2,2) == 1.0)
assert(math.abs(testdiv(1.5,1.6)-0.9375) < 1e-12)
assert(math.abs(testdiv("1.5",1.6)-0.9375) < 1e-12)
assert(math.abs(testdiv("1.5","1.6")-0.9375) < 1e-12)
print("test 34 OK")
print("Test 34 OK")
-- test 35
@ -907,7 +907,7 @@ assert(t[1]() == 10)
assert(t[2]() == 10)
assert(t[1]() == 20)
assert(t[2]() == 20)
print("test 35 OK")
print("Test 35 OK")
-- test 36
-- upvalues
@ -924,7 +924,7 @@ local f = y()
assert(f() == 1)
x=5
assert(f() == 5)
print("test 36 OK")
print("Test 36 OK")
-- test 37
-- upvalues
@ -945,7 +945,7 @@ local f = y()
assert(f() == 3)
x1=5
assert(f() == 5)
print("test 37 OK")
print("Test 37 OK")
-- test 38
function x()
@ -960,7 +960,7 @@ f=x()
assert(compile(f))
assert(f() == 2)
assert(f() == 3)
print("test 38 OK")
print("Test 38 OK")
-- test setupval, getupval
function x()
@ -974,7 +974,7 @@ compile(y)
assert(y(2) == 2)
assert(y(2) == 4)
assert(y(3) == 7)
print('test 39 OK')
print('Test 39 OK')
-- test 40
x=function(a,b)
@ -985,7 +985,7 @@ assert(compile(x))
-- if ravi.jit() then ravi.compile(x) end
assert(x(5,2) == 1)
assert(math.abs(x(5.1,2.1)-0.9) < 1e-6)
print("test 40 OK")
print("Test 40 OK")
-- test 41
x=function(a,b)
@ -996,7 +996,7 @@ assert(compile(x))
-- if ravi.jit() then ravi.compile(x) end
assert(x(5,2) == 2)
assert(math.abs(x(5.5,2.1)-2.0) < 1e-6)
print("test 41 OK")
print("Test 41 OK")
-- test 42
x = function ()
@ -1008,10 +1008,10 @@ x = function ()
end
if (not compile(x)) then
print("test FAILED to compile")
print("Test FAILED to compile")
end
assert(x() == 5.1)
print("test 42 OK")
print("Test 42 OK")
-- test parameter types
x = function (a: integer, b: number)
@ -1023,7 +1023,7 @@ end
assert(x(1,5.5) == 6.5)
compile(x)
assert(x(1,5.5) == 6.5)
print'test 43 OK'
print'Test 43 OK'
x=function (a:number[], b:integer)
local j: number = a[b]
@ -1038,7 +1038,7 @@ assert(y() == 4.2)
compile(x)
compile(y)
assert(y() == 4.2)
print'test 44 OK'
print'Test 44 OK'
-- test 45
function x(t) return t; end
@ -1066,7 +1066,7 @@ end
assert(compile(f))
assert(not pcall(f))
print("test 45 OK")
print("Test 45 OK")
-- test 47
function test_idiv()
@ -1092,7 +1092,7 @@ function test_idiv()
end
compile(test_idiv)
test_idiv()
print'test 47 (IDIV) OK'
print'Test 47 (IDIV) OK'
function test_tableaccess()
-- Test specialised version of GETTABLE and SETTABLE
@ -1105,9 +1105,9 @@ function test_tableaccess()
t.data.city = 'london'
return t.name, t.data.city
end
check(f, 'NEWTABLE', 'SETTABLE_S', 'NEWTABLE',
'SETTABLE_S', 'GETTABLE_S', 'SETTABLE_SK',
'GETTABLE_S', 'GETTABLE_S' , 'GETTABLE_SK',
check(f, 'NEWTABLE', 'TABLE_SETFIELD', 'NEWTABLE',
'TABLE_SETFIELD', 'TABLE_GETFIELD', 'SETFIELD',
'TABLE_GETFIELD', 'TABLE_GETFIELD' , 'GETFIELD',
'RETURN', 'RETURN')
local a,b = f()
assert(a == 'dibyendu')
@ -1127,9 +1127,9 @@ function test_tableaccess()
t[2][1] = 'london'
return t[1], t[2][1]
end
check(f, 'NEWTABLE', 'SETTABLE_I', 'NEWTABLE',
'SETTABLE_I', 'GETTABLE_I', 'SETTABLE_I',
'GETTABLE_I', 'GETTABLE_I' , 'GETTABLE_I',
check(f, 'NEWTABLE', 'SETI', 'NEWTABLE',
'SETI', 'GETI', 'SETI',
'GETI', 'GETI' , 'GETI',
'RETURN', 'RETURN')
local a,b = f()
assert(a == 'dibyendu')
@ -1149,8 +1149,8 @@ function test_self_s()
assert(t:name())
return t:name()
end
check(test_self_s, 'NEWTABLE', 'SETTABLE_S', 'CLOSURE',
'SETTABLE_S', 'GETTABUP_SK', 'SELF_S', 'CALL', 'CALL', 'SELF_S', 'TAILCALL',
check(test_self_s, 'NEWTABLE', 'TABLE_SETFIELD', 'CLOSURE',
'TABLE_SETFIELD', 'GETTABUP_SK', 'TABLE_SELF_SK', 'CALL', 'CALL', 'TABLE_SELF_SK', 'TAILCALL',
'RETURN')
assert(test_self_s() == 'dibyendu majumdar')
compile(test_self_s)
@ -1252,11 +1252,11 @@ function test_longkey()
assert(t.s == nil)
end
check(test_longkey, 'NEWTABLE', 'SETTABLE', 'GETTABUP_SK', 'GETTABLE',
'EQ', 'JMP', 'LOADBOOL', 'LOADBOOL', 'CALL', 'SETTABLE_S', 'GETTABUP_SK',
'GETTABLE_S', 'EQ', 'JMP', 'LOADBOOL', 'LOADBOOL', 'CALL', 'SETTABLE_S',
'GETTABUP_SK', 'GETTABLE_S', 'EQ', 'JMP', 'LOADBOOL', 'LOADBOOL', 'CALL',
'EQ', 'JMP', 'LOADBOOL', 'LOADBOOL', 'CALL', 'TABLE_SETFIELD', 'GETTABUP_SK',
'TABLE_GETFIELD', 'EQ', 'JMP', 'LOADBOOL', 'LOADBOOL', 'CALL', 'TABLE_SETFIELD',
'GETTABUP_SK', 'TABLE_GETFIELD', 'EQ', 'JMP', 'LOADBOOL', 'LOADBOOL', 'CALL',
'LOADK', 'GETTABUP_SK', 'GETTABLE', 'EQ', 'JMP', 'LOADBOOL', 'LOADBOOL', 'CALL',
'GETTABUP_SK', 'GETTABLE_S', 'EQ', 'JMP', 'LOADBOOL', 'LOADBOOL', 'CALL',
'GETTABUP_SK', 'TABLE_GETFIELD', 'EQ', 'JMP', 'LOADBOOL', 'LOADBOOL', 'CALL',
'RETURN')
assert(pcall(test_longkey));
compile(test_longkey);
@ -1584,10 +1584,117 @@ function x()
:find'not contain __ prefix')
end
check(x, 'GETTABUP_SK', 'NEWTABLE', 'GETTABUP_SK', 'CLOSURE',
'CALL', 'SETLIST', 'GETTABLE_I', 'SELF_SK', 'LOADK',
'CALL', 'SETLIST', 'GETI', 'SELF_SK', 'LOADK',
'CALL', 'CALL', 'RETURN')
print 'Test 64 OK'
x = function()
local i: integer = @integer 1
local n: number = @number 1.2
assert(i == 1 and n == 1.2)
local j = { 1, 2, 3, 4.2, 5 }
i = @integer( @integer (j[2]) )
n = @number( @number (j[4]) )
assert(i == 2)
assert(n == 4.2)
end
check(x, 'LOADK', 'LOADK', 'GETTABUP_SK', 'EQ_II',
'JMP', 'EQ_FF', 'JMP', 'LOADBOOL', 'LOADBOOL',
'CALL', 'NEWTABLE', 'LOADK', 'LOADK', 'LOADK',
'LOADK', 'LOADK', 'SETLIST', 'GETI', 'TOINT',
'MOVEI', 'GETI', 'TOFLT', 'MOVEF', 'GETTABUP_SK',
'EQ_II', 'JMP', 'LOADBOOL', 'LOADBOOL', 'CALL',
'GETTABUP_SK', 'EQ_FF', 'JMP', 'LOADBOOL', 'LOADBOOL',
'CALL', 'RETURN')
x()
compile(x)
x()
print 'Test 65 OK'
function x()
local a,b = 1,2
local c: integer,d: integer = @integer a, @integer b
assert(c == a and b == d)
end
check(x, 'LOADK', 'LOADK', 'TOINT', 'MOVE',
'TOINT', 'MOVE', 'GETTABUP_SK', 'EQ', 'JMP',
'EQ', 'JMP', 'LOADBOOL', 'LOADBOOL', 'CALL',
'RETURN')
x()
compile(x)
x()
print 'Test 66 OK'
g = { 1, 5.5 }
local h = { 10, 4.2 }
function x()
local a: integer = 11
local b: number = 6.5
local c = 6
a = @integer( g[1] ) + @integer( h[1] ) * @integer( c )
c = 3.2
b = @number( g[2] ) * @number( h[2] ) - @number( c )
return a,b
end
y,z = x()
assert(y == 61 and math.abs(z - 19.9) < 1e-5)
compile(x)
y,z = x()
assert(y == 61 and math.abs(z - 19.9) < 1e-10)
check(x, 'LOADK', 'LOADK', 'LOADK', 'GETTABUP_SK',
'GETI', 'TOINT', 'GETTABUP', 'TOINT', 'TOINT',
'MULII', 'ADDII', 'LOADK', 'GETTABUP_SK', 'GETI',
'TOFLT', 'GETTABUP', 'TOFLT', 'MULFF', 'TOFLT',
'SUBFF', 'MOVE', 'MOVE', 'RETURN', 'RETURN')
print 'Test 67 OK'
x=load 'local t: number[] = {}'
check(x, 'NEW_FARRAY', 'RETURN')
print 'Test 68 OK'
x=load 'local t = @number[] {}'
check(x, 'NEW_FARRAY', 'RETURN')
print 'Test 69 OK'
x=load 'local t: number[] = @number[] ( @number[] {} )'
check(x, 'NEW_FARRAY', 'RETURN')
print 'Test 70 OK'
function x()
return { @integer[] {1,2}, @number[] {42} }
end
check(x, 'NEWTABLE', 'NEW_IARRAY', 'LOADK', 'LOADK',
'SETLIST', 'NEW_FARRAY', 'LOADK', 'SETLIST',
'SETLIST', 'RETURN', 'RETURN')
y = x()
assert(ravitype(y[1]) == 'integer[]')
assert(ravitype(y[2]) == 'number[]')
print 'Test 71 OK'
function x()
return @integer[] @integer[] @integer[]{1}
end
check(x, 'NEW_IARRAY', 'LOADK', 'SETLIST', 'RETURN', 'RETURN')
assert(ravitype(x()) == 'integer[]')
print 'Test 72 OK'
function x()
return nil or @integer[] {1}
end
assert(ravitype(x()) == 'integer[]')
check(x, 'NEW_IARRAY', 'LOADK', 'SETLIST', 'RETURN', 'RETURN')
print 'Test 73 OK'
function x()
return @number[]( @integer[] {1} and @number[] {42} )
end
assert(ravitype(x()) == 'number[]')
assert(x()[1] == 42.0)
check(x, 'NEW_IARRAY', 'LOADK', 'SETLIST', 'TEST',
'JMP', 'NEW_FARRAY', 'LOADK', 'SETLIST', 'TOFARRAY',
'RETURN', 'RETURN')
print 'Test 74 OK'
for k,v in pairs(opcodes_coverage)
do
print(k, v)

@ -55,8 +55,8 @@ opcodes_coverage.SETLIST = 0
opcodes_coverage.CLOSURE = 0
opcodes_coverage.VARARG = 0
opcodes_coverage.EXTRAARG = 0
opcodes_coverage.NEWARRAYI = 0
opcodes_coverage.NEWARRAYF = 0
opcodes_coverage.NEW_IARRAY = 0
opcodes_coverage.NEW_FARRAY = 0
opcodes_coverage.LOADIZ = 0
opcodes_coverage.LOADFZ = 0
opcodes_coverage.UNMF = 0
@ -77,26 +77,26 @@ opcodes_coverage.DIVIF = 0
opcodes_coverage.DIVII = 0
opcodes_coverage.TOINT = 0
opcodes_coverage.TOFLT = 0
opcodes_coverage.TOARRAYI = 0
opcodes_coverage.TOARRAYF = 0
opcodes_coverage.TOIARRAY = 0
opcodes_coverage.TOFARRAY = 0
opcodes_coverage.MOVEI = 0
opcodes_coverage.MOVEF = 0
opcodes_coverage.MOVEAI = 0
opcodes_coverage.MOVEAF = 0
opcodes_coverage.GETTABLE_AI = 0
opcodes_coverage.GETTABLE_AF = 0
opcodes_coverage.SETTABLE_AI = 0
opcodes_coverage.SETTABLE_AF = 0
opcodes_coverage.MOVEIARRAY = 0
opcodes_coverage.MOVEFARRAY = 0
opcodes_coverage.IARRAY_GET = 0
opcodes_coverage.FARRAY_GET = 0
opcodes_coverage.IARRAY_SET = 0
opcodes_coverage.FARRAY_SET = 0
opcodes_coverage.FORLOOP_IP = 0
opcodes_coverage.FORLOOP_I1 = 0
opcodes_coverage.FORPREP_IP = 0
opcodes_coverage.FORPREP_I1 = 0
opcodes_coverage.SETUPVALI = 0
opcodes_coverage.SETUPVALF = 0
opcodes_coverage.SETUPVALAI = 0
opcodes_coverage.SETUPVALAF = 0
opcodes_coverage.SETTABLE_AII = 0
opcodes_coverage.SETTABLE_AFF = 0
opcodes_coverage.SETUPVAL_IARRAY = 0
opcodes_coverage.SETUPVAL_FARRAY = 0
opcodes_coverage.IARRAY_SETI = 0
opcodes_coverage.FARRAY_SETF = 0
opcodes_coverage.BAND_II = 0
opcodes_coverage.BOR_II = 0
opcodes_coverage.BXOR_II = 0
@ -109,16 +109,16 @@ opcodes_coverage.LT_II = 0
opcodes_coverage.LT_FF = 0
opcodes_coverage.LE_II = 0
opcodes_coverage.LE_FF = 0
opcodes_coverage.GETTABLE_I = 0
opcodes_coverage.GETTABLE_S = 0
opcodes_coverage.SETTABLE_I = 0
opcodes_coverage.SETTABLE_S = 0
opcodes_coverage.SETTABLE_SK = 0
opcodes_coverage.GETTABLE_SK = 0
opcodes_coverage.GETI = 0
opcodes_coverage.TABLE_GETFIELD = 0
opcodes_coverage.SETI = 0
opcodes_coverage.TABLE_SETFIELD = 0
opcodes_coverage.SETFIELD = 0
opcodes_coverage.GETFIELD = 0
opcodes_coverage.TOTAB = 0
opcodes_coverage.MOVETAB = 0
opcodes_coverage.SETUPVALT = 0
opcodes_coverage.SELF_S = 0
opcodes_coverage.TABLE_SELF_SK = 0
opcodes_coverage.TOTYPE = 0
opcodes_coverage.TOSTRING = 0
opcodes_coverage.TOCLOSURE = 0
@ -175,8 +175,8 @@ end
check(x, {'LOADK', 'LOADK', 'GETTABUP_SK', 'EQ_II',
'JMP', 'EQ_FF', 'JMP', 'LOADBOOL', 'LOADBOOL',
'CALL', 'NEWTABLE', 'LOADK', 'LOADK', 'LOADK',
'LOADK', 'LOADK', 'SETLIST', 'GETTABLE_I', 'TOINT',
'MOVEI', 'GETTABLE_I', 'TOFLT', 'MOVEF', 'GETTABUP_SK',
'LOADK', 'LOADK', 'SETLIST', 'GETI', 'TOINT',
'MOVEI', 'GETI', 'TOFLT', 'MOVEF', 'GETTABUP_SK',
'EQ_II', 'JMP', 'LOADBOOL', 'LOADBOOL', 'CALL',
'GETTABUP_SK', 'EQ_FF', 'JMP', 'LOADBOOL', 'LOADBOOL',
'CALL', 'RETURN'})
@ -214,25 +214,25 @@ compile(x)
y,z = x()
assert(y == 61 and math.abs(z - 19.9) < 1e-10)
check(x, {'LOADK', 'LOADK', 'LOADK', 'GETTABUP_SK',
'GETTABLE_I', 'TOINT', 'GETTABUP', 'TOINT', 'TOINT',
'MULII', 'ADDII', 'LOADK', 'GETTABUP_SK', 'GETTABLE_I',
'GETI', 'TOINT', 'GETTABUP', 'TOINT', 'TOINT',
'MULII', 'ADDII', 'LOADK', 'GETTABUP_SK', 'GETI',
'TOFLT', 'GETTABUP', 'TOFLT', 'MULFF', 'TOFLT',
'SUBFF', 'MOVE', 'MOVE', 'RETURN', 'RETURN'})
x=load 'local t: number[] = {}'
check(x, {'NEWARRAYF', 'RETURN'})
check(x, {'NEW_FARRAY', 'RETURN'})
x=load 'local t = @number[] {}'
check(x, {'NEWARRAYF', 'RETURN'})
check(x, {'NEW_FARRAY', 'RETURN'})
x=load 'local t: number[] = @number[] ( @number[] {} )'
check(x, {'NEWARRAYF', 'RETURN'})
check(x, {'NEW_FARRAY', 'RETURN'})
function x()
return { @integer[] {1,2}, @number[] {42} }
end
check(x, {'NEWTABLE', 'NEWARRAYI', 'LOADK', 'LOADK',
'SETLIST', 'NEWARRAYF', 'LOADK', 'SETLIST',
check(x, {'NEWTABLE', 'NEW_IARRAY', 'LOADK', 'LOADK',
'SETLIST', 'NEW_FARRAY', 'LOADK', 'SETLIST',
'SETLIST', 'RETURN', 'RETURN'})
y = x()
assert(ravitype(y[1]) == 'integer[]')
@ -241,20 +241,20 @@ assert(ravitype(y[2]) == 'number[]')
function x()
return @integer[] @integer[] @integer[]{1}
end
check(x, {'NEWARRAYI', 'LOADK', 'SETLIST', 'RETURN', 'RETURN'})
check(x, {'NEW_IARRAY', 'LOADK', 'SETLIST', 'RETURN', 'RETURN'})
assert(ravitype(x()) == 'integer[]')
function x()
return nil or @integer[] {1}
end
assert(ravitype(x()) == 'integer[]')
check(x, {'NEWARRAYI', 'LOADK', 'SETLIST', 'RETURN', 'RETURN'})
check(x, {'NEW_IARRAY', 'LOADK', 'SETLIST', 'RETURN', 'RETURN'})
function x()
return @number[]( @integer[] {1} and @number[] {42} )
end
assert(ravitype(x()) == 'number[]')
assert(x()[1] == 42.0)
check(x, {'NEWARRAYI', 'LOADK', 'SETLIST', 'TEST',
'JMP', 'NEWARRAYF', 'LOADK', 'SETLIST', 'TOARRAYF',
check(x, {'NEW_IARRAY', 'LOADK', 'SETLIST', 'TEST',
'JMP', 'NEW_FARRAY', 'LOADK', 'SETLIST', 'TOFARRAY',
'RETURN', 'RETURN'})

@ -82,20 +82,6 @@ then
exit 1
fi
$LUA ravi_tests2.ravi
if [ $? != 0 ]
then
echo "ravi_tests2 failed"
exit 1
fi
$LUA -e"ravi.auto(true,1)" ravi_tests2.ravi
if [ $? != 0 ]
then
echo "ravi_tests2 failed"
exit 1
fi
echo "======================================="
$LUA gaussian2.lua

@ -268,7 +268,7 @@ Parameter lists may have static type annotations as well, so when parsing parame
}
else if (tt == RAVI_TARRAYFLT || tt == RAVI_TARRAYINT) {
/* code an instruction to convert in place */
luaK_codeABC(ls->fs, tt == RAVI_TARRAYFLT ? OP_RAVI_TOARRAYF : OP_RAVI_TOARRAYI, i, 0, 0);
luaK_codeABC(ls->fs, tt == RAVI_TARRAYFLT ? OP_RAVI_TOFARRAY : OP_RAVI_TOIARRAY, i, 0, 0);
}
}
}
@ -415,7 +415,7 @@ The main changes compared to ``explist()`` are the calls to ``ravi_typecheck()``
/* code an instruction to convert in place */
luaK_codeABC(ls->fs,
vars[i] == RAVI_TARRAYFLT ?
OP_RAVI_TOARRAYF : OP_RAVI_TOARRAYI,
OP_RAVI_TOFARRAY : OP_RAVI_TOIARRAY,
a + (i - n), 0, 0);
}
else if ((vars[n] == RAVI_TNUMFLT || vars[n] == RAVI_TNUMINT) &&
@ -435,7 +435,7 @@ 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 ``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 ``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.
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 ``TOIARRAY`` and ``TOFARRAY`` 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 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.
@ -558,7 +558,7 @@ Note the use of ``register_to_localvar_index()`` in functions below.
OP_RAVI_TOFLT : OP_RAVI_TOINT, i, 0, 0);
else if (ravi_type == RAVI_TARRAYINT || ravi_type == RAVI_TARRAYFLT)
luaK_codeABC(ls->fs, ravi_type == RAVI_TARRAYINT ?
OP_RAVI_TOARRAYI : OP_RAVI_TOARRAYF, i, 0, 0);
OP_RAVI_TOIARRAY : OP_RAVI_TOFARRAY, i, 0, 0);
}
}
@ -610,10 +610,10 @@ Assignment statements have to be enhanced to perform similar type checks as for
/* table value set - if array access then use specialized versions */
if (var->ravi_type == RAVI_TARRAYFLT &&
var->u.ind.key_type == RAVI_TNUMINT)
op = OP_RAVI_SETTABLE_AF;
op = OP_RAVI_FARRAY_SET;
else if (var->ravi_type == RAVI_TARRAYINT &&
var->u.ind.key_type == RAVI_TNUMINT)
op = OP_RAVI_SETTABLE_AI;
op = OP_RAVI_IARRAY_SET;
}
int e = luaK_exp2RK(fs, ex);
luaK_codeABC(fs, op, var->u.ind.t, var->u.ind.idx, e);
@ -679,10 +679,10 @@ Any ``MOVE`` instructions must be modified so that if the target is register tha
luaK_codeABC(fs, OP_RAVI_MOVEF, reg, e->u.info, 0);
break;
case RAVI_TARRAYINT:
luaK_codeABC(fs, OP_RAVI_MOVEAI, reg, e->u.info, 0);
luaK_codeABC(fs, OP_RAVI_MOVEIARRAY, reg, e->u.info, 0);
break;
case RAVI_TARRAYFLT:
luaK_codeABC(fs, OP_RAVI_MOVEAF, reg, e->u.info, 0);
luaK_codeABC(fs, OP_RAVI_MOVEFARRAY, reg, e->u.info, 0);
break;
default:
luaK_codeABC(fs, OP_MOVE, reg, e->u.info, 0);
@ -817,10 +817,10 @@ When expression reference indexed variables, i.e., tables, we need to emit speci
/* table access - set specialized op codes if array types are detected */
if (e->ravi_type == RAVI_TARRAYFLT &&
e->u.ind.key_type == RAVI_TNUMINT)
op = OP_RAVI_GETTABLE_AF;
op = OP_RAVI_FARRAY_GET;
else if (e->ravi_type == RAVI_TARRAYINT &&
e->u.ind.key_type == RAVI_TNUMINT)
op = OP_RAVI_GETTABLE_AI;
op = OP_RAVI_IARRAY_GET;
else
op = OP_GETTABLE;
if (e->ravi_type == RAVI_TARRAYFLT || e->ravi_type == RAVI_TARRAYINT)
@ -1045,9 +1045,9 @@ When we need to generate assignments to an upvalue (OP_SETUPVAL) we need to use
else if (var->ravi_type == RAVI_TNUMFLT)
op = OP_RAVI_SETUPVALF;
else if (var->ravi_type == RAVI_TARRAYINT)
op = OP_RAVI_SETUPVALAI;
op = OP_RAVI_SETUPVAL_IARRAY;
else if (var->ravi_type == RAVI_TARRAYFLT)
op = OP_RAVI_SETUPVALAF;
op = OP_RAVI_SETUPVAL_FARRAY;
else
luaX_syntaxerror(fs->ls,
luaO_pushfstring(fs->ls->L, "Invalid assignment of "

@ -34,7 +34,7 @@ The Architecture of Ravi's JIT Compilation
* The decision to call a JIT compiled version is made in the Lua Infrastructure (specifically in ``luaD_precall()`` function in ``ldo.c``)
* The JIT compiler translates Lua/Ravi bytecode to LLVM IR - i.e. it does not translate Lua source code.
* There is no inlining of Lua functions.
* Generally the JIT compiler implements the same instructions as in ``lvm.c`` - however for some bytecodes the code calls a C function rather than generating inline IR. These opcodes are OP_LOADNIL, OP_NEWTABLE, OP_RAVI_NEWARRAYINT, OP_RAVI_NEWARRAYFLT, OP_SETLIST, OP_CONCAT, OP_CLOSURE, OP_VARARG, OP_RAVI_SHL_II, OP_RAVI_SHR_II.
* Generally the JIT compiler implements the same instructions as in ``lvm.c`` - however for some bytecodes the code calls a C function rather than generating inline IR. These opcodes are OP_LOADNIL, OP_NEWTABLE, OP_RAVI_NEW_IARRAYNT, OP_RAVI_NEW_FARRAYLT, OP_SETLIST, OP_CONCAT, OP_CLOSURE, OP_VARARG, OP_RAVI_SHL_II, OP_RAVI_SHR_II.
* Ravi represents Lua values as done by Lua 5.3 - i.e. in a 16 byte structure.
* Ravi compiler generates type specifc opcodes which result in simpler and higher performance LLVM IR.
@ -154,9 +154,9 @@ Note that if a Lua functions contains a bytecode that cannot be be JITed then th
+-------------------------+----------+--------------------------------------------------+
| OP_EXTRAARG | N/A | extra (larger) argument for previous opcode |
+-------------------------+----------+--------------------------------------------------+
| OP_RAVI_NEWARRAYI | YES | R(A) := array of int |
| OP_RAVI_NEW_IARRAY | YES | R(A) := array of int |
+-------------------------+----------+--------------------------------------------------+
| OP_RAVI_NEWARRAYF | YES | R(A) := array of float |
| OP_RAVI_NEW_FARRAY | YES | R(A) := array of float |
+-------------------------+----------+--------------------------------------------------+
| OP_RAVI_LOADIZ | YES | R(A) := tointeger(0) |
+-------------------------+----------+--------------------------------------------------+
@ -194,28 +194,28 @@ Note that if a Lua functions contains a bytecode that cannot be be JITed then th
+-------------------------+----------+--------------------------------------------------+
| OP_RAVI_TOFLT | YES | R(A) := tofloat(R(A)) |
+-------------------------+----------+--------------------------------------------------+
| OP_RAVI_TOARRAYI | YES | R(A) := to_arrayi(R(A)) |
| OP_RAVI_TOIARRAY | YES | R(A) := to_arrayi(R(A)) |
+-------------------------+----------+--------------------------------------------------+
| OP_RAVI_TOARRAYF | YES | R(A) := to_arrayf(R(A)) |
| OP_RAVI_TOFARRAY | YES | R(A) := to_arrayf(R(A)) |
+-------------------------+----------+--------------------------------------------------+
| OP_RAVI_MOVEI | YES | R(A) := R(B), check R(B) is integer |
+-------------------------+----------+--------------------------------------------------+
| OP_RAVI_MOVEF | YES | R(A) := R(B), check R(B) is number |
+-------------------------+----------+--------------------------------------------------+
| OP_RAVI_MOVEAI | YES | R(A) := R(B), check R(B) is array of integer |
| OP_RAVI_MOVEIARRAY | YES | R(A) := R(B), check R(B) is array of integer |
+-------------------------+----------+--------------------------------------------------+
| OP_RAVI_MOVEAF | YES | R(A) := R(B), check R(B) is array of numbers |
| OP_RAVI_MOVEFARRAY | YES | R(A) := R(B), check R(B) is array of numbers |
+-------------------------+----------+--------------------------------------------------+
| OP_RAVI_GETTABLE_AI | YES | R(A) := R(B)[RK(C)] where R(B) is array of |
| OP_RAVI_IARRAY_GET | YES | R(A) := R(B)[RK(C)] where R(B) is array of |
| | | integers and RK(C) is integer |
+-------------------------+----------+--------------------------------------------------+
| OP_RAVI_GETTABLE_AF | YES | R(A) := R(B)[RK(C)] where R(B) is array of |
| OP_RAVI_FARRAY_GET | YES | R(A) := R(B)[RK(C)] where R(B) is array of |
| | | numbers and RK(C) is integer |
+-------------------------+----------+--------------------------------------------------+
| OP_RAVI_SETTABLE_AI | YES | R(A)[RK(B)] := RK(C) where RK(B) is an integer |
| OP_RAVI_IARRAY_SET | YES | R(A)[RK(B)] := RK(C) where RK(B) is an integer |
| | | R(A) is array of integers, and RK(C) is an int |
+-------------------------+----------+--------------------------------------------------+
| OP_RAVI_SETTABLE_AF | YES | R(A)[RK(B)] := RK(C) where RK(B) is an integer |
| OP_RAVI_FARRAY_SET | YES | R(A)[RK(B)] := RK(C) where RK(B) is an integer |
| | | R(A) is array of numbers, and RK(C) is a number |
+-------------------------+----------+--------------------------------------------------+
| OP_RAVI_FORLOOP_IP | YES | R(A)+=R(A+2); |
@ -236,15 +236,15 @@ Note that if a Lua functions contains a bytecode that cannot be be JITed then th
+-------------------------+----------+--------------------------------------------------+
| OP_RAVI_SETUPVALF | YES (1) | UpValue[B] := tonumber(R(A)) |
+-------------------------+----------+--------------------------------------------------+
| OP_RAVI_SETUPVALAI | YES (1) | UpValue[B] := toarrayint(R(A)) |
| OP_RAVI_SETUPVAL_IARRAY | YES (1) | UpValue[B] := toarrayint(R(A)) |
+-------------------------+----------+--------------------------------------------------+
| OP_RAVI_SETUPVALAF | YES (1) | UpValue[B] := toarrayflt(R(A)) |
| OP_RAVI_SETUPVAL_FARRAY | YES (1) | UpValue[B] := toarrayflt(R(A)) |
+-------------------------+----------+--------------------------------------------------+
| OP_RAVI_SETTABLE_AII | YES | R(A)[RK(B)] := RK(C) where RK(B) is an integer |
| OP_RAVI_IARRAY_SETI | YES | R(A)[RK(B)] := RK(C) where RK(B) is an integer |
| | | R(A) is array of integers, and RK(C) is an int |
| | | No conversion as input is known to be int |
+-------------------------+----------+--------------------------------------------------+
| OP_RAVI_SETTABLE_AFF | YES | R(A)[RK(B)] := RK(C) where RK(B) is an integer |
| OP_RAVI_FARRAY_SETF | YES | R(A)[RK(B)] := RK(C) where RK(B) is an integer |
| | | R(A) is array of numbers, and RK(C) is a number |
| | | No conversion as input is known to be float |
+-------------------------+----------+--------------------------------------------------+
@ -272,17 +272,17 @@ Note that if a Lua functions contains a bytecode that cannot be be JITed then th
+-------------------------+----------+--------------------------------------------------+
| OP_RAVI_LE_FF | YES | if ((RK(B) <= RK(C)) ~= A) then pc++ |
+-------------------------+----------+--------------------------------------------------+
| OP_RAVI_GETTABLE_I | YES | R(A) := R(B)[RK(C)], integer key |
| OP_RAVI_GETI | YES | R(A) := R(B)[RK(C)], integer key |
+-------------------------+----------+--------------------------------------------------+
| OP_RAVI_GETTABLE_S | YES | R(A) := R(B)[RK(C)], string key |
| OP_RAVI_TABLE_GETFIELD | YES | R(A) := R(B)[RK(C)], string key |
+-------------------------+----------+--------------------------------------------------+
| OP_RAVI_GETTABLE_SK | YES | R(A) := R(B)[RK(C)], string key |
| OP_RAVI_GETFIELD | YES | R(A) := R(B)[RK(C)], string key |
+-------------------------+----------+--------------------------------------------------+
| OP_RAVI_SETTABLE_I | YES (4) | R(A)[RK(B)] := RK(C), integer key |
| OP_RAVI_SETI | YES (4) | R(A)[RK(B)] := RK(C), integer key |
+-------------------------+----------+--------------------------------------------------+
| OP_RAVI_SETTABLE_S | YES (3) | R(A)[RK(B)] := RK(C), string key |
| OP_RAVI_TABLE_SETFIELD | YES (3) | R(A)[RK(B)] := RK(C), string key |
+-------------------------+----------+--------------------------------------------------+
| OP_RAVI_SETTABLE_SK | YES | R(A)[RK(B)] := RK(C), string key |
| OP_RAVI_SETFIELD | YES | R(A)[RK(B)] := RK(C), string key |
+-------------------------+----------+--------------------------------------------------+
| OP_RAVI_TOTAB | YES | R(A) := to_table(R(A)) |
+-------------------------+----------+--------------------------------------------------+
@ -292,7 +292,7 @@ Note that if a Lua functions contains a bytecode that cannot be be JITed then th
+-------------------------+----------+--------------------------------------------------+
| OP_RAVI_SELF_SK | YES | R(A+1) := R(B); R(A) := R(B)[RK(C)] |
+-------------------------+----------+--------------------------------------------------+
| OP_RAVI_SELF_S | YES | R(A+1) := R(B); R(A) := R(B)[RK(C)] |
| OP_RAVI_TABLE_SELF_SK | YES | R(A+1) := R(B); R(A) := R(B)[RK(C)] |
+-------------------------+----------+--------------------------------------------------+
| OP_RAVI_GETTABUP_SK | YES | R(A) := UpValue[B][RK(C)] |
+-------------------------+----------+--------------------------------------------------+

@ -0,0 +1,27 @@
New Parser and Code Generator for Ravi
======================================
These are some design notes on the new parser / code generator.
There will be several phases:
1. Convert input into syntax tree - this will look very much like the input source, i.e. there will be fornum loops, if statements,
while and repeat loops etc. During this phase only the types for literals and local decalarations will be known.
2. The next phase will be a type checking phase. In this phase types will be derive for expressions, and also type assertions will be
added where required such as unpon function entry, and after function calls. But the overall syntax tree will still resemble the input
source except for the additional instructions.
3. Third phase will be to assign virtual registers; first to locals, and then to temporaries. For simplicity I will probably keep the
temporaries and locals in separate ranges.
4. Next phase will be linearize the instructions - during this phase the loops, if statements etc will get translated to equivalent of
conditional and unconditional jumps.
5. We could at this stage generate byte code and finish. Initially maybe we will stop here.
6. The next phase will be translate into basic blocks.
7. Following that we will construct a CFG, perform dominator analysis and convert to SSA form.
Some other things
-----------------
1. locals that are used as up-values or passed or overwritten by function calls should be marked as having 'escaped'.
Having this knowledge will enable backend JIT to use the stack for values that cannot escape.
2. during code generation it will be good to know which registers are type constant - i.e. their types do not change. register allocation
should be designed / implemented so that we try to avoid over-writing type data where possible. This will allow backend JIT
to generate more optimized code.

@ -1,5 +1,5 @@
/*
** $Id: lapi.c,v 2.259 2016/02/29 14:27:14 roberto Exp $
** $Id: lapi.c,v 2.259.1.2 2017/12/06 18:35:12 roberto Exp $
** Lua API
** See Copyright Notice in lua.h
*/
@ -580,6 +580,7 @@ LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) {
lua_lock(L);
if (n == 0) {
setfvalue(L->top, fn);
api_incr_top(L);
}
else {
CClosure *cl;
@ -595,9 +596,9 @@ LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) {
/* does not need barrier because closure is white */
}
setclCvalue(L, L->top, cl);
api_incr_top(L);
luaC_checkGC(L);
}
api_incr_top(L);
luaC_checkGC(L);
lua_unlock(L);
}
@ -681,11 +682,12 @@ LUA_API int lua_geti (lua_State *L, int idx, lua_Integer n) {
if (ttisLtable(t) || !ttistable(t)) {
if (luaV_fastgeti(L, t, n, slot)) {
setobj2s(L, L->top, slot);
api_incr_top(L);
}
else {
TValue aux;
setivalue(&aux, n);
luaV_finishget(L, t, &aux, L->top, slot);
setivalue(L->top, n);
api_incr_top(L);
luaV_finishget(L, t, L->top - 1, L->top - 1, slot);
}
}
else {
@ -702,8 +704,8 @@ LUA_API int lua_geti (lua_State *L, int idx, lua_Integer n) {
setnilvalue(L->top);
}
}
api_incr_top(L);
}
api_incr_top(L);
lua_unlock(L);
return ttnov(L->top - 1);
}
@ -716,7 +718,7 @@ LUA_API int lua_rawget(lua_State *L, int idx) {
api_check(L, ttistable(t), "table expected");
h = hvalue(t);
if (ttisLtable(t)) {
setobj2s(L, L->top - 1, luaH_get(hvalue(t), L->top - 1));
setobj2s(L, L->top - 1, luaH_get(h, L->top - 1));
}
else if (ttisfarray(t)) {
TValue *key = L->top - 1;
@ -759,7 +761,7 @@ LUA_API int lua_rawgeti (lua_State *L, int idx, lua_Integer n) {
api_check(L, ttistable(t), "table expected");
h = hvalue(t);
if (ttisLtable(t)) {
setobj2s(L, L->top, luaH_getint(hvalue(t), n));
setobj2s(L, L->top, luaH_getint(h, n));
}
else if (ttisfarray(t)) {
if (n <= raviH_getn(h)) { raviH_get_float_inline(L, h, n, L->top); }
@ -782,13 +784,11 @@ LUA_API int lua_rawgeti (lua_State *L, int idx, lua_Integer n) {
LUA_API int lua_rawgetp (lua_State *L, int idx, const void *p) {
StkId t;
TValue k;
Table *h;
lua_lock(L);
t = index2addr(L, idx);
api_check(L, ttisLtable(t), "Lua table expected");
h = hvalue(t);
setpvalue(&k, cast(void *, p));
setobj2s(L, L->top, luaH_get(h, &k));
setobj2s(L, L->top, luaH_get(hvalue(t), &k));
api_incr_top(L);
lua_unlock(L);
return ttnov(L->top - 1);
@ -1019,11 +1019,13 @@ LUA_API void lua_seti (lua_State *L, int idx, lua_Integer n) {
if (ttisLtable(t) || !ttistable(t)) {
if (luaV_fastgeti(L, t, n, slot)) {
luaV_finishfastset(L, t, slot, L->top - 1);
L->top--; /* pop value */
}
else {
TValue aux;
setivalue(&aux, n);
luaV_finishset(L, t, &aux, L->top - 1, slot);
setivalue(L->top, n);
api_incr_top(L);
luaV_finishset(L, t, L->top - 1, L->top - 2, slot);
L->top -= 2; /* pop value and key */
}
}
else {
@ -1051,8 +1053,8 @@ LUA_API void lua_seti (lua_State *L, int idx, lua_Integer n) {
luaG_runerror(L, "value cannot be converted to integer");
}
}
L->top--; /* pop value */
}
L->top--; /* pop value */
lua_unlock(L);
}
@ -1060,19 +1062,18 @@ LUA_API void lua_seti (lua_State *L, int idx, lua_Integer n) {
LUA_API void lua_rawset (lua_State *L, int idx) {
StkId o;
TValue *slot;
Table *t;
lua_lock(L);
api_checknelems(L, 2);
o = index2addr(L, idx);
api_check(L, ttistable(o), "table expected");
t = hvalue(o);
if (ttisLtable(o)) {
slot = luaH_set(L, t, L->top - 2);
slot = luaH_set(L, hvalue(o), L->top - 2);
setobj2t(L, slot, L->top - 1);
invalidateTMcache(t);
luaC_barrierback(L, t, L->top - 1);
invalidateTMcache(hvalue(o));
luaC_barrierback(L, hvalue(o), L->top - 1);
}
else if (ttisfarray(o)) {
Table *t = hvalue(o);
TValue *key = L->top - 2;
TValue *val = L->top - 1;
if (!ttisinteger(key)) luaG_typeerror(L, key, "index");
@ -1092,6 +1093,7 @@ LUA_API void lua_rawset (lua_State *L, int idx) {
}
}
else {
Table *t = hvalue(o);
TValue *key = L->top - 2;
TValue *val = L->top - 1;
if (!ttisinteger(key)) luaG_typeerror(L, key, "index");
@ -1114,17 +1116,16 @@ LUA_API void lua_rawset (lua_State *L, int idx) {
LUA_API void lua_rawseti (lua_State *L, int idx, lua_Integer n) {
StkId o;
Table *t;
lua_lock(L);
api_checknelems(L, 1);
o = index2addr(L, idx);
api_check(L, ttistable(o), "table expected");
t = hvalue(o);
if (ttisLtable(o)) {
luaH_setint(L, t, n, L->top - 1);
luaC_barrierback(L, t, L->top - 1);
luaH_setint(L, hvalue(o), n, L->top - 1);
luaC_barrierback(L, hvalue(o), L->top - 1);
}
else if (ttisfarray(o)) {
Table *t = hvalue(o);
TValue *val = L->top - 1;
if (ttisfloat(val)) { raviH_set_float_inline(L, t, n, fltvalue(val)); }
else if (ttisinteger(val)) {
@ -1138,6 +1139,7 @@ LUA_API void lua_rawseti (lua_State *L, int idx, lua_Integer n) {
}
}
else {
Table *t = hvalue(o);
TValue *val = L->top - 1;
if (ttisinteger(val)) { raviH_set_int_inline(L, t, n, ivalue(val)); }
else {
@ -1154,17 +1156,15 @@ LUA_API void lua_rawseti (lua_State *L, int idx, lua_Integer n) {
LUA_API void lua_rawsetp (lua_State *L, int idx, const void *p) {
StkId o;
Table *t;
TValue k, *slot;
lua_lock(L);
api_checknelems(L, 1);
o = index2addr(L, idx);
api_check(L, ttisLtable(o), "table expected");
t = hvalue(o);
setpvalue(&k, cast(void *, p));
slot = luaH_set(L, t, &k);
slot = luaH_set(L, hvalue(o), &k);
setobj2t(L, slot, L->top - 1);
luaC_barrierback(L, t, L->top - 1);
luaC_barrierback(L, hvalue(o), L->top - 1);
L->top--;
lua_unlock(L);
}
@ -1341,6 +1341,7 @@ LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data,
return status;
}
LUA_API int lua_dump (lua_State *L, lua_Writer writer, void *data, int strip) {
int status;
TValue *o;

@ -1,5 +1,5 @@
/*
** $Id: lauxlib.c,v 1.289 2016/12/20 18:37:00 roberto Exp $
** $Id: lauxlib.c,v 1.289.1.1 2017/04/19 17:20:42 roberto Exp $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
@ -760,6 +760,7 @@ LUALIB_API int luaL_loadbufferx (lua_State *L, const char *buff, size_t size,
return lua_load(L, getS, &ls, name, mode);
}
LUALIB_API int luaL_loadstring (lua_State *L, const char *s) {
return luaL_loadbuffer(L, s, strlen(s), s);
}
@ -1080,66 +1081,3 @@ LUALIB_API int (raviL_dumpast) (lua_State *L) {
return 0;
}
#if 0
/* The normal Lua metatable functions in C use string
keys - these are expensive as the key needs to be
converted to Lua string, hash code computed etc.
Following implementations are taken from a post in
Lua mailing list (http://lua-users.org/lists/lua-l/2010-11/msg00151.html)
They use lightuserdata instead of strings to speed
things up
meta_key is the key assigned to the meta
table of the userdata */
LUALIB_API int raviL_newmetatable(lua_State *L, const void *meta_key, const char *tname) {
lua_pushlightuserdata(L, (void *)meta_key);
lua_rawget(L, LUA_REGISTRYINDEX);
if (!lua_isnil(L, -1)) { /* name already in use? */
return 0; /* leave previous value on top, but return 0 */
}
lua_pop(L, 1); /* pop the nil value */
lua_createtable(L, 0, 2); /* create metatable */
lua_pushstring(L, tname);
lua_setfield(L, -2, "__name"); /* metatable.__name = tname */
lua_pushlightuserdata(L, (void *)meta_key); /* meta_key */
lua_pushvalue(L, -2); /* table */
lua_rawset(L, LUA_REGISTRYINDEX); /* assign table to meta_key in the registry */
return 1;
}
/* meta_key is the key assigned to the meta table of the userdata */
LUALIB_API void raviL_getmetatable(lua_State *L, const void *meta_key) {
lua_pushlightuserdata(L, (void *)meta_key); /* meta_key */
lua_rawget(L, LUA_REGISTRYINDEX); /* obtain the value associated with
meta_key from registry */
}
/* arg_index is the position of userdata argument on the stack
meta_key is the key assigned to the meta table of the userdata */
LUALIB_API void *raviL_testudata(lua_State *L, int arg_index,
const void *meta_key) {
void *p = lua_touserdata(L, arg_index);
if (p != NULL) { /* value is a userdata? */
if (lua_getmetatable(L, arg_index)) { /* does it have a metatable? */
lua_pushlightuserdata(L, (void *)meta_key); /* meta_key */
lua_rawget(
L,
LUA_REGISTRYINDEX); /* get correct metatable associated with meta_key */
if (!lua_rawequal(L, -1, -2)) /* compare: does it have the correct mt? */
p = NULL;
lua_pop(L, 2); /* remove both metatables */
}
}
return p; /* to avoid warnings */
}
/* arg_index is the position of userdata argument on the stack
meta_key is the key assigned to the meta table of the userdata */
LUALIB_API void *raviL_checkudata(lua_State *L, int arg_index,
const void *meta_key) {
void *p = raviL_testudata(L, arg_index, meta_key);
if (p == NULL)
luaL_argerror(L, arg_index, meta_key);
return p;
}
#endif

@ -1,5 +1,5 @@
/*
** $Id: lbaselib.c,v 1.314 2016/09/05 19:06:34 roberto Exp $
** $Id: lbaselib.c,v 1.314.1.1 2017/04/19 17:39:34 roberto Exp $
** Basic library
** See Copyright Notice in lua.h
*/
@ -355,7 +355,6 @@ static int luaB_load (lua_State *L) {
return load_aux(L, status, env);
}
/* }====================================================== */

@ -1,5 +1,5 @@
/*
** $Id: lbitlib.c,v 1.30 2015/11/11 19:08:09 roberto Exp $
** $Id: lbitlib.c,v 1.30.1.1 2017/04/19 17:20:42 roberto Exp $
** Standard library for bitwise operations
** See Copyright Notice in lua.h
*/

@ -1,5 +1,5 @@
/*
** $Id: lcode.c,v 2.112 2016/12/22 13:08:50 roberto Exp $
** $Id: lcode.c,v 2.112.1.1 2017/04/19 17:20:42 roberto Exp $
** Code generator for Lua
** See Copyright Notice in lua.h
*/
@ -601,16 +601,16 @@ void luaK_dischargevars (FuncState *fs, expdesc *e) {
/* TODO we should do this for upvalues too */
/* table access - set specialized op codes if array types are detected */
if (e->ravi_type == RAVI_TARRAYFLT && e->u.ind.key_ravi_type == RAVI_TNUMINT)
op = OP_RAVI_GETTABLE_AF;
op = OP_RAVI_FARRAY_GET;
else if (e->ravi_type == RAVI_TARRAYINT && e->u.ind.key_ravi_type == RAVI_TNUMINT)
op = OP_RAVI_GETTABLE_AI;
op = OP_RAVI_IARRAY_GET;
/* Check that we have a short string constant */
else if (e->ravi_type == RAVI_TTABLE && e->u.ind.key_ravi_type == RAVI_TSTRING && isshortstr(fs, e->u.ind.idx))
op = OP_RAVI_GETTABLE_S;
else if (/* e->ravi_type == RAVI_TTABLE &&*/ e->u.ind.key_ravi_type == RAVI_TNUMINT)
op = OP_RAVI_GETTABLE_I;
op = OP_RAVI_TABLE_GETFIELD;
else if (e->u.ind.key_ravi_type == RAVI_TNUMINT)
op = OP_RAVI_GETI;
else if (e->u.ind.key_ravi_type == RAVI_TSTRING && isshortstr(fs, e->u.ind.idx))
op = OP_RAVI_GETTABLE_SK;
op = OP_RAVI_GETFIELD;
else
op = OP_GETTABLE;
if (e->ravi_type == RAVI_TARRAYFLT || e->ravi_type == RAVI_TARRAYINT)
@ -687,10 +687,10 @@ static void discharge2reg (FuncState *fs, expdesc *e, int reg) {
luaK_codeABC(fs, OP_RAVI_MOVEF, reg, e->u.info, 0);
break;
case RAVI_TARRAYINT:
luaK_codeABC(fs, OP_RAVI_MOVEAI, reg, e->u.info, 0);
luaK_codeABC(fs, OP_RAVI_MOVEIARRAY, reg, e->u.info, 0);
break;
case RAVI_TARRAYFLT:
luaK_codeABC(fs, OP_RAVI_MOVEAF, reg, e->u.info, 0);
luaK_codeABC(fs, OP_RAVI_MOVEFARRAY, reg, e->u.info, 0);
break;
case RAVI_TTABLE:
luaK_codeABC(fs, OP_RAVI_MOVETAB, reg, e->u.info, 0);
@ -869,7 +869,7 @@ static void check_valid_store(FuncState *fs, expdesc *var, expdesc *ex) {
var->ravi_type == RAVI_TSTRING ||
var->ravi_type == RAVI_TFUNCTION ||
var->ravi_type == RAVI_TUSERDATA)) {
/* handled by MOVEI, MOVEF, MOVEAI, MOVEAF at runtime */
/* handled by MOVEI, MOVEF, MOVEIARRAY, MOVEFARRAY at runtime */
return;
}
if (var->ravi_type == RAVI_TNUMFLT) {
@ -951,9 +951,9 @@ static OpCode check_valid_setupval(FuncState *fs, expdesc *var, expdesc *ex,
else if (var->ravi_type == RAVI_TNUMFLT)
op = OP_RAVI_SETUPVALF;
else if (var->ravi_type == RAVI_TARRAYINT)
op = OP_RAVI_SETUPVALAI;
op = OP_RAVI_SETUPVAL_IARRAY;
else if (var->ravi_type == RAVI_TARRAYFLT)
op = OP_RAVI_SETUPVALAF;
op = OP_RAVI_SETUPVAL_FARRAY;
else if (var->ravi_type == RAVI_TTABLE)
op = OP_RAVI_SETUPVALT;
else if (var->ravi_type == RAVI_TSTRING)
@ -998,28 +998,28 @@ void luaK_storevar (FuncState *fs, expdesc *var, expdesc *ex) {
var->u.ind.key_ravi_type == RAVI_TNUMINT) {
if (!(ex->ravi_type == RAVI_TNUMFLT || (ex->k == VINDEXED && ex->ravi_type == RAVI_TARRAYFLT)))
/* input value may need conversion */
op = OP_RAVI_SETTABLE_AF;
op = OP_RAVI_FARRAY_SET;
else
/* input value is known to be number */
op = OP_RAVI_SETTABLE_AFF;
op = OP_RAVI_FARRAY_SETF;
} else if (var->ravi_type == RAVI_TARRAYINT &&
var->u.ind.key_ravi_type == RAVI_TNUMINT) {
if (!(ex->ravi_type == RAVI_TNUMINT || (ex->k == VINDEXED && ex->ravi_type == RAVI_TARRAYINT)))
/* input value may need conversion */
op = OP_RAVI_SETTABLE_AI;
op = OP_RAVI_IARRAY_SET;
else
/* input value is known to be integer */
op = OP_RAVI_SETTABLE_AII;
} else if (/* var->ravi_type == RAVI_TTABLE &&*/ var->u.ind.key_ravi_type == RAVI_TNUMINT) {
/* table with integer key */
op = OP_RAVI_SETTABLE_I;
op = OP_RAVI_IARRAY_SETI;
} else if (var->u.ind.key_ravi_type == RAVI_TNUMINT) {
/* index op with integer key, target may not be a table */
op = OP_RAVI_SETI;
} else if (var->ravi_type == RAVI_TTABLE && var->u.ind.key_ravi_type == RAVI_TSTRING && isshortstr(fs, var->u.ind.idx)) {
/* table with string key */
op = OP_RAVI_SETTABLE_S;
op = OP_RAVI_TABLE_SETFIELD;
}
else if (var->u.ind.key_ravi_type == RAVI_TSTRING && isshortstr(fs, var->u.ind.idx)) {
/* table with string key */
op = OP_RAVI_SETTABLE_SK;
/* index op with string key, target may not be a table */
op = OP_RAVI_SETFIELD;
}
}
int e = luaK_exp2RK(fs, ex);
@ -1041,7 +1041,7 @@ void luaK_self (FuncState *fs, expdesc *e, expdesc *key) {
If we only know the key is a string constant
we emit specialized bytecode OP_RAVI_SELF_SK
If we also know that the variable is a table
then we emit OP_RAVI_SELF_S
then we emit OP_RAVI_TABLE_SELF_SK
*/
int is_string_constant_key =
key->k == VK &&
@ -1058,7 +1058,9 @@ void luaK_self (FuncState *fs, expdesc *e, expdesc *key) {
e->u.info = fs->freereg; /* base register for op_self */
e->k = VNONRELOC; /* self expression has a fixed register */
luaK_reserveregs(fs, 2); /* function and 'self' produced by op_self */
luaK_codeABC(fs, table_and_string ? OP_RAVI_SELF_S : (is_string_constant_key ? OP_RAVI_SELF_SK : OP_SELF), e->u.info, ereg, luaK_exp2RK(fs, key));
luaK_codeABC(fs, table_and_string ? OP_RAVI_TABLE_SELF_SK :
(is_string_constant_key ? OP_RAVI_SELF_SK : OP_SELF),
e->u.info, ereg, luaK_exp2RK(fs, key));
freeexp(fs, key);
}
@ -1499,26 +1501,26 @@ static void code_type_assertion(FuncState *fs, UnOpr op, expdesc *e, TString *us
if (e->ravi_type == RAVI_TTABLE && e->pc >= 0) {
Instruction *i = &fs->f->code[e->pc];
if (GET_OPCODE(*i) == OP_NEWTABLE) {
SET_OPCODE(*i, OP_RAVI_NEWARRAYI);
SET_OPCODE(*i, OP_RAVI_NEW_IARRAY);
e->ravi_type = RAVI_TARRAYINT;
DEBUG_EXPR(raviY_printf(fs, "code_type_assertion (OP_NEWTABLE to OP_RAVI_NEWARRAYI) %e\n", e));
DEBUG_EXPR(raviY_printf(fs, "code_type_assertion (OP_NEWTABLE to OP_RAVI_NEW_IARRAY) %e\n", e));
}
return;
}
opcode = OP_RAVI_TOARRAYI;
opcode = OP_RAVI_TOIARRAY;
tt = RAVI_TARRAYINT;
}
else if (op == OPR_TO_NUMARRAY && e->ravi_type != RAVI_TARRAYFLT) {
if (e->ravi_type == RAVI_TTABLE && e->pc >= 0) {
Instruction *i = &fs->f->code[e->pc];
if (GET_OPCODE(*i) == OP_NEWTABLE) {
SET_OPCODE(*i, OP_RAVI_NEWARRAYF);
SET_OPCODE(*i, OP_RAVI_NEW_FARRAY);
e->ravi_type = RAVI_TARRAYFLT;
DEBUG_EXPR(raviY_printf(fs, "code_type_assertion (OP_NEWTABLE to OP_RAVI_NEWARRAYI) %e\n", e));
DEBUG_EXPR(raviY_printf(fs, "code_type_assertion (OP_NEWTABLE to OP_RAVI_NEW_IARRAY) %e\n", e));
}
return;
}
opcode = OP_RAVI_TOARRAYF;
opcode = OP_RAVI_TOFARRAY;
tt = RAVI_TARRAYFLT;
}
else if (op == OPR_TO_TABLE && e->ravi_type != RAVI_TTABLE) {

@ -1,5 +1,5 @@
/*
** $Id: lcorolib.c,v 1.10 2016/04/11 19:19:55 roberto Exp $
** $Id: lcorolib.c,v 1.10.1.1 2017/04/19 17:20:42 roberto Exp $
** Coroutine Library
** See Copyright Notice in lua.h
*/

@ -1,5 +1,5 @@
/*
** $Id: lctype.c,v 1.12 2014/11/02 19:19:04 roberto Exp $
** $Id: lctype.c,v 1.12.1.1 2017/04/19 17:20:42 roberto Exp $
** 'ctype' functions for Lua
** See Copyright Notice in lua.h
*/

@ -1,5 +1,5 @@
/*
** $Id: ldblib.c,v 1.151 2015/11/23 11:29:43 roberto Exp $
** $Id: ldblib.c,v 1.151.1.1 2017/04/19 17:20:42 roberto Exp $
** Interface from Lua to its debug API
** See Copyright Notice in lua.h
*/

@ -1,5 +1,5 @@
/*
** $Id: ldebug.c,v 2.121 2016/10/19 12:32:10 roberto Exp $
** $Id: ldebug.c,v 2.121.1.2 2017/07/10 17:21:50 roberto Exp $
** Debug Interface
** See Copyright Notice in lua.h
*/
@ -468,8 +468,8 @@ static const char *getobjname (Proto *p, int lastpc, int reg,
switch (op) {
case OP_RAVI_MOVEI:
case OP_RAVI_MOVEF:
case OP_RAVI_MOVEAF:
case OP_RAVI_MOVEAI:
case OP_RAVI_MOVEFARRAY:
case OP_RAVI_MOVEIARRAY:
case OP_RAVI_MOVETAB:
case OP_MOVE: {
int b = GETARG_B(i); /* move from 'b' to 'a' */
@ -477,11 +477,11 @@ static const char *getobjname (Proto *p, int lastpc, int reg,
return getobjname(p, pc, b, name); /* get name for 'b' */
break;
}
case OP_RAVI_GETTABLE_I:
case OP_RAVI_GETTABLE_S:
case OP_RAVI_GETTABLE_SK:
case OP_RAVI_GETTABLE_AI:
case OP_RAVI_GETTABLE_AF:
case OP_RAVI_GETI:
case OP_RAVI_TABLE_GETFIELD:
case OP_RAVI_GETFIELD:
case OP_RAVI_IARRAY_GET:
case OP_RAVI_FARRAY_GET:
case OP_GETTABUP:
case OP_RAVI_GETTABUP_SK:
case OP_GETTABLE: {
@ -508,7 +508,7 @@ static const char *getobjname (Proto *p, int lastpc, int reg,
break;
}
case OP_RAVI_SELF_SK:
case OP_RAVI_SELF_S:
case OP_RAVI_TABLE_SELF_SK:
case OP_SELF: {
int k = GETARG_C(i); /* key index */
kname(p, pc, k, name);
@ -546,12 +546,12 @@ static const char *funcnamefromcode (lua_State *L, CallInfo *ci,
return "for iterator";
}
/* all other instructions can call only through metamethods */
/* Ravi: added GETTABLE_SK and SELF_SK because the call may be through metamethod rather than table */
/* Ravi: added GETFIELD and SELF_SK because the call may be through metamethod rather than table */
case OP_SELF: case OP_GETTABUP: case OP_GETTABLE:
case OP_RAVI_SELF_SK: case OP_RAVI_GETTABUP_SK: case OP_RAVI_GETTABLE_SK: case OP_RAVI_GETTABLE_I:
case OP_RAVI_SELF_SK: case OP_RAVI_GETTABUP_SK: case OP_RAVI_GETFIELD: case OP_RAVI_GETI:
tm = TM_INDEX;
break;
case OP_SETTABUP: case OP_SETTABLE: case OP_RAVI_SETTABLE_SK: case OP_RAVI_SETTABLE_I:
case OP_SETTABUP: case OP_SETTABLE: case OP_RAVI_SETFIELD: case OP_RAVI_SETI:
tm = TM_NEWINDEX;
break;
case OP_ADD: case OP_SUB: case OP_MUL: case OP_MOD:

@ -1,5 +1,5 @@
/*
** $Id: ldo.c,v 2.157 2016/12/13 15:52:21 roberto Exp $
** $Id: ldo.c,v 2.157.1.1 2017/04/19 17:20:42 roberto Exp $
** Stack and Call structure of Lua
** See Copyright Notice in lua.h
*/

@ -1,5 +1,5 @@
/*
** $Id: ldump.c,v 2.37 2015/10/08 15:53:49 roberto Exp $
** $Id: ldump.c,v 2.37.1.1 2017/04/19 17:20:42 roberto Exp $
** save precompiled Lua chunks
** See Copyright Notice in lua.h
*/

File diff suppressed because it is too large Load Diff

@ -1,5 +1,5 @@
/*
** $Id: linit.c,v 1.39 2016/12/04 20:17:24 roberto Exp $
** $Id: linit.c,v 1.39.1.1 2017/04/19 17:20:42 roberto Exp $
** Initialization of libraries for lua.c and other clients
** See Copyright Notice in lua.h
*/

@ -1,5 +1,5 @@
/*
** $Id: liolib.c,v 2.151 2016/12/20 18:37:00 roberto Exp $
** $Id: liolib.c,v 2.151.1.1 2017/04/19 17:29:57 roberto Exp $
** Standard I/O (and system) library
** See Copyright Notice in lua.h
*/
@ -206,11 +206,16 @@ static int aux_close (lua_State *L) {
}
static int f_close (lua_State *L) {
tofile(L); /* make sure argument is an open stream */
return aux_close(L);
}
static int io_close (lua_State *L) {
if (lua_isnone(L, 1)) /* no argument? */
lua_getfield(L, LUA_REGISTRYINDEX, IO_OUTPUT); /* use standard output */
tofile(L); /* make sure argument is an open stream */
return aux_close(L);
return f_close(L);
}
@ -713,7 +718,7 @@ static const luaL_Reg iolib[] = {
** methods for file handles
*/
static const luaL_Reg flib[] = {
{"close", io_close},
{"close", f_close},
{"flush", f_flush},
{"lines", f_lines},
{"read", f_read},

@ -1,5 +1,5 @@
/*
** $Id: llex.c,v 2.96 2016/05/02 14:02:12 roberto Exp $
** $Id: llex.c,v 2.96.1.1 2017/04/19 17:20:42 roberto Exp $
** Lexical Analyzer
** See Copyright Notice in lua.h
*/

@ -1,5 +1,5 @@
/*
** $Id: lmathlib.c,v 1.119 2016/12/22 13:08:50 roberto Exp $
** $Id: lmathlib.c,v 1.119.1.1 2017/04/19 17:20:42 roberto Exp $
** Standard mathematical library
** See Copyright Notice in lua.h
*/

@ -1,5 +1,5 @@
/*
** $Id: lmem.c,v 1.91 2015/03/06 19:45:54 roberto Exp $
** $Id: lmem.c,v 1.91.1.1 2017/04/19 17:20:42 roberto Exp $
** Interface to Memory Manager
** See Copyright Notice in lua.h
*/

@ -1,5 +1,5 @@
/*
** $Id: loadlib.c,v 1.130 2017/01/12 17:14:26 roberto Exp $
** $Id: loadlib.c,v 1.130.1.1 2017/04/19 17:20:42 roberto Exp $
** Dynamic library loader for Lua
** See Copyright Notice in lua.h
**

@ -1,5 +1,5 @@
/*
** $Id: lobject.c,v 2.113 2016/12/22 13:08:50 roberto Exp $
** $Id: lobject.c,v 2.113.1.1 2017/04/19 17:29:57 roberto Exp $
** Some generic functions over Lua objects
** See Copyright Notice in lua.h
*/
@ -435,7 +435,8 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) {
}
case 'p': { /* a pointer */
char buff[4*sizeof(void *) + 8]; /* should be enough space for a '%p' */
int l = l_sprintf(buff, sizeof(buff), "%p", va_arg(argp, void *));
void *p = va_arg(argp, void *);
int l = lua_pointer2str(buff, sizeof(buff), p);
pushstr(L, buff, l);
break;
}

@ -1,5 +1,5 @@
/*
** $Id: lopcodes.c,v 1.55 2015/01/05 13:48:33 roberto Exp $
** $Id: lopcodes.c,v 1.55.1.1 2017/04/19 17:20:42 roberto Exp $
** Opcodes for Lua virtual machine
** See Copyright Notice in lua.h
*/
@ -78,8 +78,8 @@ LUAI_DDEF const char *const luaP_opnames[NUM_OPCODES+1] = {
"VARARG",
"EXTRAARG",
"NEWARRAYI", /* A R(A) := array of int */
"NEWARRAYF", /* A R(A) := array of float */
"NEW_IARRAY", /* A R(A) := array of int */
"NEW_FARRAY", /* A R(A) := array of float */
"LOADIZ", /* A R(A) := tointeger(0) */
"LOADFZ", /* A R(A) := tonumber(0) */
@ -107,8 +107,8 @@ LUAI_DDEF const char *const luaP_opnames[NUM_OPCODES+1] = {
"TOINT", /* A R(A) := toint(R(A)) */
"TOFLT", /* A R(A) := tofloat(R(A)) */
"TOARRAYI", /* A R(A) := to_arrayi(R(A)) */
"TOARRAYF", /* A R(A) := to_arrayf(R(A)) */
"TOIARRAY", /* A R(A) := to_arrayi(R(A)) */
"TOFARRAY", /* A R(A) := to_arrayf(R(A)) */
"TOTAB", /* A R(A) := to_table(R(A)) */
"TOSTRING",
"TOCLOSURE",
@ -116,17 +116,17 @@ LUAI_DDEF const char *const luaP_opnames[NUM_OPCODES+1] = {
"MOVEI", /* A B R(A) := R(B) */
"MOVEF", /* A B R(A) := R(B) */
"MOVEAI", /* A B R(A) := R(B), check R(B) is array of int */
"MOVEAF", /* A B R(A) := R(B), check R(B) is array of floats */
"MOVEIARRAY", /* A B R(A) := R(B), check R(B) is array of int */
"MOVEFARRAY", /* A B R(A) := R(B), check R(B) is array of floats */
"MOVETAB", /* A B R(A) := R(B), check R(B) is a table */
"GETTABLE_AI",/* A B C R(A) := R(B)[RK(C)] where R(B) is array of integers and RK(C) is int */
"GETTABLE_AF",/* A B C R(A) := R(B)[RK(C)] where R(B) is array of floats and RK(C) is int */
"IARRAY_GET",/* A B C R(A) := R(B)[RK(C)] where R(B) is array of integers and RK(C) is int */
"FARRAY_GET",/* A B C R(A) := R(B)[RK(C)] where R(B) is array of floats and RK(C) is int */
"SETTABLE_AI",/* A B C R(A)[RK(B)] := RK(C) where RK(B) is an int, R(A) is array of ints, and RK(C) is an int */
"SETTABLE_AF",/* A B C R(A)[RK(B)] := RK(C) where RK(B) is an int, R(A) is array of floats, and RK(C) is an float */
"SETTABLE_AII",/* A B C R(A)[RK(B)] := RK(C) where RK(B) is an int, R(A) is array of ints, and RK(C) is an int */
"SETTABLE_AFF",/* A B C R(A)[RK(B)] := RK(C) where RK(B) is an int, R(A) is array of floats, and RK(C) is an float */
"IARRAY_SET",/* A B C R(A)[RK(B)] := RK(C) where RK(B) is an int, R(A) is array of ints, and RK(C) is an int */
"FARRAY_SET",/* A B C R(A)[RK(B)] := RK(C) where RK(B) is an int, R(A) is array of floats, and RK(C) is an float */
"IARRAY_SETI",/* A B C R(A)[RK(B)] := RK(C) where RK(B) is an int, R(A) is array of ints, and RK(C) is an int */
"FARRAY_SETF",/* A B C R(A)[RK(B)] := RK(C) where RK(B) is an int, R(A) is array of floats, and RK(C) is an float */
"FORLOOP_IP",
"FORLOOP_I1",
@ -135,8 +135,8 @@ LUAI_DDEF const char *const luaP_opnames[NUM_OPCODES+1] = {
"SETUPVALI", /* A B UpValue[B] := tointeger(R(A)) */
"SETUPVALF", /* A B UpValue[B] := tonumber(R(A)) */
"SETUPVALAI", /* A B UpValue[B] := toarrayint(R(A)) */
"SETUPVALAF", /* A B UpValue[B] := toarrayflt(R(A)) */
"SETUPVAL_IARRAY", /* A B UpValue[B] := toarrayint(R(A)) */
"SETUPVAL_FARRAY", /* A B UpValue[B] := toarrayflt(R(A)) */
"SETUPVALT", /* A B UpValue[B] := to_table(R(A)) */
"BAND_II",/* A B C R(A) := RK(B) & RK(C) */
@ -153,15 +153,15 @@ LUAI_DDEF const char *const luaP_opnames[NUM_OPCODES+1] = {
"LE_II", /* A B C if ((RK(B) <= RK(C)) ~= A) then pc++ */
"LE_FF", /* A B C if ((RK(B) <= RK(C)) ~= A) then pc++ */
"GETTABLE_S", /* A B C R(A) := R(B)[RK(C)], string key */
"SETTABLE_S", /* A B C R(A)[RK(B)] := RK(C), string key */
"SELF_S", /* A B C R(A+1) := R(B); R(A) := R(B)[RK(C)] */
"TABLE_GETFIELD", /* A B C R(A) := R(B)[RK(C)], string key */
"TABLE_SETFIELD", /* A B C R(A)[RK(B)] := RK(C), string key */
"TABLE_SELF_SK", /* A B C R(A+1) := R(B); R(A) := R(B)[RK(C)] */
"GETTABLE_I", /* A B C R(A) := R(B)[RK(C)], integer key */
"SETTABLE_I", /* A B C R(A)[RK(B)] := RK(C), integer key */
"GETTABLE_SK", /* _SK */ /* A B C R(A) := R(B)[RK(C)], string key */
"GETI", /* A B C R(A) := R(B)[RK(C)], integer key */
"SETI", /* A B C R(A)[RK(B)] := RK(C), integer key */
"GETFIELD", /* _SK */ /* A B C R(A) := R(B)[RK(C)], string key */
"SELF_SK", /* _SK*/ /* A B C R(A+1) := R(B); R(A) := R(B)[RK(C)] */
"SETTABLE_SK", /*_SK */ /* A B C R(A)[RK(B)] := RK(C), string key */
"SETFIELD", /*_SK */ /* A B C R(A)[RK(B)] := RK(C), string key */
"GETTABUP_SK",
NULL
};
@ -219,8 +219,8 @@ LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = {
,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_VARARG */
,opmode(0, 0, OpArgU, OpArgU, iAx) /* OP_EXTRAARG */
,opmode(0, 1, OpArgN, OpArgN, iABC) /* OP_RAVI_NEWARRAYI A R(A) := array of int */
,opmode(0, 1, OpArgN, OpArgN, iABC) /* OP_RAVI_NEWARRAYF A R(A) := array of float */
,opmode(0, 1, OpArgN, OpArgN, iABC) /* OP_RAVI_NEW_IARRAY A R(A) := array of int */
,opmode(0, 1, OpArgN, OpArgN, iABC) /* OP_RAVI_NEW_FARRAY A R(A) := array of float */
,opmode(0, 1, OpArgN, OpArgN, iABC) /* OP_RAVI_LOADIZ A R(A) := tointeger(0) */
,opmode(0, 1, OpArgN, OpArgN, iABC) /* OP_RAVI_LOADFZ A R(A) := tonumber(0) */
@ -248,8 +248,8 @@ LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = {
,opmode(0, 1, OpArgN, OpArgN, iABC) /* OP_RAVI_TOINT A R(A) := toint(R(A)) */
,opmode(0, 1, OpArgN, OpArgN, iABC) /* OP_RAVI_TOFLT A R(A) := tonumber(R(A)) */
,opmode(0, 1, OpArgN, OpArgN, iABC) /* OP_RAVI_TOARRAYI A R(A) := check_array_of_int(R(A)) */
,opmode(0, 1, OpArgN, OpArgN, iABC) /* OP_RAVI_TOARRAYF A R(A) := check_array_of_float(R(A)) */
,opmode(0, 1, OpArgN, OpArgN, iABC) /* OP_RAVI_TOIARRAY A R(A) := check_array_of_int(R(A)) */
,opmode(0, 1, OpArgN, OpArgN, iABC) /* OP_RAVI_TOFARRAY A R(A) := check_array_of_float(R(A)) */
,opmode(0, 1, OpArgN, OpArgN, iABC) /* OP_RAVI_TOTAB A R(A) := check_table(R(A)) */
,opmode(0, 1, OpArgN, OpArgN, iABC) /* OP_RAVI_TOSTRING */
,opmode(0, 1, OpArgN, OpArgN, iABC) /* OP_RAVI_TOCLOSURE */
@ -257,17 +257,17 @@ LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = {
,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_RAVI_MOVEI A B R(A) := tointeger(R(B)) */
,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_RAVI_MOVEF A B R(A) := tonumber(R(B)) */
,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_RAVI_MOVEAI A B R(A) := R(B), check R(B) is array of int */
,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_RAVI_MOVEAF A B R(A) := R(B), check R(B) is array of floats */
,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_RAVI_MOVEIARRAY A B R(A) := R(B), check R(B) is array of int */
,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_RAVI_MOVEFARRAY A B R(A) := R(B), check R(B) is array of floats */
,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_RAVI_MOVETAB A B R(A) := R(B), check R(B) is a table */
,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_RAVI_GETTABLE_AI A B C R(A) := R(B)[RK(C)] where R(B) is array of integers and RK(C) is int */
,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_RAVI_GETTABLE_AF A B C R(A) := R(B)[RK(C)] where R(B) is array of floats and RK(C) is int */
,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_RAVI_IARRAY_GET A B C R(A) := R(B)[RK(C)] where R(B) is array of integers and RK(C) is int */
,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_RAVI_FARRAY_GET A B C R(A) := R(B)[RK(C)] where R(B) is array of floats and RK(C) is int */
,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_RAVI_SETTABLE_AI A B C R(A)[RK(B)] := RK(C) where RK(B) is an int, R(A) is array of ints, and RK(C) is an int */
,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_RAVI_SETTABLE_AF A B C R(A)[RK(B)] := RK(C) where RK(B) is an int, R(A) is array of floats, and RK(C) is an float */
,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_RAVI_SETTABLE_AII A B C R(A)[RK(B)] := RK(C) where RK(B) is an int, R(A) is array of ints, and RK(C) is an int */
,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_RAVI_SETTABLE_AFF A B C R(A)[RK(B)] := RK(C) where RK(B) is an int, R(A) is array of floats, and RK(C) is an float */
,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_RAVI_IARRAY_SET A B C R(A)[RK(B)] := RK(C) where RK(B) is an int, R(A) is array of ints, and RK(C) is an int */
,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_RAVI_FARRAY_SET A B C R(A)[RK(B)] := RK(C) where RK(B) is an int, R(A) is array of floats, and RK(C) is an float */
,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_RAVI_IARRAY_SETI A B C R(A)[RK(B)] := RK(C) where RK(B) is an int, R(A) is array of ints, and RK(C) is an int */
,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_RAVI_FARRAY_SETF A B C R(A)[RK(B)] := RK(C) where RK(B) is an int, R(A) is array of floats, and RK(C) is an float */
,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_RAVI_FORLOOP_IP */
,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_RAVI_FORLOOP_I1 */
@ -276,8 +276,8 @@ LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = {
,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_RAVI_SETUPVALI */
,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_RAVI_SETUPVALF */
,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_RAVI_SETUPVALAI */
,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_RAVI_SETUPVALAF */
,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_RAVI_SETUPVAL_IARRAY */
,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_RAVI_SETUPVAL_FARRAY */
,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_RAVI_SETUPVALT */
,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_RAVI_BAND_II */
@ -294,15 +294,15 @@ LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = {
,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_RAVI_LE_II */
,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_RAVI_LE_FF */
,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_RAVI_GETTABLE_S */
,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_RAVI_SETTABLE_S */
,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_RAVI_SELF_S */
,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_RAVI_TABLE_GETFIELD */
,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_RAVI_TABLE_SETFIELD */
,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_RAVI_TABLE_SELF_SK */
,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_RAVI_GETTABLE_I */
,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_RAVI_SETTABLE_I */
,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_RAVI_GETTABLE_SK */
,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_RAVI_GETI */
,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_RAVI_SETI */
,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_RAVI_GETFIELD */
,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_RAVI_SELF_SK */
,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_RAVI_SETTABLE_SK */
,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_RAVI_SETFIELD */
,opmode(0, 1, OpArgU, OpArgK, iABC) /* OP_RAVI_GETTABUP_SK */
};
@ -449,8 +449,8 @@ static void PrintCode(const Proto* f)
case OP_GETUPVAL:
case OP_RAVI_SETUPVALI:
case OP_RAVI_SETUPVALF:
case OP_RAVI_SETUPVALAI:
case OP_RAVI_SETUPVALAF:
case OP_RAVI_SETUPVAL_IARRAY:
case OP_RAVI_SETUPVAL_FARRAY:
case OP_RAVI_SETUPVALT:
case OP_SETUPVAL:
printf("\t; %s",UPVALNAME(b));
@ -466,24 +466,24 @@ static void PrintCode(const Proto* f)
if (ISK(c)) { printf(" "); PrintConstant(f,INDEXK(c)); }
break;
case OP_GETTABLE:
case OP_RAVI_GETTABLE_I:
case OP_RAVI_GETTABLE_S:
case OP_RAVI_GETTABLE_AF:
case OP_RAVI_GETTABLE_AI:
case OP_RAVI_GETI:
case OP_RAVI_TABLE_GETFIELD:
case OP_RAVI_FARRAY_GET:
case OP_RAVI_IARRAY_GET:
case OP_SELF:
case OP_RAVI_GETTABLE_SK:
case OP_RAVI_SELF_S:
case OP_RAVI_GETFIELD:
case OP_RAVI_TABLE_SELF_SK:
case OP_RAVI_SELF_SK:
if (ISK(c)) { printf("\t; "); PrintConstant(f,INDEXK(c)); }
break;
case OP_SETTABLE:
case OP_RAVI_SETTABLE_I:
case OP_RAVI_SETTABLE_S:
case OP_RAVI_SETTABLE_SK:
case OP_RAVI_SETTABLE_AF:
case OP_RAVI_SETTABLE_AFF:
case OP_RAVI_SETTABLE_AI:
case OP_RAVI_SETTABLE_AII:
case OP_RAVI_SETI:
case OP_RAVI_TABLE_SETFIELD:
case OP_RAVI_SETFIELD:
case OP_RAVI_FARRAY_SET:
case OP_RAVI_FARRAY_SETF:
case OP_RAVI_IARRAY_SET:
case OP_RAVI_IARRAY_SETI:
case OP_ADD:
case OP_RAVI_ADDFF:
case OP_RAVI_ADDFI:

@ -1,5 +1,5 @@
/*
** $Id: loslib.c,v 1.65 2016/07/18 17:58:58 roberto Exp $
** $Id: loslib.c,v 1.65.1.1 2017/04/19 17:29:57 roberto Exp $
** Standard Operating System library
** See Copyright Notice in lua.h
*/
@ -293,7 +293,8 @@ static int os_date (lua_State *L) {
else
stm = l_localtime(&t, &tmr);
if (stm == NULL) /* invalid date? */
luaL_error(L, "time result cannot be represented in this installation");
return luaL_error(L,
"time result cannot be represented in this installation");
if (strcmp(s, "*t") == 0) {
lua_createtable(L, 0, 9); /* 9 = number of fields */
setallfields(L, stm);
@ -340,7 +341,8 @@ static int os_time (lua_State *L) {
setallfields(L, &ts); /* update fields with normalized values */
}
if (t != (time_t)(l_timet)t || t == (time_t)(-1))
luaL_error(L, "time result cannot be represented in this installation");
return luaL_error(L,
"time result cannot be represented in this installation");
l_pushtime(L, t);
return 1;
}

@ -1,5 +1,5 @@
/*
** $Id: lparser.c,v 2.155 2016/08/01 19:51:24 roberto Exp $
** $Id: lparser.c,v 2.155.1.2 2017/04/29 18:11:40 roberto Exp $
** Lua Parser
** See Copyright Notice in lua.h
*/
@ -584,8 +584,8 @@ static void ravi_code_typecoersion(LexState *ls, int reg, ravitype_t ravi_type,
ravi_type == RAVI_TNUMFLT ? OP_RAVI_TOFLT : OP_RAVI_TOINT, reg,
0, 0);
else if (ravi_type == RAVI_TARRAYINT || ravi_type == RAVI_TARRAYFLT)
luaK_codeABC(ls->fs, ravi_type == RAVI_TARRAYINT ? OP_RAVI_TOARRAYI
: OP_RAVI_TOARRAYF,
luaK_codeABC(ls->fs, ravi_type == RAVI_TARRAYINT ? OP_RAVI_TOIARRAY
: OP_RAVI_TOFARRAY,
reg, 0, 0);
else if (ravi_type == RAVI_TTABLE)
luaK_codeABC(ls->fs, OP_RAVI_TOTAB,
@ -1348,8 +1348,8 @@ static void ravi_typecheck(LexState *ls, expdesc *v, int *var_types,
int reg = GETARG_A(*pc);
if (reg ==
v->u.info) { /* double check that register is as expected */
op = (vartype == RAVI_TARRAYINT) ? OP_RAVI_NEWARRAYI
: OP_RAVI_NEWARRAYF;
op = (vartype == RAVI_TARRAYINT) ? OP_RAVI_NEW_IARRAY
: OP_RAVI_NEW_FARRAY;
SET_OPCODE(*pc, op); /* modify opcode */
DEBUG_CODEGEN(
raviY_printf(ls->fs, "[%d]* %o ; modify opcode\n", v->pc, *pc));
@ -2141,7 +2141,7 @@ static void test_then_block (LexState *ls, int *escapelist) {
luaK_goiffalse(ls->fs, &v); /* will jump to label if condition is true */
enterblock(fs, &bl, 0); /* must enter block before 'goto' */
gotostat(ls, v.t); /* handle goto/break */
skipnoopstat(ls); /* skip other no-op statements */
while (testnext(ls, ';')) {} /* skip colons */
if (block_follow(ls, 0)) { /* 'goto' is the entire block? */
leaveblock(fs);
return; /* and that is it */

@ -1,5 +1,5 @@
/*
** $Id: lstate.c,v 2.133 2015/11/13 12:16:51 roberto Exp $
** $Id: lstate.c,v 2.133.1.1 2017/04/19 17:39:34 roberto Exp $
** Global State
** See Copyright Notice in lua.h
*/

@ -1,5 +1,5 @@
/*
** $Id: lstring.c,v 2.56 2015/11/23 11:32:51 roberto Exp $
** $Id: lstring.c,v 2.56.1.1 2017/04/19 17:20:42 roberto Exp $
** String table (keeps all strings handled by Lua)
** See Copyright Notice in lua.h
*/

@ -1,5 +1,5 @@
/*
** $Id: lstrlib.c,v 1.254 2016/12/22 13:08:50 roberto Exp $
** $Id: lstrlib.c,v 1.259 2017/11/16 13:19:06 roberto Exp roberto $
** Standard library for string operations and pattern-matching
** See Copyright Notice in lua.h
*/
@ -200,6 +200,151 @@ static int str_dump (lua_State *L) {
/*
** {======================================================
** METAMETHODS
** =======================================================
*/
static int tonum (lua_State *L, int arg) {
if (lua_type(L, arg) == LUA_TNUMBER) { /* already a number? */
lua_pushvalue(L, arg);
return 1;
}
else { /* check whether it is a numerical string */
size_t len;
const char *s = lua_tolstring(L, arg, &len);
return (s != NULL && lua_stringtonumber(L, s) == len + 1);
}
}
static int toint (lua_State *L, int arg) {
if (!tonum(L, arg))
return 0; /* not coercible to a number */
else if (lua_isinteger(L, arg))
return 1; /* already an integer */
else { /* a float */
int ok;
lua_Integer n = lua_tointegerx(L, arg, &ok);
if (!ok)
return 0;
else {
lua_pop(L, 1); /* remove the float */
lua_pushinteger(L, n); /* push an integer */
return 1;
}
}
}
static void trymt (lua_State *L, const char *mtname) {
lua_settop(L, 2); /* back to the original arguments */
if (lua_type(L, 2) == LUA_TSTRING || !luaL_getmetafield(L, 2, mtname))
luaL_error(L, "attempt to %s a '%s' with a '%s'", mtname + 2,
luaL_typename(L, -2), luaL_typename(L, -1));
lua_insert(L, -3); /* put metamethod before arguments */
lua_call(L, 2, 1); /* call metamethod */
}
static int arith (lua_State *L, int op, const char *mtname) {
if (tonum(L, 1) && tonum(L, 2))
lua_arith(L, op); /* result will be on the top */
else
trymt(L, mtname);
return 1;
}
static int bitwise (lua_State *L, int op, const char *mtname) {
if (toint(L, 1) && toint(L, 2))
lua_arith(L, op); /* result will be on the top */
else
trymt(L, mtname);
return 1;
}
static int arith_add (lua_State *L) {
return arith(L, LUA_OPADD, "__add");
}
static int arith_sub (lua_State *L) {
return arith(L, LUA_OPSUB, "__sub");
}
static int arith_mul (lua_State *L) {
return arith(L, LUA_OPMUL, "__mul");
}
static int arith_mod (lua_State *L) {
return arith(L, LUA_OPMOD, "__mod");
}
static int arith_pow (lua_State *L) {
return arith(L, LUA_OPPOW, "__pow");
}
static int arith_div (lua_State *L) {
return arith(L, LUA_OPDIV, "__div");
}
static int arith_idiv (lua_State *L) {
return arith(L, LUA_OPIDIV, "__idiv");
}
static int arith_unm (lua_State *L) {
return arith(L, LUA_OPUNM, "__unm");
}
static int bitwise_band (lua_State *L) {
return bitwise(L, LUA_OPBAND, "__band");
}
static int bitwise_bor (lua_State *L) {
return bitwise(L, LUA_OPBOR, "__bor");
}
static int bitwise_bxor (lua_State *L) {
return bitwise(L, LUA_OPBXOR, "__bxor");
}
static int bitwise_shl (lua_State *L) {
return bitwise(L, LUA_OPSHL, "__shl");
}
static int bitwise_shr (lua_State *L) {
return bitwise(L, LUA_OPSHR, "__shr");
}
static int bitwise_bnot (lua_State *L) {
return bitwise(L, LUA_OPBNOT, "__bnot");
}
static const luaL_Reg stringmetamethods[] = {
{"__add", arith_add},
{"__sub", arith_sub},
{"__mul", arith_mul},
{"__mod", arith_mod},
{"__pow", arith_pow},
{"__div", arith_div},
{"__idiv", arith_idiv},
{"__unm", arith_unm},
{"__band", bitwise_band},
{"__bor", bitwise_bor},
{"__bxor", bitwise_bxor},
{"__shl", bitwise_shl},
{"__shr", bitwise_shr},
{"__bnot", bitwise_bnot},
{"__index", NULL}, /* placeholder */
{NULL, NULL}
};
/* }====================================================== */
/*
** {======================================================
** PATTERN MATCHING
@ -851,7 +996,7 @@ static int num2straux (char *buff, int sz, lua_Number x) {
lua_Number m = l_mathop(frexp)(x, &e); /* 'x' fraction and exponent */
int n = 0; /* character count */
if (m < 0) { /* is number negative? */
buff[n++] = '-'; /* add signal */
buff[n++] = '-'; /* add sign */
m = -m; /* make it positive */
}
buff[n++] = '0'; buff[n++] = 'x'; /* add "0x" */
@ -879,7 +1024,7 @@ static int lua_number2strx (lua_State *L, char *buff, int sz,
buff[i] = toupper(uchar(buff[i]));
}
else if (fmt[SIZELENMOD] != 'a')
luaL_error(L, "modifiers for format '%%a'/'%%A' not implemented");
return luaL_error(L, "modifiers for format '%%a'/'%%A' not implemented");
return n;
}
@ -1199,8 +1344,8 @@ static int getnum (const char **fmt, int df) {
static int getnumlimit (Header *h, const char **fmt, int df) {
int sz = getnum(fmt, df);
if (sz > MAXINTSIZE || sz <= 0)
luaL_error(h->L, "integral size (%d) out of limits [1,%d]",
sz, MAXINTSIZE);
return luaL_error(h->L, "integral size (%d) out of limits [1,%d]",
sz, MAXINTSIZE);
return sz;
}
@ -1562,7 +1707,9 @@ static const luaL_Reg strlib[] = {
static void createmetatable (lua_State *L) {
lua_createtable(L, 0, 1); /* table to be metatable for strings */
/* table to be metatable for strings */
luaL_newlibtable(L, stringmetamethods);
luaL_setfuncs(L, stringmetamethods, 0);
lua_pushliteral(L, ""); /* dummy string */
lua_pushvalue(L, -2); /* copy table */
lua_setmetatable(L, -2); /* set table as metatable for strings */

@ -1,5 +1,5 @@
/*
** $Id: ltable.c,v 2.118 2016/11/07 12:38:35 roberto Exp $
** $Id: ltable.c,v 2.118.1.4 2018/06/08 16:22:51 roberto Exp $
** Lua tables (hash)
** See Copyright Notice in lua.h
*/
@ -243,7 +243,9 @@ static unsigned int computesizes (unsigned int nums[], unsigned int *pna) {
unsigned int na = 0; /* number of elements to go to array part */
unsigned int optimal = 0; /* optimal size for array part */
/* loop while keys can fill more than half of total size */
for (i = 0, twotoi = 1; *pna > twotoi / 2; i++, twotoi *= 2) {
for (i = 0, twotoi = 1;
twotoi > 0 && *pna > twotoi / 2;
i++, twotoi *= 2) {
if (nums[i] > 0) {
a += nums[i];
if (a > twotoi/2) { /* more than half elements present? */
@ -356,17 +358,34 @@ static void setnodevector (lua_State *L, Table *t, unsigned int size) {
}
typedef struct {
Table *t;
unsigned int nhsize;
} AuxsetnodeT;
static void auxsetnode (lua_State *L, void *ud) {
AuxsetnodeT *asn = cast(AuxsetnodeT *, ud);
setnodevector(L, asn->t, asn->nhsize);
}
void luaH_resize (lua_State *L, Table *t, unsigned int nasize,
unsigned int nhsize) {
unsigned int i;
int j;
AuxsetnodeT asn;
unsigned int oldasize = t->sizearray;
int oldhsize = allocsizenode(t);
Node *nold = t->node; /* save old hash ... */
if (nasize > oldasize) /* array part must grow? */
setarrayvector(L, t, nasize);
/* create new hash part with appropriate size */
setnodevector(L, t, nhsize);
asn.t = t; asn.nhsize = nhsize;
if (luaD_rawrunprotected(L, auxsetnode, &asn) != LUA_OK) { /* mem. error? */
setarrayvector(L, t, oldasize); /* array back to its original size */
luaD_throw(L, LUA_ERRMEM); /* rethrow memory error */
}
if (nasize < oldasize) { /* array part must shrink? */
t->sizearray = nasize;
/* re-insert elements from vanishing slice */
@ -695,13 +714,13 @@ void luaH_setint (lua_State *L, Table *t, lua_Integer key, TValue *value) {
}
static int unbound_search (Table *t, unsigned int j) {
unsigned int i = j; /* i is zero or a present index */
static lua_Unsigned unbound_search (Table *t, lua_Unsigned j) {
lua_Unsigned i = j; /* i is zero or a present index */
j++;
/* find 'i' and 'j' such that i is present and j is not */
while (!ttisnil(luaH_getint(t, j))) {
i = j;
if (j > cast(unsigned int, MAX_INT)/2) { /* overflow? */
if (j > l_castS2U(LUA_MAXINTEGER) / 2) { /* overflow? */
/* table was built with bad purposes: resort to linear search */
i = 1;
while (!ttisnil(luaH_getint(t, i))) i++;
@ -711,7 +730,7 @@ static int unbound_search (Table *t, unsigned int j) {
}
/* now do a binary search between them */
while (j - i > 1) {
unsigned int m = (i+j)/2;
lua_Unsigned m = (i+j)/2;
if (ttisnil(luaH_getint(t, m))) j = m;
else i = m;
}

@ -1,5 +1,5 @@
/*
** $Id: ltablib.c,v 1.93 2016/02/25 19:41:54 roberto Exp $
** $Id: ltablib.c,v 1.93.1.1 2017/04/19 17:20:42 roberto Exp $
** Library for Table Manipulation
** See Copyright Notice in lua.h
*/

@ -1,5 +1,5 @@
/*
** $Id: ltm.c,v 2.38 2016/12/22 13:08:50 roberto Exp $
** $Id: ltm.c,v 2.38.1.1 2017/04/19 17:39:34 roberto Exp $
** Tag methods
** See Copyright Notice in lua.h
*/

@ -1,5 +1,5 @@
/*
** $Id: lua.c,v 1.230 2017/01/12 17:14:26 roberto Exp $
** $Id: lua.c,v 1.230.1.1 2017/04/19 17:29:57 roberto Exp $
** Lua stand-alone interpreter
** See Copyright Notice in lua.h
*/
@ -153,7 +153,7 @@ static void print_usage (lua_State *L, const char *badoption) {
"Available options are:\n"
" -e stat execute string 'stat'\n"
" -i enter interactive mode after executing 'script'\n"
" -l name require library 'name'\n"
" -l name require library 'name' into global 'name'\n"
" -v show version information\n"
" -E ignore environment variables\n"
" -- stop handling options\n"

@ -1,5 +1,5 @@
/*
** $Id: luac.c,v 1.75 2015/03/12 01:58:27 lhf Exp $
** $Id: luac.c,v 1.76 2018/06/19 01:32:02 lhf Exp $
** Lua compiler (saves bytecodes to files; also lists bytecodes)
** See Copyright Notice in lua.h
*/
@ -206,7 +206,7 @@ int main(int argc, char* argv[])
}
/*
** $Id: luac.c,v 1.75 2015/03/12 01:58:27 lhf Exp $
** $Id: luac.c,v 1.76 2018/06/19 01:32:02 lhf Exp $
** print bytecodes
** See Copyright Notice in lua.h
*/
@ -373,6 +373,7 @@ static void PrintCode(const Proto* f)
case OP_ADD:
case OP_SUB:
case OP_MUL:
case OP_MOD:
case OP_POW:
case OP_DIV:
case OP_IDIV:

@ -1,5 +1,5 @@
/*
** $Id: lundump.c,v 2.44 2015/11/02 16:09:30 roberto Exp $
** $Id: lundump.c,v 2.44.1.1 2017/04/19 17:20:42 roberto Exp $
** load precompiled Lua chunks
** See Copyright Notice in lua.h
*/

@ -1,5 +1,5 @@
/*
** $Id: lutf8lib.c,v 1.16 2016/12/22 13:08:50 roberto Exp $
** $Id: lutf8lib.c,v 1.16.1.1 2017/04/19 17:29:57 roberto Exp $
** Standard library for UTF-8 manipulation
** See Copyright Notice in lua.h
*/
@ -171,7 +171,7 @@ static int byteoffset (lua_State *L) {
}
else {
if (iscont(s + posi))
luaL_error(L, "initial position is a continuation byte");
return luaL_error(L, "initial position is a continuation byte");
if (n < 0) {
while (n < 0 && posi > 0) { /* move back */
do { /* find beginning of previous character */

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save