~pixelherodev/zyg

7dccbd7d9dc502f2cd859c4c7ebd84a0d8f3acd7 — Noam Preil 3 months ago 27187f8 + 7fe6184
merge
4 files changed, 15 insertions(+), 13 deletions(-)

M driver.c
M parser.c
M profile.sh -rwxr-xr-x => -rw-r--r--
M sema.c
M driver.c => driver.c +2 -1
@@ 335,7 335,8 @@ tests(void)
	if(f == NULL)
		FATAL_EXIT("Failed to open test binary", 0);
	cpu->memory = calloc(65536, 1);
	if(fread(&((char*)cpu->memory)[0x20], 1, 65536 - 0x20, f) == 0 || ferror(f))
	fread(&((char*)cpu->memory)[0x20], 1, 65536 - 0x20, f);
	if(ferror(f))
		FATAL_EXIT("failed to read test binary", 0);
	fclose(f);
	cpu->read_byte = cpu_read;

M parser.c => parser.c +12 -11
@@ 728,7 728,7 @@ struct prefix {
	uint32_t value;
};

static struct prefix failed = { prefix_error, 0 };
static struct prefix failed = { prefix_error };

// Returns a series of operations to perform, or the address of failed on failure
static struct prefix *


@@ 1166,11 1166,13 @@ p_fnproto(int legacy)
static uint32_t
p_fnexpr(int legacy, int external)
{
	uint32_t type;
	uint32_t block = -1;
	uint32_t ident = -1;
	uint32_t type, block, ident, fn;
	block = -1;
	ident = -1;
	if(legacy){
		ident = p_ident();
		if(ident == -1)
			return -1;
		parser_advance();
	}
	type = p_fnproto(legacy);


@@ 1186,13 1188,17 @@ p_fnexpr(int legacy, int external)
			return -1;
		}
	}
	return c3append(&ctx.tree, C3_VALUE_FN, 3, type, block, ident);
	fn = c3append(&ctx.tree, C3_VALUE_FN, 2, type, block);
	stbds_hmput(ctx.analysis.names, fn, ident);
	return fn;
}

static uint32_t
p_fn_legacy(int external)
{
	uint32_t value = p_fnexpr(1, external);
	if(value == -1)
		return -1;
	if(external){
		parser_advance();
		EXPECT(C3_SCOLON, "Expected semicolon to end vardecl, found '%s'",c3tagstr(ctx.tokens.tags[ctx.i]));


@@ 1203,10 1209,7 @@ p_fn_legacy(int external)
static uint32_t
p_expr(void)
{
	uint32_t expr;
	// TODO: don't special-case these here
	expr = p_boolor_expr();
	return expr;
	return p_boolor_expr();
}

static uint32_t


@@ 1278,8 1281,6 @@ p_var_decl(void)
			ERROR("failed to read expr", 0);
			return -1;
		}
		if(c3nodetag(ctx.tree, value) == C3_VALUE_FN)
			ctx.tree.ast.nodes[value + 1 + 2].node_index = ident;
		parser_advance();
	}
	EXPECT(C3_SCOLON, "Expected semicolon to end vardecl, found '%s'",c3tagstr(ctx.tokens.tags[ctx.i]));

M profile.sh => profile.sh +0 -0
M sema.c => sema.c +1 -1
@@ 50,7 50,7 @@ anal_execute(c3ctx *c3)
			return 0;
		}
		// 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(c3nodetag(*c3, t) == C3_VALUE_FN && c3nodechild(*c3, t, 1) != -1){
			if(l_fn(t) == UINT32_MAX){
				ERROR("Failed to extract expression semantics", 0);
				return 0;