fix compilation on MAC OSX

pull/81/head
Dibyendu Majumdar 9 years ago
parent 2caa9c1637
commit 05e8448b15

@ -49,7 +49,7 @@ if (MSVC)
add_definitions("/wd4291")
endif()
if (CMAKE_COMPILER_IS_GNUCXX OR APPLE)
if (CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_C_FLAGS "-std=c99 -O1 -g3 -fsanitize=address -Wall -Wextra -DLUA_COMPAT_5_2 -DLUA_USE_LINUX")
set(CMAKE_C_FLAGS_DEBUG "-std=c99 -O0 -g3 -fsanitize=address -Wall -Wextra -DLUA_COMPAT_5_2 -DLUA_USE_LINUX")
set(CMAKE_C_FLAGS_RELEASE "-std=c99 -O3 -Wall -Wextra -DLUA_COMPAT_5_2 -DLUA_USE_LINUX")
@ -60,6 +60,17 @@ if (CMAKE_COMPILER_IS_GNUCXX OR APPLE)
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-fno-rtti -O1 -g3 -fsanitize=address -Wall -Wno-sign-compare -std=c++11 -fno-exceptions -DLUA_COMPAT_5_2 -DLUA_USE_LINUX")
endif()
if (APPLE)
set(CMAKE_C_FLAGS "-std=c99 -O1 -g3 -Wall -Wextra -DLUA_COMPAT_5_2 -DLUA_USE_MACOSX")
set(CMAKE_C_FLAGS_DEBUG "-std=c99 -O0 -g3 -Wall -Wextra -DLUA_COMPAT_5_2 -DLUA_USE_MACOSX")
set(CMAKE_C_FLAGS_RELEASE "-std=c99 -O3 -Wall -Wextra -DLUA_COMPAT_5_2 -DLUA_USE_MACOSX")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-std=c99 -O1 -g3 -Wall -Wextra -DLUA_COMPAT_5_2 -DLUA_USE_MACOSX")
set(CMAKE_CXX_FLAGS "-O1 -g3 -Wall -fno-rtti -Wno-sign-compare -std=c++11 -fno-exceptions -DLUA_COMPAT_5_2 -DLUA_USE_MACOSX")
set(CMAKE_CXX_FLAGS_RELEASE "-fno-rtti -O3 -Wall -Wno-sign-compare -std=c++11 -fno-exceptions -DLUA_COMPAT_5_2 -DLUA_USE_MACOSX")
set(CMAKE_CXX_FLAGS_DEBUG "-fno-rtti -O0 -g3 -Wall -Wno-sign-compare -std=c++11 -fno-exceptions -DLUA_COMPAT_5_2 -DLUA_USE_MACOSX")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-fno-rtti -O1 -g3 -Wall -Wno-sign-compare -std=c++11 -fno-exceptions -DLUA_COMPAT_5_2 -DLUA_USE_MACOSX")
endif()
include_directories("${PROJECT_SOURCE_DIR}/include")
add_definitions(-DLUA_COMPAT_MODULE -DCOCO_DISABLE)
@ -78,9 +89,12 @@ set (LUA_LIB_SRCS src/lauxlib.c src/lbaselib.c src/lbitlib.c src/lcorolib.c src/
file(GLOB RAVI_HEADERS "${PROJECT_SOURCE_DIR}/include/*.h")
if (MSVC)
if (MSVC OR APPLE)
source_group("Ravi Headers" FILES ${RAVI_HEADERS})
source_group("Ravi Source Files" FILES ${LUA_CORE_SRCS} ${LUA_LIB_SRCS})
if (APPLE)
set(EXTRA_LIBRARIES m readline)
endif()
else()
# On Linux we need to link libdl to get access to
# functions like dlopen()

@ -669,6 +669,7 @@ LUA_API int lua_rawget (lua_State *L, int idx) {
setnilvalue(key);
}
} break;
default: lua_assert(0); break;
}
lua_unlock(L);
return ttnov(L->top - 1);
@ -700,6 +701,10 @@ LUA_API int lua_rawgeti (lua_State *L, int idx, lua_Integer n) {
setnilvalue(L->top);
}
} break;
default:
lua_assert(0);
break;
}
api_incr_top(L);
lua_unlock(L);
@ -873,6 +878,10 @@ LUA_API void lua_rawset (lua_State *L, int idx) {
luaG_runerror(L, "value cannot be converted to number");
}
} break;
default:
lua_assert(0);
break;
}
invalidateTMcache(t);
luaC_barrierback(L, t, L->top-1);
@ -919,6 +928,10 @@ LUA_API void lua_rawseti (lua_State *L, int idx, lua_Integer n) {
luaG_runerror(L, "value cannot be converted to number");
}
} break;
default:
lua_assert(0);
break;
}
luaC_barrierback(L, t, L->top-1);
L->top--;

