Skip to content

Commit

Permalink
Added LazyExecutable for deferred CompiledMethod loading.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Ford committed Apr 22, 2011
1 parent 7b9ed03 commit 6fbce5a
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 3 deletions.
15 changes: 15 additions & 0 deletions kernel/bootstrap/lazy_executable.rb
@@ -0,0 +1,15 @@
module Rubinius
class LazyExecutable
attr_accessor :path
attr_accessor :name

def self.new(path, name, index)
Ruby.primitive :lazy_executable_create
raise PrimitiveFailure, "Rubinius::LazyExecutable.new failed"
end

def inspect
"<Rubinius::LazyExecutable #{@path.inspect}, #{@name.inspect}>"
end
end
end
1 change: 1 addition & 0 deletions kernel/bootstrap/load_order18.txt
Expand Up @@ -13,6 +13,7 @@ configuration.rbc
dir.rbc
exception.rbc
executable.rbc
lazy_executable.rbc
false.rbc
fixnum.rbc
gc.rbc
Expand Down
2 changes: 1 addition & 1 deletion lib/compiler/compiled_file.rb
Expand Up @@ -34,7 +34,7 @@ def self.load(stream)
end

##
# Writes the CompiledFile +cm+ to +file+.
# Writes the CompiledMethod +cm+ to +file+.
def self.dump(cm, file)
File.open(file, "w") do |f|
new("!RBIX", Rubinius::Signature, "x").encode_to(f, cm)
Expand Down
1 change: 1 addition & 0 deletions rakelib/vm.rake
Expand Up @@ -96,6 +96,7 @@ field_extract_headers = %w[
vm/builtin/call_unit.hpp
vm/builtin/call_unit_adapter.hpp
vm/builtin/cache.hpp
vm/builtin/lazy_executable.hpp
]

############################################################
Expand Down
1 change: 0 additions & 1 deletion vm/builtin/compiledmethod.cpp
Expand Up @@ -20,7 +20,6 @@
#include "dispatch.hpp"
#include "call_frame.hpp"
#include "object_utils.hpp"
#include "vm/object_utils.hpp"
#include "configuration.hpp"

#include "inline_cache.hpp"
Expand Down
35 changes: 35 additions & 0 deletions vm/builtin/lazy_executable.cpp
@@ -0,0 +1,35 @@
#include "builtin/lazy_executable.hpp"
#include "builtin/class.hpp"
#include "builtin/lookuptable.hpp"
#include "builtin/symbol.hpp"
#include "builtin/fixnum.hpp"

#include "dispatch.hpp"
#include "call_frame.hpp"
#include "arguments.hpp"

#include "object_utils.hpp"

namespace rubinius {
void LazyExecutable::init(STATE) {
GO(lmethod).set(state->new_class("LazyExecutable", G(executable), G(rubinius)));
G(lmethod)->set_object_type(state, LazyExecutableType);
G(lmethod)->name(state, state->symbol("Rubinius::LazyExecutable"));
G(lmethod)->set_const(state, "Index", LookupTable::create(state));
}

LazyExecutable* LazyExecutable::create(STATE, Symbol* path, Symbol* name) {
LazyExecutable* le = state->new_object<LazyExecutable>(G(lmethod));
le->path(state, path);
le->name(state, name);

le->execute = lazy_executor;
return le;
}

Object* LazyExecutable::lazy_executor(STATE, CallFrame* call_frame, Executable* exec,
Module* mod, Arguments& args)
{
return Qnil;
}
}
35 changes: 35 additions & 0 deletions vm/builtin/lazy_executable.hpp
@@ -0,0 +1,35 @@
#include "builtin/executable.hpp"

namespace rubinius {
struct CallFrame;
class Dispatch;
class Arguments;
class Symbol;
class Fixnum;

class LazyExecutable : public Executable {
public:
const static object_type type = LazyExecutableType;

private:
Symbol* path_; // slot
Symbol* name_; // slot

public:
attr_accessor(path, Symbol);
attr_accessor(name, Symbol);

static void init(STATE);

// Ruby.primitive :lazy_executable_create
static LazyExecutable* create(STATE, Symbol* path, Symbol* name);

static Object* lazy_executor(STATE, CallFrame* call_frame,
Executable* exec, Module* mod, Arguments& args);

class Info : public Executable::Info {
public:
BASIC_TYPEINFO(Executable::Info)
};
};
}
4 changes: 3 additions & 1 deletion vm/globals.hpp
Expand Up @@ -112,6 +112,7 @@ namespace rubinius {
TypedRoot<Class*> cls_weakref;
TypedRoot<Class*> fiber;
TypedRoot<Class*> alias;
TypedRoot<Class*> lmethod;

/* Add new globals above this line. */

Expand Down Expand Up @@ -229,7 +230,8 @@ namespace rubinius {
global_cache_entry(&roots),
cls_weakref(&roots),
fiber(&roots),
alias(&roots)
alias(&roots),
lmethod(&roots)

/* Add initialize of globals above this line. */
{ }
Expand Down
2 changes: 2 additions & 0 deletions vm/ontology.cpp
Expand Up @@ -20,6 +20,7 @@
#include "builtin/float.hpp"
#include "builtin/io.hpp"
#include "builtin/iseq.hpp"
#include "builtin/lazy_executable.hpp"
#include "builtin/list.hpp"
#include "builtin/lookuptable.hpp"
#include "builtin/methodtable.hpp"
Expand Down Expand Up @@ -257,6 +258,7 @@ namespace rubinius {
String::init(this);
kcode::init(this);
Executable::init(this);
LazyExecutable::init(this);
CompiledMethod::init(this);
IO::init(this);
BlockEnvironment::init(this);
Expand Down

0 comments on commit 6fbce5a

Please sign in to comment.