Sha256: 30f3a410b4cace3c213f8dad6b302b1b949a0733f0bfb4753ac88d54b4ba4222

Contents?: true

Size: 1.63 KB

Versions: 11

Compression:

Stored size: 1.63 KB

Contents

#include "instruction.h"
#include "insns_info.h"
#include <ruby.h>

#ifndef RARRAY_LEN
#define RARRAY_LEN(a) RARRAY(a)->len
#endif

#ifndef RARRAY_PTR
#define RARRAY_PTR(a) RARRAY(a)->ptr
#endif

#ifdef RUBY_VM

/*
 * call-seq:
 *   Instruction.new(*operands) => Instruction
 *
 * Create a new instruction with the given operands.
 */
static VALUE instruction_initialize(int argc, VALUE * argv, VALUE self)
{
  VALUE operands = rb_ary_new4(argc, argv);
  rb_iv_set(self, "@operands", operands);
  return Qnil;
}

/*
 * call-seq:
 *   instruction.operands => Array
 *
 * Returns the instructions operands.
 */
static VALUE instruction_operands(VALUE self)
{
  return rb_iv_get(self, "@operands");
}

VALUE allocate_instruction(int instruction, VALUE args)
{
  return rb_class_new_instance(
      RARRAY_LEN(args),
      RARRAY_PTR(args),
      instruction_class[instruction]);
}

#endif

void Init_instruction(void)
{
#ifdef RUBY_VM
  VALUE rb_cRubyVM;
  VALUE rb_cInstruction;

  if(!rb_const_defined(rb_cObject, rb_intern("RubyVM")))
  {
    rb_define_const(
        rb_cObject,
        "RubyVM",
        rb_const_get(rb_cObject, rb_intern("VM")));
  }

  rb_cRubyVM = rb_define_class("RubyVM", rb_cObject);

  rb_cInstruction = rb_define_class_under(rb_cRubyVM, "Instruction", rb_cObject);
  rb_define_method(rb_cInstruction, "initialize", instruction_initialize, -1);
  rb_define_method(rb_cInstruction, "operands", instruction_operands, 0);
  rb_undef_method(rb_cInstruction, "new");

  define_instruction_subclasses(rb_cInstruction);

  /* Silence compiler warnings about unused static functions */
  insn_name(0);
  insn_op_type(0, 0);
  insn_op_types(0);
#endif
}

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
ruby-internal-0.8.5 ext/internal/vm/instruction/instruction.c
ruby-internal-0.8.4 ext/internal/vm/instruction/instruction.c
ruby-internal-0.8.3 ext/internal/vm/instruction/instruction.c
ruby-internal-0.8.2 ext/internal/vm/instruction/instruction.c
ruby-internal-0.8.1 ext/internal/vm/instruction/instruction.c
ruby-internal-0.8.0 ext/internal/vm/instruction/instruction.c
ruby-internal-0.7.3 ext/internal/vm/instruction/instruction.c
ruby-internal-0.7.2 ext/internal/vm/instruction/instruction.c
ruby-internal-0.7.1 ext/internal/vm/instruction/instruction.c
ruby-internal-0.7.0 ext/internal/vm/instruction/instruction.c
ruby-internal-0.6.0 ext/internal/vm/instruction/instruction.c