Radicalc  Check-in [5c1fe9e51e]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:starting to detach type name from type
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 5c1fe9e51eeb9379f6157c8c0a36ae36618d788d18a8fd870b60a5c3cb3f0da5
User & Date: athaudia 2017-07-10 15:08:24.626
Context
2017-07-11
00:59
annotating data types check-in: afc06aeb77 user: athaudia tags: trunk
2017-07-10
15:08
starting to detach type name from type check-in: 5c1fe9e51e user: athaudia tags: trunk
2017-07-05
01:47
restructured data type printing check-in: 29ec2b46a7 user: athaudia tags: trunk
Changes
Side-by-Side Diff Ignore Whitespace Patch
Changes to bootstrap/main.c.
179
180
181
182
183
184
185

186

187
188
189
190
191
192
193
194
195
196
197


198
199
200
201
202
203
204
205
206
207

208

209
210
211
212
213

214

215
216
217
218
219
220
221
222
223


224
225
226
227
228
229
230
231
232
233

234
235
236
237
238
239
240
179
180
181
182
183
184
185
186

187
188
189
190
191
192
193
194
195
196
197

198
199
200
201
202
203
204
205
206
207
208
209
210

211
212
213
214
215
216
217

218
219
220
221
222
223
224
225
226

227
228
229
230
231
232
233
234
235
236
237

238
239
240
241
242
243
244
245







+
-
+










-
+
+










+
-
+





+
-
+








-
+
+









-
+








struct node {
	struct node** childs;
	int child_count;
	char* name;
	enum node_type type;
	char* val;
	char* data_type_str;
	struct data_type data_type;
	struct data_type* data_type;
	
};

struct node* node_new(enum node_type type) {
	struct node* node = malloc(sizeof(struct node));
	node->childs = 0;
	node->child_count = 0;
	node->name = 0;
	node->type = type;
	node->val = 0;
	node->data_type.name = 0;
	node->data_type_str = 0;
	node->data_type = 0;
	return node;
}

void node_add_child(struct node* parent, struct node* child) {
	int new_size = sizeof(struct node*) * (++parent->child_count);
	parent->childs = realloc(parent->childs, new_size);
	parent->childs[parent->child_count-1] = child;
}

struct function_parameter {
	char* data_type_str;
	struct data_type data_type;
	struct data_type* data_type;
	char* name;
};

struct function {
	char* name;
	char* return_type_str;
	struct data_type return_type;
	struct data_type* return_type;
	struct function_parameter* params;
	int param_count;
	struct node* body;
};

struct function* function_new() {
	struct function* fun = malloc(sizeof(struct function));
	fun->name = 0;
	fun->return_type.name = 0;
	fun->return_type_str = 0;
	fun->return_type = 0;
	fun->params = 0;
	fun->param_count = 0;
	fun->body = node_new(NODE_FUNBODY);
}

void function_add_param(struct function* fun, char* name, char* type) {
	int new_size = sizeof(struct function_parameter) * (++fun->param_count);
	fun->params = realloc(fun->params, new_size);
	fun->params[fun->param_count-1].name = name;
	fun->params[fun->param_count-1].data_type.name = type;
	fun->params[fun->param_count-1].data_type_str = type;
}

struct token* expect(enum token_type type) {
	if(type == tokens[parse_pos].type) {
		++parse_pos;
		return &tokens[parse_pos-1];
	}
324
325
326
327
328
329
330
331

332
333
334
335
336
337
338
329
330
331
332
333
334
335

336
337
338
339
340
341
342
343







-
+







			else
				break;
		}
	}
	expect(TOK_PAREN_CLOSE);
	if(tokens[parse_pos].type == TOK_COLON) {
		expect(TOK_COLON);
		fun->return_type.name = expect(TOK_IDENT)->str;
		fun->return_type_str = expect(TOK_IDENT)->str;
	}
	expect(TOK_NEWLINE);
	while(!is_next_tok(TOK_END)) {
		node_add_child(fun->body, p_statement());
	}
	expect(TOK_END);
	expect(TOK_NEWLINE);
373
374
375
376
377
378
379

380
381
382

383
384
385

386
387
388
389
390
391
392
378
379
380
381
382
383
384
385
386
387

388
389
390
391
392
393
394
395
396
397
398
399







+


-
+



+







		printf("TOKEN %d %s\n", tokens[i].type, tokens[i].str);
}

void print_indent(int num) {
	for(int i = 0; i < num; ++i) printf("  ");
}

/*
void print_data_type(struct data_type* data_type) {
	if(data_type->name)
		printf("%s", data_type->name);
		printf("%s", data_type_str);
	else
		printf("void");
}
*/

void print_tree(struct node* node, int indent) {
	switch(node->type) {
		case NODE_ROOT:
			for(int j = 0; j < node->child_count; ++j) {
				print_tree(node->childs[j], 0);
				printf("\n");
417
418
419
420
421
422
423
424

425
426
427

428
429
430
431
432
433
434
424
425
426
427
428
429
430

431
432
433

434
435
436
437
438
439
440
441







-
+


-
+







			printf("(UNKNOWN TOKEN)");
	}
}

void print_functions() {
	for(int i = 0; i < function_count; ++i) {
		struct function* fun = functions[i];
		print_data_type(&fun->return_type);
		//print_data_type(&fun->return_type);
		printf(" %s(", fun->name);
		for(int i = 0; i < fun->param_count; ++i) {
			print_data_type(&fun->params[i].data_type);
			//print_data_type(&fun->params[i].data_type);
			printf(" %s", fun->params[i].name);
			if(i < fun->param_count-1)
				printf(", ");
		}
		printf(")\n");
		for(int j = 0; j < fun->body->child_count; ++j) {
			print_tree(fun->body->childs[j], 1);