summaryrefslogtreecommitdiff
path: root/symbol.c
blob: a9d1d1f8e67e2aa95fcda4341543d2c42cb99b70 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <u.h>
#include <libc.h>
#include <bio.h>

#include "apl9.h"

Symtab *globalsymtab;

Symbol *
getsym(Symtab *tab, Rune *name)
{
	for(int i = 0; i < tab->nsyms; i++)
		if(runestrcmp(tab->syms[i]->name, name) == 0)
			return tab->syms[i];
	
	tab->nsyms++;
	tab->syms = realloc(tab->syms, sizeof(Symbol *) * tab->nsyms);
	tab->syms[tab->nsyms-1] = malloc(sizeof(Symbol));
	tab->syms[tab->nsyms-1]->name = runestrdup(name);
	tab->syms[tab->nsyms-1]->undefined = 1;
	return tab->syms[tab->nsyms-1];
}

Symtab *
newsymtab(void)
{
	Symtab *tab = malloc(sizeof(Symtab));
	tab->nsyms = 0;
	tab->syms = nil;
	return tab;
}