1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
  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");
    }
}