diff options
author | Benoit Giannangeli <giann@users.noreply.github.com> | 2017-03-01 11:54:57 +0100 |
---|---|---|
committer | Benoit Giannangeli <benoit.giannangeli@boursorama.fr> | 2017-03-01 12:19:22 +0100 |
commit | 166b951b9d05eff654ef664124f17c8a37f418a6 (patch) | |
tree | a783d5f05cd640d06065c514b87bc7cf74f5e506 /src/lapi.js | |
parent | 94a301a27a8a75c4684790a99a898262b8354f68 (diff) | |
parent | 444182dbbb18f44cf7cafc378f092c28006be365 (diff) | |
download | fengari-166b951b9d05eff654ef664124f17c8a37f418a6.tar.gz fengari-166b951b9d05eff654ef664124f17c8a37f418a6.tar.bz2 fengari-166b951b9d05eff654ef664124f17c8a37f418a6.zip |
Merge pull request #2 from giann/feature/lex-parse
Lexing & Parsing
Diffstat (limited to 'src/lapi.js')
-rw-r--r-- | src/lapi.js | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/src/lapi.js b/src/lapi.js index d0c099f..36da7c6 100644 --- a/src/lapi.js +++ b/src/lapi.js @@ -1,18 +1,18 @@ -/* jshint esversion: 6 */ "use strict"; const assert = require('assert'); +const ldebug = require('./ldebug.js'); const ldo = require('./ldo.js'); +const lfunc = require('./lfunc.js'); +const llex = require('./llex.js'); const lobject = require('./lobject.js'); +const lstate = require('./lstate.js'); const ltm = require('./ltm.js'); -const lfunc = require('./lfunc.js'); const lua = require('./lua.js'); const luaconf = require('./luaconf.js'); -const lstate = require('./lstate.js'); -const lvm = require('./lvm.js'); const lundump = require('./lundump.js'); -const ldebug = require('./ldebug.js'); +const lvm = require('./lvm.js'); const MAXUPVAL = lfunc.MAXUPVAL; const CT = lua.constant_types; const TS = lua.thread_status; @@ -138,7 +138,7 @@ const lua_settop = function(L, idx) { const lua_pop = function(L, n) { lua_settop(L, -n - 1); -} +}; const reverse = function(L, from, to) { for (; from < to; from++, to--) { @@ -150,7 +150,7 @@ const reverse = function(L, from, to) { /* ** Let x = AB, where A is a prefix of length 'n'. Then, -** rotate x n == BA. But BA == (A^r . B^r)^r. +** rotate x n === BA. But BA === (A^r . B^r)^r. */ const lua_rotate = function(L, idx, n) { let t = L.stack[L.top - 1]; @@ -357,7 +357,7 @@ const lua_settable = function(L, idx) { }; const lua_setfield = function(L, idx, k) { - auxsetstr(L, index2addr(L, idx), k) + auxsetstr(L, index2addr(L, idx), k); }; const lua_seti = function(L, idx, n) { @@ -515,11 +515,11 @@ const lua_rawlen = function(L, idx) { }; const lua_tointeger = function(L, idx) { - return lvm.tointeger(index2addr(L, idx)) + return lvm.tointeger(index2addr(L, idx)); }; const lua_tonumber = function(L, idx) { - return lvm.tonumber(index2addr(L, idx)) + return lvm.tonumber(index2addr(L, idx)); }; const lua_tothread = function(L, idx) { @@ -587,7 +587,7 @@ const f_call = function(L, ud) { const lua_type = function(L, idx) { let o = index2addr(L, idx); - return o.ttnov(); // TODO: isvalid ? luaO_nilobject != nil tvalue ? + return o.ttnov(); // TODO: isvalid ? luaO_nilobject !== nil tvalue ? }; const lua_typename = function(L, t) { @@ -597,7 +597,7 @@ const lua_typename = function(L, t) { const lua_isnoneornil = function(L, n) { return lua_type(L, n) <= 0; -} +}; const lua_istable = function(L, idx) { return index2addr(L, idx).ttistable(); @@ -626,13 +626,14 @@ const lua_rawequal = function(L, index1, index2) { ** 'load' and 'call' functions (run Lua code) */ -const lua_load = function(L, data, chunckname) { +// TODO: reader is ignored because we don't implement ZIO +const lua_load = function(L, reader, data, chunckname, mode) { + let z = new llex.MBuffer(data); if (!chunckname) chunckname = "?"; - - let status = ldo.luaD_protectedparser(L, data, chunckname); - if (status === TS.LUA_OK) { + 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 */ - if (f.nupvalues >= 1) { /* does it have an upvalue? */ + if (f.nupvalues >= 1) { /* does it have an upvalue? */ /* get global table from registry */ let reg = L.l_G.l_registry; let gt = reg.value.get(lua.LUA_RIDX_GLOBALS - 1); @@ -640,7 +641,6 @@ const lua_load = function(L, data, chunckname) { f.upvals[0].u.value = gt; } } - return status; }; @@ -663,7 +663,7 @@ const lua_callk = function(L, nargs, nresults, ctx, k) { ldo.luaD_callnoyield(L, func, nresults); } - if (nresults == lua.LUA_MULTRET && L.ci.top < L.top) + if (nresults === lua.LUA_MULTRET && L.ci.top < L.top) L.ci.top = L.top; }; @@ -714,7 +714,7 @@ const lua_pcallk = function(L, nargs, nresults, errfunc, ctx, k) { status = TS.LUA_OK; } - if (nresults == lua.LUA_MULTRET && L.ci.top < L.top) + if (nresults === lua.LUA_MULTRET && L.ci.top < L.top) L.ci.top = L.top; return status; |