Advertisement
Guest User

lua 5.4 pure function

a guest
Jul 15th, 2019
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.69 KB | None | 0 0
  1. #/bin/sh
  2.  
  3. wget -c https://www.lua.org/work/lua-5.4.0-alpha.tar.gz
  4. cat > patch.txt <<'EOF'
  5. diff -r 55beab95170f src/Makefile
  6. --- a/src/Makefile  Mon Jul 15 19:07:40 2019 +0300
  7. +++ b/src/Makefile  Mon Jul 15 19:08:06 2019 +0300
  8. @@ -7,7 +7,8 @@
  9.  PLAT= none
  10.  
  11.  CC= gcc -std=gnu99
  12. -CFLAGS= -O2 -Wall -Wextra -DLUA_COMPAT_5_3 $(SYSCFLAGS) $(MYCFLAGS)
  13. +#CFLAGS= -O2 -Wall -Wextra -DLUA_COMPAT_5_3 $(SYSCFLAGS) $(MYCFLAGS)
  14. +CFLAGS= -O2 -Wall -Wextra $(SYSCFLAGS) $(MYCFLAGS)
  15.  LDFLAGS= $(SYSLDFLAGS) $(MYLDFLAGS)
  16.  LIBS= -lm $(SYSLIBS) $(MYLIBS)
  17.  
  18. diff -r 55beab95170f src/llex.c
  19. --- a/src/llex.c  Mon Jul 15 19:07:40 2019 +0300
  20. +++ b/src/llex.c  Mon Jul 15 19:08:06 2019 +0300
  21. @@ -41,7 +41,7 @@
  22.      "and", "break", "do", "else", "elseif",
  23.      "end", "false", "for", "function", "goto", "if",
  24.      "in", "local", "nil", "not", "or", "repeat",
  25. -    "return", "then", "true", "until", "while",
  26. +    "return", "then", "true", "until", "pure", "while",
  27.      "//", "..", "...", "==", ">=", "<=", "~=",
  28.      "<<", ">>", "::", "<eof>",
  29.      "<number>", "<integer>", "<name>", "<string>"
  30. diff -r 55beab95170f src/llex.h
  31. --- a/src/llex.h  Mon Jul 15 19:07:40 2019 +0300
  32. +++ b/src/llex.h  Mon Jul 15 19:08:06 2019 +0300
  33. @@ -28,7 +28,7 @@
  34.    TK_AND = FIRST_RESERVED, TK_BREAK,
  35.    TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION,
  36.    TK_GOTO, TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT,
  37. -  TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE,
  38. +  TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_PURE, TK_WHILE,
  39.    /* other terminal symbols */
  40.    TK_IDIV, TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE,
  41.    TK_SHL, TK_SHR,
  42. diff -r 55beab95170f src/lparser.c
  43. --- a/src/lparser.c Mon Jul 15 19:07:40 2019 +0300
  44. +++ b/src/lparser.c Mon Jul 15 19:08:06 2019 +0300
  45. @@ -367,6 +367,10 @@
  46.          markupval(fs, v);  /* local will be used as an upval */
  47.      }
  48.      else {  /* not found as local at current level; try upvalues */
  49. +      if (fs->pure) {
  50. +        var->k=VVOID;
  51. +        return;
  52. +      }
  53.        int idx = searchupvalue(fs, n);  /* try existing upvalues */
  54.        if (idx < 0) {  /* not found? */
  55.          singlevaraux(fs->prev, n, var, 0);  /* try upper levels */
  56. @@ -391,6 +395,12 @@
  57.    singlevaraux(fs, varname, var, 1);
  58.    if (var->k == VVOID) {  /* global name? */
  59.      expdesc key;
  60. +    if (fs->pure) {
  61. +      const char *msg = "'%s' is unreacheble in pure function";
  62. +      msg = luaO_pushfstring(ls->L, msg, getstr(varname));
  63. +      luaK_semerror(ls, msg);  /* error */
  64. +      return;
  65. +    }
  66.      singlevaraux(fs, ls->envn, var, 1);  /* get environment variable */
  67.      lua_assert(var->k != VVOID);  /* this one must exist */
  68.      codestring(ls, &key, varname);  /* key is variable name */
  69. @@ -667,6 +677,7 @@
  70.    fs->nlocvars = 0;
  71.    fs->nactvar = 0;
  72.    fs->needclose = 0;
  73. +  fs->pure = 0;
  74.    fs->firstlocal = ls->dyd->actvar.n;
  75.    fs->firstlabel = ls->dyd->label.n;
  76.    fs->bl = NULL;
  77. @@ -924,6 +935,10 @@
  78.    }
  79.    parlist(ls);
  80.    checknext(ls, ')');
  81. +  if (ls->t.token==TK_PURE) {
  82. +    luaX_next(ls); /* skip pure */
  83. +    new_fs.pure=1;
  84. +  }
  85.    statlist(ls);
  86.    new_fs.f->lastlinedefined = ls->linenumber;
  87.    check_match(ls, TK_END, TK_FUNCTION, line);
  88. diff -r 55beab95170f src/lparser.h
  89. --- a/src/lparser.h Mon Jul 15 19:07:40 2019 +0300
  90. +++ b/src/lparser.h Mon Jul 15 19:08:06 2019 +0300
  91. @@ -141,6 +141,7 @@
  92.    lu_byte freereg;  /* first free register */
  93.    lu_byte iwthabs;  /* instructions issued since last absolute line info */
  94.    lu_byte needclose;  /* function needs to close upvalues when returning */
  95. +  lu_byte pure;
  96.  } FuncState;
  97. EOF
  98. tar xf lua-5.4.0-alpha.tar.gz
  99. cd lua-5.4.0-alpha
  100. patch -p 1 < ../patch.txt
  101. make linux-readline
  102. cp src/{lua,luac} ..
  103. cd ..
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement