First version of the FML interpreter. It's slow and memory isn't
[egate.git] / fml / fmlp.h
1 /*
2  * FML interpreter. Europagate, 1995
3  *
4  * $Log: fmlp.h,v $
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.
8  *
9  */
10
11 #include "fml.h"
12
13 #define FML_MAX_TOKEN 2048
14
15 #define FML_ATOM_BUF 12
16
17 struct fml_node {
18     void *p[2];
19     unsigned is_atom : 1;
20 };
21
22 struct fml_atom {
23     struct fml_atom *next;
24     char buf[FML_ATOM_BUF];
25 };
26
27 struct fml_node *fml_tokenize (Fml fml);
28 struct fml_node *fml_node_alloc (Fml fml);
29 struct fml_atom *fml_atom_alloc (Fml fml, char *str);
30 int fml_atom_str (struct fml_atom *a, char *str);
31 void fml_atom_strx (struct fml_atom *a, char *str, int max);
32 int fml_atom_val (struct fml_atom *a);
33 struct fml_node *fml_mk_list (Fml fml, struct fml_node *fn);
34 void fml_node_delete (Fml fml, struct fml_node *fn);
35 struct fml_node *fml_node_copy (Fml fml, struct fml_node *fn);
36
37 struct token {
38     int             kind;
39     int             after_char;
40     int             maxbuf;
41     int             offset;
42     char            *atombuf;
43     char            *tokenbuf;
44
45     int             escape_char;
46
47     struct          fml_node *sub;
48     struct          fml_atom *atom;
49     char            sbuf[FML_ATOM_BUF*4];
50 };
51
52 struct fml_sym_info {
53     int kind;
54     struct fml_node *args;
55     struct fml_node *body;
56     struct fml_node *(*binary)(Fml fml, struct fml_node *l,
57                                struct fml_node *r);
58     struct fml_node *(*prefix)(Fml fml, struct fml_node **lp,
59                                struct token *tp);
60 };
61
62 struct fml_sym_tab *fml_sym_open (void);
63 void fml_sym_close (struct fml_sym_tab **tabp);
64 struct fml_sym_info *fml_sym_add (struct fml_sym_tab *tab, const char *s);
65 struct fml_sym_info *fml_sym_add_local (struct fml_sym_tab *tab,const char *s);
66
67 struct fml_sym_info *fml_sym_lookup (struct fml_sym_tab *tab, const char *s);
68 struct fml_sym_info *fml_sym_lookup_local (struct fml_sym_tab *tab,
69                                            const char *s);
70 void fml_sym_push (struct fml_sym_tab *tab);
71 void fml_sym_pop (struct fml_sym_tab *tab, void(*ph)(struct fml_sym_info *i));
72
73 void fml_pr_list (struct fml_node *p);
74
75 #define FML_FUNC     1
76 #define FML_IF       2
77 #define FML_ELSE     3
78 #define FML_PREFIX   4
79 #define FML_VAR      5
80 #define FML_FOREACH  6
81 #define FML_RETURN   7
82 #define FML_SET      8
83 #define FML_WHILE    9
84 #define FML_CBINARY 10
85 #define FML_CPREFIX 11
86 #define FML_BINARY  12
87 #define FML_BIN     13
88
89