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 (NO, "--NO"), \
52 MALA_COMMON_STRING (LITERAL, "--LITERAL"), \
53 MALA_COMMON_STRING (ENVSUBST, "--ENVSUBST"), \
54 MALA_COMMON_STRING (SETENV, "--SETENV"), \
55 MALA_COMMON_STRING (SECTION, "--SECTION"), \
56 MALA_COMMON_STRING (BEFORE_HERE, "--BEFORE-HERE"), \
57 MALA_COMMON_STRING (BEGIN, "--BEGIN"), \
58 MALA_COMMON_STRING (END, "--END"), \
59 MALA_COMMON_STRING (DEL, "--DEL"), \
60 MALA_COMMON_STRING (EVAL, "--EVAL"), \
61 MALA_COMMON_STRING (STOP, "--STOP"), \
62 MALA_COMMON_STRING (TRY, "--TRY"), \
63 MALA_COMMON_STRING (ERROR_MISSING_ARGUMENT, "--ERROR-MISSING-ARGUMENT"), \
64 MALA_COMMON_STRING (ERROR_MISSING_END, "--ERROR-MISSING-END"), \
65 MALA_COMMON_STRING (ERROR_END_WITHOUT_BEGIN, "--ERROR-END-WITHOUT-BEGIN"), \
66 MALA_COMMON_STRING (ERROR_MACRO_SYNTAX, "--ERROR-MACRO-SYNTAX"), \
67 MALA_COMMON_STRING (ERROR_NESTING_LIMIT_EXCEED, "--ERROR-NESTING-LIMIT-EXCEED"), \
68 MALA_COMMON_STRING (ERROR_ACTION_NOT_DEFINED, "--ERROR-ACTION-NOT-DEFINED"), \
69 MALA_COMMON_STRING (ERROR_NOT_A_PREDICATE, "--ERROR-NOT-A-PREDICATE"), \
70 MALA_COMMON_STRING (ERROR_WRONG_TYPE, "--ERROR-WRONG-TYPE"), \
71 MALA_COMMON_STRING (ERROR_OUT_OF_RANGE, "--ERROR-OUT-OF-RANGE"), \
72 MALA_COMMON_STRING (UNHANDLED_ERROR, "--UNHANDLED-ERROR"), \
73 MALA_COMMON_STRING (MAX, "") \
77 #define MALA_COMMON_STRING(E,s) MALA_STRING_##E
78 enum mala_common_strings_enum MALA_COMMON_STRINGS
;
79 #undef MALA_COMMON_STRING
81 typedef enum mala_common_strings_enum mala_common_string
;
83 const char * mala_engine_states
[MALA_STATE_TABLE_SIZEOF
+1];
86 struct mala_engine_struct
89 * every tokenized word is collected in 'words'
90 * actions can be bound to these words through the strings user variable
94 acogc_factory gcfactory_buckets
;
95 acogc_factory gcfactory_strings
;
96 acogc_factory gcfactory_stringbucketnodes
;
97 acogc_factory gcfactory_stringlists
;
98 acogc_factory gcfactory_actions
;
99 acogc_factory gcfactory_programs
;
101 MalaStringBucket words
;
103 mala_trace engine_trace
; // TODO
105 /* --BEGIN ... --END blocks are translated to --BLOCK-xxxxxxxx macros,
106 where xxxxxxxx is a monotonic incrementing counter, its value is stored here */
111 MalaString common_string
[MALA_STRING_MAX
];
119 mala_engine_init (MalaEngine self
);
126 mala_engine_new_main (int (*initfunc
) (MalaEngine
),
127 int argc
, char ** argv
,
128 mala_actioninit
* actions_init
);
132 mala_engine_erase (MalaEngine self
);
135 mala_engine_free (MalaEngine self
);
138 mala_engine_actions_register (MalaEngine
, MalaActionInit
);
142 mala_engine_action_new_cstr (MalaEngine self
,
144 MalaParserFunc parser
,
146 acogc_alloc_type data_alloc
,
151 mala_engine_run_cstr (MalaEngine self
,
153 MalaStringList_ref result
);
156 mala_engine_state_get (MalaEngine self
);
159 mala_engine_state_str (MalaEngine self
);
162 mala_engine_clearstate (MalaEngine self
);
165 mala_engine_tmpname (MalaEngine self
, const char* templ
);
167 static inline MalaAction
168 mala_engine_action_get_cstr (MalaEngine engine
, const char * cname
)
170 MalaString s
= mala_stringbucket_find (engine
->words
, cname
);
171 return s
? s
->action
: NULL
;
174 #endif /*MALA_ENGINE_H*/
178 // c-file-style: "gnu"
180 // arch-tag: 47d718f6-e397-400c-93a6-bc71f475c0c7