diff --git a/lib/bosl/compiler/basic_expressions.rb b/lib/bosl/compiler/basic_expressions.rb index bdcc469f..ce4b4426 100644 --- a/lib/bosl/compiler/basic_expressions.rb +++ b/lib/bosl/compiler/basic_expressions.rb @@ -11,66 +11,38 @@ 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) - method.source.add_code Virtual::Set.new( int , to ) - to - end + def on_int expression + int = expression.first + to = Virtual::Return.new(Virtual::Integer , int) + method.source.add_code Virtual::Set.new( int , to ) + to + end - def on_true expression - to = Virtual::Return.new(Virtual::Reference , true ) - method.source.add_code Virtual::Set.new( true , to ) - to - end + def on_true expression + to = Virtual::Return.new(Virtual::Reference , true ) + method.source.add_code Virtual::Set.new( true , to ) + to + end - def on_false expression - to = Virtual::Return.new(Virtual::Reference , false) - method.source.add_code Virtual::Set.new( false , to ) - to - end + def on_false expression + to = Virtual::Return.new(Virtual::Reference , false) + method.source.add_code Virtual::Set.new( false , to ) + to + end - def on_nil expression - to = Virtual::Return.new(Virtual::Reference , nil) - method.source.add_code Virtual::Set.new( nil , to ) - 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 - to = Virtual::Return.new(Virtual::Reference , value) - method.source.constants << value - 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 + def on_nil expression + to = Virtual::Return.new(Virtual::Reference , nil) + method.source.add_code Virtual::Set.new( nil , to ) + to + end + def on_string expression + # Clearly a TODO here to implement strings rather than reusing symbols + value = expression.first.to_sym + to = Virtual::Return.new(Virtual::Reference , value) + method.source.constants << value + method.source.add_code Virtual::Set.new( value , to ) + to + end end end diff --git a/lib/bosl/compiler/compound_expressions.rb b/lib/bosl/compiler/compound_expressions.rb index c7c4051c..960dd640 100644 --- a/lib/bosl/compiler/compound_expressions.rb +++ b/lib/bosl/compiler/compound_expressions.rb @@ -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 diff --git a/lib/bosl/compiler/module_expression.rb b/lib/bosl/compiler/module_expression.rb index 93dcae7c..53f05b1a 100644 --- a/lib/bosl/compiler/module_expression.rb +++ b/lib/bosl/compiler/module_expression.rb @@ -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 diff --git a/lib/parfait/list.rb b/lib/parfait/list.rb index 15eef3cb..78fb8b4a 100644 --- a/lib/parfait/list.rb +++ b/lib/parfait/list.rb @@ -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 diff --git a/lib/virtual/block.rb b/lib/virtual/block.rb index b22e01bc..ec8718c3 100644 --- a/lib/virtual/block.rb +++ b/lib/virtual/block.rb @@ -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 diff --git a/test/fragments/test_all.rb b/test/fragments/test_all.rb index df406310..bc7bc9d5 100644 --- a/test/fragments/test_all.rb +++ b/test/fragments/test_all.rb @@ -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" diff --git a/test/fragments/test_class.rb b/test/fragments/test_class.rb new file mode 100644 index 00000000..6a260530 --- /dev/null +++ b/test/fragments/test_class.rb @@ -0,0 +1,21 @@ +require_relative 'helper' + +class TestBasicClass < MiniTest::Test + include Fragments + + def test_class_basic + @string_input = <