Class: Haxor::Vm::Core
- Inherits:
-
Object
- Object
- Haxor::Vm::Core
- Defined in:
- lib/haxor/vm/core.rb
Instance Attribute Summary collapse
-
#mem ⇒ Object
readonly
Returns the value of attribute mem.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize ⇒ Core
constructor
A new instance of Core.
- #load_program(filename) ⇒ Object
- #register_subsystem(id, object) ⇒ Object
- #subsystem(id) ⇒ Object
Constructor Details
#initialize ⇒ Core
Returns a new instance of Core.
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/haxor/vm/core.rb', line 6 def initialize @subsystems = {} register_subsystem :cpu, Cpu::Core.new register_subsystem :mem, Mem.new(Consts::RESERVED_MEM) register_subsystem :stack, Stack.new register_subsystem :os, Os.new # register_subsystem :registers, Registers.new @units = [] @opcodes = {} end |
Instance Attribute Details
#mem ⇒ Object (readonly)
Returns the value of attribute mem.
4 5 6 |
# File 'lib/haxor/vm/core.rb', line 4 def mem @mem end |
Instance Method Details
#execute ⇒ Object
27 28 29 30 31 |
# File 'lib/haxor/vm/core.rb', line 27 def execute loop do subsystem(:cpu).iterate end end |
#load_program(filename) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/haxor/vm/core.rb', line 33 def load_program(filename) exe = File.read(filename, encoding: 'ASCII-8BIT') @hdr = Header.new @hdr.parse! exe if @hdr.version != Consts::VERSION fail 'Program is compiled for different version of Haxor VM Machine' end exe = exe[@hdr.size..-1] # cut off header subsystem(:mem).replace_region Consts::RESERVED_MEM, exe subsystem(:cpu).ip = @hdr.entry_point # instruction pointer subsystem(:mem).enlarge @hdr.bss_size subsystem(:mem).enlarge @hdr.stack_size subsystem(:cpu).reg Vm::Cpu::Core::REG_STACK, subsystem(:mem).size end |
#register_subsystem(id, object) ⇒ Object
18 19 20 21 |
# File 'lib/haxor/vm/core.rb', line 18 def register_subsystem(id, object) @subsystems[id] = object object.vm = self end |
#subsystem(id) ⇒ Object
23 24 25 |
# File 'lib/haxor/vm/core.rb', line 23 def subsystem(id) @subsystems[id] end |