Atualizado docs. Implementado ops logicos.
[myPerl.git] / symtab.c
blob097837d0973ece0a965199fae6ccd06b51583f9d
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <strings.h>
6 #include "symtab.h"
7 #include "heap.h"
8 #include "code.h"
10 #define MAX_DEPTH 1024 /* maximum value of scope */
12 symtab_t *symtab[MAX_DEPTH];
14 void
15 initsym(void)
17 memset(symtab, 0, MAX_DEPTH*sizeof(symtab_t));
20 symtab_t *
21 putsym(char *name, int scope, int addr, int dim, int size)
23 symtab_t *node = calloc(1, sizeof(symtab_t));
25 node->name = name; /* the scanner strduped it. */
26 node->offset = data_location(size);
27 node->scope = scope;
28 node->addr = addr;
29 node->dim = dim;
30 node->size = size;
31 node->next = symtab[scope];
32 symtab[scope] = node; /* lazy user proof :-) */
34 return node;
37 symtab_t *
38 getsym(char *name, int scope)
40 symtab_t *p;
41 int i;
43 for (i = scope; i >= 0; --i)
44 for (p = symtab[i]; p; p = p->next)
45 if (strcmp(p->name, name) == 0)
46 return p;
48 return NULL;
51 static void
52 scoperem_aux(symtab_t *node)
54 if (! node)
55 return;
57 scoperem_aux(node->next);
58 free(node->name);
59 free(node);
62 void
63 scoperem(int scope)
65 scoperem_aux(symtab[scope]);
66 symtab[scope] = NULL;