change the debug output to be more readable
This commit is contained in:
parent
7c1c5431bc
commit
88a26414eb
@ -46,6 +46,10 @@ module Arm
|
|||||||
block << sub( result , left , right )
|
block << sub( result , left , right )
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
def integer_left_shift block , result , left , right
|
||||||
|
block << mov( result , left , shift_lsr: right )
|
||||||
|
result
|
||||||
|
end
|
||||||
|
|
||||||
def function_call into , call
|
def function_call into , call
|
||||||
raise "Not CallSite #{call.inspect}" unless call.is_a? Vm::CallSite
|
raise "Not CallSite #{call.inspect}" unless call.is_a? Vm::CallSite
|
||||||
|
@ -53,7 +53,9 @@ module Ast
|
|||||||
def inspect
|
def inspect
|
||||||
self.class.name + '.new("' + string + '")'
|
self.class.name + '.new("' + string + '")'
|
||||||
end
|
end
|
||||||
|
def to_s
|
||||||
|
'"' + string + '"'
|
||||||
|
end
|
||||||
def compile context , into
|
def compile context , into
|
||||||
value = Vm::StringConstant.new(string)
|
value = Vm::StringConstant.new(string)
|
||||||
context.object_space.add_object value
|
context.object_space.add_object value
|
||||||
|
@ -17,7 +17,9 @@ module Ast
|
|||||||
end
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
"def #{name}( " + params.join(",") + ") \n" + body.join("\n") + "end\n"
|
ret = "def "
|
||||||
|
ret += "#{receiver}." if receiver
|
||||||
|
ret + "#{name}( " + params.join(",") + ") \n" + body.join("\n") + "end\n"
|
||||||
end
|
end
|
||||||
def compile context , into
|
def compile context , into
|
||||||
raise "function does not compile into anything #{self}" if into
|
raise "function does not compile into anything #{self}" if into
|
||||||
@ -31,6 +33,7 @@ module Ast
|
|||||||
end
|
end
|
||||||
class_name = context.current_class.name
|
class_name = context.current_class.name
|
||||||
function = Vm::Function.new(name , args )
|
function = Vm::Function.new(name , args )
|
||||||
|
# class depends on receiver
|
||||||
context.current_class.add_function function
|
context.current_class.add_function function
|
||||||
|
|
||||||
parent_locals = context.locals
|
parent_locals = context.locals
|
||||||
@ -41,8 +44,8 @@ module Ast
|
|||||||
into = function.body
|
into = function.body
|
||||||
last_compiled = nil
|
last_compiled = nil
|
||||||
body.each do |b|
|
body.each do |b|
|
||||||
|
puts "compiling in function #{b}"
|
||||||
last_compiled = b.compile(context , into)
|
last_compiled = b.compile(context , into)
|
||||||
puts "compiled in function #{last_compiled.inspect}"
|
|
||||||
raise "alarm #{last_compiled} \n #{b}" unless last_compiled.is_a? Vm::Word
|
raise "alarm #{last_compiled} \n #{b}" unless last_compiled.is_a? Vm::Word
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -18,23 +18,23 @@ module Ast
|
|||||||
true_block = false_block.new_block "#{into.name}_if_true"
|
true_block = false_block.new_block "#{into.name}_if_true"
|
||||||
merge_block = true_block.new_block "#{into.name}_if_merge"
|
merge_block = true_block.new_block "#{into.name}_if_merge"
|
||||||
|
|
||||||
|
puts "compiling if condition #{cond}"
|
||||||
cond_val = cond.compile(context , into)
|
cond_val = cond.compile(context , into)
|
||||||
puts "compiled if condition #{cond_val.inspect}"
|
|
||||||
into.b true_block , condition_code: cond_val.operator
|
into.b true_block , condition_code: cond_val.operator
|
||||||
|
|
||||||
if_false.each do |part|
|
if_false.each do |part|
|
||||||
|
puts "compiling in if false #{part}"
|
||||||
last = part.compile(context , false_block )
|
last = part.compile(context , false_block )
|
||||||
puts "compiled in if false #{last.inspect}"
|
|
||||||
end
|
end
|
||||||
false_block.b merge_block
|
false_block.b merge_block
|
||||||
|
|
||||||
last = nil
|
last = nil
|
||||||
if_true.each do |part|
|
if_true.each do |part|
|
||||||
|
puts "compiling in if true #{part}"
|
||||||
last = part.compile(context , true_block )
|
last = part.compile(context , true_block )
|
||||||
puts "compiled in if true #{last.inspect}"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
puts "compile if end"
|
puts "compiled if: end"
|
||||||
into.insert_at merge_block
|
into.insert_at merge_block
|
||||||
|
|
||||||
return last
|
return last
|
||||||
|
@ -22,7 +22,7 @@ module Ast
|
|||||||
# check if it's a function definition and add
|
# check if it's a function definition and add
|
||||||
# if not, execute it, but that does means we should be in crystal (executable), not ruby. ie throw an error for now
|
# if not, execute it, but that does means we should be in crystal (executable), not ruby. ie throw an error for now
|
||||||
raise "only functions for now #{expression.inspect}" unless expression.is_a? Ast::FunctionExpression
|
raise "only functions for now #{expression.inspect}" unless expression.is_a? Ast::FunctionExpression
|
||||||
puts "compiling expression #{expression.inspect}"
|
puts "compiling expression #{expression}"
|
||||||
expression_value = expression.compile(context , nil )
|
expression_value = expression.compile(context , nil )
|
||||||
#puts "compiled expression #{expression_value.inspect}"
|
#puts "compiled expression #{expression_value.inspect}"
|
||||||
end
|
end
|
||||||
|
@ -16,9 +16,9 @@ module Ast
|
|||||||
"#{left} #{operator} #{right}"
|
"#{left} #{operator} #{right}"
|
||||||
end
|
end
|
||||||
def compile context , into
|
def compile context , into
|
||||||
puts "compile operator #{to_s}"
|
puts "compiling operator #{to_s}"
|
||||||
r_val = right.compile(context , into)
|
r_val = right.compile(context , into)
|
||||||
puts "compiled right #{r_val.inspect}"
|
#puts "compiled right #{r_val.inspect}"
|
||||||
if operator == "=" # assignment, value based
|
if operator == "=" # assignment, value based
|
||||||
raise "Can only assign variables, not #{left}" unless left.is_a?(NameExpression)
|
raise "Can only assign variables, not #{left}" unless left.is_a?(NameExpression)
|
||||||
l_val = context.locals[left.name]
|
l_val = context.locals[left.name]
|
||||||
@ -52,6 +52,9 @@ module Ast
|
|||||||
when "-"
|
when "-"
|
||||||
res = context.function.new_local
|
res = context.function.new_local
|
||||||
code = res.minus into , l_val , r_val
|
code = res.minus into , l_val , r_val
|
||||||
|
when "<<"
|
||||||
|
res = context.function.new_local
|
||||||
|
code = res.left_shift into , l_val , r_val
|
||||||
else
|
else
|
||||||
raise "unimplemented operator #{operator} #{self}"
|
raise "unimplemented operator #{operator} #{self}"
|
||||||
end
|
end
|
||||||
|
@ -14,8 +14,8 @@ module Ast
|
|||||||
[:expression]
|
[:expression]
|
||||||
end
|
end
|
||||||
def compile context , into
|
def compile context , into
|
||||||
|
puts "compiling return expression #{expression}, now return in 7"
|
||||||
expression_value = expression.compile(context , into)
|
expression_value = expression.compile(context , into)
|
||||||
puts "compiled return expression #{expression_value.inspect}, now return in 7"
|
|
||||||
# copied from function expression: TODO make function
|
# copied from function expression: TODO make function
|
||||||
|
|
||||||
return_reg = Vm::Integer.new(7)
|
return_reg = Vm::Integer.new(7)
|
||||||
|
@ -16,13 +16,13 @@ module Ast
|
|||||||
def compile context , into
|
def compile context , into
|
||||||
while_block = into.new_block "#{into.name}_while"
|
while_block = into.new_block "#{into.name}_while"
|
||||||
ret = while_block.new_block "#{into.name}_return"
|
ret = while_block.new_block "#{into.name}_return"
|
||||||
|
puts "compiling while condition #{condition}"
|
||||||
cond_val = condition.compile(context , while_block)
|
cond_val = condition.compile(context , while_block)
|
||||||
puts "compiled while condition #{cond_val.inspect}"
|
|
||||||
while_block.b ret , condition_code: cond_val.not_operator
|
while_block.b ret , condition_code: cond_val.not_operator
|
||||||
last = nil
|
last = nil
|
||||||
body.each do |part|
|
body.each do |part|
|
||||||
|
puts "compiling in while #{part}"
|
||||||
last = part.compile(context , while_block )
|
last = part.compile(context , while_block )
|
||||||
puts "compiled in while #{last.inspect}"
|
|
||||||
end
|
end
|
||||||
while_block.b while_block
|
while_block.b while_block
|
||||||
puts "compile while end"
|
puts "compile while end"
|
||||||
|
@ -127,6 +127,9 @@ module Vm
|
|||||||
def minus block , first , right
|
def minus block , first , right
|
||||||
RegisterMachine.instance.integer_minus block , self , first , right
|
RegisterMachine.instance.integer_minus block , self , first , right
|
||||||
end
|
end
|
||||||
|
def left_shift block , first , right
|
||||||
|
RegisterMachine.instance.integer_left_shift block , self , first , right
|
||||||
|
end
|
||||||
|
|
||||||
def load block , right
|
def load block , right
|
||||||
if(right.is_a? IntegerConstant)
|
if(right.is_a? IntegerConstant)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user