Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rubinius/rubinius
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 7f103b10ea2c^
Choose a base ref
...
head repository: rubinius/rubinius
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: ff2c3ec6715a
Choose a head ref
  • 2 commits
  • 8 files changed
  • 1 contributor

Commits on May 28, 2015

  1. Copy the full SHA
    7f103b1 View commit details
  2. Generate first cut of CodeDB for kernel.

    This all needs to be properly extracted into a compiler facility.
    brixen committed May 28, 2015
    Copy the full SHA
    ff2c3ec View commit details
Showing with 213 additions and 1 deletion.
  1. +22 −0 kernel/delta/code_db.rb
  2. +1 −0 kernel/delta/load_order.txt
  3. +112 −1 rakelib/kernel.rake
  4. +1 −0 rakelib/vm.rake
  5. +34 −0 vm/builtin/code_db.cpp
  6. +39 −0 vm/builtin/code_db.hpp
  7. +2 −0 vm/globals.hpp
  8. +2 −0 vm/ontology.cpp
22 changes: 22 additions & 0 deletions kernel/delta/code_db.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module Rubinius
class CodeDB
class << self
undef :new
end

def self.open(path)
Rubinius.primitive :code_db_open
raise PrimitiveFailure, "Rubinius::CodeDB.open primitive failed"
end

def self.load(m_id)
Rubinius.primitive :code_db_load
raise PrimitiveFailure, "Rubinius::CodeDB.load primitive failed"
end

def store(code)
Rubinius.primitive :code_db_store
raise PrimitiveFailure, "Rubinius::CodeDB#store primitive failed"
end
end
end
1 change: 1 addition & 0 deletions kernel/delta/load_order.txt
Original file line number Diff line number Diff line change
@@ -20,3 +20,4 @@ ffi.rbc
ruby_constants.rbc
pack.rbc
metrics.rbc
code_db.rbc
113 changes: 112 additions & 1 deletion rakelib/kernel.rake
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@ def kernel_clean
rm_rf Dir["**/*.rbc",
"**/.*.rbc",
"kernel/**/signature.rb",
"runtime/kernel",
"spec/capi/ext/*.{o,sig,#{$dlext}}",
],
:verbose => $verbose
@@ -59,6 +60,16 @@ end
# Collection of all files in the kernel runtime. Modified by
# various tasks below.
runtime_files = FileList["runtime/platform.conf"]
code_db_source = FileList[]
code_db_files = FileList[
"runtime/kernel/contents",
"runtime/kernel/data",
"runtime/kernel/index",
"runtime/kernel/initialize"
]
code_db_scripts = []
code_db_code = []
code_db_data = []

