summaryrefslogtreecommitdiff
path: root/libs/liblua/src/lcode.c
diff options
context:
space:
mode:
authoraunsane <aunsane@gmail.com>2016-12-27 00:46:46 +0300
committeraunsane <aunsane@gmail.com>2016-12-27 00:47:12 +0300
commit4f5ab8c9b5866c4445d8f37f608244ea9bf4494f (patch)
tree2e1e5a3dee91e0c8f9aed1cdc8f2465d9e1b3d35 /libs/liblua/src/lcode.c
parentab80b3e01ac99d5f31e2de10bf8299579afa87b4 (diff)
Updated lua lib to 5.3.4
Diffstat (limited to 'libs/liblua/src/lcode.c')
-rw-r--r--libs/liblua/src/lcode.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/libs/liblua/src/lcode.c b/libs/liblua/src/lcode.c
index 2cd0dd2d5c..aca0256d44 100644
--- a/libs/liblua/src/lcode.c
+++ b/libs/liblua/src/lcode.c
@@ -1,5 +1,5 @@
/*
-** $Id: lcode.c,v 2.109 2016/05/13 19:09:21 roberto Exp $
+** $Id: lcode.c,v 2.111 2016/07/19 17:12:07 roberto Exp roberto $
** Code generator for Lua
** See Copyright Notice in lua.h
*/
@@ -40,7 +40,7 @@
** If expression is a numeric constant, fills 'v' with its value
** and returns 1. Otherwise, returns 0.
*/
-static int tonumeral(expdesc *e, TValue *v) {
+static int tonumeral(const expdesc *e, TValue *v) {
if (hasjumps(e))
return 0; /* not a numeral */
switch (e->k) {
@@ -86,7 +86,7 @@ void luaK_nil (FuncState *fs, int from, int n) {
/*
** Gets the destination address of a jump instruction. Used to traverse
** a list of jumps.
-*/
+*/
static int getjump (FuncState *fs, int pc) {
int offset = GETARG_sBx(fs->f->code[pc]);
if (offset == NO_JUMP) /* point to itself represents end of list */
@@ -754,7 +754,7 @@ void luaK_exp2val (FuncState *fs, expdesc *e) {
** (that is, it is either in a register or in 'k' with an index
** in the range of R/K indices).
** Returns R/K index.
-*/
+*/
int luaK_exp2RK (FuncState *fs, expdesc *e) {
luaK_exp2val(fs, e);
switch (e->k) { /* move constants to 'k' */
@@ -975,7 +975,8 @@ static int validop (int op, TValue *v1, TValue *v2) {
** Try to "constant-fold" an operation; return 1 iff successful.
** (In this case, 'e1' has the final result.)
*/
-static int constfolding (FuncState *fs, int op, expdesc *e1, expdesc *e2) {
+static int constfolding (FuncState *fs, int op, expdesc *e1,
+ const expdesc *e2) {
TValue v1, v2, res;
if (!tonumeral(e1, &v1) || !tonumeral(e2, &v2) || !validop(op, &v1, &v2))
return 0; /* non-numeric operands or not safe to fold */
@@ -1014,11 +1015,14 @@ static void codeunexpval (FuncState *fs, OpCode op, expdesc *e, int line) {
** (everything but logical operators 'and'/'or' and comparison
** operators).
** Expression to produce final result will be encoded in 'e1'.
+** Because 'luaK_exp2RK' can free registers, its calls must be
+** in "stack order" (that is, first on 'e2', which may have more
+** recent registers to be released).
*/
static void codebinexpval (FuncState *fs, OpCode op,
expdesc *e1, expdesc *e2, int line) {
- int rk1 = luaK_exp2RK(fs, e1); /* both operands are "RK" */
- int rk2 = luaK_exp2RK(fs, e2);
+ int rk2 = luaK_exp2RK(fs, e2); /* both operands are "RK" */
+ int rk1 = luaK_exp2RK(fs, e1);
freeexps(fs, e1, e2);
e1->u.info = luaK_codeABC(fs, op, 0, rk1, rk2); /* generate opcode */
e1->k = VRELOCABLE; /* all those operations are relocatable */
@@ -1060,9 +1064,9 @@ static void codecomp (FuncState *fs, BinOpr opr, expdesc *e1, expdesc *e2) {
** Aplly prefix operation 'op' to expression 'e'.
*/
void luaK_prefix (FuncState *fs, UnOpr op, expdesc *e, int line) {
- static expdesc ef = {VKINT, {0}, NO_JUMP, NO_JUMP}; /* fake 2nd operand */
+ static const expdesc ef = {VKINT, {0}, NO_JUMP, NO_JUMP};
switch (op) {
- case OPR_MINUS: case OPR_BNOT:
+ case OPR_MINUS: case OPR_BNOT: /* use 'ef' as fake 2nd operand */
if (constfolding(fs, op + LUA_OPUNM, e, &ef))
break;
/* FALLTHROUGH */