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}"
|
||||
end
|
||||
else
|
||||
if( me.type == :int)
|
||||
if( me.type.is_a? Phisol::Integer)
|
||||
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
|
||||
|
@ -40,13 +40,10 @@ module Phisol
|
||||
@method.source.receiver = r
|
||||
puts "compile method #{@method.name}"
|
||||
|
||||
|
||||
#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
|
||||
ret = process(ex)
|
||||
raise ret.inspect if ret.is_a? Virtual::Instruction
|
||||
end
|
||||
@method.source.return_type = return_type
|
||||
@method = nil
|
||||
Virtual::Return.new(return_type)
|
||||
end
|
||||
|
@ -5,7 +5,7 @@ module Register
|
||||
module ClassMethods
|
||||
def plus c
|
||||
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
|
||||
|
||||
tmp = Register.tmp_reg :int
|
||||
@ -44,7 +44,7 @@ module Register
|
||||
|
||||
def putint context
|
||||
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
|
||||
return putint_function
|
||||
# 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
|
||||
def fibo context
|
||||
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
|
||||
return fibo_function
|
||||
# result = fibo_function.return_type
|
||||
|
@ -7,7 +7,7 @@ module Register
|
||||
# so it is responsible for initial setup
|
||||
def __init__ context
|
||||
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
|
||||
function.source.blocks.first.codes.pop # no Method enter
|
||||
function.source.blocks.last.codes.pop # no Method return
|
||||
@ -26,7 +26,7 @@ module Register
|
||||
end
|
||||
def exit context
|
||||
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
|
||||
ret = Virtual::RegisterMachine.instance.exit(function)
|
||||
function.set_return ret
|
||||
@ -34,7 +34,7 @@ module Register
|
||||
end
|
||||
def __send context
|
||||
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
|
||||
end
|
||||
|
||||
|
@ -58,15 +58,20 @@ module Virtual
|
||||
def init method , return_type = nil
|
||||
# first block we have to create with .new , as new_block assumes a current
|
||||
enter = Block.new( "enter" , method ).add_code(MethodEnter.new( method ))
|
||||
@return_type = return_type if return_type
|
||||
set_return_type( return_type )
|
||||
@blocks = [enter]
|
||||
@current = enter
|
||||
new_block("return").add_code(MethodReturn.new(method))
|
||||
@constants = []
|
||||
end
|
||||
attr_reader :blocks , :constants
|
||||
attr_accessor :return_type , :current , :receiver
|
||||
attr_reader :blocks , :constants , :return_type
|
||||
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)
|
||||
# the added instruction will become the new insertion point
|
||||
def add_code instruction
|
||||
|
Loading…
Reference in New Issue
Block a user