removed old test sources
[mala.git] / engine / program.h
blob28c383dda052e7f86725e0f47952f724ae4fd5b2
1 /*
2 program.h - MaLa program descriptor
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_PROGRAM_H
21 #define MALA_PROGRAM_H
23 #include <stdio.h>
24 #include "mala_types.h"
25 #include "stringlist.h"
27 struct mala_program_struct
29 MalaStringList program; // list containing the actual program
30 MalaStringList pptr; // points to the position *before* the next to be evaluated string
31 MalaEngine engine;
32 int nesting_limit;
33 int nesting_level;
34 int negated:1;
35 mala_state state;
39 extern const char * mala_program_states [];
41 void
42 mala_program_acogc_initize (void* o);
44 acogc_mark_result
45 mala_program_acogc_mark (void* o);
47 MalaProgram
48 mala_program_new_cstr (const char * cmd, MalaEngine engine);
50 void
51 mala_program_run (MalaProgram self, mala_state dest);
53 mala_state
54 mala_program_eval_arg (MalaProgram self, int n, mala_state dest, MalaStringList_ref dst);
56 mala_state
57 mala_program_eval_arg_fmt (MalaProgram self, int n, const char* fmt, void* dst);
59 static inline int
60 mala_program_exists_arg (MalaProgram self, int n)
62 return !!llist_get_nth_stop (&self->pptr->node, n, llist_get_prev (&self->program->node));
65 static inline mala_state
66 mala_program_commonexception (MalaProgram self, mala_common_string idx)
68 mala_stringlist_insert_after (self->pptr,
69 mala_stringlist_node_new (self->engine->common_string[idx],
70 self->engine));
71 return self->state = MALA_EXCEPTION;
74 static inline mala_state
75 mala_program_commonexception_at (MalaProgram self, mala_common_string idx, MalaStringList node)
77 mala_stringlist_insert_before (node,
78 mala_stringlist_node_new (self->engine->common_string[idx],
79 self->engine));
80 return self->state = MALA_EXCEPTION;
83 static inline mala_state
84 mala_program_state_get (MalaProgram self);
86 mala_state
87 mala_program_step (MalaProgram self);
89 static inline void
90 mala_program_action_done (MalaProgram prg, int args);
93 static inline MalaAction
94 mala_program_pptr_action (MalaProgram self);
96 static inline MalaString
97 mala_program_pptr_string (MalaProgram self);
99 static inline const char*
100 mala_program_pptr_cstr (MalaProgram self);
105 * inlines
108 static inline mala_state
109 mala_program_state_get (MalaProgram self)
111 return self ? self->state : MALA_EINVALID;
114 void
115 mala_program_action_done (MalaProgram prg, int args)
117 while (args--)
119 TODO("assert not delete over end of program");
120 mala_stringlist_remove (mala_stringlist_next (prg->pptr));
122 if (prg->nesting_level)
123 mala_stringlist_next (prg->pptr)->string = prg->engine->common_string[MALA_STRING_PASS];
124 else
125 mala_stringlist_remove (mala_stringlist_next (prg->pptr));
128 static inline MalaAction
129 mala_program_pptr_action (MalaProgram self)
131 return mala_stringlist_next (self->pptr)->string->action;
134 static inline MalaString
135 mala_program_pptr_string (MalaProgram self)
137 return mala_stringlist_next (self->pptr)->string;
140 static inline const char*
141 mala_program_pptr_cstr (MalaProgram self)
143 return mala_string_cstr (mala_stringlist_next (self->pptr)->string);
146 #endif /*MALA_PROGRAM_H*/
148 // Local Variables:
149 // mode: C
150 // c-file-style: "gnu"
151 // End:
152 // arch-tag: 0c5dbf2d-8ae2-4e00-874d-d47c8251f709
153 // end_of_file