Skip to content

Commit 8fa6346

Browse files
committed
Add token memory management infrastructure
- Add token_info_t structure with type, value, and source location tracking - Add source_location_t for precise error reporting (line, column, filename) - Add token_pool_t for freelist-based memory reuse pattern - Add token_buffer_t for 8-token circular buffer lookahead capability
1 parent 94f345c commit 8fa6346

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

src/defs.h

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
#define MAX_PARAMS 8
2020
#define MAX_LOCALS 1600
2121
#define MAX_FIELDS 64
22-
#define MAX_TYPES 128
23-
#define MAX_IR_INSTR 60000
22+
#define MAX_TYPES 256
23+
#define MAX_IR_INSTR 80000
2424
#define MAX_BB_PRED 128
2525
#define MAX_BB_DOM_SUCC 64
2626
#define MAX_BB_RDOM_SUCC 256
@@ -180,6 +180,37 @@ typedef enum {
180180
T_cppd_pragma
181181
} token_t;
182182

183+
/* Source location tracking for better error reporting */
184+
typedef struct {
185+
int line;
186+
int column;
187+
char *filename;
188+
} source_location_t;
189+
190+
/* Token structure with metadata for enhanced lexing */
191+
typedef struct token_info {
192+
token_t type;
193+
char value[MAX_TOKEN_LEN];
194+
source_location_t location;
195+
struct token_info *next; /* For freelist management */
196+
} token_info_t;
197+
198+
/* Token freelist for memory reuse */
199+
typedef struct {
200+
token_info_t *freelist;
201+
int allocated_count;
202+
int reused_count; /* Statistics for debugging */
203+
} token_pool_t;
204+
205+
/* Token buffer for improved lookahead */
206+
#define TOKEN_BUFFER_SIZE 8
207+
typedef struct {
208+
token_info_t *tokens[TOKEN_BUFFER_SIZE];
209+
int head;
210+
int tail;
211+
int count;
212+
} token_buffer_t;
213+
183214
/* builtin types */
184215
typedef enum {
185216
TYPE_void = 0,

0 commit comments

Comments
 (0)