OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/ast_transformer.h" | 5 #include "vm/ast_transformer.h" |
6 | 6 |
7 #include "vm/object_store.h" | 7 #include "vm/object_store.h" |
8 #include "vm/parser.h" | 8 #include "vm/parser.h" |
9 #include "vm/thread.h" | 9 #include "vm/thread.h" |
10 | 10 |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 result_ = new (Z) TypeNode(node->token_pos(), node->type()); | 122 result_ = new (Z) TypeNode(node->token_pos(), node->type()); |
123 } | 123 } |
124 | 124 |
125 | 125 |
126 void AwaitTransformer::VisitAwaitNode(AwaitNode* node) { | 126 void AwaitTransformer::VisitAwaitNode(AwaitNode* node) { |
127 // Await transformation: | 127 // Await transformation: |
128 // | 128 // |
129 // :await_temp_var_X = <expr>; | 129 // :await_temp_var_X = <expr>; |
130 // AwaitMarker(kNewContinuationState); | 130 // AwaitMarker(kNewContinuationState); |
131 // :result_param = _awaitHelper( | 131 // :result_param = _awaitHelper( |
132 // :await_temp_var_X, :async_then_callback, :async_catch_error_callback); | 132 // :await_temp_var_X, |
| 133 // :async_then_callback, |
| 134 // :async_catch_error_callback, |
| 135 // :async_op); |
133 // return; // (return_type() == kContinuationTarget) | 136 // return; // (return_type() == kContinuationTarget) |
134 // | 137 // |
135 // :saved_try_ctx_var = :await_saved_try_ctx_var_y; | 138 // :saved_try_ctx_var = :await_saved_try_ctx_var_y; |
136 // :await_temp_var_(X+1) = :result_param; | 139 // :await_temp_var_(X+1) = :result_param; |
137 | 140 |
138 const TokenPosition token_pos = ST(node->token_pos()); | 141 const TokenPosition token_pos = ST(node->token_pos()); |
139 LocalVariable* async_op = | 142 LocalVariable* async_op = |
140 GetVariableInScope(preamble_->scope(), Symbols::AsyncOperation()); | 143 GetVariableInScope(preamble_->scope(), Symbols::AsyncOperation()); |
141 LocalVariable* async_then_callback = | 144 LocalVariable* async_then_callback = |
142 GetVariableInScope(preamble_->scope(), Symbols::AsyncThenCallback()); | 145 GetVariableInScope(preamble_->scope(), Symbols::AsyncThenCallback()); |
143 LocalVariable* async_catch_error_callback = GetVariableInScope( | 146 LocalVariable* async_catch_error_callback = GetVariableInScope( |
144 preamble_->scope(), Symbols::AsyncCatchErrorCallback()); | 147 preamble_->scope(), Symbols::AsyncCatchErrorCallback()); |
145 LocalVariable* result_param = | 148 LocalVariable* result_param = |
146 GetVariableInScope(preamble_->scope(), Symbols::AsyncOperationParam()); | 149 GetVariableInScope(preamble_->scope(), Symbols::AsyncOperationParam()); |
147 LocalVariable* error_param = GetVariableInScope( | 150 LocalVariable* error_param = GetVariableInScope( |
148 preamble_->scope(), Symbols::AsyncOperationErrorParam()); | 151 preamble_->scope(), Symbols::AsyncOperationErrorParam()); |
149 LocalVariable* stack_trace_param = GetVariableInScope( | 152 LocalVariable* stack_trace_param = GetVariableInScope( |
150 preamble_->scope(), Symbols::AsyncOperationStackTraceParam()); | 153 preamble_->scope(), Symbols::AsyncOperationStackTraceParam()); |
151 | 154 |
152 AstNode* transformed_expr = Transform(node->expr()); | 155 AstNode* transformed_expr = Transform(node->expr()); |
153 LocalVariable* await_temp = | 156 LocalVariable* await_temp = |
154 AddNewTempVarToPreamble(transformed_expr, ST(node->token_pos())); | 157 AddNewTempVarToPreamble(transformed_expr, ST(node->token_pos())); |
155 | 158 |
156 AwaitMarkerNode* await_marker = | 159 AwaitMarkerNode* await_marker = |
157 new (Z) AwaitMarkerNode(async_temp_scope_, node->scope(), token_pos); | 160 new (Z) AwaitMarkerNode(async_temp_scope_, node->scope(), token_pos); |
158 preamble_->Add(await_marker); | 161 preamble_->Add(await_marker); |
159 | 162 |
160 // :result_param = _awaitHelper( | 163 // :result_param = _awaitHelper( |
161 // :await_temp, :async_then_callback, :async_catch_error_callback) | 164 // :await_temp, |
| 165 // :async_then_callback, |
| 166 // :async_catch_error_callback, |
| 167 // :async_op) |
162 const Library& async_lib = Library::Handle(Library::AsyncLibrary()); | 168 const Library& async_lib = Library::Handle(Library::AsyncLibrary()); |
163 const Function& async_await_helper = Function::ZoneHandle( | 169 const Function& async_await_helper = Function::ZoneHandle( |
164 Z, async_lib.LookupFunctionAllowPrivate(Symbols::AsyncAwaitHelper())); | 170 Z, async_lib.LookupFunctionAllowPrivate(Symbols::AsyncAwaitHelper())); |
165 ASSERT(!async_await_helper.IsNull()); | 171 ASSERT(!async_await_helper.IsNull()); |
166 ArgumentListNode* async_await_helper_args = | 172 ArgumentListNode* async_await_helper_args = |
167 new (Z) ArgumentListNode(token_pos); | 173 new (Z) ArgumentListNode(token_pos); |
168 async_await_helper_args->Add(new (Z) LoadLocalNode(token_pos, await_temp)); | 174 async_await_helper_args->Add(new (Z) LoadLocalNode(token_pos, await_temp)); |
169 async_await_helper_args->Add( | 175 async_await_helper_args->Add( |
170 new (Z) LoadLocalNode(token_pos, async_then_callback)); | 176 new (Z) LoadLocalNode(token_pos, async_then_callback)); |
171 async_await_helper_args->Add( | 177 async_await_helper_args->Add( |
172 new (Z) LoadLocalNode(token_pos, async_catch_error_callback)); | 178 new (Z) LoadLocalNode(token_pos, async_catch_error_callback)); |
| 179 async_await_helper_args->Add(new (Z) LoadLocalNode(token_pos, async_op)); |
173 StaticCallNode* await_helper_call = new (Z) StaticCallNode( | 180 StaticCallNode* await_helper_call = new (Z) StaticCallNode( |
174 node->token_pos(), async_await_helper, async_await_helper_args); | 181 node->token_pos(), async_await_helper, async_await_helper_args); |
175 | 182 |
176 preamble_->Add( | 183 preamble_->Add( |
177 new (Z) StoreLocalNode(token_pos, result_param, await_helper_call)); | 184 new (Z) StoreLocalNode(token_pos, result_param, await_helper_call)); |
178 | 185 |
179 ReturnNode* continuation_return = new (Z) ReturnNode(token_pos); | 186 ReturnNode* continuation_return = new (Z) ReturnNode(token_pos); |
180 continuation_return->set_return_type(ReturnNode::kContinuationTarget); | 187 continuation_return->set_return_type(ReturnNode::kContinuationTarget); |
181 preamble_->Add(continuation_return); | 188 preamble_->Add(continuation_return); |
182 | 189 |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 } | 514 } |
508 | 515 |
509 | 516 |
510 void AwaitTransformer::VisitThrowNode(ThrowNode* node) { | 517 void AwaitTransformer::VisitThrowNode(ThrowNode* node) { |
511 AstNode* new_exception = Transform(node->exception()); | 518 AstNode* new_exception = Transform(node->exception()); |
512 result_ = MakeName( | 519 result_ = MakeName( |
513 new (Z) ThrowNode(node->token_pos(), new_exception, node->stacktrace())); | 520 new (Z) ThrowNode(node->token_pos(), new_exception, node->stacktrace())); |
514 } | 521 } |
515 | 522 |
516 } // namespace dart | 523 } // namespace dart |
OLD | NEW |