add reference parameter to eval_arg
[mala.git] / engine / program.h
blobb038d5bb18afb2a89693510cb8c29346037c2e9b
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 negated:1;
33 mala_state state;
37 extern const char * mala_program_states [];
39 void
40 mala_program_acogc_initize (void* o);
42 acogc_mark_result
43 mala_program_acogc_mark (void* o);
45 MalaProgram
46 mala_program_new_cstr (const char * cmd, MalaEngine engine);
48 MalaProgram
49 mala_program_copy (MalaProgram source);
51 void
52 mala_program_run (MalaProgram self, mala_state dest);
54 mala_state
55 mala_program_eval_arg (MalaProgram self, int n, mala_state dest, MalaStringList_ref dst);
57 static inline int
58 mala_program_exists_arg (MalaProgram self, int n)
60 return !!llist_get_nth_stop (&self->pptr->node, n, llist_get_prev (&self->program->node));
63 static inline mala_state
64 mala_program_commonexception (MalaProgram self, mala_common_string idx)
66 mala_stringlist_insert_after (self->pptr,
67 mala_stringlist_node_new (self->engine->common_string[idx],
68 self->engine));
69 return self->state = MALA_EXCEPTION;
72 static inline mala_state
73 mala_program_state_get (MalaProgram self);
75 mala_state
76 mala_program_step (MalaProgram self);
78 static inline void
79 mala_program_action_done (MalaProgram prg, int args);
81 static inline MalaAction
82 mala_program_pptr_action (MalaProgram self);
87 * inlines
90 static inline mala_state
91 mala_program_state_get (MalaProgram self)
93 return self ? self->state : MALA_EINVALID;
96 void
97 mala_program_action_done (MalaProgram prg, int args)
101 TODO("assert not delete over end of program");
102 mala_stringlist_remove (mala_stringlist_next (prg->pptr));
104 while (args--);
108 static inline MalaAction
109 mala_program_pptr_action (MalaProgram self)
111 return mala_stringlist_next (self->pptr)->string->action;
114 #endif /*MALA_PROGRAM_H*/
116 // Local Variables:
117 // mode: C
118 // c-file-style: "gnu"
119 // End:
120 // arch-tag: 0c5dbf2d-8ae2-4e00-874d-d47c8251f709
121 // end_of_file