Skip to content

Commit

Permalink
issue #100 #70 #88
Browse files Browse the repository at this point in the history
  • Loading branch information
Dibyendu Majumdar committed Sep 23, 2016
1 parent c6ee38a commit 5a83899
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 135 deletions.
20 changes: 4 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,16 @@ if (NOT STATIC_BUILD)
endif()
target_link_libraries(${LIBRAVI_NAME} ${EXTRA_LIBRARIES} ${LLVM_LIBS} ${GCCJIT_LIBRARIES})

# Ravi executable
add_executable(ravi src/lua.c)
target_link_libraries(ravi ${LIBRAVI_NAME})

#VM test
# Simple VM tests
add_executable(test_vm tests/test_vm.c)
target_link_libraries(test_vm ${LIBRAVI_NAME})

if (LLVM_JIT)
#LLVM playground
# LLVM playground
add_executable(test_llvm tests/test_llvm.cpp)
target_link_libraries(test_llvm ${LIBRAVI_NAME})
endif ()
Expand All @@ -274,21 +275,8 @@ endif ()
add_test(TestVM test_vm)
add_test(TestMisc test_misc)

# Build VSCode Debug Adapter for Ravi
if (STATIC_BUILD AND NOT GCC_JIT)
#Static library for the debugger
#add_library(libravinojit
# ${RAVI_HEADERS}
# ${LUA_LIB_SRCS}
# ${LUA_CORE_SRCS}
# src/ravi_nojit.c)
#if (WIN32)
# # enable DLL export
# set_target_properties(libravistatic PROPERTIES DEFINE_SYMBOL "LUA_BUILD_AS_DLL")
#else()
# set_target_properties(libravistatic PROPERTIES PREFIX "")
#endif ()
#target_link_libraries(libravistatic ${EXTRA_LIBRARIES})

add_executable(testravidebug vscode-debugger/src/testravidebug.c vscode-debugger/src/json.c vscode-debugger/src/protocol.c)
target_link_libraries(testravidebug ${LIBRAVI_NAME})

Expand Down
3 changes: 3 additions & 0 deletions include/lopcodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,9 @@ OP_RAVI_MOVETAB, /* A B R(A) := R(B), check R(B) is a table */
OP_RAVI_SETUPVALT,/* A B UpValue[B] := to_table(R(A)) */
OP_RAVI_SELF_S,/* A B C R(A+1) := R(B); R(A) := R(B)[RK(C)] */

/* Following opcodes are specialized for access where the
key is known to be string but the variable may or may not be
a 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)] */
OP_RAVI_SETTABLE_SK,/* A B C R(A)[RK(B)] := RK(C), string key */
Expand Down
2 changes: 0 additions & 2 deletions include/lvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,5 @@ LUAI_FUNC void raviV_op_setupvalt(lua_State *L, LClosure *cl, TValue *ra, int b)
LUAI_FUNC void raviV_op_setupval(lua_State *L, LClosure *cl, TValue *ra, int b);
LUAI_FUNC void raviV_op_shl(lua_State *L, TValue *ra, TValue *rb, TValue *rc);
LUAI_FUNC void raviV_op_shr(lua_State *L, TValue *ra, TValue *rb, TValue *rc);
LUAI_FUNC void raviV_finishget(lua_State *L, const TValue *t, TValue *key, StkId val);


#endif
15 changes: 0 additions & 15 deletions include/ravi_llvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,6 @@
#include <vector>
#include <memory>

//#if 0
//#if defined(LUA_BUILD_AS_DLL)
//#if defined(_WIN32)
//#if defined(RAVI_LIB)
//#define RAVI_API __declspec(dllexport)
//#else
//#define RAVI_API __declspec(dllimport)
//#endif
//#else
//#define RAVI_API extern
//#endif
//#else
//#define RAVI_API extern
//#endif

#endif

