several larger changes came together, bit of cleaning too

- all code must be in functions (which must be in classes).
— changes a fair few tests
— also changes api, as method is not recursive, not passed around
- all state in instance vars in compiler (no accessors)
- class is another such variable, surely more coming
all green again
This commit is contained in:
Torsten Ruger
2015-10-06 00:27:13 +03:00
parent 3d36fd1746
commit f4a4ccb98e
37 changed files with 302 additions and 205 deletions

View File

@ -1,6 +1,6 @@
module Bosl
Compiler.class_eval do
# function attr_reader :name, :params, :body , :receiver
def on_function expression
#puts expression.inspect
return_type , name , parameters, kids , receiver = *expression
@ -24,23 +24,30 @@ module Bosl
end
end
else
r = Virtual::Self.new(:int)
class_name = method.for_class.name
r = @clazz
class_name = @clazz.name
end
new_method = Virtual::MethodSource.create_method(class_name, return_type, name , args )
new_method.source.receiver = r
new_method.for_class.add_instance_method new_method
raise "Already in method #{@method}" if @method
@method = @clazz.get_instance_method( name )
if(@method)
puts "Warning, redefining method #{name}" unless name == :main
#TODO check args / type compatibility
@method.source.init @method
else
@method = Virtual::MethodSource.create_method(class_name, return_type, name , args )
@method.for_class.add_instance_method @method
end
@method.source.receiver = r
puts "compile method #{@method.name}"
old_method = @method
@method = new_method
#frame = frame.new_frame
kids.to_a.each do |ex|
return_type = process(ex)
raise return_type.inspect if return_type.is_a? Virtual::Instruction
end
@method = old_method
new_method.source.return_type = return_type
@method.source.return_type = return_type
@method = nil
Virtual::Return.new(return_type)
end
end