소스 검색

Update draft for interning same symbol

pull/2/head
mtardy 4 년 전
부모
커밋
01a1ae3919
2개의 변경된 파일7개의 추가작업 그리고 9개의 파일을 삭제
  1. +2
    -3
      .gitignore
  2. +5
    -6
      draft.c

+ 2
- 3
.gitignore 파일 보기

@ -1,11 +1,10 @@
# vscode settings
.vscode/
# dicho
dicho.c
# ignore generated parser
calc.c
# ignore compiled parser
calc
a.out

+ 5
- 6
draft.c 파일 보기

@ -10,7 +10,6 @@ typedef struct symbol_t {
int value;
} symbol_t;
typedef struct table_t {
symbol_t **array;
int size;
@ -69,13 +68,13 @@ symbol_t *intern(char *ident, bool create)
bsearch_t res = binary_search(table.array, 0, table.size - 1, ident);
printf("pos:%d\n", res.pos);
if (create) {
symbol_t *new_symbol = malloc(sizeof(symbol_t));
new_symbol->ident = strdup(ident);
new_symbol->defined = false;
symbol_t *new_symbol;
if (res.found) {
free(table.array[res.pos]);
table.array[res.pos] = new_symbol;
new_symbol = table.array[res.pos];
} else {
new_symbol = malloc(sizeof(symbol_t));
new_symbol->ident = strdup(ident);
new_symbol->defined = false;
printf("insert:%d\n", insert(&table, new_symbol, res.pos));
}
return new_symbol;

불러오는 중...
취소
저장