Skip to content

Commit c68d233

Browse files
committed
Implement Array operand IR2JVM.
1 parent 2a7805b commit c68d233

File tree

6 files changed

+41
-17
lines changed

6 files changed

+41
-17
lines changed

build_lib/invokebinder.jar

4.51 KB
Binary file not shown.

src/org/jruby/ir/operands/Array.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import java.util.List;
44
import java.util.Map;
5+
6+
import org.jruby.ir.targets.JVM;
57
import org.jruby.ir.transformations.inlining.InlinerInfo;
68
import org.jruby.runtime.DynamicScope;
79
import org.jruby.runtime.ThreadContext;
@@ -118,4 +120,15 @@ public Object retrieve(ThreadContext context, IRubyObject self, DynamicScope cur
118120

119121
return context.getRuntime().newArray(elements);
120122
}
123+
124+
@Override
125+
public void compile(JVM jvm) {
126+
jvm.method().loadLocal(0);
127+
128+
for (Operand operand : elts) {
129+
jvm.emit(operand);
130+
}
131+
132+
jvm.method().array(elts.length);
133+
}
121134
}

src/org/jruby/ir/operands/Operand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,6 @@ public Object retrieve(ThreadContext context, IRubyObject self, DynamicScope cur
8282
}
8383

8484
public void compile(JVM jvm) {
85-
throw new RuntimeException(this.getClass().getSimpleName() + " has no compile logic.");
85+
throw new RuntimeException("operand " + this.getClass().getSimpleName() + " has no compile logic.");
8686
}
8787
}

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

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
11
package org.jruby.ir.targets;
22

3-
import com.headius.invoke.binder.Binder;
4-
import org.jcodings.Encoding;
5-
import org.jcodings.EncodingDB;
6-
import org.jcodings.specific.USASCIIEncoding;
3+
import com.headius.invokebinder.Binder;
4+
import org.jruby.RubyArray;
75
import org.jruby.RubyClass;
86
import org.jruby.RubyEncoding;
97
import org.jruby.RubyFixnum;
10-
import org.jruby.RubyInstanceConfig;
118
import org.jruby.RubyString;
129
import org.jruby.RubySymbol;
1310
import org.jruby.internal.runtime.methods.DynamicMethod;
14-
import org.jruby.javasupport.util.RuntimeHelpers;
1511
import org.jruby.runtime.Block;
1612
import org.jruby.runtime.CallType;
1713
import org.jruby.runtime.ThreadContext;
1814
import org.jruby.runtime.builtin.IRubyObject;
1915
import org.jruby.runtime.callsite.CacheEntry;
20-
import org.jruby.runtime.encoding.EncodingService;
21-
import org.jruby.runtime.invokedynamic.JRubyCallSite;
2216
import org.jruby.util.JavaNameMangler;
2317
import org.objectweb.asm.Handle;
2418
import org.objectweb.asm.Opcodes;
@@ -29,13 +23,11 @@
2923
import java.lang.invoke.MethodHandles;
3024
import java.lang.invoke.MethodType;
3125
import java.lang.invoke.MutableCallSite;
32-
import java.lang.invoke.SwitchPoint;
33-
import java.util.Arrays;
3426

35-
import static org.jruby.runtime.invokedynamic.InvokeDynamicSupport.*;
36-
import static org.jruby.util.CodegenUtils.*;
3727
import static java.lang.invoke.MethodHandles.*;
38-
import static java.lang.invoke.MethodType.*;
28+
import static org.jruby.runtime.invokedynamic.InvokeDynamicSupport.*;
29+
import static org.jruby.util.CodegenUtils.p;
30+
import static org.jruby.util.CodegenUtils.sig;
3931

4032
public class Bootstrap {
4133
public static CallSite string(Lookup lookup, String name, MethodType type, String value, int encoding) {
@@ -47,6 +39,15 @@ public static CallSite string(Lookup lookup, String name, MethodType type, Strin
4739
return site;
4840
}
4941

42+
public static CallSite array(Lookup lookup, String name, MethodType type) {
43+
MethodHandle handle = Binder
44+
.from(type)
45+
.collect(1, IRubyObject[].class)
46+
.invokeStaticQuiet(MethodHandles.lookup(), Bootstrap.class, "array");
47+
CallSite site = new ConstantCallSite(handle);
48+
return site;
49+
}
50+
5051
private static class InvokeSite extends MutableCallSite {
5152
public InvokeSite(MethodType type, String name) {
5253
super(type);
@@ -117,6 +118,10 @@ public static Handle string() {
117118
return new Handle(Opcodes.H_INVOKESTATIC, p(Bootstrap.class), "string", sig(CallSite.class, Lookup.class, String.class, MethodType.class, String.class, int.class));
118119
}
119120

121+
public static Handle array() {
122+
return new Handle(Opcodes.H_INVOKESTATIC, p(Bootstrap.class), "array", sig(CallSite.class, Lookup.class, String.class, MethodType.class));
123+
}
124+
120125
public static Handle invoke() {
121126
return new Handle(Opcodes.H_INVOKESTATIC, p(Bootstrap.class), "invoke", sig(CallSite.class, Lookup.class, String.class, MethodType.class));
122127
}
@@ -138,6 +143,10 @@ public static IRubyObject string(String value, int encoding, ThreadContext conte
138143
return RubyString.newStringNoCopy(context.runtime, value.getBytes(RubyEncoding.ISO));
139144
}
140145

146+
public static IRubyObject array(ThreadContext context, IRubyObject[] elts) {
147+
return RubyArray.newArrayNoCopy(context.runtime, elts);
148+
}
149+
141150
public static IRubyObject invoke(InvokeSite site, ThreadContext context, IRubyObject self) throws Throwable {
142151
RubyClass selfClass = pollAndGetClass(context, self);
143152
String methodName = site.name;

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ public void returnValue() {
162162
adapter.areturn();
163163
}
164164

165+
public void array(int length) {
166+
adapter.invokedynamic("array", sig(JVM.OBJECT, params(ThreadContext.class, JVM.OBJECT, length)), Bootstrap.array());
167+
}
168+
165169
public int newLocal(String name, Type type) {
166170
int index = variableCount++;
167171
variableTypes.put(index, type);

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,8 @@ public void emit(Operand operand) {
189189
operand.compile(this);
190190
} else if (operand instanceof Variable) {
191191
emitVariable((Variable)operand);
192-
} else if (operand instanceof Symbol) {
193-
operand.compile(this);
194192
} else {
195-
throw new RuntimeException("unsupported operand in compiler: " + operand.getClass());
193+
operand.compile(this);
196194
}
197195
}
198196

0 commit comments

Comments
 (0)