@ -17,6 +17,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
/* ORDER OP */
@ -388,6 +389,7 @@ static void PrintRaviCodePC(const Proto* f, Instruction i, int pc)
if (getBMode(o) != OpArgN) printf(" %d", getBMode(o) == OpArgK ? (MYK(INDEXK(b))) : b);
if (getCMode(o) != OpArgN) printf(" %d", getCMode(o) == OpArgK ? (MYK(INDEXK(c))) : c);
break;
default: break;
}
printf("\n");
}

@ -1196,8 +1196,8 @@ static void ravi_typecheck(LexState *ls, expdesc *v, int *vars, int nvars, int n
luaK_codeABC(ls->fs, vars[i] == RAVI_TARRAYFLT ? OP_RAVI_TOARRAYF : OP_RAVI_TOARRAYI, a + (i - n), 0, 0);
}
else if ((vars[n] == RAVI_TNUMFLT || vars[n] == RAVI_TNUMINT) && v->k == VINDEXED) {
if (vars[n] == RAVI_TNUMFLT && v->ravi_type != RAVI_TARRAYFLT ||
vars[n] == RAVI_TNUMINT && v->ravi_type != RAVI_TARRAYINT)
if ((vars[n] == RAVI_TNUMFLT && v->ravi_type != RAVI_TARRAYFLT) ||
(vars[n] == RAVI_TNUMINT && v->ravi_type != RAVI_TARRAYINT))
luaX_syntaxerror(ls, "Invalid local assignment");
}
else
@ -1816,7 +1816,7 @@ static void fornum (LexState *ls, TString *varname, int line) {
vvar = &fs->f->locvars[fs->nlocvars - 1]; /* index variable - not yet active so get it from locvars*/
checknext(ls, '=');
/* get the type of each expression */
Fornuminfo tidx = { RAVI_TANY }, tlimit = { RAVI_TANY }, tstep = { RAVI_TNUMINT };
Fornuminfo tidx = { RAVI_TANY,0,0 }, tlimit = { RAVI_TANY,0,0 }, tstep = { RAVI_TNUMINT,0,0 };
Fornuminfo *info = NULL;
exp1(ls, &tidx); /* initial value */
checknext(ls, ',');

@ -690,7 +690,6 @@ int raviH_getn(Table *t) {
}
static void ravi_resize_array(lua_State *L, Table *t) {
unsigned int i;
unsigned int size = t->ravi_array.size + 10;
t->ravi_array.data = (char *) luaM_reallocv(L, t->ravi_array.data, t->ravi_array.size, size, sizeof(lua_Number));
lua_Number *data = (lua_Number*) t->ravi_array.data;

@ -1507,7 +1507,6 @@ void ravi_dump_ci(lua_State *L, CallInfo *ci) {
StkId func = ci->func;
int func_type = ttype(func);
StkId base = NULL;
const char *func_typename;
Proto *p = NULL;
int funcpos = ci->func - L->stack;
StkId stack_ptr = ci->top - 1;

@ -806,7 +806,7 @@ void RaviCodeGenerator::emit_UNM(RaviFunctionDef *def, llvm::Value *L_ci,
// Copy RB to local nb
auto src = emit_load_reg_n(def, rb);
auto ins = emit_store_local_n(def, src, nb);
emit_store_local_n(def, src, nb);
def->builder->CreateBr(float_op);

@ -73,7 +73,6 @@ void RaviCodeGenerator::emit_CALL(RaviFunctionDef *def, llvm::Value *L_ci,
// }
llvm::Instruction *base_ptr = emit_load_base(def);
llvm::Value *top = nullptr;
// int nresults = c - 1;
int nresults = C - 1;

@ -108,7 +108,7 @@ llvm::Value *RaviCodeGenerator::emit_boolean_testfalse(RaviFunctionDef *def,
def->builder->CreateCondBr(isnil, then_block, else_block);
def->builder->SetInsertPoint(then_block);
auto ins = emit_store_local_int(def, isnil, var);
emit_store_local_int(def, isnil, var);
def->builder->CreateBr(end_block);
def->f->getBasicBlockList().push_back(else_block);
@ -125,7 +125,7 @@ llvm::Value *RaviCodeGenerator::emit_boolean_testfalse(RaviFunctionDef *def,
// Test type == LUA_TBOOLEAN && bool value == 0
llvm::Value *andvalue = def->builder->CreateAnd(isbool, boolzero);
auto ins2 = emit_store_local_int(def, andvalue, var);
emit_store_local_int(def, andvalue, var);
def->builder->CreateBr(end_block);
def->f->getBasicBlockList().push_back(end_block);

@ -426,8 +426,7 @@ void RaviCodeGenerator::emit_iFORLOOP(RaviFunctionDef *def, llvm::Value *L_ci,
"next.idx", false, true);
// save new index
llvm::Instruction *idx_store =
emit_store_local_n(def, new_idx, idx_int_ptr);
emit_store_local_n(def, new_idx, idx_int_ptr);
// lua_Integer limit = ivalue(ra + 1);
llvm::Instruction *limit_int_value =

@ -141,8 +141,7 @@ void RaviCodeGenerator::emit_FORPREP2(RaviFunctionDef *def, llvm::Value *L_ci,
// all values are integers
// lua_Integer initv = (stopnow ? 0 : ivalue(init));
// Save step
llvm::Instruction *istep_store =
emit_store_local_n(def, pstep_ivalue, forloop_target.istep);
emit_store_local_n(def, pstep_ivalue, forloop_target.istep);
// Get stopnow
llvm::Instruction *stopnow_val = emit_load_local_int(def, stopnow);
@ -180,8 +179,7 @@ void RaviCodeGenerator::emit_FORPREP2(RaviFunctionDef *def, llvm::Value *L_ci,
llvm::Value *sub =
def->builder->CreateSub(phi1, pstep_ivalue, "initv-pstep.i", false, true);
llvm::Instruction *init_ivalue_store =
emit_store_local_n(def, sub, forloop_target.iidx);
emit_store_local_n(def, sub, forloop_target.iidx);
// Ok so now we need to decide which jump target
isinc = def->builder->CreateICmpSGT(pstep_ivalue, def->types->kluaInteger[0],
@ -242,7 +240,7 @@ void RaviCodeGenerator::emit_FORPREP2(RaviFunctionDef *def, llvm::Value *L_ci,
// Already a float - copy to nlimit
llvm::Instruction *plimit_nvalue_load = emit_load_reg_n(def, plimit);
llvm::Instruction *nlimit_store = emit_store_local_n(def, plimit_nvalue_load, forloop_target.flimit);
emit_store_local_n(def, plimit_nvalue_load, forloop_target.flimit);
// Go to the PSTEP section
llvm::BasicBlock *else1_pstep =
@ -291,7 +289,7 @@ void RaviCodeGenerator::emit_FORPREP2(RaviFunctionDef *def, llvm::Value *L_ci,
// We float then copy to nstep
llvm::Instruction *pstep_nvalue_load = emit_load_reg_n(def, pstep);
llvm::Instruction *nstep_store = emit_store_local_n(def, pstep_nvalue_load, forloop_target.fstep);
emit_store_local_n(def, pstep_nvalue_load, forloop_target.fstep);
// Now go to handle initial value
llvm::BasicBlock *else1_pinit =
@ -338,8 +336,7 @@ void RaviCodeGenerator::emit_FORPREP2(RaviFunctionDef *def, llvm::Value *L_ci,
// Already float so copy to ninit
llvm::Instruction *pinit_nvalue_load = emit_load_reg_n(def, init);
llvm::Instruction *fidx_store =
emit_store_local_n(def, pinit_nvalue_load, forloop_target.fidx);
emit_store_local_n(def, pinit_nvalue_load, forloop_target.fidx);
// Go to final section
llvm::BasicBlock *else1_pdone =
@ -380,8 +377,7 @@ void RaviCodeGenerator::emit_FORPREP2(RaviFunctionDef *def, llvm::Value *L_ci,
llvm::Value *init_n =
def->builder->CreateFSub(ninit_load, nstep_load, "ninit-nstep");
llvm::Instruction *ninit_store =
emit_store_local_n(def, init_n, forloop_target.fidx);
emit_store_local_n(def, init_n, forloop_target.fidx);
// Done so jump to forloop
llvm::Value *fstep_gt_zero = def->builder->CreateFCmpOGT(
@ -579,8 +575,7 @@ void RaviCodeGenerator::emit_FORPREP(RaviFunctionDef *def, llvm::Value *L_ci,
// Already a float - copy to nlimit
llvm::Instruction *plimit_nvalue_load = emit_load_reg_n(def, plimit);
llvm::Instruction *nlimit_store =
emit_store_local_n(def, plimit_nvalue_load, nlimit);
emit_store_local_n(def, plimit_nvalue_load, nlimit);
// Go to the PSTEP section
llvm::BasicBlock *else1_pstep =
@ -633,8 +628,7 @@ void RaviCodeGenerator::emit_FORPREP(RaviFunctionDef *def, llvm::Value *L_ci,
// We float then copy to nstep
llvm::Instruction *pstep_nvalue_load = emit_load_reg_n(def, pstep);
llvm::Instruction *nstep_store =
emit_store_local_n(def, pstep_nvalue_load, nstep);
emit_store_local_n(def, pstep_nvalue_load, nstep);
// Now go to handle initial value
llvm::BasicBlock *else1_pinit =
@ -686,8 +680,7 @@ void RaviCodeGenerator::emit_FORPREP(RaviFunctionDef *def, llvm::Value *L_ci,
// Already float so copy to ninit
llvm::Instruction *pinit_nvalue_load = emit_load_reg_n(def, init);
llvm::Instruction *ninit_store =
emit_store_local_n(def, pinit_nvalue_load, ninit);
emit_store_local_n(def, pinit_nvalue_load, ninit);
// Go to final section
llvm::BasicBlock *else1_pdone =
@ -775,25 +768,21 @@ void RaviCodeGenerator::emit_iFORPREP(RaviFunctionDef *def, llvm::Value *L_ci,
"initv-pstep.i", false, true);
// Save idx
llvm::Instruction *iinit_store =
emit_store_local_n(def, idx, forloop_target.iidx);
emit_store_local_n(def, idx, forloop_target.iidx);
// Save step
llvm::Instruction *istep_store =
emit_store_local_n(def, step_ivalue, forloop_target.istep);
emit_store_local_n(def, step_ivalue, forloop_target.istep);
} else {
// setivalue(init, initv - ivalue(pstep));
llvm::Value *idx = def->builder->CreateSub(
init_ivalue, def->types->kluaInteger[1], "initv-pstep.i", false, true);
// Save idx
llvm::Instruction *iinit_store =
emit_store_local_n(def, idx, forloop_target.iidx);
emit_store_local_n(def, idx, forloop_target.iidx);
}
// Save limit
llvm::Instruction *ilimit_store =
emit_store_local_n(def, limit_ivalue, forloop_target.ilimit);
emit_store_local_n(def, limit_ivalue, forloop_target.ilimit);
// We are done so jump to forloop
lua_assert(def->jmp_targets[pc].jmp1);

@ -132,7 +132,7 @@ void RaviCodeGenerator::emit_MOVEI(RaviFunctionDef *def, llvm::Value *L_ci,
// Already a int - move
llvm::Instruction *tmp = emit_load_reg_i(def, src);
llvm::Instruction *store = emit_store_local_n(def, tmp, var);
emit_store_local_n(def, tmp, var);
def->builder->CreateBr(end1);
// we need to convert
@ -206,7 +206,7 @@ void RaviCodeGenerator::emit_MOVEF(RaviFunctionDef *def, llvm::Value *L_ci,
// Already a float - copy to var
llvm::Instruction *tmp = emit_load_reg_n(def, src);
llvm::Instruction *store = emit_store_local_n(def, tmp, var);
emit_store_local_n(def, tmp, var);
def->builder->CreateBr(end1);
// we need to convert

@ -58,7 +58,6 @@ void RaviCodeGenerator::emit_RETURN(RaviFunctionDef *def, llvm::Value *L_ci,
// Load pointer to base
llvm::Instruction *base_ptr = emit_load_base(def);
llvm::Value *top = nullptr;
// Get pointer to register A
llvm::Value *ra_ptr = emit_gep_ra(def, base_ptr, A);

@ -236,7 +236,7 @@ void RaviCodeGenerator::emit_SETTABLE_AI(RaviFunctionDef *def,
llvm::Value *ptr = def->builder->CreateGEP(data, ukey);
llvm::Instruction *ins = def->builder->CreateStore(value, ptr);
def->builder->CreateStore(value, ptr);
// TODO tbaa
def->builder->CreateBr(end_block);
@ -307,7 +307,7 @@ void RaviCodeGenerator::emit_SETTABLE_AF(RaviFunctionDef *def,
// Copy RC to local
auto src = emit_load_reg_n(def, rc);
auto ins = emit_store_local_n(def, src, nc);
emit_store_local_n(def, src, nc);
def->builder->CreateBr(set_af);
// Convert int to float
@ -317,7 +317,7 @@ void RaviCodeGenerator::emit_SETTABLE_AF(RaviFunctionDef *def,
llvm::Instruction *ivalue = emit_load_reg_i(def, rc);
llvm::Value *floatvalue =
def->builder->CreateSIToFP(ivalue, def->types->lua_NumberT);
auto ins1 = emit_store_local_n(def, floatvalue, nc);
emit_store_local_n(def, floatvalue, nc);
def->builder->CreateBr(set_af);
def->f->getBasicBlockList().push_back(set_af);
@ -343,7 +343,7 @@ void RaviCodeGenerator::emit_SETTABLE_AF(RaviFunctionDef *def,
llvm::Value *ptr = def->builder->CreateGEP(data, ukey);
llvm::Instruction *ins2 = def->builder->CreateStore(load_nc, ptr);
def->builder->CreateStore(load_nc, ptr);
// TODO tbaa
def->builder->CreateBr(end_block);

@ -27,6 +27,7 @@ static int test_luacomp1(const char *code)
return rc;
}
#if 0
static int test_luacompfile(const char *code)
{
int rc = 0;
@ -79,6 +80,7 @@ static int test_luafileexec1(const char *code, int expected)
lua_close(L);
return rc;
}
#endif
/* test supplied lua code compiles */
@ -118,7 +120,7 @@ static int test_luacompexec1(const char *code, int expected)
return rc;
}
int main(int argc, const char *argv[])
int main()
{
int failures = 0;
//

Loading…
Cancel
Save