Class: Wardite::Op

Inherits:
Object
  • Object
show all
Defined in:
lib/wardite/instruction.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code, operand) ⇒ Op

Returns a new instance of Op.



10
11
12
13
# File 'lib/wardite/instruction.rb', line 10

def initialize(code, operand)
  @code = code
  @operand = operand
end

Instance Attribute Details

#codeObject

: Symbol



4
5
6
# File 'lib/wardite/instruction.rb', line 4

def code
  @code
end

#operandObject

: Array



6
7
8
# File 'lib/wardite/instruction.rb', line 6

def operand
  @operand
end

Class Method Details

.i2type(code) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/wardite/instruction.rb', line 68

def self.i2type(code)
  case code
  when 0x7f
    :i32
  when 0x7e
    :i64
  when 0x7d
    :f32
  when 0x7c
    :f64
  else
    raise "unknown type code #{code}"
  end
end

.operand_of(code) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/wardite/instruction.rb', line 50

def self.operand_of(code)
  case code
  when :local_get, :local_set, :call
    [:u32]
  when :i32_const
    [:i32]
  when :i32_store
    [:u32, :u32]
  when :if
    [:u8_block]
  else
    []
  end
end

.to_sym(chr) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/wardite/instruction.rb', line 17

def self.to_sym(chr)
  case chr
  when "\u0004"
    :if
  when "\u000b"
    :end
  when "\u000f"
    :return
  when "\u0010"
    :call
  when "\u0020"
    :local_get
  when "\u0021"
    :local_set
  when "\u0036"
    :i32_store
  when "\u0041"
    :i32_const
  when "\u0048"
    :i32_lts
  when "\u004d"
    :i32_leu
  when "\u006a"
    :i32_add
  when "\u006b"
    :i32_sub
  else
    raise NotImplementedError, "unimplemented: #{"%04x" % chr.ord}"
  end
end