@MessageResolution(receiverType = TruffleNull.class) static class TruffleNullMessageResolution { @Resolve(message = "IS_NULL") abstract static class TruffleNullIsNullNode extends Node { @SuppressWarnings("unused") public boolean access(TruffleNull obj) { return true; } } } }
static String getReceiverTypeFullClassName(MessageResolution message) { String receiverTypeFullClassName; try { message.receiverType().getName(); throw new AssertionError(); } catch (MirroredTypeException mte) { // This exception is always thrown: use the mirrors to inspect the class receiverTypeFullClassName = ElementUtils.getQualifiedName(mte.getTypeMirror()); } return receiverTypeFullClassName; }
private static boolean isReceiverNonStaticInner(MessageResolution message) { try { message.receiverType(); throw new AssertionError(); } catch (MirroredTypeException mte) { // This exception is always thrown: use the mirrors to inspect the class DeclaredType type = (DeclaredType) mte.getTypeMirror(); TypeElement element = (TypeElement) type.asElement(); if (element.getNestingKind() == NestingKind.MEMBER || element.getNestingKind() == NestingKind.LOCAL) { for (Modifier modifier : element.getModifiers()) { if (modifier.compareTo(Modifier.STATIC) == 0) { return false; } } return true; } else { return false; } } }
@MessageResolution(receiverType = RegexObjectExecMethod.class) class RegexObjectExecMethodMessageResolution { @Resolve(message = "EXECUTE") abstract static class ExecuteRegexExecNode extends Node { @Child private ExecuteRegexObjectNode executeNode = ExecuteRegexObjectNode.create(); 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]); } } @Resolve(message = "IS_EXECUTABLE") abstract static class IsExecutableRegexExecNode extends Node { @SuppressWarnings("unused") public boolean access(RegexObjectExecMethod receiver) { return true; } } }
@MessageResolution(receiverType = HostFunction.class) class HostFunctionMR { @Resolve(message = "EXECUTE") abstract static class ExecuteNode extends Node { @Child private HostExecuteNode doExecute; public Object access(HostFunction function, Object[] args) { if (doExecute == null) { CompilerDirectives.transferToInterpreterAndInvalidate(); doExecute = insert(HostExecuteNode.create()); } return doExecute.execute(function.method, function.obj, args, function.languageContext); } } @Resolve(message = "IS_EXECUTABLE") abstract static class IsExecutableNode extends Node { public Object access(@SuppressWarnings("unused") HostFunction receiver) { return Boolean.TRUE; } } }
@MessageResolution(receiverType = NullValue.class) static final class NullValue implements TruffleObject { private static final NullValue INSTANCE = new NullValue(); NullValue() { } @Resolve(message = "IS_NULL") abstract static class IsNull extends Node { public Object access(@SuppressWarnings("unused") NullValue receiver) { return true; } } @Override public ForeignAccess getForeignAccess() { return NullValueForeign.ACCESS; } static boolean isInstance(TruffleObject array) { return array instanceof NullValue; } }
@MessageResolution(receiverType = JavaFunctionObject.class) class JavaFunctionMessageResolution { @Resolve(message = "EXECUTE") abstract static class ExecuteNode extends Node { @Child private ExecuteMethodNode doExecute; public Object access(JavaFunctionObject function, Object[] args) { if (doExecute == null) { CompilerDirectives.transferToInterpreterAndInvalidate(); doExecute = insert(ExecuteMethodNode.create()); } return doExecute.execute(function.method, function.obj, args, function.languageContext); } } @Resolve(message = "IS_EXECUTABLE") abstract static class IsExecutableNode extends Node { public Object access(@SuppressWarnings("unused") JavaFunctionObject receiver) { return Boolean.TRUE; } } }
@SuppressWarnings("unused") @MessageResolution(receiverType = StructuredData.class) class StructuredDataMessageResolution { @Resolve(message = "GET_SIZE")
@MessageResolution(receiverType = RegexEngine.class) static class RegexEngineMessageResolution { @Resolve(message = "EXECUTE") abstract static class RegexEngineExecuteNode extends Node { @Child private ExpectStringNode expectPatternNode = ExpectStringNode.create(); @Child private ExpectStringNode expectFlagsNode = ExpectStringNode.create(); 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); } } @Resolve(message = "IS_EXECUTABLE") abstract static class RegexEngineIsExecutableNode extends Node { @SuppressWarnings("unused") public boolean access(RegexEngine receiver) { return true; } } } }
@MessageResolution(receiverType = CompiledRegexObject.class) static class CompiledRegexObjectMessageResolution { @Resolve(message = "EXECUTE") abstract static class CompiledRegexObjectExecuteNode extends Node { @Child private ExecuteRegexDispatchNode doExecute = ExecuteRegexDispatchNode.create(); 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]); } } @Resolve(message = "IS_EXECUTABLE") abstract static class CompiledRegexObjectIsExecutableNode extends Node { @SuppressWarnings("unused") public boolean access(CompiledRegexObject receiver) { return true; } } } }
@MessageResolution(receiverType = ErrnoMirror.class) public final class ErrnoMirrorMessageResolution {
@MessageResolution(receiverType = VariableNamesObject.class) static final class VariableNamesMessageResolution { @Resolve(message = "HAS_SIZE") abstract static class VarNamesHasSizeNode extends Node { public Object access(VariableNamesObject varNames) { return true; } } @Resolve(message = "GET_SIZE") abstract static class VarNamesGetSizeNode extends Node { public Object access(VariableNamesObject varNames) { return varNames.names.size(); } } @Resolve(message = "READ") abstract static class VarNamesReadNode extends Node { @TruffleBoundary public Object access(VariableNamesObject varNames, int index) { try { return varNames.names.get(index); } catch (IndexOutOfBoundsException ioob) { throw UnknownIdentifierException.raise(Integer.toString(index)); } } } } }
@MessageResolution(receiverType = VariableNamesObject.class) static final class VariableNamesMessageResolution { @Resolve(message = "HAS_SIZE") abstract static class VarNamesHasSizeNode extends Node { @SuppressWarnings("unused") public Object access(VariableNamesObject varNames) { return true; } } @Resolve(message = "GET_SIZE") abstract static class VarNamesGetSizeNode extends Node { public Object access(VariableNamesObject varNames) { return varNames.names.size(); } } @Resolve(message = "READ") abstract static class VarNamesReadNode extends Node { @TruffleBoundary public Object access(VariableNamesObject varNames, int index) { try { return varNames.names.get(index); } catch (IndexOutOfBoundsException ioob) { throw UnknownIdentifierException.raise(Integer.toString(index)); } } } } }
@MessageResolution(receiverType = ClassNamesObject.class) static final class ClassNamesMessageResolution { @Resolve(message = "HAS_SIZE") abstract static class ClassNamesHasSizeNode extends Node { @SuppressWarnings("unused") public Object access(ClassNamesObject varNames) { return true; } } @Resolve(message = "GET_SIZE") abstract static class ClassNamesGetSizeNode extends Node { public Object access(ClassNamesObject varNames) { return varNames.names.size(); } } @Resolve(message = "READ") abstract static class ClassNamesReadNode extends Node { @TruffleBoundary public Object access(ClassNamesObject varNames, int index) { try { return varNames.names.get(index); } catch (IndexOutOfBoundsException ioob) { throw UnknownIdentifierException.raise(Integer.toString(index)); } } } } }
@MessageResolution(receiverType = TruffleReadOnlyMapKeysObject.class) static final class TruffleReadOnlyMapKeysObjectMessageResolution { @Resolve(message = "HAS_SIZE") abstract static class TruffleReadOnlyMapKeysObjectHasSizeNode extends Node { @SuppressWarnings("unused") public Object access(TruffleReadOnlyMapKeysObject keysObject) { return true; } } @Resolve(message = "GET_SIZE") abstract static class TruffleReadOnlyMapKeysObjectGetSizeNode extends Node { public Object access(TruffleReadOnlyMapKeysObject keysObject) { return keysObject.keys.length; } } @Resolve(message = "READ") abstract static class TruffleReadOnlyMapKeysObjectReadNode extends Node { public Object access(TruffleReadOnlyMapKeysObject keysObject, int index) { if (index >= keysObject.keys.length) { CompilerDirectives.transferToInterpreter(); throw UnknownIdentifierException.raise(Integer.toString(index)); } return keysObject.keys[index]; } } } }
@MessageResolution(receiverType = ClassNamesObject.class) static final class ClassNamesMessageResolution { @Resolve(message = "HAS_SIZE") abstract static class ClassNamesHasSizeNode extends Node { @SuppressWarnings("unused") public Object access(ClassNamesObject varNames) { return true; } } @Resolve(message = "GET_SIZE") abstract static class ClassNamesGetSizeNode extends Node { public Object access(ClassNamesObject varNames) { return varNames.names.size(); } } @Resolve(message = "READ") abstract static class ClassNamesReadNode extends Node { @TruffleBoundary public Object access(ClassNamesObject varNames, int index) { try { return varNames.names.get(index); } catch (IndexOutOfBoundsException ioob) { throw UnknownIdentifierException.raise(Integer.toString(index)); } } } } }
@MessageResolution(receiverType = RegexCompiler.class) static class RegexCompilerMessageResolution {
@MessageResolution(receiverType = EmptyGlobalBindings.class) static class EmptyGlobalBindingsResolution {
@MessageResolution(receiverType = StructuredDataEntry.class) class StructuredDataEntryMessageResolution {
@MessageResolution(receiverType = VariableNamesObject.class) static final class VariableNamesMessageResolution { @Resolve(message = "HAS_SIZE") abstract static class VarNamesHasSizeNode extends Node { @SuppressWarnings("unused") public Object access(VariableNamesObject varNames) { return true; } } @Resolve(message = "GET_SIZE") abstract static class VarNamesGetSizeNode extends Node { public Object access(VariableNamesObject varNames) { return varNames.names.size(); } } @Resolve(message = "READ") abstract static class VarNamesReadNode extends Node { @TruffleBoundary public Object access(VariableNamesObject varNames, int index) { try { return varNames.names.get(index); } catch (IndexOutOfBoundsException ioob) { throw UnknownIdentifierException.raise(Integer.toString(index)); } } } } }