Skip to content

Commit

Permalink
implement OP_LEN
Browse files Browse the repository at this point in the history
  • Loading branch information
Dibyendu Majumdar committed Mar 24, 2015
1 parent d356fbe commit c41106a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
5 changes: 4 additions & 1 deletion include/ravi_llvmcodegen.h
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ class RaviCodeGenerator {
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);
Expand Down Expand Up @@ -709,6 +709,9 @@ class RaviCodeGenerator {
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);

Expand Down
11 changes: 10 additions & 1 deletion ravi-tests/ravi_tests1.ravi
Original file line number Diff line number Diff line change
Expand Up @@ -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")
2 changes: 1 addition & 1 deletion readthedocs/ravi-jit-status.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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) |
+-------------------------+----------+--------------------------------------------------+
Expand Down
5 changes: 5 additions & 0 deletions src/ravi_llvmcodegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions src/ravi_llvmtable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit c41106a

Please sign in to comment.