Method: RCSimCinterface.rcsim_add_behavior_events
- Defined in:
- ext/hruby_sim/hruby_rcsim_build.c
.rcsim_add_behavior_events(behaviorV, eventVs) ⇒ Object
Adds events to a C behavior.
1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 |
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 1138 VALUE rcsim_add_behavior_events(VALUE mod, VALUE behaviorV, VALUE eventVs) { /* Get the C behavior from the Ruby value. */ Behavior behavior; value_to_rcsim(BehaviorS,behaviorV,behavior); // printf("rcsim_add_behavior_events with behavior=%p\n",behavior); /* Prepare the size for the events. */ long num = RARRAY_LEN(eventVs); long old_num = behavior->num_events; behavior->num_events += num; // printf("first behavior->events=%p\n",behavior->events); fflush(stdout); behavior->events = realloc(behavior->events, sizeof(Event[behavior->num_events])); // behavior->events = (Event*)my_realloc(behavior->events, // sizeof(Event[old_num]), sizeof(Event[behavior->num_events])); // printf("now behavior->events=%p\n",behavior->events); fflush(stdout); // printf("access test: %p\n",behavior->events[0]); fflush(stdout); /* Get and add the events from the Ruby value. */ for(long i=0; i< num; ++i) { Event event; // show_access(behavior->events,old_num+i); value_to_rcsim(EventS,rb_ary_entry(eventVs,i),event); behavior->events[old_num + i] = event; /* Update the signal of the event to say it activates the behavior. */ SignalI sig = event->signal; switch(event->edge) { case ANYEDGE: sig->num_any++; // printf("first sig->any=%p\n",sig->any); fflush(stdout); sig->any = realloc(sig->any,sizeof(Object[sig->num_any])); // sig->any = (Object*)my_realloc(sig->any, // sizeof(Object[sig->num_any-1]),sizeof(Object[sig->num_any])); // printf("now sig->any=%p\n",sig->any); fflush(stdout); // printf("access test: %p\n",sig->any[0]); fflush(stdout); // show_access(sig->any,sig->num_any-1); // printf("sig->any=%p\n",sig->any); sig->any[sig->num_any-1] = (Object)behavior; break; case POSEDGE: sig->num_pos++; // printf("first sig->pos=%p\n",sig->pos); fflush(stdout); sig->pos = realloc(sig->pos,sizeof(Object[sig->num_pos])); // sig->pos = (Object*)my_realloc(sig->pos, // sizeof(Object[sig->num_pos-1]),sizeof(Object[sig->num_pos])); // printf("now sig->pos=%p\n",sig->pos); fflush(stdout); // printf("access test: %p\n",sig->pos[0]); fflush(stdout); // show_access(sig->pos,sig->num_pos-1); // printf("sig->pos=%p\n",sig->pos); sig->pos[sig->num_pos-1] = (Object)behavior; break; case NEGEDGE: sig->num_neg++; // printf("first sig->neg=%p\n",sig->neg); fflush(stdout); sig->neg = realloc(sig->neg,sizeof(Object[sig->num_neg])); // sig->neg = (Object*)my_realloc(sig->neg, // sizeof(Object[sig->num_neg-1]),sizeof(Object[sig->num_neg])); // printf("now sig->neg=%p\n",sig->neg); fflush(stdout); // printf("access test: %p\n",sig->neg[0]); fflush(stdout); // show_access(sig->neg,sig->num_neg-1); // printf("sig->neg=%p\n",sig->neg); sig->neg[sig->num_neg-1] = (Object)behavior; break; default: perror("Invalid value for an edge."); } } return behaviorV; } |