Guest User

Untitled

a guest
Apr 25th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. ~/NetBeansProjects/rubinius ➔ ruby -r shotgun/lib/primitives.rb -r shotgun/lib/jprimitives.rb -e "ShotgunPrimitives.new.generate_select(STDOUT)"
  2. ## RubiniusPrimitives.java
  3. public static IRubyObject cpu_primitive_add(ThreadContext context, IRubyObject self, IRubyObject[] args, Block block) {
  4. ARITY(1);
  5. GUARD(FIXNUM_P(msg->recv));
  6. OBJECT t1 = stack_pop();
  7. if(FIXNUM_P(t1)) {
  8. RET(fixnum_add(state, msg->recv, t1));
  9. } else if(BIGNUM_P(t1)) {
  10. RET(bignum_add(state, bignum_new(state, N2I(msg->recv)), t1));
  11. } else if(FLOAT_P(t1)) {
  12. OBJECT t2 = float_coerce(state, msg->recv);
  13. RET(float_new(state, FLOAT_TO_DOUBLE(t2) + FLOAT_TO_DOUBLE(t1)));
  14. } else {
  15. FAIL();
  16. }
  17. }
  18. public static IRubyObject cpu_primitive_bignum_add(ThreadContext context, IRubyObject self, IRubyObject[] args, Block block) {
  19. ARITY(1);
  20. GUARD(BIGNUM_P(msg->recv));
  21. OBJECT t1 = stack_pop();
  22. if(BIGNUM_P(t1) || FIXNUM_P(t1)) {
  23. RET(bignum_add(state, msg->recv, t1));
  24. } else if(FLOAT_P(t1)) {
  25. double a = bignum_to_double(state, msg->recv);
  26. RET(float_new(state, a + FLOAT_TO_DOUBLE(t1)));
  27. } else {
  28. FAIL();
  29. }
  30. }
  31. public static IRubyObject cpu_primitive_sub(ThreadContext context, IRubyObject self, IRubyObject[] args, Block block) {
  32. ARITY(1);
  33. GUARD(FIXNUM_P(msg->recv));
  34. OBJECT t1 = stack_pop();
  35. if(FIXNUM_P(t1)) {
  36. RET(fixnum_sub(state, msg->recv, t1));
  37. } else if(BIGNUM_P(t1)) {
  38. RET(bignum_sub(state, bignum_new(state, N2I(msg->recv)), t1));
  39. } else if(FLOAT_P(t1)) {
  40. OBJECT t2 = float_coerce(state, msg->recv);
  41. RET(float_new(state, FLOAT_TO_DOUBLE(t2) - FLOAT_TO_DOUBLE(t1)));
  42. } else {
  43. FAIL();
  44. ...
Add Comment
Please, Sign In to add comment