FloatObjectSite.java

  1. package org.jruby.ir.targets;

  2. import org.jruby.RubyFloat;
  3. import org.jruby.runtime.ThreadContext;
  4. import org.jruby.runtime.builtin.IRubyObject;
  5. import org.objectweb.asm.Handle;
  6. import org.objectweb.asm.Opcodes;

  7. import java.lang.invoke.CallSite;
  8. import java.lang.invoke.MethodHandles;
  9. import java.lang.invoke.MethodType;

  10. import static org.jruby.util.CodegenUtils.p;
  11. import static org.jruby.util.CodegenUtils.sig;

  12. /**
  13. * Created by headius on 10/23/14.
  14. */
  15. public class FloatObjectSite extends LazyObjectSite {
  16.     private final double value;

  17.     public FloatObjectSite(MethodType type, double value) {
  18.         super(type);

  19.         this.value = value;
  20.     }

  21.     public static final Handle BOOTSTRAP = new Handle(Opcodes.H_INVOKESTATIC, p(FloatObjectSite.class), "bootstrap", sig(CallSite.class, MethodHandles.Lookup.class, String.class, MethodType.class, double.class));

  22.     public static CallSite bootstrap(MethodHandles.Lookup lookup, String name, MethodType type, double value) {
  23.         return new FloatObjectSite(type, value).bootstrap(lookup);
  24.     }

  25.     public IRubyObject construct(ThreadContext context) {
  26.         return RubyFloat.newFloat(context.runtime, value);
  27.     }
  28. }