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/parser.h" | 7 #include "vm/parser.h" |
8 | 8 |
9 namespace dart { | 9 namespace dart { |
10 | 10 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
78 void AwaitTransformer::VisitLiteralNode(LiteralNode* node) { | 78 void AwaitTransformer::VisitLiteralNode(LiteralNode* node) { |
79 result_ = node; | 79 result_ = node; |
80 } | 80 } |
81 | 81 |
82 | 82 |
83 void AwaitTransformer::VisitTypeNode(TypeNode* node) { | 83 void AwaitTransformer::VisitTypeNode(TypeNode* node) { |
84 result_ = new(I) TypeNode(node->token_pos(), node->type()); | 84 result_ = new(I) TypeNode(node->token_pos(), node->type()); |
85 } | 85 } |
86 | 86 |
87 | 87 |
88 void AwaitTransformer::VisitAwaitMarkerNode(AwaitMarkerNode* node) { | |
89 // Await markers are generated by the transformer, but should never reach a | |
90 // 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.
| |
91 UNREACHABLE(); | |
92 } | |
93 | |
88 | 94 |
89 void AwaitTransformer::VisitAwaitNode(AwaitNode* node) { | 95 void AwaitTransformer::VisitAwaitNode(AwaitNode* node) { |
90 // Await transformation: | 96 // Await transformation: |
91 // | 97 // |
92 // :await_temp_var_X = <expr>; | 98 // :await_temp_var_X = <expr>; |
93 // :result_param = :await_temp_var_X; | 99 // :result_param = :await_temp_var_X; |
94 // if (:result_param is Future) { | 100 // if (:result_param is Future) { |
95 // // :result_param.then(:async_op); | 101 // AwaitMarker(kNewcontinuationState); |
102 // :result_param.then(:async_op); | |
103 // return; // (is_regular_return() == false) | |
96 // } | 104 // } |
97 // :await_temp_var_(X+1) = :result_param; | 105 // :await_temp_var_(X+1) = :result_param; |
98 | 106 |
99 LocalVariable* async_op = preamble_->scope()->LookupVariable( | 107 LocalVariable* async_op = preamble_->scope()->LookupVariable( |
100 Symbols::AsyncOperation(), false); | 108 Symbols::AsyncOperation(), false); |
101 ASSERT(async_op != NULL); | 109 ASSERT(async_op != NULL); |
102 LocalVariable* result_param = preamble_->scope()->LookupVariable( | 110 LocalVariable* result_param = preamble_->scope()->LookupVariable( |
103 Symbols::AsyncOperationParam(), false); | 111 Symbols::AsyncOperationParam(), false); |
104 ASSERT(result_param != NULL); | 112 ASSERT(result_param != NULL); |
105 | 113 |
106 node->expr()->Visit(this); | 114 node->expr()->Visit(this); |
107 preamble_->Add(new(I) StoreLocalNode(Scanner::kNoSourcePos, | 115 preamble_->Add(new(I) StoreLocalNode( |
108 result_param, | 116 Scanner::kNoSourcePos, result_param, result_)); |
109 result_)); | |
110 LoadLocalNode* load_result_param = new(I) LoadLocalNode( | 117 LoadLocalNode* load_result_param = new(I) LoadLocalNode( |
111 Scanner::kNoSourcePos, result_param); | 118 Scanner::kNoSourcePos, result_param); |
112 SequenceNode* is_future_branch = new(I) SequenceNode( | 119 SequenceNode* is_future_branch = new(I) SequenceNode( |
113 Scanner::kNoSourcePos, preamble_->scope()); | 120 Scanner::kNoSourcePos, preamble_->scope()); |
121 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
| |
122 new(I) AwaitMarkerNode(AwaitMarkerNode::kNewContinuationState); | |
123 await_marker->set_scope(preamble_->scope()); | |
124 is_future_branch->Add(await_marker); | |
114 ArgumentListNode* args = new(I) ArgumentListNode(Scanner::kNoSourcePos); | 125 ArgumentListNode* args = new(I) ArgumentListNode(Scanner::kNoSourcePos); |
115 args->Add(new(I) LoadLocalNode(Scanner::kNoSourcePos, async_op)); | 126 args->Add(new(I) LoadLocalNode(Scanner::kNoSourcePos, async_op)); |
116 // TODO(mlippautz): Once continuations are supported, just call .then(). | 127 is_future_branch->Add(new(I) InstanceCallNode( |
117 // is_future_branch->Add(new(I) InstanceCallNode( | 128 Scanner::kNoSourcePos, load_result_param, Symbols::FutureThen(), args)); |
118 // Scanner::kNoSourcePos, load_result_param, Symbols::FutureThen(), args)); | 129 ReturnNode* continuation_return = new(I) ReturnNode(Scanner::kNoSourcePos); |
119 // | 130 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(
| |
120 // For now, throw an exception. | 131 is_future_branch->Add(continuation_return); |
121 const String& exception = String::ZoneHandle( | 132 |
122 I, String::New("awaitable futures not yet supported", Heap::kOld)); | |
123 is_future_branch->Add(new(I) ThrowNode( | |
124 Scanner::kNoSourcePos, | |
125 new(I) LiteralNode( | |
126 Scanner::kNoSourcePos, | |
127 String::ZoneHandle(I, Symbols::New(exception))), | |
128 NULL)); | |
129 const Class& cls = Class::ZoneHandle( | 133 const Class& cls = Class::ZoneHandle( |
130 I, library_.LookupClass(Symbols::Future())); | 134 I, library_.LookupClass(Symbols::Future())); |
131 const AbstractType& future_type = AbstractType::ZoneHandle(I, | 135 const AbstractType& future_type = AbstractType::ZoneHandle(I, |
132 cls.RareType()); | 136 cls.RareType()); |
133 ASSERT(!future_type.IsNull()); | 137 ASSERT(!future_type.IsNull()); |
134 TypeNode* future_type_node = new(I) TypeNode( | 138 preamble_->Add(new(I) IfNode( |
135 Scanner::kNoSourcePos, future_type); | |
136 IfNode* is_future_if = new(I) IfNode( | |
137 Scanner::kNoSourcePos, | 139 Scanner::kNoSourcePos, |
138 new(I) ComparisonNode(Scanner::kNoSourcePos, | 140 new(I) ComparisonNode(Scanner::kNoSourcePos, |
139 Token::kIS, | 141 Token::kIS, |
140 load_result_param, | 142 load_result_param, |
141 future_type_node), | 143 new(I) TypeNode(Scanner::kNoSourcePos, |
144 future_type)), | |
142 is_future_branch, | 145 is_future_branch, |
143 NULL); | 146 NULL)); |
144 preamble_->Add(is_future_if); | 147 preamble_->Add(new(I) AwaitMarkerNode( |
145 | 148 AwaitMarkerNode::kTargetForContinuation)); |
146 // TODO(mlippautz): Join for await needs to happen here. | |
147 | 149 |
148 LocalVariable* result = AddToPreambleNewTempVar(new(I) LoadLocalNode( | 150 LocalVariable* result = AddToPreambleNewTempVar(new(I) LoadLocalNode( |
149 Scanner::kNoSourcePos, result_param)); | 151 Scanner::kNoSourcePos, result_param)); |
150 result_ = new(I) LoadLocalNode(Scanner::kNoSourcePos, result); | 152 result_ = new(I) LoadLocalNode(Scanner::kNoSourcePos, result); |
151 } | 153 } |
152 | 154 |
153 | 155 |
154 // Transforms boolean expressions into a sequence of evaluatons that only lazily | 156 // Transforms boolean expressions into a sequence of evaluatons that only lazily |
155 // evaluate subexpressions. | 157 // evaluate subexpressions. |
156 // | 158 // |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
499 void AwaitTransformer::VisitThrowNode(ThrowNode* node) { | 501 void AwaitTransformer::VisitThrowNode(ThrowNode* node) { |
500 // TODO(mlippautz): Check if relevant. | 502 // TODO(mlippautz): Check if relevant. |
501 AstNode* new_exception = Transform(node->exception()); | 503 AstNode* new_exception = Transform(node->exception()); |
502 AstNode* new_stacktrace = Transform(node->stacktrace()); | 504 AstNode* new_stacktrace = Transform(node->stacktrace()); |
503 result_ = new(I) ThrowNode(node->token_pos(), | 505 result_ = new(I) ThrowNode(node->token_pos(), |
504 new_exception, | 506 new_exception, |
505 new_stacktrace); | 507 new_stacktrace); |
506 } | 508 } |
507 | 509 |
508 } // namespace dart | 510 } // namespace dart |
OLD | NEW |