Mercurial > hg > truffle
comparison truffle/com.oracle.truffle.api.vm/src/com/oracle/truffle/api/vm/SymbolInvokerImpl.java @ 22135:e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
author | Jaroslav Tulach <jaroslav.tulach@oracle.com> |
---|---|
date | Mon, 07 Sep 2015 17:07:20 +0200 |
parents | 626862cfa58d |
children | dc83cc1f94f2 3aad794eec0e |
comparison
equal
deleted
inserted
replaced
22134:025869c88840 | 22135:e70b20f4bb00 |
---|---|
38 } else { | 38 } else { |
39 type = (Class) TruffleLanguage.class; | 39 type = (Class) TruffleLanguage.class; |
40 } | 40 } |
41 RootNode symbolNode; | 41 RootNode symbolNode; |
42 if ((symbol instanceof String) || (symbol instanceof Number) || (symbol instanceof Boolean) || (symbol instanceof Character)) { | 42 if ((symbol instanceof String) || (symbol instanceof Number) || (symbol instanceof Boolean) || (symbol instanceof Character)) { |
43 symbolNode = new ConstantRootNode(type, symbol); | 43 symbolNode = RootNode.createConstantNode(symbol); |
44 } else { | 44 } else { |
45 Node executeMain = Message.createExecute(arr.length).createNode(); | 45 Node executeMain = Message.createExecute(arr.length).createNode(); |
46 symbolNode = new TemporaryRoot(type, executeMain, (TruffleObject) symbol, arr.length); | 46 symbolNode = createTemporaryRoot(type, executeMain, (TruffleObject) symbol, arr.length); |
47 } | 47 } |
48 return Truffle.getRuntime().createCallTarget(symbolNode); | 48 return Truffle.getRuntime().createCallTarget(symbolNode); |
49 } | 49 } |
50 | 50 |
51 private static final class ConstantRootNode extends RootNode { | 51 @SuppressWarnings("rawtypes") |
52 | 52 public static RootNode createTemporaryRoot(Class<? extends TruffleLanguage> lang, Node foreignAccess, TruffleObject function, int argumentLength) { |
53 private final Object value; | 53 return new TemporaryRoot(lang, foreignAccess, function, argumentLength); |
54 | |
55 public ConstantRootNode(Class<? extends TruffleLanguage<?>> lang, Object value) { | |
56 super(lang, null, null); | |
57 this.value = value; | |
58 } | |
59 | |
60 @Override | |
61 public Object execute(VirtualFrame vf) { | |
62 return value; | |
63 } | |
64 } | 54 } |
65 | 55 |
66 private static class TemporaryRoot extends RootNode { | 56 static class TemporaryRoot extends RootNode { |
67 @Child private Node foreignAccess; | 57 @Child private Node foreignAccess; |
68 @Child private ConvertNode convert; | 58 @Child private ConvertNode convert; |
69 private final int argumentLength; | 59 private final int argumentLength; |
70 private final TruffleObject function; | 60 private final TruffleObject function; |
71 | 61 |
72 public TemporaryRoot(Class<? extends TruffleLanguage<?>> lang, Node foreignAccess, TruffleObject function, int argumentLength) { | 62 @SuppressWarnings("rawtypes") |
63 public TemporaryRoot(Class<? extends TruffleLanguage> lang, Node foreignAccess, TruffleObject function, int argumentLength) { | |
73 super(lang, null, null); | 64 super(lang, null, null); |
74 this.foreignAccess = foreignAccess; | 65 this.foreignAccess = foreignAccess; |
75 this.convert = new ConvertNode(); | 66 this.convert = new ConvertNode(); |
76 this.function = function; | 67 this.function = function; |
77 this.argumentLength = argumentLength; | 68 this.argumentLength = argumentLength; |