From 2e8b514e9cf5749062c6af965b7ad3d5c9680cee Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Tue, 12 May 2015 14:58:29 +0300 Subject: [PATCH] start to use parfait classes bit of a bumpy road --- lib/parfait.rb | 31 +++++++++++++++++++++++++++++++ lib/parfait/hash.rb | 4 ++-- lib/salama.rb | 4 ---- lib/virtual/boot_space.rb | 2 +- 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/lib/parfait.rb b/lib/parfait.rb index 211da352..e05d40bd 100644 --- a/lib/parfait.rb +++ b/lib/parfait.rb @@ -7,3 +7,34 @@ require "parfait/array" require "parfait/string" require "parfait/message" require "parfait/frame" + +# Below we define functions (in different classes) that are not part of the run-time +# They are used for the boot process, ie when this codes executes in the vm that builds salama + +# To stay sane, we use the same classes that we use later, but "adapt" them to work in ruby +# This affects mainly memory layout + +module FakeMem + def initialize + @memory = [] + end +end + +class Parfait::Object + include FakeMem + def self.new_object &args + puts "I am #{self}" + object = self.new(*args) + object + end + def object_length + @memory.length + end +end +class Parfait::Class +end +class Parfait::Array + def length + object_length + end +end diff --git a/lib/parfait/hash.rb b/lib/parfait/hash.rb index d70a8b4e..dfe69c43 100644 --- a/lib/parfait/hash.rb +++ b/lib/parfait/hash.rb @@ -3,8 +3,8 @@ module Parfait class Hash < Object def initialize - @keys = Array.new() - @values = Array.new() + @keys = Array.new_object() + @values = Array.new_object() end def values() @values diff --git a/lib/salama.rb b/lib/salama.rb index 6241b3dd..13465f54 100644 --- a/lib/salama.rb +++ b/lib/salama.rb @@ -1,9 +1,5 @@ require 'parslet' -module Parfait - eval(File.open("./lib/parfait/hash.rb").read) -end - require "stream_reader" require "elf/object_writer" require 'salama-reader' diff --git a/lib/virtual/boot_space.rb b/lib/virtual/boot_space.rb index dfcd581e..25ab2e12 100644 --- a/lib/virtual/boot_space.rb +++ b/lib/virtual/boot_space.rb @@ -14,7 +14,7 @@ module Virtual def initialize super() - @classes = Parfait::Hash.new + @classes = Parfait::Hash.new_object #global objects (data) @objects = [] @symbols = []