#endif
18 changes: 7 additions & 11 deletions include/ravi_llvmcodegen.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ extern "C" {
#include <iterator>
#include <type_traits>

#define RAVI_API

namespace ravi {

/*
Expand Down Expand Up @@ -271,7 +269,6 @@ struct LuaLLVMTypes {
llvm::FunctionType *raviV_op_setupvalaiT;
llvm::FunctionType *raviV_op_setupvalafT;
llvm::FunctionType *raviV_op_setupvaltT;
llvm::FunctionType *raviV_finishgetT;

llvm::FunctionType *raviH_set_intT;
llvm::FunctionType *raviH_set_floatT;
Expand Down Expand Up @@ -358,18 +355,18 @@ struct LuaLLVMTypes {
// via a shared_ptr. This ensures that RaviJITModule gets
// released when no longer referenced.

class RAVI_API RaviJITState;
class RAVI_API RaviJITModule;
class RAVI_API RaviJITFunction;
class RaviJITState;
class RaviJITModule;
class RaviJITFunction;

class RAVI_API RaviJITStateFactory {
class RaviJITStateFactory {
public:
static std::unique_ptr<RaviJITState> newJITState();
};

// A wrapper for LLVM Module
// Maintains a dedicated ExecutionEngine for the module
class RAVI_API RaviJITModule {
class RaviJITModule {
// The Context that owns this module
RaviJITState *owner_;

Expand Down Expand Up @@ -428,7 +425,7 @@ class RAVI_API RaviJITModule {
// This object is stored in the Lua Proto structure
// and gets destroyed when the Lua function is
// garbage collected
class RAVI_API RaviJITFunction {
class RaviJITFunction {
// The Module in which this function lives
// We hold a shared_ptr to the module so that
// the module will be destroyed when the
Expand Down Expand Up @@ -482,7 +479,7 @@ class RAVI_API RaviJITFunction {

// Ravi's LLVM JIT State
// All of the JIT information is held here
class RAVI_API RaviJITState {
class RaviJITState {
// The LLVM Context
llvm::LLVMContext *context_;

Expand Down Expand Up @@ -641,7 +638,6 @@ struct RaviFunctionDef {
llvm::Function *raviV_op_setupvalaiF;
llvm::Function *raviV_op_setupvalafF;
llvm::Function *raviV_op_setupvaltF;
llvm::Function *raviV_finishgetF;

// array setters
llvm::Function *raviH_set_intF;
Expand Down
1 change: 1 addition & 0 deletions src/ldebug.c
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,7 @@ static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) {
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 */
case OP_SELF: case OP_GETTABUP: case OP_GETTABLE: case OP_RAVI_GETTABLE_SK: case OP_RAVI_SELF_SK:
tm = TM_INDEX;
break;
Expand Down
22 changes: 17 additions & 5 deletions src/lopcodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ LUAI_DDEF const char *const luaP_opnames[NUM_OPCODES+1] = {
"SETUPVALT", /* A B UpValue[B] := to_table(R(A)) */
"SELF_S", /* A B C R(A+1) := R(B); R(A) := R(B)[RK(C)] */
// TODO temporary hack to allow existing tests to see old opcode names
"GETTABLE", /* _SK */ /* A B C R(A) := R(B)[RK(C)], string key */
"SELF", /* _SK*/ /* A B C R(A+1) := R(B); R(A) := R(B)[RK(C)] */
"SETTABLE", /*_SK */ /* A B C R(A)[RK(B)] := RK(C), string key */
"GETTABLE_SK", /* _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 */
NULL
};

Expand Down Expand Up @@ -627,8 +627,20 @@ static void setnameval(lua_State *L, const char *name, int val) {

static char *buildop2(Proto *p, int pc, char *buff, size_t len) {
int line = getfuncline(p, pc);
snprintf(buff, len, "(%4d) %4d - ", line, pc);
raviP_instruction_to_str(buff + strlen(buff), len - strlen(buff), p->code[pc]);
char tbuf[100];
raviP_instruction_to_str(tbuf, sizeof tbuf, p->code[pc]);
/* This is a temporary hack to output old opcode names to prevent tests from breaking */
if (strncmp(tbuf, luaP_opnames[OP_RAVI_GETTABLE_SK], strlen(luaP_opnames[OP_RAVI_GETTABLE_SK])) == 0 ||
strncmp(tbuf, luaP_opnames[OP_RAVI_SELF_SK], strlen(luaP_opnames[OP_RAVI_SELF_SK])) == 0 ||
strncmp(tbuf, luaP_opnames[OP_RAVI_SETTABLE_SK], strlen(luaP_opnames[OP_RAVI_SETTABLE_SK])) == 0) {
char *cp = strstr(tbuf, "_SK ");
if (cp != NULL) {
cp[0] = ' ';
cp[1] = ' ';
cp[2] = ' ';
}
}
snprintf(buff, len, "(%4d) %4d - %s", line, pc, tbuf);
return buff;
}

Expand Down
31 changes: 17 additions & 14 deletions src/ltable.c
Original file line number Diff line number Diff line change
Expand Up @@ -610,23 +610,26 @@ const TValue *luaH_getstr (Table *t, TString *key) {
/*
** main search function
*/
const TValue *luaH_get (Table *t, const TValue *key) {
switch (ttype(key)) {
case LUA_TSHRSTR: return luaH_getshortstr(t, tsvalue(key));
case LUA_TNUMINT: return luaH_getint(t, ivalue(key));
case LUA_TNIL: return luaO_nilobject;
case LUA_TNUMFLT: {
lua_Integer k;
if (luaV_tointeger(key, &k, 0)) /* index is int? */
return luaH_getint(t, k); /* use specialized version */
/* else... */
} /* FALLTHROUGH */
default:
return getgeneric(t, key);
const TValue *luaH_get(Table *t, const TValue *key) {
int tt = ttype(key);
if (tt == LUA_TSHRSTR)
return luaH_getshortstr(t, tsvalue(key));
else if (tt == LUA_TNUMINT)
return luaH_getint(t, ivalue(key));
else if (tt == LUA_TNIL)
return luaO_nilobject;
else if (tt == LUA_TNUMFLT) {
lua_Integer k;
if (luaV_tointeger(key, &k, 0)) /* index is int? */
return luaH_getint(t, k); /* use specialized version */
/* else... */
return getgeneric(t, key);
} /* FALLTHROUGH */
else {
return getgeneric(t, key);
}
}


/*
** beware: when using this function you probably need to check a GC
** barrier and invalidate the TM cache.
Expand Down
Loading

0 comments on commit 5a83899

Please sign in to comment.