Skip to content

Commit

Permalink
Finished merging kernel/ into a single directory.
Browse files Browse the repository at this point in the history
Kernel does not yet boot. Some dependencies still need to be resolved.
  • Loading branch information
brixen committed Jan 26, 2016
1 parent f787371 commit 5bf7a88
Showing 75 changed files with 4,648 additions and 4,742 deletions.
9 changes: 9 additions & 0 deletions kernel/class.rb
Original file line number Diff line number Diff line change
@@ -65,3 +65,12 @@ def superclass
return cls
end
end
code = Class.method_table.lookup(:new).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
237 changes: 237 additions & 0 deletions kernel/code_loader.rb
Original file line number Diff line number Diff line change
@@ -469,3 +469,240 @@ def update_paths(file, path)
end
end
end
# Implementation-specific behavior for Kernel#require and Kernel#load.
#
# In particular, this file implements #load_file for loading a Ruby source
# file and #load_library for loading a shared library extension file.
#
# Also provides #require_compiled which loads a precompiled version of a Ruby
# source file. Several CodeLoader class methods are implemented as a
# convenient way to invoke the CodeLoader.

module Rubinius
class InvalidRBC < RuntimeError; end

class CodeLoader

# Loads compiled files. Performs exactly as Kernel#require except that
#
# require "some_file"
#
# will resolve to "some_file.rbc" on the $LOAD_PATH, rather than
# "some_file.rb".
#
# However, if "some_file.rbc" does not exist, then like #require, this
# method will search for a shared library extension file to load using the
# platform's file extension for shared libraries. This simplifies loading
# a set of pre-compiled .rbc files that also may load an extension as in
# the case of loading the compiler on bootstrap.
def require_compiled(check_version=true)
saved_check = CodeLoader.check_version
saved_extension = CodeLoader.source_extension

CodeLoader.load_compiled = true
CodeLoader.check_version = check_version
CodeLoader.source_extension = ".rbc"

req = self.require

Rubinius.run_script self.compiled_code

CodeLoader.loaded_hook.trigger!(@path)

add_feature

return true
ensure
req.remove! if req

CodeLoader.check_version = saved_check
CodeLoader.source_extension = saved_extension
CodeLoader.load_compiled = false
end

# Loads a Ruby source file specified on the command line. There is no
# search required as the path on the command line must directly refernce a
# loadable file. Also, the value of __FILE__ in a script loaded on the
# command line differs from the value in a file loaded by Kernel#require
# or Kernel#load.
def load_script(debug)
@file_path = @path
@load_path = File.expand_path @path

load_error unless loadable? @load_path
script = load_file

script.make_main!

Rubinius.run_script self.compiled_code

CodeLoader.loaded_hook.trigger!(@path)
end

# Overrides the version of #add_feature provided in kernel/common. When
# loading precompiled source files via #require, adds ".rb" files to
# $LOADED_FEATURES.
def add_feature
name = @feature.suffix?(".rbc") ? @feature[0..-2] : @feature
$LOADED_FEATURES << name
add_feature_to_index(feature)
end

# Default check_version flag to true
@check_version = true

# Requires pre-installed gems directly to prevent Bundler and RubyGems
# from disabling the gems and to permit bootstrapping RubyGems.
#
# TODO: Patch Bundler to recognize pre-installed gems when resolving
# dependencies and fix RubyGems hijacking #require.
def rubygems_require
if dir = rubygems_search_require
$LOAD_PATH.unshift dir
return true
end

return false
end

def rubygems_search_require
library_found = nil

self.class.rubygems_dirs.each do |dir|
if @type and check_path(dir, @path, "", @type)
return dir
elsif check_path(dir, @path, CodeLoader.source_extension, :ruby)
return dir
elsif check_path(dir, @path, LIBSUFFIX, :library)
library_found = dir
end
end

library_found
end

class << self
attr_accessor :load_compiled
attr_accessor :check_version

def rubygems_dirs
@rubygems_dirs ||= Dir["#{Rubinius::GEMS_PATH}/gems/**/lib"]
end

# Loads rubygems using the bootstrap standard library files.
def load_rubygems
require "rubygems"
end

# Loads the pre-compiled bytecode compiler. Sets up paths needed by the
# compiler to find dependencies like the parser.
def load_compiler
begin
Dir["#{Rubinius::RUNTIME_PATH}/gems/**/lib"].each do |dir|
$LOAD_PATH.unshift dir
end

require_compiled "rubinius/toolset"

