Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Reorganized kernel to improve loading order.
These are the desired phases for booting Rubinius:

1. boot the VM itself with the ability to load and execute bytecode;
2. create the bootstrap methods and functions to be able to define
   class/module and methods;
3. load the kernel code, only defining class/module and methods;
4. run all 'init' / setup code for the kernel, defining initial runtime data
   structures and constant values;
5. create the Loader instance and parse command line options;
6. run user code.
  • Loading branch information
brixen committed Jan 31, 2016
1 parent 3a683eb commit fb59e4d
Show file tree
Hide file tree
Showing 55 changed files with 1,431 additions and 1,563 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -83,6 +83,7 @@ Gemfile.installed.lock
vm/include/capi/ruby/digest.h

/kernel/signature.rb
/kernel/build_config.rb

# Generated documentation
doc/generated/vm
Expand Down
14 changes: 4 additions & 10 deletions kernel/alpha.rb
Expand Up @@ -104,7 +104,6 @@ def new(*args)
end
end


module Kernel

# Return the Class object this object is an instance of.
Expand Down Expand Up @@ -244,7 +243,6 @@ def clone
# See kernel/bootstrap/rubinius.rb
#
module Rubinius

module Runtime
def self.dup_as_array(obj)
Rubinius.primitive :array_dup_as_array
Expand Down Expand Up @@ -322,7 +320,6 @@ def []=(key, val)
# kernel/common/constant_table.rb
#
class ConstantTable

# Perform lookup for constant name.
#
def lookup(name)
Expand All @@ -344,7 +341,6 @@ def store(name, constant, visibility)
# kernel/common/method_table.rb
#
class MethodTable

# Perform lookup for method name.
#
def lookup(name)
Expand All @@ -368,7 +364,6 @@ def alias(name, visibility, original_name, original_exec, original_mod)
end
end


class Symbol
# Produce String representation of this Symbol.
#
Expand All @@ -384,7 +379,6 @@ def to_sym
end
end


class String
# Returns the <code>Symbol</code> corresponding to <i>self</i>, creating the
# symbol if it did not previously exist. See <code>Symbol#id2name</code>.
Expand Down Expand Up @@ -414,7 +408,6 @@ def to_s
end
end


module Process
# Terminate with given status code.
#
Expand Down Expand Up @@ -445,7 +438,6 @@ def self.exit!(code=1)
end
end


class Module
def method_table ; @method_table ; end
def constant_table ; @constant_table ; end
Expand Down Expand Up @@ -672,9 +664,7 @@ def custom_call_site(name)
end
end


module Rubinius

class AccessVariable
attr_reader :name
end
Expand Down Expand Up @@ -795,3 +785,7 @@ class Object
include Kernel
end

module Enumerable; end
class Integer; end
class Numeric; end
class String; end
9 changes: 1 addition & 8 deletions kernel/argf.rb
Expand Up @@ -530,7 +530,7 @@ def advance!
@advance = false

file = ARGV.shift
@stream = stream(file)
@stream = stream(file)
@filename = file

if $-i && @stream != STDIN
Expand All @@ -546,10 +546,3 @@ def advance!
private :advance!
end
end

#
# The virtual concatenation file of the files given on command line (or
# from $stdin if no files were given.) Usable like an IO.
#
ARGF = Rubinius::ARGFClass.new

11 changes: 2 additions & 9 deletions kernel/array.rb
@@ -1,4 +1,6 @@
class Array
include Enumerable

def self.allocate
Rubinius.primitive :array_allocate
raise PrimitiveFailure, "Array.allocate primitive failed"
Expand All @@ -20,12 +22,6 @@ def new_reserved(count)
raise PrimitiveFailure, "Array.new_reserved primitive failed"
end

# THIS MUST NOT BE REMOVED. the kernel requires a simple
# Array#[] to work while parts of the kernel boot.
def [](idx)
at(idx)
end

def []=(idx, ent)
Rubinius.check_frozen

Expand Down Expand Up @@ -126,9 +122,6 @@ def to_tuple
tuple.copy_from @tuple, @start, @total, 0
tuple
end
end
class Array
include Enumerable

# The flow control for many of these methods is
# pretty evil due to how MRI works. There is
Expand Down
1 change: 0 additions & 1 deletion kernel/array_mirror.rb
Expand Up @@ -91,7 +91,6 @@ def repeated_permutation_size(combination_size)
return 0 if combination_size < 0
@object.size ** combination_size
end

end
end
end
11 changes: 5 additions & 6 deletions kernel/autoload.rb
Expand Up @@ -2,17 +2,17 @@
# Used to implement Module#autoload.

class Autoload
def self.allocate
Rubinius.primitive :autoload_allocate
raise PrimtiveFailure, "Autoload.allocate primitive failed"
end

attr_reader :name
attr_reader :scope
attr_reader :path
attr_reader :constant
attr_reader :thread

def self.allocate
Rubinius.primitive :autoload_allocate
raise PrimtiveFailure, "Autoload.allocate primitive failed"
end

def initialize(name, scope, path)
@name = name
@scope = scope
Expand Down Expand Up @@ -98,5 +98,4 @@ def find_const(under)

under.const_missing(name)
end

end
3 changes: 1 addition & 2 deletions kernel/basic_object.rb
Expand Up @@ -37,8 +37,7 @@ def __id__
Rubinius.primitive :object_id
raise ::PrimitiveFailure, "BasicObject#__id__ primitive failed"
end
end
class BasicObject

def method_missing(meth, *args)
::Kernel.raise ::NoMethodError, "Unable to send '#{meth}' on instance of BasicObject"
end
Expand Down
3 changes: 0 additions & 3 deletions kernel/bignum.rb
@@ -1,5 +1,4 @@
class Bignum < Integer

