add FunctionCall instruction and the missing puts (stub)

This commit is contained in:
Torsten Ruger 2014-08-22 15:08:46 +03:00
parent e19b7be111
commit 91ce05364a
7 changed files with 20 additions and 5 deletions

View File

@ -58,7 +58,7 @@ module Boot
obj.add_method_definition Salama::Kernel.send(f , @context)
end
obj = get_or_create_class :String
[:get , :set].each do |f|
[:get , :set , :puts].each do |f|
#puts "Boot String::#{f}"
obj.add_method_definition Boot::String.send(f , @context)
end

View File

@ -9,6 +9,10 @@ module Boot
set_function = Virtual::MethodDefinition.new(:set , [Virtual::Integer, Virtual::Integer] , Virtual::Integer ,Virtual::Integer )
return set_function
end
def puts context
puts_function = Virtual::MethodDefinition.new(:puts , [] )
return puts_function
end
end
extend ClassMethods
end

View File

@ -9,6 +9,10 @@ module Boot
set_function = Virtual::Function.new(:set , Virtual::Integer ,[Virtual::Integer, Virtual::Integer] , Virtual::Integer )
return set_function
end
def puts context
puts_function = Virtual::Function.new(:puts , Virtual::Integer ,[] , Virtual::Reference )
return puts_function
end
end
extend ClassMethods
end

View File

@ -15,8 +15,9 @@ module Trickle
elsif( me.is_a? Virtual::ObjectConstant )
clazz = me.clazz
method = clazz.get_method_definition code.name
puts "Found me a method #{method}"
raise "Method not implemented #{clazz.name}.#{code.name}" unless method
call = Virtual::FunctionCall.new( method )
block.replace(code , [call] )
else
raise "unimplemented"
end

View File

@ -34,7 +34,7 @@ module Virtual
end
# replace a code with an array of new codes. This is what happens in passes all the time
def replace_with code , new_codes
def replace code , new_codes
index = @codes.index code
raise "Code not found #{code} in #{self}" unless index
@codes.delete_at(index)

View File

@ -75,6 +75,13 @@ module Virtual
attr_reader :name , :me , :args
end
class FunctionCall < Instruction
def initialize method
@method = method
end
attr_reader :method
end
# class for Set instructions, A set is basically a mem move.
# to and from are indexes into the known objects(frame,message,self and new_message), or from may be a constant
class Set < Instruction

View File

@ -7,9 +7,8 @@ class HelloTest < MiniTest::Test
machine = Virtual::Machine.boot
expressions = machine.compile_main @string_input
puts ""
puts Sof::Writer.write(expressions)
Virtual::Object.space.run_passes
puts ""
puts Sof::Writer.write(expressions)
# puts Sof::Writer.write(Virtual::Object.space)
end