Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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");
- }
- }
Add Comment
Please, Sign In to add comment