Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Last tag attempt!

git-svn-id: http://svn.codehaus.org/jruby/tags/jruby-1_1_4@7570 961051c9-f516-0410-bf72-c9f7e237a7b7
  • Loading branch information...
commit 543db206e561b770d892c191946ef55cda8a9dd9 2 parents 5744d3a + 24be9a6
Thomas E Enebo enebo authored
45 lib/ruby/site_ruby/1.8/compiler/builder.rb
View
@@ -110,10 +110,15 @@ def method?
class ClassBuilder
include Util
include TypeNamespace
+
+ begin
+ import "jruby.objectweb.asm.Opcodes"
+ import "jruby.objectweb.asm.ClassWriter"
+ rescue
+ import "org.objectweb.asm.Opcodes"
+ import "org.objectweb.asm.ClassWriter"
+ end
- import "jruby.objectweb.asm.Opcodes"
- import "jruby.objectweb.asm.ClassWriter"
- include Opcodes
import java.lang.Object
import java.lang.Void
include Signature
@@ -135,7 +140,7 @@ def initialize(file_builder, class_name, file_name, superclass = Object, *interf
interface_paths = []
interfaces.each {|interface| interface_paths << path(interface)}
- @class_writer.visit(V1_4, ACC_PUBLIC | ACC_SUPER, class_name, nil, path(superclass), interface_paths.to_java(:string))
+ @class_writer.visit(Opcodes::V1_4, Opcodes::ACC_PUBLIC | Opcodes::ACC_SUPER, class_name, nil, path(superclass), interface_paths.to_java(:string))
@class_writer.visit_source(file_name, nil)
@constructor = nil
@@ -158,7 +163,7 @@ def generate
if @constructor
@constructor.generate_constructor(@superclass)
else
- method = MethodBuilder.new(self, ACC_PUBLIC, "<init>", [])
+ method = MethodBuilder.new(self, Opcodes::ACC_PUBLIC, "<init>", [])
method.start
method.aload 0
method.invokespecial @superclass, "<init>", Void::TYPE
@@ -176,7 +181,7 @@ def generate
# generate fields
@fields.each do |name, field|
- @class_writer.visit_field(ACC_PROTECTED, field.name, class_id(field.type), nil, nil)
+ @class_writer.visit_field(Opcodes::ACC_PROTECTED, field.name, class_id(field.type), nil, nil)
end
String.from_java_bytes(@class_writer.to_byte_array)
@@ -218,20 +223,30 @@ def method(name, *signature, &block)
raise "Overloading not yet supported"
end
- mb = MethodBuilder.new(self, ACC_PUBLIC, name, signature)
+ mb = MethodBuilder.new(self, Opcodes::ACC_PUBLIC, name, signature)
deferred_builder = DeferredMethodBuilder.new(name, mb, signature, block)
if name == "<init>"
@constructor = deferred_builder
else
@instance_methods[name] = deferred_builder
end
+
+ mb
end
# New version does not instance_eval, to allow for easier embedding
def static_method(name, *signature, &block)
- mb = MethodBuilder.new(self, ACC_PUBLIC | ACC_STATIC, name, signature)
- deferred_builder = DeferredMethodBuilder.new(name, mb, signature, block)
- @static_methods[name] = deferred_builder
+ mb = MethodBuilder.new(self, Opcodes::ACC_PUBLIC | Opcodes::ACC_STATIC, name, signature)
+# deferred_builder = DeferredMethodBuilder.new(name, mb, signature, block)
+# @static_methods[name] = deferred_builder
+
+ if block
+ mb.start
+ block.yield(mb)
+ mb.stop
+ else
+ mb
+ end
end
# name for signature generation using the class being generated
@@ -318,8 +333,12 @@ def method?
end
class MethodBuilder
- import "jruby.objectweb.asm.Opcodes"
- include Opcodes
+ begin
+ import "jruby.objectweb.asm.Opcodes"
+ rescue
+ import "org.objectweb.asm.Opcodes"
+ end
+
include Compiler::Bytecode
attr_reader :method_visitor
@@ -335,7 +354,7 @@ def initialize(class_builder, modifiers, name, signature)
@locals = {}
- @static = (modifiers & ACC_STATIC) != 0
+ @static = (modifiers & Opcodes::ACC_STATIC) != 0
@locals['this'] = TypedVariable.new("this", @class_builder, 0) unless @static
end
21 lib/ruby/site_ruby/1.8/compiler/builder2.rb
View
@@ -3,9 +3,14 @@
module Compiler
class ClassBuilder
- import "jruby.objectweb.asm.Opcodes"
- import "jruby.objectweb.asm.ClassWriter"
- include Opcodes
+ begin
+ import "jruby.objectweb.asm.Opcodes"
+ import "jruby.objectweb.asm.ClassWriter"
+ rescue
+ import "org.objectweb.asm.Opcodes"
+ import "org.objectweb.asm.ClassWriter"
+ end
+
import java.lang.Object
import java.lang.Void
include Signature
@@ -18,7 +23,7 @@ def initialize(class_name, file_name, superclass, *interfaces)
interface_paths = []
interfaces.each {|interface| interface_paths << path(interface)}
- @class_writer.visit(V1_4, ACC_PUBLIC | ACC_SUPER, class_name, nil, path(superclass), interface_paths.to_java(:string))
+ @class_writer.visit(Opcodes::V1_4, Opcodes::ACC_PUBLIC | Opcodes::ACC_SUPER, class_name, nil, path(superclass), interface_paths.to_java(:string))
@class_writer.visit_source(file_name, nil)
end
@@ -33,21 +38,21 @@ def generate
end
def field(name, type)
- @class_writer.visitField(ACC_PUBLIC, name.to_s, ci(type), nil, nil)
+ @class_writer.visitField(Opcodes::ACC_PUBLIC, name.to_s, ci(type), nil, nil)
end
def constructor(*signature, &block)
signature.unshift Void::TYPE
- MethodBuilder.build(self, ACC_PUBLIC, "<init>", signature, &block)
+ MethodBuilder.build(self, Opcodes::ACC_PUBLIC, "<init>", signature, &block)
end
def method(name, *signature, &block)
- MethodBuilder.build(self, ACC_PUBLIC, name.to_s, signature, &block)
+ MethodBuilder.build(self, Opcodes::ACC_PUBLIC, name.to_s, signature, &block)
end
def static_method(name, *signature, &block)
- MethodBuilder.build(self, ACC_PUBLIC | ACC_STATIC, name.to_s, signature, &block)
+ MethodBuilder.build(self, Opcodes::ACC_PUBLIC | Opcodes::ACC_STATIC, name.to_s, signature, &block)
end
# name for signature generation using the class being generated
96 lib/ruby/site_ruby/1.8/compiler/bytecode.rb
View
@@ -5,9 +5,14 @@ module Compiler
# JVM assembly code. Included classes must just provide a method_visitor accessor
module Bytecode
include Signature
-
- import "jruby.objectweb.asm.Opcodes"
- import "jruby.objectweb.asm.Label"
+
+ begin
+ import "jruby.objectweb.asm.Opcodes"
+ import "jruby.objectweb.asm.Label"
+ rescue Exception
+ import "org.objectweb.asm.Opcodes"
+ import "org.objectweb.asm.Label"
+ end
import java.lang.Object
import java.lang.System
@@ -20,11 +25,11 @@ module Bytecode
case const_name
when "ALOAD", "ASTORE",
- "BISTORE", "BILOAD",
"ISTORE", "ILOAD",
"LSTORE", "LLOAD",
"FSTORE", "FLOAD",
- "DSTORE", "DLOAD"
+ "DSTORE", "DLOAD",
+ "RET"
# variable instructions
eval "
def #{const_down}(var)
@@ -44,6 +49,13 @@ def #{const_down}(value)
method_visitor.visit_ldc_insn(value)
end
", b, __FILE__, __LINE__
+
+ when "BIPUSH", "SIPUSH"
+ eval "
+ def #{const_down}(value)
+ method_visitor.visit_int_insn(Opcodes::#{const_name}, value)
+ end
+ "
when "INVOKESTATIC", "INVOKEVIRTUAL", "INVOKEINTERFACE", "INVOKESPECIAL"
# method instructions
@@ -62,16 +74,20 @@ def returnvoid()
when "DUP", "SWAP", "POP", "POP2", "DUP_X1", "DUP_X2", "DUP2", "DUP2_X1", "DUP2_X2",
"NOP",
"ARRAYLENGTH",
- "ARETURN", "ATHROW", "ACONST_NULL", "AALOAD",
+ "ARETURN", "ATHROW", "ACONST_NULL", "AALOAD", "AASTORE",
"BALOAD", "BASTORE",
- "ICONST_0", "ICONST_1", "ICONST_2", "ICONST_3", "IRETURN", "IALOAD",
- "IADD", "IINC", "ISUB", "IDIV", "IMUL", "INEG", "IAND", "IOR", "IXOR",
- "LCONST_0", "LCONST_1", "LRETURN", "LALOAD",
- "LADD", "LINC", "LSUB", "LDIV", "LMUL", "LNEG", "LAND", "LOR", "LXOR",
- "FCONST_0", "FCONST_1", "FCONST_2", "FRETURN", "FALOAD",
- "FADD", "FINC", "FSUB", "FDIV", "FMUL", "FNEG",
- "DCONST_0", "DCONST_1", "DRETURN", "DALOAD",
- "DADD", "DINC", "DSUB", "DDIV", "DMUL", "DNEG"
+ "CALOAD", "CASTORE",
+ "SALOAD", "SASTORE",
+ "ICONST_M1", "ICONST_0", "ICONST_1", "ICONST_2", "ICONST_3", "ICONST_4", "ICONST_5", "IRETURN", "IALOAD",
+ "IADD", "IINC", "ISUB", "IDIV", "IMUL", "INEG", "IAND", "IOR", "IXOR", "IASTORE",
+ "IUSHR", "ISHL", "ISHR", "I2L", "I2S", "I2F", "I2D", "I2B", "IREM", "I2C",
+ "LCONST_0", "LCONST_1", "LRETURN", "LALOAD", "LASTORE", "LCMP", "LSHL", "LSHR", "LREM", "LUSHR",
+ "LADD", "LINC", "LSUB", "LDIV", "LMUL", "LNEG", "LAND", "LOR", "LXOR", "L2I", "L2F", "L2D",
+ "FCONST_0", "FCONST_1", "FCONST_2", "FRETURN", "FALOAD", "F2D", "F2I", "FASTORE",
+ "FADD", "FSUB", "FDIV", "FMUL", "FNEG", "FREM", "FCMPG", "F2L", "FCMPL",
+ "DCONST_0", "DCONST_1", "DRETURN", "DALOAD", "DASTORE", "D2I", "D2F", "D2L",
+ "DADD", "DINC", "DSUB", "DDIV", "DMUL", "DNEG", "DCMPL", "DCMPG", "DREM",
+ "MONITORENTER", "MONITOREXIT"
# bare instructions
eval "
def #{const_down}
@@ -96,7 +112,8 @@ def #{const_down}(type, name, field_sig)
", b, __FILE__, __LINE__
when "GOTO", "IFEQ", "IFNE", "IF_ACMPEQ", "IF_ACMPNE", "IF_ICMPEQ", "IF_ICMPNE", "IF_ICMPLT",
- "IF_ICMPGT", "IF_ICMPLE", "IF_ICMPGE", "IFNULL", "IFNONNULL"
+ "IF_ICMPGT", "IF_ICMPLE", "IF_ICMPGE", "IFNULL", "IFNONNULL", "JSR",
+ "IFLE", "IFGE", "IFLT", "IFGT"
# jump instructions
eval "
def #{const_down}(target)
@@ -104,6 +121,14 @@ def #{const_down}(target)
end
", b, __FILE__, __LINE__
+ when "MULTIANEWARRAY"
+ # multi-dim array
+ eval "
+ def #{const_down}(type, dims)
+ method_visitor.visit_multi_anew_array_insn(ci(type), dims)
+ end
+ ", b, __FILE__, __LINE__
+
when "LOOKUPSWITCH"
def lookupswitch(default, ints, cases)
method_visitor.visit_lookup_switch_insn(default, ints, cases)
@@ -113,6 +138,20 @@ def lookupswitch(default, ints, cases)
def tableswitch(min, max, default, cases)
method_visitor.visit_table_switch_insn(min, max, default, cases)
end
+
+ when "F_FULL", "ACC_ENUM", "ACC_SYNTHETIC", "ACC_INTERFACE", "ACC_PUBLIC",
+ "ACC_PRIVATE", "ACC_PROTECTED", "ACC_DEPRECATED", "ACC_BRIDGE",
+ "ACC_VARARGS", "ACC_SUPER", "F_CHOP", "F_APPEND", "FLOAT", "F_SAME",
+ "T_LONG", "INTEGER", "T_BYTE", "ACC_STATIC", "ACC_SYNCHRONIZED",
+ "T_BOOLEAN", "ACC_ANNOTATION", "ACC_ABSTRACT", "LONG", "ACC_TRANSIENT",
+ "T_DOUBLE", "DOUBLE", "ACC_STRICT", "NULL", "T_FLOAT", "ACC_FINAL",
+ "F_SAME1", "ACC_NATIVE", "F_NEW", "T_CHAR", "T_INT", "ACC_VOLATILE",
+ "V1_6", "V1_5", "V1_4", "V1_3", "V1_2", "V1_1", "UNINITIALIZED_THIS",
+ "TOP", "T_SHORT"
+ # non-instructions
+
+ else
+ raise "Unknown opcode: " + const_name
end
end
@@ -162,5 +201,32 @@ def swap2
def line(num)
method_visitor.visit_line_number num, Label.new
end
+
+ def push_int(num)
+ if (num <= Java::java.lang.Byte::MAX_VALUE && num >= Java::java.lang.Byte::MIN_VALUE)
+ case num
+ when -1
+ iconst_m1
+ when 0
+ iconst_0
+ when 1
+ iconst_1
+ when 2
+ iconst_2
+ when 3
+ iconst_3
+ when 4
+ iconst_4
+ when 5
+ iconst_5
+ else
+ bipush(num)
+ end
+ elsif (num <= Java::java.lang.Short::MAX_VALUE && num >= Java::java.lang.Short::MIN_VALUE)
+ sipush(num)
+ else
+ ldc(num)
+ end
+ end
end
end
48 lib/ruby/site_ruby/1.8/duby/c_compiler.rb
View
@@ -5,12 +5,12 @@ module Duby
module Compiler
class C
class MathCompiler
- def call(compiler, name, recv, args)
- recv.compile(compiler)
+ def call(compiler, call)
+ call.target.compile(compiler)
- compiler.src << " #{name} "
+ compiler.src << " #{call.name} "
- args.each {|arg| arg.compile(compiler)}
+ call.parameters.each {|param| param.compile(compiler)}
end
end
@@ -28,58 +28,70 @@ def initialize(filename)
def compile(ast)
ast.compile(self)
end
+
+ def define_main(body)
+ old_src, @src = @src, "int main(int argc, char **argv)\n{\n"
+
+ body.compile(self)
+
+ @src << "}\n\n"
+
+ @src = old_src + @src
+ end
def define_method(name, signature, args, body)
- @src << "#{type_mapper[signature[:return]]} #{name}("
+ old_src, @src = @src, "#{type_mapper[signature[:return]]} #{name}("
args.compile(self)
- @src << ") {"
+ @src << ")\n{\n"
body.compile(self)
- @src << "}\n\n"
+ @src << "\n}\n\n"
+
+ @src = old_src + @src
end
def declare_argument(name, type)
@src << "#{type_mapper[type]} #{name}"
end
- def branch(condition, body, els)
+ def branch(iff)
@src << "if ("
- condition.compile(self)
+ iff.condition.compile(self)
@src << ") {"
- body.compile(self)
+ iff.body.compile(self)
- if els
+ if iff.else
@src << "} else {"
- els.compile(self)
+ iff.else.compile(self)
end
@src << "}"
end
- def call(name, recv, args)
- call_compilers[recv.inferred_type].call(self, name, recv, args)
+ def call(call)
+ call_compilers[call.target.inferred_type].call(self, call)
end
def call_compilers
@call_compilers ||= {}
end
- def self_call(name, args)
- @src << "#{name}("
+ def self_call(fcall)
+ @src << "#{fcall.name}("
- args.each {|arg| arg.compile(self)}
+ fcall.parameters.each {|param| param.compile(self)}
@src << ")"
end
- def local(name)
+ def local(name, type)
@src << name
end
12 lib/ruby/site_ruby/1.8/duby/compiler.rb
View
@@ -34,13 +34,13 @@ def compile(compiler)
class Local
def compile(compiler)
- compiler.local(name)
+ compiler.local(name, inferred_type)
end
end
class LocalAssignment
def compile(compiler)
- compiler.local_assign(name) {
+ compiler.local_assign(name, inferred_type) {
value.compile(compiler)
}
end
@@ -48,7 +48,7 @@ def compile(compiler)
class Script
def compile(compiler)
- body.compile(compiler)
+ compiler.define_main(body)
end
end
@@ -72,7 +72,7 @@ def compile(compiler)
class If
def compile(compiler)
- compiler.branch(condition, body, self.else)
+ compiler.branch(self)
end
end
@@ -84,13 +84,13 @@ def compile(compiler)
class FunctionalCall
def compile(compiler)
- compiler.self_call(name, parameters)
+ compiler.self_call(self)
end
end
class Call
def compile(compiler)
- compiler.call(name, target, parameters)
+ compiler.call(self)
end
end
end
257 lib/ruby/site_ruby/1.8/duby/jvm_compiler.rb
View
@@ -1,103 +1,172 @@
require 'duby'
+require 'compiler/builder'
module Duby
module Compiler
- class C
+ class JVM
class MathCompiler
- def call(compiler, name, recv, args)
- recv.call
-
- compiler.src << " #{name} "
+ def call(compiler, call)
+ call.target.compile(compiler)
+ call.parameters.each {|param| param.compile(compiler)}
- args.call
+ target_type = call.target.inferred_type
+ case target_type
+ when AST.type(:fixnum)
+ case call.name
+ when '-'
+ compiler.method.isub
+ when '+'
+ compiler.method.iadd
+ else
+ compiler.method.invokevirtual(
+ compiler.type_mapper[call.target.inferred_type],
+ call.name,
+ [compiler.type_mapper[call.inferred_type], *call.parameters.map {|param| compiler.type_mapper[param.inferred_type]}])
+ end
+ else
+ compiler.method.invokevirtual(
+ compiler.type_mapper[call.target.inferred_type],
+ call.name,
+ [compiler.type_mapper[call.inferred_type], *call.parameters.map {|param| compiler.type_mapper[param.inferred_type]}])
+ end
end
end
- attr_accessor :filename, :src
+ attr_accessor :filename, :src, :method
def initialize(filename)
@filename = filename
@src = ""
- self.type_mapper[AST::TypeReference.new(:fixnum)] = "int"
+ self.type_mapper[AST.type(:fixnum)] = Java::int
+ self.type_mapper[AST.type(:string, true)] = Java::java.lang.String[]
- self.call_compilers[AST::TypeReference.new(:fixnum)] = MathCompiler.new
+ self.call_compilers[AST.type(:fixnum)] = MathCompiler.new
+
+ @file = ::Compiler::FileBuilder.new(filename)
+ @class = @file.public_class(filename.split('.')[0])
end
def compile(ast)
ast.compile(this)
end
+
+ def define_main(body)
+ oldmethod, @method = @method, @class.static_method("main", type_mapper[AST.type(:void)], type_mapper[AST.type(:string, true)])
+
+ @method.start
+
+ body.compile(self)
+
+ @method.returnvoid
+ @method.stop
+
+ @method = oldmethod
+ end
def define_method(name, signature, args, body)
- @src << "#{type_mapper[signature[:return]]} #{name}("
-
- args.call
+ oldmethod, @method = @method, @class.static_method(name.to_s, type_mapper[signature[:return]], *args.args.map {|arg| type_mapper[arg.inferred_type]})
+
+ @method.start
- @src << ") {"
+ #args.call
- body.call
+ body.compile(self)
+
+ case signature[:return]
+ when AST.type(:fixnum)
+ @method.ireturn
+ else
+ @method.aload 0
+ @method.areturn
+ end
- @src << "}\n\n"
+ @method.stop
+
+ @method = oldmethod
end
def declare_argument(name, type)
- @src << "#{type_mapper[type]} #{name}"
+ # declare local vars for arguments here
end
- def branch(condition, body_proc, else_proc)
- @src << "if ("
-
- condition.call
+ def branch(iff)
+ elselabel = @method.label
+ donelabel = @method.label
- @src << ") {"
-
- body_proc.call
-
- if else_proc
- @src << "} else {"
-
- else_proc.call
+ # this is ugly...need a better way to abstract the idea of compiling a
+ # conditional branch while still fitting into JVM opcodes
+ predicate = iff.condition.predicate
+ case iff.condition.predicate
+ when AST::Call
+ case predicate.target.inferred_type
+ when AST.type(:fixnum)
+ # fixnum conditional, so we need to use JVM opcodes
+ case predicate.parameters[0].inferred_type
+ when AST.type(:fixnum)
+ # fixnum on fixnum, easy
+ case predicate.name
+ when '<'
+ predicate.target.compile(self)
+ predicate.parameters[0].compile(self)
+ @method.if_icmpge(elselabel)
+ else
+ raise "Unknown :fixnum on :fixnum predicate operation: " + predicate.name
+ end
+ else
+ raise "Unknown :fixnum on " + predicate.parameters[0].inferred_type + " predicate operations: " + predicate.name
+ end
+ else
+ raise "Unknown " + predicate.target.inferred_type + " on " + predicate.parameters[0].inferred_type + " predicate operations: " + predicate.name
+ end
end
-
- @src << "}"
+
+ iff.body.compile(self)
+
+ @method.goto(donelabel)
+
+ elselabel.set!
+
+ iff.else.compile(self) if iff.else
+
+ donelabel.set!
end
- def call(name, recv_type, recv, args)
- call_compilers[recv_type].call(self, name, recv, args)
+ def call(call)
+ call_compilers[call.target.inferred_type].call(self, call)
end
def call_compilers
@call_compilers ||= {}
end
- def self_call(name, args)
- @src << "#{name}("
-
- args.call
-
- @src << ")"
+ def self_call(fcall)
+ fcall.parameters.each {|param| param.compile(self)}
+ @method.invokestatic(
+ @method.this,
+ fcall.name,
+ [type_mapper[fcall.inferred_type], *fcall.parameters.map {|param| type_mapper[param.inferred_type]}])
end
- def local(name)
- @src << name
+ def local(name, type)
+ case type
+ when AST.type(:fixnum)
+ @method.iload(@method.local(name))
+ else
+ @method.aload(@method.local(name))
+ end
end
def fixnum(value)
- @src << value.to_s
+ @method.push_int(value)
end
def newline
- @src << ";\n"
- end
-
- def ret
- @src << "return "
-
- yield
+ # TODO: line numbering
end
def generate
- @src
+ @file.generate{|filename, builder| File.open(filename, 'w') {|f| f.write(builder.generate)}}
end
def type_mapper
@@ -105,90 +174,6 @@ def type_mapper
end
end
end
-
- module AST
- class Script
- def compile(compiler)
- # preparations for the .c file would go here
- body.compile(compiler)
- end
- end
-
- class Body
- def compile(compiler)
- last = children[-1]
- children.each do |child|
- child.compile(compiler)
- compiler.newline
- end
- end
- end
-
- class MethodDefinition
- def compile(compiler)
- args_callback = proc {arguments.compile(compiler)}
- body_callback = proc {body.compile(compiler)}
- compiler.define_method(name, signature, args_callback, body_callback)
- end
- end
-
- class Arguments
- def compile(compiler)
- args.each {|arg| compiler.declare_argument(arg.name, arg.inferred_type)} if args
- end
- end
-
- class Noop
- def compile(compiler)
- # nothing
- end
- end
-
- class Fixnum
- def compile(compiler)
- compiler.fixnum(literal)
- end
- end
-
- class If
- def compile(compiler)
- cond_callback = proc { condition.compile(compiler) }
- body_callback = proc { body.compile(compiler) }
- else_callback = proc { self.else.compile(compiler)}
-
- compiler.branch(cond_callback, body_callback, else_callback)
- end
- end
-
- class Condition
- def compile(compiler)
- predicate.compile(compiler)
- end
- end
-
- class FunctionalCall
- def compile(compiler)
- args_callback = proc { parameters.each {|param| param.compile(compiler)}}
-
- compiler.self_call(name, args_callback)
- end
- end
-
- class Call
- def compile(compiler)
- recv_callback = proc { target.compile(compiler) }
- args_callback = proc { parameters.each {|param| param.compile(compiler)}}
-
- compiler.call(name, target.inferred_type, recv_callback, args_callback)
- end
- end
-
- class Local
- def compile(compiler)
- compiler.local(name)
- end
- end
- end
end
if __FILE__ == $0
@@ -198,10 +183,10 @@ def compile(compiler)
ast.infer(typer)
typer.resolve(true)
- compiler = Duby::Compiler::JVM.new("#{ARGV[0].split('.')[0]}.class")
+ compiler = Duby::Compiler::JVM.new(ARGV[0])
ast.compile(compiler)
- File.open(compiler.filename, "w") {|file| file.write(compiler.generate)}
+ compiler.generate
end
__END__
require 'duby'
@@ -250,7 +235,7 @@ def initialize(filename)
@filename = filename
@file_builder = FileBuilder.new(filename)
- fixnum_type = AST::TypeReference.new(:fixnum)
+ fixnum_type = AST.type(:fixnum)
self.type_mapper[fixnum_type] = Java::int.java_class
102 maven/jruby-complete/pom.xml
View
@@ -90,91 +90,8 @@
</dependencies>
<build>
- <sourceDirectory>${project.basedir}/../../src</sourceDirectory>
- <testSourceDirectory>${project.basedir}/../../test</testSourceDirectory>
<plugins>
<plugin>
- <artifactId>maven-dependency-plugin</artifactId>
- <executions>
- <execution>
- <phase>generate-resources</phase>
- <goals>
- <goal>unpack</goal>
- </goals>
- <configuration>
- <artifactItems>
- <artifactItem>
- <groupId>asm</groupId>
- <artifactId>asm</artifactId>
- <version>3.0</version>
- </artifactItem>
- <artifactItem>
- <groupId>asm</groupId>
- <artifactId>asm-commons</artifactId>
- <version>3.0</version>
- </artifactItem>
- <artifactItem>
- <groupId>asm</groupId>
- <artifactId>asm-util</artifactId>
- <version>3.0</version>
- </artifactItem>
- <artifactItem>
- <groupId>asm</groupId>
- <artifactId>asm-analysis</artifactId>
- <version>3.0</version>
- </artifactItem>
- <artifactItem>
- <groupId>asm</groupId>
- <artifactId>asm-tree</artifactId>
- <version>3.0</version>
- </artifactItem>
- <artifactItem>
- <groupId>biz.aQute</groupId>
- <artifactId>bndlib</artifactId>
- <version>0.0.249</version>
- </artifactItem>
- <artifactItem>
- <groupId>jline</groupId>
- <artifactId>jline</artifactId>
- <version>0.9.93</version>
- </artifactItem>
- <artifactItem>
- <groupId>org.jruby.joni</groupId>
- <artifactId>joni</artifactId>
- <version>1.0.3</version>
- </artifactItem>
- <artifactItem>
- <groupId>joda-time</groupId>
- <artifactId>joda-time</artifactId>
- <version>1.5.1</version>
- </artifactItem>
- <artifactItem>
- <groupId>org.jruby.extras</groupId>
- <artifactId>jna</artifactId>
- <version>3.0.2</version>
- </artifactItem>
- <artifactItem>
- <groupId>org.jruby.ext.posix</groupId>
- <artifactId>jna-posix</artifactId>
- <version>0.7</version>
- </artifactItem>
- <artifactItem>
- <groupId>org.jruby.extras</groupId>
- <artifactId>jvyamlb</artifactId>
- <version>0.2.3</version>
- </artifactItem>
- <artifactItem>
- <groupId>org.jruby.extras</groupId>
- <artifactId>bytelist</artifactId>
- <version>0.1</version>
- </artifactItem>
- </artifactItems>
- <outputDirectory>${project.build.outputDirectory}</outputDirectory>
- </configuration>
- </execution>
- </executions>
- </plugin>
- <plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
@@ -196,30 +113,17 @@
<executions>
<execution>
<id>copy-jar</id>
- <phase>process-classes</phase>
+ <phase>package</phase>
<goals><goal>run</goal></goals>
<configuration>
<tasks>
-<echo message="whoo"/>
- <copy file="${project.basedir}/../../lib/jruby-complete.jar" tofile="${project.build.directory}/${project.build.finalName}.jar"/>
+ <echo>copy ${project.basedir}/../../lib/jruby-complete.jar to ${project.build.directory}/${project.build.finalName}.jar</echo>
+ <copy overwrite="true" file="${project.basedir}/../../lib/jruby-complete.jar" tofile="${project.build.directory}/${project.build.finalName}.jar"/>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
- <plugin>
- <artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <includes>
- <!-- <include>org/jruby/test/MainTestSuite.java</include> -->
- <!-- <include>org/jruby/test/ScriptTestSuite.java</include> -->
- <!-- <include>org/jruby/test/TestUnitTestSuite.java</include> -->
- </includes>
- <excludes>
- <exclude>**/*.java</exclude>
- </excludes>
- </configuration>
- </plugin>
</plugins>
</build>
</project>
103 maven/jruby/pom.xml
View
@@ -90,91 +90,8 @@
</dependencies>
<build>
- <sourceDirectory>${basedir}/../../src</sourceDirectory>
- <testSourceDirectory>${basedir}/../../test</testSourceDirectory>
<plugins>
<plugin>
- <artifactId>maven-dependency-plugin</artifactId>
- <executions>
- <execution>
- <phase>generate-resources</phase>
- <goals>
- <goal>unpack</goal>
- </goals>
- <configuration>
- <artifactItems>
- <artifactItem>
- <groupId>asm</groupId>
- <artifactId>asm</artifactId>
- <version>3.0</version>
- </artifactItem>
- <artifactItem>
- <groupId>asm</groupId>
- <artifactId>asm-commons</artifactId>
- <version>3.0</version>
- </artifactItem>
- <artifactItem>
- <groupId>asm</groupId>
- <artifactId>asm-util</artifactId>
- <version>3.0</version>
- </artifactItem>
- <artifactItem>
- <groupId>asm</groupId>
- <artifactId>asm-analysis</artifactId>
- <version>3.0</version>
- </artifactItem>
- <artifactItem>
- <groupId>asm</groupId>
- <artifactId>asm-tree</artifactId>
- <version>3.0</version>
- </artifactItem>
- <artifactItem>
- <groupId>biz.aQute</groupId>
- <artifactId>bndlib</artifactId>
- <version>0.0.249</version>
- </artifactItem>
- <artifactItem>
- <groupId>jline</groupId>
- <artifactId>jline</artifactId>
- <version>0.9.93</version>
- </artifactItem>
- <artifactItem>
- <groupId>org.jruby.joni</groupId>
- <artifactId>joni</artifactId>
- <version>1.0.3</version>
- </artifactItem>
- <artifactItem>
- <groupId>joda-time</groupId>
- <artifactId>joda-time</artifactId>
- <version>1.5.1</version>
- </artifactItem>
- <artifactItem>
- <groupId>org.jruby.extras</groupId>
- <artifactId>jna</artifactId>
- <version>3.0.2</version>
- </artifactItem>
- <artifactItem>
- <groupId>org.jruby.ext.posix</groupId>
- <artifactId>jna-posix</artifactId>
- <version>0.7</version>
- </artifactItem>
- <artifactItem>
- <groupId>org.jruby.extras</groupId>
- <artifactId>jvyamlb</artifactId>
- <version>0.2.3</version>
- </artifactItem>
- <artifactItem>
- <groupId>org.jruby.extras</groupId>
- <artifactId>bytelist</artifactId>
- <version>0.1</version>
- </artifactItem>
- </artifactItems>
- <outputDirectory>${project.build.outputDirectory}</outputDirectory>
- </configuration>
- </execution>
- </executions>
- </plugin>
- <plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
@@ -196,31 +113,17 @@
<executions>
<execution>
<id>copy-jar</id>
- <phase>process-classes</phase>
+ <phase>package</phase>
<goals><goal>run</goal></goals>
<configuration>
<tasks>
-<echo message="whoo"/>
- <copy file="${project.basedir}/../../lib/jruby.jar" tofile="${project.build.directory}/${project.build.finalName}.jar"/>
+ <echo>copy ${project.basedir}/../../lib/jruby.jar to ${project.build.directory}/${project.build.finalName}.jar</echo>
+ <copy overwrite="true" file="${project.basedir}/../../lib/jruby.jar" tofile="${project.build.directory}/${project.build.finalName}.jar"/>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <includes>
- <!-- <include>org/jruby/test/MainTestSuite.java</include> -->
- <!-- <include>org/jruby/test/ScriptTestSuite.java</include> -->
- <!-- <include>org/jruby/test/TestUnitTestSuite.java</include> -->
- </includes>
- <excludes>
- <exclude>**/*.java</exclude>
- </excludes>
- </configuration>
- </plugin>
</plugins>
</build>
</project>
136 pom.xml
View
@@ -126,141 +126,5 @@
<artifactId>wagon-webdav</artifactId>
</extension>
</extensions>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- <configuration>
- <archive>
- <manifest>
- <mainClass>${jruby.main.class}</mainClass>
- <packageName>${jruby.package}</packageName>
- </manifest>
- </archive>
- </configuration>
- </plugin>
- </plugins>
</build>
- <profiles>
- <profile>
- <id>jruby</id>
- <activation>
- <activeByDefault>true</activeByDefault>
- </activation>
- <build>
- <resources>
- <resource>
- <directory>${project.basedir}/../../src</directory>
- <includes>
- <include>**/*.rb</include>
- </includes>
- </resource>
- <resource>
- <directory>${project.basedir}/../../lib/ruby/site_ruby/1.8</directory>
- <includes>
- <include>builtin/**/*.rb</include>
- </includes>
- </resource>
- </resources>
- <testResources>
- <testResource>
- <directory>${project.basedir}/../..</directory>
- <includes>
- <include>build.xml</include>
- <include>test/**/*.rb</include>
- <include>test/**/*.txt</include>
- <include>test/*index</include>
- <include>test/**/*.yml</include>
- <include>test/**/*.jar</include>
- <include>test/**/*.properties</include>
- </includes>
- </testResource>
- <testResource>
- <directory>${project.basedir}/../../test</directory>
- <includes>
- <include>org/jruby/**/*.rb</include>
- </includes>
- </testResource>
- </testResources>
- <plugins>
- <plugin>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <source>${javac.version}</source>
- <target>${javac.version}</target>
- </configuration>
- </plugin>
- <plugin>
- <artifactId>maven-antrun-plugin</artifactId>
- <executions>
- <execution>
- <id>filter-jruby-properties</id>
- <phase>process-resources</phase>
- <goals>
- <goal>run</goal>
- </goals>
- <configuration>
- <tasks>
- <tstamp><format property="build.date" pattern="yyyy-MM-dd"/></tstamp>
- <copy todir="${project.build.outputDirectory}" overwrite="true" failonerror="false">
- <fileset dir="${project.build.sourceDirectory}">
- <include name="**/*.properties"/>
- </fileset>
- <filterset>
- <filter token="os.arch" value="${os.arch}"/>
- <filter token="java.specification.version" value="${java.specification.version}"/>
- <filter token="javac.version" value="${javac.version}"/>
- <filter token="build.date" value="${build.date}"/>
- </filterset>
- </copy>
- </tasks>
- </configuration>
- </execution>
- </executions>
- <dependencies>
- <dependency>
- <groupId>ant</groupId>
- <artifactId>ant-junit</artifactId>
- <version>1.6.5</version>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>3.8.1</version>
- </dependency>
- </dependencies>
- </plugin>
- </plugins>
- </build>
- <properties>
- <jruby.package>org.jruby</jruby.package>
- <jruby.main.class>org.jruby.Main</jruby.main.class>
- <javac.version>${java.specification.version}</javac.version>
- <jruby.launch.memory>384m</jruby.launch.memory>
- </properties>
- </profile>
- <profile>
- <id>jruby-release</id>
- <activation>
- <property>
- <name>release</name>
- <value>true</value>
- </property>
- </activation>
- <properties>
- <javac.version>1.5</javac.version>
- </properties>
- <build>
- <plugins>
- <plugin>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <source>1.5</source>
- <target>1.5</target>
- </configuration>
- </plugin>
- </plugins>
- </build>
- </profile>
- </profiles>
</project>
4 test/compiler/duby/test_compilation.rb
View
@@ -63,7 +63,7 @@ def test_local
new_ast.compile(@compiler)
- assert_equal([[:local_assign, nil, "a"], [:fixnum, 1], [:local, nil, "a"]], @compiler.calls)
+ assert_equal([[:local_assign, "a", nil], [:fixnum, 1], [:local, "a", nil]], @compiler.calls)
end
def test_local_typed
@@ -72,7 +72,7 @@ def test_local_typed
new_ast.infer(typer)
new_ast.compile(@compiler)
- assert_equal([[:local_assign, AST.type(:fixnum), "a"], [:fixnum, 1], [:local, AST.type(:fixnum), "a"]], @compiler.calls)
+ assert_equal([[:local_assign, "a", AST.type(:fixnum)], [:fixnum, 1], [:local, "a", AST.type(:fixnum)]], @compiler.calls)
end
=begin
def test_args
4 test/compiler/test_builder.rb
View
@@ -1,5 +1,5 @@
require 'test/unit'
-require 'compiler/builder'
+require 'compiler/builder2'
require 'compiler/signature'
class TestBuilder < Test::Unit::TestCase
@@ -66,6 +66,6 @@ def test_class_builder
end
end
- File.open("MyClass.class", "w") {|file| file.write(class_bytes)}
+ assert class_bytes
end
end
180 test/compiler/test_bytecode.rb
View
@@ -3,8 +3,13 @@
class TestBytecode < Test::Unit::TestCase
include Compiler::Bytecode
+
+ begin
+ import "jruby.objectweb.asm.Opcodes"
+ rescue
+ import "org.objectweb.asm.Opcodes"
+ end
- import "jruby.objectweb.asm.Opcodes"
import java.lang.System
import java.lang.Integer
import java.lang.Void
@@ -35,14 +40,45 @@ def method_visitor
def test_var_insns
assert_equal([:visit_var_insn, Opcodes::ALOAD, :a], (aload :a))
assert_equal([:visit_var_insn, Opcodes::ILOAD, :a], (iload :a))
+ assert_equal([:visit_var_insn, Opcodes::LLOAD, :a], (lload :a))
+ assert_equal([:visit_var_insn, Opcodes::FLOAD, :a], (fload :a))
+ assert_equal([:visit_var_insn, Opcodes::DLOAD, :a], (dload :a))
assert_equal([:visit_var_insn, Opcodes::ASTORE, :a], (astore :a))
assert_equal([:visit_var_insn, Opcodes::ISTORE, :a], (istore :a))
+ assert_equal([:visit_var_insn, Opcodes::LSTORE, :a], (lstore :a))
+ assert_equal([:visit_var_insn, Opcodes::FSTORE, :a], (fstore :a))
+ assert_equal([:visit_var_insn, Opcodes::DSTORE, :a], (dstore :a))
+
+ assert_equal([:visit_var_insn, Opcodes::RET, :a], (ret :a))
end
def test_ldc
assert_equal([:visit_ldc_insn, "a"], (ldc :a))
assert_equal([:visit_ldc_insn, "a"], (ldc "a"))
assert_equal([:visit_ldc_insn, java.lang.Integer.new(1)], (ldc_int 1))
+ assert_equal([:visit_ldc_insn, java.lang.Long.new(1)], (ldc_long 1))
+ assert_equal([:visit_ldc_insn, java.lang.Float.new(1)], (ldc_float 1))
+ assert_equal([:visit_ldc_insn, java.lang.Double.new(1)], (ldc_double 1))
+ end
+
+ def test_int_insns
+ assert_equal([:visit_int_insn, Opcodes::BIPUSH, 1], (bipush 1))
+ assert_equal([:visit_int_insn, Opcodes::SIPUSH, 1], (sipush 1))
+
+ assert_equal([:visit_int_insn, Opcodes::BIPUSH, -2], (push_int(-2)))
+ assert_equal([:visit_insn, Opcodes::ICONST_M1], (push_int(-1)))
+ assert_equal([:visit_insn, Opcodes::ICONST_0], (push_int(0)))
+ assert_equal([:visit_insn, Opcodes::ICONST_1], (push_int(1)))
+ assert_equal([:visit_insn, Opcodes::ICONST_2], (push_int(2)))
+ assert_equal([:visit_insn, Opcodes::ICONST_3], (push_int(3)))
+ assert_equal([:visit_insn, Opcodes::ICONST_4], (push_int(4)))
+ assert_equal([:visit_insn, Opcodes::ICONST_5], (push_int(5)))
+ assert_equal([:visit_int_insn, Opcodes::BIPUSH, 6], (push_int(6)))
+
+ assert_equal([:visit_int_insn, Opcodes::SIPUSH, -129], (push_int(-129)))
+ assert_equal([:visit_int_insn, Opcodes::SIPUSH, 128], (push_int(128)))
+ assert_equal([:visit_ldc_insn, -65537], (push_int(-65537)))
+ assert_equal([:visit_ldc_insn, 65536], (push_int(65536)))
end
def test_method_insns
@@ -67,35 +103,138 @@ def test_return
assert_equal([:visit_insn, Opcodes::RETURN], (returnvoid))
end
- def test_bare_insns
- assert_equal([:visit_insn, Opcodes::IRETURN], (ireturn))
- assert_equal([:visit_insn, Opcodes::ARETURN], (areturn))
+ def test_nop
+ assert_equal([:visit_insn, Opcodes::NOP], (nop))
+ end
+
+ def test_stack_insns
assert_equal([:visit_insn, Opcodes::DUP], (dup))
assert_equal([:visit_insn, Opcodes::SWAP], (swap))
assert_equal([:visit_insn, Opcodes::POP], (pop))
assert_equal([:visit_insn, Opcodes::POP2], (pop2))
- assert_equal([:visit_insn, Opcodes::ICONST_0], (iconst_0))
- assert_equal([:visit_insn, Opcodes::ICONST_1], (iconst_1))
- assert_equal([:visit_insn, Opcodes::ICONST_2], (iconst_2))
- assert_equal([:visit_insn, Opcodes::ICONST_3], (iconst_3))
- assert_equal([:visit_insn, Opcodes::LCONST_0], (lconst_0))
- assert_equal([:visit_insn, Opcodes::ISUB], (isub))
- assert_equal([:visit_insn, Opcodes::ACONST_NULL], (aconst_null))
assert_equal([:visit_insn, Opcodes::NOP], (nop))
- assert_equal([:visit_insn, Opcodes::AALOAD], (aaload))
- assert_equal([:visit_insn, Opcodes::IALOAD], (iaload))
- assert_equal([:visit_insn, Opcodes::BALOAD], (baload))
- assert_equal([:visit_insn, Opcodes::BASTORE], (bastore))
assert_equal([:visit_insn, Opcodes::DUP_X1], (dup_x1))
assert_equal([:visit_insn, Opcodes::DUP_X2], (dup_x2))
assert_equal([:visit_insn, Opcodes::DUP2], (dup2))
assert_equal([:visit_insn, Opcodes::DUP2_X1], (dup2_x1))
assert_equal([:visit_insn, Opcodes::DUP2_X2], (dup2_x2))
- assert_equal([:visit_insn, Opcodes::ATHROW], (athrow))
+ end
+
+ def test_arraylength
assert_equal([:visit_insn, Opcodes::ARRAYLENGTH], (arraylength))
+ end
+
+ def test_reference_insns
+ assert_equal([:visit_insn, Opcodes::ACONST_NULL], (aconst_null))
+ assert_equal([:visit_insn, Opcodes::ARETURN], (areturn))
+ assert_equal([:visit_insn, Opcodes::ATHROW], (athrow))
+ assert_equal([:visit_insn, Opcodes::AALOAD], (aaload))
+ assert_equal([:visit_insn, Opcodes::AASTORE], (aastore))
+ end
+
+ def test_byte_insns
+ assert_equal([:visit_insn, Opcodes::BALOAD], (baload))
+ assert_equal([:visit_insn, Opcodes::BASTORE], (bastore))
+ end
+
+ def test_char_insns
+ assert_equal([:visit_insn, Opcodes::CALOAD], (caload))
+ assert_equal([:visit_insn, Opcodes::CASTORE], (castore))
+ end
+
+ def test_short_insns
+ assert_equal([:visit_insn, Opcodes::SALOAD], (saload))
+ assert_equal([:visit_insn, Opcodes::SASTORE], (sastore))
+ end
+
+ def test_int_insns
+ assert_equal([:visit_insn, Opcodes::ICONST_M1], (iconst_m1))
+ assert_equal([:visit_insn, Opcodes::ICONST_0], (iconst_0))
+ assert_equal([:visit_insn, Opcodes::ICONST_1], (iconst_1))
+ assert_equal([:visit_insn, Opcodes::ICONST_2], (iconst_2))
+ assert_equal([:visit_insn, Opcodes::ICONST_3], (iconst_3))
+ assert_equal([:visit_insn, Opcodes::ICONST_4], (iconst_4))
+ assert_equal([:visit_insn, Opcodes::ICONST_5], (iconst_5))
+ assert_equal([:visit_insn, Opcodes::IALOAD], (iaload))
+ assert_equal([:visit_insn, Opcodes::IASTORE], (iastore))
+ assert_equal([:visit_insn, Opcodes::IRETURN], (ireturn))
assert_equal([:visit_insn, Opcodes::IADD], (iadd))
assert_equal([:visit_insn, Opcodes::ISUB], (isub))
assert_equal([:visit_insn, Opcodes::IINC], (iinc))
+ assert_equal([:visit_insn, Opcodes::IDIV], (idiv))
+ assert_equal([:visit_insn, Opcodes::IMUL], (imul))
+ assert_equal([:visit_insn, Opcodes::INEG], (ineg))
+ assert_equal([:visit_insn, Opcodes::IAND], (iand))
+ assert_equal([:visit_insn, Opcodes::IOR], (ior))
+ assert_equal([:visit_insn, Opcodes::IXOR], (ixor))
+ assert_equal([:visit_insn, Opcodes::IUSHR], (iushr))
+ assert_equal([:visit_insn, Opcodes::ISHL], (ishl))
+ assert_equal([:visit_insn, Opcodes::ISHR], (ishr))
+ assert_equal([:visit_insn, Opcodes::IREM], (irem))
+ assert_equal([:visit_insn, Opcodes::I2L], (i2l))
+ assert_equal([:visit_insn, Opcodes::I2S], (i2s))
+ assert_equal([:visit_insn, Opcodes::I2B], (i2b))
+ assert_equal([:visit_insn, Opcodes::I2C], (i2c))
+ assert_equal([:visit_insn, Opcodes::I2D], (i2d))
+ assert_equal([:visit_insn, Opcodes::I2F], (i2f))
+ end
+
+ def test_long_insns
+ assert_equal([:visit_insn, Opcodes::LCONST_0], (lconst_0))
+ assert_equal([:visit_insn, Opcodes::LCONST_1], (lconst_1))
+ assert_equal([:visit_insn, Opcodes::LALOAD], (laload))
+ assert_equal([:visit_insn, Opcodes::LASTORE], (lastore))
+ assert_equal([:visit_insn, Opcodes::LRETURN], (lreturn))
+ assert_equal([:visit_insn, Opcodes::LADD], (ladd))
+ assert_equal([:visit_insn, Opcodes::LSUB], (lsub))
+ assert_equal([:visit_insn, Opcodes::LDIV], (ldiv))
+ assert_equal([:visit_insn, Opcodes::LMUL], (lmul))
+ assert_equal([:visit_insn, Opcodes::LNEG], (lneg))
+ assert_equal([:visit_insn, Opcodes::LAND], (land))
+ assert_equal([:visit_insn, Opcodes::LOR], (lor))
+ assert_equal([:visit_insn, Opcodes::LXOR], (lxor))
+ assert_equal([:visit_insn, Opcodes::LUSHR], (lushr))
+ assert_equal([:visit_insn, Opcodes::LSHL], (lshl))
+ assert_equal([:visit_insn, Opcodes::LSHR], (lshr))
+ assert_equal([:visit_insn, Opcodes::LREM], (lrem))
+ assert_equal([:visit_insn, Opcodes::L2I], (l2i))
+ assert_equal([:visit_insn, Opcodes::L2D], (l2d))
+ assert_equal([:visit_insn, Opcodes::L2F], (l2f))
+ end
+
+ def test_float_insns
+ assert_equal([:visit_insn, Opcodes::FALOAD], (faload))
+ assert_equal([:visit_insn, Opcodes::FASTORE], (fastore))
+ assert_equal([:visit_insn, Opcodes::FRETURN], (freturn))
+ assert_equal([:visit_insn, Opcodes::FADD], (fadd))
+ assert_equal([:visit_insn, Opcodes::FSUB], (fsub))
+ assert_equal([:visit_insn, Opcodes::FDIV], (fdiv))
+ assert_equal([:visit_insn, Opcodes::FMUL], (fmul))
+ assert_equal([:visit_insn, Opcodes::FNEG], (fneg))
+ assert_equal([:visit_insn, Opcodes::FREM], (frem))
+ assert_equal([:visit_insn, Opcodes::F2L], (f2l))
+ assert_equal([:visit_insn, Opcodes::F2D], (f2d))
+ assert_equal([:visit_insn, Opcodes::F2I], (f2i))
+ end
+
+ def test_double_insns
+ assert_equal([:visit_insn, Opcodes::DALOAD], (daload))
+ assert_equal([:visit_insn, Opcodes::DASTORE], (dastore))
+ assert_equal([:visit_insn, Opcodes::DRETURN], (dreturn))
+ assert_equal([:visit_insn, Opcodes::DADD], (dadd))
+ assert_equal([:visit_insn, Opcodes::DSUB], (dsub))
+ assert_equal([:visit_insn, Opcodes::DDIV], (ddiv))
+ assert_equal([:visit_insn, Opcodes::DMUL], (dmul))
+ assert_equal([:visit_insn, Opcodes::DNEG], (dneg))
+ assert_equal([:visit_insn, Opcodes::DREM], (drem))
+ assert_equal([:visit_insn, Opcodes::D2L], (d2l))
+ assert_equal([:visit_insn, Opcodes::D2F], (d2f))
+ assert_equal([:visit_insn, Opcodes::D2I], (d2i))
+ end
+
+ def test_sync_insns
+ assert_equal([:visit_insn, Opcodes::MONITORENTER], (monitorenter))
+ assert_equal([:visit_insn, Opcodes::MONITOREXIT], (monitorexit))
end
def test_type_insns
@@ -122,6 +261,10 @@ def test_jump_insns
assert_equal([:visit_jump_insn, Opcodes::GOTO, lbl.label], (goto lbl))
assert_equal([:visit_jump_insn, Opcodes::IFEQ, lbl.label], (ifeq lbl))
assert_equal([:visit_jump_insn, Opcodes::IFNE, lbl.label], (ifne lbl))
+ assert_equal([:visit_jump_insn, Opcodes::IFLE, lbl.label], (ifle lbl))
+ assert_equal([:visit_jump_insn, Opcodes::IFLT, lbl.label], (iflt lbl))
+ assert_equal([:visit_jump_insn, Opcodes::IFGE, lbl.label], (ifge lbl))
+ assert_equal([:visit_jump_insn, Opcodes::IFGT, lbl.label], (ifgt lbl))
assert_equal([:visit_jump_insn, Opcodes::IF_ACMPEQ, lbl.label], (if_acmpeq lbl))
assert_equal([:visit_jump_insn, Opcodes::IF_ACMPNE, lbl.label], (if_acmpne lbl))
assert_equal([:visit_jump_insn, Opcodes::IF_ICMPEQ, lbl.label], (if_icmpeq lbl))
@@ -132,6 +275,11 @@ def test_jump_insns
assert_equal([:visit_jump_insn, Opcodes::IF_ICMPGE, lbl.label], (if_icmpge lbl))
assert_equal([:visit_jump_insn, Opcodes::IFNULL, lbl.label], (ifnull lbl))
assert_equal([:visit_jump_insn, Opcodes::IFNONNULL, lbl.label], (ifnonnull lbl))
+ assert_equal([:visit_jump_insn, Opcodes::JSR, lbl.label], (jsr lbl))
+ end
+
+ def test_multidim_array
+ assert_equal([:visit_multi_anew_array_insn, "Ljava/lang/Integer;", 5], (multianewarray Integer, 5))
end
def test_lookup_switch
Please sign in to comment.
Something went wrong with that request. Please try again.