type now means class name
update reader (with new type definition) remove type class (now symbol) update all types to class name symbols
This commit is contained in:
@ -55,7 +55,6 @@ module Phisol
|
||||
end
|
||||
end
|
||||
|
||||
require_relative "type"
|
||||
require_relative "ast_helper"
|
||||
require_relative "compiler/basic_values"
|
||||
require_relative "compiler/call_site"
|
||||
|
@ -19,26 +19,26 @@ module Phisol
|
||||
end
|
||||
|
||||
def on_true statement
|
||||
reg = use_reg :ref
|
||||
reg = use_reg :Boolean
|
||||
@method.source.add_code Register::LoadConstant.new( statement, true , reg )
|
||||
return reg
|
||||
end
|
||||
|
||||
def on_false statement
|
||||
reg = use_reg :ref
|
||||
reg = use_reg :Boolean
|
||||
@method.source.add_code Register::LoadConstant.new( statement, false , reg )
|
||||
return reg
|
||||
end
|
||||
|
||||
def on_nil statement
|
||||
reg = use_reg :ref
|
||||
reg = use_reg :NilClass
|
||||
@method.source.add_code Register::LoadConstant.new( statement, nil , reg )
|
||||
return reg
|
||||
end
|
||||
|
||||
def on_string statement
|
||||
value = statement.first.to_sym
|
||||
reg = use_reg :ref
|
||||
reg = use_reg :Word
|
||||
@method.source.constants << value
|
||||
@method.source.add_code Register::LoadConstant.new( statement, value , reg )
|
||||
return reg
|
||||
|
@ -9,12 +9,7 @@ module Phisol
|
||||
if receiver
|
||||
me = process( receiver.to_a.first )
|
||||
else
|
||||
if @method.for_class.name == :Integer
|
||||
type = :int
|
||||
else
|
||||
type = :ref
|
||||
end
|
||||
me = Register.self_reg type
|
||||
me = Register.self_reg @method.for_class.name
|
||||
end
|
||||
#move the new message (that we need to populate to make a call) to std register
|
||||
new_message = Register.resolve_to_register(:new_message)
|
||||
@ -22,7 +17,7 @@ module Phisol
|
||||
# move our receiver there
|
||||
@method.source.add_code Register.set_slot( statement , me , :new_message , :receiver)
|
||||
# load method name and set to new message (for exceptions/debug)
|
||||
name_tmp = use_reg(:ref)
|
||||
name_tmp = use_reg(:Word)
|
||||
@method.source.add_code Register::LoadConstant.new(statement, name , name_tmp)
|
||||
@method.source.add_code Register.set_slot( statement , name_tmp , :new_message , :name)
|
||||
# next arguments. reset tmp regs for each and load result into new_message
|
||||
@ -56,17 +51,12 @@ module Phisol
|
||||
raise "unimplemented: \n#{code} \nfor #{ref.inspect}"
|
||||
end
|
||||
else
|
||||
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
|
||||
raise "Method not implemented Integer.#{name}" unless method
|
||||
@method.source.add_code Virtual::MethodCall.new( method )
|
||||
else
|
||||
method = @clazz.get_instance_method(name)
|
||||
raise "Method not implemented #{@clazz.name}.#{name}" unless method
|
||||
@method.source.add_code Virtual::MethodCall.new( method )
|
||||
end
|
||||
clazz = Virtual.machine.space.get_class_by_name(me.type)
|
||||
raise "No such class #{me.type}" unless clazz
|
||||
method = clazz.get_instance_method(name)
|
||||
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 )
|
||||
end
|
||||
raise "Method not implemented #{me.value}.#{name}" unless method
|
||||
ret = use_reg( method.source.return_type )
|
||||
|
@ -7,7 +7,7 @@ module Phisol
|
||||
# whichever way this goes the result is stored in the return slot (as all compiles)
|
||||
def on_name statement
|
||||
name = statement.to_a.first
|
||||
return Virtual::Self.new( Phisol::Reference.new(@clazz)) if name == :self
|
||||
return Virtual::Self.new( @clazz) if name == :self
|
||||
# either an argument, so it's stored in message
|
||||
if( index = @method.has_arg(name))
|
||||
type = @method.arguments[index].type
|
||||
|
@ -1,44 +0,0 @@
|
||||
|
||||
module Phisol
|
||||
# Integer and (Object) References are the main derived classes, but float will come.
|
||||
|
||||
class Type
|
||||
def == other
|
||||
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
|
||||
return type if type.is_a? Type
|
||||
case type
|
||||
when :int
|
||||
self.int
|
||||
when :ref
|
||||
self.ref
|
||||
else
|
||||
raise "No type maps to:#{type} (#{type.class})"
|
||||
end
|
||||
end
|
||||
|
||||
def self.int
|
||||
return Integer.new
|
||||
end
|
||||
def self.ref
|
||||
return Reference.new
|
||||
end
|
||||
end
|
||||
|
||||
class Integer < Type
|
||||
end
|
||||
|
||||
class Reference < Type
|
||||
# possibly unknown value, but known class (as in methods)
|
||||
def initialize clazz = nil
|
||||
@of_class = clazz
|
||||
end
|
||||
attr_reader :of_class
|
||||
end
|
||||
|
||||
end
|
Reference in New Issue
Block a user