pass message to compile, not frame
This commit is contained in:
parent
13a05e7b72
commit
8d7b353f33
@ -4,25 +4,25 @@ module Ast
|
|||||||
|
|
||||||
class IntegerExpression < Expression
|
class IntegerExpression < Expression
|
||||||
# attr_reader :value
|
# attr_reader :value
|
||||||
def compile method , frame
|
def compile method , message
|
||||||
Virtual::IntegerConstant.new value
|
Virtual::IntegerConstant.new value
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class TrueExpression
|
class TrueExpression
|
||||||
def compile method , frame
|
def compile method , message
|
||||||
Virtual::TrueValue.new
|
Virtual::TrueValue.new
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class FalseExpression
|
class FalseExpression
|
||||||
def compile method , frame
|
def compile method , message
|
||||||
Virtual::FalseValue.new
|
Virtual::FalseValue.new
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class NilExpression
|
class NilExpression
|
||||||
def compile method , frame
|
def compile method , message
|
||||||
Virtual::NilValue.new
|
Virtual::NilValue.new
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -33,19 +33,19 @@ module Ast
|
|||||||
# compiling name needs to check if it's a variable and if so resolve it
|
# compiling name needs to check if it's a variable and if so resolve it
|
||||||
# otherwise it's a method without args and a send is ussued.
|
# otherwise it's a method without args and a send is ussued.
|
||||||
# this makes the namespace static, ie when eval and co are implemented method needs recompilation
|
# this makes the namespace static, ie when eval and co are implemented method needs recompilation
|
||||||
def compile method , frame
|
def compile method , message
|
||||||
return Virtual::Self.new( Virtual::Mystery.new ) if name == :self
|
return Virtual::Self.new( Virtual::Mystery.new ) if name == :self
|
||||||
if method.has_var(name)
|
if method.has_var(name)
|
||||||
frame.compile_get(method , name )
|
message.compile_get(method , name )
|
||||||
else
|
else
|
||||||
frame.compile_send( method , name , Virtual::Self.new( Virtual::Mystery.new ) )
|
message.compile_send( method , name , Virtual::Self.new( Virtual::Mystery.new ) )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class ModuleName < NameExpression
|
class ModuleName < NameExpression
|
||||||
|
|
||||||
def compile method , frame
|
def compile method , message
|
||||||
clazz = ::Virtual::Object.space.get_or_create_class name
|
clazz = ::Virtual::Object.space.get_or_create_class name
|
||||||
raise "uups #{clazz}.#{name}" unless clazz
|
raise "uups #{clazz}.#{name}" unless clazz
|
||||||
#class qualifier, means call from metaclass
|
#class qualifier, means call from metaclass
|
||||||
@ -56,7 +56,7 @@ module Ast
|
|||||||
|
|
||||||
class StringExpression < Expression
|
class StringExpression < Expression
|
||||||
# attr_reader :string
|
# attr_reader :string
|
||||||
def compile method , frame
|
def compile method , message
|
||||||
value = Virtual::StringConstant.new(string)
|
value = Virtual::StringConstant.new(string)
|
||||||
::Virtual::Object.space.add_object value
|
::Virtual::Object.space.add_object value
|
||||||
value
|
value
|
||||||
@ -65,10 +65,10 @@ module Ast
|
|||||||
class AssignmentExpression < Expression
|
class AssignmentExpression < Expression
|
||||||
#attr_reader :left, :right
|
#attr_reader :left, :right
|
||||||
|
|
||||||
def compile method , frame
|
def compile method , message
|
||||||
raise "must assign to NameExpression , not #{left}" unless left.instance_of? NameExpression
|
raise "must assign to NameExpression , not #{left}" unless left.instance_of? NameExpression
|
||||||
r = right.compile(method,frame)
|
r = right.compile(method,message)
|
||||||
frame.compile_set( method , left.name , r )
|
message.compile_set( method , left.name , r )
|
||||||
end
|
end
|
||||||
def old_scratch
|
def old_scratch
|
||||||
if operator == "=" # assignment, value based
|
if operator == "=" # assignment, value based
|
||||||
@ -93,7 +93,7 @@ module Ast
|
|||||||
end
|
end
|
||||||
|
|
||||||
class VariableExpression < NameExpression
|
class VariableExpression < NameExpression
|
||||||
def compile method , frame
|
def compile method , message
|
||||||
method.add Virtual::ObjectGet.new(name)
|
method.add Virtual::ObjectGet.new(name)
|
||||||
Virtual::Return.new( Virtual::Mystery.new )
|
Virtual::Return.new( Virtual::Mystery.new )
|
||||||
end
|
end
|
||||||
|
@ -4,10 +4,10 @@ module Ast
|
|||||||
class CallSiteExpression < Expression
|
class CallSiteExpression < Expression
|
||||||
# attr_reader :name, :args , :receiver
|
# attr_reader :name, :args , :receiver
|
||||||
@@counter = 0
|
@@counter = 0
|
||||||
def compile method , frame
|
def compile method , message
|
||||||
me = receiver.compile( method, frame )
|
me = receiver.compile( method, message )
|
||||||
with = args.collect{|a| a.compile( method,frame)}
|
with = args.collect{|a| a.compile( method,message)}
|
||||||
frame.compile_send( method , name , me , with )
|
message.compile_send( method , name , me , with )
|
||||||
end
|
end
|
||||||
|
|
||||||
def scratch
|
def scratch
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
module Ast
|
module Ast
|
||||||
class ExpressionList < Expression
|
class ExpressionList < Expression
|
||||||
# attr_reader :expressions
|
# attr_reader :expressions
|
||||||
def compile method , frame
|
def compile method , message
|
||||||
expressions.collect { |part| part.compile( method, frame ) }
|
expressions.collect { |part| part.compile( method, message ) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
@ -1,17 +1,17 @@
|
|||||||
module Ast
|
module Ast
|
||||||
class FunctionExpression < Expression
|
class FunctionExpression < Expression
|
||||||
# attr_reader :name, :params, :body , :receiver
|
# attr_reader :name, :params, :body , :receiver
|
||||||
def compile method , frame
|
def compile method , message
|
||||||
args = params.collect do |p|
|
args = params.collect do |p|
|
||||||
raise "error, arguemnt must be a identifier, not #{p}" unless p.is_a? NameExpression
|
raise "error, arguemnt must be a identifier, not #{p}" unless p.is_a? NameExpression
|
||||||
Virtual::Argument.new( p.name , Virtual::Mystery.new )
|
Virtual::Argument.new( p.name , Virtual::Mystery.new )
|
||||||
end
|
end
|
||||||
r = receiver ? receiver.compile(method,frame) : Virtual::SelfReference.new
|
r = receiver ? receiver.compile(method,message) : Virtual::SelfReference.new
|
||||||
method = Virtual::MethodDefinition.new(name , args , r )
|
method = Virtual::MethodDefinition.new(name , args , r )
|
||||||
#frame = frame.new_frame
|
#frame = frame.new_frame
|
||||||
return_type = nil
|
return_type = nil
|
||||||
body.each do |ex|
|
body.each do |ex|
|
||||||
return_type = ex.compile(method,frame )
|
return_type = ex.compile(method,message )
|
||||||
raise return_type.inspect if return_type.is_a? Virtual::Instruction
|
raise return_type.inspect if return_type.is_a? Virtual::Instruction
|
||||||
end
|
end
|
||||||
method.return_type = return_type
|
method.return_type = return_type
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
module Ast
|
module Ast
|
||||||
class IfExpression < Expression
|
class IfExpression < Expression
|
||||||
# attr_reader :cond, :if_true, :if_false
|
# attr_reader :cond, :if_true, :if_false
|
||||||
def compile method , frame
|
def compile method , message
|
||||||
is = cond.compile(method,frame)
|
is = cond.compile(method,message)
|
||||||
# is.is_false(frame,method)
|
# is.is_false(frame,method)
|
||||||
# TODO should/will use different branches for different conditions.
|
# TODO should/will use different branches for different conditions.
|
||||||
branch = Virtual::ImplicitBranch.new "if_merge"
|
branch = Virtual::ImplicitBranch.new "if_merge"
|
||||||
method.add branch
|
method.add branch
|
||||||
last = is
|
last = is
|
||||||
if_true.each do |part|
|
if_true.each do |part|
|
||||||
last = part.compile(method,frame )
|
last = part.compile(method,message )
|
||||||
raise part.inspect if last.nil?
|
raise part.inspect if last.nil?
|
||||||
end
|
end
|
||||||
merge = Virtual::Label.new(branch.name)
|
merge = Virtual::Label.new(branch.name)
|
||||||
@ -17,7 +17,7 @@ module Ast
|
|||||||
branch.swap
|
branch.swap
|
||||||
method.current = branch
|
method.current = branch
|
||||||
if_false.each do |part|
|
if_false.each do |part|
|
||||||
last = part.compile(method,frame )
|
last = part.compile(method,message )
|
||||||
raise part.inspect if last.nil?
|
raise part.inspect if last.nil?
|
||||||
end
|
end
|
||||||
method.add merge
|
method.add merge
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
module Ast
|
module Ast
|
||||||
class OperatorExpression < Expression
|
class OperatorExpression < Expression
|
||||||
# attr_reader :operator, :left, :right
|
# attr_reader :operator, :left, :right
|
||||||
def compile method , frame
|
def compile method , message
|
||||||
call = CallSiteExpression.new( operator , [right] , left )
|
call = CallSiteExpression.new( operator , [right] , left )
|
||||||
call.compile(method,frame)
|
call.compile(method,message)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
@ -1,17 +1,17 @@
|
|||||||
module Ast
|
module Ast
|
||||||
class WhileExpression < Expression
|
class WhileExpression < Expression
|
||||||
# attr_reader :condition, :body
|
# attr_reader :condition, :body
|
||||||
def compile method , frame
|
def compile method , message
|
||||||
start = Virtual::Label.new("while_start")
|
start = Virtual::Label.new("while_start")
|
||||||
method.add start
|
method.add start
|
||||||
is = condition.compile(method,frame)
|
is = condition.compile(method,message)
|
||||||
branch = Virtual::ImplicitBranch.new "while"
|
branch = Virtual::ImplicitBranch.new "while"
|
||||||
merge = Virtual::Label.new(branch.name)
|
merge = Virtual::Label.new(branch.name)
|
||||||
branch.other = merge #false jumps to end of while
|
branch.other = merge #false jumps to end of while
|
||||||
method.add branch
|
method.add branch
|
||||||
last = is
|
last = is
|
||||||
body.each do |part|
|
body.each do |part|
|
||||||
last = part.compile(method,frame )
|
last = part.compile(method,message )
|
||||||
raise part.inspect if last.nil?
|
raise part.inspect if last.nil?
|
||||||
end
|
end
|
||||||
# unconditionally brnach to the start
|
# unconditionally brnach to the start
|
||||||
|
Loading…
Reference in New Issue
Block a user