1.1 --- a/boot-truffle/src/main/java/net/java/html/boot/truffle/TrufflePresenter.java Wed Jul 06 17:22:52 2016 +0200
1.2 +++ b/boot-truffle/src/main/java/net/java/html/boot/truffle/TrufflePresenter.java Sat Jul 16 08:11:49 2016 +0200
1.3 @@ -47,7 +47,6 @@
1.4 import com.oracle.truffle.api.TruffleLanguage;
1.5 import com.oracle.truffle.api.interop.TruffleObject;
1.6 import com.oracle.truffle.api.interop.java.JavaInterop;
1.7 -import com.oracle.truffle.api.interop.java.MethodMessage;
1.8 import com.oracle.truffle.api.source.Source;
1.9 import com.oracle.truffle.api.vm.PolyglotEngine;
1.10 import java.io.Closeable;
1.11 @@ -71,10 +70,14 @@
1.12 private Eval eval;
1.13 private WrapArray copy;
1.14 private final Executor exc;
1.15 + private final CallTarget isNull;
1.16 + private final CallTarget isArray;
1.17
1.18 TrufflePresenter(Executor exc, TruffleObject eval) {
1.19 this.exc = exc;
1.20 this.eval = eval == null ? null : JavaInterop.asJavaFunction(Eval.class, eval);
1.21 + this.isNull = Truffle.getRuntime().createCallTarget(new IsNullNode());
1.22 + this.isArray = Truffle.getRuntime().createCallTarget(new IsArrayNode());
1.23 }
1.24
1.25 @Override
1.26 @@ -120,16 +123,6 @@
1.27 getEval().eval(src.getCode());
1.28 }
1.29
1.30 - interface IsArray {
1.31 - @MethodMessage(message = "HAS_SIZE")
1.32 - public boolean hasSize();
1.33 - }
1.34 -
1.35 - interface IsNull {
1.36 - @MethodMessage(message = "IS_NULL")
1.37 - public boolean isNull();
1.38 - }
1.39 -
1.40 interface WrapArray {
1.41 public Object copy(Object arr);
1.42 }
1.43 @@ -141,18 +134,14 @@
1.44 final Object checkArray(Object val) throws Exception {
1.45 if (val instanceof TruffleObject) {
1.46 final TruffleObject truffleObj = (TruffleObject)val;
1.47 - IsArray arrayTest = JavaInterop.asJavaObject(IsArray.class, truffleObj);
1.48 - try {
1.49 - if (arrayTest.hasSize()) {
1.50 - List<?> list = JavaInterop.asJavaObject(List.class, truffleObj);
1.51 - Object[] arr = list.toArray();
1.52 - for (int i = 0; i < arr.length; i++) {
1.53 - arr[i] = toJava(arr[i]);
1.54 - }
1.55 - return arr;
1.56 + boolean hasSize = (boolean) isArray.call(truffleObj);
1.57 + if (hasSize) {
1.58 + List<?> list = JavaInterop.asJavaObject(List.class, truffleObj);
1.59 + Object[] arr = list.toArray();
1.60 + for (int i = 0; i < arr.length; i++) {
1.61 + arr[i] = toJava(arr[i]);
1.62 }
1.63 - } catch (NegativeArraySizeException ex) {
1.64 - // swallow
1.65 + return arr;
1.66 }
1.67 }
1.68 return val;
1.69 @@ -164,14 +153,9 @@
1.70 jsArray = ((JavaValue) jsArray).get();
1.71 }
1.72 if (jsArray instanceof TruffleObject) {
1.73 - IsNull checkNull = JavaInterop.asJavaFunction(IsNull.class, (TruffleObject)jsArray);
1.74 - try {
1.75 - if (checkNull.isNull()) {
1.76 - return null;
1.77 - }
1.78 - } catch (NegativeArraySizeException ex) {
1.79 - System.err.println("negative size for " + jsArray);
1.80 - ex.printStackTrace();
1.81 + boolean checkNull = (boolean) isNull.call(jsArray);
1.82 + if (checkNull) {
1.83 + return null;
1.84 }
1.85 }
1.86 try {