2 * FML interpreter. Europagate, 1995
5 * Revision 1.1.1.1 1995/02/06 13:48:10 adam
6 * First version of the FML interpreter. It's slow and memory isn't
7 * freed properly. In particular, the FML nodes aren't released yet.
17 struct fml_sym_info info;
26 struct fml_sym **array;
29 struct fml_sym_tab *fml_sym_open (void)
31 struct fml_sym_tab *tab;
34 tab = malloc (sizeof (*tab));
39 tab->array = malloc (sizeof(*tab->array) * tab->hash);
45 for (i = 0; i<tab->hash; i++)
50 void fml_sym_close (struct fml_sym_tab **tabp)
52 struct fml_sym *sym, *sym1;
54 for (i = (*tabp)->hash; --i >= 0; )
55 for (sym = (*tabp)->array[i]; sym; sym = sym1)
65 void fml_sym_push (struct fml_sym_tab *tab)
70 void fml_sym_pop (struct fml_sym_tab *tab, void (*ph)(struct fml_sym_info *i))
75 assert (tab->level > 0);
76 for (i = tab->hash; --i >= 0; )
81 if ((*fsp)->level == tab->level)
99 static unsigned fml_sym_hash (const char *s, unsigned hash)
108 static struct fml_sym_info *sym_add (struct fml_sym_tab *tab,
109 const char *s, int level)
113 struct fml_sym **sym_entry;
115 cp = malloc (strlen(s)+1);
120 sym = malloc (sizeof (*sym));
126 sym_entry = tab->array + fml_sym_hash (s, tab->hash);
128 sym->next = *sym_entry;
134 struct fml_sym_info *fml_sym_add (struct fml_sym_tab *tab, const char *s)
136 return sym_add (tab, s, 0);
139 struct fml_sym_info *fml_sym_add_local (struct fml_sym_tab *tab, const char *s)
141 return sym_add (tab, s, tab->level);
144 static struct fml_sym_info *sym_lookup (struct fml_sym_tab *tab,
145 const char *s, int level)
148 struct fml_sym *sym0 = NULL;
149 struct fml_sym **sym_entry;
151 sym_entry = tab->array + fml_sym_hash (s, tab->hash);
152 for (sym = *sym_entry; sym; sym = sym->next)
153 if (!strcmp (sym->name, s))
154 if (!sym0 || sym->level > sym0->level)
158 assert (sym0->level <= tab->level);
159 if (level && sym0->level != level)
167 struct fml_sym_info *fml_sym_lookup (struct fml_sym_tab *tab, const char *s)
169 return sym_lookup (tab, s, 0);
172 struct fml_sym_info *fml_sym_lookup_local (struct fml_sym_tab *tab,
175 return sym_lookup (tab, s, tab->level);