Skip to content

Commit eaf9ae9

Browse files
committed
Implement StandardError, Float in IR JIT.
1 parent 129ff2d commit eaf9ae9

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

src/org/jruby/ir/targets/Bootstrap.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
import static java.lang.invoke.MethodHandles.*;
4141
import static java.lang.invoke.MethodType.methodType;
42+
import org.jruby.RubyFloat;
4243
import static org.jruby.runtime.invokedynamic.InvokeDynamicSupport.*;
4344
import static org.jruby.util.CodegenUtils.p;
4445
import static org.jruby.util.CodegenUtils.sig;
@@ -872,4 +873,32 @@ public static IRubyObject fixnum(MutableCallSite site, long value, ThreadContext
872873
);
873874
return fixnum;
874875
}
876+
877+
///////////////////////////////////////////////////////////////////////////
878+
// Float binding
879+
880+
public static Handle flote() {
881+
return new Handle(Opcodes.H_INVOKESTATIC, p(Bootstrap.class), "flote", sig(CallSite.class, Lookup.class, String.class, MethodType.class, double.class));
882+
}
883+
884+
public static CallSite flote(Lookup lookup, String name, MethodType type, double value) {
885+
MutableCallSite site = new MutableCallSite(type);
886+
MethodHandle handle = Binder
887+
.from(IRubyObject.class, ThreadContext.class)
888+
.insert(0, site, value)
889+
.cast(IRubyObject.class, MutableCallSite.class, double.class, ThreadContext.class)
890+
.invokeStaticQuiet(MethodHandles.lookup(), Bootstrap.class, "flote");
891+
site.setTarget(handle);
892+
return site;
893+
}
894+
895+
public static IRubyObject flote(MutableCallSite site, double value, ThreadContext context) {
896+
RubyFloat flote = RubyFloat.newFloat(context.runtime, value);
897+
site.setTarget(Binder
898+
.from(IRubyObject.class, ThreadContext.class)
899+
.drop(0)
900+
.constant(flote)
901+
);
902+
return flote;
903+
}
875904
}

src/org/jruby/ir/targets/IRBytecodeAdapter.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ public void push(Long l) {
5757
adapter.aload(0);
5858
adapter.invokedynamic("fixnum", sig(JVM.OBJECT, ThreadContext.class), Bootstrap.fixnum(), l);
5959
}
60+
61+
public void push(Double d) {
62+
adapter.aload(0);
63+
adapter.invokedynamic("flote", sig(JVM.OBJECT, ThreadContext.class), Bootstrap.flote(), d);
64+
}
6065

6166
public void push(ByteList bl) {
6267
adapter.aload(0);
@@ -186,8 +191,7 @@ public void pushBoolean(boolean b) {
186191
}
187192

188193
public void pushObjectClass() {
189-
adapter.aload(0);
190-
adapter.getfield(p(ThreadContext.class), "runtime", ci(Ruby.class));
194+
pushRuntime();
191195
adapter.invokevirtual(p(Ruby.class), "getObject", sig(RubyClass.class));
192196
}
193197

src/org/jruby/ir/targets/JVMVisitor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,8 +1234,7 @@ public void Fixnum(Fixnum fixnum) {
12341234

12351235
@Override
12361236
public void Float(org.jruby.ir.operands.Float flote) {
1237-
super.Float(flote);
1238-
// jvm.method().push(flote.getValue());
1237+
jvm.method().push(flote.getValue());
12391238
}
12401239

12411240
@Override
@@ -1312,7 +1311,8 @@ public void Splat(Splat splat) {
13121311

13131312
@Override
13141313
public void StandardError(StandardError standarderror) {
1315-
super.StandardError(standarderror); //To change body of overridden methods use File | Settings | File Templates.
1314+
jvm.method().pushRuntime();
1315+
jvm.method().adapter.invokevirtual(p(Ruby.class), "getStandardError", sig(RubyClass.class));
13161316
}
13171317

13181318
@Override

0 commit comments

Comments
 (0)