working on if
This commit is contained in:
@ -67,7 +67,7 @@ module Ast
|
||||
|
||||
def compile frame , method
|
||||
raise "must assign to NameExpression , not #{left}" unless left.instance_of? NameExpression
|
||||
r = right.compile(frame,method)
|
||||
r = right.compile(frame , method)
|
||||
frame.compile_set( method , left.name , r )
|
||||
end
|
||||
end
|
||||
|
@ -2,9 +2,12 @@ module Ast
|
||||
class FunctionExpression < Expression
|
||||
# attr_reader :name, :params, :body , :receiver
|
||||
def compile frame , method
|
||||
args = params.collect{ |p| p.compile(frame , method )}
|
||||
args = params.collect do |p|
|
||||
raise "error, arguemnt must be a identifier, not #{p}" unless p.is_a? NameExpression
|
||||
Virtual::Argument.new( p.name , Virtual::Mystery.new )
|
||||
end
|
||||
r = receiver ? receiver.compile(frame,method) : Virtual::SelfReference.new
|
||||
method = Virtual::Method.new(name , params , r )
|
||||
method = Virtual::Method.new(name , args , r )
|
||||
frame = frame.new_frame
|
||||
return_type = nil
|
||||
body.each do |ex|
|
||||
|
@ -2,7 +2,14 @@ module Ast
|
||||
class IfExpression < Expression
|
||||
# attr_reader :cond, :if_true, :if_false
|
||||
def compile frame , method
|
||||
Virtual::Reference
|
||||
is = cond.compile(frame , method)
|
||||
# is.is_false(frame,method)
|
||||
last = is
|
||||
if_true.each do |part|
|
||||
last = part.compile(frame,method )
|
||||
raise part.inspect if last.nil?
|
||||
end
|
||||
last
|
||||
end
|
||||
def old
|
||||
f = context.function
|
||||
|
Reference in New Issue
Block a user