From f87526f86f675805dbd00fd6bb5edb7ad12f3568 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20R=C3=BCger?= Date: Mon, 19 Aug 2019 11:33:12 +0300 Subject: [PATCH] Renaming Vool exppressions rightly Class, Method and Lambda (was block) are expressions. Just making things clearer, especially for the blocks (ahem, lambdas) is matters. wip --- lib/mom/instruction/basic_values.rb | 8 ++-- lib/parfait.rb | 4 +- lib/parfait/data_object.rb | 4 +- lib/parfait/integer.rb | 2 - lib/parfait/vool_method.rb | 2 +- lib/ruby/class_method_statement.rb | 2 +- lib/ruby/class_statement.rb | 2 +- lib/ruby/method_statement.rb | 2 +- lib/ruby/return_statement.rb | 2 +- lib/ruby/ruby_block_statement.rb | 2 +- lib/ruby/statement.rb | 2 +- lib/ruby/statements.rb | 9 ++-- lib/vool/assignment.rb | 2 +- lib/vool/basic_values.rb | 21 ++++----- lib/vool/call_statement.rb | 2 +- ...class_statement.rb => class_expression.rb} | 4 +- ...tatement.rb => class_method_expression.rb} | 2 +- lib/vool/if_statement.rb | 2 +- ...mbda_statement.rb => lambda_expression.rb} | 4 +- ...thod_statement.rb => method_expression.rb} | 2 +- lib/vool/return_statement.rb | 2 +- lib/vool/send_statement.rb | 6 +-- lib/vool/statement.rb | 43 +++++++++---------- lib/vool/statements.rb | 14 +++++- lib/vool/variables.rb | 8 ++-- lib/vool/while_statement.rb | 2 +- lib/vool/yield_statement.rb | 4 +- test/ruby/helper.rb | 4 +- test/ruby/test_class_method_statement.rb | 4 +- test/ruby/test_class_statement.rb | 2 +- test/ruby/test_class_statement2.rb | 2 +- test/ruby/test_class_statement3.rb | 2 +- test/ruby/test_ruby_block_statement.rb | 2 +- test/ruby/test_ruby_block_statement1.rb | 2 +- test/ruby/test_variables.rb | 4 +- test/rubyx/parfait/test_data_object.rb | 41 ++++++++++++++++++ test/rubyx/parfait/test_integer.rb | 32 ++++++++++++++ test/vool/{blocks => lambdas}/helper.rb | 0 test/vool/{blocks => lambdas}/test_assign.rb | 0 .../{blocks => lambdas}/test_class_blocks.rb | 0 .../{blocks => lambdas}/test_if_condition.rb | 0 .../{blocks => lambdas}/test_while_simple.rb | 0 ..._statement.rb => test_class_expression.rb} | 0 ...statement.rb => test_method_expression.rb} | 0 44 files changed, 162 insertions(+), 92 deletions(-) rename lib/vool/{class_statement.rb => class_expression.rb} (97%) rename lib/vool/{class_method_statement.rb => class_method_expression.rb} (96%) rename lib/vool/{lambda_statement.rb => lambda_expression.rb} (96%) rename lib/vool/{method_statement.rb => method_expression.rb} (97%) create mode 100644 test/rubyx/parfait/test_data_object.rb create mode 100644 test/rubyx/parfait/test_integer.rb rename test/vool/{blocks => lambdas}/helper.rb (100%) rename test/vool/{blocks => lambdas}/test_assign.rb (100%) rename test/vool/{blocks => lambdas}/test_class_blocks.rb (100%) rename test/vool/{blocks => lambdas}/test_if_condition.rb (100%) rename test/vool/{blocks => lambdas}/test_while_simple.rb (100%) rename test/vool/{test_class_statement.rb => test_class_expression.rb} (100%) rename test/vool/{test_method_statement.rb => test_method_expression.rb} (100%) diff --git a/lib/mom/instruction/basic_values.rb b/lib/mom/instruction/basic_values.rb index f3402c4a..ec5a7270 100644 --- a/lib/mom/instruction/basic_values.rb +++ b/lib/mom/instruction/basic_values.rb @@ -5,13 +5,13 @@ module Mom class Constant end - class BlockConstant < Constant - attr_reader :block + class LambdaConstant < Constant + attr_reader :lambda def initialize(bl) - @block = bl + @lambda = bl end def to_parfait(compiler) - @block + @lambda end end diff --git a/lib/parfait.rb b/lib/parfait.rb index 35ab3f39..381efd5e 100644 --- a/lib/parfait.rb +++ b/lib/parfait.rb @@ -20,14 +20,12 @@ module Parfait end end - ["object" , "factory" ].each do |file_name| + ["object" , "data_object","integer","factory" ].each do |file_name| path = File.expand_path( "../parfait/#{file_name}.rb" , __FILE__) module_eval( File.read path) end end -require_relative "parfait/data_object" -require_relative "parfait/integer" require_relative "parfait/behaviour" require_relative "parfait/class" require_relative "parfait/meta_class" diff --git a/lib/parfait/data_object.rb b/lib/parfait/data_object.rb index 3f8b76ae..5cca15ca 100644 --- a/lib/parfait/data_object.rb +++ b/lib/parfait/data_object.rb @@ -19,11 +19,10 @@ # DataObjects still have a type, and so can have objects before the data starts # # A marker class -module Parfait class DataObject < Object def self.type_length - raise "called #{self}" + raise "called " + self.to_s end def padded_length self.class.memory_size * 4 @@ -53,4 +52,3 @@ module Parfait 32 end end -end diff --git a/lib/parfait/integer.rb b/lib/parfait/integer.rb index 5d660d9b..77be3532 100644 --- a/lib/parfait/integer.rb +++ b/lib/parfait/integer.rb @@ -1,4 +1,3 @@ -module Parfait # Integer class for representing maths on Integers # Integers are Objects, specifically DataObjects # - they have fixed value @@ -92,4 +91,3 @@ module Parfait 1 # 0 type end end -end diff --git a/lib/parfait/vool_method.rb b/lib/parfait/vool_method.rb index 603f0273..59023d30 100644 --- a/lib/parfait/vool_method.rb +++ b/lib/parfait/vool_method.rb @@ -23,7 +23,7 @@ module Parfait raise "Name must be symbol" unless name.is_a?(Symbol) raise "args_type must be type" unless args_type.is_a?(Parfait::Type) raise "frame_type must be type" unless frame_type.is_a?(Parfait::Type) - raise "source must be vool" unless source.is_a?(Vool::Statement) + raise "source must be vool not#{source.class}" unless source.is_a?(Vool::Statement) raise "Empty bod" if(@source.is_a?(Vool::Statements) and @source.empty?) end diff --git a/lib/ruby/class_method_statement.rb b/lib/ruby/class_method_statement.rb index 753d718f..faf60240 100644 --- a/lib/ruby/class_method_statement.rb +++ b/lib/ruby/class_method_statement.rb @@ -2,7 +2,7 @@ module Ruby class ClassMethodStatement < MethodStatement def to_vool - Vool::ClassMethodStatement.new( @name , @args.dup , @body.to_vool) + Vool::ClassMethodExpression.new( @name , @args.dup , @body.to_vool) end def to_s(depth = 0) diff --git a/lib/ruby/class_statement.rb b/lib/ruby/class_statement.rb index bd0e4c6f..32a8334f 100644 --- a/lib/ruby/class_statement.rb +++ b/lib/ruby/class_statement.rb @@ -29,7 +29,7 @@ module Ruby meths += transform_statement(meth) end end - Vool::ClassStatement.new(@name , @super_class_name, Vool::Statements.new(meths) ) + Vool::ClassExpression.new(@name , @super_class_name, Vool::Statements.new(meths) ) end # We rewrite certain send statements (so raise error for all else) diff --git a/lib/ruby/method_statement.rb b/lib/ruby/method_statement.rb index e95b0ec3..d32f13f6 100644 --- a/lib/ruby/method_statement.rb +++ b/lib/ruby/method_statement.rb @@ -14,7 +14,7 @@ module Ruby else @body = replace_return( @body ) end - Vool::MethodStatement.new( @name , @args.dup , @body.to_vool) + Vool::MethodExpression.new( @name , @args.dup , @body.to_vool) end def replace_return(statement) diff --git a/lib/ruby/return_statement.rb b/lib/ruby/return_statement.rb index cfed6a8d..1afb85cb 100644 --- a/lib/ruby/return_statement.rb +++ b/lib/ruby/return_statement.rb @@ -5,7 +5,7 @@ module Ruby attr_reader :return_value def initialize(value) - @return_value = value || NilConstant.new + @return_value = value || NilConstant.new end def to_vool diff --git a/lib/ruby/ruby_block_statement.rb b/lib/ruby/ruby_block_statement.rb index 8947dde0..64e31b67 100644 --- a/lib/ruby/ruby_block_statement.rb +++ b/lib/ruby/ruby_block_statement.rb @@ -20,7 +20,7 @@ module Ruby # def to_vool block_name = "implicit_block_#{object_id}".to_sym - block = Vool::LambdaStatement.new( @args.dup , @body.to_vool) + block = Vool::LambdaExpression.new( @args.dup , @body.to_vool) assign = Vool::LocalAssignment.new( block_name , block) sendd = @send.to_vool if(sendd.is_a?(Vool::Statements)) diff --git a/lib/ruby/statement.rb b/lib/ruby/statement.rb index ef8efb14..17ea1247 100644 --- a/lib/ruby/statement.rb +++ b/lib/ruby/statement.rb @@ -10,7 +10,7 @@ module Ruby # Many statements exist in the vool layer in quite a similar arrangement # Especially for different types of assignment we can abstract the creation # of the vool, by using the right class to instantiate, the "vool_brother" - # Ie same class_name, but in the Vool module + # Ie same class_name, but in the Vool module def vool_brother eval "Vool::#{class_name}" end diff --git a/lib/ruby/statements.rb b/lib/ruby/statements.rb index 653c75cf..e8182307 100644 --- a/lib/ruby/statements.rb +++ b/lib/ruby/statements.rb @@ -34,11 +34,12 @@ module Ruby self end def to_vool - if( single? ) - first.to_vool - else - vool_brother.new(@statements.collect{|s| s.to_vool}) + return first.to_vool if( single? ) + brother = vool_brother.new(nil) + @statements.each do |s| + brother << s.to_vool end + brother end def to_s(depth = 0) diff --git a/lib/vool/assignment.rb b/lib/vool/assignment.rb index 163c3879..35f138ed 100644 --- a/lib/vool/assignment.rb +++ b/lib/vool/assignment.rb @@ -33,7 +33,7 @@ module Vool # Derived classes do not implement to_mom, only slot_position def to_mom(compiler) to = Mom::SlotDefinition.new(:message , self.slot_position(compiler)) - from = @value.slot_definition(compiler) + from = @value.to_slot(compiler) assign = Mom::SlotLoad.new(self,to,from) return assign unless @value.is_a?(CallStatement) @value.to_mom(compiler) << assign diff --git a/lib/vool/basic_values.rb b/lib/vool/basic_values.rb index a65ef96b..3fe511d6 100644 --- a/lib/vool/basic_values.rb +++ b/lib/vool/basic_values.rb @@ -1,9 +1,6 @@ module Vool #Marker class for different constants class Constant < Expression - #gobble it up - def each(&block) - end end # An integer at the vool level @@ -12,17 +9,15 @@ module Vool def initialize(value) @value = value end - def slot_definition(_) + def to_slot(_) return Mom::SlotDefinition.new(Mom::IntegerConstant.new(@value) , []) end def ct_type Parfait.object_space.get_type_by_class_name(:Integer) end - def to_s + def to_s(depth = 0) value.to_s end - def each(&block) - end end # An float at the vool level class FloatConstant < Constant @@ -33,7 +28,7 @@ module Vool def ct_type true end - def to_s + def to_s(depth = 0) value.to_s end end @@ -42,7 +37,7 @@ module Vool def ct_type Parfait.object_space.get_type_by_class_name(:True) end - def slot_definition(_) + def to_slot(_) return Mom::SlotDefinition.new(Parfait.object_space.true_object , []) end def to_s(depth = 0) @@ -54,7 +49,7 @@ module Vool def ct_type Parfait.object_space.get_type_by_class_name(:False) end - def slot_definition(_) + def to_slot(_) return Mom::SlotDefinition.new(Parfait.object_space.false_object , []) end def to_s(depth = 0) @@ -66,7 +61,7 @@ module Vool def ct_type Parfait.object_space.get_type_by_class_name(:Nil) end - def slot_definition(_) + def to_slot(_) return Mom::SlotDefinition.new(Parfait.object_space.nil_object , []) end def to_s(depth = 0) @@ -80,7 +75,7 @@ module Vool def initialize(type = nil) @my_type = type end - def slot_definition(compiler) + def to_slot(compiler) @my_type = compiler.receiver_type Mom::SlotDefinition.new(:message , [:receiver]) end @@ -101,7 +96,7 @@ module Vool def initialize(value) @value = value end - def slot_definition(_) + def to_slot(_) return Mom::SlotDefinition.new(Mom::StringConstant.new(@value),[]) end def ct_type diff --git a/lib/vool/call_statement.rb b/lib/vool/call_statement.rb index fc5ca5ab..6c2e25a3 100644 --- a/lib/vool/call_statement.rb +++ b/lib/vool/call_statement.rb @@ -10,7 +10,7 @@ module Vool # When used as right hand side, this tells what data to move to get the result into # a varaible. It is (off course) the return value of the message - def slot_definition(_) + def to_slot(_) Mom::SlotDefinition.new(:message ,[ :return_value]) end diff --git a/lib/vool/class_statement.rb b/lib/vool/class_expression.rb similarity index 97% rename from lib/vool/class_statement.rb rename to lib/vool/class_expression.rb index 5657fd5e..3cfd5cd8 100644 --- a/lib/vool/class_statement.rb +++ b/lib/vool/class_expression.rb @@ -8,14 +8,14 @@ module Vool # # The Parfait class gets created lazily on the way down to mom, ie the clazz # attribute will only be set after to_mom, or a direct call to create_class - class ClassStatement < Statement + class ClassExpression < Expression attr_reader :name, :super_class_name , :body attr_reader :clazz def initialize( name , supe , body) @name , @super_class_name = name , supe case body - when MethodStatement + when MethodExpression @body = Statements.new([body]) when Statements @body = body diff --git a/lib/vool/class_method_statement.rb b/lib/vool/class_method_expression.rb similarity index 96% rename from lib/vool/class_method_statement.rb rename to lib/vool/class_method_expression.rb index 076dacd4..9b4ab97e 100644 --- a/lib/vool/class_method_statement.rb +++ b/lib/vool/class_method_expression.rb @@ -1,5 +1,5 @@ module Vool - class ClassMethodStatement < Statement + class ClassMethodExpression < Expression attr_reader :name, :args , :body def initialize( name , args , body ) diff --git a/lib/vool/if_statement.rb b/lib/vool/if_statement.rb index b97a21e5..c7ebd829 100644 --- a/lib/vool/if_statement.rb +++ b/lib/vool/if_statement.rb @@ -15,7 +15,7 @@ module Vool false_label = Mom::Label.new( self , "false_label_#{object_id.to_s(16)}") merge_label = Mom::Label.new( self , "merge_label_#{object_id.to_s(16)}") - check = Mom::TruthCheck.new(condition.slot_definition(compiler) , false_label) + check = Mom::TruthCheck.new(condition.to_slot(compiler) , false_label) if @condition.is_a?(CallStatement) head = @condition.to_mom(compiler) head << check diff --git a/lib/vool/lambda_statement.rb b/lib/vool/lambda_expression.rb similarity index 96% rename from lib/vool/lambda_statement.rb rename to lib/vool/lambda_expression.rb index a91c26cd..7dc1d424 100644 --- a/lib/vool/lambda_statement.rb +++ b/lib/vool/lambda_expression.rb @@ -1,5 +1,5 @@ module Vool - class LambdaStatement < Statement + class LambdaExpression < Expression attr_reader :args , :body , :clazz def initialize( args , body , clazz = nil) @@ -13,7 +13,7 @@ module Vool # # This means we do the compiler here (rather than to_mom, which is in # fact never called) - def slot_definition(compiler) + def to_slot(compiler) return Mom::SlotDefinition.new(Mom::LambdaConstant.new(parfait_block(compiler)) , []) end diff --git a/lib/vool/method_statement.rb b/lib/vool/method_expression.rb similarity index 97% rename from lib/vool/method_statement.rb rename to lib/vool/method_expression.rb index bc2b3fd0..96abf790 100644 --- a/lib/vool/method_statement.rb +++ b/lib/vool/method_expression.rb @@ -1,5 +1,5 @@ module Vool - class MethodStatement < Statement + class MethodExpression < Expression attr_reader :name, :args , :body def initialize( name , args , body ) diff --git a/lib/vool/return_statement.rb b/lib/vool/return_statement.rb index ccb0a230..a19643ba 100644 --- a/lib/vool/return_statement.rb +++ b/lib/vool/return_statement.rb @@ -18,7 +18,7 @@ module Vool # - activate return sequence (reinstantiate old message and jump to return address) def to_mom( compiler ) load = Mom::SlotLoad.new( self , [:message , :return_value] , - @return_value.slot_definition(compiler) ) + @return_value.to_slot(compiler) ) if @return_value.is_a?(CallStatement) ret = @return_value.to_mom(compiler) ret << load diff --git a/lib/vool/send_statement.rb b/lib/vool/send_statement.rb index d547f0ad..15f4dd49 100644 --- a/lib/vool/send_statement.rb +++ b/lib/vool/send_statement.rb @@ -46,11 +46,11 @@ module Vool def message_setup(compiler,called_method) setup = Mom::MessageSetup.new( called_method ) - mom_receive = @receiver.slot_definition(compiler) + mom_receive = @receiver.to_slot(compiler) arg_target = [:message , :next_message , :arguments] args = [] @arguments.each_with_index do |arg , index| # +1 because of type - args << Mom::SlotLoad.new(self, arg_target + [index + 1] , arg.slot_definition(compiler)) + args << Mom::SlotLoad.new(self, arg_target + [index + 1] , arg.to_slot(compiler)) end setup << Mom::ArgumentTransfer.new(self, mom_receive , args ) end @@ -90,7 +90,7 @@ module Vool private def receiver_type_definition(compiler) - defi = @receiver.slot_definition(compiler) + defi = @receiver.to_slot(compiler) defi.slots << :type defi end diff --git a/lib/vool/statement.rb b/lib/vool/statement.rb index 8aea9849..aab229e2 100644 --- a/lib/vool/statement.rb +++ b/lib/vool/statement.rb @@ -2,7 +2,7 @@ # Object Oriented # Language # -# VOOL is the abstraction of ruby, ruby minus some of the fluff +# VOOL is the abstraction of ruby, ruby minusthe fluff # fluff is generally what makes ruby nice to use, like 3 ways to achieve the same thing # if/unless/ternary , reverse ifs (ie statement if condition), reverse whiles, # implicit blocks, splats and multiple assigns etc @@ -10,19 +10,17 @@ # Also, Vool is a typed tree, not abstract, so there is a base class Statement # and all it's derivation that make up the syntax tree # -# Also Vool has expression and statements and simple syntax. So returns must be explicit -# not everthing is just assignable, ifs can only test simple expressions etc (wip) -# -# This allows us to write compilers or passes of the compiler(s) as functions on the -# classes. -# +# Also Vool has expression and statements, revealing that age old dichotomy of code and +# data. Statements represent code whereas Expressions resolve to data. +# (in ruby there are no pure statements, everthing resolves to data) module Vool # Base class for all statements in the tree. Derived classes correspond to known language # constructs # - # Compilers or compiler passes are written by implementing methods. - # + # Basically Statements represent code, generally speaking code "does things". + # But Vool distinguishes Expressions (see below), that represent data, and as such + # don't do things themselves, rather passively participate in being pushed around class Statement def to_mom( _ ) @@ -37,7 +35,13 @@ module Vool end - class Expression + # An Expression is a Statement that represents data. ie variables constants + # (see basic_values) , but alos classes, methods and lambdas + class Expression < Statement + + def each(&block) + block.call(self) + end def ct_type nil @@ -46,20 +50,13 @@ module Vool def normalize raise "should not be normalized #{self}" end - def to_mom(compiler) - raise "should not be momed #{self}" - end - # for loading into a lot, return the "slot_definition" that can be passed to + # for loading into a slot, return the "slot_definition" that can be passed to # SlotLoad. - def slot_definition(compiler) + def to_slot(compiler) raise "not iplemented in #{self}" end - def at_depth(depth , *strings) - prefix = " " * 2 * depth - strings.collect{|str| prefix + str}.join("\n") - end end end @@ -67,14 +64,14 @@ end require_relative "assignment" require_relative "basic_values" -require_relative "block_statement" require_relative "call_statement" -require_relative "class_statement" +require_relative "class_expression" require_relative "if_statement" require_relative "ivar_assignment" +require_relative "lambda_expression" require_relative "local_assignment" -require_relative "method_statement" -require_relative "class_method_statement" +require_relative "method_expression" +require_relative "class_method_expression" require_relative "return_statement" require_relative "statements" require_relative "send_statement" diff --git a/lib/vool/statements.rb b/lib/vool/statements.rb index 4a60c67e..39d717d1 100644 --- a/lib/vool/statements.rb +++ b/lib/vool/statements.rb @@ -36,13 +36,18 @@ module Vool end def <<(o) if(o.is_a?(Statements)) - o.each {|s| @statements << s } + o.statements.each do |s| + raise "not a statement #{s}" unless s.is_a?(Statement) + @statements << s + end else + raise "not a statement #{o}" unless o.is_a?(Statement) @statements << o end self end def prepend(o) + raise "not a statement #{o}" unless o.is_a?(Statement) @statements = [o] + @statements end def shift @@ -62,7 +67,12 @@ module Vool stats = @statements.dup first = stats.shift.to_mom(compiler) while( nekst = stats.shift ) - first.append nekst.to_mom(compiler) + next_mom = nekst.to_mom(compiler) + if next_mom.is_a?(Mom::BlockCompiler) + compiler.block_compilers << next_mom + else + first.append next_mom + end end first end diff --git a/lib/vool/variables.rb b/lib/vool/variables.rb index 644cc23b..8b2ad1e4 100644 --- a/lib/vool/variables.rb +++ b/lib/vool/variables.rb @@ -10,11 +10,11 @@ module Vool class LocalVariable < Expression include Named - def slot_definition(compiler) + def to_slot(compiler) slot_def = compiler.slot_type_for(@name) Mom::SlotDefinition.new(:message , slot_def) end - def to_s + def to_s(depth = 0) name.to_s end def each(&block) @@ -24,7 +24,7 @@ module Vool class InstanceVariable < Expression include Named - def slot_definition(_) + def to_slot(_) Mom::SlotDefinition.new(:message , [ :receiver , @name] ) end # used to collect type information @@ -51,7 +51,7 @@ module Vool def ct_type get_named_class.meta_class.instance_type end - def slot_definition(_) + def to_slot(_) return Mom::SlotDefinition.new( get_named_class, []) end def get_named_class diff --git a/lib/vool/while_statement.rb b/lib/vool/while_statement.rb index c192c9ea..4622f064 100644 --- a/lib/vool/while_statement.rb +++ b/lib/vool/while_statement.rb @@ -15,7 +15,7 @@ module Vool codes = cond_label codes << @hoisted.to_mom(compiler) if @hoisted codes << @condition.to_mom(compiler) if @condition.is_a?(SendStatement) - codes << Mom::TruthCheck.new(condition.slot_definition(compiler) , merge_label) + codes << Mom::TruthCheck.new(condition.to_slot(compiler) , merge_label) codes << @body.to_mom(compiler) codes << Mom::Jump.new(cond_label) codes << merge_label diff --git a/lib/vool/yield_statement.rb b/lib/vool/yield_statement.rb index 0170318c..13e1ac15 100644 --- a/lib/vool/yield_statement.rb +++ b/lib/vool/yield_statement.rb @@ -49,11 +49,11 @@ module Vool def yield_arg_block(compiler) arg_index = compiler.get_method.arguments_type.get_length - 1 setup = Mom::MessageSetup.new( arg_index ) - mom_receive = @receiver.slot_definition(compiler) + mom_receive = @receiver.to_slot(compiler) arg_target = [:message , :next_message , :arguments] args = [] @arguments.each_with_index do |arg , index| # +1 because of type - args << Mom::SlotLoad.new(self, arg_target + [index + 1] , arg.slot_definition(compiler)) + args << Mom::SlotLoad.new(self, arg_target + [index + 1] , arg.to_slot(compiler)) end setup << Mom::ArgumentTransfer.new( self , mom_receive , args ) setup << Mom::BlockYield.new( self , arg_index ) diff --git a/test/ruby/helper.rb b/test/ruby/helper.rb index 0e6b2b12..e5c7d3cd 100644 --- a/test/ruby/helper.rb +++ b/test/ruby/helper.rb @@ -29,13 +29,13 @@ module Ruby @vool.body.statements.last end def test_class - assert_equal Vool::ClassStatement , @vool.class + assert_equal Vool::ClassExpression , @vool.class end def test_body assert_equal Vool::Statements , @vool.body.class end def test_getter - assert_equal Vool::MethodStatement , getter.class + assert_equal Vool::MethodExpression , getter.class end def test_getter_return assert_equal Vool::ReturnStatement , getter.body.class diff --git a/test/ruby/test_class_method_statement.rb b/test/ruby/test_class_method_statement.rb index 96137616..79874bab 100644 --- a/test/ruby/test_class_method_statement.rb +++ b/test/ruby/test_class_method_statement.rb @@ -18,7 +18,7 @@ module Ruby input = "def self.tryout(arg) ; arg = true ; return arg ; end " @str = compile( input ).to_s assert @str.include?("def self.tryou"), @str - assert @str.include?("arg = true"), @str + assert @str.include?("arg = true"), @str end end class TestClassMethodStatement2 < MiniTest::Test @@ -43,7 +43,7 @@ module Ruby @lst = compile( input ).to_vool end def test_method - assert_equal Vool::ClassMethodStatement , @lst.class + assert_equal Vool::ClassMethodExpression , @lst.class end def test_method_args assert_equal [:arg1, :arg2] , @lst.args diff --git a/test/ruby/test_class_statement.rb b/test/ruby/test_class_statement.rb index 6d9f3ecf..ccb0a3a1 100644 --- a/test/ruby/test_class_statement.rb +++ b/test/ruby/test_class_statement.rb @@ -9,7 +9,7 @@ module Ruby @vool = compile( input ).to_vool end def test_class - assert_equal Vool::ClassStatement , @vool.class + assert_equal Vool::ClassExpression , @vool.class end def test_body assert_equal Vool::Statements , @vool.body.class diff --git a/test/ruby/test_class_statement2.rb b/test/ruby/test_class_statement2.rb index b71a458f..6edcbd89 100644 --- a/test/ruby/test_class_statement2.rb +++ b/test/ruby/test_class_statement2.rb @@ -12,7 +12,7 @@ module Ruby assert_equal 2 , @vool.body.length , "setter, getter" end def test_setter - assert_equal Vool::MethodStatement , setter.class + assert_equal Vool::MethodExpression , setter.class end def test_setter_assign assert_equal Vool::Statements , setter.body.class diff --git a/test/ruby/test_class_statement3.rb b/test/ruby/test_class_statement3.rb index dab662aa..5e9b2d23 100644 --- a/test/ruby/test_class_statement3.rb +++ b/test/ruby/test_class_statement3.rb @@ -11,7 +11,7 @@ module Ruby assert_equal 4 , @vool.body.length , "2 setters, 2 getters" end def test_setter - assert_equal Vool::MethodStatement , setter.class + assert_equal Vool::MethodExpression , setter.class end def test_setter_assign assert_equal Vool::Statements , setter.body.class diff --git a/test/ruby/test_ruby_block_statement.rb b/test/ruby/test_ruby_block_statement.rb index 50172fba..ae96c0ac 100644 --- a/test/ruby/test_ruby_block_statement.rb +++ b/test/ruby/test_ruby_block_statement.rb @@ -38,7 +38,7 @@ module Ruby def test_first assert_equal Vool::LocalAssignment , @lst.first.class assert @lst.first.name.to_s.start_with?("implicit_block_") - assert_equal Vool::LambdaStatement , @lst.first.value.class + assert_equal Vool::LambdaExpression , @lst.first.value.class end def test_last_send assert_equal 2 , @lst.length diff --git a/test/ruby/test_ruby_block_statement1.rb b/test/ruby/test_ruby_block_statement1.rb index 125672ab..fa967e60 100644 --- a/test/ruby/test_ruby_block_statement1.rb +++ b/test/ruby/test_ruby_block_statement1.rb @@ -41,7 +41,7 @@ module Ruby assert @lst.first.first.name.to_s.start_with?("implicit_block") end def test_block_assign_right - assert_equal Vool::LambdaStatement , @lst.first.first.value.class + assert_equal Vool::LambdaExpression , @lst.first.first.value.class end def test_a_assign assert_equal Vool::LocalAssignment , @lst.first.last.class diff --git a/test/ruby/test_variables.rb b/test/ruby/test_variables.rb index 754f91c0..5faad74d 100644 --- a/test/ruby/test_variables.rb +++ b/test/ruby/test_variables.rb @@ -55,8 +55,8 @@ module Ruby class TestVariablesVool < MiniTest::Test include RubyTests def test_local_basic - lst = compile( "foo = 1 ; foo").to_vool - assert_equal Vool::LocalVariable , lst.statements[1].class + lst = compile( "foo = 1 ; return foo").to_vool + assert_equal Vool::LocalVariable , lst.statements[1].return_value.class end def test_instance_basic diff --git a/test/rubyx/parfait/test_data_object.rb b/test/rubyx/parfait/test_data_object.rb new file mode 100644 index 00000000..4f2497e1 --- /dev/null +++ b/test/rubyx/parfait/test_data_object.rb @@ -0,0 +1,41 @@ +require_relative "helper" + +module RubyX + + class TestDatObjectCompile #< MiniTest::Test + include ParfaitHelper + def setup + @compiler = compiler + @compiler.ruby_to_vool load_parfait(:object) + end + def source + load_parfait(:data_object) + end + def test_load + assert source.include?("class DataObject") + assert source.length > 1500 , source.length + end + def test_vool + vool = @compiler.ruby_to_vool source + assert_equ Vool::ScopeStatement , vool.class + assert_equal Vool::ClassStatement , vool[0].class + assert_equal Vool::ScopeStatement , vool[1].class + assert_equal Vool::ClassStatement , vool[1][0].class + assert_equal :DataObject , vool[1][0].name + assert_equal :Data4 , vool[1][1].name + assert_equal :Data8 , vool[1][2].name + end + def test_mom + mom = @compiler.ruby_to_mom source + assert_equal Mom::MomCollection , mom.class + end + def qtest_risc + risc = compiler.ruby_to_risc source + assert_equal Risc::RiscCollection , risc.class + end + def qtest_binary + risc = compiler.ruby_to_binary source , :interpreter + assert_equal Risc::Linker , risc.class + end + end +end diff --git a/test/rubyx/parfait/test_integer.rb b/test/rubyx/parfait/test_integer.rb new file mode 100644 index 00000000..3bf8a885 --- /dev/null +++ b/test/rubyx/parfait/test_integer.rb @@ -0,0 +1,32 @@ +require_relative "helper" + +module RubyX + + class TestIntegerCompile < MiniTest::Test + include ParfaitHelper + def source + load_parfait(:integer) + end + def test_load + assert source.include?("class Integer") + assert source.length > 2000 + end + def qtest_vool + vool = compiler.ruby_to_vool source + assert_equal Vool::ClassStatement , vool.class + assert_equal :Object , vool.name + end + def qtest_mom + mom = compiler.ruby_to_mom source + assert_equal Mom::MomCollection , mom.class + end + def qtest_risc + risc = compiler.ruby_to_risc source + assert_equal Risc::RiscCollection , risc.class + end + def qtest_binary + risc = compiler.ruby_to_binary source , :interpreter + assert_equal Risc::Linker , risc.class + end + end +end diff --git a/test/vool/blocks/helper.rb b/test/vool/lambdas/helper.rb similarity index 100% rename from test/vool/blocks/helper.rb rename to test/vool/lambdas/helper.rb diff --git a/test/vool/blocks/test_assign.rb b/test/vool/lambdas/test_assign.rb similarity index 100% rename from test/vool/blocks/test_assign.rb rename to test/vool/lambdas/test_assign.rb diff --git a/test/vool/blocks/test_class_blocks.rb b/test/vool/lambdas/test_class_blocks.rb similarity index 100% rename from test/vool/blocks/test_class_blocks.rb rename to test/vool/lambdas/test_class_blocks.rb diff --git a/test/vool/blocks/test_if_condition.rb b/test/vool/lambdas/test_if_condition.rb similarity index 100% rename from test/vool/blocks/test_if_condition.rb rename to test/vool/lambdas/test_if_condition.rb diff --git a/test/vool/blocks/test_while_simple.rb b/test/vool/lambdas/test_while_simple.rb similarity index 100% rename from test/vool/blocks/test_while_simple.rb rename to test/vool/lambdas/test_while_simple.rb diff --git a/test/vool/test_class_statement.rb b/test/vool/test_class_expression.rb similarity index 100% rename from test/vool/test_class_statement.rb rename to test/vool/test_class_expression.rb diff --git a/test/vool/test_method_statement.rb b/test/vool/test_method_expression.rb similarity index 100% rename from test/vool/test_method_statement.rb rename to test/vool/test_method_expression.rb