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_alpha (c ) ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
17+ #define is_digit (c ) ((c >= '0' && c <= '9'))
18+ #define is_alnum (c ) (is_alpha(c) || is_digit(c))
19+ #define is_hex (c ) \
20+ (is_digit(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))
21+
1322/* Limitations */
1423#define MAX_TOKEN_LEN 256
1524#define MAX_ID_LEN 64
2635#define MAX_BB_DOM_SUCC 64
2736#define MAX_BB_RDOM_SUCC 256
2837#define MAX_GLOBAL_IR 256
29- #define MAX_SOURCE 1048576
3038#define MAX_CODE 262144
3139#define MAX_DATA 262144
3240#define MAX_SYMTAB 65536
3341#define MAX_STRTAB 65536
3442#define MAX_HEADER 1024
3543#define MAX_PROGRAM_HEADER 1024
3644#define MAX_SECTION 1024
37- #define MAX_ALIASES 128
3845#define MAX_SECTION_HEADER 1024
3946#define MAX_SHSTR 1024
4047#define MAX_INTERP 1024
5663#define SMALL_ARENA_SIZE 65536 /* 64 KiB - for small allocations */
5764#define LARGE_ARENA_SIZE 524288 /* 512 KiB - for instruction arena */
5865#define DEFAULT_FUNCS_SIZE 64
59- #define DEFAULT_INCLUSIONS_SIZE 16
66+ #define DEFAULT_SRC_FILE_COUNT 8
6067
6168/* Arena compaction bitmask flags for selective memory reclamation */
6269#define COMPACT_ARENA_BLOCK 0x01 /* BLOCK_ARENA - variables/blocks */
@@ -131,6 +138,7 @@ typedef struct {
131138/* lexer tokens */
132139typedef enum {
133140 T_start , /* FIXME: Unused, intended for lexer state machine init */
141+ T_eof , /* end-of-file (EOF) */
134142 T_numeric ,
135143 T_identifier ,
136144 T_comma , /* , */
@@ -179,7 +187,6 @@ typedef enum {
179187 T_question , /* ? */
180188 T_colon , /* : */
181189 T_semicolon , /* ; */
182- T_eof , /* end-of-file (EOF) */
183190 T_ampersand , /* & */
184191 T_return ,
185192 T_if ,
@@ -211,38 +218,36 @@ typedef enum {
211218 T_cppd_endif ,
212219 T_cppd_ifdef ,
213220 T_cppd_ifndef ,
214- T_cppd_pragma
215- } token_t ;
221+ T_cppd_pragma ,
222+ /* C pre-processor specific, these kinds
223+ * will be removed after pre-processing is done.
224+ */
225+ T_newline ,
226+ T_backslash ,
227+ T_whitespace ,
228+ T_tab
229+ } token_kind_t ;
216230
217231/* Source location tracking for better error reporting */
218232typedef struct {
233+ int pos ; /* raw source file position */
234+ int len ; /* length of token */
219235 int line ;
220236 int column ;
221237 char * filename ;
222238} source_location_t ;
223239
224- /* Token structure with metadata for enhanced lexing */
225- typedef struct token_info {
226- token_t type ;
227- char value [MAX_TOKEN_LEN ];
240+ typedef struct token {
241+ token_kind_t kind ;
242+ char * literal ;
228243 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 ;
244+ struct token * next ;
245+ } token_t ;
237246
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 ;
247+ typedef struct token_stream {
248+ token_t * head ;
249+ token_t * tail ;
250+ } token_stream_t ;
246251
247252/* String pool for identifier deduplication */
248253typedef struct {
@@ -387,7 +392,7 @@ struct var {
387392 int in_loop ;
388393 struct var * base ;
389394 int subscript ;
390- struct var * subscripts [64 ];
395+ struct var * subscripts [128 ];
391396 int subscripts_idx ;
392397 rename_t rename ;
393398 ref_block_list_t ref_block_list ; /* blocks which kill variable */
@@ -412,25 +417,13 @@ struct var {
412417 bool ofs_based_on_stack_top ;
413418};
414419
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-
426420typedef struct func func_t ;
427421
428422/* block definition */
429423struct block {
430424 var_list_t locals ;
431425 struct block * parent ;
432426 func_t * func ;
433- macro_t * macro ;
434427 struct block * next ;
435428};
436429
@@ -494,13 +487,6 @@ typedef struct {
494487 type_t * type ;
495488} lvalue_t ;
496489
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-
504490/* constants for enums */
505491typedef struct {
506492 char alias [MAX_VAR_LEN ];
0 commit comments