Skip to content

Make a contextual push/pop ctx for code body construction #69

@Ed94

Description

@Ed94

I realized I can have an ergonomic feature for at least code bodies similar to construction pattern used in Imguis (such as the one done in SectrPrototype)

so it would be essentially

Code body = def_body(CT_Global_Body);
push(body);

CodeTypedef td = parse_typedef(...);
... Any built code asts automatically parent to the body

pop(body);

A auto-defer could be made so its just:

PopDefer parent_scope = scope(body);

// Where it just pops using a destructor. Or a for-loop push-pop for C11
for (b32 pushed = push(body); pushed; --pushed, pop(body))
{
	...
}

#define scope(body) for (b32 pushed = push(body); pushed; --pushed, pop(body))

Requires that the Context struct tracks a some sort of stack of bodies that would automatically have ASTs appended to them from the AST builder interfaces (upfront, parsing, untyped, etc). Usage would be as simple as:

Code<Something> def_<something>(...)
{
	...
	
	if (_ctx.body_stack.front) { 
		body_append( _ctx.body_stack.front, result );
	}
	return result;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    Status

    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions