Skip to content

Commit

Permalink
Showing 308 changed files with 3,029 additions and 2,045 deletions.
1 change: 1 addition & 0 deletions machine/builtin/block_environment.cpp
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
#include "object_utils.hpp"
#include "on_stack.hpp"
#include "memory.hpp"
#include "machine_code.hpp"

#include "builtin/block_environment.hpp"
#include "builtin/class.hpp"
1 change: 1 addition & 0 deletions machine/builtin/compiled_code.cpp
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
#include "configuration.hpp"
#include "object_utils.hpp"
#include "memory.hpp"
#include "machine_code.hpp"
#include "on_stack.hpp"
#include "logger.hpp"

1 change: 1 addition & 0 deletions machine/builtin/executable.cpp
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@
#include "call_frame.hpp"
#include "dispatch.hpp"
#include "memory.hpp"
#include "machine_code.hpp"
#include "object_utils.hpp"

#include "builtin/class.hpp"
1 change: 1 addition & 0 deletions machine/builtin/location.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "memory.hpp"
#include "machine_code.hpp"
#include "call_frame.hpp"
#include "on_stack.hpp"

2 changes: 2 additions & 0 deletions machine/builtin/system.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "arguments.hpp"

#include "builtin/array.hpp"
#include "builtin/bignum.hpp"
#include "builtin/block_environment.hpp"
@@ -32,6 +33,7 @@
#include "helpers.hpp"
#include "lookup_data.hpp"
#include "memory.hpp"
#include "machine_code.hpp"
#include "object_utils.hpp"
#include "on_stack.hpp"
#include "signal.hpp"
23 changes: 22 additions & 1 deletion machine/call_frame.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#ifndef RBX_CALL_FRAME_HPP
#define RBX_CALL_FRAME_HPP

#include "machine_code.hpp"
#include "unwind_info.hpp"
#include "stack_variables.hpp"
#include "dispatch.hpp"
#include "arguments.hpp"
#include "object_utils.hpp"

#include "builtin/compiled_code.hpp"
#include "builtin/symbol.hpp"

#include <ostream>
@@ -23,6 +24,14 @@ namespace rubinius {
class RuntimeDataHolder;
}

struct InterpreterState {
int call_flags;

InterpreterState()
: call_flags(0)
{}
};

