while compiles. jo
This commit is contained in:
parent
d50c38f5ad
commit
d6b5d46165
@ -26,10 +26,15 @@ module Arm
|
|||||||
end
|
end
|
||||||
|
|
||||||
def integer_load block , left , right
|
def integer_load block , left , right
|
||||||
reg = "r#{left.register}".to_sym
|
block.add_code mov( :left => left , :right => right )
|
||||||
block.add_code mov( :left => reg , :right => right )
|
|
||||||
left
|
left
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def integer_move block , left , right
|
||||||
|
block.add_code mov( :left => left , :right => right )
|
||||||
|
left
|
||||||
|
end
|
||||||
|
|
||||||
def string_load block , str_lit , reg
|
def string_load block , str_lit , reg
|
||||||
block.add_code add( :left => "r#{reg}".to_sym , :extra => str_lit ) #right is pc, implicit
|
block.add_code add( :left => "r#{reg}".to_sym , :extra => str_lit ) #right is pc, implicit
|
||||||
#second arg is a hack to get the stringlength without coding
|
#second arg is a hack to get the stringlength without coding
|
||||||
|
@ -13,7 +13,6 @@ module Ast
|
|||||||
call = Vm::CallSite.new( name , params , function)
|
call = Vm::CallSite.new( name , params , function)
|
||||||
call.load_args into
|
call.load_args into
|
||||||
call.do_call into
|
call.do_call into
|
||||||
call
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def inspect
|
def inspect
|
||||||
|
@ -16,8 +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
|
||||||
raise "no #{arg.inspect}" if arg.register != index
|
arg.move( into , index ) if arg.register != index
|
||||||
#arg.load( into , index )
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -73,6 +73,11 @@ module Vm
|
|||||||
def load block , right
|
def load block , right
|
||||||
CMachine.instance.integer_load block , self , right
|
CMachine.instance.integer_load block , self , right
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def move block , right
|
||||||
|
CMachine.instance.integer_move block , self , right
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
require_relative "constants"
|
require_relative "constants"
|
@ -23,15 +23,14 @@ class TestRunner < MiniTest::Test
|
|||||||
program = Vm::Program.new "Arm"
|
program = Vm::Program.new "Arm"
|
||||||
syntax = parser.parse_with_debug(string)
|
syntax = parser.parse_with_debug(string)
|
||||||
parts = Parser::Transform.new.apply(syntax)
|
parts = Parser::Transform.new.apply(syntax)
|
||||||
# file is a list of expressions, al but the last must be a function
|
# file is a list of expressions, all but the last must be a function
|
||||||
# and the last is wrapped as a main
|
# and the last is wrapped as a main
|
||||||
parts.each_with_index do |part,index|
|
parts.each_with_index do |part,index|
|
||||||
if index = parts.length
|
if index == (parts.length - 1)
|
||||||
expr = part.compile( program.context , nil )
|
|
||||||
program.main = expr
|
|
||||||
else
|
|
||||||
expr = part.compile( program.context , program.main )
|
expr = part.compile( program.context , program.main )
|
||||||
raise "should be function definition for now" unless expr.is_a? Function
|
else
|
||||||
|
expr = part.compile( program.context , nil )
|
||||||
|
raise "should be function definition for now" unless expr.is_a? Vm::Function
|
||||||
program.add_function expr
|
program.add_function expr
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user