diff --git a/Guardfile b/Guardfile index 59d4824a..9610dcfb 100644 --- a/Guardfile +++ b/Guardfile @@ -23,7 +23,7 @@ guard :minitest , all_on_start: false do # with Minitest::Unit watch(%r{^lib/parfait/type.rb}) { Dir["test/parfait/type/test_*.rb"] } # ruby compiler tests have a whole directory - watch(%r{^lib/rubyx/ruby_compiler.rb}) { Dir["test/rubyx/ruby_compiler/test_*.rb"] } + watch(%r{^lib/ruby/ruby_compiler.rb}) { Dir["test/ruby/test_*.rb"] } watch(%r{^lib/vool/statements/send_statement.rb}) { [ Dir["test/vool/send/test_*.rb"] ] } diff --git a/lib/rubyx.rb b/lib/rubyx.rb index 4602c687..62cf4f0e 100644 --- a/lib/rubyx.rb +++ b/lib/rubyx.rb @@ -1,12 +1,3 @@ -require "parser/ruby22" -require "ast" - -AST::Node.class_eval do - def first - children.first - end -end - require "rx-file" require "util/logging" @@ -15,5 +6,6 @@ require_relative "risc" require_relative "arm/arm_machine" require_relative "arm/arm_platform" require_relative "vool/statement" +require_relative "ruby" require_relative "rubyx/rubyx_compiler" require_relative "mom/mom" diff --git a/lib/rubyx/rubyx_compiler.rb b/lib/rubyx/rubyx_compiler.rb index 45b9aead..19c5934b 100644 --- a/lib/rubyx/rubyx_compiler.rb +++ b/lib/rubyx/rubyx_compiler.rb @@ -1,5 +1,3 @@ -require_relative "ruby_compiler" - module RubyX class RubyXCompiler attr_reader :source @@ -9,8 +7,8 @@ module RubyX end def ruby_to_vool - vool = RubyCompiler.compile( source ) - vool = vool.normalize + ruby = Ruby::RubyCompiler.compile( source ) + vool = ruby.to_vool vool end diff --git a/lib/vool/assign_statement.rb b/lib/vool/assign_statement.rb index df8f8854..f0d014fe 100644 --- a/lib/vool/assign_statement.rb +++ b/lib/vool/assign_statement.rb @@ -6,36 +6,6 @@ module Vool @name , @value = name , value end - def normalize() - raise "not named left #{name.class}" unless name.is_a?(Symbol) - case value - when Named , Constant - return copy - when SendStatement - return normalize_send - else - raise "unsupported right #{value}" - end - end - - def copy(value = nil) - value ||= @value - self.class.new(name,value) - end - - def normalize_send - statements = value.normalize() - return copy( statements ) if statements.is_a?(SendStatement) - assign = statements.statements.pop - statements << copy(assign) - statements - end - - def chain_assign(assign , compiler) - return assign unless @value.is_a?(SendStatement) - @value.to_mom(compiler) << assign - end - def each(&block) block.call(self) @value.each(&block) @@ -49,11 +19,6 @@ module Vool class IvarAssignment < Assignment - def normalize() - super() - return IvarAssignment.new(@name , @value) - end - def to_mom( compiler ) to = Mom::SlotDefinition.new(:message ,[ :receiver , @name]) from = @value.slot_definition(compiler) diff --git a/lib/vool/block_statement.rb b/lib/vool/block_statement.rb index 3e946ba3..233cd0f8 100644 --- a/lib/vool/block_statement.rb +++ b/lib/vool/block_statement.rb @@ -33,10 +33,6 @@ module Vool @body.each(&block) end - def normalize - BlockStatement.new( @args , @body.normalize) - end - # create the parfait block (parfait representation of the block, a Callable similar # to CallableMethod) def parfait_block(compiler) diff --git a/lib/vool/class_statement.rb b/lib/vool/class_statement.rb index a89bf78b..d7d76be1 100644 --- a/lib/vool/class_statement.rb +++ b/lib/vool/class_statement.rb @@ -17,11 +17,6 @@ module Vool end end - def normalize - meths = body.statements.collect{|meth| meth.normalize} - ClassStatement.new(@name , @super_class_name, Statements.new(meths) ) - end - def to_mom( _ ) create_class_object method_compilers = body.statements.collect do |node| diff --git a/lib/vool/if_statement.rb b/lib/vool/if_statement.rb index dfaad714..4bd8f1a3 100644 --- a/lib/vool/if_statement.rb +++ b/lib/vool/if_statement.rb @@ -1,7 +1,6 @@ -require_relative "normalizer" + module Vool class IfStatement < Statement - include Normalizer attr_reader :condition , :if_true , :if_false @@ -11,15 +10,6 @@ module Vool @if_false = if_false end - 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 - rest - end - def to_mom( compiler ) if_false ? full_if(compiler) : simple_if(compiler) end diff --git a/lib/vool/method_statement.rb b/lib/vool/method_statement.rb index 50ffaa41..baea66ce 100644 --- a/lib/vool/method_statement.rb +++ b/lib/vool/method_statement.rb @@ -23,10 +23,6 @@ module Vool @body.each(&block) end - def normalize - MethodStatement.new( @name , @args , @body.normalize) - end - def has_yield? each{|statement| return true if statement.is_a?(YieldStatement)} return false diff --git a/lib/vool/normalizer.rb b/lib/vool/normalizer.rb deleted file mode 100644 index 7574731e..00000000 --- a/lib/vool/normalizer.rb +++ /dev/null @@ -1,22 +0,0 @@ -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 hoisted above the if - # - # also constants count, though they may not be so useful in ifs, but returns - def normalize_name( condition ) - if( condition.is_a?(ScopeStatement) and condition.single?) - condition = condition.first - end - return [condition] if condition.is_a?(Named) or condition.is_a?(Constant) - condition = condition.normalize - local = "tmp_#{object_id}".to_sym - assign = Statements.new [LocalAssignment.new( local , condition)] - [LocalVariable.new(local) , assign] - end - end -end diff --git a/lib/vool/return_statement.rb b/lib/vool/return_statement.rb index ac045f33..86736e16 100644 --- a/lib/vool/return_statement.rb +++ b/lib/vool/return_statement.rb @@ -1,6 +1,5 @@ module Vool class ReturnStatement < Statement - include Normalizer attr_reader :return_value @@ -8,14 +7,6 @@ module Vool @return_value = value end - def normalize - val , rest = *normalize_name(@return_value) - me = ReturnStatement.new(val) - return me unless rest - rest << me - rest - end - def each(&block) block.call(@return_value) end diff --git a/lib/vool/send_statement.rb b/lib/vool/send_statement.rb index b9629c53..feca3bf6 100644 --- a/lib/vool/send_statement.rb +++ b/lib/vool/send_statement.rb @@ -27,30 +27,6 @@ module Vool @arguments << block end - def normalize - statements = Statements.new([]) - arguments = [] - @arguments.each_with_index do |arg , index | - normalize_arg(arg , arguments , statements) - end - if statements.empty? - return SendStatement.new(@name, @receiver , @arguments) - else - statements << SendStatement.new(@name, @receiver , arguments) - return statements - end - end - - def normalize_arg(arg , arguments , statements) - if arg.respond_to?(:slot_definition) and !arg.is_a?(SendStatement) - arguments << arg - return - end - assign = LocalAssignment.new( "tmp_#{arg.object_id}".to_sym, arg) - statements << assign - arguments << LocalVariable.new(assign.name) - end - def to_s "#{receiver}.#{name}(#{arguments.join(', ')})" end diff --git a/lib/vool/statement.rb b/lib/vool/statement.rb index 09d93b48..f0d22944 100644 --- a/lib/vool/statement.rb +++ b/lib/vool/statement.rb @@ -25,12 +25,6 @@ module Vool # class Statement - # after creation vool normalizes to ensure valid syntax and simplify - # also throw errors if violation - def normalize() - raise self.class.name - end - def to_mom( _ ) # temporary warning to find unimplemented kids raise "Not implemented for #{self}" diff --git a/lib/vool/statements.rb b/lib/vool/statements.rb index 22651ead..58fbb74c 100644 --- a/lib/vool/statements.rb +++ b/lib/vool/statements.rb @@ -44,13 +44,6 @@ module Vool @statements.each{|a| a.each(&block)} end - def normalize - if( single? ) - first.normalize - else - Statements.new(@statements.collect{|s| s.normalize}) - end - end def to_s(depth = 0) at_depth(depth , *@statements.collect{|st| st.to_s(depth)}) end @@ -58,12 +51,5 @@ module Vool end class ScopeStatement < Statements - def normalize - if( single? ) - first.normalize - else - ScopeStatement.new(@statements.collect{|s| s.normalize}) - end - end end end diff --git a/lib/vool/while_statement.rb b/lib/vool/while_statement.rb index b8e245e0..aa388df4 100644 --- a/lib/vool/while_statement.rb +++ b/lib/vool/while_statement.rb @@ -1,8 +1,6 @@ -require_relative "normalizer" module Vool class WhileStatement < Statement - include Normalizer attr_reader :condition , :body , :hoisted def initialize( condition , body , hoisted = nil) @@ -11,11 +9,6 @@ module Vool @body = body end - def normalize - cond , rest = *normalize_name(@condition) - WhileStatement.new(cond , @body.normalize , rest) - end - def to_mom( compiler ) merge_label = Mom::Label.new( "merge_label_#{object_id.to_s(16)}") cond_label = Mom::Label.new( "cond_label_#{object_id.to_s(16)}") diff --git a/lib/vool/yield_statement.rb b/lib/vool/yield_statement.rb index 69e16aaa..b8121d26 100644 --- a/lib/vool/yield_statement.rb +++ b/lib/vool/yield_statement.rb @@ -8,30 +8,6 @@ module Vool @arguments ||= [] end - def normalize - statements = Statements.new([]) - arguments = [] - @arguments.each_with_index do |arg , index | - normalize_arg(arg , arguments , statements) - end - if statements.empty? - return YieldStatement.new(@name, @receiver , @arguments) - else - statements << YieldStatement.new(@name, @receiver , arguments) - return statements - end - end - - def normalize_arg(arg , arguments , statements) - if arg.respond_to?(:slot_definition) and !arg.is_a?(YieldStatement) - arguments << arg - return - end - assign = LocalAssignment.new( "tmp_#{arg.object_id}".to_sym, arg) - statements << assign - arguments << LocalVariable.new(assign.name) - end - def to_s "#{receiver}.#{name}(#{arguments.join(', ')})" end