1010
1111/* definitions */
1212
13+ /* Common macro functions */
14+ #define is_whitespace (c ) (c == ' ' || c == '\t')
15+ #define is_newline (c ) (c == '\r' || c == '\n')
16+ #define is_alnum (c ) \
17+ ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || \
18+ (c >= '0' && c <= '9') || (c == '_'))
19+ #define is_digit (c ) ((c >= '0' && c <= '9'))
20+ #define is_hex (c ) \
21+ (is_digit(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))
22+
1323/* Limitations */
1424#define MAX_TOKEN_LEN 256
1525#define MAX_ID_LEN 64
2636#define MAX_BB_DOM_SUCC 64
2737#define MAX_BB_RDOM_SUCC 256
2838#define MAX_GLOBAL_IR 256
29- #define MAX_SOURCE 1048576
3039#define MAX_CODE 262144
3140#define MAX_DATA 262144
3241#define MAX_SYMTAB 65536
3342#define MAX_STRTAB 65536
3443#define MAX_HEADER 1024
3544#define MAX_PROGRAM_HEADER 1024
3645#define MAX_SECTION 1024
37- #define MAX_ALIASES 128
3846#define MAX_SECTION_HEADER 1024
3947#define MAX_SHSTR 1024
4048#define MAX_INTERP 1024
5664#define SMALL_ARENA_SIZE 65536 /* 64 KiB - for small allocations */
5765#define LARGE_ARENA_SIZE 524288 /* 512 KiB - for instruction arena */
5866#define DEFAULT_FUNCS_SIZE 64
59- #define DEFAULT_INCLUSIONS_SIZE 16
67+ #define DEFAULT_SRC_FILE_COUNT 8
6068
6169/* Arena compaction bitmask flags for selective memory reclamation */
6270#define COMPACT_ARENA_BLOCK 0x01 /* BLOCK_ARENA - variables/blocks */
@@ -131,6 +139,7 @@ typedef struct {
131139/* lexer tokens */
132140typedef enum {
133141 T_start , /* FIXME: Unused, intended for lexer state machine init */
142+ T_eof , /* end-of-file (EOF) */
134143 T_numeric ,
135144 T_identifier ,
136145 T_comma , /* , */
@@ -179,7 +188,6 @@ typedef enum {
179188 T_question , /* ? */
180189 T_colon , /* : */
181190 T_semicolon , /* ; */
182- T_eof , /* end-of-file (EOF) */
183191 T_ampersand , /* & */
184192 T_return ,
185193 T_if ,
@@ -211,38 +219,36 @@ typedef enum {
211219 T_cppd_endif ,
212220 T_cppd_ifdef ,
213221 T_cppd_ifndef ,
214- T_cppd_pragma
215- } token_t ;
222+ T_cppd_pragma ,
223+ /* C pre-processor specific, these kinds
224+ * will be removed after pre-processing is done.
225+ */
226+ T_newline ,
227+ T_backslash ,
228+ T_whitespace ,
229+ T_tab
230+ } token_kind_t ;
216231
217232/* Source location tracking for better error reporting */
218233typedef struct {
234+ int pos ; /* raw source file position */
235+ int len ; /* length of token */
219236 int line ;
220237 int column ;
221238 char * filename ;
222239} source_location_t ;
223240
224- /* Token structure with metadata for enhanced lexing */
225- typedef struct token_info {
226- token_t type ;
227- char value [MAX_TOKEN_LEN ];
241+ typedef struct token {
242+ token_kind_t kind ;
243+ char * literal ;
228244 source_location_t location ;
229- struct token_info * next ; /* For freelist management */
230- } token_info_t ;
231-
232- /* Token freelist for memory reuse */
233- typedef struct {
234- token_info_t * freelist ;
235- int allocated_count ;
236- } token_pool_t ;
245+ struct token * next ;
246+ } token_t ;
237247
238- /* Token buffer for improved lookahead */
239- #define TOKEN_BUFFER_SIZE 8
240- typedef struct {
241- token_info_t * tokens [TOKEN_BUFFER_SIZE ];
242- int head ;
243- int tail ;
244- int count ;
245- } token_buffer_t ;
248+ typedef struct token_stream {
249+ token_t * head ;
250+ token_t * tail ;
251+ } token_stream_t ;
246252
247253/* String pool for identifier deduplication */
248254typedef struct {
@@ -387,7 +393,7 @@ struct var {
387393 int in_loop ;
388394 struct var * base ;
389395 int subscript ;
390- struct var * subscripts [64 ];
396+ struct var * subscripts [128 ];
391397 int subscripts_idx ;
392398 rename_t rename ;
393399 ref_block_list_t ref_block_list ; /* blocks which kill variable */
@@ -412,25 +418,13 @@ struct var {
412418 bool ofs_based_on_stack_top ;
413419};
414420
415- typedef struct {
416- char name [MAX_VAR_LEN ];
417- bool is_variadic ;
418- int start_source_idx ;
419- var_t param_defs [MAX_PARAMS ];
420- int num_param_defs ;
421- int params [MAX_PARAMS ];
422- int num_params ;
423- bool disabled ;
424- } macro_t ;
425-
426421typedef struct func func_t ;
427422
428423/* block definition */
429424struct block {
430425 var_list_t locals ;
431426 struct block * parent ;
432427 func_t * func ;
433- macro_t * macro ;
434428 struct block * next ;
435429};
436430
@@ -494,13 +488,6 @@ typedef struct {
494488 type_t * type ;
495489} lvalue_t ;
496490
497- /* alias for #defines */
498- typedef struct {
499- char alias [MAX_VAR_LEN ];
500- char value [MAX_VAR_LEN ];
501- bool disabled ;
502- } alias_t ;
503-
504491/* constants for enums */
505492typedef struct {
506493 char alias [MAX_VAR_LEN ];
0 commit comments