diff options
| author | Li Jin <dragon-fly@qq.com> | 2025-07-17 19:22:33 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2025-07-17 19:22:33 +0800 |
| commit | 828fee1907a8fd8773d304d3d9a49fc0e2f8cb84 (patch) | |
| tree | f4b82e38c793fee7141b5d8f4d326fd31bee985e | |
| parent | c03bf36db11bcd90034b0e67bd1f5c8c0765eb7f (diff) | |
| download | yuescript-828fee1907a8fd8773d304d3d9a49fc0e2f8cb84.tar.gz yuescript-828fee1907a8fd8773d304d3d9a49fc0e2f8cb84.tar.bz2 yuescript-828fee1907a8fd8773d304d3d9a49fc0e2f8cb84.zip | |
Fixed a crash.
| -rw-r--r-- | spec/outputs/codes_from_doc.lua | 29 | ||||
| -rw-r--r-- | spec/outputs/codes_from_doc_zh.lua | 29 | ||||
| -rw-r--r-- | src/yuescript/yue_compiler.cpp | 14 |
3 files changed, 41 insertions, 31 deletions
diff --git a/spec/outputs/codes_from_doc.lua b/spec/outputs/codes_from_doc.lua index 085179c..f1e46d9 100644 --- a/spec/outputs/codes_from_doc.lua +++ b/spec/outputs/codes_from_doc.lua | |||
| @@ -209,14 +209,16 @@ for _key_0, _value_0 in pairs(b) do | |||
| 209 | end | 209 | end |
| 210 | end | 210 | end |
| 211 | merge = _tab_0 | 211 | merge = _tab_0 |
| 212 | print((function() | 212 | local last |
| 213 | do | ||
| 213 | local _item_0 = data.items | 214 | local _item_0 = data.items |
| 214 | return _item_0[#_item_0] | 215 | last = _item_0[#_item_0] |
| 215 | end)()) | 216 | end |
| 216 | print((function() | 217 | local second_last |
| 218 | do | ||
| 217 | local _item_0 = data.items | 219 | local _item_0 = data.items |
| 218 | return _item_0[#_item_0 - 1] | 220 | second_last = _item_0[#_item_0 - 1] |
| 219 | end)()) | 221 | end |
| 220 | local mt = { } | 222 | local mt = { } |
| 221 | local add | 223 | local add |
| 222 | add = function(self, right) | 224 | add = function(self, right) |
| @@ -2603,14 +2605,16 @@ for _key_0, _value_0 in pairs(b) do | |||
| 2603 | end | 2605 | end |
| 2604 | end | 2606 | end |
| 2605 | merge = _tab_0 | 2607 | merge = _tab_0 |
| 2606 | print((function() | 2608 | local last |
| 2609 | do | ||
| 2607 | local _item_0 = data.items | 2610 | local _item_0 = data.items |
| 2608 | return _item_0[#_item_0] | 2611 | last = _item_0[#_item_0] |
| 2609 | end)()) | 2612 | end |
| 2610 | print((function() | 2613 | local second_last |
| 2614 | do | ||
| 2611 | local _item_0 = data.items | 2615 | local _item_0 = data.items |
| 2612 | return _item_0[#_item_0 - 1] | 2616 | second_last = _item_0[#_item_0 - 1] |
| 2613 | end)()) | 2617 | end |
| 2614 | local mt = { } | 2618 | local mt = { } |
| 2615 | local add | 2619 | local add |
| 2616 | add = function(self, right) | 2620 | add = function(self, right) |
| @@ -3207,6 +3211,7 @@ local some_string = "Here is a string\n that has a line break in it." | |||
| 3207 | print("I am " .. tostring(math.random() * 100) .. "% sure.") | 3211 | print("I am " .. tostring(math.random() * 100) .. "% sure.") |
| 3208 | local integer = 1000000 | 3212 | local integer = 1000000 |
| 3209 | local hex = 0xEFBBBF | 3213 | local hex = 0xEFBBBF |
| 3214 | local binary = 19 | ||
| 3210 | local my_function | 3215 | local my_function |
| 3211 | my_function = function() end | 3216 | my_function = function() end |
| 3212 | my_function() | 3217 | my_function() |
diff --git a/spec/outputs/codes_from_doc_zh.lua b/spec/outputs/codes_from_doc_zh.lua index bb9af58..4689232 100644 --- a/spec/outputs/codes_from_doc_zh.lua +++ b/spec/outputs/codes_from_doc_zh.lua | |||
| @@ -209,14 +209,16 @@ for _key_0, _value_0 in pairs(b) do | |||
| 209 | end | 209 | end |
| 210 | end | 210 | end |
| 211 | merge = _tab_0 | 211 | merge = _tab_0 |
| 212 | print((function() | 212 | local last |
| 213 | do | ||
| 213 | local _item_0 = data.items | 214 | local _item_0 = data.items |
| 214 | return _item_0[#_item_0] | 215 | last = _item_0[#_item_0] |
| 215 | end)()) | 216 | end |
| 216 | print((function() | 217 | local second_last |
| 218 | do | ||
| 217 | local _item_0 = data.items | 219 | local _item_0 = data.items |
| 218 | return _item_0[#_item_0 - 1] | 220 | second_last = _item_0[#_item_0 - 1] |
| 219 | end)()) | 221 | end |
| 220 | local mt = { } | 222 | local mt = { } |
| 221 | local add | 223 | local add |
| 222 | add = function(self, right) | 224 | add = function(self, right) |
| @@ -2597,14 +2599,16 @@ for _key_0, _value_0 in pairs(b) do | |||
| 2597 | end | 2599 | end |
| 2598 | end | 2600 | end |
| 2599 | merge = _tab_0 | 2601 | merge = _tab_0 |
| 2600 | print((function() | 2602 | local last |
| 2603 | do | ||
| 2601 | local _item_0 = data.items | 2604 | local _item_0 = data.items |
| 2602 | return _item_0[#_item_0] | 2605 | last = _item_0[#_item_0] |
| 2603 | end)()) | 2606 | end |
| 2604 | print((function() | 2607 | local second_last |
| 2608 | do | ||
| 2605 | local _item_0 = data.items | 2609 | local _item_0 = data.items |
| 2606 | return _item_0[#_item_0 - 1] | 2610 | second_last = _item_0[#_item_0 - 1] |
| 2607 | end)()) | 2611 | end |
| 2608 | local mt = { } | 2612 | local mt = { } |
| 2609 | local add | 2613 | local add |
| 2610 | add = function(self, right) | 2614 | add = function(self, right) |
| @@ -3201,6 +3205,7 @@ local some_string = "这是一个字符串\n 并包括一个换行。" | |||
| 3201 | print("我有" .. tostring(math.random() * 100) .. "%的把握。") | 3205 | print("我有" .. tostring(math.random() * 100) .. "%的把握。") |
| 3202 | local integer = 1000000 | 3206 | local integer = 1000000 |
| 3203 | local hex = 0xEFBBBF | 3207 | local hex = 0xEFBBBF |
| 3208 | local binary = 19 | ||
| 3204 | local my_function | 3209 | local my_function |
| 3205 | my_function = function() end | 3210 | my_function = function() end |
| 3206 | my_function() | 3211 | my_function() |
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index 35d99bd..f952e9a 100644 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp | |||
| @@ -5448,14 +5448,14 @@ private: | |||
| 5448 | if (argsDef->varArg) { | 5448 | if (argsDef->varArg) { |
| 5449 | newArgs.emplace_back(_parser.toString(argsDef->varArg)); | 5449 | newArgs.emplace_back(_parser.toString(argsDef->varArg)); |
| 5450 | } | 5450 | } |
| 5451 | } | 5451 | if (argsDef->label) { |
| 5452 | if (argsDef->label) { | 5452 | hasCheck = true; |
| 5453 | hasCheck = true; | 5453 | const auto& astName = _parser.toString(argsDef->label); |
| 5454 | const auto& astName = _parser.toString(argsDef->label); | 5454 | if (!_parser.hasAST(astName)) { |
| 5455 | if (!_parser.hasAST(astName)) { | 5455 | throw CompileError("invalid AST name"sv, argsDef->label); |
| 5456 | throw CompileError("invalid AST name"sv, argsDef->label); | 5456 | } |
| 5457 | argChecks.emplace_back("..."s + astName); | ||
| 5457 | } | 5458 | } |
| 5458 | argChecks.emplace_back("..."s + astName); | ||
| 5459 | } | 5459 | } |
| 5460 | std::string macroCodes = "_ENV=require('yue').macro_env\n("s + join(newArgs, ","sv) + ")->"s + _parser.toString(macroLit->body); | 5460 | std::string macroCodes = "_ENV=require('yue').macro_env\n("s + join(newArgs, ","sv) + ")->"s + _parser.toString(macroLit->body); |
| 5461 | auto chunkName = "=(macro "s + macroName + ')'; | 5461 | auto chunkName = "=(macro "s + macroName + ')'; |
