17 res = xmalloc (HASHSIZE * sizeof(struct list));
18 for (i = 0; i < HASHSIZE; i++)
25 get_bucket_number(char* name)
28 unsigned char* p = name;
31 n = n * MAGIC + toupper(*p++);
38 /* if not found, variable with value "" is created */
40 find_var(char* name, struct list* hash)
45 n = get_bucket_number(name);
46 int nocase = isupper(*name);
47 LIST_FOREACH(p, hash + n)
48 if (!(nocase ? strcasecmp : strcmp)(p->name,name))
51 p = xmalloc(sizeof(struct variable));
52 p->name = xstrdup(name);
53 p->varcode = current_varcode++;
54 list_add_last(hash+n, &p->car);
62 if (cur_const_n >= cur_const_s) {
64 const_tab = xrealloc(const_tab, cur_const_s);
67 const_tab[cur_const_n] = c;
69 return -cur_const_n++;
73 new_instr(struct code c)
75 struct code* p = xmalloc(sizeof(struct code));
77 list_add_last(&input_code, &p->car);
80 /* return number of variable where lies result
81 * pref_var < 0 => no preference
84 evaluate(struct tree* t, int pref_var)
88 if (t->st == ST_LEAF) {
90 } else if (t->st == ST_OP) {
92 left = evaluate(t->pt.op.left, -1);
93 right = evaluate(t->pt.op.right, -1);
94 switch (t->pt.op.op) {
100 ins.u.cat.res = pref_var;
102 ins.u.cat.res = current_varcode++;;
104 return ins.u.cat.res;
107 die("evaluate: got to default");
110 die("evaluate: I can evaluate only expressions but I got %d",
115 do_ass(struct tree* t)
119 var_l = t->pt.ass.left->pt.leaf.n;
120 var_r = evaluate(t->pt.ass.right, -1);
130 reset_temp_var_count(void)
132 current_varcode = temp_varcode_start;
136 compile(struct tree* t)
142 reset_temp_var_count();
143 compile(t->pt.block.head);
144 compile(t->pt.block.tail);
154 die("compile: got to default");
163 LIST_FOREACH(p, &input_code) {
166 printf("SET %d %d\n", p->u.set.l, p->u.set.r);
169 printf("CAT %d %d %d\n", p->u.cat.l,
170 p->u.cat.r, p->u.cat.res);
173 printf("not implemented, opcode: %d\n",