reviving more tests
This commit is contained in:
parent
e4c799ecb6
commit
001af3f8b6
@ -2,8 +2,13 @@ module Compiler
|
|||||||
|
|
||||||
def self.compile expression , method , message
|
def self.compile expression , method , message
|
||||||
exp_name = expression.class.name.split("::").last.sub("Expression","").downcase
|
exp_name = expression.class.name.split("::").last.sub("Expression","").downcase
|
||||||
puts "Expression #{exp_name}"
|
#puts "Expression #{exp_name}"
|
||||||
|
begin
|
||||||
self.send "compile_#{exp_name}".to_sym , expression, method , message
|
self.send "compile_#{exp_name}".to_sym , expression, method , message
|
||||||
|
rescue NoMethodError => e
|
||||||
|
puts exp_name
|
||||||
|
raise e
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -12,7 +12,7 @@ module Compiler
|
|||||||
|
|
||||||
# attr_reader :value
|
# attr_reader :value
|
||||||
def self.compile_integer expession , method , message
|
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)
|
to = Virtual::NewReturn.new(Virtual::Integer , int)
|
||||||
method.add_code Virtual::Set.new( to , int)
|
method.add_code Virtual::Set.new( to , int)
|
||||||
to
|
to
|
||||||
@ -41,14 +41,14 @@ module Compiler
|
|||||||
|
|
||||||
# attr_reader :name
|
# attr_reader :name
|
||||||
# compiling name needs to check if it's a variable and if so resolve it
|
# 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
|
# this makes the namespace static, ie when eval and co are implemented method needs recompilation
|
||||||
def self.compile_name expession , method , message
|
def self.compile_name expession , method , message
|
||||||
return Virtual::Self.new( Virtual::Mystery ) if expession.name == :self
|
return Virtual::Self.new( Virtual::Mystery ) if expession.name == :self
|
||||||
if method.has_var(expession.name)
|
if method.has_var(expession.name)
|
||||||
message.compile_get(method , expession.name )
|
message.compile_get(method , expession.name )
|
||||||
else
|
else
|
||||||
raise "Unimplemented #{self}"
|
raise "TODO unimplemented branch #{expession.class}(#{expession})"
|
||||||
message.compile_send( method , expession.name , Virtual::Self.new( Virtual::Mystery ) )
|
message.compile_send( method , expession.name , Virtual::Self.new( Virtual::Mystery ) )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -8,7 +8,7 @@ module Virtual
|
|||||||
|
|
||||||
# additionally frame, self and return are slots in Message and NewMessage
|
# additionally frame, self and return are slots in Message and NewMessage
|
||||||
|
|
||||||
class Slot
|
class Slot < Object
|
||||||
MESSAGE_REGISTER = :r0
|
MESSAGE_REGISTER = :r0
|
||||||
SELF_REGISTER = :r1
|
SELF_REGISTER = :r1
|
||||||
FRAME_REGISTER = :r2
|
FRAME_REGISTER = :r2
|
||||||
|
@ -2,4 +2,4 @@
|
|||||||
require_relative "arm/test_all"
|
require_relative "arm/test_all"
|
||||||
require "parfait/hash_test"
|
require "parfait/hash_test"
|
||||||
|
|
||||||
#require_relative "virtual/test_all"
|
require_relative "virtual/test_all"
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
require_relative "test_basic"
|
require_relative "test_basic"
|
||||||
require_relative "test_methods"
|
#require_relative "test_methods"
|
||||||
|
@ -5,27 +5,28 @@ class TestBasic < MiniTest::Test
|
|||||||
|
|
||||||
def test_number
|
def test_number
|
||||||
@string_input = '42 '
|
@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
|
check
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_true
|
def test_true
|
||||||
@string_input = '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
|
check
|
||||||
end
|
end
|
||||||
def test_false
|
def test_false
|
||||||
@string_input = '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
|
check
|
||||||
end
|
end
|
||||||
def test_nil
|
def test_nil
|
||||||
@string_input = '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
|
check
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_name
|
def pest_name
|
||||||
|
#TODO
|
||||||
@string_input = 'foo '
|
@string_input = 'foo '
|
||||||
@output = "---RETURN_MARKER- !ruby/object:Virtual::ReturnRETURN_MARKER name: :returnRETURN_MARKER type: !ruby/class 'Virtual::Mystery'RETURN_MARKER"
|
@output = "---RETURN_MARKER- !ruby/object:Virtual::ReturnRETURN_MARKER name: :returnRETURN_MARKER type: !ruby/class 'Virtual::Mystery'RETURN_MARKER"
|
||||||
check
|
check
|
||||||
@ -33,17 +34,17 @@ class TestBasic < MiniTest::Test
|
|||||||
|
|
||||||
def test_self
|
def test_self
|
||||||
@string_input = '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
|
check
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_instance_variable
|
def test_instance_variable
|
||||||
@string_input = '@foo_bar '
|
@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
|
check
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_module_name
|
def pest_module_name
|
||||||
@string_input = 'FooBar '
|
@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"
|
@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
|
check
|
||||||
@ -51,7 +52,7 @@ class TestBasic < MiniTest::Test
|
|||||||
|
|
||||||
def test_string
|
def test_string
|
||||||
@string_input = "\"hello\""
|
@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
|
check
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -11,10 +11,8 @@ module VirtualHelper
|
|||||||
def check
|
def check
|
||||||
machine = Virtual::Machine.boot
|
machine = Virtual::Machine.boot
|
||||||
expressions = machine.compile_main @string_input
|
expressions = machine.compile_main @string_input
|
||||||
should = YAML.load(@output.gsub("RETURN_MARKER" , "\n"))
|
is = Sof::Writer.write(expressions).gsub("\n" , "*^*")
|
||||||
assert_equal should , expressions , expressions.to_yaml.gsub("\n" , "RETURN_MARKER") + "\n" + Sof::Writer.write(expressions)
|
assert_equal is , @output
|
||||||
puts ""
|
|
||||||
puts Sof::Writer.write(expressions)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user