public Object access(RegexObject receiver, String name, Object[] args) { if (!name.equals("exec")) { throw UnknownIdentifierException.raise(name); } if (args.length != 2) { throw ArityException.raise(2, args.length); } return executeNode.execute(receiver, args[0], args[1]); } }
/** * Raises an {@link ArityException}, hidden as a {@link RuntimeException}, which allows throwing * it without an explicit throws declaration. The {@link ForeignAccess} methods (e.g. * <code> ForeignAccess.sendRead </code>) catch the exceptions and re-throw them as checked * exceptions. * * @param expectedArity the number of arguments expected by the foreign object * @param actualArity the number of provided by the foreign access * * @return the exception * @since 0.11 */ public static RuntimeException raise(int expectedArity, int actualArity) { CompilerDirectives.transferToInterpreter(); return silenceException(RuntimeException.class, new ArityException(expectedArity, actualArity)); }
private PolyglotException handleInvalidArity(ArityException e) { int actual = e.getActualArity(); int expected = e.getExpectedArity(); return error(String.format("Expected %s number of arguments but got %s when creating a new instance of %s.", expected, actual, toString())); }
public Object access(RegexObjectExecMethod receiver, Object[] args) { if (args.length != 2) { throw ArityException.raise(2, args.length); } return executeNode.execute(receiver.getRegexObject(), args[0], args[1]); } }
protected final Object executeShared(Object receiver, Object[] args) { Object[] guestArguments = toGuestValues.apply(polyglot.languageContext, args); try { return ForeignAccess.sendExecute(executeNode, (TruffleObject) receiver, guestArguments); } catch (UnsupportedTypeException e) { CompilerDirectives.transferToInterpreter(); throw invalidExecuteArgumentType(polyglot.languageContext, receiver, e); } catch (ArityException e) { CompilerDirectives.transferToInterpreter(); throw invalidExecuteArity(polyglot.languageContext, receiver, guestArguments, e.getExpectedArity(), e.getActualArity()); } catch (UnsupportedMessageException e) { CompilerDirectives.transferToInterpreter(); return polyglot.executeUnsupported(receiver); } }
/** * Raises an {@link ArityException}, hidden as a {@link RuntimeException}, which allows throwing * it without an explicit throws declaration. The {@link ForeignAccess} methods (e.g. * <code> ForeignAccess.sendRead </code>) catch the exceptions and re-throw them as checked * exceptions. * * @param expectedArity the number of arguments expected by the foreign object * @param actualArity the number of provided by the foreign access * * @return the exception * @since 0.11 */ public static RuntimeException raise(int expectedArity, int actualArity) { CompilerDirectives.transferToInterpreter(); return silenceException(RuntimeException.class, new ArityException(expectedArity, actualArity)); }
public Object access(CompiledRegexObject receiver, Object[] args) { if (args.length != 3) { throw ArityException.raise(3, args.length); } if (!(args[0] instanceof RegexObject)) { throw UnsupportedTypeException.raise(args); } return doExecute.execute(receiver.getCompiledRegex(), (RegexObject) args[0], args[1], args[2]); } }
protected final Object executeShared(PolyglotLanguageContext context, Object receiver, Object[] args) { Object[] guestArguments = toGuestValues.apply(context, args); try { return ForeignAccess.sendExecute(executeNode, (TruffleObject) receiver, guestArguments); } catch (UnsupportedTypeException e) { CompilerDirectives.transferToInterpreter(); throw invalidExecuteArgumentType(context, receiver, e); } catch (ArityException e) { CompilerDirectives.transferToInterpreter(); throw invalidExecuteArity(context, receiver, guestArguments, e.getExpectedArity(), e.getActualArity()); } catch (UnsupportedMessageException e) { CompilerDirectives.transferToInterpreter(); return executeUnsupported(context, receiver); } }
public Object access(RegexEngine receiver, Object[] args) { if (!(args.length == 1 || args.length == 2)) { throw ArityException.raise(2, args.length); } String pattern = expectPatternNode.execute(args[0]); String flags = args.length == 2 ? expectFlagsNode.execute(args[1]) : ""; RegexSource regexSource = new RegexSource(pattern, flags); return receiver.compile(regexSource); } }
@Override protected Object executeImpl(PolyglotLanguageContext context, Object receiver, Object[] args) { Object[] instantiateArguments = toGuestValues.apply(context, (Object[]) args[ARGUMENT_OFFSET]); try { return toHostValue.execute(context, ForeignAccess.sendNew(newInstanceNode, (TruffleObject) receiver, instantiateArguments)); } catch (UnsupportedTypeException e) { CompilerDirectives.transferToInterpreter(); throw invalidInstantiateArgumentType(context, receiver, args); } catch (ArityException e) { CompilerDirectives.transferToInterpreter(); throw invalidInstantiateArity(context, receiver, args, e.getExpectedArity(), e.getActualArity()); } catch (UnsupportedMessageException e) { CompilerDirectives.transferToInterpreter(); return newInstanceUnsupported(context, receiver); } }
private Object newArray(HostObject receiver, Object[] args) { if (args.length != 1) { throw ArityException.raise(1, args.length); } if (toJava == null) { CompilerDirectives.transferToInterpreterAndInvalidate(); toJava = insert(ToHostNode.create()); } int length; try { length = (int) toJava.execute(args[0], int.class, null, receiver.languageContext); } catch (ClassCastException | NullPointerException e) { // conversion failed by ToJavaNode throw UnsupportedTypeException.raise(e, args); } Object array = Array.newInstance(receiver.asClass().getComponentType(), length); return HostObject.forObject(array, receiver.languageContext); }
protected final Object executeShared(PolyglotLanguageContext context, Object receiver, String key, Object[] guestArguments) { TruffleObject truffleReceiver = (TruffleObject) receiver; try { return ForeignAccess.sendInvoke(invokeNode, truffleReceiver, key, guestArguments); } catch (UnsupportedMessageException e) { CompilerDirectives.transferToInterpreter(); invokeUnsupported(context, receiver, key); return null; } catch (UnknownIdentifierException e) { CompilerDirectives.transferToInterpreter(); throw invalidMemberKey(context, receiver, key); } catch (UnsupportedTypeException e) { CompilerDirectives.transferToInterpreter(); throw invalidExecuteArgumentType(context, receiver, e); } catch (ArityException e) { CompilerDirectives.transferToInterpreter(); throw invalidExecuteArity(context, receiver, guestArguments, e.getExpectedArity(), e.getActualArity()); } }
public Object access(RegexCompiler receiver, Object[] args) { if (!(args.length == 1 || args.length == 2)) { throw ArityException.raise(2, args.length); } if (!(args[0] instanceof String)) { throw UnsupportedTypeException.raise(args); } String pattern = (String) args[0]; String flags = ""; if (args.length == 2) { if (!(args[1] instanceof String)) { throw UnsupportedTypeException.raise(args); } flags = (String) args[1]; } RegexSource regexSource = new RegexSource(pattern, flags); return receiver.compile(regexSource); } }
CompilerDirectives.transferToInterpreter(); if (executable) { throw JavaInteropErrors.invalidExecuteArity(languageContext, function, functionArgs, e.getExpectedArity(), e.getActualArity()); } else { throw JavaInteropErrors.invalidInstantiateArity(languageContext, function, functionArgs, e.getExpectedArity(), e.getActualArity());
throw ArityException.raise((args.length > maxOverallArity ? maxOverallArity : minOverallArity), args.length);
CompilerDirectives.transferToInterpreter(); if (executable) { throw HostInteropErrors.invalidExecuteArity(languageContext, function, functionArgs, e.getExpectedArity(), e.getActualArity()); } else { throw HostInteropErrors.invalidInstantiateArity(languageContext, function, functionArgs, e.getExpectedArity(), e.getActualArity());
private Object newArray(JavaObject receiver, Object[] args) { if (args.length != 1) { throw ArityException.raise(1, args.length); } if (toJava == null) { CompilerDirectives.transferToInterpreterAndInvalidate(); toJava = insert(ToJavaNode.create()); } int length; try { length = (int) toJava.execute(args[0], int.class, null, receiver.languageContext); } catch (ClassCastException | NullPointerException e) { // conversion failed by ToJavaNode throw UnsupportedTypeException.raise(e, args); } Object array = Array.newInstance(receiver.asClass().getComponentType(), length); return JavaObject.forObject(array, receiver.languageContext); }
} catch (ArityException e) { CompilerDirectives.transferToInterpreter(); throw HostInteropErrors.invalidExecuteArity(polyglotContext, receiver, arguments, e.getExpectedArity(), e.getActualArity()); } catch (UnsupportedMessageException e) { CompilerDirectives.transferToInterpreter();
public Object access(ComplexNumber complex, String identifier, Object[] arguments) { if (arguments.length != 1) { throw ArityException.raise(1, arguments.length); } if (!(arguments[0] instanceof ComplexNumber)) { throw UnsupportedTypeException.raise(arguments); } ComplexNumber a = complex; ComplexNumber b = (ComplexNumber) arguments[0]; switch (identifier) { case ADD: return add(a, b); case SUB: return sub(a, b); default: throw UnknownIdentifierException.raise(identifier); } }
} catch (ArityException e) { CompilerDirectives.transferToInterpreter(); throw JavaInteropErrors.invalidExecuteArity(polyglotContext, receiver, arguments, e.getExpectedArity(), e.getActualArity()); } catch (UnsupportedMessageException e) { CompilerDirectives.transferToInterpreter();