---
title: "null"
author: "dearwolf"
date: "2010-01-05T19:25:17Z"
tags: []
categories: ["编程语言"]
slug: "null"
draft: false
lastmod: "2010-01-05T19:25:17Z"
id: 563242
url: "https://dearwolf.iteye.com/blog/563242"
---

```
{
        :no_arg       => 1,
        :var          => 2,
        :implicit_var => 1,
        :ldc          => 2,
        :ldc_w        => 3,
        :label        => 3,
        :method       => 3,
        :field        => 3,
        :int          => 2,
        :iinc         => 3,
        :type         => 3,
        :lookup_switch  => -1
      }.each do |type, size|
        class_eval %Q{
          def #{type}_instructions(*opcode, &block)
            instructions(#{size}, *opcode, &block)
          end
        }
      end
```

 

```
  {
    :Method => [:owner, :name, :desc],
    :Field  => [:owner, :name, :desc],
    :Var    => [:var],
    :Type   => [:type],
    :Int    => [:operand],
    :Iinc   => [:var, :incr],
    :Jump   => [:label],
    :Ldc    => [:constant],
    :LookupSwitch => [:default_label, :case_table]
  }.each do |type, args|
    module_eval <<-INSTRUCTION
    class #{type}Insn < Instruction
      attr_accessor #{args.collect{|item| ":#{item}"}.join(',')}

      def initialize(opcode, #{args.collect{|item| "#{item}"}.join(',')})
        super(opcode)
        #{args.collect{|item| "@#{item} = #{item}"}.join("\n")}
      end

      def ==(insn)
        super(insn) && #{args.collect{|item| "@#{item} == insn.#{item}"}.join('&&')}
      end
    end
    INSTRUCTION
```