struct CallFrame {
enum Flags {
cIsLambda = 1 << 0,
@@ -47,13 +56,17 @@ namespace rubinius {

int flags;
int ip_;
int ret_ip_;
int exception_ip_;

VariableScope* top_scope_;
StackVariables* scope;

Arguments* arguments;
Object** stack_ptr_;
MachineCode* machine_code;
InterpreterState* is;
UnwindInfoSet* unwinds;

// Stack
Object* stk[0];
@@ -169,10 +182,18 @@ namespace rubinius {
return ip_++;
}

// TODO: instructions
// void next_ip(int width) {
// ip_ += width;
void next_ip() {
}

void ret_ip() {
ip_ = ret_ip_;
}

void exception_ip() {
ip_ = exception_ip_;
}

/**
18 changes: 11 additions & 7 deletions machine/instructions/add_scope.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
#include "interpreter/instructions.hpp"

inline void rubinius::instruction_add_scope(STATE, CallFrame* call_frame) {
Object* obj = stack_pop();
Module* mod = as<Module>(obj);
LexicalScope* scope = LexicalScope::create(state);
scope->module(state, mod);
scope->parent(state, call_frame->lexical_scope());
call_frame->lexical_scope_ = scope;
namespace rubinius {
namespace instructions {
inline void add_scope(STATE, CallFrame* call_frame) {
Object* obj = stack_pop();
Module* mod = as<Module>(obj);
LexicalScope* scope = LexicalScope::create(state);
scope->module(state, mod);
scope->parent(state, call_frame->lexical_scope());
call_frame->lexical_scope_ = scope;
}
}
}
6 changes: 5 additions & 1 deletion machine/instructions/allow_private.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#include "interpreter/instructions.hpp"

inline void rubinius::instruction_allow_private() {
namespace rubinius {
namespace instructions {
inline void allow_private() {
}
}
}
62 changes: 35 additions & 27 deletions machine/instructions/cast_array.hpp
Original file line number Diff line number Diff line change
@@ -1,34 +1,42 @@
#include "interpreter/instructions.hpp"

inline bool rubinius::instruction_cast_array(STATE, CallFrame* call_frame) {
// Use stack_top and not stack_pop because we may need
// to preserve and reread the value from the stack below.
Object* t1 = stack_top();
if(t1->nil_p()) {
t1 = Array::create(state, 0);
} else if(Tuple* tup = try_as<Tuple>(t1)) {
t1 = Array::from_tuple(state, tup);
} else if(!kind_of<Array>(t1)) {
Object* recv = G(type);
Arguments args(G(sym_coerce_to_array), recv, 1, &t1);
Dispatch dispatch(G(sym_coerce_to_array));
#include "object_utils.hpp"

Object* res = dispatch.send(state, args);
#include "builtin/array.hpp"

// If the send still doesn't produce an array, wrap
// the value in one.
if(res && !kind_of<Array>(res)) {
Array* ary = Array::create(state, 1);
// Don't read t1 here, it's not GC safe because we called
// a method.
ary->set(state, 0, stack_top());
t1 = ary;
} else {
t1 = res;
}
}
namespace rubinius {
namespace instructions {
inline bool cast_array(STATE, CallFrame* call_frame) {
// Use stack_top and not stack_pop because we may need
// to preserve and reread the value from the stack below.
Object* t1 = stack_top();
if(t1->nil_p()) {
t1 = Array::create(state, 0);
} else if(Tuple* tup = try_as<Tuple>(t1)) {
t1 = Array::from_tuple(state, tup);
} else if(!rubinius::kind_of<Array>(t1)) {
Object* recv = G(type);
Arguments args(G(sym_coerce_to_array), recv, 1, &t1);
Dispatch dispatch(G(sym_coerce_to_array));

Object* res = dispatch.send(state, args);

(void)stack_pop(); // Remove original value
// If the send still doesn't produce an array, wrap
// the value in one.
if(res && !rubinius::kind_of<Array>(res)) {
Array* ary = Array::create(state, 1);
// Don't read t1 here, it's not GC safe because we called
// a method.
ary->set(state, 0, stack_top());
t1 = ary;
} else {
t1 = res;
}
}

CHECK_AND_PUSH(t1);
(void)stack_pop(); // Remove original value

CHECK_AND_PUSH(t1);
}
}
}
68 changes: 37 additions & 31 deletions machine/instructions/cast_for_multi_block_arg.hpp
Original file line number Diff line number Diff line change
@@ -1,39 +1,45 @@
#include "interpreter/instructions.hpp"

inline bool rubinius::instruction_cast_for_multi_block_arg(STATE, CallFrame* call_frame) {
if(!call_frame->arguments) {
Exception::internal_error(state, "no arguments object");
return false;
}
#include "builtin/array.hpp"

/* If there is only one argument and that thing is an array...
AND the thing being invoked is not a lambda... */
if(!(call_frame->flags & CallFrame::cIsLambda) &&
call_frame->arguments->total() == 1) {
Object* obj = call_frame->arguments->get_argument(0);
if(kind_of<Array>(obj)) {
stack_push(obj);
} else if(CBOOL(obj->respond_to(state, G(sym_to_ary), cFalse))) {
obj = obj->send(state, G(sym_to_ary));
if(!obj) return false;
if(kind_of<Array>(obj)) {
stack_push(obj);
} else {
Exception::type_error(state, "to_ary must return an Array");
namespace rubinius {
namespace instructions {
inline bool cast_for_multi_block_arg(STATE, CallFrame* call_frame) {
if(!call_frame->arguments) {
Exception::internal_error(state, "no arguments object");
return false;
}
} else {
Array* ary = Array::create(state, 1);
ary->set(state, 0, obj);
stack_push(ary);
}
} else {
Array* ary = Array::create(state, call_frame->arguments->total());
for(size_t i = 0; i < call_frame->arguments->total(); i++) {
ary->set(state, i, call_frame->arguments->get_argument(i));

/* If there is only one argument and that thing is an array...
AND the thing being invoked is not a lambda... */
if(!(call_frame->flags & CallFrame::cIsLambda) &&
call_frame->arguments->total() == 1) {
Object* obj = call_frame->arguments->get_argument(0);
if(rubinius::kind_of<Array>(obj)) {
stack_push(obj);
} else if(CBOOL(obj->respond_to(state, G(sym_to_ary), cFalse))) {
obj = obj->send(state, G(sym_to_ary));
if(!obj) return false;
if(rubinius::kind_of<Array>(obj)) {
stack_push(obj);
} else {
Exception::type_error(state, "to_ary must return an Array");
return false;
}
} else {
Array* ary = Array::create(state, 1);
ary->set(state, 0, obj);
stack_push(ary);
}
} else {
Array* ary = Array::create(state, call_frame->arguments->total());
for(size_t i = 0; i < call_frame->arguments->total(); i++) {
ary->set(state, i, call_frame->arguments->get_argument(i));
}
stack_push(ary);
}

return true;
}
stack_push(ary);
}

return true;
}
38 changes: 21 additions & 17 deletions machine/instructions/cast_for_single_block_arg.hpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
#include "interpreter/instructions.hpp"

inline bool rubinius::instruction_cast_for_single_block_arg(STATE, CallFrame* call_frame) {
if(!call_frame->arguments) {
Exception::internal_error(state, "no arguments object");
return false;
}
namespace rubinius {
namespace instructions {
inline bool cast_for_single_block_arg(STATE, CallFrame* call_frame) {
if(!call_frame->arguments) {
Exception::internal_error(state, "no arguments object");
return false;
}

int k = call_frame->arguments->total();
if(k == 0) {
stack_push(cNil);
} else if(k == 1) {
stack_push(call_frame->arguments->get_argument(0));
} else {
Array* ary = Array::create(state, k);
for(int i = 0; i < k; i++) {
ary->set(state, i, call_frame->arguments->get_argument(i));
}
stack_push(ary);
}

int k = call_frame->arguments->total();
if(k == 0) {
stack_push(cNil);
} else if(k == 1) {
stack_push(call_frame->arguments->get_argument(0));
} else {
Array* ary = Array::create(state, k);
for(int i = 0; i < k; i++) {
ary->set(state, i, call_frame->arguments->get_argument(i));
return true;
}
stack_push(ary);
}

return true;
}
Loading

0 comments on commit f356477

Please sign in to comment.