refactor: 重构前端代码并添加日志功能
- 重命名和重构了多个文件,包括 lexer、parser 和 AST 相关代码 - 添加了日志功能,使用 LOG_* 宏替代原有的 error 和 warn 函数 - 优化了错误处理和内存分配方式 - 调整了代码结构,提高了模块化和可读性
This commit is contained in:
19
lib/utils/tokbuf/token.c
Normal file
19
lib/utils/tokbuf/token.c
Normal file
@ -0,0 +1,19 @@
|
||||
// #include <lib/rt/rt.h>
|
||||
// #include "token.h"
|
||||
|
||||
// #define ROUND_IDX(idx) ((idx) % tokbuf->cap)
|
||||
// #define POW2(x) (1 << (x))
|
||||
|
||||
// void init_toks(tok_stream_t* tokbuf, int cap,
|
||||
// tok_stream_close_func close, tok_stream_get_func gettok, void* stream)
|
||||
// {
|
||||
// tokbuf->cap_mask = POW2(cap) - 1;
|
||||
// // tokbuf->buf =
|
||||
|
||||
// }
|
||||
// int toks_next( tok_stream_t* toks, tok_t* out);
|
||||
// int toks_peek( tok_stream_t* toks, tok_t* out, int lookahead);
|
||||
// const tok_t* toks_peek_ref(tok_stream_t* toks, int lookahead);
|
||||
// int toks_reset(tok_stream_t* toks);
|
||||
// int toks_seek( tok_stream_t* toks, int pos);
|
||||
// int toks_close(tok_stream_t* toks);
|
68
lib/utils/tokbuf/token.h
Normal file
68
lib/utils/tokbuf/token.h
Normal file
@ -0,0 +1,68 @@
|
||||
#ifndef __SMCC_TOKBUF_H__
|
||||
#define __SMCC_TOKBUF_H__
|
||||
|
||||
#include <lib/rt/rt.h>
|
||||
|
||||
typedef struct loc {
|
||||
const char *fname;
|
||||
int line;
|
||||
int col;
|
||||
short len;
|
||||
} loc_t;
|
||||
|
||||
typedef enum tok_type {
|
||||
TK_BASIC_INVALID, // 错误占位
|
||||
TK_BASIC_KEYWORD, // 关键字
|
||||
TK_BASIC_OPERATOR, // 操作符
|
||||
TK_BASIC_IDENTIFIER, // 标识符
|
||||
TK_BASIC_LITERAL, // 字面量
|
||||
TK_BASIC_PUNCTUATOR, // 标点符号
|
||||
TK_BASIC_EOF // 结束标记
|
||||
} tok_type_t;
|
||||
|
||||
typedef union ctype {
|
||||
u8_t u8;
|
||||
u16_t u16;
|
||||
u32_t u32;
|
||||
u64_t u64;
|
||||
i8_t i8;
|
||||
i16_t i16;
|
||||
i32_t i32;
|
||||
i64_t i64;
|
||||
f32_t f32;
|
||||
f64_t f64;
|
||||
iptr_t iptr;
|
||||
uptr_t uptr;
|
||||
void* ptr;
|
||||
} ctype_t;
|
||||
|
||||
typedef struct tok {
|
||||
tok_type_t type;
|
||||
int sub_type;
|
||||
loc_t loc;
|
||||
ctype_t val;
|
||||
} tok_t;
|
||||
|
||||
// typedef void(*tok_stream_close_func)(void* stream);
|
||||
// typedef void(*tok_stream_get_func)(void* stream, tok_t* token);
|
||||
// typedef struct tok_stream {
|
||||
// int cur;
|
||||
// int end;
|
||||
// int cap_mask;
|
||||
// tok_t* buf;
|
||||
|
||||
// void* stream;
|
||||
// tok_stream_close_func close;
|
||||
// tok_stream_get_func gettok;
|
||||
// } tok_stream_t;
|
||||
|
||||
// void init_toks(tok_stream_t* tokbuf, int cap,
|
||||
// tok_stream_close_func close, tok_stream_get_func gettok, void* stream);
|
||||
// int toks_next( tok_stream_t* toks, tok_t* out);
|
||||
// int toks_peek( tok_stream_t* toks, tok_t* out, int lookahead);
|
||||
// const tok_t* toks_peek_unsafe(tok_stream_t* toks, int lookahead);
|
||||
// int toks_reset(tok_stream_t* toks);
|
||||
// int toks_seek( tok_stream_t* toks, int pos);
|
||||
// int toks_close(tok_stream_t* toks);
|
||||
|
||||
#endif // __SMCC_TOKEN_H__
|
Reference in New Issue
Block a user