# unary operators

def ~
Expand Down Expand Up @@ -167,8 +166,6 @@ def size
Rubinius.primitive :bignum_size
raise PrimitiveFailure, "Bignum#size primitive failed"
end
end
class Bignum < Integer

# see README-DEVELOPERS regarding safe math compiler plugin
alias_method :/, :divide
Expand Down
31 changes: 14 additions & 17 deletions kernel/block_environment.rb
@@ -1,5 +1,19 @@
##
# Describes the environment a block was created in. BlockEnvironment is used
# to create a BlockContext.

module Rubinius
class BlockEnvironment
attr_reader :scope
attr_reader :top_scope
attr_reader :module

# The CompiledCode that implements the code for the block
attr_reader :compiled_code
attr_reader :constant_scope

attr_accessor :proc_environment

def self.allocate
Rubinius.primitive :blockenvironment_allocate
raise PrimitiveFailure, "BlockEnvironment.allocate primitive failed"
Expand Down Expand Up @@ -62,23 +76,6 @@ def defined_line
@block_env.line
end
end
end
end
##
# Describes the environment a block was created in. BlockEnvironment is used
# to create a BlockContext.

module Rubinius
class BlockEnvironment
attr_reader :scope
attr_reader :top_scope
attr_reader :module

# The CompiledCode that implements the code for the block
attr_reader :compiled_code
attr_reader :constant_scope

attr_accessor :proc_environment

def from_proc?
@proc_environment
Expand Down
17 changes: 7 additions & 10 deletions kernel/byte_array.rb
@@ -1,3 +1,6 @@
##
# An array of bytes, used as a low-level data store for implementing various
# other classes.
module Rubinius
class ByteArray
def self.allocate
Expand Down Expand Up @@ -34,11 +37,15 @@ def get_byte(index)
raise PrimitiveFailure, "ByteArray#get_byte primitive failed"
end

alias_method :[], :get_byte

def set_byte(index, value)
Rubinius.primitive :bytearray_set_byte
raise PrimitiveFailure, "ByteArray#set_byte primitive failed"
end

alias_method :[]=, :set_byte

def compare_bytes(other, a, b)
Rubinius.primitive :bytearray_compare_bytes
raise PrimitiveFailure, "ByteArray#compare_bytes primitive failed"
Expand Down Expand Up @@ -87,16 +94,6 @@ def reverse(start, total)
Rubinius.primitive :bytearray_reverse
raise PrimitiveFailure, "ByteArray#reverse primitive failed"
end
end
end
##
# An array of bytes, used as a low-level data store for implementing various
# other classes.

module Rubinius
class ByteArray
alias_method :[], :get_byte
alias_method :[]=, :set_byte

# TODO: encoding
def character_at_index(index)
Expand Down
1 change: 0 additions & 1 deletion kernel/call_custom_cache.rb
Expand Up @@ -11,4 +11,3 @@ def inspect

end
end

2 changes: 0 additions & 2 deletions kernel/call_site.rb
@@ -1,6 +1,5 @@
module Rubinius
class CallSite

attr_reader :name
attr_reader :executable

Expand All @@ -20,6 +19,5 @@ def location
def inspect
"#<#{self.class.name}:0x#{self.object_id.to_s(16)} #{location}##{@name}(#{hits})>"
end

end
end
1 change: 0 additions & 1 deletion kernel/capi.rb
@@ -1,5 +1,4 @@
module Rubinius

# CAPI contains utility methods used by capi.
module CAPI
def self.coerce(x, y, error=false)
Expand Down
12 changes: 0 additions & 12 deletions kernel/channel.rb
Expand Up @@ -8,13 +8,8 @@
# that same thread, the VM wakes up t1 and the value passed to #send is
# returned. This allows us to implement all manner of Thread semantics, such
# as Mutex.
#
# Channel is used heavily by Scheduler, to allow ruby code to interact with
# the outside world in a thread aware manner.

module Rubinius
class Channel

##
# Returns nil if nothing is waiting, or a List object which contains all
# Thread objects waiting on this Channel.
Expand Down Expand Up @@ -71,14 +66,7 @@ def try_receive
Rubinius.primitive :channel_try_receive
raise PrimitiveFailure, "Channel#try_receive primitive failed"
end
end
end
##
# A communication mechanism based on pi-calculus channels used primarily to
# communicate between ruby and the VM about events.

module Rubinius
class Channel
def inspect
"#<Rubinius::Channel:0x#{object_id.to_s(16)}>"
end
Expand Down
1 change: 0 additions & 1 deletion kernel/character.rb
@@ -1,6 +1,5 @@
module Rubinius
class Character < ::String

def self.__allocate__
Rubinius.primitive :character_allocate
raise PrimitiveFailure, "Rubinius::Character.allocate primitive failed"
Expand Down
11 changes: 0 additions & 11 deletions kernel/class.rb
Expand Up @@ -11,8 +11,6 @@ def set_superclass(sup)
end

private :set_superclass
end
class Class

def initialize(sclass=Object, name=nil, under=nil)
raise TypeError, "already initialized class" if @instance_type
Expand Down Expand Up @@ -65,12 +63,3 @@ def superclass
return cls
end
end
code = Class.method_table.lookup(:new).get_method
code.serial = Rubinius::CompiledCode::KernelMethodSerial

class Class
undef_method :append_features
undef_method :extend_object
undef_method :module_function
undef_method :prepend_features
end

0 comments on commit fb59e4d

Please sign in to comment.