@Override public Object get(int index) { try { return ForeignAccess.sendRead(nodes.read, object, index); } catch (UnknownIdentifierException | UnsupportedMessageException ex) { throw ex.raise(); } }
@Override public Object get(int index) { try { return ForeignAccess.sendRead(nodes.read, object, index); } catch (UnknownIdentifierException | UnsupportedMessageException ex) { throw ex.raise(); } }
@Override public Object getValue() { try { return ForeignAccess.sendRead(nodes.read, object, key); } catch (UnknownIdentifierException | UnsupportedMessageException ex) { throw ex.raise(); } }
@Override public Object get(Object key) { try { return ForeignAccess.sendRead(nodes.read, object, key); } catch (UnknownIdentifierException ex) { return null; // key not present in the map } catch (UnsupportedMessageException ex) { throw ex.raise(); } }
@Override public Object getValue() { try { return ForeignAccess.sendRead(nodes.read, object, key); } catch (UnknownIdentifierException | UnsupportedMessageException ex) { throw ex.raise(); } }
@Override public Object get(Object key) { try { return ForeignAccess.sendRead(nodes.read, object, key); } catch (UnknownIdentifierException ex) { return null; // key not present in the map } catch (UnsupportedMessageException ex) { throw ex.raise(); } }
@Override public Entry<Object, Object> next() { Object key; try { key = ForeignAccess.sendRead(nodes.read, props, index++); } catch (UnknownIdentifierException | UnsupportedMessageException ex) { throw ex.raise(); } return new TruffleEntry(nodes, object, key); }
@Override public Entry<Object, Object> next() { Object key; try { key = ForeignAccess.sendRead(nodes.read, props, index++); } catch (UnknownIdentifierException | UnsupportedMessageException ex) { throw ex.raise(); } return new TruffleEntry(key); }
@TruffleBoundary private Object collectKeys(TruffleObject[] scopes) throws UnsupportedMessageException { // unfortunately we cannot do much butter as scopes might have // overlapping keys. So we need to make the set unique. Set<String> keySet = new HashSet<>(); for (TruffleObject scope : scopes) { TruffleObject keys = ForeignAccess.sendKeys(keysNode, scope); int size = ((Number) ForeignAccess.sendGetSize(getSizeNode, keys)).intValue(); for (int i = 0; i < size; i++) { try { keySet.add((String) ForeignAccess.sendRead(readNode, keys, i)); } catch (UnknownIdentifierException e) { } } } return new DefaultScope.VariableNamesObject(keySet); }
@TruffleBoundary private Object collectKeys(TruffleObject[] scopes) throws UnsupportedMessageException { // unfortunately we cannot do much butter as scopes might have // overlapping keys. So we need to make the set unique. Set<String> keySet = new HashSet<>(); for (TruffleObject scope : scopes) { TruffleObject keys = ForeignAccess.sendKeys(keysNode, scope); int size = ((Number) ForeignAccess.sendGetSize(getSizeNode, keys)).intValue(); for (int i = 0; i < size; i++) { try { keySet.add((String) ForeignAccess.sendRead(readNode, keys, i)); } catch (UnknownIdentifierException e) { } } } return new DefaultScope.VariableNamesObject(keySet); }
@Override Object execute(TruffleObject[] scopes, int length, Object[] arguments, int offset) throws UnknownIdentifierException, UnsupportedMessageException { String identifier = expectIdentifier(arguments, offset, Message.READ); if (isConstantSingleLength()) { return ForeignAccess.sendRead(readNode, scopes[0], identifier); } else if (length > 0) { for (int i = 0; i < length; i++) { TruffleObject scopeObject = scopes[i]; if (KeyInfo.isReadable(ForeignAccess.sendKeyInfo(keyInfoNode, scopeObject, identifier))) { return ForeignAccess.sendRead(readNode, scopeObject, identifier); } } } throw UnknownIdentifierException.raise(identifier); }
@Override Object execute(TruffleObject[] scopes, int length, Object[] arguments, int offset) throws UnknownIdentifierException, UnsupportedMessageException { String identifier = expectIdentifier(arguments, offset, Message.READ); if (isConstantSingleLength()) { return ForeignAccess.sendRead(readNode, scopes[0], identifier); } else if (length > 0) { for (int i = 0; i < length; i++) { TruffleObject scopeObject = scopes[i]; if (KeyInfo.isReadable(ForeignAccess.sendKeyInfo(keyInfoNode, scopeObject, identifier))) { return ForeignAccess.sendRead(readNode, scopeObject, identifier); } } } throw UnknownIdentifierException.raise(identifier); }
public Object access(VirtualFrame frame, ComplexNumbersB complexNumbers, Number index, TruffleObject value) { if (readReal == null || readImag == null) { CompilerDirectives.transferToInterpreterAndInvalidate(); this.readReal = insert(Message.READ.createNode()); this.readImag = insert(Message.READ.createNode()); } try { Number realPart = TckLanguage.expectNumber(ForeignAccess.sendRead(readReal, value, ComplexNumber.REAL_IDENTIFIER)); Number imagPart = TckLanguage.expectNumber(ForeignAccess.sendRead(readImag, value, ComplexNumber.IMAGINARY_IDENTIFIER)); complexNumbers.getReals()[index.intValue()] = realPart.doubleValue(); complexNumbers.getImags()[index.intValue()] = imagPart.doubleValue(); return value; } catch (UnknownIdentifierException | UnsupportedMessageException e) { return null; } }
@Specialization public char doCharAt(TruffleObject input, int index, @Cached("createReadMessageNode()") Node readNode) { try { Object c = ForeignAccess.sendRead(readNode, input, index); if (c instanceof Character) { return (char) c; } else if (c instanceof Number) { assert ((Number) c).intValue() < Character.MAX_VALUE; return (char) ((Number) c).intValue(); } CompilerDirectives.transferToInterpreter(); throw UnsupportedTypeException.raise(new Object[]{c}); } catch (UnknownIdentifierException | UnsupportedMessageException e) { CompilerDirectives.transferToInterpreter(); throw new RuntimeException(e); } } }
public Object access(ComplexNumbersA complexNumbers, Number index, TruffleObject value) { if (readReal == null || readImag == null) { CompilerDirectives.transferToInterpreterAndInvalidate(); this.readReal = insert(Message.READ.createNode()); this.readImag = insert(Message.READ.createNode()); } try { Number realPart = TckLanguage.expectNumber(ForeignAccess.sendRead(readReal, value, new Object[]{ComplexNumber.REAL_IDENTIFIER})); Number imagPart = TckLanguage.expectNumber(ForeignAccess.sendRead(readImag, value, new Object[]{ComplexNumber.IMAGINARY_IDENTIFIER})); int idx = TckLanguage.checkBounds(index.intValue(), complexNumbers.getData().length / 2); complexNumbers.getData()[idx * 2] = realPart.doubleValue(); complexNumbers.getData()[idx * 2 + 1] = imagPart.doubleValue(); return value; } catch (UnknownIdentifierException | UnsupportedMessageException e) { return null; } }
@Override protected Object executeImpl(PolyglotLanguageContext languageContext, TruffleObject receiver, Object[] args) { Object key = args[ARGUMENT_OFFSET]; Object result = null; if (isValidKey(receiver, key) && KeyInfo.isReadable(sendKeyInfo(keyInfo, receiver, key))) { try { result = toHost.execute(sendRead(read, receiver, key), cache.valueClass, cache.valueType, languageContext); } catch (ClassCastException | NullPointerException e) { // expected exceptions from casting to the host value. throw e; } catch (UnknownIdentifierException e) { return null; } catch (UnsupportedMessageException e) { // be robust for misbehaving languages return null; } } return result; }
@Override protected Object executeImpl(Object languageContext, TruffleObject receiver, Object[] args, int offset) { Object key = args[offset]; Object result = null; if (isValidKey(receiver, key) && KeyInfo.isReadable(sendKeyInfo(keyInfo, receiver, key))) { try { result = toHost.execute(sendRead(read, receiver, key), cache.valueClass, cache.valueType, languageContext); } catch (ClassCastException | NullPointerException e) { // expected exceptions from casting to the host value. throw e; } catch (UnknownIdentifierException e) { return null; } catch (UnsupportedMessageException e) { // be robust for misbehaving languages return null; } } return result; }
@Override protected Object executeImpl(PolyglotLanguageContext context, Object receiver, Object[] args) { long index = (long) args[ARGUMENT_OFFSET]; try { return toHostValue.execute(context, ForeignAccess.sendRead(readArrayNode, (TruffleObject) receiver, index)); } catch (UnsupportedMessageException e) { CompilerDirectives.transferToInterpreter(); return getArrayElementUnsupported(context, receiver); } catch (UnknownIdentifierException e) { CompilerDirectives.transferToInterpreter(); throw invalidArrayIndex(context, receiver, index); } }
@Override protected Object executeImpl(Object receiver, Object[] args) { long index = (long) args[1]; try { return toHostValue.execute(ForeignAccess.sendRead(readArrayNode, (TruffleObject) receiver, index)); } catch (UnsupportedMessageException e) { CompilerDirectives.transferToInterpreter(); return polyglot.getArrayElementUnsupported(receiver); } catch (UnknownIdentifierException e) { CompilerDirectives.transferToInterpreter(); throw invalidArrayIndex(polyglot.languageContext, receiver, index); } }
Object lookupGuest(String symbolName) { ensureInitialized(null); Iterable<?> topScopes = VMAccessor.instrumentAccess().findTopScopes(env); for (Object topScope : topScopes) { Scope scope = (Scope) topScope; TruffleObject variables = (TruffleObject) scope.getVariables(); int symbolInfo = ForeignAccess.sendKeyInfo(keyInfoNode, variables, symbolName); if (KeyInfo.isExisting(symbolInfo) && KeyInfo.isReadable(symbolInfo)) { try { return ForeignAccess.sendRead(readNode, variables, symbolName); } catch (InteropException ex) { throw new AssertionError(symbolName, ex); } } } return null; }