diff options
| author | Benoit Giannangeli <benoit.giannangeli@boursorama.fr> | 2017-02-17 09:27:51 +0100 | 
|---|---|---|
| committer | Benoit Giannangeli <benoit.giannangeli@boursorama.fr> | 2017-02-17 09:27:51 +0100 | 
| commit | 50aa5b5029165be03d0cfb34e7d664795dd80898 (patch) | |
| tree | dc42e1a73ac367fef1a88c3dd0502a0879eebea3 /src | |
| parent | 4eea48935f2e0ea1267d314f2900af2a1a4b8b02 (diff) | |
| download | fengari-50aa5b5029165be03d0cfb34e7d664795dd80898.tar.gz fengari-50aa5b5029165be03d0cfb34e7d664795dd80898.tar.bz2 fengari-50aa5b5029165be03d0cfb34e7d664795dd80898.zip  | |
More accurate state and closure init
Diffstat (limited to 'src')
| -rw-r--r-- | src/lapi.js | 1 | ||||
| -rw-r--r-- | src/ldo.js | 22 | ||||
| -rw-r--r-- | src/lfunc.js | 20 | ||||
| -rw-r--r-- | src/lstate.js | 21 | ||||
| -rw-r--r-- | src/lundump.js | 6 | 
5 files changed, 48 insertions, 22 deletions
diff --git a/src/lapi.js b/src/lapi.js index 0e3c3bd..976841d 100644 --- a/src/lapi.js +++ b/src/lapi.js @@ -10,6 +10,7 @@ const lfunc     = require('./lfunc.js');  const lua       = require('./lua.js');  const lstate    = require('./lstate.js');  const lvm       = require('./lvm.js'); +const lundump   = require('./lundump.js');  const MAXUPVAL  = lfunc.MAXUPVAL;  const CT        = lua.constant_types;  const TS        = lua.thread_status; @@ -261,6 +261,28 @@ const luaD_callnoyield = function(L, off, nResults) {    L.nny--;  }; +// TODO: since we only handle binary, no need for a reader or mode +const f_parser = function(L, data) { +    assert(data instanceof DataView, "data must be a DataView"); + +    let p = new lundump.BytecodeParser(data); +    let cl = p.luaU_undump(); + +    assert(cl.nupvalues == cl.p.sizeupvalues); + +    lfunc.luaF_initupvals(L, cl); +}; + +const luaD_protectedparser = function(L, data, name) { +    L.nny++; + +    let status = luaD_pcall(L, f_parser, data, L.top, L.errfunc); + +    L.nny--; + +    return status; +}; +  module.exports.nil                        = nil;  module.exports.luaD_precall               = luaD_precall;  module.exports.luaD_poscall               = luaD_poscall; diff --git a/src/lfunc.js b/src/lfunc.js index f3e11d3..39ad049 100644 --- a/src/lfunc.js +++ b/src/lfunc.js @@ -88,8 +88,18 @@ const luaF_close = function(L, level) {      }  }; -module.exports.Proto      = Proto; -module.exports.UpVal      = UpVal; -module.exports.findupval  = findupval; -module.exports.luaF_close = luaF_close; -module.exports.MAXUPVAL   = 255;
\ No newline at end of file +const luaF_initupvals = function(L, cl) { +    for (let i = 0; i < cl.nupvalues; i++) { +        let uv = new UpVal(); +        uv.refcount = 1; +        uv.u.value = null; +        uv.v = uv.u.value; +    } +}; + +module.exports.Proto            = Proto; +module.exports.UpVal            = UpVal; +module.exports.findupval        = findupval; +module.exports.luaF_close       = luaF_close; +module.exports.MAXUPVAL         = 255; +module.exports.luaF_initupvals  = luaF_initupvals;
\ No newline at end of file diff --git a/src/lstate.js b/src/lstate.js index 4d71be7..54e7ac7 100644 --- a/src/lstate.js +++ b/src/lstate.js @@ -44,22 +44,11 @@ class CallInfo {  class lua_State {      constructor(cl) { -        if (cl) { // TODO: remove -            this.top = 1; -            this.ci = new CallInfo(0, cl, 1, 1, null, null); -            this.ci.u.l.savedpc = cl.p.code; -            this.ci.nresults = LUA_MULTRET; -            this.ciOff = 0; -            this.stack = [ -                cl -            ]; -        } else { -            this.base_ci = new CallInfo(); // Will be populated later -            this.top = 0; -            this.ci = null; -            this.ciOff = null; -            this.stack = []; -        } +        this.base_ci = new CallInfo(); // Will be populated later +        this.top = 0; +        this.ci = null; +        this.ciOff = null; +        this.stack = [];          this.openupval = [];          this.status = TS.LUA_OK;          this.next = null; diff --git a/src/lundump.js b/src/lundump.js index 0ff3143..ab1dd6f 100644 --- a/src/lundump.js +++ b/src/lundump.js @@ -290,10 +290,14 @@ class BytecodeParser {      } -    luaU_undump() { +    luaU_undump(L) {          this.checkHeader();          let cl = new LClosure(this.readByte()); + +        L.stack[L.top] = cl; +        L.top++; +          cl.p = new Proto();          this.readFunction(cl.p);  | 