Rubinius::ToolSets.create :runtime do
require_compiled "rubinius/melbourne"
require_compiled "rubinius/processor"
require_compiled "rubinius/compiler"
require_compiled "rubinius/ast"
end
rescue Object => e
raise LoadError, "Unable to load the bytecode compiler", e
end
end

def require_compiled(name, check_version=true)
new(name).require_compiled(check_version)
end

def load_script(name, debug=false)
new(name).load_script(debug)
end

def execute_script(script)
eval(script, TOPLEVEL_BINDING)
end

def save_compiled?
@save_compiled ||= Config["compiler.no_rbc"] == nil
end
end

# Given a path to a Ruby source file to load (i.e. @load_path), determines
# whether a compiled version exists and is up-to-date. If it is, loads the
# compiled version. Otherwise, compiles the Ruby source file.
#
# TODO: Make the compiled version checking logic available as a Compiler
# convenience method.
def load_file(wrap=false)
signature = CodeLoader.check_version ? Signature : 0
version = Rubinius::RUBY_LIB_VERSION

if CodeLoader.load_compiled
code = load_compiled_file @load_path, signature, version
else
c = Rubinius::ToolSets::Runtime::Compiler
compiled_name = c.compiled_name @load_path

if compiled_name
begin
compiled_stat = File::Stat.stat compiled_name

if compiled_stat and @stat.mtime >= compiled_stat.mtime
code = compile_file @load_path, compiled_name
else
begin
code = load_compiled_file compiled_name, signature, version
rescue TypeError, InvalidRBC
code = compile_file @load_path, compiled_name
end
end
rescue Errno::ENOENT
code = compile_file @load_path, compiled_name
end
else
code = compile_file @load_path, compiled_name
end
end

script = code.create_script(wrap)
script.file_path = @file_path
script.data_path = @load_path

@compiled_code = code
CodeLoader.compiled_hook.trigger! script
return script
end

attr_reader :compiled_code

# Compile a Ruby source file and save the compiled file. Return the
# internal representation (CompiledCode) of the Ruby source file.
def compile_file(file, compiled)
c = Rubinius::ToolSets::Runtime::Compiler
if CodeLoader.save_compiled?
c.compile file, compiled
else
c.compile_file file
end
end

# Load a compiled version of a Ruby source file.
def load_compiled_file(path, signature, version)
Rubinius.primitive :compiledfile_load

raise InvalidRBC, path
end

# Load a shared library extension file.
def load_library
name = File.basename @load_path, LIBSUFFIX

NativeMethod.load_extension(@load_path, name)
end
end
end
149 changes: 0 additions & 149 deletions kernel/common/constant_scope.rb

This file was deleted.

51 changes: 0 additions & 51 deletions kernel/common/ctype.rb

This file was deleted.

223 changes: 0 additions & 223 deletions kernel/common/dir.rb

This file was deleted.

588 changes: 0 additions & 588 deletions kernel/common/encoding.rb

This file was deleted.

298 changes: 0 additions & 298 deletions kernel/common/env.rb

This file was deleted.

533 changes: 0 additions & 533 deletions kernel/common/exception.rb

This file was deleted.

26 changes: 0 additions & 26 deletions kernel/common/executable.rb

This file was deleted.

11 changes: 0 additions & 11 deletions kernel/common/false.rb

This file was deleted.

1,356 changes: 0 additions & 1,356 deletions kernel/common/file.rb

This file was deleted.

65 changes: 0 additions & 65 deletions kernel/common/fixnum.rb

This file was deleted.

82 changes: 0 additions & 82 deletions kernel/common/gc.rb

This file was deleted.

94 changes: 0 additions & 94 deletions kernel/common/load_order.txt

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
149 changes: 149 additions & 0 deletions kernel/constant_scope.rb
Original file line number Diff line number Diff line change
@@ -34,3 +34,152 @@ def class_variable_get_or_set(sym, val)
# eventually be deprecated in favor of ConstantScope.
StaticScope = ConstantScope
end
##
# A linked list that details the static, lexical scope the method was created
# in.
#
# TODO: document

module Rubinius
class ConstantScope

#
# @todo Verify the recursion here does not cause problems. --rue
#
def initialize(mod, par = nil)
@module = mod
@parent = par
end

# Source code of this scope.
attr_accessor :script

# Module or class this lexical scope enclosed into.
attr_reader :module

# Constant scope object this scope enclosed into.
attr_reader :parent

