checking return type is a type
This commit is contained in:
parent
e33a20dd41
commit
d899d542a4
@ -56,7 +56,7 @@ module Phisol
|
|||||||
raise "unimplemented: \n#{code} \nfor #{ref.inspect}"
|
raise "unimplemented: \n#{code} \nfor #{ref.inspect}"
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if( me.type == :int)
|
if( me.type.is_a? Phisol::Integer)
|
||||||
name = :plus if name == :+
|
name = :plus if name == :+
|
||||||
method = Virtual.machine.space.get_class_by_name(:Integer).get_instance_method(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
|
||||||
|
@ -40,13 +40,10 @@ module Phisol
|
|||||||
@method.source.receiver = r
|
@method.source.receiver = r
|
||||||
puts "compile method #{@method.name}"
|
puts "compile method #{@method.name}"
|
||||||
|
|
||||||
|
|
||||||
#frame = frame.new_frame
|
|
||||||
kids.to_a.each do |ex|
|
kids.to_a.each do |ex|
|
||||||
return_type = process(ex)
|
ret = process(ex)
|
||||||
raise return_type.inspect if return_type.is_a? Virtual::Instruction
|
raise ret.inspect if ret.is_a? Virtual::Instruction
|
||||||
end
|
end
|
||||||
@method.source.return_type = return_type
|
|
||||||
@method = nil
|
@method = nil
|
||||||
Virtual::Return.new(return_type)
|
Virtual::Return.new(return_type)
|
||||||
end
|
end
|
||||||
|
@ -5,7 +5,7 @@ module Register
|
|||||||
module ClassMethods
|
module ClassMethods
|
||||||
def plus c
|
def plus c
|
||||||
plus_function = Virtual::MethodSource.create_method(:Integer,:int,:plus , [:int] )
|
plus_function = Virtual::MethodSource.create_method(:Integer,:int,:plus , [:int] )
|
||||||
plus_function.source.return_type = Phisol::Type.int
|
plus_function.source.set_return_type Phisol::Type.int
|
||||||
plus_function.source.receiver = Phisol::Integer
|
plus_function.source.receiver = Phisol::Integer
|
||||||
|
|
||||||
tmp = Register.tmp_reg :int
|
tmp = Register.tmp_reg :int
|
||||||
@ -44,7 +44,7 @@ module Register
|
|||||||
|
|
||||||
def putint context
|
def putint context
|
||||||
putint_function = Virtual::MethodSource.create_method(:Integer,:int,:putint , [] )
|
putint_function = Virtual::MethodSource.create_method(:Integer,:int,:putint , [] )
|
||||||
putint_function.source.return_type = Phisol::Type.int
|
putint_function.source.set_return_type Phisol::Type.int
|
||||||
putint_function.source.receiver = Phisol::Integer
|
putint_function.source.receiver = Phisol::Integer
|
||||||
return putint_function
|
return putint_function
|
||||||
# buffer = Parfait::Word.new(" ") # create a buffer
|
# buffer = Parfait::Word.new(" ") # create a buffer
|
||||||
@ -73,7 +73,7 @@ module Register
|
|||||||
# not my hand off course, found in the net http://www.peter-cockerell.net/aalp/html/ch-5.html
|
# not my hand off course, found in the net http://www.peter-cockerell.net/aalp/html/ch-5.html
|
||||||
def fibo context
|
def fibo context
|
||||||
fibo_function = Virtual::MethodSource.create_method(:Integer,:int,:fibo , [] )
|
fibo_function = Virtual::MethodSource.create_method(:Integer,:int,:fibo , [] )
|
||||||
fibo_function.source.return_type = Phisol::Type.int
|
fibo_function.source.set_return_type Phisol::Type.int
|
||||||
fibo_function.source.receiver = Phisol::Integer
|
fibo_function.source.receiver = Phisol::Integer
|
||||||
return fibo_function
|
return fibo_function
|
||||||
# result = fibo_function.return_type
|
# result = fibo_function.return_type
|
||||||
|
@ -7,7 +7,7 @@ module Register
|
|||||||
# so it is responsible for initial setup
|
# so it is responsible for initial setup
|
||||||
def __init__ context
|
def __init__ context
|
||||||
function = Virtual::MethodSource.create_method(:Kernel,:int,:__init__ , [])
|
function = Virtual::MethodSource.create_method(:Kernel,:int,:__init__ , [])
|
||||||
function.source.return_type = Phisol::Type.int
|
function.source.set_return_type Phisol::Type.int
|
||||||
# no method enter or return (automatically added), remove
|
# no method enter or return (automatically added), remove
|
||||||
function.source.blocks.first.codes.pop # no Method enter
|
function.source.blocks.first.codes.pop # no Method enter
|
||||||
function.source.blocks.last.codes.pop # no Method return
|
function.source.blocks.last.codes.pop # no Method return
|
||||||
@ -26,7 +26,7 @@ module Register
|
|||||||
end
|
end
|
||||||
def exit context
|
def exit context
|
||||||
function = Virtual::MethodSource.create_method(:Kernel,:int,:exit , [])
|
function = Virtual::MethodSource.create_method(:Kernel,:int,:exit , [])
|
||||||
function.source.return_type = Phisol::Type.int
|
function.source.set_return_type Phisol::Type.int
|
||||||
return function
|
return function
|
||||||
ret = Virtual::RegisterMachine.instance.exit(function)
|
ret = Virtual::RegisterMachine.instance.exit(function)
|
||||||
function.set_return ret
|
function.set_return ret
|
||||||
@ -34,7 +34,7 @@ module Register
|
|||||||
end
|
end
|
||||||
def __send context
|
def __send context
|
||||||
function = Virtual::MethodSource.create_method(:Kernel,:int ,:__send , [] )
|
function = Virtual::MethodSource.create_method(:Kernel,:int ,:__send , [] )
|
||||||
function.source.return_type = Phisol::Type.int
|
function.source.set_return_type Phisol::Type.int
|
||||||
return function
|
return function
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -58,15 +58,20 @@ module Virtual
|
|||||||
def init method , return_type = nil
|
def init method , return_type = nil
|
||||||
# first block we have to create with .new , as new_block assumes a current
|
# first block we have to create with .new , as new_block assumes a current
|
||||||
enter = Block.new( "enter" , method ).add_code(MethodEnter.new( method ))
|
enter = Block.new( "enter" , method ).add_code(MethodEnter.new( method ))
|
||||||
@return_type = return_type if return_type
|
set_return_type( return_type )
|
||||||
@blocks = [enter]
|
@blocks = [enter]
|
||||||
@current = enter
|
@current = enter
|
||||||
new_block("return").add_code(MethodReturn.new(method))
|
new_block("return").add_code(MethodReturn.new(method))
|
||||||
@constants = []
|
@constants = []
|
||||||
end
|
end
|
||||||
attr_reader :blocks , :constants
|
attr_reader :blocks , :constants , :return_type
|
||||||
attr_accessor :return_type , :current , :receiver
|
attr_accessor :current , :receiver
|
||||||
|
|
||||||
|
def set_return_type type
|
||||||
|
return if type.nil?
|
||||||
|
raise "not type #{type}" unless type.is_a? Phisol::Type
|
||||||
|
@return_type = type
|
||||||
|
end
|
||||||
# add an instruction after the current (insertion point)
|
# add an instruction after the current (insertion point)
|
||||||
# the added instruction will become the new insertion point
|
# the added instruction will become the new insertion point
|
||||||
def add_code instruction
|
def add_code instruction
|
||||||
|
Loading…
x
Reference in New Issue
Block a user