diff --git a/lib/arm/arm_machine.rb b/lib/arm/arm_machine.rb index 641b26aa..c2b98001 100644 --- a/lib/arm/arm_machine.rb +++ b/lib/arm/arm_machine.rb @@ -32,7 +32,7 @@ module Arm end def word_load value , reg - raise "nnn " unless reg.class == Symbol + raise "not a register :#{reg}:" unless reg.class == Symbol mov( :left => reg , :right => value ) end def string_load str_lit , reg diff --git a/lib/ast/basic_expressions.rb b/lib/ast/basic_expressions.rb index fc0a187f..11e9c666 100644 --- a/lib/ast/basic_expressions.rb +++ b/lib/ast/basic_expressions.rb @@ -23,6 +23,11 @@ module Ast def initialize name @name = name end + def compile context + variable = Vm::Variable.new(@name) + context.locals[@name] = variable + variable + end def inspect self.class.name + ".new(" + name + ")" end diff --git a/lib/ast/function_expression.rb b/lib/ast/function_expression.rb index 84a54577..144b9a66 100644 --- a/lib/ast/function_expression.rb +++ b/lib/ast/function_expression.rb @@ -14,11 +14,15 @@ module Ast end def compile context - args = params.collect{|p| Vm::Value.type p.name } - function = Vm::Function.new(name ,args ) - context.program.add_function function parent_locals = context.locals context.locals = {} + args = [] + params.each do |param| + args << param.compile(context) # making the argument a local + end +# args = params.collect{|p| Vm::Value.type p.name } + function = Vm::Function.new(name ,args ) + context.program.add_function function block.each do |b| compiled = b.compile context if compiled.is_a? Vm::Block diff --git a/lib/ast/operator_expressions.rb b/lib/ast/operator_expressions.rb index 882d1bf6..8fa54fa1 100644 --- a/lib/ast/operator_expressions.rb +++ b/lib/ast/operator_expressions.rb @@ -35,8 +35,10 @@ module Ast end def compile context - var = @assigned.compile(context) - context.locals[@assignee] = var + value = @assigned.compile(context) + variable = Vm::Variable.new @assignee , :r0 , value + context.locals[@assignee] = variable + variable end def attributes diff --git a/lib/vm/function.rb b/lib/vm/function.rb index 0ea7cd42..feb751d2 100644 --- a/lib/vm/function.rb +++ b/lib/vm/function.rb @@ -56,7 +56,6 @@ module Vm def assemble io @entry.assemble(io) - raise @body.inspect @body.assemble(io) @exit.assemble(io) end diff --git a/lib/vm/values.rb b/lib/vm/values.rb index d2eb581d..71d692fc 100644 --- a/lib/vm/values.rb +++ b/lib/vm/values.rb @@ -36,7 +36,6 @@ module Vm end t end - end class Word < Value @@ -60,7 +59,22 @@ module Vm Machine.instance.signed_plus self , signed end end - + + class Variable < Value + attr_reader :name , :register + def initialize name , register = nil , val = nil + super(val) + @register = register + @name = name + end + def length + @value.length + end + def assemble io + @value.load @register + end + end + # The name really says it all. # The only interesting thing is storage. # Currently string are stored "inline" , ie in the code segment.