@@ -94,31 +94,37 @@ int init_layout(tis_t* tis, char* layoutfile, int layoutmode) {
94
94
while (isspace (ch = fgetc (layout ))) {
95
95
// discard whitespace
96
96
}
97
+ tis -> nodes [i ] = calloc (1 , sizeof (tis_node_t ));
98
+ tis -> nodes [i ]-> row = i / tis -> cols ;
99
+ tis -> nodes [i ]-> col = i % tis -> cols ;
100
+ tis -> nodes [i ]-> writereg = TIS_REGISTER_INVALID ;
97
101
switch (ch ) {
98
102
case 'C' : // compute
99
103
case 'c' :
100
- tis -> nodes [i ] = calloc (1 , sizeof (tis_node_t ));
101
104
tis -> nodes [i ]-> type = TIS_NODE_TYPE_COMPUTE ;
102
105
tis -> nodes [i ]-> id = id ++ ;
103
- tis -> nodes [i ]-> row = i / tis -> cols ;
104
- tis -> nodes [i ]-> col = i % tis -> cols ;
105
- tis -> nodes [i ]-> writereg = TIS_REGISTER_INVALID ;
106
106
tis -> nodes [i ]-> last = TIS_REGISTER_INVALID ;
107
107
break ;
108
108
case 'M' : // memory (assume stack memory)
109
109
case 'm' :
110
110
case 'S' : // stack memory
111
111
case 's' :
112
- error ("Not yet implemented\n" );
112
+ tis -> nodes [i ]-> type = TIS_NODE_TYPE_MEMORY_STACK ;
113
+ tis -> nodes [i ]-> index = 0 ;
114
+ error ("Node type not yet implemented\n" );
115
+ fclose (layout );
113
116
return INIT_FAIL ;
114
117
case 'R' : // random access memory
115
118
case 'r' :
116
- error ("Not yet implemented\n" );
119
+ tis -> nodes [i ]-> type = TIS_NODE_TYPE_MEMORY_RAM ;
120
+ tis -> nodes [i ]-> index = 0 ;
121
+ error ("Node type not yet implemented\n" );
122
+ fclose (layout );
117
123
return INIT_FAIL ;
118
- case 'D' : // damaged
124
+ case 'D' : // damaged / disabled
119
125
case 'd' :
120
- error ( "Not yet implemented\n" ) ;
121
- return INIT_FAIL ;
126
+ tis -> nodes [ i ] -> type = TIS_NODE_TYPE_DAMAGED ;
127
+ break ;
122
128
case EOF :
123
129
error ("Unexpected EOF while reading node specifiers\n" );
124
130
fclose (layout );
@@ -169,19 +175,24 @@ int init_layout(tis_t* tis, char* layoutfile, int layoutmode) {
169
175
}
170
176
} else if (tis -> inputs [index ]-> type == TIS_IO_TYPE_IOSTREAM_ASCII ||
171
177
tis -> inputs [index ]-> type == TIS_IO_TYPE_IOSTREAM_NUMERIC ) {
172
- if (strcasecmp (buf , "STDIN" ) == 0 ||
173
- strcasecmp (buf , "-" ) == 0 ) {
174
- debug ("Set I%zu to use stdin\n" , index );
175
- tis -> inputs [index ]-> file .file = stdin ; // TODO make sure this doesn't already have a file
176
- } else {
177
- debug ("Set I%zu to use file %.*s\n" , index , BUFSIZE , buf );
178
- if ((tis -> inputs [index ]-> file .file = fopen (buf , "r" )) == NULL ) {
179
- error ("Unable to open %.*s for reading\n" , BUFSIZE , buf ); // TODO what to do about this? error out?
178
+ if (tis -> inputs [index ]-> file .file == NULL ) {
179
+ if (strcasecmp (buf , "STDIN" ) == 0 ||
180
+ strcasecmp (buf , "-" ) == 0 ) {
181
+ debug ("Set I%zu to use stdin\n" , index );
182
+ tis -> inputs [index ]-> file .file = stdin ; // TODO make sure this doesn't already have a file
183
+ } else {
184
+ debug ("Set I%zu to use file %.*s\n" , index , BUFSIZE , buf );
185
+ if ((tis -> inputs [index ]-> file .file = fopen (buf , "r" )) == NULL ) {
186
+ error ("Unable to open %.*s for reading\n" , BUFSIZE , buf ); // TODO what to do about this? error out?
187
+ }
188
+ register_file_handle (tis -> inputs [index ]-> file .file );
180
189
}
181
- register_file_handle (tis -> inputs [index ]-> file .file );
190
+ } else {
191
+ goto skip_io_token ;
182
192
}
183
193
} else {
184
194
// TODO node type not implemented? internal error?
195
+ goto skip_io_token ;
185
196
}
186
197
break ;
187
198
case 1 :
@@ -198,25 +209,30 @@ int init_layout(tis_t* tis, char* layoutfile, int layoutmode) {
198
209
}
199
210
} else if (tis -> outputs [index ]-> type == TIS_IO_TYPE_IOSTREAM_ASCII ||
200
211
tis -> outputs [index ]-> type == TIS_IO_TYPE_IOSTREAM_NUMERIC ) {
201
- if (strcasecmp (buf , "STDOUT" ) == 0 ||
202
- strcasecmp (buf , "-" ) == 0 ) {
203
- debug ("Set O%zu to use stdout\n" , index );
204
- tis -> outputs [index ]-> file .file = stdout ; // TODO make sure this doesn't already have a file
205
- } else if (strcasecmp (buf , "STDERR" ) == 0 ) {
206
- debug ("Set O%zu to use stderr\n" , index );
207
- tis -> outputs [index ]-> file .file = stderr ;
212
+ if (tis -> outputs [index ]-> file .file == NULL ) {
213
+ if (strcasecmp (buf , "STDOUT" ) == 0 ||
214
+ strcasecmp (buf , "-" ) == 0 ) {
215
+ debug ("Set O%zu to use stdout\n" , index );
216
+ tis -> outputs [index ]-> file .file = stdout ; // TODO make sure this doesn't already have a file
217
+ } else if (strcasecmp (buf , "STDERR" ) == 0 ) {
218
+ debug ("Set O%zu to use stderr\n" , index );
219
+ tis -> outputs [index ]-> file .file = stderr ;
220
+ } else {
221
+ debug ("Set O%zu to use file %.*s\n" , index , BUFSIZE , buf );
222
+ if ((tis -> outputs [index ]-> file .file = fopen (buf , "a" )) == NULL ) {
223
+ error ("Unable to open %.*s for writing\n" , BUFSIZE , buf ); // TODO what to do about this? error out?
224
+ }
225
+ register_file_handle (tis -> outputs [index ]-> file .file );
226
+ }
208
227
} else if (tis -> outputs [index ]-> type == TIS_IO_TYPE_IOSTREAM_NUMERIC &&
209
228
sscanf (buf , "%d" , & (tis -> outputs [index ]-> file .sep )) == 1 ) {
210
- // nothing to do
229
+ debug ( "Set O%zu separator to %d\n" , index , tis -> outputs [ index ] -> file . sep );
211
230
} else {
212
- debug ("Set O%zu to use file %.*s\n" , index , BUFSIZE , buf );
213
- if ((tis -> outputs [index ]-> file .file = fopen (buf , "a" )) == NULL ) {
214
- error ("Unable to open %.*s for writing\n" , BUFSIZE , buf ); // TODO what to do about this? error out?
215
- }
216
- register_file_handle (tis -> outputs [index ]-> file .file );
231
+ goto skip_io_token ;
217
232
}
218
233
} else {
219
- // TODO node type not implemented? internal error?
234
+ // TODO io node type not implemented? internal error?
235
+ goto skip_io_token ;
220
236
}
221
237
break ;
222
238
case 2 :
@@ -277,7 +293,7 @@ int init_nodes(tis_t* tis, char* sourcefile) {
277
293
* nl = '\0' ;
278
294
}
279
295
280
- debug ( "parse line: %.*s\n" , BUFSIZE , buf );
296
+ spam ( "Parse line: %.*s\n" , BUFSIZE , buf );
281
297
282
298
if (buf [0 ] == '\0' ) {
283
299
// empty line; ignore
@@ -533,7 +549,7 @@ int tick(tis_t* tis) {
533
549
tis -> nodes [i ]-> laststate = state ;
534
550
}
535
551
}
536
- debug ( "quiescent = %d\n" , quiescent );
552
+ spam ( "System quiescent? %d\n" , quiescent );
537
553
return quiescent ;
538
554
}
539
555
@@ -609,8 +625,8 @@ int main(int argc, char** argv) {
609
625
break ;
610
626
case 3 :
611
627
sourcefile = argvector [0 ];
612
- tis .rows = atoi (argvector [1 ]);
613
- tis .cols = atoi (argvector [2 ]);
628
+ tis .rows = atoi (argvector [1 ]); // TODO ensure that there is nothing else in this arg
629
+ tis .cols = atoi (argvector [2 ]); // TODO ensure that there is nothing else in this arg
614
630
debug ("Read dimensions %zur %zuc from command line\n" , tis .rows , tis .cols );
615
631
break ;
616
632
default :
0 commit comments