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.
23 #include "mala_types.h"
24 #include "stringbucket.h"
25 #include "stringlist.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 note that "--WORLD" must be the first one
36 #define MALA_COMMON_STRINGS \
38 MALA_COMMON_STRING (WORLD, "--WORLD"), \
39 MALA_COMMON_STRING (COMMANDLINE, "--COMMANDLINE"), \
40 MALA_COMMON_STRING (PROGRAM, "--PROGRAM"), \
41 MALA_COMMON_STRING (ARGUMENTS, "--ARGUMENTS"), \
42 MALA_COMMON_STRING (FALSE, "--FALSE"), \
43 MALA_COMMON_STRING (TRUE, "--TRUE"), \
44 MALA_COMMON_STRING (EMPTY, ""), \
45 MALA_COMMON_STRING (ZERO, "0"), \
46 MALA_COMMON_STRING (PASS, "--PASS"), \
47 MALA_COMMON_STRING (EXCLAMATIONMARK, "!"), \
48 MALA_COMMON_STRING (ASSIGN, "="), \
49 MALA_COMMON_STRING (BACKQUOTE, "`"), \
50 MALA_COMMON_STRING (NOT, "--NOT"), \
51 MALA_COMMON_STRING (LITERAL, "--LITERAL"), \
52 MALA_COMMON_STRING (ENVSUBST, "--ENVSUBST"), \
53 MALA_COMMON_STRING (SETENV, "--SETENV"), \
54 MALA_COMMON_STRING (SECTION, "--SECTION"), \
55 MALA_COMMON_STRING (BEFORE_HERE, "--BEFORE-HERE"), \
56 MALA_COMMON_STRING (BEGIN, "--BEGIN"), \
57 MALA_COMMON_STRING (END, "--END"), \
58 MALA_COMMON_STRING (DEL, "--DEL"), \
59 MALA_COMMON_STRING (DEFAULT_PARSER, "--DEFAULT-PARSER"), \
60 MALA_COMMON_STRING (PP_COMMANDLINE, "--PP-COMMANDLINE"), \
61 MALA_COMMON_STRING (PP_CONFIGFILE, "--PP-CONFIGFILE"), \
62 MALA_COMMON_STRING (PP_INTERACTIVE, "--PP-INTERACTIVE"), \
63 MALA_COMMON_STRING (FLAG_LITERAL_EXPANSION, "--FLAG-LITERAL-EXPANSION"), \
64 MALA_COMMON_STRING (FLAG_EXCLAM_EXPANSION, "--FLAG-EXCLAM-EXPANSION"), \
65 MALA_COMMON_STRING (FLAG_NO_EXPANSION, "--FLAG-NO-EXPANSION"), \
66 MALA_COMMON_STRING (FLAG_NUMSPLIT_EXPANSION, "--FLAG-NUMSPLIT-EXPANSION"), \
67 MALA_COMMON_STRING (FLAG_CHAR_EXPANSION, "--FLAG-CHAR-EXPANSION"), \
68 MALA_COMMON_STRING (FLAG_ASSIGN_EXPANSION, "--FLAG-ASSIGN-EXPANSION"), \
69 MALA_COMMON_STRING (FLAG_SETENV_EXPANSION, "--FLAG-SETENV-EXPANSION"), \
70 MALA_COMMON_STRING (FLAG_ENVVAR_EXPANSION, "--FLAG-ENVVAR-EXPANSION"), \
71 MALA_COMMON_STRING (FLAG_UNDERSCORE_EXPANSION, "--FLAG-UNDERSCORE-EXPANSION"), \
72 MALA_COMMON_STRING (FLAG_BRACKET_EXPANSION, "--FLAG-BRACKET-EXPANSION"), \
73 MALA_COMMON_STRING (FLAG_ASSIGN_CONTRACTION, "--FLAG-ASSIGN-CONTRACTION"), \
74 MALA_COMMON_STRING (ERROR, "--ERROR"), \
75 MALA_COMMON_STRING (ERROR_MISSING_ARGUMENT, "--ERROR-MISSING-ARGUMENT"), \
76 MALA_COMMON_STRING (ERROR_MISSING_END, "--ERROR-MISSING-END"), \
77 MALA_COMMON_STRING (ERROR_END_WITHOUT_BEGIN, "--ERROR-END-WITHOUT-BEGIN"), \
78 MALA_COMMON_STRING (ERROR_MACRO_SYNTAX, "--ERROR-MACRO-SYNTAX"), \
79 MALA_COMMON_STRING (ERROR_NESTING_LIMIT_EXCEED, "--ERROR-NESTING-LIMIT-EXCEED"), \
80 MALA_COMMON_STRING (ERROR_ACTION_NOT_DEFINED, "--ERROR-ACTION-NOT-DEFINED"), \
81 MALA_COMMON_STRING (MAX, "") \
85 #define MALA_COMMON_STRING(E,s) MALA_STRING_##E
86 enum mala_common_strings_enum MALA_COMMON_STRINGS
;
87 #undef MALA_COMMON_STRING
89 typedef enum mala_common_strings_enum mala_common_string
;
91 const char * mala_engine_states
[MALA_STATE_TABLE_SIZEOF
+1];
94 struct mala_engine_struct
97 * every tokenized word is collected in 'words'
98 * actions can be bound to these words through the strings user variable
102 acogc_factory gcfactory_buckets
;
103 acogc_factory gcfactory_strings
;
104 acogc_factory gcfactory_stringbucketnodes
;
105 acogc_factory gcfactory_stringlists
;
106 acogc_factory gcfactory_actions
;
107 acogc_factory gcfactory_programs
;
109 MalaStringBucket words
;
113 mala_trace engine_trace
;
115 /* --BEGIN ... --END blocks are translated to --BLOCK-xxxxxxxx macros,
116 where xxxxxxxx is a monotonic incrementing counter, its value is stored here */
121 MalaString common_string
[MALA_STRING_MAX
];
129 mala_engine_init (MalaEngine self
);
136 mala_engine_new_main (int (*initfunc
) (MalaEngine
),
137 int argc
, char ** argv
,
138 mala_actioninit
* actions_init
);
142 mala_engine_erase (MalaEngine self
);
145 mala_engine_free (MalaEngine self
);
148 mala_engine_actions_register (MalaEngine
, MalaActionInit
);
152 mala_engine_action_new_cstr (MalaEngine self
,
154 MalaParserFunc parser
,
156 acogc_alloc_type data_alloc
,
161 mala_engine_run_cstr (MalaEngine self
,
163 MalaStringList_ref result
);
166 mala_engine_state_get (MalaEngine self
);
169 mala_engine_state_str (MalaEngine self
);
172 mala_engine_clearstate (MalaEngine self
);
175 mala_engine_tmpname (MalaEngine self
, const char* templ
);
177 static inline MalaAction
178 mala_engine_action_get_cstr (MalaEngine engine
, const char * cname
)
180 MalaString s
= mala_stringbucket_find (engine
->words
, cname
);
181 return s
? s
->action
: NULL
;
184 #endif /*MALA_ENGINE_H*/
188 // c-file-style: "gnu"
190 // arch-tag: 47d718f6-e397-400c-93a6-bc71f475c0c7