Method: RCSimCinterface.rcsim_add_scope_scopes

Defined in:
ext/hruby_sim/hruby_rcsim_build.c

.rcsim_add_scope_scopes(scopeV, scpVs) ⇒ Object

Adds sub scopes to a C scope.



1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 1111

VALUE rcsim_add_scope_scopes(VALUE mod, VALUE scopeV, VALUE scpVs) {
    /* Get the C scope from the Ruby value. */
    Scope scope;
    value_to_rcsim(ScopeS,scopeV,scope);
    // printf("rcsim_add_scope_scopes with scope=%p\n",scope);
    /* Prepare the size for the sub scopes. */
    long num = RARRAY_LEN(scpVs);
    long old_num = scope->num_scopes;
    scope->num_scopes += num;
    // printf("first scope->scopes=%p\n",scope->scopes); fflush(stdout);
    scope->scopes = realloc(scope->scopes,
                            sizeof(Scope[scope->num_scopes]));
    // scope->scopes = (Scope*)my_realloc(scope->scopes,
    //         sizeof(Scope[old_num]), sizeof(Scope[scope->num_scopes]));
    // printf("now scope->scopes=%p\n",scope->scopes); fflush(stdout);
    // printf("access test: %p\n",scope->scopes[0]); fflush(stdout);
    /* Get and add the sub scopes from the Ruby value. */
    for(long i=0; i< num; ++i) {
        Scope scp;
        // show_access(scope->scopes,old_num+i);
        value_to_rcsim(ScopeS,rb_ary_entry(scpVs,i),scp);
        scope->scopes[old_num + i] = scp;
    }
    return scopeV;
}