remove unknown type

This commit is contained in:
Torsten Ruger 2015-09-23 18:35:37 +03:00
parent 4b613fb632
commit 9fe01c7b31
15 changed files with 49 additions and 38 deletions

View File

@ -8,13 +8,13 @@ module Bosl
if receiver
me = process( receiver.to_a.first )
else
me = Virtual::Self.new
me = Virtual::Self.new :int
end
## need two step process, compile and save to frame
# then move from frame to new message
method.source.add_code Virtual::NewMessage.new
method.source.add_code Virtual::Set.new( me , Virtual::NewSelf.new(me.type))
method.source.add_code Virtual::Set.new( name.to_sym , Virtual::NewMessageName.new())
method.source.add_code Virtual::Set.new( name.to_sym , Virtual::NewMessageName.new(:int))
compiled_args = []
arguments.to_a.each_with_index do |arg , i|
#compile in the running method, ie before passing control

View File

@ -24,10 +24,10 @@ module Bosl
end
end
else
r = Virtual::Self.new()
r = Virtual::Self.new(:int)
class_name = method.for_class.name
end
new_method = Virtual::MethodSource.create_method(class_name, name , args )
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

View File

@ -9,12 +9,12 @@ module Bosl
name = expression.to_a.first
return Virtual::Self.new( Virtual::Reference.new(method.for_class)) if name == :self
# either an argument, so it's stored in message
ret = Virtual::Return.new
ret = Virtual::Return.new :int
if( index = method.has_arg(name))
method.source.add_code Virtual::Set.new( Virtual::ArgSlot.new(index ) , ret)
method.source.add_code Virtual::Set.new( Virtual::ArgSlot.new(:int,index ) , ret)
else # or a local so it is in the frame
index = method.ensure_local( name )
method.source.add_code Virtual::Set.new(Virtual::FrameSlot.new(index ) , ret )
method.source.add_code Virtual::Set.new(Virtual::FrameSlot.new(:int,index ) , ret )
end
return ret
end

View File

@ -3,7 +3,7 @@ module Bosl
# operator attr_reader :operator, :left, :right
def on_operator expression
operator , left , right = *expression
Virtual::Return.new()
Virtual::Return.new(:int)
end
def on_assign expression
@ -11,7 +11,7 @@ module Bosl
name = name.to_a.first
v = process(value)
index = method.ensure_local( name )
method.source.add_code Virtual::Set.new(Virtual::FrameSlot.new(index ) , v )
method.source.add_code Virtual::Set.new(Virtual::FrameSlot.new(:int,index ) , v )
end
end

View File

@ -4,7 +4,7 @@ module Register
module Integer
module ClassMethods
def plus c
plus_function = Virtual::MethodSource.create_method(:Integer,:plus , [:Integer] )
plus_function = Virtual::MethodSource.create_method(:Integer,:int,:plus , [:Integer] )
plus_function.source.return_type = Virtual::Integer
plus_function.source.receiver = Virtual::Integer
@ -43,7 +43,7 @@ module Register
# end
def putint context
putint_function = Virtual::MethodSource.create_method(:Integer,:putint , [] )
putint_function = Virtual::MethodSource.create_method(:Integer,:int,:putint , [] )
putint_function.source.return_type = Virtual::Integer
putint_function.source.receiver = Virtual::Integer
return putint_function
@ -72,7 +72,7 @@ module Register
# a hand coded version of the fibonachi numbers
# 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,:fibo , [] )
fibo_function = Virtual::MethodSource.create_method(:Integer,:int,:fibo , [] )
fibo_function.source.return_type = Virtual::Integer
fibo_function.source.receiver = Virtual::Integer
return fibo_function

View File

@ -6,7 +6,7 @@ module Register
# it isn't really a function, ie it is jumped to (not called), exits and may not return
# so it is responsible for initial setup
def __init__ context
function = Virtual::MethodSource.create_method(:Kernel,:__init__ , [])
function = Virtual::MethodSource.create_method(:Kernel,:int,:__init__ , [])
function.source.return_type = Virtual::Integer
# no method enter or return (automatically added), remove
function.source.blocks.first.codes.pop # no Method enter
@ -25,7 +25,7 @@ module Register
return function
end
def exit context
function = Virtual::MethodSource.create_method(:Kernel,:exit , [])
function = Virtual::MethodSource.create_method(:Kernel,:int,:exit , [])
function.source.return_type = Virtual::Integer
return function
ret = Virtual::RegisterMachine.instance.exit(function)
@ -33,7 +33,7 @@ module Register
function
end
def __send context
function = Virtual::MethodSource.create_method(:Kernel ,:__send , [] )
function = Virtual::MethodSource.create_method(:Kernel,:int ,:__send , [] )
function.source.return_type = Virtual::Integer
return function
end

View File

