namespace cleanup
remove unnecessary Virtual namespace prefix which was a large motivation for the move
This commit is contained in:
parent
de8fe46fe0
commit
d41676fdfd
@ -13,30 +13,30 @@ module Virtual
|
||||
|
||||
# attr_reader :value
|
||||
def self.compile_integer expression , method
|
||||
int = Virtual::IntegerConstant.new(expression.value)
|
||||
to = Virtual::Return.new(Virtual::Integer , int)
|
||||
method.add_code Virtual::Set.new( to , int)
|
||||
int = IntegerConstant.new(expression.value)
|
||||
to = Return.new(Integer , int)
|
||||
method.add_code Set.new( to , int)
|
||||
to
|
||||
end
|
||||
|
||||
def self.compile_true expression , method
|
||||
value = Virtual::TrueConstant.new
|
||||
to = Virtual::Return.new(Virtual::Reference , value)
|
||||
method.add_code Virtual::Set.new( to , value )
|
||||
value = TrueConstant.new
|
||||
to = Return.new(Reference , value)
|
||||
method.add_code Set.new( to , value )
|
||||
to
|
||||
end
|
||||
|
||||
def self.compile_false expression , method
|
||||
value = Virtual::FalseConstant.new
|
||||
to = Virtual::Return.new(Virtual::Reference , value)
|
||||
method.add_code Virtual::Set.new( to , value )
|
||||
value = FalseConstant.new
|
||||
to = Return.new(Reference , value)
|
||||
method.add_code Set.new( to , value )
|
||||
to
|
||||
end
|
||||
|
||||
def self.compile_nil expression , method
|
||||
value = Virtual::NilConstant.new
|
||||
to = Virtual::Return.new(Virtual::Reference , value)
|
||||
method.add_code Virtual::Set.new( to , value )
|
||||
value = NilConstant.new
|
||||
to = Return.new(Reference , value)
|
||||
method.add_code Set.new( to , value )
|
||||
to
|
||||
end
|
||||
|
||||
@ -45,7 +45,7 @@ module Virtual
|
||||
# otherwise it's a method without args and a send is issued.
|
||||
# whichever way this goes the result is stored in the return slot (as all compiles)
|
||||
def self.compile_name expression , method
|
||||
return Virtual::Self.new( Virtual::Mystery ) if expression.name == :self
|
||||
return Self.new( Mystery ) if expression.name == :self
|
||||
name = expression.name
|
||||
if method.has_var(expression.name)
|
||||
# either an argument, so it's stored in message
|
||||
@ -62,19 +62,19 @@ module Virtual
|
||||
|
||||
|
||||
def self.compile_module expression , method
|
||||
clazz = Virtual::BootSpace.space.get_or_create_class name
|
||||
clazz = BootSpace.space.get_or_create_class name
|
||||
raise "uups #{clazz}.#{name}" unless clazz
|
||||
to = Virtual::Return.new(Virtual::Reference , clazz )
|
||||
method.add_code Virtual::Set.new( to , clazz )
|
||||
to = Return.new(Reference , clazz )
|
||||
method.add_code Set.new( to , clazz )
|
||||
to
|
||||
end
|
||||
|
||||
# attr_reader :string
|
||||
def self.compile_string expression , method
|
||||
value = Virtual::StringConstant.new(expression.string)
|
||||
to = Virtual::Return.new(Virtual::Reference , value)
|
||||
Virtual::BootSpace.space.add_object value
|
||||
method.add_code Virtual::Set.new( to , value )
|
||||
value = StringConstant.new(expression.string)
|
||||
to = Return.new(Reference , value)
|
||||
BootSpace.space.add_object value
|
||||
method.add_code Set.new( to , value )
|
||||
to
|
||||
end
|
||||
|
||||
@ -85,17 +85,17 @@ module Virtual
|
||||
raise "oh noo, nil from where #{expression.right.inspect}" unless r
|
||||
index = method.has_arg(name)
|
||||
if index
|
||||
method.add_code Virtual::Set.new(Virtual::Return.new , Virtual::MessageSlot.new(index , r,type , r ))
|
||||
method.add_code Set.new(Return.new , MessageSlot.new(index , r,type , r ))
|
||||
else
|
||||
index = method.ensure_local(expression.left.name)
|
||||
method.add_code Virtual::Set.new(Virtual::Return.new , Virtual::FrameSlot.new(index , r.type , r ))
|
||||
method.add_code Set.new(Return.new , FrameSlot.new(index , r.type , r ))
|
||||
end
|
||||
r
|
||||
end
|
||||
|
||||
def self.compile_variable expression, method
|
||||
method.add_code Virtual::InstanceGet.new(expression.name)
|
||||
Virtual::Return.new( Virtual::Mystery )
|
||||
method.add_code InstanceGet.new(expression.name)
|
||||
Return.new( Mystery )
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -6,23 +6,23 @@ module Virtual
|
||||
|
||||
def self.compile_callsite expession , method
|
||||
me = Compiler.compile( expession.receiver , method )
|
||||
method.add_code Virtual::NewMessage.new
|
||||
method.add_code Virtual::Set.new(Virtual::NewSelf.new(me.type), me)
|
||||
method.add_code Virtual::Set.new(Virtual::NewName.new(), Virtual::StringConstant.new(expession.name))
|
||||
method.add_code NewMessage.new
|
||||
method.add_code Set.new(NewSelf.new(me.type), me)
|
||||
method.add_code Set.new(NewName.new(), StringConstant.new(expession.name))
|
||||
compiled_args = []
|
||||
expession.args.each_with_index do |arg , i|
|
||||
#compile in the running method, ie before passing control
|
||||
val = Compiler.compile( arg , method)
|
||||
# move the compiled value to it's slot in the new message
|
||||
to = Virtual::NewMessageSlot.new(i ,val.type , val)
|
||||
to = NewMessageSlot.new(i ,val.type , val)
|
||||
# (doing this immediately, not after the loop, so if it's a return it won't get overwritten)
|
||||
method.add_code Virtual::Set.new(to , val )
|
||||
method.add_code Set.new(to , val )
|
||||
compiled_args << to
|
||||
end
|
||||
method.add_code Virtual::MessageSend.new(expession.name , me , compiled_args) #and pass control
|
||||
method.add_code MessageSend.new(expession.name , me , compiled_args) #and pass control
|
||||
# the effect of the method is that the NewMessage Return slot will be filled, return it
|
||||
# (this is what is moved _inside_ above loop for such expressions that are calls (or constants))
|
||||
Virtual::Return.new( method.return_type )
|
||||
Return.new( method.return_type )
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -6,17 +6,17 @@ module Virtual
|
||||
raise "error, argument must be a identifier, not #{p}" unless p.is_a? Ast::NameExpression
|
||||
p.name
|
||||
end
|
||||
r = expression.receiver ? Compiler.compile(expression.receiver, method ) : Virtual::Self.new()
|
||||
new_method = Virtual::CompiledMethod.new(expression.name , args , r )
|
||||
new_method.class_name = r.is_a?(Virtual::BootClass) ? r.name : method.class_name
|
||||
clazz = Virtual::BootSpace.space.get_or_create_class(new_method.class_name)
|
||||
r = expression.receiver ? Compiler.compile(expression.receiver, method ) : Self.new()
|
||||
new_method = CompiledMethod.new(expression.name , args , r )
|
||||
new_method.class_name = r.is_a?(BootClass) ? r.name : method.class_name
|
||||
clazz = BootSpace.space.get_or_create_class(new_method.class_name)
|
||||
clazz.add_instance_method new_method
|
||||
|
||||
#frame = frame.new_frame
|
||||
return_type = nil
|
||||
expression.body.each do |ex|
|
||||
return_type = Compiler.compile(ex,new_method )
|
||||
raise return_type.inspect if return_type.is_a? Virtual::Instruction
|
||||
raise return_type.inspect if return_type.is_a? Instruction
|
||||
end
|
||||
new_method.return_type = return_type
|
||||
new_method
|
||||
@ -26,13 +26,13 @@ module Virtual
|
||||
locals = {}
|
||||
expression.params.each_with_index do |param , index|
|
||||
arg = param.name
|
||||
register = Virtual::RegisterReference.new(Virtual::RegisterMachine.instance.receiver_register).next_reg_use(index + 1)
|
||||
arg_value = Virtual::Integer.new(register)
|
||||
register = RegisterReference.new(RegisterMachine.instance.receiver_register).next_reg_use(index + 1)
|
||||
arg_value = Integer.new(register)
|
||||
locals[arg] = arg_value
|
||||
args << arg_value
|
||||
end
|
||||
# class depends on receiver
|
||||
me = Virtual::Integer.new( Virtual::RegisterMachine.instance.receiver_register )
|
||||
me = Integer.new( RegisterMachine.instance.receiver_register )
|
||||
if expression.receiver.nil?
|
||||
clazz = context.current_class
|
||||
else
|
||||
@ -40,7 +40,7 @@ module Virtual
|
||||
clazz = c.meta_class
|
||||
end
|
||||
|
||||
function = Virtual::Function.new(name , me , args )
|
||||
function = Function.new(name , me , args )
|
||||
clazz.add_code_function function
|
||||
|
||||
parent_locals = context.locals
|
||||
@ -52,11 +52,11 @@ module Virtual
|
||||
expression.body.each do |b|
|
||||
puts "compiling in function #{b}"
|
||||
last_compiled = b.compile(context)
|
||||
raise "alarm #{last_compiled} \n #{b}" unless last_compiled.is_a? Virtual::Word
|
||||
raise "alarm #{last_compiled} \n #{b}" unless last_compiled.is_a? Word
|
||||
end
|
||||
|
||||
return_reg = Virtual::Integer.new(Virtual::RegisterMachine.instance.return_register)
|
||||
if last_compiled.is_a?(Virtual::IntegerConstant) or last_compiled.is_a?(Virtual::ObjectConstant)
|
||||
return_reg = Integer.new(RegisterMachine.instance.return_register)
|
||||
if last_compiled.is_a?(IntegerConstant) or last_compiled.is_a?(ObjectConstant)
|
||||
return_reg.load function , last_compiled if last_compiled.register_symbol != return_reg.register_symbol
|
||||
else
|
||||
return_reg.move( function, last_compiled ) if last_compiled.register_symbol != return_reg.register_symbol
|
||||
|
@ -12,8 +12,8 @@ module Virtual
|
||||
|
||||
is = Compiler.compile(expression.cond, method )
|
||||
# TODO should/will use different branches for different conditions.
|
||||
# just a scetch : cond_val = cond_val.is_true?(method) unless cond_val.is_a? Virtual::BranchCondition
|
||||
method.add_code Virtual::IsTrueBranch.new( true_block )
|
||||
# just a scetch : cond_val = cond_val.is_true?(method) unless cond_val.is_a? BranchCondition
|
||||
method.add_code IsTrueBranch.new( true_block )
|
||||
|
||||
# compile the true block (as we think of it first, even it is second in sequential order)
|
||||
method.current true_block
|
||||
@ -30,7 +30,7 @@ module Virtual
|
||||
last = Compiler.compile(part,method )
|
||||
raise part.inspect if last.nil?
|
||||
end
|
||||
method.add_code Virtual::UnconditionalBranch.new( merge_block )
|
||||
method.add_code UnconditionalBranch.new( merge_block )
|
||||
|
||||
puts "compiled if: end"
|
||||
method.current merge_block
|
||||
|
@ -6,7 +6,7 @@ module Virtual
|
||||
end
|
||||
|
||||
def self.compile_class expression , method
|
||||
clazz = ::Virtual::BootSpace.space.get_or_create_class expression.name
|
||||
clazz = ::BootSpace.space.get_or_create_class expression.name
|
||||
puts "Created class #{clazz.name.inspect}"
|
||||
expression.expressions.each do |expr|
|
||||
# check if it's a function definition and add
|
||||
|
@ -3,7 +3,7 @@ module Virtual
|
||||
|
||||
# return attr_reader :expression
|
||||
def self.compile_return expression, scope ,method
|
||||
Virtual::Reference.new
|
||||
Reference.new
|
||||
end
|
||||
def old
|
||||
into = context.function
|
||||
@ -11,8 +11,8 @@ module Virtual
|
||||
expression_value = expression.compile(context)
|
||||
# copied from function expression: TODO make function
|
||||
|
||||
return_reg = Virtual::Integer.new(Virtual::RegisterMachine.instance.return_register)
|
||||
if expression_value.is_a?(Virtual::IntegerConstant) or expression_value.is_a?(Virtual::ObjectConstant)
|
||||
return_reg = Integer.new(RegisterMachine.instance.return_register)
|
||||
if expression_value.is_a?(IntegerConstant) or expression_value.is_a?(ObjectConstant)
|
||||
return_reg.load into , expression_value
|
||||
else
|
||||
return_reg.move( into, expression_value ) if expression_value.register_symbol != return_reg.register_symbol
|
||||
|
@ -3,11 +3,11 @@ module Virtual
|
||||
|
||||
# while- attr_reader :condition, :body
|
||||
def self.compile_while expression, method
|
||||
start = Virtual::Label.new("while_start")
|
||||
start = Label.new("while_start")
|
||||
method.add_code start
|
||||
is = expression.condition.compile(method )
|
||||
branch = Virtual::IsTrueBranch.new "while"
|
||||
merge = Virtual::Label.new(branch.name)
|
||||
branch = IsTrueBranch.new "while"
|
||||
merge = Label.new(branch.name)
|
||||
branch.other = merge #false jumps to end of while
|
||||
method.add_code branch
|
||||
last = is
|
||||
|
Loading…
Reference in New Issue
Block a user