diff --git a/lib/parfait.rb b/lib/parfait.rb index 9b1724f4..894b75ba 100644 --- a/lib/parfait.rb +++ b/lib/parfait.rb @@ -10,6 +10,7 @@ require_relative "parfait/list" require_relative "parfait/word" require_relative "parfait/binary_code" require_relative "parfait/typed_method" +require_relative "parfait/vool_method" require_relative "parfait/dictionary" require_relative "parfait/type" require_relative "parfait/message" diff --git a/lib/parfait/class.rb b/lib/parfait/class.rb index 721570c3..cd063f77 100644 --- a/lib/parfait/class.rb +++ b/lib/parfait/class.rb @@ -1,4 +1,4 @@ -# Class is mainly a list of methods with a name. The methods are untyped. +# Class is mainly a list of methods with a name. The methods are untyped, sis Vool. # The memory layout of an object is determined by the Type (see there). # The class carries the "current" type, ie the type an object would be if you created an instance @@ -36,6 +36,7 @@ module Parfait end def add_method(method) + raise "Must be untyped method #{method}" unless method.is_a? Parfait::VoolMethod @methods[method.name] = method end diff --git a/lib/parfait/typed_method.rb b/lib/parfait/typed_method.rb index 12ba43d2..74d519e1 100644 --- a/lib/parfait/typed_method.rb +++ b/lib/parfait/typed_method.rb @@ -1,6 +1,5 @@ # A TypedMethod is static object that primarily holds the executable code. # It is called typed, because all arguments and variables it uses are typed. -# (Type means basic type, ie integer or reference) # It's relation to the method a ruby programmer knows (called RubyMethod) is many to one, # meaning one RubyMethod (untyped) has many TypedMethod implementations. diff --git a/lib/vool/vool_method.rb b/lib/parfait/vool_method.rb similarity index 62% rename from lib/vool/vool_method.rb rename to lib/parfait/vool_method.rb index 26826d07..036d33ce 100644 --- a/lib/vool/vool_method.rb +++ b/lib/parfait/vool_method.rb @@ -1,5 +1,15 @@ -module Vool +module Parfait + # This represents the method at source code level (sis vool) + # + # Type objects are already created for args and locals, but the main attribute + # is the source, which is a Vool::Statement + # + # Classes store VoolMethods, while Types store TypedMethod + # A Type referes to a Class , but a Class (interface) is implemented by many types + # as it changes during the course of it's life. Types do not change. Objects have + # type, and so only indirectly a class. + # class VoolMethod attr_reader :name , :args_type , :locals_type , :source @@ -9,6 +19,7 @@ module Vool raise "Name must be symbol" unless name.is_a?(Symbol) raise "args_type must be type" unless args_type.is_a?(Parfait::Type) raise "locals_type must be type" unless locals_type.is_a?(Parfait::Type) + raise "source must be vool" unless source.is_a?(Vool::Statement) end def normalize_source diff --git a/lib/vool.rb b/lib/vool.rb index e7cb4cfa..170eb220 100644 --- a/lib/vool.rb +++ b/lib/vool.rb @@ -1,2 +1 @@ require_relative "vool/vool_compiler" -require_relative "vool/vool_method" diff --git a/lib/vool/README.md b/lib/vool/README.md index c510696b..4e52f692 100644 --- a/lib/vool/README.md +++ b/lib/vool/README.md @@ -1,6 +1,7 @@ # VOOL Virtual Object Oriented Language +-------------------------------- in other words, ruby without the fluff. @@ -11,7 +12,7 @@ Possibly later other languages can compile to this level, eg by running in the s Vool is the layer of concrete syntax tree. The Parser gem is used to parse ruby. It creates an abstract syntax tree which is then transformed. -The next layer down is the Vom, Virtual object Machine, which uses an instruction tree. +The next layer down is the Mom, Minimal object Machine, which uses an instruction tree. That is on the way down we create instructions, but stay in tree format. Only the next step down to the Risc layer moves to an instruction stream. diff --git a/lib/vool/statements/method_statement.rb b/lib/vool/statements/method_statement.rb index 20858b06..a9abd739 100644 --- a/lib/vool/statements/method_statement.rb +++ b/lib/vool/statements/method_statement.rb @@ -31,9 +31,16 @@ module Vool def create_objects args_type = make_type locals_type = make_locals - method = Vool::VoolMethod.new(name , args_type , locals_type , body ) + method = Parfait::VoolMethod.new(name , args_type , locals_type , body ) @clazz.add_method( method ) - # compile_methods(clazz,methods) + end + + def compile_methods(clazz , methods) + methods.each do |method| + code = Passes::MethodCompiler.new(method).get_code + typed_method = method.create_parfait_method(clazz.instance_type) + Vm::MethodCompiler.new( typed_method ).init_method.process( code ) + end end private @@ -52,23 +59,5 @@ module Vool Parfait::NamedList.type_for( type_hash ) end - def create_methods(clazz , body) - methods = Passes::MethodCollector.new.collect(body) - methods.each do |method| - clazz.add_method( method ) - normalizer = Passes::Normalizer.new(method) - method.normalize_source { |sourc| normalizer.process( sourc ) } - end - methods - end - - def compile_methods(clazz , methods) - methods.each do |method| - code = Passes::MethodCompiler.new(method).get_code - typed_method = method.create_parfait_method(clazz.instance_type) - Vm::MethodCompiler.new( typed_method ).init_method.process( code ) - end - end - end end diff --git a/test/fragments/test_adds.rb b/test/fragments/test_adds.rb new file mode 100644 index 00000000..5d072961 --- /dev/null +++ b/test/fragments/test_adds.rb @@ -0,0 +1,26 @@ +#require_relative 'helper' + +module Rubyx + class TestRubyAdds < MiniTest::Test +# include RubyxTests + + def pest_ruby_adds + @string_input = <