|
29 | 29 | import com.oracle.truffle.api.dsl.NodeChild; |
30 | 30 | import com.oracle.truffle.api.dsl.Specialization; |
31 | 31 | import com.oracle.truffle.api.frame.VirtualFrame; |
32 | | -import com.oracle.truffle.api.interop.ArityException; |
33 | 32 | import com.oracle.truffle.api.interop.ForeignAccess; |
34 | 33 | import com.oracle.truffle.api.interop.Message; |
35 | 34 | import com.oracle.truffle.api.interop.TruffleObject; |
36 | 35 | import com.oracle.truffle.api.interop.UnknownIdentifierException; |
37 | 36 | import com.oracle.truffle.api.interop.UnsupportedMessageException; |
38 | | -import com.oracle.truffle.api.interop.UnsupportedTypeException; |
39 | 37 | import com.oracle.truffle.api.nodes.LoopNode; |
40 | 38 | import com.oracle.truffle.api.nodes.Node; |
41 | 39 | import com.oracle.truffle.api.nodes.UnexpectedResultException; |
@@ -172,10 +170,6 @@ protected WriteVariableNode createWriteVariable(String name) { |
172 | 170 | return WriteVariableNode.createAnonymous(name, Mode.REGULAR, null); |
173 | 171 | } |
174 | 172 |
|
175 | | - protected LoopNode createForIterableLoopNode(String iteratorName) { |
176 | | - return createLoopNode(new ForIterableRepeatingNode(this, var.getIdentifier(), RASTUtils.cloneNode(body), iteratorName)); |
177 | | - } |
178 | | - |
179 | 173 | protected LoopNode createForKeysLoopNode(String indexName, String positionName, String lengthName, String rangeName, String keysName) { |
180 | 174 | return createLoopNode(new ForKeysRepeatingNode(this, var.getIdentifier(), RASTUtils.cloneNode(body), indexName, positionName, lengthName, rangeName, keysName)); |
181 | 175 | } |
@@ -320,81 +314,6 @@ protected void writePosition(VirtualFrame frame, int index) { |
320 | 314 | } |
321 | 315 | } |
322 | 316 |
|
323 | | - private static final class ForIterableRepeatingNode extends AbstractRepeatingNode { |
324 | | - |
325 | | - private final ConditionProfile conditionProfile = ConditionProfile.createBinaryProfile(); |
326 | | - private final BranchProfile breakBlock = BranchProfile.create(); |
327 | | - private final BranchProfile nextBlock = BranchProfile.create(); |
328 | | - |
329 | | - @Child private WriteVariableNode writeElementNode; |
330 | | - @Child private LocalReadVariableNode readIteratorNode; |
331 | | - |
332 | | - @Child private Node readForeignNode; |
333 | | - @Child private Node executeForeignNode; |
334 | | - |
335 | | - // only used for toString |
336 | | - private final ForNode forNode; |
337 | | - |
338 | | - ForIterableRepeatingNode(ForNode forNode, String var, RNode body, String iteratorName) { |
339 | | - super(body); |
340 | | - this.forNode = forNode; |
341 | | - this.writeElementNode = WriteVariableNode.createAnonymous(var, Mode.REGULAR, createNextLoad(iteratorName), false); |
342 | | - |
343 | | - this.readIteratorNode = LocalReadVariableNode.create(iteratorName, true); |
344 | | - |
345 | | - this.executeForeignNode = Message.EXECUTE.createNode(); |
346 | | - this.readForeignNode = Message.READ.createNode(); |
347 | | - |
348 | | - // pre-initialize the profile so that loop exits to not deoptimize |
349 | | - conditionProfile.profile(false); |
350 | | - } |
351 | | - |
352 | | - private static RNode createNextLoad(String iteratorName) { |
353 | | - RCodeBuilder<RSyntaxNode> builder = RContext.getASTBuilder(); |
354 | | - RSyntaxNode receiver = builder.lookup(RSyntaxNode.INTERNAL, iteratorName, false); |
355 | | - RSyntaxNode next = builder.lookup(RSyntaxNode.INTERNAL, "next", true); |
356 | | - RSyntaxNode access = builder.lookup(RSyntaxNode.INTERNAL, "$", true); |
357 | | - RSyntaxNode nextCall = builder.call(RSyntaxNode.INTERNAL, access, receiver, next); |
358 | | - return builder.call(RSyntaxNode.INTERNAL, nextCall).asRNode(); |
359 | | - } |
360 | | - |
361 | | - @Override |
362 | | - public boolean executeRepeating(VirtualFrame frame) { |
363 | | - try { |
364 | | - TruffleObject iterator = (TruffleObject) readIteratorNode.execute(frame); |
365 | | - assert iterator != null; |
366 | | - |
367 | | - if (conditionProfile.profile(hasNext(iterator))) { |
368 | | - writeElementNode.voidExecute(frame); |
369 | | - body.voidExecute(frame); |
370 | | - return true; |
371 | | - } |
372 | | - return false; |
373 | | - } catch (BreakException e) { |
374 | | - breakBlock.enter(); |
375 | | - return false; |
376 | | - } catch (NextException e) { |
377 | | - nextBlock.enter(); |
378 | | - return true; |
379 | | - } |
380 | | - } |
381 | | - |
382 | | - private boolean hasNext(TruffleObject iterator) { |
383 | | - try { |
384 | | - TruffleObject hasNextFun = (TruffleObject) ForeignAccess.sendRead(readForeignNode, iterator, "hasNext"); |
385 | | - return (boolean) ForeignAccess.sendExecute(executeForeignNode, hasNextFun); |
386 | | - } catch (UnknownIdentifierException | UnsupportedMessageException | UnsupportedTypeException | ArityException ex) { |
387 | | - throw RInternalError.shouldNotReachHere(ex, "Could not retrieve hasNext function"); |
388 | | - } |
389 | | - } |
390 | | - |
391 | | - @Override |
392 | | - public String toString() { |
393 | | - return forNode.toString(); |
394 | | - } |
395 | | - |
396 | | - } |
397 | | - |
398 | 317 | @Override |
399 | 318 | public RSyntaxElement[] getSyntaxArguments() { |
400 | 319 | return new RSyntaxElement[]{var, getRange().asRSyntaxNode(), body.asRSyntaxNode()}; |
|
0 commit comments