# Module or class representing the 'current class'. MRI manipulates
# this outside of the lexical scope and uses it for undef and method
# definition.
attr_accessor :current_module

# Set to indicate that no methods may be add to this scope
attr_accessor :disabled_for_methods

# Lazy initialized hash map used for flip-flops
attr_accessor :flip_flops

def const_defined?(name, search_parents=true)
scope = self
while scope and scope.module != Object
return true if scope.module.const_defined?(name)
scope = scope.parent
end

return Object.const_defined?(name)
end

def inspect
current = " current=#{@current_module}" if @current_module
"#<#{self.class.name}:0x#{self.object_id.to_s(16)} parent=#{@parent.inspect} module=#{@module}#{current}>"
end

def to_s
inspect
end

# Indicates if this is a toplevel/default scope
def top_level?
!@parent
end

# Use the same info as the current ConstantScope, but set current_module to
# +mod+. Chains off the current ConstantScope.
def using_current_as(mod)
if top_level?
# Don't chain up if this is a toplevel, create a new one.
cs = dup
else
cs = ConstantScope.new @module, self
end

cs.current_module = mod
return cs
end

def using_disabled_scope
cs = using_current_as(@module)
cs.disabled_for_methods = true
return cs
end

def for_method_definition
if @disabled_for_methods
raise TypeError, "unable to create methods in this scope"
end

return @current_module if @current_module
return @module
end

def alias_method(name, original)
Rubinius.privately do
for_method_definition.alias_method name, original
end
end

def __undef_method__(name)
Rubinius.privately do
for_method_definition.undef_method name
end
end

def active_path
script = current_script
if script
if path = script.file_path
return path.dup
end
end

return "__unknown__.rb"
end

def absolute_active_path
script = current_script
if script
if path = script.data_path
return path.dup
end
end

return nil
end

def data_path
script = current_script
if script and script.main?
if path = script.data_path
return path.dup
end
end

return nil
end

def current_script
scope = self
while scope and !scope.script
scope = scope.parent
end
return scope && scope.script
end

def const_set(name, value)
@module.const_set name, value
end
end
end

File renamed without changes.
File renamed without changes.
51 changes: 51 additions & 0 deletions kernel/delta/ctype.rb → kernel/ctype.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,54 @@
##
# Mixin containing byte classification methods.
#--
# isspace, islower, ... are not in MRI core library.

module Rubinius::CType
# The character literals (?x) are Fixnums in 1.8 and Strings in 1.9
# so we use literal values instead so this is 1.8/1.9 compatible.

# \n \r \t \f \v \a \b \e
def self.isctrl(num)
(num >= 7 and num <= 13) or num == 27
end

# ' ' \n \t \r \f \v
def self.isspace(num)
num == 32 or (num >= 9 and num <= 13)
end

def self.isupper(num)
num >= 65 and num <= 90
end

def self.islower(num)
num >= 97 and num <= 122
end

def self.isdigit(num)
num >= 48 and num <= 57
end

def self.isalnum(num)
islower(num) or isupper(num) or isdigit(num)
end

def self.toupper!(num)
num - 32
end

def self.toupper(num)
islower(num) ? toupper!(num) : num
end

def self.tolower!(num)
num + 32
end

def self.tolower(num)
isupper(num) ? tolower!(num) : num
end
end
module Rubinius::CType
def self.toprint(num)
# The character literals (?x) are Fixnums in 1.8 and Strings in 1.9
File renamed without changes.
9 changes: 0 additions & 9 deletions kernel/delta/class.rb

This file was deleted.

237 changes: 0 additions & 237 deletions kernel/delta/code_loader.rb

This file was deleted.

17 changes: 0 additions & 17 deletions kernel/delta/exception.rb

This file was deleted.

20 changes: 0 additions & 20 deletions kernel/delta/ffi.rb

This file was deleted.

19 changes: 0 additions & 19 deletions kernel/delta/file.rb

This file was deleted.

26 changes: 0 additions & 26 deletions kernel/delta/file_test.rb

This file was deleted.

173 changes: 0 additions & 173 deletions kernel/delta/kernel.rb

This file was deleted.

56 changes: 0 additions & 56 deletions kernel/delta/math.rb

This file was deleted.

216 changes: 0 additions & 216 deletions kernel/delta/module.rb

This file was deleted.

370 changes: 0 additions & 370 deletions kernel/delta/rubinius.rb

This file was deleted.

13 changes: 0 additions & 13 deletions kernel/delta/signal.rb

This file was deleted.

104 changes: 0 additions & 104 deletions kernel/delta/struct.rb

