summaryrefslogtreecommitdiff
path: root/src/lfunc.js
diff options
context:
space:
mode:
authorBenoit Giannangeli <giann@users.noreply.github.com>2017-03-01 11:54:57 +0100
committerBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-03-01 12:19:22 +0100
commit166b951b9d05eff654ef664124f17c8a37f418a6 (patch)
treea783d5f05cd640d06065c514b87bc7cf74f5e506 /src/lfunc.js
parent94a301a27a8a75c4684790a99a898262b8354f68 (diff)
parent444182dbbb18f44cf7cafc378f092c28006be365 (diff)
downloadfengari-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/lfunc.js')
-rw-r--r--src/lfunc.js24
1 files changed, 20 insertions, 4 deletions
diff --git a/src/lfunc.js b/src/lfunc.js
index 3b3c8ce..227606d 100644
--- a/src/lfunc.js
+++ b/src/lfunc.js
@@ -1,6 +1,8 @@
/*jshint esversion: 6 */
"use strict";
-const assert = require('assert');
+const assert = require('assert');
+
+const lobject = require('./lobject.js');
class Proto {
@@ -53,6 +55,15 @@ class UpVal {
}
+const luaF_newLclosure = function(L, n) {
+ let c = new lobject.LClosure();
+ c.p = null;
+ c.nupvalues = n;
+ while (n--) c.upvals[n] = null;
+ return c;
+};
+
+
const findupval = function(L, level) {
let pp = L.openupval;
@@ -91,12 +102,16 @@ const luaF_close = function(L, level) {
}
};
+/*
+** fill a closure with new closed upvalues
+*/
const luaF_initupvals = function(L, cl) {
for (let i = 0; i < cl.nupvalues; i++) {
let uv = new UpVal(L);
uv.refcount = 1;
uv.u.value = null;
uv.v = uv.u.value;
+ cl.upvals[i] = uv;
}
};
@@ -108,7 +123,7 @@ const luaF_getlocalname = function(f, local_number, pc) {
for (let i = 0; i < f.locvars.length && f.locvars[i].startpc <= pc; i++) {
if (pc < f.locvars[i].endpc) { /* is variable active? */
local_number--;
- if (local_number == 0)
+ if (local_number === 0)
return f.locvars[i].varname;
}
}
@@ -116,10 +131,11 @@ const luaF_getlocalname = function(f, local_number, pc) {
}
+module.exports.MAXUPVAL = 255;
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_getlocalname = luaF_getlocalname
module.exports.luaF_initupvals = luaF_initupvals;
-module.exports.luaF_getlocalname = luaF_getlocalname \ No newline at end of file
+module.exports.luaF_newLclosure = luaF_newLclosure; \ No newline at end of file