use --WORLD as root of all actions (GC just deletes --WORLD)
[mala.git] / engine / engine.h
blobbbaceae4f75475434fe05fe471c750f22b5757c3
1 /*
2 engine.h - MaLa core engine
4 Copyright (C) 2004, Christian Thaeter <chth@gmx.net>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License version 2 as
8 published by the Free Software Foundation.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, contact me.
20 #ifndef MALA_ENGINE_H
21 #define MALA_ENGINE_H
23 #include "mala_types.h"
24 #include "stringbucket.h"
25 #include "stringlist.h"
26 //#include "action.h"
29 Build a table of common strings, this strings are
30 a) get never garbage collected (except at end)
31 b) are fast accessible with their symbolic index
33 TODO: MALA_EXPAND (WORLD, "--WORLD"),
35 #define MALA_COMMON_STRINGS \
36 { \
37 MALA_EXPAND (EMPTY, ""), \
38 MALA_EXPAND (FALSE, "--FALSE"), \
39 MALA_EXPAND (TRUE, "--TRUE"), \
40 MALA_EXPAND (ZERO, "0"), \
41 MALA_EXPAND (PASS, "--PASS"), \
42 MALA_EXPAND (EXCLAMATIONMARK, "!"), \
43 MALA_EXPAND (ASSIGN, "="), \
44 MALA_EXPAND (BACKQUOTE, "`"), \
45 MALA_EXPAND (NOT, "--NOT"), \
46 MALA_EXPAND (LITERAL, "--LITERAL"), \
47 MALA_EXPAND (ENVSUBST, "--ENVSUBST"), \
48 MALA_EXPAND (SETENV, "--SETENV"), \
49 MALA_EXPAND (SECTION, "--SECTION"), \
50 MALA_EXPAND (HERE, "--HERE"), \
51 MALA_EXPAND (BEGIN, "--BEGIN"), \
52 MALA_EXPAND (END, "--END"), \
53 MALA_EXPAND (DEL, "--DEL"), \
54 MALA_EXPAND (DEFAULT_PARSER, "--DEFAULT-PARSER"), \
55 MALA_EXPAND (FLAG_LITERAL_EXPANSION, "--FLAG-LITERAL-EXPANSION"), \
56 MALA_EXPAND (FLAG_EXCLAM_EXPANSION, "--FLAG-EXCLAM-EXPANSION"), \
57 MALA_EXPAND (FLAG_NO_EXPANSION, "--FLAG-NO-EXPANSION"), \
58 MALA_EXPAND (FLAG_NUMSPLIT_EXPANSION, "--FLAG-NUMSPLIT-EXPANSION"), \
59 MALA_EXPAND (FLAG_CHAR_EXPANSION, "--FLAG-CHAR-EXPANSION"), \
60 MALA_EXPAND (FLAG_ASSIGN_EXPANSION, "--FLAG-ASSIGN-EXPANSION"), \
61 MALA_EXPAND (FLAG_SETENV_EXPANSION, "--FLAG-SETENV-EXPANSION"), \
62 MALA_EXPAND (FLAG_ENVVAR_EXPANSION, "--FLAG-ENVVAR-EXPANSION"), \
63 MALA_EXPAND (FLAG_UNDERSCORE_EXPANSION, "--FLAG-UNDERSCORE-EXPANSION"), \
64 MALA_EXPAND (FLAG_BRACKET_EXPANSION, "--FLAG-BRACKET-EXPANSION"), \
65 MALA_EXPAND (FLAG_ASSIGN_CONTRACTION, "--FLAG-ASSIGN-CONTRACTION"), \
66 MALA_EXPAND (ERROR_MISSING_ARGUMENT, "--ERROR-MISSING-ARGUMENT"), \
67 MALA_EXPAND (ERROR_MISSING_END, "--ERROR-MISSING-END"), \
68 MALA_EXPAND (ERROR_END_WITHOUT_BEGIN, "--ERROR-END-WITHOUT-BEGIN"), \
69 MALA_EXPAND (ERROR_BLOCK_NOT_ALLOWED, "--ERROR-BLOCK-NOT-ALLOWED"), \
70 MALA_EXPAND (ERROR_PARAMETER_SYNTAX, "--ERROR-PARAMETER-SYNTAX"), \
71 MALA_EXPAND (ERROR_WRONG_TYPE, "--ERROR-WRONG-TYPE"), \
72 MALA_EXPAND (MAX, NULL) \
75 #define MALA_EXPAND(E,s) MALA_STRING_##E
76 enum mala_common_strings_enum MALA_COMMON_STRINGS;
77 #undef MALA_EXPAND
79 const char * mala_engine_states [MALA_STATE_TABLE_SIZEOF+1];
81 //#ifdef MALA_PRIVATE
82 struct mala_engine_struct
85 * every tokenized word is collected in 'words'
86 * actions can be bound to these words through the strings user variable
88 mala_stringbucket words;
89 mala_stringlist program;
90 mala_stringlist arguments;
92 MalaString common_string[MALA_STRING_MAX];
94 /*TODO static ringbuffer char ringbuffer *[10] */
96 //const char * argv_0;
98 int negated:1;
100 mala_trace engine_trace;
101 mala_trace* gc_trace;
103 /* --BEGIN ... --END blocks are translated to --BLOCK-xxxxxxxx macros,
104 where xxxxxxxx is a monotonic incrementing counter, its value is stored here */
105 unsigned blockcnt;
107 int state;
109 //#endif
112 \f/**/
117 * Mala engine
119 MalaEngine
120 mala_engine_new ();
122 #if 0
123 MalaEngine
124 mala_engine_new_main (int (*initfunc) (MalaEngine),
125 int argc, char ** argv,
126 mala_actioninit * actions_init);
127 #endif
129 void
130 mala_engine_free (MalaEngine self);
133 mala_engine_actions_register (MalaEngine, MalaActionInit);
136 mala_engine_exception (MalaEngine self,
137 MalaStringListNode_ref pptr,
138 MalaStringListNode here,
139 MalaString message);
142 mala_engine_ppexpand_define (MalaEngine self, const char * name, int argc, char **argv);
145 mala_engine_pushback_word (MalaEngine self, const char * word);
147 MalaStringList
148 mala_engine_getprogram (MalaEngine self);
150 mala_state
151 mala_engine_state_get (MalaEngine self);
153 const char *
154 mala_engine_state_str (MalaEngine self);
156 void
157 mala_engine_clearstate (MalaEngine self);
160 mala_engine_negated (MalaEngine self);
162 void
163 mala_engine_clear_negated (MalaEngine self);
165 void
166 mala_engine_dumpprogram (MalaEngine self, FILE* stream, const char * prefix, const char * suffix);
168 void
169 mala_engine_dumpargs (MalaEngine self, FILE* stream, const char * prefix, const char * suffix);
171 MalaEngine
172 mala_engine_run (MalaEngine self);
174 MalaEngine
175 mala_engine_step (MalaEngine);
178 mala_engine_eval (MalaEngine self, MalaStringListNode_ref pptr);
180 void
181 mala_engine_command_done (MalaEngine eng, MalaStringListNode_ref pptr, int args);
185 //int
186 //mala_engine_expansions (MalaEngine self, MalaStringListNode_ref pptr);
190 mala_engine_string_istrue (MalaEngine self, MalaString str);
193 mala_engine_check_expansionflag (MalaEngine self, int flag);
197 mala_engine_ppexpand (MalaEngine self, MalaStringList list, MalaStringListNode_ref pptr);
200 mala_engine_literal_expansion (MalaEngine self,
201 MalaStringList list,
202 MalaStringListNode_ref pptr);
205 mala_engine_backquote_expansion (MalaEngine self,
206 MalaStringList list,
207 MalaStringListNode_ref pptr);
210 mala_engine_numsplit_expansion (MalaEngine self,
211 MalaStringList list,
212 MalaStringListNode_ref pptr);
215 mala_engine_exclam_expansion (MalaEngine self,
216 MalaStringList list,
217 MalaStringListNode_ref pptr);
220 mala_engine_no_expansion (MalaEngine self,
221 MalaStringList list,
222 MalaStringListNode_ref pptr);
225 mala_engine_assign_expansion (MalaEngine self,
226 MalaStringList list,
227 MalaStringListNode_ref pptr);
230 mala_engine_envvar_expansion (MalaEngine self,
231 MalaStringList list,
232 MalaStringListNode_ref pptr);
235 mala_engine_char_expansion (MalaEngine self,
236 MalaStringList list,
237 MalaStringListNode_ref pptr);
240 mala_engine_underscore_expansion (MalaEngine self,
241 MalaStringList list,
242 MalaStringListNode_ref pptr);
244 int mala_engine_setenv_expansion (MalaEngine self,
245 MalaStringList list,
246 MalaStringListNode_ref pptr);
248 int mala_engine_bracket_expansion (MalaEngine self,
249 MalaStringList list,
250 MalaStringListNode_ref pptr);
252 int mala_engine_assign_contraction (MalaEngine self,
253 MalaStringList list,
254 MalaStringListNode_ref pptr);
257 mala_engine_add_action_cstr (MalaEngine self, const char* cname, void* data,
258 MalaParserFunc parser, MalaDataFactory factory,
259 MalaAction parent);
262 mala_engine_add_action (MalaEngine self, MalaString name, void* data,
263 MalaParserFunc parser, MalaDataFactory factory,
264 MalaAction parent);
267 MalaStringListNode
268 mala_engine_arg_eval (MalaEngine self,
269 MalaStringListNode_ref pptr,
270 unsigned nth,
271 int final_state);
275 mala_engine_arg_eval_fmt (MalaEngine self,
276 MalaStringListNode_ref pptr,
277 unsigned nth,
278 const char* fmt,
279 void * dest,
280 MalaPredicate pred,
281 void * constraint);
283 MalaString
284 mala_engine_arg_eval_string (MalaEngine self,
285 MalaStringListNode_ref pptr,
286 unsigned nth,
287 MalaPredicate pred,
288 void * constraint);
291 #if 0 /*TODO*/
293 MalaEngine
294 mala_engine_new_initfunc (int (*initfunc) (MalaEngine));
298 void
299 mala_engine_pushfront_program (MalaEngine self, int args, char ** argv);
303 mala_engine_erase_action (MalaEngine, const t_uchar * key);
306 mala_engine_eval (MalaEngine self, LList pptr);
309 mala_engine_deepeval (MalaEngine self, LList pptr);
313 mala_engine_exception (MalaEngine, LList begin, LList end, const char *);
315 MalaAction
316 mala_engine_action_new (MalaEngine, t_uchar** name, void** data,
317 MalaParserFunc parser, MalaDataDestructor destructor);
320 MalaAction
321 mala_engine_getaction (MalaEngine, const t_uchar * name);
323 MalaAction
324 mala_engine_getprevaction (MalaEngine, const t_uchar * name);
326 #endif /*TODO*/
332 #endif /*MALA_ENGINE_H*/
334 // Local Variables:
335 // mode: C
336 // c-file-style: "gnu"
337 // End:
338 // arch-tag: 47d718f6-e397-400c-93a6-bc71f475c0c7
339 // end_of_file