# Names of subdirectories of the language directories.
dir_names = %w[
@@ -172,6 +183,8 @@ file signature => signature_file do |t|
end
runtime_files << signature

code_db_source << "kernel/alpha.rb"

# All the kernel files
dir_names.each do |dir|
directory(runtime_dir = "runtime/#{dir}")
@@ -193,9 +206,13 @@ dir_names.each do |dir|
rbc = runtime_dir + name.chomp!
rb = kernel_dir + name.chop
kernel_file_task runtime_files, signature_file, rb, rbc
code_db_source << rb
end
end

code_db_source << "kernel/delta/converter_paths.rb"
code_db_source << "kernel/loader.rb"

[ signature_file,
"kernel/alpha.rb",
"kernel/loader.rb",
@@ -238,12 +255,106 @@ namespace :compiler do
task :generate => [signature_file]
end

directory "runtime/kernel"

class CodeDBCompiler
def self.m_id
@m_id ||= 0
@m_id += 1
end

def self.compile(file, line, transforms)
compiler = Rubinius::ToolSets::Build::Compiler.new :file, :compiled_code

parser = compiler.parser
parser.root Rubinius::ToolSets::Build::AST::Script

if transforms.kind_of? Array
transforms.each { |t| parser.enable_category t }
else
parser.enable_category transforms
end

parser.input file, line

generator = compiler.generator
generator.processor Rubinius::ToolSets::Build::Generator

compiler.run
end

def self.marshal(code)
marshaler = Rubinius::ToolSets::Build::CompiledFile::Marshal.new
marshaler.marshal code
end
end

file "runtime/kernel/data" => ["runtime/kernel"] + runtime_files do |t|
puts "CodeDB: writing data..."

code_db_source.each do |file|
id = CodeDBCompiler.m_id

code_db_code << [id, CodeDBCompiler.compile(file, 1, [:default, :kernel])]

code_db_scripts << id
end

while x = code_db_code.shift
id, cc = x

cc.literals.each_with_index do |x, index|
if x.kind_of? Rubinius::CompiledCode
cc.literals[index] = i = CodeDBCompiler.m_id
code_db_code.unshift [i, x]
end
end

marshaled = CodeDBCompiler.marshal cc

code_db_data << [id, marshaled]
end

File.open t.name, "wb" do |f|
code_db_data.map! do |id, marshaled|
offset = f.pos
f.write marshaled

[id, offset, f.pos - offset]
end
end
end

file "runtime/kernel/index" => "runtime/kernel/data" do |t|
puts "CodeDB: writing index..."

File.open t.name, "wb" do |f|
code_db_data.each { |id, offset, length| f.puts "#{id} #{offset} #{length}" }
end
end

file "runtime/kernel/contents" => "runtime/kernel/data" do |t|
puts "CodeDB: writing contents..."

File.open t.name, "wb" do |f|
code_db_source.each { |x| f.puts x }
end
end

file "runtime/kernel/initialize" => "runtime/kernel/data" do |t|
puts "CodeDB: writing initialize..."

File.open t.name, "wb" do |f|
code_db_scripts.each { |x| f.puts x }
end
end

desc "Build all kernel files (alias for kernel:build)"
task :kernel => 'kernel:build'

namespace :kernel do
desc "Build all kernel files"
task :build => ['compiler:load'] + runtime_files
task :build => ['compiler:load'] + runtime_files + code_db_files

desc "Delete all .rbc files"
task :clean do
1 change: 1 addition & 0 deletions rakelib/vm.rake
Original file line number Diff line number Diff line change
@@ -124,6 +124,7 @@ field_extract_headers = %w[
vm/builtin/character.hpp
vm/builtin/thread_state.hpp
vm/builtin/jit.hpp
vm/builtin/code_db.hpp
]

transcoders_src_dir = File.expand_path "../../vendor/oniguruma/enc/trans", __FILE__
34 changes: 34 additions & 0 deletions vm/builtin/code_db.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "builtin/class.hpp"
#include "builtin/code_db.hpp"
#include "builtin/compiled_code.hpp"
#include "builtin/string.hpp"

#include "object_utils.hpp"
#include "ontology.hpp"

namespace rubinius {
void CodeDB::init(STATE) {
GO(codedb).set(ontology::new_class_under(state, "CodeDB", G(rubinius)));
G(codedb)->set_object_type(state, CodeDBType);
}

CodeDB* CodeDB::open(STATE, String* path) {
CodeDB* codedb = create(state, path->c_str(state));

return codedb;
}

CodeDB* CodeDB::create(STATE, const char* path) {
CodeDB* codedb = state->vm()->new_object<CodeDB>(G(codedb));

return codedb;
}

CompiledCode* CodeDB::load(STATE, String* m_id) {
return nil<CompiledCode>();
}

Object* CodeDB::store(STATE, CompiledCode* code) {
return cNil;
}
}
39 changes: 39 additions & 0 deletions vm/builtin/code_db.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#ifndef RBX_CODEDB_HPP
#define RBX_CODEDB_HPP

#include "builtin/object.hpp"

namespace rubinius {
class CompiledCode;

class CodeDB : public Object {
public:
const static object_type type = CodeDBType;

private:
String* path_; // slot
int data_fd_;

public:
attr_accessor(path, String);

static void init(STATE);
static CodeDB* create(STATE, const char* path);

// Rubinius.primitive :code_db_open
static CodeDB* open(STATE, String* path);

// Rubinius.primitive :code_db_load
static CompiledCode* load(STATE, String* m_id);

// Rubinius.primitive :code_db_store
Object* store(STATE, CompiledCode* code);

class Info : public TypeInfo {
public:
BASIC_TYPEINFO(TypeInfo)
};
};
}

#endif
2 changes: 2 additions & 0 deletions vm/globals.hpp
Original file line number Diff line number Diff line change
@@ -130,6 +130,7 @@ namespace rubinius {
TypedRoot<Class*> logger;
TypedRoot<JIT*> jit;
TypedRoot<Module*> runtime;
TypedRoot<Class*> codedb;

TypedRoot<Encoding*> usascii_encoding, utf8_encoding, ascii8bit_encoding;

@@ -264,6 +265,7 @@ namespace rubinius {
logger(&roots),
jit(&roots),
runtime(&roots),
codedb(&roots),
usascii_encoding(&roots),
utf8_encoding(&roots),
ascii8bit_encoding(&roots)
2 changes: 2 additions & 0 deletions vm/ontology.cpp
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@
#include "builtin/byte_array.hpp"
#include "builtin/character.hpp"
#include "builtin/class.hpp"
#include "builtin/code_db.hpp"
#include "builtin/compact_lookup_table.hpp"
#include "builtin/compiled_code.hpp"
#include "builtin/channel.hpp"
@@ -368,6 +369,7 @@ namespace rubinius {
FSEvent::init(state);
Logger::init(state);
JIT::init(state);
CodeDB::init(state);
}

// @todo document all the sections of bootstrap_ontology