better calcite and operator to expand the interpreter test

This commit is contained in:
Torsten Ruger
2015-10-07 10:05:34 +03:00
parent af6366f2d1
commit 83ef902b55
6 changed files with 97 additions and 24 deletions

View File

@ -8,7 +8,11 @@ module Bosl
if receiver
me = process( receiver.to_a.first )
else
me = Virtual::Self.new :int
if @method.class.name == :Integer
me = Virtual::Self.new :int
else
me = Virtual::Self.new :ref
end
end
## need two step process, compile and save to frame
# then move from frame to new message
@ -39,17 +43,11 @@ module Bosl
raise "Method not implemented #{me.class}.#{code.name}" unless method
@method.source.add_code Virtual::MethodCall.new( method )
elsif( me.is_a? Fixnum )
name = :plus if name == :+
method = Virtual.machine.space.get_class_by_name(:Integer).get_instance_method(name)
puts Virtual.machine.space.get_class_by_name(:Integer).method_names.to_a
#puts Virtual.machine.space.get_class_by_name(:Integer).method_names.to_a
raise "Method not implemented Integer.#{name}" unless method
@method.source.add_code Virtual::MethodCall.new( method )
else
# note: this is the current view: call internal send, even the method name says else
# but send is "special" and accesses the internal method name and resolves.
kernel = Virtual.machine.space.get_class_by_name(:Kernel)
method = kernel.get_instance_method(:__send)
@method.source.add_code Virtual::MethodCall.new( method )
raise "unimplemented: \n#{code} \nfor #{ref.inspect}"
end
else
@ -60,7 +58,9 @@ module Bosl
raise "Method not implemented Integer.#{name}" unless method
@method.source.add_code Virtual::MethodCall.new( method )
else
raise "me #{me}"
method = @clazz.get_instance_method(name)
raise "Method not implemented Integer.#{name}" unless method
@method.source.add_code Virtual::MethodCall.new( method )
end
end
raise "Method not implemented #{me.value}.#{name}" unless method

View File

@ -1,10 +1,25 @@
module Bosl
Compiler.class_eval do
# operator attr_reader :operator, :left, :right
def on_operator expression
operator , left , right = *expression
#raise "not quite there"
Virtual::Return.new(:int)
puts "operator #{expression.inspect}"
operator , left_e , right_e = *expression
left_slot = process(left_e)
right_slot = process(right_e)
puts "left #{left_slot}"
puts "right #{right_slot}"
tmp1 = Register.tmp_reg
tmp2 = tmp1.next_reg_use
get = Register.get_slot_to(expression , left_slot , tmp1 )
get2 = Register.get_slot_to(expression , right_slot , tmp2 )
puts "GET #{get}"
puts "GET2 #{get2}"
@method.source.add_code get
@method.source.add_code get2
@method.source.add_code Register::OperatorInstruction.new(expression,operator, tmp1,tmp2)
Virtual::Return.new(:int )
end
def on_assign expression