move mom instruction up one

just like the risc one, also some basic tests
This commit is contained in:
Torsten Rüger 2019-08-06 20:44:39 +03:00
parent 66c2adda20
commit 5d1d485565
4 changed files with 51 additions and 18 deletions

View File

@ -13,6 +13,17 @@ module Mom
class Instruction class Instruction
include Util::List include Util::List
def initialize( source , nekst = nil )
@source = source
@next = nekst
return unless source
unless source.is_a?(String) or
source.is_a?(Vool::Statement)
raise "Source must be string or Instruction, not #{source.class}"
end
end
attr_reader :source
# to_risc, like the name says, converts the instruction to it's Risc equivalent. # to_risc, like the name says, converts the instruction to it's Risc equivalent.
# The Risc machine is basically a simple register machine (kind of arm). # The Risc machine is basically a simple register machine (kind of arm).
# In other words Mom is the higher abstraction and so mom instructions convert # In other words Mom is the higher abstraction and so mom instructions convert
@ -27,18 +38,18 @@ module Mom
end end
require_relative "label" require_relative "instruction/label"
require_relative "check" require_relative "instruction/check"
require_relative "basic_values" require_relative "instruction/basic_values"
require_relative "simple_call" require_relative "instruction/simple_call"
require_relative "dynamic_call" require_relative "instruction/dynamic_call"
require_relative "block_yield" require_relative "instruction/block_yield"
require_relative "resolve_method" require_relative "instruction/resolve_method"
require_relative "truth_check" require_relative "instruction/truth_check"
require_relative "not_same_check" require_relative "instruction/not_same_check"
require_relative "jump" require_relative "instruction/jump"
require_relative "return_jump" require_relative "instruction/return_jump"
require_relative "slot_load" require_relative "instruction/slot_load"
require_relative "return_sequence" require_relative "instruction/return_sequence"
require_relative "message_setup" require_relative "instruction/message_setup"
require_relative "argument_transfer" require_relative "instruction/argument_transfer"

View File

@ -14,6 +14,8 @@
module Mom module Mom
end end
require_relative "instruction/instruction.rb" require_relative "instruction.rb"
require_relative "mom_compiler" require_relative "mom_collection"
require_relative "callable_compiler" require_relative "callable_compiler"
require_relative "method_compiler"
require_relative "block_compiler"

View File

@ -34,7 +34,7 @@ module Parfait
def compiler_for(self_type) def compiler_for(self_type)
callable_method = create_callable_method(self_type) callable_method = create_callable_method(self_type)
compiler = Mom::CallableCompiler.new( callable_method ) compiler = Mom::MethodCompiler.new( callable_method )
head = @source.to_mom( compiler ) head = @source.to_mom( compiler )
compiler.add_mom(head) compiler.add_mom(head)
compiler compiler

View File

@ -0,0 +1,20 @@
require_relative "helper"
module Mom
class TestInstruction < MiniTest::Test
def test_instantiates
assert Instruction.new("Hi")
end
def test_string_source
assert_equal "Hi" ,Instruction.new("Hi").source
end
def test_nil_next
assert_nil Instruction.new("Hi").next
end
def test_raise
assert_raises {Instruction.new(5)}
end
end
end