Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
This paste will be private.
def add <<-CODE #{check_arity(1)}; IRubyObject arg = args[0]; #{guard(fixnum?('arg'))}; if (#{fixnum?('arg')}) { return #{to_fixnum('arg')}.op_plus(context, arg); } else if (#{bignum?('arg')}) { return #{to_bignum('arg')}.op_plus(context, arg); } else if (#{float?('arg')}) { return #{to_float('arg')}.op_plus(context, arg); } else { throw new RuntimeException(\"primitive :add failed to find a type match\"); } CODE end ## public static IRubyObject cpu_primitive_add(ThreadContext context, IRubyObject self, IRubyObject[] args, Block block) { Arity.checkArgumentCount(context.getRuntime(), args, 1, 1); IRubyObject arg = args[0]; assert arg instanceof RubyFixnum : "'arg instanceof RubyFixnum' failed"; if (arg instanceof RubyFixnum) { return (RubyFixnum(arg)).op_plus(context, arg); } else if (arg instanceof RubyBignum) { return (RubyBignum(arg)).op_plus(context, arg); } else if (arg instanceof RubyFloat) { return (RubyFloat(arg)).op_plus(context, arg); } else { throw new RuntimeException("primitive :add failed to find a type match"); } }
From the Design Piracy series on my blog: