Prism Ruby parser
Loading...
Searching...
No Matches
constant_pool.h
Go to the documentation of this file.
1
10#ifndef PRISM_CONSTANT_POOL_H
11#define PRISM_CONSTANT_POOL_H
12
13#include "prism/compiler/exported.h"
14#include "prism/compiler/inline.h"
15#include "prism/compiler/nodiscard.h"
16#include "prism/compiler/nonnull.h"
17
18#include "prism/arena.h"
19
20#include <stddef.h>
21#include <stdint.h>
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
30typedef uint32_t pm_constant_id_t;
31
43static PRISM_INLINE size_t
44pm_constant_id_index(pm_constant_id_t constant_id) {
45 return (size_t) constant_id - 1;
46}
47
51typedef struct {
53 size_t size;
54
56 size_t capacity;
57
61
64
69
76PRISM_EXPORTED_FUNCTION const uint8_t * pm_constant_start(const pm_constant_t *constant) PRISM_NONNULL(1);
77
84PRISM_EXPORTED_FUNCTION size_t pm_constant_length(const pm_constant_t *constant) PRISM_NONNULL(1);
85
91PRISM_EXPORTED_FUNCTION void pm_constant_id_list_init(pm_constant_id_list_t *list) PRISM_NONNULL(1);
92
100PRISM_EXPORTED_FUNCTION void pm_constant_id_list_append(pm_arena_t *arena, pm_constant_id_list_t *list, pm_constant_id_t id) PRISM_NONNULL(1, 2);
101
102#ifdef __cplusplus
103}
104#endif
105
106#endif
A bump allocator for the prism parser.
struct pm_arena_t pm_arena_t
An opaque pointer to an arena that is used for allocations.
Definition arena.h:22
PRISM_EXPORTED_FUNCTION void pm_constant_id_list_init(pm_constant_id_list_t *list) PRISM_NONNULL(1)
Initialize a list of constant ids.
PRISM_EXPORTED_FUNCTION const uint8_t * pm_constant_start(const pm_constant_t *constant) PRISM_NONNULL(1)
Return a raw pointer to the start of a constant.
PRISM_EXPORTED_FUNCTION void pm_constant_id_list_append(pm_arena_t *arena, pm_constant_id_list_t *list, pm_constant_id_t id) PRISM_NONNULL(1
Append a constant id to a list of constant ids.
struct pm_constant_pool_t pm_constant_pool_t
The overall constant pool, which stores constants found while parsing.
Definition constant_pool.h:68
uint32_t pm_constant_id_t
A constant id is a unique identifier for a constant in the constant pool.
Definition constant_pool.h:30
struct pm_constant_t pm_constant_t
A constant in the pool which effectively stores a string.
Definition constant_pool.h:63
PRISM_EXPORTED_FUNCTION size_t pm_constant_length(const pm_constant_t *constant) PRISM_NONNULL(1)
Return the length of a constant.
A list of constant IDs.
Definition constant_pool.h:51
size_t size
The number of constant ids in the list.
Definition constant_pool.h:53
size_t capacity
The number of constant ids that have been allocated in the list.
Definition constant_pool.h:56
pm_constant_id_t * ids
The constant ids in the list.
Definition constant_pool.h:59