~pixelherodev/zyg

f82bb4212b86a20e61a2ce2a50c225edb370ba45 — Noam Preil 3 months ago b0d3a15
[parser] legacy function syntax
1 files changed, 31 insertions(+), 13 deletions(-)

M parser.c
M parser.c => parser.c +31 -13
@@ 45,7 45,7 @@ static struct {
static uint32_t p_assign_expr(void);
static uint32_t p_block(void);
static uint32_t p_expr(void);
static uint32_t p_fnexpr(void);
static uint32_t p_fnexpr(int legacy);
static uint32_t p_type_expr(void);
static uint32_t p_ident(void);
static uint32_t p_str(void);


@@ 440,7 440,7 @@ p_primary_expr(void)
	if(parser_is(0, C3_RETURN))
		return p_return();
	if(parser_is(0, C3_FN))
		return p_fnexpr();
		return p_fnexpr(0);
	if(parser_is(0, C3_LBRACE))
		return p_block();
	if(parser_is(0, C3_LBRACE))


@@ 1088,7 1088,7 @@ p_call_conv(void)
}

static uint32_t
p_fnproto(void)
p_fnproto(int legacy)
{
	int more;
	int infer;


@@ 1098,8 1098,8 @@ p_fnproto(void)
	uint32_t ret_type;
	callconv = parser_dedup_node_tag(&ctx.accel.misc, C3_CALL_CONV_DEFAULT);
	params = NULL;
	EXPECT(C3_FN, "Expected fn token for fnproto",0);
	parser_advance();
	if(!legacy && !parser_is_consume(C3_FN))
		FATAL("Expected fn token for fnproto",0);
	EXPECT(C3_LPAREN, "Expected lparen after fn",0);
	parser_advance();
	more = 0;


@@ 1156,11 1156,16 @@ p_fnproto(void)
}

static uint32_t
p_fnexpr(void)
p_fnexpr(int legacy)
{
	uint32_t type;
	uint32_t block;
	type = p_fnproto();
	uint32_t ident = -1;
	if(legacy){
		ident = p_ident();
		parser_advance();
	}
	type = p_fnproto(legacy);
	if(type == -1){
		ERROR("Failed to read fnproto", 0);
		return -1;


@@ 1171,7 1176,14 @@ p_fnexpr(void)
		ERROR("Failed to read block", 0);
		return -1;
	}
	return c3append(&ctx.tree, C3_VALUE_FN, 3, type, block, -1);
	return c3append(&ctx.tree, C3_VALUE_FN, 3, type, block, ident);
}

static uint32_t
p_fn_legacy(void)
{
	uint32_t value = p_fnexpr(1);
	return c3append(&ctx.tree, C3_CONST, 3, c3nodechild(ctx.tree, value, 2), c3nodechild(ctx.tree, value, 0), value);
}

static uint32_t


@@ 1267,14 1279,20 @@ p_tl_decl(void)
	int export;
	uint32_t node;
	pub = parser_is_consume(C3_PUB);
	if(parser_is(0, C3_USINGNAMESPACE))
		FATAL("TODO: usingnamespace",0);
	export = parser_is_consume(C3_EXPORT);
	if(parser_is(0, C3_EXTERN))
	if(parser_is(0, C3_EXTERN)){
		FATAL("TODO: externs", 0);
	if(parser_is(0, C3_THREADLOCAL))
	}
	if(parser_is(0, C3_THREADLOCAL)){
		FATAL("TODO: thread locals", 0);
	node = p_var_decl();
	}
	if(parser_is_consume(C3_FN))
		node = p_fn_legacy();
	else if(parser_is(0, C3_USINGNAMESPACE)){
		FATAL("TODO: usingnamespace",0);
	}
	else
		node = p_var_decl();
	if(node == -1)
		return -1;
	if(pub)