Class: YTLJit::AsmType::Struct
- Inherits:
-
TypeCommon
- Object
- TypeCommon
- YTLJit::AsmType::Struct
- Defined in:
- lib/ytljit/struct.rb
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from TypeCommon
Instance Method Summary collapse
- #[](name, base = 0) ⇒ Object
-
#initialize(*spec) ⇒ Struct
constructor
A new instance of Struct.
- #offset_of(name, base = 0) ⇒ Object
- #size ⇒ Object
- #type_of(name) ⇒ Object
Constructor Details
#initialize(*spec) ⇒ Struct
Returns a new instance of Struct.
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 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/ytljit/struct.rb', line 21 def initialize(*spec) @member = [] @size = nil stat = 0 curvar = [] spec.each do |token| case stat when 0 curvar.push token stat = 1 when 1 curvar.push token stat = 2 when 2 if token.is_a?(Integer) then curvar.push token @member.push curvar curvar = [] stat = 0 else @member.push curvar if token then curvar = [token] stat = 1 else curvar = [] stat = 0 end end end # assert(stat == 0) end @member.push curvar end |
Instance Method Details
#[](name, base = 0) ⇒ Object
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/ytljit/struct.rb', line 91 def [](name, base = 0) offset = 0 @member.each do |e| if e[1] == name then return StructMember.new(e[0], offset + base) end offset += e[2] ? e[2] : e[0].size end raise "No such member #{name} in #{self}" end |
#offset_of(name, base = 0) ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/ytljit/struct.rb', line 58 def offset_of(name, base = 0) offset = 0 @member.each do |e| if e[1] == name then return offset + base end offset += e[2] ? e[2] : e[0].size end raise "No such member #{name} in #{self}" end |
#size ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/ytljit/struct.rb', line 79 def size if @size then @size else @size = 0 @member.each do |e| @size += e[2] ? e[2] : e[0].size end @size end end |
#type_of(name) ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/ytljit/struct.rb', line 69 def type_of(name) offset = 0 @member.each do |e| if e[1] == name then return e[0] end end raise "No such member #{name} in #{self}" end |