diff --git a/lib/mom/instruction/instruction.rb b/lib/mom/instruction.rb similarity index 52% rename from lib/mom/instruction/instruction.rb rename to lib/mom/instruction.rb index 0e4d5d21..c09ed54f 100644 --- a/lib/mom/instruction/instruction.rb +++ b/lib/mom/instruction.rb @@ -13,6 +13,17 @@ module Mom class Instruction 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. # 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 @@ -27,18 +38,18 @@ module Mom end -require_relative "label" -require_relative "check" -require_relative "basic_values" -require_relative "simple_call" -require_relative "dynamic_call" -require_relative "block_yield" -require_relative "resolve_method" -require_relative "truth_check" -require_relative "not_same_check" -require_relative "jump" -require_relative "return_jump" -require_relative "slot_load" -require_relative "return_sequence" -require_relative "message_setup" -require_relative "argument_transfer" +require_relative "instruction/label" +require_relative "instruction/check" +require_relative "instruction/basic_values" +require_relative "instruction/simple_call" +require_relative "instruction/dynamic_call" +require_relative "instruction/block_yield" +require_relative "instruction/resolve_method" +require_relative "instruction/truth_check" +require_relative "instruction/not_same_check" +require_relative "instruction/jump" +require_relative "instruction/return_jump" +require_relative "instruction/slot_load" +require_relative "instruction/return_sequence" +require_relative "instruction/message_setup" +require_relative "instruction/argument_transfer" diff --git a/lib/mom/mom.rb b/lib/mom/mom.rb index b93a2f3e..132c2661 100644 --- a/lib/mom/mom.rb +++ b/lib/mom/mom.rb @@ -14,6 +14,8 @@ module Mom end -require_relative "instruction/instruction.rb" -require_relative "mom_compiler" +require_relative "instruction.rb" +require_relative "mom_collection" require_relative "callable_compiler" +require_relative "method_compiler" +require_relative "block_compiler" diff --git a/lib/parfait/vool_method.rb b/lib/parfait/vool_method.rb index 788bfa17..55abf322 100644 --- a/lib/parfait/vool_method.rb +++ b/lib/parfait/vool_method.rb @@ -34,7 +34,7 @@ module Parfait def compiler_for(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 ) compiler.add_mom(head) compiler diff --git a/test/mom/test_instruction.rb b/test/mom/test_instruction.rb new file mode 100644 index 00000000..82b0d5d7 --- /dev/null +++ b/test/mom/test_instruction.rb @@ -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