Mercurial > hg > graal-jvmci-8
comparison graal/com.oracle.truffle.interop/src/com/oracle/truffle/interop/SymbolInvokerImpl.java @ 21689:ed234a3178af
Behavior of null-like values is now part of the TCK
author | Jaroslav Tulach <jaroslav.tulach@oracle.com> |
---|---|
date | Wed, 03 Jun 2015 10:17:19 +0200 |
parents | 5fa7935c5de3 |
children | 2f9e4d984d16 |
comparison
equal
deleted
inserted
replaced
21688:889b45a0dedd | 21689:ed234a3178af |
---|---|
28 | 28 |
29 import com.oracle.truffle.api.*; | 29 import com.oracle.truffle.api.*; |
30 import com.oracle.truffle.api.frame.*; | 30 import com.oracle.truffle.api.frame.*; |
31 import com.oracle.truffle.api.impl.*; | 31 import com.oracle.truffle.api.impl.*; |
32 import com.oracle.truffle.api.interop.*; | 32 import com.oracle.truffle.api.interop.*; |
33 import com.oracle.truffle.api.interop.exception.UnsupportedMessageException; | |
33 import com.oracle.truffle.api.nodes.*; | 34 import com.oracle.truffle.api.nodes.*; |
34 import com.oracle.truffle.interop.messages.*; | 35 import com.oracle.truffle.interop.messages.*; |
35 import com.oracle.truffle.interop.node.*; | 36 import com.oracle.truffle.interop.node.*; |
36 | 37 |
37 public final class SymbolInvokerImpl extends SymbolInvoker { | 38 public final class SymbolInvokerImpl extends SymbolInvoker { |
38 static final FrameDescriptor UNUSED_FRAMEDESCRIPTOR = new FrameDescriptor(); | 39 static final FrameDescriptor UNUSED_FRAMEDESCRIPTOR = new FrameDescriptor(); |
39 | 40 |
40 @Override | 41 @Override |
41 protected Object invoke(Object symbol, Object... arr) throws IOException { | 42 protected Object invoke(Object symbol, Object... arr) throws IOException { |
42 ForeignObjectAccessNode executeMain = ForeignObjectAccessNode.getAccess(Execute.create(Receiver.create(), arr.length)); | 43 ForeignObjectAccessNode callMain = ForeignObjectAccessNode.getAccess(Execute.create(Receiver.create(), arr.length)); |
43 CallTarget callTarget = Truffle.getRuntime().createCallTarget(new TemporaryRoot(executeMain, (TruffleObject) symbol, arr)); | 44 CallTarget callMainTarget = Truffle.getRuntime().createCallTarget(new TemporaryRoot(callMain, (TruffleObject) symbol, arr)); |
44 VirtualFrame frame = Truffle.getRuntime().createVirtualFrame(arr, UNUSED_FRAMEDESCRIPTOR); | 45 VirtualFrame frame = Truffle.getRuntime().createVirtualFrame(arr, UNUSED_FRAMEDESCRIPTOR); |
45 return callTarget.call(frame); | 46 Object ret = callMainTarget.call(frame); |
47 if (ret instanceof TruffleObject) { | |
48 TruffleObject tret = (TruffleObject) ret; | |
49 Object isBoxedResult; | |
50 try { | |
51 ForeignObjectAccessNode isBoxed = ForeignObjectAccessNode.getAccess(IsBoxed.create(Receiver.create())); | |
52 CallTarget isBoxedTarget = Truffle.getRuntime().createCallTarget(new TemporaryRoot(isBoxed, tret)); | |
53 isBoxedResult = isBoxedTarget.call(frame); | |
54 } catch (UnsupportedMessageException ex) { | |
55 isBoxedResult = false; | |
56 } | |
57 if (Boolean.TRUE.equals(isBoxedResult)) { | |
58 ForeignObjectAccessNode unbox = ForeignObjectAccessNode.getAccess(Unbox.create(Receiver.create())); | |
59 CallTarget unboxTarget = Truffle.getRuntime().createCallTarget(new TemporaryRoot(unbox, tret)); | |
60 Object unboxResult = unboxTarget.call(frame); | |
61 return unboxResult; | |
62 } else { | |
63 try { | |
64 ForeignObjectAccessNode isNull = ForeignObjectAccessNode.getAccess(IsNull.create(Receiver.create())); | |
65 CallTarget isNullTarget = Truffle.getRuntime().createCallTarget(new TemporaryRoot(isNull, tret)); | |
66 Object isNullResult = isNullTarget.call(frame); | |
67 if (Boolean.TRUE.equals(isNullResult)) { | |
68 return null; | |
69 } | |
70 } catch (UnsupportedMessageException ex) { | |
71 // fallthrough | |
72 } | |
73 } | |
74 } | |
75 return ret; | |
46 } | 76 } |
47 | 77 |
48 private static class TemporaryRoot extends RootNode { | 78 private static class TemporaryRoot extends RootNode { |
49 @Child private ForeignObjectAccessNode foreignAccess; | 79 @Child private ForeignObjectAccessNode foreignAccess; |
50 private final TruffleObject function; | 80 private final TruffleObject function; |