~pixelherodev/c3lib

718f594cd11395d48f3c90b37f204d3d4599a8db — Noam Preil 2 months ago 1bc526e
tmp
3 files changed, 18 insertions(+), 11 deletions(-)

M sema/expr.c
M sema/scope.c
M sema/usage.c
M sema/expr.c => sema/expr.c +3 -0
@@ 711,6 711,9 @@ expr_finish(void)
	kids = stb_sb_count(fns);
	for(i = 0; i < kids; i += 1){
		index = fns[i];
		// Only map functions with bodies (non-external)
		if(c3nodechild(*ctx.c3, c3nodechild(*ctx.c3, index, 0), 1) == -1)
			continue;
		rindex = s_map(c3nodechild(*ctx.c3, index, 0));
		if(rindex == -1){
			ERROR("ICE: unable to map function from CFG to IR; index %u: %u", index, c3nodechild(*ctx.c3, index, 0));

M sema/scope.c => sema/scope.c +0 -2
@@ 9,8 9,6 @@
#include "../stb_ds.h"
#include "scope.h"

#undef WARN
#define WARN(...)

struct c3scope{
	struct c3scope_rc{

M sema/usage.c => sema/usage.c +15 -9
@@ 62,7 62,6 @@ u_kids(uint32_t index, const char *msg, int zero)
{
	uint32_t i;
	uint16_t kid_count = c3nodekids(*ctx.c3, index);
	c3nodedump(*ctx.c3, index, 1, 1);
	for(i = zero ? 0 : 1; i < kid_count; i += 1)
		if(!u_node(index + 1 + i, 1)){
			ERROR("%s", msg);


@@ 248,10 247,13 @@ u_scope_declarative_scope(uint32_t parent_scope, uint32_t index)
	for(i = 0; i < kids; i += 1){
		child = c3nodechild(*ctx.c3, index, i);
		tag = c3nodetag(*ctx.c3, child);
		if(tag == C3_EXPORT)
		WARN("Tag: %s", c3tagstr(tag));
		if(tag == C3_EXPORT || tag == C3_EXTERN)
			child = c3nodechild(*ctx.c3, child, 0);
		if(tag == C3_PUB)
			child = c3nodechild(*ctx.c3, child, 0);
		c3nodedump(*ctx.c3, child, 1, 1);
		tag = c3nodetag(*ctx.c3, child);
		if(tag == C3_CONST || tag == C3_VAR)
			if(!scope_insert(scope, child))
				return -1;


@@ 297,6 299,8 @@ u_declarative_scope(uint32_t index)
		// compiling tests when they're not being run.
		case C3_TEST:
			break;
		case C3_EXTERN:
			break;
		case C3_COMPTIME:
			if(!u_node(index + 1 + i, 1)){
				ret = 0;


@@ 598,14 602,16 @@ u_func(uint32_t index)
		return -1;
	}
	block = c3nodechild(*ctx.c3, index, 1);
	ctx.c3->ast.nodes[block + 1].node_index = fnrettype;
	if(!u_node(index + 2, 1)){
		ERROR("Failed to analyze block call graph", 0);
		call_graph_node = -1;
	}
	else{
		call_graph_node = c3appendarr(ctx.c3, C3_DEP, stb_sb_count(ctx.call_graph.children), ctx.call_graph.children);
	if(block != -1){
		ctx.c3->ast.nodes[block + 1].node_index = fnrettype;
		if(!u_node(index + 2, 1)){
			ERROR("Failed to analyze block call graph", 0);
			call_graph_node = -1;
			goto skip_node;
		}
	}
	call_graph_node = c3appendarr(ctx.c3, C3_DEP, stb_sb_count(ctx.call_graph.children), ctx.call_graph.children);
skip_node:
	ctx.current_scope = prev_scope;
	ctx.current_fn = prev_fn;
	stb_sb_free(ctx.call_graph.children);