From dd82095cca8079f2b4a59edd66542ead451db39e Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sun, 24 Aug 2014 00:25:15 +0300 Subject: [PATCH] reditribute boot dir evenly. some was parfait, some virtual, some kernel --- Gemfile.lock | 6 +----- lib/ast/function_expression.rb | 2 +- lib/boot/string.rb | 19 ------------------- lib/kernel/all.rb | 1 + lib/{boot => kernel}/object.rb | 2 +- lib/kernel/string.rb | 17 +++++++++++++++++ lib/{boot => parfait}/boot_class.rb | 6 ++---- lib/{boot => virtual}/boot_space.rb | 11 ++++------- lib/virtual/machine.rb | 2 +- lib/{boot => virtual}/meta_class.rb | 2 +- lib/virtual/object.rb | 2 +- lib/virtual/send_implementation.rb | 3 +-- 12 files changed, 31 insertions(+), 42 deletions(-) delete mode 100644 lib/boot/string.rb rename lib/{boot => kernel}/object.rb (99%) rename lib/{boot => parfait}/boot_class.rb (94%) rename lib/{boot => virtual}/boot_space.rb (94%) rename lib/{boot => virtual}/meta_class.rb (99%) diff --git a/Gemfile.lock b/Gemfile.lock index 5b17001f..20d08b8e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,15 +1,13 @@ GIT remote: https://github.com/salama/salama-reader.git - revision: 484990b093f0b01b61028902aa5fcafee7a7c9b6 + revision: 1272af6c660efe0af93d7f5ad87d98bd04ce5d22 specs: salama-reader (0.0.2) - salama (~> 0.0.1) PATH remote: /Users/raisa/salama-arm specs: salama-arm (0.0.1) - salama (~> 0.0.1) GEM remote: http://rubygems.org/ @@ -75,8 +73,6 @@ GEM ruby_parser (~> 3.2, >= 3.2.2) ruby_parser (3.6.1) sexp_processor (~> 4.1) - salama (0.0.1) - parslet (~> 1.6.1) sexp_processor (4.4.3) simplecov (0.8.2) docile (~> 1.1.0) diff --git a/lib/ast/function_expression.rb b/lib/ast/function_expression.rb index be832f55..40fc605c 100644 --- a/lib/ast/function_expression.rb +++ b/lib/ast/function_expression.rb @@ -8,7 +8,7 @@ module Ast end r = receiver ? receiver.compile(method,message) : Virtual::Self.new() new_method = Virtual::MethodDefinition.new(name , args , r ) - new_method.class_name = r.is_a?(Boot::BootClass) ? r.name : method.class_name + new_method.class_name = r.is_a?(BootClass) ? r.name : method.class_name clazz = Virtual::Object.space.get_or_create_class(new_method.class_name) clazz.add_instance_method new_method diff --git a/lib/boot/string.rb b/lib/boot/string.rb deleted file mode 100644 index 818711b4..00000000 --- a/lib/boot/string.rb +++ /dev/null @@ -1,19 +0,0 @@ -module Boot - class String - module ClassMethods - def get context , index = Virtual::Integer - get_function = Virtual::MethodDefinition.new(:get , [ Virtual::Integer] , Virtual::Integer , Virtual::Integer ) - return get_function - end - def set context , index = Virtual::Integer , char = Virtual::Integer - set_function = Virtual::MethodDefinition.new(:set , [Virtual::Integer, Virtual::Integer] , Virtual::Integer ,Virtual::Integer ) - return set_function - end - def puts context - puts_function = Virtual::MethodDefinition.new(:puts , [] ) - return puts_function - end - end - extend ClassMethods - end -end diff --git a/lib/kernel/all.rb b/lib/kernel/all.rb index 2edd9151..67f6c7dc 100644 --- a/lib/kernel/all.rb +++ b/lib/kernel/all.rb @@ -1,3 +1,4 @@ require_relative "integer" require_relative "string" require_relative "system" +require_relative "object" diff --git a/lib/boot/object.rb b/lib/kernel/object.rb similarity index 99% rename from lib/boot/object.rb rename to lib/kernel/object.rb index 3c3513cb..d558633a 100644 --- a/lib/boot/object.rb +++ b/lib/kernel/object.rb @@ -1,4 +1,4 @@ -module Boot +module Salama class Object module ClassMethods diff --git a/lib/kernel/string.rb b/lib/kernel/string.rb index e88df929..bacfd729 100644 --- a/lib/kernel/string.rb +++ b/lib/kernel/string.rb @@ -8,4 +8,21 @@ module Salama function end end + class String + module ClassMethods + def get context , index = Virtual::Integer + get_function = Virtual::MethodDefinition.new(:get , [ Virtual::Integer] , Virtual::Integer , Virtual::Integer ) + return get_function + end + def set context , index = Virtual::Integer , char = Virtual::Integer + set_function = Virtual::MethodDefinition.new(:set , [Virtual::Integer, Virtual::Integer] , Virtual::Integer ,Virtual::Integer ) + return set_function + end + def puts context + puts_function = Virtual::MethodDefinition.new(:puts , [] ) + return puts_function + end + end + extend ClassMethods + end end diff --git a/lib/boot/boot_class.rb b/lib/parfait/boot_class.rb similarity index 94% rename from lib/boot/boot_class.rb rename to lib/parfait/boot_class.rb index 414b6ca0..24cd3813 100644 --- a/lib/boot/boot_class.rb +++ b/lib/parfait/boot_class.rb @@ -1,6 +1,5 @@ -require_relative "meta_class" +require "virtual/meta_class" -module Boot # class is mainly a list of methods with a name (for now) # layout of object is seperated into Layout class BootClass < Virtual::ObjectConstant @@ -10,7 +9,7 @@ module Boot @instance_methods = [] @name = name.to_sym @super_class_name = super_class_name.to_sym - @meta_class = MetaClass.new(self) + @meta_class = Virtual::MetaClass.new(self) end attr_reader :name , :instance_methods , :meta_class , :context , :super_class_name def add_instance_method method @@ -42,4 +41,3 @@ module Boot end end -end \ No newline at end of file diff --git a/lib/boot/boot_space.rb b/lib/virtual/boot_space.rb similarity index 94% rename from lib/boot/boot_space.rb rename to lib/virtual/boot_space.rb index 12781ba0..34ed442b 100644 --- a/lib/boot/boot_space.rb +++ b/lib/virtual/boot_space.rb @@ -1,10 +1,7 @@ -require_relative "boot_class" -#require "vm/call_site" +require "parfait/boot_class" require "kernel/all" -require_relative "object" -require_relative "string" -module Boot +module Virtual # The BootSpace contains all objects for a program. In functional terms it is a program, but in oo # it is a collection of objects, some of which are data, some classes, some functions @@ -66,7 +63,7 @@ module Boot obj = get_or_create_class :Object [:index_of , :_get_instance_variable , :_set_instance_variable].each do |f| #puts "Boot Object::#{f}" - obj.add_instance_method Boot::Object.send(f , @context) + obj.add_instance_method Salama::Object.send(f , @context) end [:putstring,:putint,:fibo,:exit].each do |f| #puts "Boot Kernel::#{f}" @@ -75,7 +72,7 @@ module Boot obj = get_or_create_class :String [:get , :set , :puts].each do |f| #puts "Boot String::#{f}" - obj.add_instance_method Boot::String.send(f , @context) + obj.add_instance_method Salama::String.send(f , @context) end end diff --git a/lib/virtual/machine.rb b/lib/virtual/machine.rb index 5ea1ed8d..5273dfe7 100644 --- a/lib/virtual/machine.rb +++ b/lib/virtual/machine.rb @@ -83,5 +83,5 @@ require_relative "value" require_relative "type" require_relative "object" require_relative "constants" -require "boot/boot_space" +require_relative "boot_space" require_relative "send_implementation" diff --git a/lib/boot/meta_class.rb b/lib/virtual/meta_class.rb similarity index 99% rename from lib/boot/meta_class.rb rename to lib/virtual/meta_class.rb index 5c441c65..3d39a8b1 100644 --- a/lib/boot/meta_class.rb +++ b/lib/virtual/meta_class.rb @@ -1,4 +1,4 @@ -module Boot +module Virtual # class that acts like a class, but is really the object # described in the ruby language book as the eigenclass, what you get with diff --git a/lib/virtual/object.rb b/lib/virtual/object.rb index f708ac53..60e67301 100644 --- a/lib/virtual/object.rb +++ b/lib/virtual/object.rb @@ -32,7 +32,7 @@ module Virtual if defined? @@space @@space else - @@space = ::Boot::BootSpace.new + @@space = BootSpace.new end end end diff --git a/lib/virtual/send_implementation.rb b/lib/virtual/send_implementation.rb index db08cf60..89330769 100644 --- a/lib/virtual/send_implementation.rb +++ b/lib/virtual/send_implementation.rb @@ -9,8 +9,7 @@ module Virtual me = code.me next unless ( me.type == Reference) if( me.is_a? Constant) - Boot::BootClass - if( me.is_a? Boot::BootClass ) + if( me.is_a? BootClass ) raise "unimplemented" elsif( me.is_a? ObjectConstant ) clazz = me.clazz