bugfix 添加lib的修改
This commit is contained in:
parent
b57f21556a
commit
1cf26c43f3
@ -25,7 +25,7 @@ TOKBUF_DIR = $(UTILS_DIR)/tokbuf
|
||||
SRCS += \
|
||||
$(DS_DIR)/hashtable.c \
|
||||
$(STRPOOL_DIR)/strpool.c \
|
||||
$(SYMTAB_DIR)/symtab.c \
|
||||
# $(SYMTAB_DIR)/symtab.c \
|
||||
# $(TOKBUF_DIR)/tokbuf.c
|
||||
|
||||
# 生成目标文件列表
|
||||
|
@ -11,6 +11,7 @@
|
||||
type *data; \
|
||||
} name \
|
||||
|
||||
// You can't malloc at init function becase some user just need a header
|
||||
#define vector_init(vec) \
|
||||
do { \
|
||||
(vec).size = 0, \
|
||||
|
@ -1,62 +0,0 @@
|
||||
#include "symtab.h"
|
||||
|
||||
static u32_t hash_func(const void* _key) {
|
||||
const symtab_key_t* key = (symtab_key_t*)_key;
|
||||
return rt_strhash(key->strp_name);
|
||||
}
|
||||
|
||||
static int key_cmp(const void* _key1, const void* _key2) {
|
||||
const symtab_key_t* key1 = (symtab_key_t*)_key1;
|
||||
const symtab_key_t* key2 = (symtab_key_t*)_key2;
|
||||
if (rt_strcmp(key1->strp_name, key2->strp_name) == 0) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void init_symtab(symtab_t* symtab) {
|
||||
symtab->cur_scope = NULL;
|
||||
symtab->gid = 1;
|
||||
init_hashtable(&symtab->global_table);
|
||||
symtab->global_table.hash_func = hash_func;
|
||||
symtab->global_table.key_cmp = key_cmp;
|
||||
init_hashtable(&symtab->local_table);
|
||||
symtab->local_table.hash_func = hash_func;
|
||||
symtab->local_table.key_cmp = key_cmp;
|
||||
}
|
||||
|
||||
void symtab_destroy(symtab_t* symtab) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
void symtab_enter_scope(symtab_t* symtab) {
|
||||
scope_t *scope = (scope_t*)salloc_alloc(sizeof(scope_t));
|
||||
scope->parent = symtab->cur_scope;
|
||||
scope->uid = symtab->gid++;
|
||||
init_hashtable(&scope->table);
|
||||
|
||||
scope->table.hash_func = hash_func;
|
||||
scope->table.key_cmp = key_cmp;
|
||||
symtab->cur_scope = scope;
|
||||
}
|
||||
|
||||
void symtab_leave_scope(symtab_t* symtab) {
|
||||
Assert(symtab->cur_scope != NULL);
|
||||
scope_t *parent = symtab->cur_scope->parent;
|
||||
hashtable_destory(&symtab->cur_scope->table);
|
||||
salloc_free(symtab->cur_scope);
|
||||
symtab->cur_scope = parent;
|
||||
}
|
||||
|
||||
void* symtab_get(symtab_t* symtab, symtab_key_t* key) {
|
||||
for (scope_t* scope = symtab->cur_scope; scope != NULL; scope = scope->parent) {
|
||||
void* val = hashtable_get(&scope->table, key);
|
||||
if (val != NULL) {
|
||||
return val;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
void* symtab_add(symtab_t* symtab, symtab_key_t* key, void* val) {
|
||||
return hashtable_set(&symtab->cur_scope->table, key, val);
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
#ifndef __SMCC_SYMTABL_H__
|
||||
#define __SMCC_SYMTABL_H__
|
||||
|
||||
#include <lib/core.h>
|
||||
#include <lib/utils/ds/hashtable.h>
|
||||
#include <lib/utils/strpool/strpool.h>
|
||||
|
||||
// FIXME 架构上可能有更好的方式解决
|
||||
|
||||
typedef struct symtab_key {
|
||||
const char* strp_name;
|
||||
int uid;
|
||||
} symtab_key_t;
|
||||
|
||||
typedef struct scope {
|
||||
int uid;
|
||||
struct scope* parent;
|
||||
hash_table_t table;
|
||||
} scope_t;
|
||||
|
||||
typedef struct symtab {
|
||||
hash_table_t global_table;
|
||||
hash_table_t local_table;
|
||||
scope_t* cur_scope;
|
||||
int gid; // global id for generating unique scope id
|
||||
} symtab_t;
|
||||
|
||||
void init_symtab(symtab_t* symtab);
|
||||
void symtab_destroy(symtab_t* symtab);
|
||||
|
||||
void symtab_enter_scope(symtab_t* symtab);
|
||||
void symtab_leave_scope(symtab_t* symtab);
|
||||
|
||||
void* symtab_get(symtab_t* symtab, symtab_key_t* key);
|
||||
|
||||
// WARNING key and val need you save, especially val
|
||||
void* symtab_add(symtab_t* symtab, symtab_key_t* key, void* val);
|
||||
|
||||
#endif
|
@ -2,7 +2,6 @@
|
||||
#define __SMCC_LIB_UTILS_H__
|
||||
|
||||
#include "strpool/strpool.h"
|
||||
#include "symtab/symtab.h"
|
||||
#include "tokbuf/tokbuf.h"
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user