Exemplo n.º 1
0
void
init_cfunc_struct(mrb_state *mrb, struct RClass* module)
{
    struct cfunc_state *state = cfunc_state(mrb, module);
    struct RClass *struct_class = mrb_define_class_under(mrb, module, "Struct", mrb->object_class);
    set_cfunc_state(mrb, struct_class, state);
    state->struct_class = struct_class;
    
    mrb_define_class_method(mrb, struct_class, "define_struct", cfunc_struct_define_struct, ARGS_REQ(1));
}
Exemplo n.º 2
0
void
init_cfunc_rubyvm(mrb_state *mrb, struct RClass* module)
{
    struct cfunc_state *state = cfunc_state(mrb, module);

    struct RClass *rubyvm_class = mrb_define_class_under(mrb, module, "RubyVM", mrb->object_class);
    state->rubyvm_class = rubyvm_class;
    set_cfunc_state(mrb, rubyvm_class, state);

    mrb_define_class_method(mrb, rubyvm_class, "thread", cfunc_rubyvm_class_thread, ARGS_REQ(1));
    mrb_define_method(mrb, rubyvm_class, "dispatch", cfunc_rubyvm_dispatch, ARGS_ANY());

    struct RClass *rubyvm_task_class = mrb_define_class_under(mrb, rubyvm_class, "Task", mrb->object_class);
    state->rubyvm_task_class = rubyvm_task_class;

    mrb_define_method(mrb, rubyvm_task_class, "wait", cfunc_rubyvm_task_wait, ARGS_NONE());
    mrb_define_method(mrb, rubyvm_task_class, "result", cfunc_rubyvm_task_result, ARGS_NONE());
    mrb_define_method(mrb, rubyvm_task_class, "status", cfunc_rubyvm_task_status, ARGS_NONE());

    mrb_define_const(mrb, rubyvm_task_class, "QUEUED", mrb_fixnum_value(queue_task_queued));
    mrb_define_const(mrb, rubyvm_task_class, "RUNNING", mrb_fixnum_value(queue_task_running));
    mrb_define_const(mrb, rubyvm_task_class, "FINISHED", mrb_fixnum_value(queue_task_finished));
}
Exemplo n.º 3
0
void init_cfunc_type(mrb_state *mrb, struct RClass* module)
{
    struct cfunc_state *state = cfunc_state(mrb, module);
    struct RClass *type_class = mrb_define_class_under(mrb, module, "Type", mrb->object_class);
    MRB_SET_INSTANCE_TT(type_class, MRB_TT_DATA);
    state->type_class = type_class;
    set_cfunc_state(mrb, type_class, state);

    int ai = mrb_gc_arena_save(mrb);
    mrb_define_class_method(mrb, type_class, "refer", cfunc_type_class_refer, ARGS_REQ(1));
    mrb_define_class_method(mrb, type_class, "size", cfunc_type_size, ARGS_NONE());
    mrb_define_class_method(mrb, type_class, "align", cfunc_type_align, ARGS_NONE());
    mrb_define_class_method(mrb, type_class, "get", cfunc_type_class_get, ARGS_REQ(1));
    mrb_define_class_method(mrb, type_class, "set", cfunc_type_class_set, ARGS_REQ(2));

    mrb_define_method(mrb, type_class, "initialize", cfunc_type_initialize, ARGS_ANY());
    mrb_define_method(mrb, type_class, "value", cfunc_type_get_value, ARGS_NONE());
    mrb_define_method(mrb, type_class, "value=", cfunc_type_set_value, ARGS_REQ(1));
    mrb_define_method(mrb, type_class, "addr", cfunc_type_addr, ARGS_NONE());
    mrb_define_method(mrb, type_class, "to_ffi_value", cfunc_type_addr, ARGS_NONE());
    DONE;

    int map_size = sizeof(types) / sizeof(struct mrb_ffi_type);
    int i;
    for(i = 0; i < map_size; ++i) {
        struct RClass *new_class = mrb_define_class_under(mrb, module, types[i].name, type_class);
        mrb_value ffi_type = mrb_obj_value(Data_Wrap_Struct(mrb, mrb->object_class, &cfunc_class_ffi_data_type, &types[i]));
        mrb_obj_iv_set(mrb, (struct RObject*)new_class, mrb_intern_cstr(mrb, "@ffi_type"), ffi_type);
    }
    DONE;
    
    mrb_value mod = mrb_obj_value(module);
    state->void_class = mrb_class_ptr(mrb_const_get(mrb, mod, mrb_intern_cstr(mrb, "Void")));
    state->uint8_class = mrb_class_ptr(mrb_const_get(mrb, mod, mrb_intern_cstr(mrb, "UInt8")));
    state->sint8_class = mrb_class_ptr(mrb_const_get(mrb, mod, mrb_intern_cstr(mrb, "SInt8")));
    state->uint16_class = mrb_class_ptr(mrb_const_get(mrb, mod, mrb_intern_cstr(mrb, "UInt16")));
    state->sint16_class = mrb_class_ptr(mrb_const_get(mrb, mod, mrb_intern_cstr(mrb, "SInt16")));
    state->uint32_class = mrb_class_ptr(mrb_const_get(mrb, mod, mrb_intern_cstr(mrb, "UInt32")));
    state->sint32_class = mrb_class_ptr(mrb_const_get(mrb, mod, mrb_intern_cstr(mrb, "SInt32")));
    state->uint64_class = mrb_class_ptr(mrb_const_get(mrb, mod, mrb_intern_cstr(mrb, "UInt64")));
    state->sint64_class = mrb_class_ptr(mrb_const_get(mrb, mod, mrb_intern_cstr(mrb, "SInt64")));
    state->float_class = mrb_class_ptr(mrb_const_get(mrb, mod, mrb_intern_cstr(mrb, "Float")));
    state->double_class = mrb_class_ptr(mrb_const_get(mrb, mod, mrb_intern_cstr(mrb, "Double")));
    DONE;

    mrb_define_class_method(mrb, mrb->nil_class, "size", cfunc_nil_size, ARGS_NONE());
    mrb_define_class_method(mrb, mrb->nil_class, "align", cfunc_nil_align, ARGS_NONE());
    DONE;

    // uint64 specific
    struct RClass *uint64_class = state->uint64_class;
    mrb_define_class_method(mrb, uint64_class, "get", cfunc_uint64_class_get, ARGS_REQ(1));
    mrb_define_method(mrb, uint64_class, "value", cfunc_uint64_get_value, ARGS_NONE());
    mrb_define_method(mrb, uint64_class, "low", cfunc_uint64_get_low, ARGS_NONE());
    mrb_define_method(mrb, uint64_class, "low=", cfunc_uint64_set_low, ARGS_REQ(1));
    mrb_define_method(mrb, uint64_class, "high", cfunc_uint64_get_high, ARGS_NONE());
    mrb_define_method(mrb, uint64_class, "high=", cfunc_uint64_set_high, ARGS_REQ(1));
    mrb_define_method(mrb, uint64_class, "to_s", cfunc_uint64_to_s, ARGS_REQ(1));
    mrb_define_method(mrb, uint64_class, "divide", cfunc_uint64_divide, ARGS_REQ(1));
    DONE;
    
    // sint64 specific
    struct RClass *sint64_class = state->sint64_class;
    mrb_define_class_method(mrb, sint64_class, "get", cfunc_sint64_class_get, ARGS_REQ(1));
    mrb_define_method(mrb, sint64_class, "value", cfunc_sint64_get_value, ARGS_NONE());
    mrb_define_method(mrb, sint64_class, "low", cfunc_uint64_get_low, ARGS_NONE());
    mrb_define_method(mrb, sint64_class, "low=", cfunc_uint64_set_low, ARGS_REQ(1));
    mrb_define_method(mrb, sint64_class, "high", cfunc_uint64_get_high, ARGS_NONE());
    mrb_define_method(mrb, sint64_class, "high=", cfunc_uint64_set_high, ARGS_REQ(1));
    mrb_define_method(mrb, sint64_class, "to_s", cfunc_int64_to_s, ARGS_REQ(1));
    DONE;
}