first propper hoisting test

had to change course, normalising and object creation is not possible
in one go
have to now generate random tmp vars  that will have to be picked up
later (sorted by tmp_ prefix?)
This commit is contained in:
Torsten Ruger
2018-03-15 12:46:56 +05:30
parent 9ddcb3224c
commit 3702411043
13 changed files with 149 additions and 54 deletions

View File

@ -7,9 +7,9 @@ module Vool
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)
raise "not named left #{name.class}" unless @name.is_a?(Symbol)
raise "unsupported right #{value}" unless @value.is_a?(Named) or
@value.is_a?(SendStatement) or @value.is_a?(Constant)
self
end

View File

@ -48,10 +48,8 @@ module Vool
end
class SelfExpression < Expression
attr_reader :clazz
def set_class(clazz)
@clazz = clazz
end
def to_mom(in_method)
@clazz = in_method.clazz
Mom::SlotDefinition.new(:message , [:receiver])
end
def ct_type

View File

@ -5,12 +5,12 @@ module Vool
def initialize( name , supe , body)
@name , @super_class_name , @body = name , supe , body
unless( body.is_a?(ScopeStatement))
@body = ScopeStatement.new([])
@body.statements << body if body
end
@body = ScopeStatement.new([]) unless body
end
def normalize
ClassStatement.new(@name , @super_class_name, @body.normalize )
end
# compilation to the next layer, mom
# context coming in for class is nil, also for methods, henceafter a method is passed down
def to_mom( _ )
@ -18,7 +18,7 @@ module Vool
Mom::Statements.new(methods)
end
def collect(arr)
def each()
@body.collect(arr)
super
end

View File

@ -12,10 +12,10 @@ module Vool
simplify_condition
end
def normalize(method)
cond , rest = *normalize_name(@condition, method)
fals = @if_false ? @if_false.normalize(method) : nil
me = IfStatement.new(cond , @if_true.normalize(method), fals)
def normalize
cond , rest = *normalize_name(@condition)
fals = @if_false ? @if_false.normalize : nil
me = IfStatement.new(cond , @if_true.normalize, fals)
return me unless rest
rest << me
end

View File

@ -2,13 +2,10 @@ module Vool
class MethodStatement < Statement
attr_reader :name, :args , :body , :clazz
def initialize( name , args , body)
def initialize( name , args , body , clazz = nil)
@name , @args , @body = name , args , body
unless( body.is_a?(ScopeStatement))
@body = ScopeStatement.new([])
@body.statements << body if body
end
@body = ScopeStatement.new([]) unless body
@clazz = clazz
end
# compile to mom instructions. methods themselves do no result in instructions (yet)
@ -24,8 +21,8 @@ module Vool
super
end
def set_class(clazz)
@clazz = clazz
def normalize
MethodStatement.new( @name , @args , @body.normalize)
end
def create_objects
@ -50,7 +47,7 @@ module Vool
def make_frame
type_hash = {}
vars = []
@body.collect([]).each { |node| node.add_local(vars) }
@body.each([]).each { |node| node.add_local(vars) }
vars.each { |var| type_hash[var] = :Object }
Parfait::NamedList.type_for( type_hash )
end

View File

@ -6,10 +6,10 @@ module Vool
#
# eg if( @var % 5) is not normalized
# but if(tmp_123) is with tmp_123 = @var % 5 hoited above the if
def normalize_name( condition , method )
def normalize_name( condition )
return [condition] if condition.is_a?(Named)
local = method.create_tmp
assign = LocalAssignment.new( local , condition)
local = "tmp_#{object_id}"
assign = Statements.new [LocalAssignment.new( local , condition)]
[LocalVariable.new(local) , assign]
end
end