aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lapi.js8
-rw-r--r--src/ldebug.js16
-rw-r--r--src/ldo.js4
-rw-r--r--src/lobject.js12
-rw-r--r--src/lparser.js2
-rw-r--r--src/lundump.js2
-rw-r--r--src/lvm.js8
7 files changed, 22 insertions, 30 deletions
diff --git a/src/lapi.js b/src/lapi.js
index 9c01e95..52bc8fa 100644
--- a/src/lapi.js
+++ b/src/lapi.js
@@ -54,7 +54,7 @@ const index2addr = function(L, idx) {
if (ci.func.ttislcf()) /* light C function? */
return lobject.luaO_nilobject; /* it has no upvalues */
else {
- return idx <= ci.func.nupvalues ? ci.func.upvalue[idx - 1] : lobject.luaO_nilobject;
+ return idx <= ci.func.value.nupvalues ? ci.func.value.upvalue[idx - 1] : lobject.luaO_nilobject;
}
}
};
@@ -277,7 +277,7 @@ const lua_pushcclosure = function(L, fn, n) {
cl.upvalue[n] = L.stack[L.top + n];
}
- L.stack[L.top] = cl;
+ L.stack[L.top] = new TValue(CT.LUA_TCCL, cl);
}
L.top++;
@@ -812,7 +812,7 @@ const lua_load = function(L, reader, data, chunckname, mode) {
if (!chunckname) chunckname = [defs.char["?"]];
let status = ldo.luaD_protectedparser(L, z, chunckname, mode);
if (status === TS.LUA_OK) { /* no errors? */
- let f = L.stack[L.top - 1]; /* get newly created function */
+ let f = L.stack[L.top - 1].value; /* get newly created function */
if (f.nupvalues >= 1) { /* does it have an upvalue? */
/* get global table from registry */
let reg = L.l_G.l_registry;
@@ -828,7 +828,7 @@ const lua_dump = function(L, writer, data, strip) {
assert(1 < L.top - L.ci.funcOff, "not enough elements in the stack");
let o = L.stack[L.top -1];
if (o.ttisLclosure())
- return ldump.luaU_dump(L, o.p, writer, data, strip);
+ return ldump.luaU_dump(L, o.value.p, writer, data, strip);
return 1;
};
diff --git a/src/ldebug.js b/src/ldebug.js
index 6350c3e..c9c4c1e 100644
--- a/src/ldebug.js
+++ b/src/ldebug.js
@@ -18,7 +18,7 @@ const CT = defs.constant_types;
const TS = defs.thread_status;
const currentline = function(ci) {
- return ci.func.p.lineinfo ? ci.func.p.lineinfo[ci.pcOff] : -1;
+ return ci.func.value.p.lineinfo ? ci.func.value.p.lineinfo[ci.pcOff] : -1;
};
/*
@@ -87,7 +87,7 @@ const upvalname = function(p, uv) {
};
const findvararg = function(ci, n, pos) {
- let nparams = ci.func.p.numparams;
+ let nparams = ci.func.value.p.numparams;
if (n >= ci.u.l.base - ci.funcOff - nparams)
return null; /* no such vararg */
else {
@@ -106,7 +106,7 @@ const findlocal = function(L, ci, n) {
return findvararg(ci, -n);
else {
base = ci.u.l.base;
- name = lfunc.luaF_getlocalname(ci.func.p, n, ci.pcOff);
+ name = lfunc.luaF_getlocalname(ci.func.value.p, n, ci.pcOff);
}
} else
base = ci.funcOff + 1;
@@ -272,7 +272,7 @@ const lua_getinfo = function(L, what, ar) {
assert(ci.func.ttisfunction());
}
- cl = func.ttisclosure() ? func : null;
+ cl = func.ttisclosure() ? func.value : null;
status = auxgetinfo(L, what, ar, cl, ci);
if (what.indexOf('f'.charCodeAt(0)) >= 0) {
L.stack[L.top++] = func;
@@ -439,7 +439,7 @@ const funcnamefromcode = function(L, ci) {
};
let tm = 0; /* (initial value avoids warnings) */
- let p = ci.func.p; /* calling function */
+ let p = ci.func.value.p; /* calling function */
let pc = ci.pcOff - 1; /* calling instruction index */
let i = p.code[pc]; /* calling instruction */
@@ -530,7 +530,7 @@ const varinfo = function(L, o) {
kind = getupvalname(L, ci, o); /* check whether 'o' is an upvalue */
let stkid = isinstack(L, ci, o);
if (!kind && stkid) /* no? try a register */
- kind = getobjname(ci.func.p, ci.pcOff, stkid - ci.u.l.base);
+ kind = getobjname(ci.func.value.p, ci.pcOff, stkid - ci.u.l.base);
}
return defs.to_luastring(kind ? ` (${defs.to_jsstring(kind.funcname)} '${defs.to_jsstring(kind.name.value ? kind.name.value : kind.name)}')` : ``);
@@ -579,7 +579,7 @@ const luaG_addinfo = function(L, msg, src, line) {
const luaG_runerror = function(L, msg) {
let ci = L.ci;
if (ci.callstatus & lstate.CIST_LUA) /* if Lua function, add source:line information */
- luaG_addinfo(L, msg, ci.func.p.source, currentline(ci));
+ luaG_addinfo(L, msg, ci.func.value.p.source, currentline(ci));
luaG_errormsg(L);
};
@@ -620,7 +620,7 @@ const luaG_traceexec = function(L) {
if (counthook)
ldo.luaD_hook(L, defs.LUA_HOOKCOUNT, -1); /* call count hook */
if (mask & defs.LUA_MASKLINE) {
- let p = ci.func.p;
+ let p = ci.func.value.p;
let npc = ci.pcOff; // pcRel(ci.u.l.savedpc, p);
let newline = p.lineinfo ? p.lineinfo[npc] : -1;
if (npc === 0 || /* call linehook when enter a new function, */
diff --git a/src/ldo.js b/src/ldo.js
index 6b37e14..1e9d355 100644
--- a/src/ldo.js
+++ b/src/ldo.js
@@ -52,7 +52,7 @@ const luaD_precall = function(L, off, nresults) {
switch(func.type) {
case CT.LUA_TCCL:
case CT.LUA_TLCF: {
- let f = func.type === CT.LUA_TCCL ? func.f : func.value;
+ let f = func.type === CT.LUA_TCCL ? func.value.f : func.value;
// next_ci
if (L.ci.next) {
@@ -85,7 +85,7 @@ const luaD_precall = function(L, off, nresults) {
return true;
}
case CT.LUA_TLCL: {
- let p = func.p;
+ let p = func.value.p;
let n = L.top - off - 1;
let fsize = p.maxstacksize;
let base;
diff --git a/src/lobject.js b/src/lobject.js
index d7751b3..f7d07d7 100644
--- a/src/lobject.js
+++ b/src/lobject.js
@@ -195,11 +195,9 @@ const table_index = function(table, key) {
return v ? v : luaO_nilobject;
};
-class LClosure extends TValue {
+class LClosure {
constructor(L, n) {
- super(CT.LUA_TLCL, null);
-
this.p = null;
this.nupvalues = n;
@@ -213,22 +211,16 @@ class LClosure extends TValue {
this.upvals = [
_ENV
];
-
- this.value = this;
}
}
-class CClosure extends TValue {
+class CClosure {
constructor(f, n) {
- super(CT.LUA_TCCL, null);
-
this.f = f;
this.nupvalues = n;
this.upvalue = new Array(n);
-
- this.value = this;
}
}
diff --git a/src/lparser.js b/src/lparser.js
index 86b286a..b8cfeed 100644
--- a/src/lparser.js
+++ b/src/lparser.js
@@ -1546,7 +1546,7 @@ const luaY_parser = function(L, z, buff, dyd, name, firstchar) {
let lexstate = new llex.LexState();
let funcstate = new FuncState();
let cl = lfunc.luaF_newLclosure(L, 1); /* create main closure */
- L.stack[L.top++] = cl;
+ L.stack[L.top++] = new TValue(defs.CT.LUA_TLCL, cl);
lexstate.h = new TValue(defs.CT.LUA_TTABLE, ltable.luaH_new(L)); /* create table for scanner */
L.stack[L.top++] = lexstate.h;
funcstate.f = cl.p = new Proto(L);
diff --git a/src/lundump.js b/src/lundump.js
index 3d7233c..9162501 100644
--- a/src/lundump.js
+++ b/src/lundump.js
@@ -282,7 +282,7 @@ class BytecodeParser {
let cl = new lobject.LClosure(this.L, this.readByte());
- this.L.stack[this.L.top] = cl;
+ this.L.stack[this.L.top] = new lobject.TValue(defs.CT.LUA_TLCL, cl);
this.L.top++;
cl.p = new Proto();
diff --git a/src/lvm.js b/src/lvm.js
index 7f4392f..24822b6 100644
--- a/src/lvm.js
+++ b/src/lvm.js
@@ -114,7 +114,7 @@ const luaV_execute = function(L) {
specialCase = null;
} else {
ci = L.ci;
- cl = ci.func;
+ cl = ci.func.value;
k = cl.p.k;
base = ci.u.l.base;
@@ -523,7 +523,7 @@ const luaV_execute = function(L) {
let nfuncOff = nci.funcOff;
let ofunc = oci.func;
let ofuncOff = oci.funcOff;
- let lim = nci.u.l.base + nfunc.p.numparams;
+ let lim = nci.u.l.base + nfunc.value.p.numparams;
if (cl.p.p.length > 0) lfunc.luaF_close(L, oci.u.l.base);
for (let aux = 0; nfuncOff + aux < lim; aux++)
L.stack[ofuncOff + aux] = L.stack[nfuncOff + aux];
@@ -538,7 +538,7 @@ const luaV_execute = function(L) {
ci = L.ci;
L.ciOff--;
- assert(L.top === oci.u.l.base + L.stack[ofuncOff].p.maxstacksize);
+ assert(L.top === oci.u.l.base + L.stack[ofuncOff].value.p.maxstacksize);
continue newframe;
}
@@ -668,7 +668,7 @@ const luaV_execute = function(L) {
let ncl = new LClosure(L, nup);
ncl.p = p;
- L.stack[ra] = ncl;
+ L.stack[ra] = new TValue(CT.LUA_TLCL, ncl);
for (let i = 0; i < nup; i++) {
if (uv[i].instack)