Skip to content

Commit

Permalink
issue #100
Browse files Browse the repository at this point in the history
  • Loading branch information
Dibyendu Majumdar committed Oct 7, 2016
1 parent b48a096 commit cd0150e
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 3 deletions.
2 changes: 1 addition & 1 deletion include/lstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ typedef struct CallInfo {
short nresults; /* expected number of results from this function */
lu_byte callstatus;
lu_byte jitstatus; /* Only valid if Lua function - if 1 means JITed - RAVI extension */
short stacklevel; /* Ravi extension - stack level, bootom level is 0 */
short stacklevel; /* Ravi extension - stack level, bottom level is 0 */
} CallInfo;


Expand Down
2 changes: 1 addition & 1 deletion src/lcode.c
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ void luaK_self (FuncState *fs, expdesc *e, expdesc *key) {
int is_string_constant_key =
key->k == VK &&
key->ravi_type == RAVI_TSTRING &&
isshortstr(fs, RKASK(key->u.info));
ttisshrstring(&fs->f->k[key->u.info]);
int table_and_string =
e->ravi_type == RAVI_TTABLE &&
is_string_constant_key;
Expand Down
60 changes: 60 additions & 0 deletions src/lparser.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,65 @@ const char *raviY_typename(ravitype_t tt) {
}
}

static void PrintString(FILE *fp, const TString* ts)
{
const char* s = getstr(ts);
size_t i, n = tsslen(ts);
fprintf(fp, "%c", '"');
for (i = 0; i<n; i++)
{
int c = (int)(unsigned char)s[i];
switch (c)
{
case '"': fprintf(fp, "\\\""); break;
case '\\': fprintf(fp, "\\\\"); break;
case '\a': fprintf(fp, "\\a"); break;
case '\b': fprintf(fp, "\\b"); break;
case '\f': fprintf(fp, "\\f"); break;
case '\n': fprintf(fp, "\\n"); break;
case '\r': fprintf(fp, "\\r"); break;
case '\t': fprintf(fp, "\\t"); break;
case '\v': fprintf(fp, "\\v"); break;
default: if (isprint(c))
fprintf(fp, "%c", c);
else
fprintf(fp, "\\%03d", c);
}
}
fprintf(fp, "%c", '"');
}

static void PrintConstant(FILE *fp, const Proto* f, int i)
{
const TValue* o = &f->k[i];
switch (ttype(o))
{
case LUA_TNIL:
fprintf(fp, "nil");
break;
case LUA_TBOOLEAN:
fprintf(fp, bvalue(o) ? "true" : "false");
break;
case LUA_TNUMFLT:
{
char buff[100];
sprintf(buff, LUA_NUMBER_FMT, fltvalue(o));
fprintf(fp, "%s", buff);
if (buff[strspn(buff, "-0123456789")] == '\0') fprintf(fp, ".0");
break;
}
case LUA_TNUMINT:
fprintf(fp, LUA_INTEGER_FMT, ivalue(o));
break;
case LUA_TSHRSTR: case LUA_TLNGSTR:
PrintString(fp, tsvalue(o));
break;
default: /* cannot happen */
fprintf(fp, "? type=%d", ttype(o));
break;
}
}

/* RAVI - prints a Lua expression node */
static void print_expdesc(FILE *fp, FuncState *fs, const expdesc *e) {
char buf[80] = {0};
Expand Down Expand Up @@ -221,6 +280,7 @@ void raviY_printf(FuncState *fs, const char *format, ...) {
}
}
va_end(ap);
fflush(stdout);
}

/*
Expand Down
8 changes: 7 additions & 1 deletion src/lvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,13 @@ int luaV_execute (lua_State *L) {
luaH_resize(L, t, luaO_fb2int(b), luaO_fb2int(c));
checkGC(L, ra + 1);
} break;
case OP_RAVI_SELF_SK:
case OP_RAVI_SELF_SK: {
StkId rb = RB(i); /* variable - may not be a table */
/* we know that the key a short string constant */
TValue *rc = RKC(i);
setobjs2s(L, ra + 1, rb);
GETTABLE_INLINE_SSKEY_PROTECTED(L, rb, rc, ra);
} break;
case OP_SELF: {
const TValue *aux;
StkId rb = RB(i);
Expand Down

0 comments on commit cd0150e

Please sign in to comment.