1010
1111/* definitions */
1212
13+ /* Common macro functions */
14+ #define is_newline (c ) (c == '\r' || c == '\n')
15+
1316/* Limitations */
1417#define MAX_TOKEN_LEN 256
1518#define MAX_ID_LEN 64
2629#define MAX_BB_DOM_SUCC 64
2730#define MAX_BB_RDOM_SUCC 256
2831#define MAX_GLOBAL_IR 256
29- #define MAX_SOURCE 1048576
3032#define MAX_CODE 262144
3133#define MAX_DATA 262144
3234#define MAX_SYMTAB 65536
3335#define MAX_STRTAB 65536
3436#define MAX_HEADER 1024
3537#define MAX_PROGRAM_HEADER 1024
3638#define MAX_SECTION 1024
37- #define MAX_ALIASES 128
3839#define MAX_SECTION_HEADER 1024
3940#define MAX_SHSTR 1024
4041#define MAX_INTERP 1024
5657#define SMALL_ARENA_SIZE 65536 /* 64 KiB - for small allocations */
5758#define LARGE_ARENA_SIZE 524288 /* 512 KiB - for instruction arena */
5859#define DEFAULT_FUNCS_SIZE 64
59- #define DEFAULT_INCLUSIONS_SIZE 16
60+ #define DEFAULT_SRC_FILE_COUNT 8
6061
6162/* Arena compaction bitmask flags for selective memory reclamation */
6263#define COMPACT_ARENA_BLOCK 0x01 /* BLOCK_ARENA - variables/blocks */
@@ -131,6 +132,7 @@ typedef struct {
131132/* lexer tokens */
132133typedef enum {
133134 T_start , /* FIXME: Unused, intended for lexer state machine init */
135+ T_eof , /* end-of-file (EOF) */
134136 T_numeric ,
135137 T_identifier ,
136138 T_comma , /* , */
@@ -179,7 +181,6 @@ typedef enum {
179181 T_question , /* ? */
180182 T_colon , /* : */
181183 T_semicolon , /* ; */
182- T_eof , /* end-of-file (EOF) */
183184 T_ampersand , /* & */
184185 T_return ,
185186 T_if ,
@@ -211,38 +212,36 @@ typedef enum {
211212 T_cppd_endif ,
212213 T_cppd_ifdef ,
213214 T_cppd_ifndef ,
214- T_cppd_pragma
215- } token_t ;
215+ T_cppd_pragma ,
216+ /* C pre-processor specific, these kinds
217+ * will be removed after pre-processing is done.
218+ */
219+ T_newline ,
220+ T_backslash ,
221+ T_whitespace ,
222+ T_tab
223+ } token_kind_t ;
216224
217225/* Source location tracking for better error reporting */
218226typedef struct {
227+ int pos ; /* raw source file position */
228+ int len ; /* length of token */
219229 int line ;
220230 int column ;
221231 char * filename ;
222232} source_location_t ;
223233
224- /* Token structure with metadata for enhanced lexing */
225- typedef struct token_info {
226- token_t type ;
227- char value [MAX_TOKEN_LEN ];
234+ typedef struct token {
235+ token_kind_t kind ;
236+ char * literal ;
228237 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 ;
238+ struct token * next ;
239+ } token_t ;
237240
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 ;
241+ typedef struct token_stream {
242+ token_t * head ;
243+ token_t * tail ;
244+ } token_stream_t ;
246245
247246/* String pool for identifier deduplication */
248247typedef struct {
@@ -387,7 +386,7 @@ struct var {
387386 int in_loop ;
388387 struct var * base ;
389388 int subscript ;
390- struct var * subscripts [64 ];
389+ struct var * subscripts [128 ];
391390 int subscripts_idx ;
392391 rename_t rename ;
393392 ref_block_list_t ref_block_list ; /* blocks which kill variable */
@@ -412,25 +411,13 @@ struct var {
412411 bool ofs_based_on_stack_top ;
413412};
414413
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-
426414typedef struct func func_t ;
427415
428416/* block definition */
429417struct block {
430418 var_list_t locals ;
431419 struct block * parent ;
432420 func_t * func ;
433- macro_t * macro ;
434421 struct block * next ;
435422};
436423
@@ -494,13 +481,6 @@ typedef struct {
494481 type_t * type ;
495482} lvalue_t ;
496483
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-
504484/* constants for enums */
505485typedef struct {
506486 char alias [MAX_VAR_LEN ];
0 commit comments