introducing expressions and constants
not everything statement anymore (as in ruby) basic statement tests working, rest havoc
This commit is contained in:
@ -5,6 +5,14 @@ module Vool
|
||||
def initialize(name , value )
|
||||
@name , @value = name , value
|
||||
end
|
||||
|
||||
def normalize()
|
||||
raise "not named left #{name}" unless @name.is_a?(Named)
|
||||
raise "unsupported right #{value}" unless @name.is_a?(Named) or
|
||||
@name.is_a?(SendStatement) or @name.is_a?(Constant)
|
||||
self
|
||||
end
|
||||
|
||||
def collect(arr)
|
||||
@value.collect(arr)
|
||||
super
|
||||
|
@ -4,13 +4,13 @@ module Vool
|
||||
Mom::SlotMove
|
||||
end
|
||||
end
|
||||
class ConstantStatement < Statement
|
||||
class Constant < Expression
|
||||
def slot_class
|
||||
Mom::SlotConstant
|
||||
end
|
||||
end
|
||||
|
||||
class IntegerStatement < ConstantStatement
|
||||
class IntegerConstant < Constant
|
||||
attr_reader :value
|
||||
def initialize(value)
|
||||
@value = value
|
||||
@ -22,7 +22,7 @@ module Vool
|
||||
Parfait.object_space.get_class_by_name(:Integer).instance_type
|
||||
end
|
||||
end
|
||||
class FloatStatement < ConstantStatement
|
||||
class FloatConstant < Constant
|
||||
attr_reader :value
|
||||
def initialize(value)
|
||||
@value = value
|
||||
@ -31,22 +31,22 @@ module Vool
|
||||
true
|
||||
end
|
||||
end
|
||||
class TrueStatement < ConstantStatement
|
||||
class TrueConstant < Constant
|
||||
def ct_type
|
||||
Parfait.object_space.get_class_by_name(:True).instance_type
|
||||
end
|
||||
end
|
||||
class FalseStatement < ConstantStatement
|
||||
class FalseConstant < Constant
|
||||
def ct_type
|
||||
Parfait.object_space.get_class_by_name(:False).instance_type
|
||||
end
|
||||
end
|
||||
class NilStatement < ConstantStatement
|
||||
class NilConstant < Constant
|
||||
def ct_type
|
||||
Parfait.object_space.get_class_by_name(:Nil).instance_type
|
||||
end
|
||||
end
|
||||
class SelfStatement < Statement
|
||||
class SelfExpression < Expression
|
||||
attr_reader :clazz
|
||||
def set_class(clazz)
|
||||
@clazz = clazz
|
||||
@ -58,9 +58,9 @@ module Vool
|
||||
@clazz.instance_type
|
||||
end
|
||||
end
|
||||
class SuperStatement < Statement
|
||||
class SuperExpression < Statement
|
||||
end
|
||||
class StringStatement < ConstantStatement
|
||||
class StringConstant < Constant
|
||||
attr_reader :value
|
||||
def initialize(value)
|
||||
@value = value
|
||||
@ -72,7 +72,7 @@ module Vool
|
||||
Parfait.object_space.get_class_by_name(:Word).instance_type
|
||||
end
|
||||
end
|
||||
class SymbolStatement < StringStatement
|
||||
class SymbolConstant < StringConstant
|
||||
def ct_type
|
||||
Parfait.object_space.get_class_by_name(:Word).instance_type
|
||||
end
|
||||
|
@ -1,10 +0,0 @@
|
||||
module Vool
|
||||
module Hoister
|
||||
def hoist_condition( method )
|
||||
return [@condition] if @condition.is_a?(Vool::Named)
|
||||
local = method.create_tmp
|
||||
assign = LocalAssignment.new( local , @condition)
|
||||
[Vool::LocalVariable.new(local) , assign]
|
||||
end
|
||||
end
|
||||
end
|
@ -1,7 +1,7 @@
|
||||
require_relative "hoister"
|
||||
require_relative "normalizer"
|
||||
module Vool
|
||||
class IfStatement < Statement
|
||||
include Hoister
|
||||
include Normalizer
|
||||
|
||||
attr_reader :condition , :if_true , :if_false
|
||||
|
||||
@ -12,6 +12,14 @@ module Vool
|
||||
simplify_condition
|
||||
end
|
||||
|
||||
def normalize(method)
|
||||
cond , rest = *normalize_name(@condition)
|
||||
fals = @if_false ? @if_false.normalize(method) : nil
|
||||
me = IfStatement.new(cond , @if_true.normalize(method), fals)
|
||||
return me unless rest
|
||||
rest << me
|
||||
end
|
||||
|
||||
def to_mom( method )
|
||||
if_true = @if_true.to_mom( method )
|
||||
if_false = @if_false ? @if_false.to_mom( method ) : nil
|
||||
|
16
lib/vool/statements/normalizer.rb
Normal file
16
lib/vool/statements/normalizer.rb
Normal file
@ -0,0 +1,16 @@
|
||||
module Vool
|
||||
module Normalizer
|
||||
# given a something, determine if it is a Name
|
||||
#
|
||||
# Return a Name, and a possible rest that has a hoisted part of the statement
|
||||
#
|
||||
# eg if( @var % 5) is not normalized
|
||||
# but if(tmp_123) is with tmp_123 = @var % 5 hoited above the if
|
||||
def normalize_name( method )
|
||||
return [@condition] if @condition.is_a?(Named)
|
||||
local = method.create_tmp
|
||||
assign = LocalAssignment.new( local , @condition)
|
||||
[LocalVariable.new(local) , assign]
|
||||
end
|
||||
end
|
||||
end
|
@ -96,8 +96,8 @@ module Vool
|
||||
[Mom::SlotMove.new([@dynamic, :cached_type] , [:receiver , :type])]
|
||||
end
|
||||
def build_method_cache_update(in_method)
|
||||
receiver = StringStatement.new(@name)
|
||||
resolve = SendStatement.new(:resolve_method , receiver , [SelfStatement.new])
|
||||
receiver = StringConstant.new(@name)
|
||||
resolve = SendStatement.new(:resolve_method , receiver , [SelfExpression.new])
|
||||
move_method = Mom::SlotMove.new([@dynamic, :cached_method] , [:receiver , :return])
|
||||
resolve.to_mom(in_method) << move_method
|
||||
end
|
||||
|
@ -6,7 +6,7 @@ module Vool
|
||||
end
|
||||
end
|
||||
|
||||
class LocalVariable < Statement
|
||||
class LocalVariable < Expression
|
||||
include Named
|
||||
def to_mom(method)
|
||||
if method.args_type.variable_index(@name)
|
||||
@ -18,7 +18,7 @@ module Vool
|
||||
end
|
||||
end
|
||||
|
||||
class InstanceVariable < Statement
|
||||
class InstanceVariable < Expression
|
||||
include Named
|
||||
def to_mom(method)
|
||||
Mom::SlotDefinition.new(:message , [ :receiver , @name] )
|
||||
@ -29,11 +29,11 @@ module Vool
|
||||
end
|
||||
end
|
||||
|
||||
class ClassVariable < Statement
|
||||
class ClassVariable < Expression
|
||||
include Named
|
||||
end
|
||||
|
||||
class ModuleName < Statement
|
||||
class ModuleName < Expression
|
||||
include Named
|
||||
end
|
||||
end
|
||||
|
@ -1,8 +1,8 @@
|
||||
require_relative "hoister"
|
||||
require_relative "normalizer"
|
||||
|
||||
module Vool
|
||||
class WhileStatement < Statement
|
||||
include Hoister
|
||||
include Normalizer
|
||||
attr_reader :condition , :statements
|
||||
|
||||
def initialize( condition , statements )
|
||||
@ -11,6 +11,13 @@ module Vool
|
||||
simplify_condition
|
||||
end
|
||||
|
||||
def normalize(method)
|
||||
cond , rest = *normalize_name(@condition)
|
||||
me = WhileStatement.new(cond , @statements.normalize(method))
|
||||
return me unless rest
|
||||
rest << me
|
||||
end
|
||||
|
||||
def to_mom( method )
|
||||
statements = @statements.to_mom( method )
|
||||
condition , hoisted = hoist_condition( method )
|
||||
|
Reference in New Issue
Block a user