diff options
Diffstat (limited to '')
| -rw-r--r-- | src/yuescript/yue_compiler.cpp | 82 |
1 files changed, 74 insertions, 8 deletions
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index 9384214..6644ca5 100644 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp | |||
| @@ -3619,14 +3619,82 @@ private: | |||
| 3619 | auto varArg = simpleValue->value.as<VarArg_t>(); | 3619 | auto varArg = simpleValue->value.as<VarArg_t>(); |
| 3620 | BREAK_IF(!varArg); | 3620 | BREAK_IF(!varArg); |
| 3621 | auto assignAction = static_cast<Assign_t*>(expListAssign->action.get()); | 3621 | auto assignAction = static_cast<Assign_t*>(expListAssign->action.get()); |
| 3622 | bool isExps = true; | 3622 | auto newInvoke = assignAction->new_ptr<InvokeArgs_t>(); |
| 3623 | for (auto item : assignAction->values.objects()) { | 3623 | if (auto appendix = stmt->appendix.get()) { |
| 3624 | if (!ast_is<Exp_t, TableBlock_t>(item)) { | 3624 | switch (appendix->item->get_id()) { |
| 3625 | isExps = false; | 3625 | case id<IfLine_t>(): { |
| 3626 | break; | 3626 | auto if_line = static_cast<IfLine_t*>(appendix->item.get()); |
| 3627 | auto ifNode = appendix->new_ptr<If_t>(); | ||
| 3628 | ifNode->type.set(if_line->type); | ||
| 3629 | ifNode->nodes.push_back(if_line->condition); | ||
| 3630 | auto expList = appendix->new_ptr<ExpList_t>(); | ||
| 3631 | for (auto val : assignAction->values.objects()) { | ||
| 3632 | switch (val->get_id()) { | ||
| 3633 | case id<If_t>(): | ||
| 3634 | case id<Switch_t>(): | ||
| 3635 | case id<With_t>(): { | ||
| 3636 | auto simpleValue = val->new_ptr<SimpleValue_t>(); | ||
| 3637 | simpleValue->value.set(val); | ||
| 3638 | auto exp = newExp(simpleValue, val); | ||
| 3639 | expList->exprs.push_back(exp); | ||
| 3640 | break; | ||
| 3641 | } | ||
| 3642 | case id<TableBlock_t>(): { | ||
| 3643 | auto tableBlock = static_cast<TableBlock_t*>(val); | ||
| 3644 | auto tabLit = val->new_ptr<TableLit_t>(); | ||
| 3645 | tabLit->values.dup(tableBlock->values); | ||
| 3646 | auto simpleValue = val->new_ptr<SimpleValue_t>(); | ||
| 3647 | simpleValue->value.set(tabLit); | ||
| 3648 | auto exp = newExp(simpleValue, val); | ||
| 3649 | expList->exprs.push_back(exp); | ||
| 3650 | break; | ||
| 3651 | } | ||
| 3652 | case id<Exp_t>(): { | ||
| 3653 | expList->exprs.push_back(val); | ||
| 3654 | break; | ||
| 3655 | } | ||
| 3656 | default: YUEE("AST node mismatch", val); break; | ||
| 3657 | } | ||
| 3658 | } | ||
| 3659 | auto newExpListAssign = assignAction->new_ptr<ExpListAssign_t>(); | ||
| 3660 | newExpListAssign->expList.set(expList); | ||
| 3661 | auto newStmt = assignAction->new_ptr<Statement_t>(); | ||
| 3662 | newStmt->content.set(newExpListAssign); | ||
| 3663 | ifNode->nodes.push_back(newStmt); | ||
| 3664 | auto newSVal = ifNode->new_ptr<SimpleValue_t>(); | ||
| 3665 | newSVal->value.set(ifNode); | ||
| 3666 | newInvoke->args.push_back(newExp(newSVal, newSVal)); | ||
| 3667 | break; | ||
| 3668 | } | ||
| 3669 | case id<WhileLine_t>(): { | ||
| 3670 | throw CompileError("while-loop line decorator is not supported here"sv, appendix->item.get()); | ||
| 3671 | break; | ||
| 3672 | } | ||
| 3673 | case id<CompInner_t>(): { | ||
| 3674 | throw CompileError("for-loop line decorator is not supported here"sv, appendix->item.get()); | ||
| 3675 | break; | ||
| 3676 | } | ||
| 3677 | default: YUEE("AST node mismatch", appendix->item.get()); break; | ||
| 3678 | } | ||
| 3679 | } | ||
| 3680 | if (newInvoke->args.empty()) { | ||
| 3681 | for (auto item : assignAction->values.objects()) { | ||
| 3682 | switch (item->get_id()) { | ||
| 3683 | case id<With_t>(): | ||
| 3684 | case id<If_t>(): | ||
| 3685 | case id<Switch_t>(): { | ||
| 3686 | auto sVal = item->new_ptr<SimpleValue_t>(); | ||
| 3687 | sVal->value.set(item); | ||
| 3688 | newInvoke->args.push_back(newExp(sVal, item)); | ||
| 3689 | break; | ||
| 3690 | } | ||
| 3691 | case id<TableBlock_t>(): | ||
| 3692 | case id<Exp_t>(): | ||
| 3693 | newInvoke->args.push_back(item); | ||
| 3694 | break; | ||
| 3695 | } | ||
| 3627 | } | 3696 | } |
| 3628 | } | 3697 | } |
| 3629 | BREAK_IF(!isExps); | ||
| 3630 | auto x = *nodes.begin(); | 3698 | auto x = *nodes.begin(); |
| 3631 | auto newBlock = x->new_ptr<Block_t>(); | 3699 | auto newBlock = x->new_ptr<Block_t>(); |
| 3632 | if (it != nodes.begin()) { | 3700 | if (it != nodes.begin()) { |
| @@ -3685,8 +3753,6 @@ private: | |||
| 3685 | newCallable->item.set(newParens); | 3753 | newCallable->item.set(newParens); |
| 3686 | auto newChainValue = x->new_ptr<ChainValue_t>(); | 3754 | auto newChainValue = x->new_ptr<ChainValue_t>(); |
| 3687 | newChainValue->items.push_back(newCallable); | 3755 | newChainValue->items.push_back(newCallable); |
| 3688 | auto newInvoke = x->new_ptr<InvokeArgs_t>(); | ||
| 3689 | newInvoke->args.dup(assignAction->values); | ||
| 3690 | newChainValue->items.push_back(newInvoke); | 3756 | newChainValue->items.push_back(newInvoke); |
| 3691 | auto newItem = newExp(newChainValue, x); | 3757 | auto newItem = newExp(newChainValue, x); |
| 3692 | auto newItemList = x->new_ptr<ExpList_t>(); | 3758 | auto newItemList = x->new_ptr<ExpList_t>(); |
