protected long getAddressFromSymbolInfo(VirtualFrame frame, RList symbol) { if (addressExtract == null) { CompilerDirectives.transferToInterpreterAndInvalidate(); addressExtract = ExtractVectorNode.create(ElementAccessMode.SUBSCRIPT, true); } return ((RExternalPtr) addressExtract.applyAccessField(frame, symbol, "address")).getAddr(); }
@ExplodeLoop @Override public RubyArray executeArray(VirtualFrame frame) { CompilerDirectives.transferToInterpreter(); final Object[] executedValues = new Object[values.length]; for (int n = 0; n < values.length; n++) { executedValues[n] = values[n].execute(frame); } final RubyArray array = RubyArray.fromObjects(getContext().getCoreLibrary().getArrayClass(), executedValues); final Object store = array.getStore(); if (store == null) { replace(new EmptyArrayLiteralNode(getContext(), getSourceSection(), values)); } if (store instanceof int[]) { replace(new IntegerFixnumArrayLiteralNode(getContext(), getSourceSection(), values)); } else if (store instanceof long[]) { replace(new LongFixnumArrayLiteralNode(getContext(), getSourceSection(), values)); } else if (store instanceof double[]) { replace(new FloatArrayLiteralNode(getContext(), getSourceSection(), values)); } else { replace(new ObjectArrayLiteralNode(getContext(), getSourceSection(), values)); } return array; }
protected String getNameFromSymbolInfo(VirtualFrame frame, RList symbol) { if (nameExtract == null) { CompilerDirectives.transferToInterpreterAndInvalidate(); nameExtract = ExtractVectorNode.create(ElementAccessMode.SUBSCRIPT, true); } return RRuntime.asString(nameExtract.applyAccessField(frame, symbol, "name")); }
@Override public Object execute(VirtualFrame frame) { if (CompilerDirectives.injectBranchProbability( getBranchProbability(), condition.executeBoolean(frame))) { if (CompilerDirectives.inInterpreter()) { thenCount++; } thenProfile.enter(); return thenBody.execute(frame); } else { if (CompilerDirectives.inInterpreter()) { elseCount++; } elseProfile.enter(); return elseBody.execute(frame); } }
@Override public void execute(VirtualFrame frame, Object value) { CompilerDirectives.transferToInterpreterAndInvalidate(); MaterializedFrame enclosingFrame = RArguments.getEnclosingFrame(frame); if (enclosingFrame != null) { execute(frame, value, enclosingFrame); } else { // we're in global scope, do a local write instead replace(UnresolvedWriteLocalFrameVariableNodeGen.create(getRhs(), symbol, mode)) .execute(frame, value); } }
@Override public boolean doesRespondTo(VirtualFrame frame, RubyBasicObject receiverObject) { // TODO(CS): copy-and-paste of the above - needs to be factored out MethodCacheEntry entry = lookupInCache(receiverObject.getLookupNode()); if (entry == null) { CompilerDirectives.transferToInterpreterAndInvalidate(); final RubyBasicObject boxedCallingSelf = getContext().getCoreLibrary().box(RubyArguments.getSelf(frame.getArguments())); try { entry = new MethodCacheEntry(lookup(boxedCallingSelf, receiverObject, name), false); } catch (UseMethodMissingException e) { try { entry = new MethodCacheEntry( lookup(boxedCallingSelf, receiverObject, "method_missing"), true); } catch (UseMethodMissingException e2) { throw new RaiseException( getContext() .getCoreLibrary() .runtimeError(receiverObject.toString() + " didn't have a #method_missing")); } } if (entry.isMethodMissing()) { hasAnyMethodsMissing = true; } cache.put(receiverObject.getLookupNode(), entry); if (cache.size() > RubyContext.GENERAL_DISPATCH_SIZE_WARNING_THRESHOLD) { getContext() .getRuntime() .getWarnings() .warn( IRubyWarnings.ID.TRUFFLE, getEncapsulatingSourceSection().getSource().getName(), getEncapsulatingSourceSection().getStartLine(), "general call node cache has " + cache.size() + " entries"); } } return !entry.isMethodMissing(); }
@Override public void setValue(VirtualFrame frame, PythonObject primary, Object value) { CompilerDirectives.transferToInterpreterAndInvalidate(); assert primary.verifyLayout(); if (!primary.getStableAssumption().isValid()) { primary.syncObjectLayoutWithClass(); } assert primary.verifyLayout(); SetDispatchNode current = this; int depth = 0; while (current.getParent() instanceof SetDispatchNode) { current = (SetDispatchNode) current.getParent(); depth++; if (!(current instanceof LinkedSetDispatchNode)) { continue; } /** * After the layout sync, if a previously missed dispatch node caches the updated layout, we * should reuse the existing dispatch node. */ LinkedSetDispatchNode linked = (LinkedSetDispatchNode) current; try { if (linked.check.accept(primary)) { linked.setValue(frame, primary, value); return; } } catch (InvalidAssumptionException e) { throw new RuntimeException(); } } if (depth < PythonOptions.AttributeAccessInlineCacheMaxDepth) { primary.setAttribute(attributeId, value); StorageLocation location = primary.getOwnValidLocation(attributeId); replace( new LinkedSetDispatchNode( attributeId, AttributeWriteNode.create(location), primary, this)); } else { replace(new GenericSetDispatchNode(attributeId)).setValue(frame, primary, value); } }
@Override public Object execute(VirtualFrame frame) { while (true) { try { final Object result = tryPart.execute(frame); elsePart.executeVoid(frame); return result; } catch (ControlFlowException exception) { controlFlowProfile.enter(); throw exception; } catch (RuntimeException exception) { CompilerDirectives.transferToInterpreter(); try { return handleException(frame, exception); } catch (RetryException e) { continue; } } } }
@Override public void execute(VirtualFrame frame, Object value, MaterializedFrame enclosingFrame) { CompilerDirectives.transferToInterpreterAndInvalidate(); if (getName().isEmpty()) { throw RError.error(this, RError.Message.ZERO_LENGTH_VARIABLE); } final WriteSuperFrameVariableNodeHelper writeNode; if (REnvironment.isGlobalEnvFrame(enclosingFrame)) { /* * we've reached the global scope, do unconditional write. if this is the first node * in the chain, needs the rhs and enclosingFrame nodes */ AccessEnclosingFrameNode enclosingFrameNode = RArguments.getEnclosingFrame(frame) == enclosingFrame ? new AccessEnclosingFrameNode() : null; writeNode = WriteSuperFrameVariableNodeGen.create( getRhs(), enclosingFrameNode, FrameSlotNode.create( findOrAddFrameSlot( enclosingFrame.getFrameDescriptor(), symbol, FrameSlotKind.Illegal)), getName(), mode); } else { WriteSuperFrameVariableNode actualWriteNode = WriteSuperFrameVariableNodeGen.create( null, null, FrameSlotNode.create(symbol), this.getName(), mode); writeNode = new WriteSuperFrameVariableConditionalNode( actualWriteNode, new UnresolvedWriteSuperFrameVariableNode(symbol, null, mode), getRhs()); } replace(writeNode).execute(frame, value, enclosingFrame); }
@Override public Object dispatch( VirtualFrame frame, RubyBasicObject receiverObject, RubyProc blockObject, Object[] argumentsObjects) { MethodCacheEntry entry = lookupInCache(receiverObject.getLookupNode()); if (entry == null) { CompilerDirectives.transferToInterpreterAndInvalidate(); final RubyBasicObject boxedCallingSelf = getContext().getCoreLibrary().box(RubyArguments.getSelf(frame.getArguments())); try { entry = new MethodCacheEntry(lookup(boxedCallingSelf, receiverObject, name), false); } catch (UseMethodMissingException e) { try { entry = new MethodCacheEntry( lookup(boxedCallingSelf, receiverObject, "method_missing"), true); } catch (UseMethodMissingException e2) { throw new RaiseException( getContext() .getCoreLibrary() .runtimeError(receiverObject.toString() + " didn't have a #method_missing")); } } if (entry.isMethodMissing()) { hasAnyMethodsMissing = true; } cache.put(receiverObject.getLookupNode(), entry); if (cache.size() > RubyContext.GENERAL_DISPATCH_SIZE_WARNING_THRESHOLD) { getContext() .getRuntime() .getWarnings() .warn( IRubyWarnings.ID.TRUFFLE, getEncapsulatingSourceSection().getSource().getName(), getEncapsulatingSourceSection().getStartLine(), "general call node cache has " + cache.size() + " entries"); } } final Object[] argumentsToUse; if (hasAnyMethodsMissing && entry.isMethodMissing()) { final Object[] modifiedArgumentsObjects = new Object[1 + argumentsObjects.length]; modifiedArgumentsObjects[0] = getContext().newSymbol(name); System.arraycopy(argumentsObjects, 0, modifiedArgumentsObjects, 1, argumentsObjects.length); argumentsToUse = modifiedArgumentsObjects; } else { argumentsToUse = argumentsObjects; } return callNode.call( frame, entry.getMethod().getCallTarget(), RubyArguments.pack( entry.getMethod().getDeclarationFrame(), receiverObject, blockObject, argumentsToUse)); }