18 res = xmalloc (HASHSIZE * sizeof(struct list));
19 for (i = 0; i < HASHSIZE; i++)
26 get_bucket_number(char* name)
29 unsigned char* p = name;
32 n = n * MAGIC + toupper(*p++);
39 /* if not found, variable with value "" is created */
41 find_var(char* name, struct list* hash)
46 n = get_bucket_number(name);
47 int nocase = isupper(*name);
48 LIST_FOREACH(p, hash + n)
49 if (!(nocase ? strcasecmp : strcmp)(p->name,name))
52 p = xmalloc(sizeof(struct variable));
53 p->name = xstrdup(name);
54 p->varcode = current_varcode++;
55 list_add_last(hash+n, &p->car);
62 list_init(&input_code);
63 var_hash = new_var_hash();
64 const_tab = xmalloc(BUFSIZE);
65 cur_const_s = BUFSIZE;
71 if (cur_const_n >= cur_const_s) {
73 const_tab = xrealloc(const_tab, cur_const_s);
76 const_tab[cur_const_n] = c;
78 return -cur_const_n++;
82 new_instr(struct code c)
84 struct code* p = xmalloc(sizeof(struct code));
86 list_add_last(&input_code, &p->car);
90 do_ass(struct tree* t)
94 var_l = find_var(t->pt.ass.left->pt.leaf.value, var_hash);
96 if (t->st == ST_LEAF) {
97 if (t->pt.leaf.type == L_VAR)
98 var_r = find_var(t->pt.leaf.value, var_hash);
100 var_r = store_const(t->pt.leaf.value);
109 compile(struct tree* t)
115 compile(t->pt.block.head);
116 compile(t->pt.block.tail);
124 die("compile: got to default");
129 print_code(struct tree* t)