Chromium Code Reviews| Index: runtime/vm/ast_transformer.cc |
| diff --git a/runtime/vm/ast_transformer.cc b/runtime/vm/ast_transformer.cc |
| index e4637e5427829ebe023c438fb493c7879df0881d..aa0d440eaf098cd3382102081cf795aefa806018 100644 |
| --- a/runtime/vm/ast_transformer.cc |
| +++ b/runtime/vm/ast_transformer.cc |
| @@ -85,6 +85,12 @@ void AwaitTransformer::VisitTypeNode(TypeNode* node) { |
| } |
| +void AwaitTransformer::VisitAwaitMarkerNode(AwaitMarkerNode* node) { |
| + // Await markers are generated by the transformer, but should never reach a |
| + // transformer. |
|
hausner
2014/08/20 19:47:48
should never be visited by the transformer?
Why n
Michael Lippautz (Google)
2014/08/20 20:56:06
Done.
|
| + UNREACHABLE(); |
| +} |
| + |
| void AwaitTransformer::VisitAwaitNode(AwaitNode* node) { |
| // Await transformation: |
| @@ -92,7 +98,9 @@ void AwaitTransformer::VisitAwaitNode(AwaitNode* node) { |
| // :await_temp_var_X = <expr>; |
| // :result_param = :await_temp_var_X; |
| // if (:result_param is Future) { |
| - // // :result_param.then(:async_op); |
| + // AwaitMarker(kNewcontinuationState); |
| + // :result_param.then(:async_op); |
| + // return; // (is_regular_return() == false) |
| // } |
| // :await_temp_var_(X+1) = :result_param; |
| @@ -104,46 +112,40 @@ void AwaitTransformer::VisitAwaitNode(AwaitNode* node) { |
| ASSERT(result_param != NULL); |
| node->expr()->Visit(this); |
| - preamble_->Add(new(I) StoreLocalNode(Scanner::kNoSourcePos, |
| - result_param, |
| - result_)); |
| + preamble_->Add(new(I) StoreLocalNode( |
| + Scanner::kNoSourcePos, result_param, result_)); |
| LoadLocalNode* load_result_param = new(I) LoadLocalNode( |
| Scanner::kNoSourcePos, result_param); |
| SequenceNode* is_future_branch = new(I) SequenceNode( |
| Scanner::kNoSourcePos, preamble_->scope()); |
| + AwaitMarkerNode* await_marker = |
|
hausner
2014/08/20 19:47:48
A comment would be helpful here, explaining what t
Michael Lippautz (Google)
2014/08/20 20:56:06
Done in ast.h
|
| + new(I) AwaitMarkerNode(AwaitMarkerNode::kNewContinuationState); |
| + await_marker->set_scope(preamble_->scope()); |
| + is_future_branch->Add(await_marker); |
| ArgumentListNode* args = new(I) ArgumentListNode(Scanner::kNoSourcePos); |
| args->Add(new(I) LoadLocalNode(Scanner::kNoSourcePos, async_op)); |
| - // TODO(mlippautz): Once continuations are supported, just call .then(). |
| - // is_future_branch->Add(new(I) InstanceCallNode( |
| - // Scanner::kNoSourcePos, load_result_param, Symbols::FutureThen(), args)); |
| - // |
| - // For now, throw an exception. |
| - const String& exception = String::ZoneHandle( |
| - I, String::New("awaitable futures not yet supported", Heap::kOld)); |
| - is_future_branch->Add(new(I) ThrowNode( |
| - Scanner::kNoSourcePos, |
| - new(I) LiteralNode( |
| - Scanner::kNoSourcePos, |
| - String::ZoneHandle(I, Symbols::New(exception))), |
| - NULL)); |
| + is_future_branch->Add(new(I) InstanceCallNode( |
| + Scanner::kNoSourcePos, load_result_param, Symbols::FutureThen(), args)); |
| + ReturnNode* continuation_return = new(I) ReturnNode(Scanner::kNoSourcePos); |
| + continuation_return->set_is_regular_return(false); |
|
hausner
2014/08/20 19:47:48
It would be nice to have a more descriptive name t
Michael Lippautz (Google)
2014/08/20 20:56:06
As discussed offline: ReturnNodes will get a type(
|
| + is_future_branch->Add(continuation_return); |
| + |
| const Class& cls = Class::ZoneHandle( |
| I, library_.LookupClass(Symbols::Future())); |
| const AbstractType& future_type = AbstractType::ZoneHandle(I, |
| cls.RareType()); |
| ASSERT(!future_type.IsNull()); |
| - TypeNode* future_type_node = new(I) TypeNode( |
| - Scanner::kNoSourcePos, future_type); |
| - IfNode* is_future_if = new(I) IfNode( |
| + preamble_->Add(new(I) IfNode( |
| Scanner::kNoSourcePos, |
| new(I) ComparisonNode(Scanner::kNoSourcePos, |
| Token::kIS, |
| load_result_param, |
| - future_type_node), |
| + new(I) TypeNode(Scanner::kNoSourcePos, |
| + future_type)), |
| is_future_branch, |
| - NULL); |
| - preamble_->Add(is_future_if); |
| - |
| - // TODO(mlippautz): Join for await needs to happen here. |
| + NULL)); |
| + preamble_->Add(new(I) AwaitMarkerNode( |
| + AwaitMarkerNode::kTargetForContinuation)); |
| LocalVariable* result = AddToPreambleNewTempVar(new(I) LoadLocalNode( |
| Scanner::kNoSourcePos, result_param)); |