@ -6,7 +6,7 @@ module Register
# main entry point, ie __init__ calls this
# defined here as empty, to be redefined
def main context
function = Virtual::MethodSource.create_method(:Object,:main , [])
function = Virtual::MethodSource.create_method(:Object, :int , :main , [])
return function
end
@ -18,7 +18,7 @@ module Register
# The at_index is just "below" the api, something we need but don't want to expose,
# so we can't code the above in ruby
def _get_instance_variable context , name = Virtual::Integer
get_function = Virtual::MethodSource.create_method(:Object,:_get_instance_variable , [ ] )
get_function = Virtual::MethodSource.create_method(:Object,:int, :_get_instance_variable , [ ] )
return get_function
# me = get_function.receiver
# var_name = get_function.args.first
@ -39,7 +39,7 @@ module Register
end
def _set_instance_variable(context , name = Virtual::Integer , value = Virtual::Integer )
set_function = Virtual::MethodSource.create_method(:Object,:_set_instance_variable ,[] )
set_function = Virtual::MethodSource.create_method(:Object,:int,:_set_instance_variable ,[] )
return set_function
# receiver set_function
# me = set_function.receiver

View File

@ -3,7 +3,7 @@ module Register
module Word
module ClassMethods
def putstring context
function = Virtual::MethodSource.create_method(:Word , :putstring , [] )
function = Virtual::MethodSource.create_method(:Word,:int , :putstring , [] )
Kernel.emit_syscall( function , :putstring )
function
end

View File

@ -34,17 +34,18 @@ module Virtual
# second, it creates MethodSource and attaches it to the method
#
# compile code then works with the method, but adds code tot the info
def self.create_method( class_name , method_name , args)
def self.create_method( class_name , return_type , method_name , args)
raise "create_method #{class_name}.#{class_name.class}" unless class_name.is_a? Symbol
raise "create_method #{method_name}.#{method_name.class}" unless method_name.is_a? Symbol
clazz = Virtual.machine.space.get_class_by_name class_name
raise "No such class #{class_name}" unless clazz
return_type = Virtual::Type.from_sym return_type
method = clazz.create_instance_method( method_name , Virtual.new_list(args))
method.source = MethodSource.new(method)
method.source = MethodSource.new(method , return_type)
method
end
# just passing the method object in for Instructions to make decisions (later)
def initialize method , return_type = Virtual::Unknown
def initialize method , return_type
# 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

View File

@ -4,7 +4,7 @@ module Virtual
# Slots in the Frame are local or temporary variables in a message
class FrameSlot < Slot
def initialize index , type = Unknown, value = nil
def initialize index , type , value = nil
super(type, value)
@index = index
end

View File

@ -7,7 +7,7 @@ module Virtual
# The Message has a layout as per the constant above
class MessageSlot < Slot
def initialize type = Unknown , value = nil
def initialize type , value = nil
super(type , value )
end
def object_name
@ -19,28 +19,28 @@ module Virtual
# Return is the return of MessageSlot
class Return < MessageSlot
def initialize type = Unknown, value = nil
def initialize type , value = nil
super( type , value )
end
end
# Self is the self in MessageSlot
class Self < MessageSlot
def initialize type = Unknown, value = nil
def initialize type , value = nil
super( type , value )
end
end
# MessageName of the current message
class MessageName < MessageSlot
def initialize type = Unknown, value = nil
def initialize type , value = nil
super( type , value )
end
end
# NewMessageName of the next message
class ArgSlot < MessageSlot
def initialize index , type = Unknown, value = nil
def initialize index , type , value = nil
@index = index
super( type , value )
end

View File

@ -7,7 +7,7 @@ module Virtual
# The Message has a layout as per the constant above
class NewMessageSlot < Slot
def initialize type = Unknown, value = nil
def initialize type , value = nil
super( type , value )
end
def object_name
@ -19,28 +19,28 @@ module Virtual
# NewReturn is the return of NewMessageSlot
class NewReturn < NewMessageSlot
def initialize type = Unknown, value = nil
def initialize type , value = nil
super( type , value )
end
end
# NewSelf is the self of NewMessageSlot
class NewSelf < NewMessageSlot
def initialize type = Unknown, value = nil
def initialize type , value = nil
super( type , value )
end
end
# NewMessageName of the next message
class NewMessageName < NewMessageSlot
def initialize type = Unknown, value = nil
def initialize type , value = nil
super( type , value )
end
end
# NewMessageName of the next message
class NewArgSlot < NewMessageSlot
def initialize index , type = Unknown, value = nil
def initialize index , type , value = nil
@index = index
super( type , value )
end

View File

@ -14,7 +14,7 @@ module Virtual
# that object
#
class SelfSlot < Slot
def initialize type = Unknown, value = nil
def initialize type , value = nil
super
end
def object_name

View File

@ -7,6 +7,19 @@ module Virtual
return false unless other.class == self.class
return true
end
# map from a type sym (currently :int/:ref) to a class of subtype of Type
# TODO needs to be made extensible in a defined way.
def self.from_sym type
case type
when :int
Virtual::Integer
when :ref
Virtual::Reference
else
raise "No type maps to:#{type}"
end
end
end
class Integer < Type
@ -20,7 +33,4 @@ module Virtual
attr_reader :of_class
end
class Unknown < Type
end
end

View File

@ -36,7 +36,7 @@ class TestBasic < MiniTest::Test
def test_name
@string_input = 'foo '
@output = "- Virtual::Return(:type => Virtual::Unknown)"
@output = "- Virtual::Return(:type => :int)"
check
end