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 (ERROR_NOT_A_PREDICATE, "--ERROR-NOT-A-PREDICATE"), \
82 MALA_COMMON_STRING (ERROR_WRONG_TYPE, "--ERROR-WRONG-TYPE"), \
83 MALA_COMMON_STRING (ERROR_OUT_OF_RANGE, "--ERROR-OUT-OF-RANGE"), \
84 MALA_COMMON_STRING (MAX, "") \
88 #define MALA_COMMON_STRING(E,s) MALA_STRING_##E
89 enum mala_common_strings_enum MALA_COMMON_STRINGS
;
90 #undef MALA_COMMON_STRING
92 typedef enum mala_common_strings_enum mala_common_string
;
94 const char * mala_engine_states
[MALA_STATE_TABLE_SIZEOF
+1];
97 struct mala_engine_struct
100 * every tokenized word is collected in 'words'
101 * actions can be bound to these words through the strings user variable
105 acogc_factory gcfactory_buckets
;
106 acogc_factory gcfactory_strings
;
107 acogc_factory gcfactory_stringbucketnodes
;
108 acogc_factory gcfactory_stringlists
;
109 acogc_factory gcfactory_actions
;
110 acogc_factory gcfactory_programs
;
112 MalaStringBucket words
;
114 mala_trace engine_trace
; // TODO
116 /* --BEGIN ... --END blocks are translated to --BLOCK-xxxxxxxx macros,
117 where xxxxxxxx is a monotonic incrementing counter, its value is stored here */
122 MalaString common_string
[MALA_STRING_MAX
];
130 mala_engine_init (MalaEngine self
);
137 mala_engine_new_main (int (*initfunc
) (MalaEngine
),
138 int argc
, char ** argv
,
139 mala_actioninit
* actions_init
);
143 mala_engine_erase (MalaEngine self
);
146 mala_engine_free (MalaEngine self
);
149 mala_engine_actions_register (MalaEngine
, MalaActionInit
);
153 mala_engine_action_new_cstr (MalaEngine self
,
155 MalaParserFunc parser
,
157 acogc_alloc_type data_alloc
,
162 mala_engine_run_cstr (MalaEngine self
,
164 MalaStringList_ref result
);
167 mala_engine_state_get (MalaEngine self
);
170 mala_engine_state_str (MalaEngine self
);
173 mala_engine_clearstate (MalaEngine self
);
176 mala_engine_tmpname (MalaEngine self
, const char* templ
);
178 static inline MalaAction
179 mala_engine_action_get_cstr (MalaEngine engine
, const char * cname
)
181 MalaString s
= mala_stringbucket_find (engine
->words
, cname
);
182 return s
? s
->action
: NULL
;
185 #endif /*MALA_ENGINE_H*/
189 // c-file-style: "gnu"
191 // arch-tag: 47d718f6-e397-400c-93a6-bc71f475c0c7