backend: Add abstract syntax tree groundwork
Signed-off-by: Ian Moffett <ian@mirocom.org>
This commit is contained in:
38
backend/ast.c
Normal file
38
backend/ast.c
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) 2026, Mirocom Laboratories
|
||||
* Provided under the BSD-3 clause
|
||||
*
|
||||
* Abstract:
|
||||
* This file implements abstract syntaxt tree creation
|
||||
* logic.
|
||||
* Author:
|
||||
* Ian M. Moffett <ian@mirocom.org>
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include "backend/ast.h"
|
||||
|
||||
int
|
||||
ast_node_alloc(struct quip_state *state, ast_type_t type, struct ast_node **res)
|
||||
{
|
||||
struct ast_node *node;
|
||||
|
||||
if (res == NULL) {
|
||||
errno = -EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
node = ptrbox_malloc(&state->ptrbox, (sizeof(*node)));
|
||||
if (node == NULL) {
|
||||
errno = -ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
|
||||
node->left = NULL;
|
||||
node->right = NULL;
|
||||
node->data = NULL;
|
||||
*res = node;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user