private Object doNewInstance( VirtualFrame frame, DynamicObject rubyClass, Object[] args, DynamicObject block) { assert block == null || RubyGuards.isRubyProc(block); final Object instance = allocateNode.call(frame, rubyClass, "allocate", null); initialize.call(frame, instance, "initialize", block, args); return instance; }
@Specialization public RubyString toS(VirtualFrame frame, RubyRange.ObjectRange range) { notDesignedForCompilation(); // TODO(CS): cast? final RubyString begin = (RubyString) toS.call(frame, range.getBegin(), "to_s", null); final RubyString end = (RubyString) toS.call(frame, range.getBegin(), "to_s", null); return getContext().makeString(begin + (range.doesExcludeEnd() ? "..." : "..") + end); }
@Specialization(guards = "!isRubyString(object)") public RubyBasicObject coerceObject(VirtualFrame frame, Object object) { final Object coerced; try { coerced = toStrNode.call(frame, object, "to_str", null); } catch (RaiseException e) { if (((RubyBasicObject) e.getRubyException()).getLogicalClass() == getContext().getCoreLibrary().getNoMethodErrorClass()) { CompilerDirectives.transferToInterpreter(); throw new RaiseException( getContext().getCoreLibrary().typeErrorNoImplicitConversion(object, "String", this)); } else { throw e; } } if (RubyGuards.isRubyString(coerced)) { return (RubyBasicObject) coerced; } else { CompilerDirectives.transferToInterpreter(); throw new RaiseException( getContext() .getCoreLibrary() .typeErrorBadCoercion(object, "String", "to_str", coerced, this)); } }
void triggerInheritedHook( VirtualFrame frame, DynamicObject subClass, DynamicObject superClass) { assert RubyGuards.isRubyClass(subClass); assert RubyGuards.isRubyClass(superClass); if (inheritedNode == null) { CompilerDirectives.transferToInterpreter(); inheritedNode = insert(DispatchHeadNodeFactory.createMethodCallOnSelf(getContext())); } inheritedNode.call(frame, superClass, "inherited", null, subClass); }
@Override public Object execute(VirtualFrame frame) { final Object tz = hashNode.call(frame, envNode.execute(frame), "[]", null, TZ); // TODO CS 4-May-15 not sure how TZ ends up being nil if (tz == nil()) { return createString("UTC"); } else if (RubyGuards.isRubyString(tz)) { return tz; } else { throw new UnsupportedOperationException(); } }
@Specialization(guards = "!isRubyBignum(b)") public boolean equal(VirtualFrame frame, DynamicObject a, DynamicObject b) { if (booleanCastNode == null) { CompilerDirectives.transferToInterpreter(); booleanCastNode = insert(BooleanCastNodeGen.create(getContext(), getSourceSection(), null)); } if (reverseCallNode == null) { CompilerDirectives.transferToInterpreter(); reverseCallNode = insert(DispatchHeadNodeFactory.createMethodCall(getContext())); } final Object reversedResult = reverseCallNode.call(frame, b, "==", null, a); return booleanCastNode.executeBoolean(frame, reversedResult); }
@Specialization public Object full(VirtualFrame frame, DynamicObject matchData) { if (getFullTuple(matchData) != null) { return getFullTuple(matchData); } if (newTupleNode == null) { CompilerDirectives.transferToInterpreter(); newTupleNode = insert(DispatchHeadNodeFactory.createMethodCall(getContext())); } final Object fullTuple = newTupleNode.call( frame, getContext().getCoreLibrary().getTupleClass(), "create", null, getFullBegin(matchData), getFullEnd(matchData)); setFullTuple(matchData, fullTuple); return fullTuple; }