2014-06-25 02:47:59 +03:00
|
|
|
# collection of the simple ones, int and strings and such
|
|
|
|
|
|
|
|
module Ast
|
|
|
|
|
|
|
|
class IntegerExpression < Expression
|
|
|
|
# attr_reader :value
|
2014-07-12 21:59:17 +03:00
|
|
|
def compile frame , method
|
2014-06-26 17:52:15 +03:00
|
|
|
Virtual::IntegerConstant.new value
|
2014-06-25 02:47:59 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-07-01 15:57:13 +03:00
|
|
|
class TrueExpression
|
2014-07-12 21:59:17 +03:00
|
|
|
def compile frame , method
|
2014-07-01 15:57:13 +03:00
|
|
|
Virtual::TrueValue.new
|
|
|
|
end
|
|
|
|
end
|
2014-07-10 17:14:38 +03:00
|
|
|
|
2014-07-01 15:57:13 +03:00
|
|
|
class FalseExpression
|
2014-07-12 21:59:17 +03:00
|
|
|
def compile frame , method
|
2014-07-01 15:57:13 +03:00
|
|
|
Virtual::FalseValue.new
|
|
|
|
end
|
|
|
|
end
|
2014-07-10 17:14:38 +03:00
|
|
|
|
2014-07-01 15:57:13 +03:00
|
|
|
class NilExpression
|
2014-07-12 21:59:17 +03:00
|
|
|
def compile frame , method
|
2014-07-01 15:57:13 +03:00
|
|
|
Virtual::NilValue.new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-06-25 02:47:59 +03:00
|
|
|
class NameExpression < Expression
|
|
|
|
# attr_reader :name
|
|
|
|
|
2014-07-10 17:14:38 +03:00
|
|
|
# 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.
|
|
|
|
# this makes the namespace static, ie when eval and co are implemented method needs recompilation
|
|
|
|
def compile frame , method
|
2014-07-15 10:35:29 +03:00
|
|
|
return Virtual::Self.new( Virtual::Mystery.new ) if name == :self
|
2014-07-10 17:14:38 +03:00
|
|
|
if method.has_var(name)
|
2014-07-13 16:00:48 +03:00
|
|
|
frame.compile_get(method , name )
|
2014-07-10 17:14:38 +03:00
|
|
|
else
|
2014-07-15 18:34:03 +03:00
|
|
|
frame.compile_send( method , name , Virtual::Self.new( Virtual::Mystery.new ) )
|
2014-07-10 17:14:38 +03:00
|
|
|
end
|
2014-06-25 02:47:59 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class ModuleName < NameExpression
|
|
|
|
|
2014-07-12 21:59:17 +03:00
|
|
|
def compile frame , method
|
2014-07-13 14:12:43 +03:00
|
|
|
clazz = ::Virtual::Object.space.get_or_create_class name
|
2014-06-25 02:47:59 +03:00
|
|
|
raise "uups #{clazz}.#{name}" unless clazz
|
|
|
|
#class qualifier, means call from metaclass
|
2014-07-14 14:06:09 +03:00
|
|
|
#clazz = clazz.meta_class
|
2014-06-25 02:47:59 +03:00
|
|
|
clazz
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class StringExpression < Expression
|
|
|
|
# attr_reader :string
|
2014-07-12 21:59:17 +03:00
|
|
|
def compile frame , method
|
2014-06-26 17:52:15 +03:00
|
|
|
value = Virtual::StringConstant.new(string)
|
2014-07-12 21:59:17 +03:00
|
|
|
::Virtual::Object.space.add_object value
|
2014-06-25 02:47:59 +03:00
|
|
|
value
|
|
|
|
end
|
|
|
|
end
|
2014-07-14 16:19:47 +03:00
|
|
|
class AssignmentExpression < Expression
|
2014-07-14 21:28:21 +03:00
|
|
|
#attr_reader :left, :right
|
|
|
|
|
2014-07-14 16:19:47 +03:00
|
|
|
def compile frame , method
|
2014-07-14 21:28:21 +03:00
|
|
|
raise "must assign to NameExpression , not #{left}" unless left.instance_of? NameExpression
|
2014-07-16 13:20:47 +03:00
|
|
|
r = right.compile(frame , method)
|
2014-07-14 21:28:21 +03:00
|
|
|
frame.compile_set( method , left.name , r )
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class VariableExpression < NameExpression
|
|
|
|
def compile frame ,method
|
2014-07-15 00:00:00 +03:00
|
|
|
method.add Virtual::ObjectGet.new(name)
|
2014-07-15 10:35:29 +03:00
|
|
|
Virtual::Return.new( Virtual::Mystery.new )
|
2014-07-14 16:19:47 +03:00
|
|
|
end
|
|
|
|
end
|
2014-06-25 02:47:59 +03:00
|
|
|
end
|