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
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
39 extern const char * mala_program_states
[];
42 mala_program_acogc_initize (void* o
);
45 mala_program_acogc_mark (void* o
);
48 mala_program_new_cstr (const char * cmd
, MalaEngine engine
);
51 mala_program_run (MalaProgram self
, mala_state dest
);
54 mala_program_eval_arg (MalaProgram self
, int n
, mala_state dest
, MalaStringList_ref dst
);
57 mala_program_eval_arg_fmt (MalaProgram self
, int n
, const char* fmt
, void* dst
);
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
],
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
],
80 return self
->state
= MALA_EXCEPTION
;
83 static inline mala_state
84 mala_program_state_get (MalaProgram self
);
87 mala_program_step (MalaProgram self
);
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
);
108 static inline mala_state
109 mala_program_state_get (MalaProgram self
)
111 return self
? self
->state
: MALA_EINVALID
;
115 mala_program_action_done (MalaProgram prg
, int 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
];
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*/
150 // c-file-style: "gnu"
152 // arch-tag: 0c5dbf2d-8ae2-4e00-874d-d47c8251f709