1#ifndef PRISM_INTERNAL_NODE_H
2#define PRISM_INTERNAL_NODE_H
10#include "prism/internal/assert.h"
16#define PM_LOCATION_START(location_) ((location_)->start)
19#define PM_LOCATION_END(location_) ((location_)->start + (location_)->length)
27 uint32_t left_end = PM_LOCATION_END(&left);
28 uint32_t right_end = PM_LOCATION_END(&right);
29 uint32_t end = left_end > right_end ? left_end : right_end;
30 pm_location_t location = { .start = start, .length = end - start };
64 if (list->size < list->capacity) {
65 list->nodes[list->size++] = node;
67 pm_scratch_node_list_append_slow(arena, list, node);
93#define PM_NODE_CHUNK_SIZE sizeof(pm_node_chunk_t)
96#define PM_NODE_CHUNK_MASK ((uintptr_t) (PM_NODE_CHUNK_SIZE - 1))
99#define PM_NODE_CHUNK_SLOTS (sizeof(((pm_node_chunk_t *) 0)->slots) / sizeof(pm_node_t *))
102#define PM_NODE_CHUNK_OF(pointer_) ((pm_node_chunk_t *) ((uintptr_t) (pointer_) & ~PM_NODE_CHUNK_MASK))
105#define PM_NODE_CHUNK_BATCH 32
115 pm_node_chunk_t *free;
118 pm_node_chunk_t *next;
121 pm_node_chunk_t *end;
132void pm_node_list_open_append_slow(
pm_node_chunks_t *chunks, pm_node_list_t *list, pm_node_t *node);
140pm_node_list_open_append(
pm_node_chunks_t *chunks, pm_node_list_t *list, pm_node_t *node) {
141 if (((uintptr_t) list->
nodes & PM_NODE_CHUNK_MASK) != 0) {
142 *list->
nodes++ = node;
145 pm_node_list_open_append_slow(chunks, list, node);
154pm_node_list_open_last(
const pm_node_list_t *list) {
155 return list->
nodes[-1];
170pm_node_list_t pm_node_list_single(
pm_arena_t *arena, pm_node_t *node);
176void pm_node_list_prepend_finalized(
pm_arena_t *arena, pm_node_list_t *list, pm_node_t *node);
183pm_node_list_slice(
const pm_node_list_t *list, uint32_t start, uint32_t size) {
184 PRISM_ASSERT(start + size <= list->size);
185 return (pm_node_list_t) { .size = size, .nodes = size == 0 ? NULL : list->
nodes + start };
A bump allocator for the prism parser.
#define PRISM_FORCE_INLINE
Force a function to be inlined at every call site.
#define PRISM_INLINE
Old Visual Studio versions do not support the inline keyword, so we need to define it to be __inline.
Functions related to nodes in the AST.
This struct represents a slice in the source code, defined by an offset and a length.
uint32_t start
The offset of the location from the start of the source.
uint32_t size
The number of nodes in the list.
struct pm_node ** nodes
The nodes in the list.