本文整理汇总了C++中AccessVariable类的典型用法代码示例。如果您正苦于以下问题:C++ AccessVariable类的具体用法?C++ AccessVariable怎么用?C++ AccessVariable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AccessVariable类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: access_read_regular_ivar
Object* AccessVariable::access_read_regular_ivar(STATE, CallFrame* call_frame, Executable* exec, Module* mod,
Arguments& args) {
AccessVariable* access = as<AccessVariable>(exec);
if(unlikely(args.total() != 0)) {
Exception::argument_error(state, 0, args.total());
return NULL;
}
Object* recv = args.recv();
return recv->get_ivar(state, access->name());
}
示例2: test_access_variable_is_slot
void test_access_variable_is_slot() {
AccessVariable* av = AccessVariable::allocate(state);
Arguments args(state->symbol("blah"), G(object));
av->name(state, state->symbol("@module_name"));
Object* ret = av->access_execute(state, av, G(object), args);
TS_ASSERT(try_as<Symbol>(ret));
TS_ASSERT_EQUALS(std::string("Object"), as<Symbol>(ret)->cpp_str(state));
}
示例3: test_access_variable
void test_access_variable() {
AccessVariable* av = AccessVariable::allocate(state);
Arguments args(state->symbol("blah"), G(object));
av->name(state, state->symbol("@blah"));
G(object)->set_ivar(state, av->name(), state->symbol("Sweet"));
Object* ret = av->execute(state, av, G(object), args);
TS_ASSERT(try_as<Symbol>(ret));
TS_ASSERT_EQUALS(std::string("Sweet"), as<Symbol>(ret)->cpp_str(state));
}
示例4: test_write_variable_is_slot
void test_write_variable_is_slot() {
AccessVariable* av = AccessVariable::allocate(state);
Symbol* val = state->symbol("Blah");
Object* ary[1] = {val};
Arguments args(state->symbol("blah"), G(object), 1, ary);
av->name(state, state->symbol("@module_name"));
av->write(state, cTrue);
Object* ret = av->access_execute(state, av, G(object), args);
TS_ASSERT_EQUALS(ret, val);
TS_ASSERT_EQUALS(val, G(object)->module_name());
}
示例5: test_write_variable
void test_write_variable() {
AccessVariable* av = AccessVariable::allocate(state);
Symbol* val = state->symbol("Blah");
Object* ary[1] = {val};
Arguments args(state->symbol("blah"), G(object), 1, ary);
av->name(state, state->symbol("@blah"));
av->write(state, cTrue);
Object* ret = av->execute(state, av, G(object), args);
TS_ASSERT_EQUALS(ret, val);
Symbol* out = as<Symbol>(G(object)->get_ivar(state, av->name()));
TS_ASSERT_EQUALS(val, out);
}
示例6: access_write_regular_ivar
Object* AccessVariable::access_write_regular_ivar(STATE, CallFrame* call_frame, Executable* exec, Module* mod,
Arguments& args) {
AccessVariable* access = as<AccessVariable>(exec);
if(unlikely(args.total() != 1)) {
Exception::argument_error(state, 1, args.total());
return NULL;
}
Object* recv = args.recv();
if(CBOOL(recv->frozen_p(state)) && CBOOL(recv->frozen_mod_disallowed(state))) {
Exception::frozen_error(state, call_frame, recv);
return 0;
}
return recv->set_ivar(state, access->name(), args.get_argument(0));
}
示例7: access_execute
/* Run when an AccessVariable is executed. Uses the details in msg.method
* to access instance variables of msg.recv */
ExecuteStatus AccessVariable::access_execute(STATE, Task* task, Message& msg) {
AccessVariable* access = as<AccessVariable>(msg.method);
/* The writer case. */
if(access->write()->true_p()) {
if(msg.args() != 1) {
Exception::argument_error(state, 1, msg.args());
}
/* Fall through, handle it as a normal ivar. */
msg.recv->set_ivar(state, access->name(), msg.get_argument(0));
task->primitive_return(msg.get_argument(0), msg);
return cExecuteContinue;
}
/* The read case. */
if(msg.args() != 0) {
Exception::argument_error(state, 0, msg.args());
} else {
task->primitive_return(msg.recv->get_ivar(state, access->name()), msg);
}
return cExecuteContinue;
}
示例8: allocate
AccessVariable* AccessVariable::allocate(STATE) {
AccessVariable* av = state->new_object<AccessVariable>(G(access_variable));
av->set_executor(AccessVariable::access_execute);
return av;
}