unsigned long size;
} string_type;
-typedef void (*stinst_type) (void);
+/* Compiled programs consist of arrays of these. */
+
+typedef union
+{
+ void (*f) (void);
+ struct dict_struct *e;
+ char *s;
+ long l;
+} pcu;
typedef struct dict_struct
{
char *word;
struct dict_struct *next;
- stinst_type *code;
+ pcu *code;
int code_length;
int code_end;
} dict_type;
dict_type *root;
-stinst_type *pc;
+pcu *pc;
static void
die (char *msg)
exec (dict_type *word)
{
pc = word->code;
- while (*pc)
- (*pc) ();
+ while (pc->f)
+ pc->f ();
}
static void
call (void)
{
- stinst_type *oldpc = pc;
- dict_type *e;
- e = (dict_type *) (pc[1]);
+ pcu *oldpc = pc;
+ dict_type *e = pc[1].e;
exec (e);
pc = oldpc + 2;
}
isp++;
icheck_range ();
pc++;
- *isp = (long) (*pc);
+ *isp = pc->l;
pc++;
}
check_range ();
init_string (tos);
pc++;
- cattext (tos, *((char **) pc));
+ cattext (tos, pc->s);
pc++;
}
{
int i;
for (i = 0; i < ptr->code_end - 1; i ++)
- if (ptr->code[i] == push_text
- && ptr->code[i + 1])
+ if (ptr->code[i].f == push_text
+ && ptr->code[i + 1].s)
{
- free ((char *) ptr->code[i + 1] - 1);
- ++ i;
+ free (ptr->code[i + 1].s - 1);
+ ++i;
}
free (ptr->code);
}
}
unsigned int
-add_to_definition (dict_type *entry, stinst_type word)
+add_to_definition (dict_type *entry, pcu word)
{
if (entry->code_end == entry->code_length)
{
add_intrinsic (char *name, void (*func) (void))
{
dict_type *new_d = newentry (xstrdup (name));
- add_to_definition (new_d, func);
- add_to_definition (new_d, 0);
+ pcu p = { func };
+ add_to_definition (new_d, p);
+ p.f = 0;
+ add_to_definition (new_d, p);
}
void
if (word[0] == ':')
{
dict_type *ptr;
+ pcu p;
/* Compile a word and add to dictionary. */
free (word);
case '"':
/* got a string, embed magic push string
function */
- add_to_definition (ptr, push_text);
- add_to_definition (ptr, (stinst_type) (word + 1));
+ p.f = push_text;
+ add_to_definition (ptr, p);
+ p.s = word + 1;
+ add_to_definition (ptr, p);
break;
case '0':
case '1':
case '9':
/* Got a number, embedd the magic push number
function */
- add_to_definition (ptr, push_number);
- add_to_definition (ptr, (stinst_type) atol (word));
+ p.f = push_number;
+ add_to_definition (ptr, p);
+ p.l = atol (word);
+ add_to_definition (ptr, p);
free (word);
break;
default:
- add_to_definition (ptr, call);
- add_to_definition (ptr, (stinst_type) lookup_word (word));
+ p.f = call;
+ add_to_definition (ptr, p);
+ p.e = lookup_word (word);
+ add_to_definition (ptr, p);
free (word);
}
string = nextword (string, &word);
}
- add_to_definition (ptr, 0);
+ p.f = 0;
+ add_to_definition (ptr, p);
free (word);
string = nextword (string, &word);
}