This file was deleted.

6 changes: 0 additions & 6 deletions kernel/delta/thread.rb

This file was deleted.

File renamed without changes.
223 changes: 223 additions & 0 deletions kernel/dir.rb
Original file line number Diff line number Diff line change
@@ -50,3 +50,226 @@ def control(kind, pos)

private :control
end
class Dir
include Enumerable

# This seems silly, I know. But we do this to make Dir more resistent to people
# screwing with ::File later (ie, fakefs)
PrivateFile = ::File

FFI = Rubinius::FFI

def self.open(path, options=undefined)
dir = new path, options
if block_given?
begin
value = yield dir
ensure
dir.close
end

return value
else
return dir
end
end

def self.entries(path, options=undefined)
ret = []

open(path, options) do |dir|
while s = dir.read
ret << s
end
end

ret
end

def self.exist?(path)
PrivateFile.directory?(path)
end

class << self
alias_method :exists?, :exist?
end

def self.home(user=nil)
PrivateFile.expand_path("~#{user}")
end

def self.[](*patterns)
if patterns.size == 1
pattern = Rubinius::Type.coerce_to_path(patterns[0])
return [] if pattern.empty?
patterns = glob_split pattern
end

glob patterns
end

def self.glob(pattern, flags=0, &block)
if pattern.kind_of? Array
patterns = pattern
else
pattern = Rubinius::Type.coerce_to_path pattern

return [] if pattern.empty?

patterns = glob_split pattern
end

matches = []
index = 0

patterns.each do |pat|
pat = Rubinius::Type.coerce_to_path pat
enc = Rubinius::Type.ascii_compatible_encoding pat
Dir::Glob.glob pat, flags, matches

total = matches.size
while index < total
Rubinius::Type.encode_string matches[index], enc
index += 1
end
end

if block
matches.each(&block)
return nil
end

return matches
end

def self.glob_split(pattern)
result = []
start = 0
while idx = pattern.find_string("\0", start)
result << pattern.byteslice(start, idx)
start = idx + 1
end
result << pattern.byteslice(start, pattern.bytesize)
end

def self.foreach(path)
return to_enum(:foreach, path) unless block_given?

open(path) do |dir|
while s = dir.read
yield s
end
end

nil
end

def self.join_path(p1, p2, dirsep)
"#{p1}#{dirsep ? '/' : ''}#{p2}"
end

def self.chdir(path = ENV['HOME'])
path = Rubinius::Type.coerce_to_path path

if block_given?
original_path = self.getwd
error = FFI::Platform::POSIX.chdir path
Errno.handle(path) if error != 0

begin
value = yield path
ensure
error = FFI::Platform::POSIX.chdir original_path
Errno.handle(original_path) if error != 0
end

return value
else
error = FFI::Platform::POSIX.chdir path
Errno.handle path if error != 0
error
end
end

def self.mkdir(path, mode = 0777)
error = FFI::Platform::POSIX.mkdir(Rubinius::Type.coerce_to_path(path), mode)
Errno.handle path if error != 0
error
end

def self.rmdir(path)
error = FFI::Platform::POSIX.rmdir(Rubinius::Type.coerce_to_path(path))
Errno.handle path if error != 0
error
end

def self.getwd
buf = String.pattern Rubinius::PATH_MAX, 0
wd = FFI::Platform::POSIX.getcwd(buf, buf.length)
Errno.handle unless wd
Rubinius::Type.external_string wd
end

def self.chroot(path)
ret = FFI::Platform::POSIX.chroot Rubinius::Type.coerce_to_path(path)
Errno.handle path if ret != 0
ret
end

def each
return to_enum unless block_given?

while s = read
yield s
end

self
end

def fileno
Rubinius.primitive :dir_fileno
raise PrimitiveFailure, "Dir#fileno primitive failed"
end

attr_reader :path

alias_method :to_path, :path

SeekKind = 0
RewindKind = 1
TellKind = 2

def pos
control TellKind, 0
end

alias_method :tell, :pos

def pos=(position)
seek(position)

position
end

def seek(position)
control SeekKind, position

self
end

def rewind
control RewindKind, 0

self
end

def inspect
"#<#{self.class}:#{object_id.to_s(16)} @path=#{@path}>"
end

class << self
alias_method :pwd, :getwd
alias_method :delete, :rmdir
alias_method :unlink, :rmdir
end
end
File renamed without changes.
Loading

0 comments on commit 5bf7a88

Please sign in to comment.