feat(frontend): 重构词法分析器
- 添加 .gitignore 文件,忽略编译器生成的二进制文件 - 重构 lexer.c 文件,改进了关键字处理和字符串处理 - 更新前端的前端、解析器和 AST 相关文件,以适应新的词法分析器 - 优化了 token 相关的定义和函数,引入了新的 token 类型
This commit is contained in:
@@ -1,27 +1,39 @@
|
||||
#ifndef __SMCC_HASHTABLE_H__
|
||||
#define __SMCC_HASHTABLE_H__
|
||||
|
||||
#include <lib/rt/rt.h>
|
||||
#include <lib/rt/rt_alloc.h>
|
||||
#include "vector.h"
|
||||
|
||||
typedef struct hash_node {
|
||||
const char* str;
|
||||
int len;
|
||||
u32_t hash;
|
||||
struct hash_node* next;
|
||||
} hash_node_t;
|
||||
// 哈希表条目状态标记
|
||||
typedef enum hash_table_entry_state {
|
||||
ENTRY_EMPTY,
|
||||
ENTRY_ACTIVE,
|
||||
ENTRY_TOMBSTONE
|
||||
} ht_entry_state_t;
|
||||
|
||||
// 哈希表条目结构(不管理key/value内存)
|
||||
typedef struct hash_entry {
|
||||
const void* key; // 由调用者管理
|
||||
void* value; // 由调用者管理
|
||||
u32_t hash; // 预计算哈希值
|
||||
ht_entry_state_t state; // 条目状态
|
||||
} hash_entry_t;
|
||||
|
||||
// 哈希表主体结构
|
||||
typedef struct hash_table {
|
||||
hash_node_t** buckets;
|
||||
int size;
|
||||
int cap;
|
||||
int max_cap;
|
||||
vector_header(entries, hash_entry_t); // 使用vector管理条目
|
||||
u32_t count; // 有效条目数(不含墓碑)
|
||||
u32_t tombstone_count; // 墓碑数量
|
||||
u32_t (*hash_func)(const void* key);
|
||||
int(*key_cmp)(const void* key1, const void* key2);
|
||||
} hash_table_t;
|
||||
|
||||
hash_table_t* new_hash_table(int init_size, int max_cap);
|
||||
void hash_table_init(hash_table_t* ht, int init_size, int max_cap);
|
||||
void hash_table_destroy(hash_table_t* ht);
|
||||
// WARN you need set hash_func and key_cmp before use
|
||||
void hashtable_init(hash_table_t* ht) ;
|
||||
|
||||
void hash_table_insert(hash_table_t* ht, const char* str, int len);
|
||||
hash_node_t* hash_table_find(hash_table_t* ht, const char* str, int len);
|
||||
void* hashtable_set(hash_table_t* ht, const void* key, void* value);
|
||||
void* hashtable_get(hash_table_t* ht, const void* key);
|
||||
void* hashtable_get(hash_table_t* ht, const void* key);
|
||||
void hashtable_destory(hash_table_t* ht);
|
||||
|
||||
#endif // __SMCC_HASHTABLE_H__
|
||||
|
||||
Reference in New Issue
Block a user