improve tests
This commit is contained in:
parent
6e009cc6df
commit
259b0afa96
@ -11,7 +11,6 @@ module Bosl
|
|||||||
# The current approach moves the constant into a variable before using it
|
# The current approach moves the constant into a variable before using it
|
||||||
# But in the future (in the one that holds great things) we optimize those unneccesay moves away
|
# But in the future (in the one that holds great things) we optimize those unneccesay moves away
|
||||||
|
|
||||||
# attr_reader :value
|
|
||||||
def on_int expression
|
def on_int expression
|
||||||
int = expression.first
|
int = expression.first
|
||||||
to = Virtual::Return.new(Virtual::Integer , int)
|
to = Virtual::Return.new(Virtual::Integer , int)
|
||||||
@ -37,15 +36,6 @@ module Bosl
|
|||||||
to
|
to
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_modulename expression
|
|
||||||
clazz = Parfait::Space.object_space.get_class_by_name expression.name
|
|
||||||
raise "compile_modulename #{clazz}.#{name}" unless clazz
|
|
||||||
to = Virtual::Return.new(Virtual::Reference , clazz )
|
|
||||||
method.source.add_code Virtual::Set.new( clazz , to )
|
|
||||||
to
|
|
||||||
end
|
|
||||||
|
|
||||||
# attr_reader :string
|
|
||||||
def on_string expression
|
def on_string expression
|
||||||
# Clearly a TODO here to implement strings rather than reusing symbols
|
# Clearly a TODO here to implement strings rather than reusing symbols
|
||||||
value = expression.first.to_sym
|
value = expression.first.to_sym
|
||||||
@ -54,23 +44,5 @@ module Bosl
|
|||||||
method.source.add_code Virtual::Set.new( value , to )
|
method.source.add_code Virtual::Set.new( value , to )
|
||||||
to
|
to
|
||||||
end
|
end
|
||||||
|
|
||||||
#attr_reader :left, :right
|
|
||||||
def on_assignment expression
|
|
||||||
unless expression.left.instance_of? Ast::NameExpression
|
|
||||||
raise "must assign to NameExpression , not #{expression.left}"
|
|
||||||
end
|
|
||||||
r = process(expression.right )
|
|
||||||
raise "oh noo, nil from where #{expression.right.inspect}" unless r
|
|
||||||
index = method.has_arg(expression.left.name.to_sym)
|
|
||||||
if index
|
|
||||||
method.source.add_code Virtual::Set.new(ArgSlot.new(index , r.type , r ) , Virtual::Return.new)
|
|
||||||
else
|
|
||||||
index = method.ensure_local(expression.left.name.to_sym)
|
|
||||||
method.source.add_code Virtual::Set.new(FrameSlot.new(index , r.type , r ) , Virtual::Return.new)
|
|
||||||
end
|
|
||||||
r
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -3,14 +3,11 @@ module Bosl
|
|||||||
|
|
||||||
# attr_reader :values
|
# attr_reader :values
|
||||||
def on_array expession, context
|
def on_array expession, context
|
||||||
raise "not implemented"
|
|
||||||
end
|
end
|
||||||
# attr_reader :key , :value
|
# attr_reader :key , :value
|
||||||
def on_association context
|
def on_association context
|
||||||
raise "not implemented"
|
|
||||||
end
|
end
|
||||||
def on_hash context
|
def on_hash context
|
||||||
raise "not implemented"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2,7 +2,8 @@ module Bosl
|
|||||||
Compiler.class_eval do
|
Compiler.class_eval do
|
||||||
# module attr_reader :name ,:expressions
|
# module attr_reader :name ,:expressions
|
||||||
def on_module expression
|
def on_module expression
|
||||||
return clazz
|
name , rest = *expression
|
||||||
|
return process_all(rest).last
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_class expression
|
def on_class expression
|
||||||
|
@ -129,7 +129,7 @@ module Parfait
|
|||||||
internal_object_shrink(len + 1)
|
internal_object_shrink(len + 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
def ==(other)
|
def equal?(other)
|
||||||
# this should call parfait get_class, alas that is not implemented yet
|
# this should call parfait get_class, alas that is not implemented yet
|
||||||
return false if other.class != self.class
|
return false if other.class != self.class
|
||||||
return false if other.get_length != self.get_length
|
return false if other.get_length != self.get_length
|
||||||
|
@ -21,12 +21,6 @@ module Virtual
|
|||||||
attr_reader :name , :codes , :method , :position
|
attr_reader :name , :codes , :method , :position
|
||||||
attr_accessor :branch
|
attr_accessor :branch
|
||||||
|
|
||||||
def reachable ret = []
|
|
||||||
add_next ret
|
|
||||||
add_branch ret
|
|
||||||
ret
|
|
||||||
end
|
|
||||||
|
|
||||||
def add_code kode
|
def add_code kode
|
||||||
@codes << kode
|
@codes << kode
|
||||||
self
|
self
|
||||||
@ -73,20 +67,24 @@ module Virtual
|
|||||||
@codes.inject(0){|count , instruction| count += instruction.byte_length }
|
@codes.inject(0){|count , instruction| count += instruction.byte_length }
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
# def reachable ret = []
|
||||||
# helper for determining reachable blocks
|
# add_next ret
|
||||||
def add_next ret
|
# add_branch ret
|
||||||
return if @next.nil?
|
# ret
|
||||||
return if ret.include? @next
|
# end
|
||||||
ret << @next
|
# # helper for determining reachable blocks
|
||||||
@next.reachable ret
|
# def add_next ret
|
||||||
end
|
# return if @next.nil?
|
||||||
# helper for determining reachable blocks
|
# return if ret.include? @next
|
||||||
def add_branch ret
|
# ret << @next
|
||||||
return if @branch.nil?
|
# @next.reachable ret
|
||||||
return if ret.include? @branch
|
# end
|
||||||
ret << @branch
|
# # helper for determining reachable blocks
|
||||||
@branch.reachable ret
|
# def add_branch ret
|
||||||
end
|
# return if @branch.nil?
|
||||||
|
# return if ret.include? @branch
|
||||||
|
# ret << @branch
|
||||||
|
# @branch.reachable ret
|
||||||
|
# end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
require_relative "test_foo"
|
require_relative "test_foo"
|
||||||
require_relative "test_if"
|
require_relative "test_if"
|
||||||
require_relative "test_hello"
|
require_relative "test_hello"
|
||||||
|
require_relative "test_class"
|
||||||
require_relative "test_putint"
|
require_relative "test_putint"
|
||||||
require_relative "test_functions"
|
require_relative "test_functions"
|
||||||
require_relative "test_recursive_fibo"
|
require_relative "test_recursive_fibo"
|
||||||
|
21
test/fragments/test_class.rb
Normal file
21
test/fragments/test_class.rb
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
require_relative 'helper'
|
||||||
|
|
||||||
|
class TestBasicClass < MiniTest::Test
|
||||||
|
include Fragments
|
||||||
|
|
||||||
|
def test_class_basic
|
||||||
|
@string_input = <<HERE
|
||||||
|
module Foo
|
||||||
|
class Bar
|
||||||
|
int buh()
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
HERE
|
||||||
|
@expect = [ Virtual::Return ]
|
||||||
|
check
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
end
|
@ -5,6 +5,16 @@ class TestList < MiniTest::Test
|
|||||||
def setup
|
def setup
|
||||||
@list = ::Parfait::List.new
|
@list = ::Parfait::List.new
|
||||||
end
|
end
|
||||||
|
def test_list_inspect
|
||||||
|
@list.set(1,1)
|
||||||
|
assert_equal "1" , @list.inspect
|
||||||
|
end
|
||||||
|
def test_list_equal
|
||||||
|
@list.set(1,1)
|
||||||
|
list = ::Parfait::List.new
|
||||||
|
list.set(1,1)
|
||||||
|
assert @list.equal? list
|
||||||
|
end
|
||||||
def test_list_create
|
def test_list_create
|
||||||
assert @list.empty?
|
assert @list.empty?
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user