/** * Name of function to add two numbers together. The symbol will be invoked with two parameters * of <code>type1</code> and <code>type2</code> and expects result of type {@link Number} * which's {@link Number#intValue()} is equivalent of <code>param1 + param2</code>. As some * languages may have different operations for different types of numbers, the actual types are * passed to the method and the implementation can decide to return different symbol based on * the parameters. * * @param type1 one of byte, short, int, long, float, double class * @param type2 one of byte, short, int, long, float, double class * @return name of globally exported symbol * @since 0.8 or earlier */ protected String plus(Class<?> type1, Class<?> type2) { return plusInt(); }
@Test public void testPlusWithInts() throws Exception { Random r = new Random(); int a = r.nextInt(100); int b = r.nextInt(100); TruffleVM.Symbol plus = findGlobalSymbol(plusInt()); Object res = plus.invoke(null, a, b); assert res instanceof Number : "+ on two ints should yield a number, but was: " + res; Number n = (Number) res; assert a + b == n.intValue() : "The value is correct: (" + a + " + " + b + ") = " + n.intValue(); }