fix register issues, some typos

This commit is contained in:
Torsten Ruger 2014-05-14 22:04:03 +03:00
parent e10f4863ee
commit 3912e0cd31
8 changed files with 26 additions and 25 deletions

View File

@ -15,14 +15,14 @@ module Arm
Vm::Bool.new
end
def integer_plus block , left , right
block.add_code add(:left => left , :right => left , :extra => :right )
left
def integer_plus block , result , left , right
block.add_code add(:left => result , :right => left , :extra => right )
result
end
def integer_minus block , left , right
block.add_code sub(:left => left , :right => left , :extra => :right )
left
def integer_minus block , result , left , right
block.add_code sub(:left => result , :right => left , :extra => right )
result
end
def integer_load block , left , right
@ -54,6 +54,7 @@ module Arm
end
def main_exit exit
syscall(exit , 1)
exit
end
def function_entry block, f_name
# entry.add_code push( :regs => [:lr] )

View File

@ -39,6 +39,7 @@ module Arm
elsif (op_with_rot = calculate_u8_with_rr(arg))
@operand = op_with_rot
@i = 1
raise "hmm"
else
raise "cannot fit numeric literal argument in operand #{arg.inspect}"
end

View File

@ -24,12 +24,8 @@ module Ast
if( l_val ) #variable existed, move data there
l_val = l_val.move( into , r_val)
else
if r_val.is_a? Vm::IntegerConstant
next_register = context.function.next_register
l_val = Vm::Integer.new(next_register).load( into , r_val )
else
l_val = r_val
end
next_register = context.function.next_register
l_val = Vm::Integer.new(next_register).load( into , r_val )
end
context.locals[left.name] = l_val
return l_val
@ -41,12 +37,15 @@ module Ast
when ">"
code = l_val.less_or_equal into , r_val
when "+"
code = l_val.plus into , r_val
res = Vm::Integer.new(context.function.next_register)
code = res.plus into , l_val , r_val
when "-"
code = l_val.minus into , r_val
res = Vm::Integer.new(context.function.next_register)
code = res.minus into , l_val , r_val
else
raise "unimplemented operator #{operator} #{self}"
end
code
end
end
end

View File

@ -16,11 +16,13 @@ module Ast
def compile context , into
cond_val = condition.compile(context , into)
#set up branches for bodies
# jump to end if done
last = nil
body.each do |part|
last = part.compile(context , into )
puts "compiled in while #{last.inspect}"
end
#jump back to test
return last
end
end

View File

@ -16,7 +16,7 @@ module Vm
if arg.is_a? IntegerConstant
Vm::Integer.new(index).load into , arg
else
arg.move( into , index ) if arg.register != index
Vm::Integer.new(index).move( into, arg ) if arg.register != index
end
end
end

View File

@ -22,8 +22,8 @@ module Vm
super()
@name = name
@args = args
@entry = Core::Kernel::function_entry( Vm::Block.new("#{name}_exit") ,name )
@exit = Core::Kernel::function_exit( Vm::Block.new("#{name}_entry") , name )
@entry = Core::Kernel::function_entry( Vm::Block.new("#{name}_entry") ,name )
@exit = Core::Kernel::function_exit( Vm::Block.new("#{name}_exit") , name )
@body = Block.new("#{name}_body")
@reg_count = 0
branch_body
@ -47,7 +47,7 @@ module Vm
@entry.link_at address , context
address += @entry.length
@body.link_at(address , context)
address += @entry.length
address += @body.length
@exit.link_at(address,context)
end

View File

@ -63,11 +63,11 @@ module Vm
CMachine.instance.integer_less_or_equal block , self , right
end
def plus block , right
CMachine.instance.integer_plus block , self , right
def plus block , left , right
CMachine.instance.integer_plus block , self , left , right
end
def minus block , right
CMachine.instance.integer_minus block , self , right
def minus block , left , right
CMachine.instance.integer_minus block , self , left , right
end
def load block , right

View File

@ -31,7 +31,6 @@ class TestRunner < MiniTest::Test
else
expr = part.compile( program.context , nil )
raise "should be function definition for now" unless expr.is_a? Vm::Function
program.add_function expr
end
end
@ -45,9 +44,8 @@ class TestRunner < MiniTest::Test
blocks.flatten.each do |b|
writer.add_symbol b.name.to_s , b.position
end
assembly = program.assemble(StringIO.new)
writer.set_text assembly.string
writer.set_text binary.string
writer.save(file.gsub(".rb" , ".o"))
# puts program.to_yaml