gruesome 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,3 @@
1
1
  module Grue
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -317,6 +317,34 @@ module Gruesome
317
317
  { :size => size, :property_number => property_number, :property_data_address => prop_address }
318
318
  end
319
319
 
320
+ def object_properties_array(index)
321
+ entry = object_entry(index)
322
+ prop_address = entry[:properties_address]
323
+
324
+ # get the length of the string in bytes
325
+ text_len = @memory.force_readb(prop_address) * 2
326
+ prop_address += 1
327
+
328
+ prop_address += text_len
329
+
330
+ properties = []
331
+
332
+ while true do
333
+ entry_info = object_get_size_and_number(prop_address)
334
+
335
+ if entry_info == nil
336
+ break
337
+ end
338
+
339
+ # regardless of version, we now have the property size and the number
340
+
341
+ properties << {:property_number => entry_info[:property_number], :size => entry_info[:size], :property_data_address => entry_info[:property_data_address]}
342
+ prop_address = entry_info[:property_data_address] + entry_info[:size]
343
+ end
344
+
345
+ properties
346
+ end
347
+
320
348
  def object_properties(index)
321
349
  entry = object_entry(index)
322
350
  prop_address = entry[:properties_address]
@@ -377,6 +405,34 @@ module Gruesome
377
405
  end
378
406
  end
379
407
 
408
+ def object_get_next_property(index, property_number)
409
+ properties = object_properties_array(index)
410
+ if property_number == 0
411
+ next_number = properties[0][:property_number]
412
+ else
413
+ cur_prop_index = nil
414
+ properties.each_with_index do |p, i|
415
+ if p[:property_number] == property_number
416
+ cur_prop_index = i
417
+ end
418
+ end
419
+
420
+ if cur_prop_index == nil
421
+ # Error: Cannot get the next property when the property given is invalid
422
+ raise "get_prop_addr gave incorrect property_number"
423
+ end
424
+
425
+ next_prop_index = cur_prop_index + 1
426
+
427
+ if next_prop_index == properties.length
428
+ next_number = 0
429
+ else
430
+ next_number = properties[next_prop_index][:property_number]
431
+ end
432
+ end
433
+ next_number
434
+ end
435
+
380
436
  def object_get_property_data_size_from_address(address)
381
437
  if @header.version <= 3
382
438
  prop_address = address - 1
@@ -24,7 +24,7 @@ module Gruesome
24
24
  LOADB = (0x10 << 3) | OpcodeClass::OP2
25
25
  GET_PROP = (0x11 << 3) | OpcodeClass::OP2
26
26
  GET_PROP_ADDR = (0x12 << 3) | OpcodeClass::OP2
27
- GET_NPROP = (0x13 << 3) | OpcodeClass::OP2
27
+ GET_NEXT_PROP = (0x13 << 3) | OpcodeClass::OP2
28
28
  ADD = (0x14 << 3) | OpcodeClass::OP2
29
29
  SUB = (0x15 << 3) | OpcodeClass::OP2
30
30
  MUL = (0x16 << 3) | OpcodeClass::OP2
@@ -161,7 +161,7 @@ module Gruesome
161
161
  if opcode_class == OpcodeClass::OP2
162
162
  case opcode
163
163
  when Opcode::OR, Opcode::AND, Opcode::LOADB, Opcode::LOADW,
164
- Opcode::GET_PROP, Opcode::GET_PROP_ADDR, Opcode::GET_NPROP,
164
+ Opcode::GET_PROP, Opcode::GET_PROP_ADDR, Opcode::GET_NEXT_PROP,
165
165
  Opcode::ADD, Opcode::SUB, Opcode::MUL, Opcode::DIV, Opcode::MOD,
166
166
  Opcode::CALL_2S
167
167
  result = true
@@ -426,7 +426,7 @@ module Gruesome
426
426
  when Opcode::LOADB then "loadb"
427
427
  when Opcode::GET_PROP then "get_prop"
428
428
  when Opcode::GET_PROP_ADDR then "get_prop_addr"
429
- when Opcode::GET_NPROP then "get_next_prop"
429
+ when Opcode::GET_NEXT_PROP then "get_next_prop"
430
430
  when Opcode::ADD then "add"
431
431
  when Opcode::SUB then "sub"
432
432
  when Opcode::MUL then "mul"
@@ -126,6 +126,9 @@ module Gruesome
126
126
  @memory.writev(instruction.destination, child)
127
127
  result = child != 0
128
128
  branch(instruction.branch_to, instruction.branch_on, result)
129
+ when Opcode::GET_NEXT_PROP
130
+ next_prop = @object_table.object_get_next_property(operands[0], operands[1])
131
+ @memory.writev(instruction.destination, next_prop)
129
132
  when Opcode::GET_PARENT
130
133
  parent = @object_table.object_get_parent(operands[0])
131
134
  @memory.writev(instruction.destination, parent)
@@ -3,7 +3,7 @@ require_relative '../../lib/gruesome/z/memory'
3
3
  describe Gruesome::Z::Memory do
4
4
  before(:each) do
5
5
  zork = File.open('test/zork1.z3', 'r')
6
- @zork_memory = Gruesome::Z::Memory.new(zork.read(zork.size))
6
+ @zork_memory = Gruesome::Z::Memory.new(zork.read(zork.size), '')
7
7
  end
8
8
 
9
9
  describe "#readb" do
@@ -13,7 +13,7 @@ describe Gruesome::Z::Processor do
13
13
  describe "#execute" do
14
14
  before(:each) do
15
15
  zork = File.open('test/zork1.z3', 'r')
16
- @zork_memory = Gruesome::Z::Memory.new(zork.read(zork.size))
16
+ @zork_memory = Gruesome::Z::Memory.new(zork.read(zork.size), '')
17
17
  @processor = Gruesome::Z::Processor.new(@zork_memory)
18
18
  @zork_memory.program_counter = 12345
19
19
  end
Binary file
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 5
9
- version: 0.0.5
8
+ - 6
9
+ version: 0.0.6
10
10
  platform: ruby
11
11
  authors:
12
12
  - Dave Wilkinson
@@ -80,6 +80,7 @@ files:
80
80
  - spec/z/memory_spec.rb
81
81
  - spec/z/processor_spec.rb
82
82
  - test/logo.txt
83
+ - test/zork1.z3
83
84
  has_rdoc: true
84
85
  homepage: http://github.com/wilkie/gruesome
85
86
  licenses: []
@@ -116,3 +117,4 @@ test_files:
116
117
  - spec/z/memory_spec.rb
117
118
  - spec/z/processor_spec.rb
118
119
  - test/logo.txt
120
+ - test/zork1.z3