implement OP_LEN

pull/81/head
Dibyendu Majumdar 9 years ago
parent d356fbef2b
commit c41106ad57

@ -597,7 +597,7 @@ public:
int A, int B, int C);
void emit_IDIV(RaviFunctionDef *def, llvm::Value *L_ci, llvm::Value *proto,
int A, int B, int C);
int A, int B, int C);
void emit_UNMF(RaviFunctionDef *def, llvm::Value *L_ci, llvm::Value *proto,
int A, int B);
@ -709,6 +709,9 @@ public:
void emit_TOFLT(RaviFunctionDef *def, llvm::Value *L_ci, llvm::Value *proto,
int A);
void emit_LEN(RaviFunctionDef *def, llvm::Value *L_ci, llvm::Value *proto,
int A, int B);
void emit_SETTABLE(RaviFunctionDef *def, llvm::Value *L_ci,
llvm::Value *proto, int A, int B, int C);

@ -441,4 +441,13 @@ end
assert(ravi.compile(x))
assert(x(5,2) == 2)
assert(math.abs(x(5.5,2.1)-2.0) < 1e-12)
print("test 33 OK")
print("test 33 OK")
-- test 34
x=function()
local t={1,2,3,4,5}
return #t
end
assert(ravi.compile(x))
assert(x() == 5)
print("test 34 OK")

@ -67,7 +67,7 @@ Note that if a Lua functions contains a bytecode that cannot be be JITed then th
+-------------------------+----------+--------------------------------------------------+
| OP_NOT | YES | R(A) := not R(B) |
+-------------------------+----------+--------------------------------------------------+
| OP_LEN | NO | R(A) := length of R(B) |
| OP_LEN | YES | R(A) := length of R(B) |
+-------------------------+----------+--------------------------------------------------+
| OP_CONCAT | NO | R(A) := R(B).. ... ..R(C) |
+-------------------------+----------+--------------------------------------------------+

@ -261,6 +261,7 @@ bool RaviCodeGenerator::canCompile(Proto *p) {
case OP_DIV:
case OP_MOD:
case OP_IDIV:
case OP_LEN:
case OP_SETTABLE:
case OP_GETTABLE:
case OP_GETUPVAL:
@ -641,6 +642,10 @@ void RaviCodeGenerator::compile(lua_State *L, Proto *p) {
int C = GETARG_C(i);
emit_SETLIST(&def, L_ci, proto, A, B, C);
} break;
case OP_LEN: {
int B = GETARG_B(i);
emit_LEN(&def, L_ci, proto, A, B);
} break;
case OP_RETURN: {
int B = GETARG_B(i);

@ -24,6 +24,14 @@
namespace ravi {
void RaviCodeGenerator::emit_LEN(RaviFunctionDef *def, llvm::Value *L_ci,
llvm::Value *proto, int A, int B) {
llvm::Instruction *base_ptr = emit_load_base(def);
llvm::Value *ra = emit_gep_ra(def, base_ptr, A);
llvm::Value *rb = emit_gep_ra(def, base_ptr, B);
def->builder->CreateCall3(def->luaV_objlenF, def->L, ra, rb);
}
// R(A)[RK(B)] := RK(C)
void RaviCodeGenerator::emit_SETTABLE(RaviFunctionDef *def, llvm::Value *L_ci,
llvm::Value *proto, int A, int B, int C) {

Loading…
Cancel
Save