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
|
||||
# But in the future (in the one that holds great things) we optimize those unneccesay moves away
|
||||
|
||||
# attr_reader :value
|
||||
def on_int expression
|
||||
int = expression.first
|
||||
to = Virtual::Return.new(Virtual::Integer , int)
|
||||
@ -37,15 +36,6 @@ module Bosl
|
||||
to
|
||||
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
|
||||
# Clearly a TODO here to implement strings rather than reusing symbols
|
||||
value = expression.first.to_sym
|
||||
@ -54,23 +44,5 @@ module Bosl
|
||||
method.source.add_code Virtual::Set.new( value , to )
|
||||
to
|
||||
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
|
||||
|
@ -3,14 +3,11 @@ module Bosl
|
||||
|
||||
# attr_reader :values
|
||||
def on_array expession, context
|
||||
raise "not implemented"
|
||||
end
|
||||
# attr_reader :key , :value
|
||||
def on_association context
|
||||
raise "not implemented"
|
||||
end
|
||||
def on_hash context
|
||||
raise "not implemented"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -2,7 +2,8 @@ module Bosl
|
||||
Compiler.class_eval do
|
||||
# module attr_reader :name ,:expressions
|
||||
def on_module expression
|
||||
return clazz
|
||||
name , rest = *expression
|
||||
return process_all(rest).last
|
||||
end
|
||||
|
||||
def on_class expression
|
||||
|
@ -129,7 +129,7 @@ module Parfait
|
||||
internal_object_shrink(len + 1)
|
||||
end
|
||||
|
||||
def ==(other)
|
||||
def equal?(other)
|
||||
# this should call parfait get_class, alas that is not implemented yet
|
||||
return false if other.class != self.class
|
||||
return false if other.get_length != self.get_length
|
||||
|
@ -21,12 +21,6 @@ module Virtual
|
||||
attr_reader :name , :codes , :method , :position
|
||||
attr_accessor :branch
|
||||
|
||||
def reachable ret = []
|
||||
add_next ret
|
||||
add_branch ret
|
||||
ret
|
||||
end
|
||||
|
||||
def add_code kode
|
||||
@codes << kode
|
||||
self
|
||||
@ -73,20 +67,24 @@ module Virtual
|
||||
@codes.inject(0){|count , instruction| count += instruction.byte_length }
|
||||
end
|
||||
|
||||
private
|
||||
# helper for determining reachable blocks
|
||||
def add_next ret
|
||||
return if @next.nil?
|
||||
return if ret.include? @next
|
||||
ret << @next
|
||||
@next.reachable ret
|
||||
end
|
||||
# helper for determining reachable blocks
|
||||
def add_branch ret
|
||||
return if @branch.nil?
|
||||
return if ret.include? @branch
|
||||
ret << @branch
|
||||
@branch.reachable ret
|
||||
end
|
||||
# def reachable ret = []
|
||||
# add_next ret
|
||||
# add_branch ret
|
||||
# ret
|
||||
# end
|
||||
# # helper for determining reachable blocks
|
||||
# def add_next ret
|
||||
# return if @next.nil?
|
||||
# return if ret.include? @next
|
||||
# ret << @next
|
||||
# @next.reachable ret
|
||||
# end
|
||||
# # helper for determining reachable blocks
|
||||
# def add_branch ret
|
||||
# return if @branch.nil?
|
||||
# return if ret.include? @branch
|
||||
# ret << @branch
|
||||
# @branch.reachable ret
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
@ -2,6 +2,7 @@
|
||||
require_relative "test_foo"
|
||||
require_relative "test_if"
|
||||
require_relative "test_hello"
|
||||
require_relative "test_class"
|
||||
require_relative "test_putint"
|
||||
require_relative "test_functions"
|
||||
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
|
||||
@list = ::Parfait::List.new
|
||||
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
|
||||
assert @list.empty?
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user