org.jruby.compiler.ir.targets.JVM Maven / Gradle / Ivy
package org.jruby.compiler.ir.targets;
import com.kenai.constantine.Constant;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Stack;
import org.jruby.RubyInstanceConfig;
import org.jruby.RubyObject;
import org.jruby.compiler.ir.CompilerTarget;
import org.jruby.compiler.ir.IRClass;
import org.jruby.compiler.ir.IRMethod;
import org.jruby.compiler.ir.IRScope;
import org.jruby.compiler.ir.IRScript;
import org.jruby.compiler.ir.instructions.BEQInstr;
import org.jruby.compiler.ir.instructions.CallInstr;
import org.jruby.compiler.ir.instructions.CopyInstr;
import org.jruby.compiler.ir.instructions.DefineClassMethodInstr;
import org.jruby.compiler.ir.instructions.DefineInstanceMethodInstr;
import org.jruby.compiler.ir.instructions.GetFieldInstr;
import org.jruby.compiler.ir.instructions.Instr;
import org.jruby.compiler.ir.instructions.JumpInstr;
import org.jruby.compiler.ir.instructions.LABEL_Instr;
import org.jruby.compiler.ir.instructions.PutFieldInstr;
import org.jruby.compiler.ir.instructions.ReceiveArgumentInstruction;
import org.jruby.compiler.ir.instructions.ReturnInstr;
import org.jruby.compiler.ir.operands.FieldRef;
import org.jruby.compiler.ir.operands.Fixnum;
import org.jruby.compiler.ir.operands.Label;
import org.jruby.compiler.ir.operands.Operand;
import org.jruby.compiler.ir.operands.Variable;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Type;
import org.objectweb.asm.commons.GeneratorAdapter;
import org.objectweb.asm.commons.Method;
import org.objectweb.asm.util.TraceClassVisitor;
import static org.objectweb.asm.Opcodes.*;
import static org.jruby.util.CodegenUtils.*;
import static org.objectweb.asm.commons.GeneratorAdapter.*;
// This class represents JVM as the target of compilation
// and outputs bytecode
public class JVM implements CompilerTarget {
private static final boolean DEBUG = true;
Stack clsStack = new Stack();
List clsAccum = new ArrayList();
IRScript script;
private static class ClassData {
public ClassData(ClassVisitor cls) {
this.cls = cls;
}
public GeneratorAdapter method() {
return methodData().method;
}
public MethodData methodData() {
return methodStack.peek();
}
public void pushmethod(String name) {
methodStack.push(new MethodData(new GeneratorAdapter(
ACC_PUBLIC | ACC_STATIC,
Method.getMethod("org.jruby.runtime.builtin.IRubyObject " + name + " (org.jruby.runtime.ThreadContext, org.jruby.runtime.builtin.IRubyObject)"),
null,
null,
cls)));
}
public void popmethod() {
method().endMethod();
methodStack.pop();
}
public ClassVisitor cls;
Stack methodStack = new Stack();
public Set fieldSet = new HashSet();
}
private static class MethodData {
public MethodData(GeneratorAdapter method) {
this.method = method;
}
public GeneratorAdapter method;
public Map varMap = new HashMap();
public Map
© 2015 - 2025 Weber Informatics LLC | Privacy Policy