13514
|
1 /*
|
|
2 * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved. This
|
|
3 * code is released under a tri EPL/GPL/LGPL license. You can use it,
|
|
4 * redistribute it and/or modify it under the terms of the:
|
|
5 *
|
|
6 * Eclipse Public License version 1.0
|
|
7 * GNU General Public License version 2
|
|
8 * GNU Lesser General Public License version 2.1
|
|
9 */
|
|
10 package com.oracle.truffle.ruby.nodes.call;
|
|
11
|
|
12 import com.oracle.truffle.api.*;
|
|
13 import com.oracle.truffle.api.frame.*;
|
|
14 import com.oracle.truffle.api.utilities.*;
|
|
15 import com.oracle.truffle.ruby.runtime.*;
|
|
16 import com.oracle.truffle.ruby.runtime.core.*;
|
|
17 import com.oracle.truffle.ruby.runtime.objects.*;
|
|
18
|
|
19 /**
|
|
20 * A node in the dispatch chain that boxes the receiver into a full Ruby {@link RubyBasicObject}.
|
|
21 * This node is initially created as an {@link UninitializedBoxingDispatchNode} and only becomes
|
|
22 * this node when we know that we do need to box on the fast path. Within this node we specialized
|
|
23 * for the case that the receiver is always already boxed.
|
|
24 */
|
|
25 public class BoxingDispatchNode extends UnboxedDispatchNode {
|
|
26
|
|
27 @Child protected BoxedDispatchNode next;
|
|
28
|
|
29 private final BranchProfile boxBranch = new BranchProfile();
|
|
30
|
|
31 public BoxingDispatchNode(RubyContext context, SourceSection sourceSection, BoxedDispatchNode next) {
|
|
32 super(context, sourceSection);
|
|
33
|
|
34 this.next = adoptChild(next);
|
|
35 }
|
|
36
|
|
37 @Override
|
|
38 public Object dispatch(VirtualFrame frame, Object receiverObject, RubyProc blockObject, Object[] argumentsObjects) {
|
|
39 RubyBasicObject boxedReceiverObject;
|
|
40
|
|
41 if (receiverObject instanceof RubyBasicObject) {
|
|
42 boxedReceiverObject = (RubyBasicObject) receiverObject;
|
|
43 } else {
|
|
44 boxBranch.enter();
|
|
45 boxedReceiverObject = getContext().getCoreLibrary().box(receiverObject);
|
|
46 }
|
|
47
|
|
48 return next.dispatch(frame, boxedReceiverObject, blockObject, argumentsObjects);
|
|
49 }
|
|
50
|
|
51 }
|