ifx most of the conversion

well . . it's still converting to ruby, minor detail
This commit is contained in:
Torsten Ruger 2018-07-19 14:59:10 +03:00
parent ae3d64eb53
commit 61225c2f20
14 changed files with 57 additions and 25 deletions

View File

@ -9,12 +9,12 @@ end
require_relative "ruby/statement"
require_relative "ruby/statements"
require_relative "ruby/assignment_statement"
require_relative "ruby/array_statement"
require_relative "ruby/block_statement"
require_relative "ruby/if_statement"
require_relative "ruby/normalizer"
require_relative "ruby/send_statement"
require_relative "ruby/assign_statement"
require_relative "ruby/class_statement"
require_relative "ruby/logical_statement"
require_relative "ruby/return_statement"
@ -24,5 +24,6 @@ require_relative "ruby/hash_statement"
require_relative "ruby/method_statement"
require_relative "ruby/ruby_compiler"
require_relative "ruby/yield_statement"
require_relative "ruby/variables"
require_relative "ruby/ruby_compiler"

View File

@ -6,7 +6,7 @@ module Ruby
@name , @value = name , value
end
def normalize()
def to_vool()
raise "not named left #{name.class}" unless name.is_a?(Symbol)
case value
when Named , Constant
@ -23,7 +23,7 @@ module Ruby
self.class.new(name,value)
end
def normalize_send
def to_vool_send
statements = value.normalize()
return copy( statements ) if statements.is_a?(SendStatement)
assign = statements.statements.pop
@ -31,11 +31,6 @@ module Ruby
statements
end
def chain_assign(assign , compiler)
return assign unless @value.is_a?(SendStatement)
@value.to_mom(compiler) << assign
end
def to_s(depth = 0)
at_depth(depth , "#{@name} = #{@value}")
end
@ -44,10 +39,14 @@ module Ruby
class IvarAssignment < Assignment
def normalize()
def to_vool()
super()
return IvarAssignment.new(@name , @value)
end
end
class LocalAssignment < Assignment
end
end

View File

@ -9,7 +9,7 @@ module Vool
@clazz = clazz
end
def normalize
def to_vool
BlockStatement.new( @args , @body.normalize)
end

View File

@ -16,7 +16,7 @@ module Ruby
end
end
def normalize
def to_vool
meths = body.statements.collect{|meth| meth.normalize}
ClassStatement.new(@name , @super_class_name, Statements.new(meths) )
end

View File

@ -12,7 +12,7 @@ module Ruby
@if_false = if_false
end
def normalize
def to_vool
cond , rest = *normalize_name(@condition)
fals = @if_false ? @if_false.normalize : nil
me = IfStatement.new(cond , @if_true.normalize, fals)

View File

@ -9,7 +9,7 @@ module Ruby
end
def normalize
def to_vool
MethodStatement.new( @name , @args , @body.normalize)
end

View File

@ -8,7 +8,7 @@ module Ruby
# but if(tmp_123) is with tmp_123 = @var % 5 hoisted above the if
#
# also constants count, though they may not be so useful in ifs, but returns
def normalize_name( condition )
def to_vool_name( condition )
if( condition.is_a?(ScopeStatement) and condition.single?)
condition = condition.first
end

View File

@ -8,7 +8,7 @@ module Ruby
@return_value = value
end
def normalize
def to_vool
val , rest = *normalize_name(@return_value)
me = ReturnStatement.new(val)
return me unless rest

View File

@ -8,7 +8,7 @@ module Ruby
@arguments ||= []
end
def normalize
def to_vool
statements = Statements.new([])
arguments = []
@arguments.each_with_index do |arg , index |
@ -22,7 +22,7 @@ module Ruby
end
end
def normalize_arg(arg , arguments , statements)
def to_vool_arg(arg , arguments , statements)
if arg.respond_to?(:slot_definition) and !arg.is_a?(SendStatement)
arguments << arg
return

View File

@ -16,7 +16,7 @@ module Ruby
class Expression
def normalize
def to_vool
raise "should not be normalized #{self}"
end

36
lib/ruby/variables.rb Normal file
View File

@ -0,0 +1,36 @@
module Ruby
module Named
attr_reader :name
def initialize name
@name = name
end
def each(&block)
end
end
class LocalVariable < Expression
include Named
def to_s
name.to_s
end
end
class InstanceVariable < Expression
include Named
# used to collect type information
def add_ivar( array )
array << @name
end
def to_s
"@#{name}"
end
end
class ClassVariable < Expression
include Named
end
class ModuleName < Expression
include Named
end
end

View File

@ -11,7 +11,7 @@ module Ruby
@body = body
end
def normalize
def to_vool
cond , rest = *normalize_name(@condition)
WhileStatement.new(cond , @body.normalize , rest)
end

View File

@ -8,7 +8,7 @@ module Ruby
@arguments ||= []
end
def normalize
def to_vool
statements = Statements.new([])
arguments = []
@arguments.each_with_index do |arg , index |
@ -22,7 +22,7 @@ module Ruby
end
end
def normalize_arg(arg , arguments , statements)
def to_vool_arg(arg , arguments , statements)
if arg.respond_to?(:slot_definition) and !arg.is_a?(YieldStatement)
arguments << arg
return

View File

@ -20,9 +20,5 @@ module Ruby
def test_method_yield?
assert_equal true , @lst.has_yield?
end
def test_method_args
Parfait.boot!
assert_equal 2 , @lst.make_arg_type.get_length
end
end
end