reduce method return type to type and introduce a single instruction for instance get
This commit is contained in:
@ -63,7 +63,18 @@ module Ast
|
||||
end
|
||||
end
|
||||
class AssignmentExpression < Expression
|
||||
#attr_reader :left, :right
|
||||
|
||||
def compile frame , method
|
||||
raise "must assign to NameExpression , not #{left}" unless left.instance_of? NameExpression
|
||||
r = right.compile(frame,method)
|
||||
frame.compile_set( method , left.name , r )
|
||||
end
|
||||
end
|
||||
|
||||
class VariableExpression < NameExpression
|
||||
def compile frame ,method
|
||||
Virtual::ObjectGet.new(name)
|
||||
end
|
||||
end
|
||||
end
|
@ -53,12 +53,4 @@ module Ast
|
||||
end
|
||||
end
|
||||
|
||||
class VariableExpression < CallSiteExpression
|
||||
# super( :_get_instance_variable , [StringExpression.new(name)] )
|
||||
def make_setter
|
||||
@name = :_set_instance_variable
|
||||
@args << StringExpression.new("value")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
@ -2,7 +2,9 @@ module Ast
|
||||
class IfExpression < Expression
|
||||
# attr_reader :cond, :if_true, :if_false
|
||||
def compile frame , method
|
||||
return nil
|
||||
Virtual::Reference
|
||||
end
|
||||
def old
|
||||
f = context.function
|
||||
# to execute the logic as the if states it, the blocks are the other way around
|
||||
# so we can the jump over the else if true ,and the else joins unconditionally after the true_block
|
||||
|
@ -2,7 +2,7 @@ module Ast
|
||||
class OperatorExpression < Expression
|
||||
# attr_reader :operator, :left, :right
|
||||
def compile frame , method
|
||||
nil
|
||||
Virtual::Reference.new
|
||||
end
|
||||
def scratch
|
||||
into = context.function
|
||||
|
@ -2,7 +2,7 @@ module Ast
|
||||
class ReturnExpression < Expression
|
||||
# attr_reader :expression
|
||||
def compile frame ,method
|
||||
nil
|
||||
Virtual::Reference.new
|
||||
end
|
||||
def sc
|
||||
into = context.function
|
||||
|
@ -2,7 +2,7 @@ module Ast
|
||||
class WhileExpression < Expression
|
||||
# attr_reader :condition, :body
|
||||
def compile frame , method
|
||||
nil
|
||||
Virtual::Reference.new
|
||||
end
|
||||
def old
|
||||
into = context.function
|
||||
|
@ -19,6 +19,9 @@ module Virtual
|
||||
def inspect
|
||||
self.class.name + ".new(#{@integer})"
|
||||
end
|
||||
def type
|
||||
Virtual::Integer
|
||||
end
|
||||
end
|
||||
|
||||
# The name really says it all.
|
||||
|
@ -35,5 +35,9 @@ module Virtual
|
||||
def compile_send method , name , with = []
|
||||
method.add FrameSend.new(name , with )
|
||||
end
|
||||
|
||||
def compile_set method , name , val
|
||||
method.add FrameSet.new(name , val )
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -39,6 +39,10 @@ module Virtual
|
||||
def initialize name
|
||||
@name = name
|
||||
end
|
||||
attr_reader :name
|
||||
def attributes
|
||||
[:name]
|
||||
end
|
||||
end
|
||||
|
||||
class FrameSend < Instruction
|
||||
@ -48,13 +52,29 @@ module Virtual
|
||||
@args = args
|
||||
end
|
||||
attr_reader :name , :args
|
||||
|
||||
def == other
|
||||
self.class == other.class && self.name == other.name
|
||||
def attributes
|
||||
[:name , :args]
|
||||
end
|
||||
def inspect
|
||||
self.class.name + ".new(:#{@name} , [ " + args.collect{|a| a.inspect}.join(",")+ "])"
|
||||
end
|
||||
class FrameSet < Instruction
|
||||
|
||||
def initialize name , val
|
||||
@name = name.to_sym
|
||||
@value = val
|
||||
end
|
||||
attr_reader :name , :value
|
||||
def attributes
|
||||
[:name , :value]
|
||||
end
|
||||
end
|
||||
|
||||
class ObjectGet < Instruction
|
||||
def initialize name
|
||||
@name = name
|
||||
end
|
||||
attr_reader :name
|
||||
def attributes
|
||||
[:name]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user