Method: RCSimCinterface.rcsim_add_scope_codes

Defined in:
ext/hruby_sim/hruby_rcsim_build.c

.rcsim_add_scope_codes(scopeV, codeVs) ⇒ Object

Adds codes to a C scope.



1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 1089

VALUE rcsim_add_scope_codes(VALUE mod, VALUE scopeV, VALUE codeVs) {
    /* Get the C scope from the Ruby value. */
    Scope scope;
    value_to_rcsim(ScopeS,scopeV,scope);
    // printf("rcsim_add_scope_codes with scope=%p\n",scope);
    /* Prepare the size for the codes. */
    long num = RARRAY_LEN(codeVs);
    long old_num = scope->num_codes;
    scope->num_codes += num;
    // printf("first scope->codes=%p\n",scope->codes); fflush(stdout);
    scope->codes = realloc(scope->codes,
                            sizeof(Code[scope->num_codes]));
    // printf("now scope->codes=%p\n",scope->codes); fflush(stdout);
    // printf("access test: %p\n",scope->codes[0]); fflush(stdout);
    /* Get and add the codes from the Ruby value. */
    for(long i=0; i< num; ++i) {
        Code code;
        value_to_rcsim(CodeS,rb_ary_entry(codeVs,i),code);
        scope->codes[old_num + i] = code;
    }
    return scopeV;
}