ifx most of the conversion
well . . it's still converting to ruby, minor detail
This commit is contained in:
parent
ae3d64eb53
commit
61225c2f20
@ -9,12 +9,12 @@ end
|
|||||||
|
|
||||||
require_relative "ruby/statement"
|
require_relative "ruby/statement"
|
||||||
require_relative "ruby/statements"
|
require_relative "ruby/statements"
|
||||||
|
require_relative "ruby/assignment_statement"
|
||||||
require_relative "ruby/array_statement"
|
require_relative "ruby/array_statement"
|
||||||
require_relative "ruby/block_statement"
|
require_relative "ruby/block_statement"
|
||||||
require_relative "ruby/if_statement"
|
require_relative "ruby/if_statement"
|
||||||
require_relative "ruby/normalizer"
|
require_relative "ruby/normalizer"
|
||||||
require_relative "ruby/send_statement"
|
require_relative "ruby/send_statement"
|
||||||
require_relative "ruby/assign_statement"
|
|
||||||
require_relative "ruby/class_statement"
|
require_relative "ruby/class_statement"
|
||||||
require_relative "ruby/logical_statement"
|
require_relative "ruby/logical_statement"
|
||||||
require_relative "ruby/return_statement"
|
require_relative "ruby/return_statement"
|
||||||
@ -24,5 +24,6 @@ require_relative "ruby/hash_statement"
|
|||||||
require_relative "ruby/method_statement"
|
require_relative "ruby/method_statement"
|
||||||
require_relative "ruby/ruby_compiler"
|
require_relative "ruby/ruby_compiler"
|
||||||
require_relative "ruby/yield_statement"
|
require_relative "ruby/yield_statement"
|
||||||
|
require_relative "ruby/variables"
|
||||||
|
|
||||||
require_relative "ruby/ruby_compiler"
|
require_relative "ruby/ruby_compiler"
|
||||||
|
@ -6,7 +6,7 @@ module Ruby
|
|||||||
@name , @value = name , value
|
@name , @value = name , value
|
||||||
end
|
end
|
||||||
|
|
||||||
def normalize()
|
def to_vool()
|
||||||
raise "not named left #{name.class}" unless name.is_a?(Symbol)
|
raise "not named left #{name.class}" unless name.is_a?(Symbol)
|
||||||
case value
|
case value
|
||||||
when Named , Constant
|
when Named , Constant
|
||||||
@ -23,7 +23,7 @@ module Ruby
|
|||||||
self.class.new(name,value)
|
self.class.new(name,value)
|
||||||
end
|
end
|
||||||
|
|
||||||
def normalize_send
|
def to_vool_send
|
||||||
statements = value.normalize()
|
statements = value.normalize()
|
||||||
return copy( statements ) if statements.is_a?(SendStatement)
|
return copy( statements ) if statements.is_a?(SendStatement)
|
||||||
assign = statements.statements.pop
|
assign = statements.statements.pop
|
||||||
@ -31,11 +31,6 @@ module Ruby
|
|||||||
statements
|
statements
|
||||||
end
|
end
|
||||||
|
|
||||||
def chain_assign(assign , compiler)
|
|
||||||
return assign unless @value.is_a?(SendStatement)
|
|
||||||
@value.to_mom(compiler) << assign
|
|
||||||
end
|
|
||||||
|
|
||||||
def to_s(depth = 0)
|
def to_s(depth = 0)
|
||||||
at_depth(depth , "#{@name} = #{@value}")
|
at_depth(depth , "#{@name} = #{@value}")
|
||||||
end
|
end
|
||||||
@ -44,10 +39,14 @@ module Ruby
|
|||||||
|
|
||||||
class IvarAssignment < Assignment
|
class IvarAssignment < Assignment
|
||||||
|
|
||||||
def normalize()
|
def to_vool()
|
||||||
super()
|
super()
|
||||||
return IvarAssignment.new(@name , @value)
|
return IvarAssignment.new(@name , @value)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class LocalAssignment < Assignment
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
@ -9,7 +9,7 @@ module Vool
|
|||||||
@clazz = clazz
|
@clazz = clazz
|
||||||
end
|
end
|
||||||
|
|
||||||
def normalize
|
def to_vool
|
||||||
BlockStatement.new( @args , @body.normalize)
|
BlockStatement.new( @args , @body.normalize)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ module Ruby
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def normalize
|
def to_vool
|
||||||
meths = body.statements.collect{|meth| meth.normalize}
|
meths = body.statements.collect{|meth| meth.normalize}
|
||||||
ClassStatement.new(@name , @super_class_name, Statements.new(meths) )
|
ClassStatement.new(@name , @super_class_name, Statements.new(meths) )
|
||||||
end
|
end
|
||||||
|
@ -12,7 +12,7 @@ module Ruby
|
|||||||
@if_false = if_false
|
@if_false = if_false
|
||||||
end
|
end
|
||||||
|
|
||||||
def normalize
|
def to_vool
|
||||||
cond , rest = *normalize_name(@condition)
|
cond , rest = *normalize_name(@condition)
|
||||||
fals = @if_false ? @if_false.normalize : nil
|
fals = @if_false ? @if_false.normalize : nil
|
||||||
me = IfStatement.new(cond , @if_true.normalize, fals)
|
me = IfStatement.new(cond , @if_true.normalize, fals)
|
||||||
|
@ -9,7 +9,7 @@ module Ruby
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def normalize
|
def to_vool
|
||||||
MethodStatement.new( @name , @args , @body.normalize)
|
MethodStatement.new( @name , @args , @body.normalize)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ module Ruby
|
|||||||
# but if(tmp_123) is with tmp_123 = @var % 5 hoisted above the if
|
# 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
|
# 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?)
|
if( condition.is_a?(ScopeStatement) and condition.single?)
|
||||||
condition = condition.first
|
condition = condition.first
|
||||||
end
|
end
|
||||||
|
@ -8,7 +8,7 @@ module Ruby
|
|||||||
@return_value = value
|
@return_value = value
|
||||||
end
|
end
|
||||||
|
|
||||||
def normalize
|
def to_vool
|
||||||
val , rest = *normalize_name(@return_value)
|
val , rest = *normalize_name(@return_value)
|
||||||
me = ReturnStatement.new(val)
|
me = ReturnStatement.new(val)
|
||||||
return me unless rest
|
return me unless rest
|
||||||
|
@ -8,7 +8,7 @@ module Ruby
|
|||||||
@arguments ||= []
|
@arguments ||= []
|
||||||
end
|
end
|
||||||
|
|
||||||
def normalize
|
def to_vool
|
||||||
statements = Statements.new([])
|
statements = Statements.new([])
|
||||||
arguments = []
|
arguments = []
|
||||||
@arguments.each_with_index do |arg , index |
|
@arguments.each_with_index do |arg , index |
|
||||||
@ -22,7 +22,7 @@ module Ruby
|
|||||||
end
|
end
|
||||||
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)
|
if arg.respond_to?(:slot_definition) and !arg.is_a?(SendStatement)
|
||||||
arguments << arg
|
arguments << arg
|
||||||
return
|
return
|
||||||
|
@ -16,7 +16,7 @@ module Ruby
|
|||||||
|
|
||||||
class Expression
|
class Expression
|
||||||
|
|
||||||
def normalize
|
def to_vool
|
||||||
raise "should not be normalized #{self}"
|
raise "should not be normalized #{self}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
36
lib/ruby/variables.rb
Normal file
36
lib/ruby/variables.rb
Normal 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
|
@ -11,7 +11,7 @@ module Ruby
|
|||||||
@body = body
|
@body = body
|
||||||
end
|
end
|
||||||
|
|
||||||
def normalize
|
def to_vool
|
||||||
cond , rest = *normalize_name(@condition)
|
cond , rest = *normalize_name(@condition)
|
||||||
WhileStatement.new(cond , @body.normalize , rest)
|
WhileStatement.new(cond , @body.normalize , rest)
|
||||||
end
|
end
|
||||||
|
@ -8,7 +8,7 @@ module Ruby
|
|||||||
@arguments ||= []
|
@arguments ||= []
|
||||||
end
|
end
|
||||||
|
|
||||||
def normalize
|
def to_vool
|
||||||
statements = Statements.new([])
|
statements = Statements.new([])
|
||||||
arguments = []
|
arguments = []
|
||||||
@arguments.each_with_index do |arg , index |
|
@arguments.each_with_index do |arg , index |
|
||||||
@ -22,7 +22,7 @@ module Ruby
|
|||||||
end
|
end
|
||||||
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)
|
if arg.respond_to?(:slot_definition) and !arg.is_a?(YieldStatement)
|
||||||
arguments << arg
|
arguments << arg
|
||||||
return
|
return
|
||||||
|
@ -20,9 +20,5 @@ module Ruby
|
|||||||
def test_method_yield?
|
def test_method_yield?
|
||||||
assert_equal true , @lst.has_yield?
|
assert_equal true , @lst.has_yield?
|
||||||
end
|
end
|
||||||
def test_method_args
|
|
||||||
Parfait.boot!
|
|
||||||
assert_equal 2 , @lst.make_arg_type.get_length
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user