change all to_risc functions to add directly

still #11
test not working yet
This commit is contained in:
Torsten Ruger 2018-08-19 13:18:25 +03:00
parent 57dc6c45bb
commit 253d2fead8
8 changed files with 16 additions and 21 deletions

View File

@ -35,7 +35,7 @@ module Mom
transfer = SlotLoad.new([:message , :next_message , :receiver] , @receiver, self).to_risc(compiler) transfer = SlotLoad.new([:message , :next_message , :receiver] , @receiver, self).to_risc(compiler)
compiler.reset_regs compiler.reset_regs
@arguments.each do |arg| @arguments.each do |arg|
transfer << arg.to_risc(compiler) arg.to_risc(compiler)
compiler.reset_regs compiler.reset_regs
end end
transfer transfer

View File

@ -12,7 +12,8 @@ module Mom
@label = label @label = label
end end
def to_risc(compiler) def to_risc(compiler)
Risc::Branch.new(self , @label.to_risc(compiler)) label = @label.to_risc(compiler)
compiler.add_code Risc::Branch.new(self , label)
end end
end end

View File

@ -27,8 +27,7 @@ module Mom
# Move method name, frame and arguemnt types from the method to the next_message # Move method name, frame and arguemnt types from the method to the next_message
# Get the message from Space and link it. # Get the message from Space and link it.
def to_risc(compiler) def to_risc(compiler)
builder = compiler.code_builder(self) build_with(compiler.builder(self))
build_with(builder)
end end
# directly called by to_risc # directly called by to_risc

View File

@ -23,11 +23,10 @@ module Mom
# basically move both left and right values into register # basically move both left and right values into register
# subtract them and see if IsZero comparison # subtract them and see if IsZero comparison
def to_risc(compiler) def to_risc(compiler)
l_val = left.to_register(compiler, self) l_reg = left.to_register(compiler, self)
r_val = right.to_register(compiler, self) r_reg = right.to_register(compiler, self)
check = Risc.op( self , :- , l_val.register , r_val.register) compiler.add_code Risc.op( self , :- , l_reg , r_reg)
check << Risc::IsZero.new( self, false_jump.to_risc(compiler)) compiler.add_code Risc::IsZero.new( self, false_jump.to_risc(compiler))
l_val << r_val << check
end end
end end
end end

View File

@ -35,7 +35,7 @@ module Mom
def to_risc( compiler ) def to_risc( compiler )
name_ = @name name_ = @name
cache_entry_ = @cache_entry cache_entry_ = @cache_entry
builder = compiler.code_builder(self) builder = compiler.builder(self)
builder.build do builder.build do
word! << name_ word! << name_
cache_entry! << cache_entry_ cache_entry! << cache_entry_
@ -64,7 +64,6 @@ module Mom
add_code ok_label add_code ok_label
cache_entry[:cached_method] << callable_method cache_entry[:cached_method] << callable_method
end end
return builder.built
end end
end end

View File

@ -8,7 +8,7 @@ module Mom
class ReturnJump < Instruction class ReturnJump < Instruction
def to_risc(compiler) def to_risc(compiler)
Risc::Branch.new(self , compiler.return_label) compiler.add_code Risc::Branch.new(self , compiler.return_label)
end end
end end

View File

@ -21,7 +21,7 @@ module Mom
class ReturnSequence < Instruction class ReturnSequence < Instruction
def to_risc(compiler) def to_risc(compiler)
compiler.reset_regs compiler.reset_regs
builder = compiler.code_builder(self) builder = compiler.builder(self)
builder.build do builder.build do
object! << message[:return_value] object! << message[:return_value]
caller_reg! << message[:caller] caller_reg! << message[:caller]
@ -38,7 +38,6 @@ module Mom
message << message[:caller] message << message[:caller]
return_address.function_return return_address.function_return
end end
builder.built
end end
def to_s def to_s

View File

@ -20,18 +20,16 @@ module Mom
def to_risc(compiler) def to_risc(compiler)
false_label = @false_jump.to_risc(compiler) false_label = @false_jump.to_risc(compiler)
builder = compiler.code_builder("TruthCheck") builder = compiler.builder("TruthCheck")
condition_code = @condition.to_register(compiler,self) condition_reg = @condition.to_register(compiler,self)
condition = condition_code.register#.set_builder(builder) builder.build do
built = builder.build do
object! << Parfait.object_space.false_object object! << Parfait.object_space.false_object
object.op :- , condition object.op :- , condition_reg
if_zero false_label if_zero false_label
object << Parfait.object_space.nil_object object << Parfait.object_space.nil_object
object.op :- , condition object.op :- , condition_reg
if_zero false_label if_zero false_label
end end
condition_code << built
end end
end end