~pixelherodev/zyg

4fd358d0f3cff9e6dfcdda8dd8d16f886233c7be — Noam Preil a month ago 3f8b1db
Fix function naming
2 files changed, 16 insertions(+), 12 deletions(-)

M parser.c
M sema.c
M parser.c => parser.c +5 -2
@@ 1190,7 1190,8 @@ p_fnexpr(int legacy, int external)
		}
	}
	fn = c3append(&ctx.tree, C3_VALUE_FN, 2, type, block);
	stbds_hmput(ctx.tree.analysis.names, fn, ident);
	stbds_hmput(ctx.tree.analysis.names, fn, c3nodechild(ctx.tree, ident, 0));
	stbds_hmput(ctx.tree.analysis.types, fn, type);
	return fn;
}



@@ 1204,7 1205,7 @@ p_fn_legacy(int external)
		parser_advance();
		EXPECT(C3_SCOLON, "Expected semicolon to end vardecl, found '%s'",c3tagstr(ctx.tokens.tags[ctx.i]));
	}
	return c3append(&ctx.tree, C3_CONST, 3, c3nodechild(ctx.tree, value, 2), c3nodechild(ctx.tree, value, 0), value);
	return c3append(&ctx.tree, C3_CONST, 3, stbds_hmget(ctx.tree.analysis.names, value), c3nodechild(ctx.tree, value, 0), value);
}

static uint32_t


@@ 1282,6 1283,8 @@ p_var_decl(void)
			ERROR("failed to read expr", 0);
			return -1;
		}
		if(c3nodetag(ctx.tree, value) == C3_VALUE_FN)
			stbds_hmput(ctx.tree.analysis.names, value, c3nodechild(ctx.tree, ident, 0));
		parser_advance();
	}
	EXPECT(C3_SCOLON, "Expected semicolon to end vardecl, found '%s'",c3tagstr(ctx.tokens.tags[ctx.i]));

M sema.c => sema.c +11 -10
@@ 7,6 7,7 @@
#include "c3/c3.h"
#include "c3/util.h"
#include "c3/sema/scope.h"
#include "c3/stb.h"
#include "c3/stb_ds.h"

#include "package.h"


@@ 19,7 20,6 @@ int t_init(c3ctx *);
int t_node(uint32_t source);
int expr_init(c3ctx *);
uint32_t l_fn(uint32_t index);
int expr_finish(void);
int expr_gen_test(void);

static void


@@ 42,6 42,8 @@ anal_execute(c3ctx *c3)
	uint32_t i;
	uint32_t t;
	uint16_t kids = stbds_hmlenu(c3->analysis.deps);
	stb_sb_free(c3->analysis.fns);
	c3->analysis.fns = NULL;
	for(i = 0; i < kids; i += 1){
		t = c3->analysis.deps[i].key;
		// TODO: comptime engine


@@ 51,23 53,22 @@ anal_execute(c3ctx *c3)
		}
		// If function and has body (i.e. not external), generate IR
		if(c3nodetag(*c3, t) == C3_VALUE_FN && c3nodechild(*c3, t, 1) != UINT32_MAX){
			if(l_fn(t) == UINT32_MAX){
			t = l_fn(t);
			if(t == UINT32_MAX){
				ERROR("Failed to extract expression semantics", 0);
				return 0;
			}
			if(!stb_sb_push_u32(&c3->analysis.fns, t))
				OOM();
		}
	}
	return 1;
}

static int
anal_finish(c3ctx *c3, int good, int out)
anal_finish(c3ctx *c3, int out)
{
	char c = 1;
	if(good && !expr_finish())
		return 0;
	if(!good)
		return 0;
	if(out == -1)
		return 1;
	if(write(out, &c, 1) != 1){


@@ 84,7 85,6 @@ anal_finish(c3ctx *c3, int good, int out)
int
analysis(c3ctx *c3, int out)
{
	int good;
	if(!t_init(c3))
		return 0;
	if(!expr_init(c3))


@@ 105,6 105,7 @@ analysis(c3ctx *c3, int out)
		return 0;
	if(zyg_ctx.usage_debug)
		usagedump(*c3);
	good = anal_execute(c3);
	return anal_finish(c3, good, out);
	if(!anal_execute(c3))
		return 0;
	return anal_finish(c3, out);
}