shared_ptr<ast::AstLambdaExpression> Expression::GenerateContinuationLambdaAst(shared_ptr<SymbolAstScope> scope, SymbolAstContext& context, shared_ptr<ast::AstDeclaration> state) { auto lambda = make_shared<AstLambdaExpression>(); { auto ref = make_shared<AstSymbolDeclaration>(); ref->composedName = T("$state") + context.GetUniquePostfix(); lambda->arguments.push_back(ref); } { auto ref = make_shared<AstSymbolDeclaration>(); ref->composedName = T("$result") + context.GetUniquePostfix(); lambda->arguments.push_back(ref); } return lambda; }
void SymbolAstResult::MergeForExpression(const SymbolAstResult& result, SymbolAstContext& context, vector<AstExpression::Ptr>& exprs, int& exprStart, AstDeclaration::Ptr& state) { if (result.RequireCps()) { auto block = make_shared<AstBlockStatement>(); for (int i = exprStart; (size_t)i < exprs.size(); i++) { auto var = make_shared<AstDeclarationStatement>(); { auto decl = make_shared<AstSymbolDeclaration>(); decl->composedName = T("$var") + context.GetUniquePostfix(); var->declaration = decl; auto declstat = make_shared<AstDeclarationStatement>(); declstat->declaration = decl; block->statements.push_back(declstat); auto assign = make_shared<AstAssignmentStatement>(); block->statements.push_back(assign); auto ref = make_shared<AstReferenceExpression>(); ref->reference = decl; assign->target = ref; assign->value = exprs[i]; } auto ref = make_shared<AstReferenceExpression>(); ref->reference = var->declaration; exprs[i] = ref; } block->statements.push_back(result.statement); if (continuation) { continuation->statement = block; } else { statement = block; } continuation = result.continuation; exprStart = exprs.size(); state = continuation->arguments[0]; } exprs.push_back(result.value); }