add lots of operators. Assignment becomes operator. fix the mess

This commit is contained in:
Torsten Ruger
2014-05-11 18:37:26 +03:00
parent 3974f2516d
commit cc5915135a
8 changed files with 85 additions and 52 deletions

View File

@@ -25,26 +25,6 @@ module Ast
end
end
class AssignmentExpression < Expression
attr_reader :assignee, :assigned
def initialize assignee, assigned
@assignee, @assigned = assignee, assigned
end
def inspect
self.class.name + ".new(" + assignee.inspect + ", " + assigned.inspect + ")"
end
def compile context
value = @assigned.compile(context)
variable = Vm::Variable.new @assignee , :r0 , value
context.locals[@assignee] = variable
variable
end
def attributes
[:assignee, :assigned]
end
end
class OperatorExpression < Expression
attr_reader :operator, :left, :right
@@ -62,6 +42,14 @@ module Ast
parent_locals = context.locals
context.locals = {}
args = []
#assignemnt
value = @assigned.compile(context)
variable = Vm::Variable.new @assignee , :r0 , value
context.locals[@assignee] = variable
variable
params.each do |param|
args << param.compile(context) # making the argument a local
end