#/bin/sh wget -c https://www.lua.org/work/lua-5.4.0-alpha.tar.gz cat > patch.txt <<'EOF' diff -r 55beab95170f src/Makefile --- a/src/Makefile Mon Jul 15 19:07:40 2019 +0300 +++ b/src/Makefile Mon Jul 15 19:08:06 2019 +0300 @@ -7,7 +7,8 @@ PLAT= none CC= gcc -std=gnu99 -CFLAGS= -O2 -Wall -Wextra -DLUA_COMPAT_5_3 $(SYSCFLAGS) $(MYCFLAGS) +#CFLAGS= -O2 -Wall -Wextra -DLUA_COMPAT_5_3 $(SYSCFLAGS) $(MYCFLAGS) +CFLAGS= -O2 -Wall -Wextra $(SYSCFLAGS) $(MYCFLAGS) LDFLAGS= $(SYSLDFLAGS) $(MYLDFLAGS) LIBS= -lm $(SYSLIBS) $(MYLIBS) diff -r 55beab95170f src/llex.c --- a/src/llex.c Mon Jul 15 19:07:40 2019 +0300 +++ b/src/llex.c Mon Jul 15 19:08:06 2019 +0300 @@ -41,7 +41,7 @@ "and", "break", "do", "else", "elseif", "end", "false", "for", "function", "goto", "if", "in", "local", "nil", "not", "or", "repeat", - "return", "then", "true", "until", "while", + "return", "then", "true", "until", "pure", "while", "//", "..", "...", "==", ">=", "<=", "~=", "<<", ">>", "::", "", "", "", "", "" diff -r 55beab95170f src/llex.h --- a/src/llex.h Mon Jul 15 19:07:40 2019 +0300 +++ b/src/llex.h Mon Jul 15 19:08:06 2019 +0300 @@ -28,7 +28,7 @@ TK_AND = FIRST_RESERVED, TK_BREAK, TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION, TK_GOTO, TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT, - TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE, + TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_PURE, TK_WHILE, /* other terminal symbols */ TK_IDIV, TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, TK_SHL, TK_SHR, diff -r 55beab95170f src/lparser.c --- a/src/lparser.c Mon Jul 15 19:07:40 2019 +0300 +++ b/src/lparser.c Mon Jul 15 19:08:06 2019 +0300 @@ -367,6 +367,10 @@ markupval(fs, v); /* local will be used as an upval */ } else { /* not found as local at current level; try upvalues */ + if (fs->pure) { + var->k=VVOID; + return; + } int idx = searchupvalue(fs, n); /* try existing upvalues */ if (idx < 0) { /* not found? */ singlevaraux(fs->prev, n, var, 0); /* try upper levels */ @@ -391,6 +395,12 @@ singlevaraux(fs, varname, var, 1); if (var->k == VVOID) { /* global name? */ expdesc key; + if (fs->pure) { + const char *msg = "'%s' is unreacheble in pure function"; + msg = luaO_pushfstring(ls->L, msg, getstr(varname)); + luaK_semerror(ls, msg); /* error */ + return; + } singlevaraux(fs, ls->envn, var, 1); /* get environment variable */ lua_assert(var->k != VVOID); /* this one must exist */ codestring(ls, &key, varname); /* key is variable name */ @@ -667,6 +677,7 @@ fs->nlocvars = 0; fs->nactvar = 0; fs->needclose = 0; + fs->pure = 0; fs->firstlocal = ls->dyd->actvar.n; fs->firstlabel = ls->dyd->label.n; fs->bl = NULL; @@ -924,6 +935,10 @@ } parlist(ls); checknext(ls, ')'); + if (ls->t.token==TK_PURE) { + luaX_next(ls); /* skip pure */ + new_fs.pure=1; + } statlist(ls); new_fs.f->lastlinedefined = ls->linenumber; check_match(ls, TK_END, TK_FUNCTION, line); diff -r 55beab95170f src/lparser.h --- a/src/lparser.h Mon Jul 15 19:07:40 2019 +0300 +++ b/src/lparser.h Mon Jul 15 19:08:06 2019 +0300 @@ -141,6 +141,7 @@ lu_byte freereg; /* first free register */ lu_byte iwthabs; /* instructions issued since last absolute line info */ lu_byte needclose; /* function needs to close upvalues when returning */ + lu_byte pure; } FuncState; EOF tar xf lua-5.4.0-alpha.tar.gz cd lua-5.4.0-alpha patch -p 1 < ../patch.txt make linux-readline cp src/{lua,luac} .. cd ..