reviving more tests

This commit is contained in:
Torsten Ruger 2015-05-05 14:04:37 +03:00
parent e4c799ecb6
commit 001af3f8b6
7 changed files with 30 additions and 26 deletions

View File

@ -2,8 +2,13 @@ module Compiler
def self.compile expression , method , message
exp_name = expression.class.name.split("::").last.sub("Expression","").downcase
puts "Expression #{exp_name}"
self.send "compile_#{exp_name}".to_sym , expression, method , message
#puts "Expression #{exp_name}"
begin
self.send "compile_#{exp_name}".to_sym , expression, method , message
rescue NoMethodError => e
puts exp_name
raise e
end
end
end

View File

@ -12,7 +12,7 @@ module Compiler
# attr_reader :value
def self.compile_integer expession , method , message
int = Virtual::IntegerConstant.new(value)
int = Virtual::IntegerConstant.new(expession.value)
to = Virtual::NewReturn.new(Virtual::Integer , int)
method.add_code Virtual::Set.new( to , int)
to
@ -41,14 +41,14 @@ module Compiler
# attr_reader :name
# compiling name needs to check if it's a variable and if so resolve it
# otherwise it's a method without args and a send is ussued.
# otherwise it's a method without args and a send is usued.
# this makes the namespace static, ie when eval and co are implemented method needs recompilation
def self.compile_name expession , method , message
return Virtual::Self.new( Virtual::Mystery ) if expession.name == :self
if method.has_var(expession.name)
message.compile_get(method , expession.name )
else
raise "Unimplemented #{self}"
raise "TODO unimplemented branch #{expession.class}(#{expession})"
message.compile_send( method , expession.name , Virtual::Self.new( Virtual::Mystery ) )
end
end

View File

@ -5,10 +5,10 @@ module Virtual
# - the frame of the method that is executing (local variables): FrameSlot
# - self as an object: SelfSlot
# - a message that will be sent, NewMessageSlot
# additionally frame, self and return are slots in Message and NewMessage
class Slot
class Slot < Object
MESSAGE_REGISTER = :r0
SELF_REGISTER = :r1
FRAME_REGISTER = :r2
@ -31,7 +31,7 @@ module Virtual
@value = value
end
end
class MessageSlot < Slot
def initialize index , type = Mystery , value = nil
super(index ,type , value )

View File

@ -2,4 +2,4 @@
require_relative "arm/test_all"
require "parfait/hash_test"
#require_relative "virtual/test_all"
require_relative "virtual/test_all"

View File

@ -1,2 +1,2 @@
require_relative "test_basic"
require_relative "test_methods"
#require_relative "test_methods"

View File

@ -5,27 +5,28 @@ class TestBasic < MiniTest::Test
def test_number
@string_input = '42 '
@output = "---RETURN_MARKER- !ruby/object:Virtual::IntegerConstantRETURN_MARKER integer: 42RETURN_MARKER"
@output = "-Virtual::NewReturn(:index => 5, :type => Virtual::Integer)*^* :value Virtual::IntegerConstant(:integer => 42)"
check
end
def test_true
@string_input = 'true '
@output = "---RETURN_MARKER- !ruby/object:Virtual::TrueConstant {}RETURN_MARKER"
@output = "-Virtual::Return(:index => 5, :type => Virtual::Reference)*^* :value Virtual::TrueConstant(:length => -1)"
check
end
def test_false
@string_input = 'false '
@output = "---RETURN_MARKER- !ruby/object:Virtual::FalseConstant {}RETURN_MARKER"
@output = "-Virtual::Return(:index => 5, :type => Virtual::Reference)*^* :value Virtual::FalseConstant(:length => -1)"
check
end
def test_nil
@string_input = 'nil '
@output = "---RETURN_MARKER- !ruby/object:Virtual::NilConstant {}RETURN_MARKER"
@output = "-Virtual::Return(:index => 5, :type => Virtual::Reference)*^* :value Virtual::NilConstant(:length => -1)"
check
end
def test_name
def pest_name
#TODO
@string_input = 'foo '
@output = "---RETURN_MARKER- !ruby/object:Virtual::ReturnRETURN_MARKER name: :returnRETURN_MARKER type: !ruby/class 'Virtual::Mystery'RETURN_MARKER"
check
@ -33,17 +34,17 @@ class TestBasic < MiniTest::Test
def test_self
@string_input = 'self '
@output = "---RETURN_MARKER- !ruby/object:Virtual::SelfRETURN_MARKER name: :selfRETURN_MARKER type: !ruby/object:Virtual::Mystery {}RETURN_MARKER"
@output = "-Virtual::Self(:index => 3, :type => Virtual::Mystery)"
check
end
def test_instance_variable
@string_input = '@foo_bar '
@output = "---RETURN_MARKER- !ruby/object:Virtual::ReturnRETURN_MARKER name: :returnRETURN_MARKER type: !ruby/object:Virtual::Mystery {}RETURN_MARKER"
@output = "-Virtual::NewReturn(:index => 5, :type => Virtual::Mystery)"
check
end
def test_module_name
def pest_module_name
@string_input = 'FooBar '
@output = "---RETURN_MARKER- &1 !ruby/object:Boot::BootClassRETURN_MARKER instance_methods: []RETURN_MARKER name: :FooBarRETURN_MARKER super_class_name: :ObjectRETURN_MARKER meta_class: !ruby/object:Boot::MetaClassRETURN_MARKER functions: []RETURN_MARKER me_self: *1RETURN_MARKER"
check
@ -51,8 +52,8 @@ class TestBasic < MiniTest::Test
def test_string
@string_input = "\"hello\""
@output = "---RETURN_MARKER- !ruby/object:Virtual::StringConstantRETURN_MARKER string: helloRETURN_MARKER"
@output = "-Virtual::Return(:index => 5, :type => Virtual::Reference)*^* :value Virtual::StringConstant(:string => 'hello')"
check
end
end
end

View File

@ -3,7 +3,7 @@ require 'parslet/convenience'
require "yaml"
module VirtualHelper
# need a code generator, for arm
# need a code generator, for arm
def setup
# @object_space = Boot::BootSpace.new "Arm"
end
@ -11,10 +11,8 @@ module VirtualHelper
def check
machine = Virtual::Machine.boot
expressions = machine.compile_main @string_input
should = YAML.load(@output.gsub("RETURN_MARKER" , "\n"))
assert_equal should , expressions , expressions.to_yaml.gsub("\n" , "RETURN_MARKER") + "\n" + Sof::Writer.write(expressions)
puts ""
puts Sof::Writer.write(expressions)
is = Sof::Writer.write(expressions).gsub("\n" , "*^*")
assert_equal is , @output
end
end