fix register issues, some typos
This commit is contained in:
parent
e10f4863ee
commit
3912e0cd31
@ -15,14 +15,14 @@ module Arm
|
|||||||
Vm::Bool.new
|
Vm::Bool.new
|
||||||
end
|
end
|
||||||
|
|
||||||
def integer_plus block , left , right
|
def integer_plus block , result , left , right
|
||||||
block.add_code add(:left => left , :right => left , :extra => :right )
|
block.add_code add(:left => result , :right => left , :extra => right )
|
||||||
left
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
def integer_minus block , left , right
|
def integer_minus block , result , left , right
|
||||||
block.add_code sub(:left => left , :right => left , :extra => :right )
|
block.add_code sub(:left => result , :right => left , :extra => right )
|
||||||
left
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
def integer_load block , left , right
|
def integer_load block , left , right
|
||||||
@ -54,6 +54,7 @@ module Arm
|
|||||||
end
|
end
|
||||||
def main_exit exit
|
def main_exit exit
|
||||||
syscall(exit , 1)
|
syscall(exit , 1)
|
||||||
|
exit
|
||||||
end
|
end
|
||||||
def function_entry block, f_name
|
def function_entry block, f_name
|
||||||
# entry.add_code push( :regs => [:lr] )
|
# entry.add_code push( :regs => [:lr] )
|
||||||
|
@ -39,6 +39,7 @@ module Arm
|
|||||||
elsif (op_with_rot = calculate_u8_with_rr(arg))
|
elsif (op_with_rot = calculate_u8_with_rr(arg))
|
||||||
@operand = op_with_rot
|
@operand = op_with_rot
|
||||||
@i = 1
|
@i = 1
|
||||||
|
raise "hmm"
|
||||||
else
|
else
|
||||||
raise "cannot fit numeric literal argument in operand #{arg.inspect}"
|
raise "cannot fit numeric literal argument in operand #{arg.inspect}"
|
||||||
end
|
end
|
||||||
|
@ -24,12 +24,8 @@ module Ast
|
|||||||
if( l_val ) #variable existed, move data there
|
if( l_val ) #variable existed, move data there
|
||||||
l_val = l_val.move( into , r_val)
|
l_val = l_val.move( into , r_val)
|
||||||
else
|
else
|
||||||
if r_val.is_a? Vm::IntegerConstant
|
|
||||||
next_register = context.function.next_register
|
next_register = context.function.next_register
|
||||||
l_val = Vm::Integer.new(next_register).load( into , r_val )
|
l_val = Vm::Integer.new(next_register).load( into , r_val )
|
||||||
else
|
|
||||||
l_val = r_val
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
context.locals[left.name] = l_val
|
context.locals[left.name] = l_val
|
||||||
return l_val
|
return l_val
|
||||||
@ -41,12 +37,15 @@ module Ast
|
|||||||
when ">"
|
when ">"
|
||||||
code = l_val.less_or_equal into , r_val
|
code = l_val.less_or_equal into , r_val
|
||||||
when "+"
|
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 "-"
|
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
|
else
|
||||||
raise "unimplemented operator #{operator} #{self}"
|
raise "unimplemented operator #{operator} #{self}"
|
||||||
end
|
end
|
||||||
|
code
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
@ -16,11 +16,13 @@ module Ast
|
|||||||
def compile context , into
|
def compile context , into
|
||||||
cond_val = condition.compile(context , into)
|
cond_val = condition.compile(context , into)
|
||||||
#set up branches for bodies
|
#set up branches for bodies
|
||||||
|
# jump to end if done
|
||||||
last = nil
|
last = nil
|
||||||
body.each do |part|
|
body.each do |part|
|
||||||
last = part.compile(context , into )
|
last = part.compile(context , into )
|
||||||
puts "compiled in while #{last.inspect}"
|
puts "compiled in while #{last.inspect}"
|
||||||
end
|
end
|
||||||
|
#jump back to test
|
||||||
return last
|
return last
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -16,7 +16,7 @@ module Vm
|
|||||||
if arg.is_a? IntegerConstant
|
if arg.is_a? IntegerConstant
|
||||||
Vm::Integer.new(index).load into , arg
|
Vm::Integer.new(index).load into , arg
|
||||||
else
|
else
|
||||||
arg.move( into , index ) if arg.register != index
|
Vm::Integer.new(index).move( into, arg ) if arg.register != index
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -22,8 +22,8 @@ module Vm
|
|||||||
super()
|
super()
|
||||||
@name = name
|
@name = name
|
||||||
@args = args
|
@args = args
|
||||||
@entry = Core::Kernel::function_entry( Vm::Block.new("#{name}_exit") ,name )
|
@entry = Core::Kernel::function_entry( Vm::Block.new("#{name}_entry") ,name )
|
||||||
@exit = Core::Kernel::function_exit( Vm::Block.new("#{name}_entry") , name )
|
@exit = Core::Kernel::function_exit( Vm::Block.new("#{name}_exit") , name )
|
||||||
@body = Block.new("#{name}_body")
|
@body = Block.new("#{name}_body")
|
||||||
@reg_count = 0
|
@reg_count = 0
|
||||||
branch_body
|
branch_body
|
||||||
@ -47,7 +47,7 @@ module Vm
|
|||||||
@entry.link_at address , context
|
@entry.link_at address , context
|
||||||
address += @entry.length
|
address += @entry.length
|
||||||
@body.link_at(address , context)
|
@body.link_at(address , context)
|
||||||
address += @entry.length
|
address += @body.length
|
||||||
@exit.link_at(address,context)
|
@exit.link_at(address,context)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -63,11 +63,11 @@ module Vm
|
|||||||
CMachine.instance.integer_less_or_equal block , self , right
|
CMachine.instance.integer_less_or_equal block , self , right
|
||||||
end
|
end
|
||||||
|
|
||||||
def plus block , right
|
def plus block , left , right
|
||||||
CMachine.instance.integer_plus block , self , right
|
CMachine.instance.integer_plus block , self , left , right
|
||||||
end
|
end
|
||||||
def minus block , right
|
def minus block , left , right
|
||||||
CMachine.instance.integer_minus block , self , right
|
CMachine.instance.integer_minus block , self , left , right
|
||||||
end
|
end
|
||||||
|
|
||||||
def load block , right
|
def load block , right
|
||||||
|
@ -31,7 +31,6 @@ class TestRunner < MiniTest::Test
|
|||||||
else
|
else
|
||||||
expr = part.compile( program.context , nil )
|
expr = part.compile( program.context , nil )
|
||||||
raise "should be function definition for now" unless expr.is_a? Vm::Function
|
raise "should be function definition for now" unless expr.is_a? Vm::Function
|
||||||
program.add_function expr
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -45,9 +44,8 @@ class TestRunner < MiniTest::Test
|
|||||||
blocks.flatten.each do |b|
|
blocks.flatten.each do |b|
|
||||||
writer.add_symbol b.name.to_s , b.position
|
writer.add_symbol b.name.to_s , b.position
|
||||||
end
|
end
|
||||||
assembly = program.assemble(StringIO.new)
|
|
||||||
|
|
||||||
writer.set_text assembly.string
|
writer.set_text binary.string
|
||||||
writer.save(file.gsub(".rb" , ".o"))
|
writer.save(file.gsub(".rb" , ".o"))
|
||||||
|
|
||||||
# puts program.to_yaml
|
# puts program.to_yaml
|
||||||
|
Loading…
Reference in New Issue
Block a user