Guest User

Untitled

a guest
Apr 25th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. def add
  2. <<-CODE
  3. #{check_arity(1)};
  4. IRubyObject arg = args[0];
  5. #{guard(fixnum?('arg'))};
  6. if (#{fixnum?('arg')}) {
  7. return #{to_fixnum('arg')}.op_plus(context, arg);
  8. } else if (#{bignum?('arg')}) {
  9. return #{to_bignum('arg')}.op_plus(context, arg);
  10. } else if (#{float?('arg')}) {
  11. return #{to_float('arg')}.op_plus(context, arg);
  12. } else {
  13. throw new RuntimeException(\"primitive :add failed to find a type match\");
  14. }
  15. CODE
  16. end
  17. ##
  18. public static IRubyObject cpu_primitive_add(ThreadContext context, IRubyObject self, IRubyObject[] args, Block block) {
  19. Arity.checkArgumentCount(context.getRuntime(), args, 1, 1);
  20. IRubyObject arg = args[0];
  21. assert arg instanceof RubyFixnum : "'arg instanceof RubyFixnum' failed";
  22. if (arg instanceof RubyFixnum) {
  23. return (RubyFixnum(arg)).op_plus(context, arg);
  24. } else if (arg instanceof RubyBignum) {
  25. return (RubyBignum(arg)).op_plus(context, arg);
  26. } else if (arg instanceof RubyFloat) {
  27. return (RubyFloat(arg)).op_plus(context, arg);
  28. } else {
  29. throw new RuntimeException("primitive :add failed to find a type match");
  30. }
  31. }
Add Comment
Please, Sign In to add comment