Move the Main instruction from register to virtual
also needs a branch in register. This way the register level is self sufficient (noticed while writing debugger)
This commit is contained in:
@ -43,4 +43,4 @@ require_relative "instructions/function_call"
|
||||
require_relative "instructions/function_return"
|
||||
require_relative "instructions/save_return"
|
||||
require_relative "instructions/register_transfer"
|
||||
require_relative "instructions/register_main"
|
||||
require_relative "instructions/branch"
|
||||
|
12
lib/register/instructions/branch.rb
Normal file
12
lib/register/instructions/branch.rb
Normal file
@ -0,0 +1,12 @@
|
||||
module Register
|
||||
|
||||
|
||||
# a branch must branch to a block.
|
||||
class Branch < Instruction
|
||||
def initialize to
|
||||
raise "No block" unless to
|
||||
@block = to
|
||||
end
|
||||
attr_reader :block
|
||||
end
|
||||
end
|
@ -1,19 +0,0 @@
|
||||
module Register
|
||||
|
||||
# This starts the register machine machine at the given function.
|
||||
|
||||
# The implementation is most likely a jump/branch , but since we have the extra layer
|
||||
# we make good use of it, ie give things descriptive names (what they do, not how)
|
||||
|
||||
class RegisterMain < Instruction
|
||||
include Positioned
|
||||
|
||||
def initialize method
|
||||
@method = method
|
||||
end
|
||||
attr_reader :method
|
||||
def word_length
|
||||
4
|
||||
end
|
||||
end
|
||||
end
|
17
lib/register/passes/main_implementation.rb
Normal file
17
lib/register/passes/main_implementation.rb
Normal file
@ -0,0 +1,17 @@
|
||||
module Register
|
||||
|
||||
# "Boot" the virtual machine at the function given
|
||||
# meaning jump to that function currently. Maybe better to do some machine setup
|
||||
# and possibly some cleanup/exit has to tie in, but that is not this day
|
||||
|
||||
class MainImplementation
|
||||
def run block
|
||||
block.codes.dup.each do |code|
|
||||
next unless code.is_a? Virtual::VirtualMain
|
||||
branch = Register::Branch.new( code.method.source.blocks.first )
|
||||
block.replace(code , branch )
|
||||
end
|
||||
end
|
||||
end
|
||||
Virtual.machine.add_pass "Register::MainImplementation"
|
||||
end
|
@ -1,6 +1,7 @@
|
||||
require_relative "instruction"
|
||||
require_relative "register_reference"
|
||||
require_relative "assembler"
|
||||
require_relative "passes/main_implementation"
|
||||
require_relative "passes/frame_implementation"
|
||||
require_relative "passes/message_implementation"
|
||||
require_relative "passes/set_implementation"
|
||||
|
Reference in New Issue
Block a user