diff options
| author | Li Jin <dragon-fly@qq.com> | 2021-01-05 16:48:53 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2021-01-05 16:48:53 +0800 |
| commit | 71b9532659abb531bd1597d88451426dcc895824 (patch) | |
| tree | c9b50856b37f759c9a31e1a6e761e77b51996fa6 /src/lua/llex.c | |
| parent | e3a31f9945053d8e8d9e4ef3d2e4c9abe563cff2 (diff) | |
| download | yuescript-71b9532659abb531bd1597d88451426dcc895824.tar.gz yuescript-71b9532659abb531bd1597d88451426dcc895824.tar.bz2 yuescript-71b9532659abb531bd1597d88451426dcc895824.zip | |
update Lua.
Diffstat (limited to 'src/lua/llex.c')
| -rw-r--r-- | src/lua/llex.c | 56 |
1 files changed, 30 insertions, 26 deletions
diff --git a/src/lua/llex.c b/src/lua/llex.c index 3d6b2b9..e991517 100644 --- a/src/lua/llex.c +++ b/src/lua/llex.c | |||
| @@ -122,26 +122,29 @@ l_noret luaX_syntaxerror (LexState *ls, const char *msg) { | |||
| 122 | 122 | ||
| 123 | 123 | ||
| 124 | /* | 124 | /* |
| 125 | ** creates a new string and anchors it in scanner's table so that | 125 | ** Creates a new string and anchors it in scanner's table so that it |
| 126 | ** it will not be collected until the end of the compilation | 126 | ** will not be collected until the end of the compilation; by that time |
| 127 | ** (by that time it should be anchored somewhere) | 127 | ** it should be anchored somewhere. It also internalizes long strings, |
| 128 | ** ensuring there is only one copy of each unique string. The table | ||
| 129 | ** here is used as a set: the string enters as the key, while its value | ||
| 130 | ** is irrelevant. We use the string itself as the value only because it | ||
| 131 | ** is a TValue readly available. Later, the code generation can change | ||
| 132 | ** this value. | ||
| 128 | */ | 133 | */ |
| 129 | TString *luaX_newstring (LexState *ls, const char *str, size_t l) { | 134 | TString *luaX_newstring (LexState *ls, const char *str, size_t l) { |
| 130 | lua_State *L = ls->L; | 135 | lua_State *L = ls->L; |
| 131 | TValue *o; /* entry for 'str' */ | ||
| 132 | TString *ts = luaS_newlstr(L, str, l); /* create new string */ | 136 | TString *ts = luaS_newlstr(L, str, l); /* create new string */ |
| 133 | setsvalue2s(L, L->top++, ts); /* temporarily anchor it in stack */ | 137 | const TValue *o = luaH_getstr(ls->h, ts); |
| 134 | o = luaH_set(L, ls->h, s2v(L->top - 1)); | 138 | if (!ttisnil(o)) /* string already present? */ |
| 135 | if (isempty(o)) { /* not in use yet? */ | 139 | ts = keystrval(nodefromval(o)); /* get saved copy */ |
| 136 | /* boolean value does not need GC barrier; | 140 | else { /* not in use yet */ |
| 137 | table is not a metatable, so it does not need to invalidate cache */ | 141 | TValue *stv = s2v(L->top++); /* reserve stack space for string */ |
| 138 | setbtvalue(o); /* t[string] = true */ | 142 | setsvalue(L, stv, ts); /* temporarily anchor the string */ |
| 143 | luaH_finishset(L, ls->h, stv, o, stv); /* t[string] = string */ | ||
| 144 | /* table is not a metatable, so it does not need to invalidate cache */ | ||
| 139 | luaC_checkGC(L); | 145 | luaC_checkGC(L); |
| 146 | L->top--; /* remove string from stack */ | ||
| 140 | } | 147 | } |
| 141 | else { /* string already present */ | ||
| 142 | ts = keystrval(nodefromval(o)); /* re-use value previously stored */ | ||
| 143 | } | ||
| 144 | L->top--; /* remove string from stack */ | ||
| 145 | return ts; | 148 | return ts; |
| 146 | } | 149 | } |
| 147 | 150 | ||
| @@ -254,9 +257,10 @@ static int read_numeral (LexState *ls, SemInfo *seminfo) { | |||
| 254 | 257 | ||
| 255 | 258 | ||
| 256 | /* | 259 | /* |
| 257 | ** reads a sequence '[=*[' or ']=*]', leaving the last bracket. | 260 | ** read a sequence '[=*[' or ']=*]', leaving the last bracket. If |
| 258 | ** If sequence is well formed, return its number of '='s + 2; otherwise, | 261 | ** sequence is well formed, return its number of '='s + 2; otherwise, |
| 259 | ** return 1 if there is no '='s or 0 otherwise (an unfinished '[==...'). | 262 | ** return 1 if it is a single bracket (no '='s and no 2nd bracket); |
| 263 | ** otherwise (an unfinished '[==...') return 0. | ||
| 260 | */ | 264 | */ |
| 261 | static size_t skip_sep (LexState *ls) { | 265 | static size_t skip_sep (LexState *ls) { |
| 262 | size_t count = 0; | 266 | size_t count = 0; |
| @@ -481,34 +485,34 @@ static int llex (LexState *ls, SemInfo *seminfo) { | |||
| 481 | } | 485 | } |
| 482 | case '=': { | 486 | case '=': { |
| 483 | next(ls); | 487 | next(ls); |
| 484 | if (check_next1(ls, '=')) return TK_EQ; | 488 | if (check_next1(ls, '=')) return TK_EQ; /* '==' */ |
| 485 | else return '='; | 489 | else return '='; |
| 486 | } | 490 | } |
| 487 | case '<': { | 491 | case '<': { |
| 488 | next(ls); | 492 | next(ls); |
| 489 | if (check_next1(ls, '=')) return TK_LE; | 493 | if (check_next1(ls, '=')) return TK_LE; /* '<=' */ |
| 490 | else if (check_next1(ls, '<')) return TK_SHL; | 494 | else if (check_next1(ls, '<')) return TK_SHL; /* '<<' */ |
| 491 | else return '<'; | 495 | else return '<'; |
| 492 | } | 496 | } |
| 493 | case '>': { | 497 | case '>': { |
| 494 | next(ls); | 498 | next(ls); |
| 495 | if (check_next1(ls, '=')) return TK_GE; | 499 | if (check_next1(ls, '=')) return TK_GE; /* '>=' */ |
| 496 | else if (check_next1(ls, '>')) return TK_SHR; | 500 | else if (check_next1(ls, '>')) return TK_SHR; /* '>>' */ |
| 497 | else return '>'; | 501 | else return '>'; |
| 498 | } | 502 | } |
| 499 | case '/': { | 503 | case '/': { |
| 500 | next(ls); | 504 | next(ls); |
| 501 | if (check_next1(ls, '/')) return TK_IDIV; | 505 | if (check_next1(ls, '/')) return TK_IDIV; /* '//' */ |
| 502 | else return '/'; | 506 | else return '/'; |
| 503 | } | 507 | } |
| 504 | case '~': { | 508 | case '~': { |
| 505 | next(ls); | 509 | next(ls); |
| 506 | if (check_next1(ls, '=')) return TK_NE; | 510 | if (check_next1(ls, '=')) return TK_NE; /* '~=' */ |
| 507 | else return '~'; | 511 | else return '~'; |
| 508 | } | 512 | } |
| 509 | case ':': { | 513 | case ':': { |
| 510 | next(ls); | 514 | next(ls); |
| 511 | if (check_next1(ls, ':')) return TK_DBCOLON; | 515 | if (check_next1(ls, ':')) return TK_DBCOLON; /* '::' */ |
| 512 | else return ':'; | 516 | else return ':'; |
| 513 | } | 517 | } |
| 514 | case '"': case '\'': { /* short literal strings */ | 518 | case '"': case '\'': { /* short literal strings */ |
| @@ -547,7 +551,7 @@ static int llex (LexState *ls, SemInfo *seminfo) { | |||
| 547 | return TK_NAME; | 551 | return TK_NAME; |
| 548 | } | 552 | } |
| 549 | } | 553 | } |
| 550 | else { /* single-char tokens (+ - / ...) */ | 554 | else { /* single-char tokens ('+', '*', '%', '{', '}', ...) */ |
| 551 | int c = ls->current; | 555 | int c = ls->current; |
| 552 | next(ls); | 556 | next(ls); |
| 553 | return c; | 557 | return c; |
