reformated common-strings macro
[mala.git] / engine / action.c
blobd07edbb1e4736d7fe26b37f5910465cd7bcc2047
1 /*
2 action.c - MaLa actions implementation
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.
19 #include <stdio.h>
21 #include "acogc.h"
22 #include "mala_types.h"
23 #include "strings.h"
24 #include "stringlist.h"
25 #include "engine.h"
26 #include "action.h"
27 #include "llist.h"
30 void
31 mala_action_acogc_initize (void* o)
33 MalaAction self = (MalaAction)o;
34 self->name = NULL;
35 llist_init (&self->childs);
36 llist_init (&self->cldnode);
37 llist_init (&self->stknode);
38 self->data = NULL;
39 self->data_alloc_type = ACOGC_UNSET;
42 void
43 mala_action_acogc_finalize (void* o)
45 MalaAction self = (MalaAction)o;
46 llist_unlink (&self->childs);
47 llist_unlink (&self->cldnode);
48 llist_unlink (&self->stknode);
49 if (self->data_alloc_type == ACOGC_ALLOC)
50 acogc_free (&self);
53 acogc_mark_result
54 mala_action_acogc_mark (void* o)
56 MalaAction self = (MalaAction)o;
58 TODO("profile marking order maybe lastmark name instead of program");
60 TODO("iterative marker");
61 LLIST_FOREACH (&self->childs, node)
62 acogc_object_mark (LLIST_TO_STRUCTP (node, mala_action, cldnode));
64 LLIST_FOREACH (&self->stknode, node)
65 acogc_object_mark (LLIST_TO_STRUCTP (node, mala_action, stknode));
67 if (self->data_alloc_type == ACOGC_GC)
68 acogc_object_mark (self->data);
70 acogc_object_lastmark (self->name);
72 return ACOGC_KEEP;
75 MalaAction
76 mala_action_new (MalaString name,
77 MalaParserFunc parser,
78 void * data,
79 acogc_alloc_type data_alloc,
80 MalaEngine engine)
82 MalaAction self = acogc_factory_alloc (&engine->gcfactory_actions);
84 self->name = name;
85 self->parser = parser;
86 self->data = data;
87 self->data_alloc_type = data_alloc;
88 llist_init (&self->childs);
90 self->parent = NULL;
91 mala_action_attach (self, name);
93 return self;
96 void
97 mala_action_attach (MalaAction self, MalaString name)
99 if (name->action)
101 //push
102 llist_insert_after (&self->stknode, &name->action->stknode);
104 else
106 // first action
107 assert (name->user_alloc_type == ACOGC_UNSET);
108 name->user_alloc_type = ACOGC_GC;
110 name->action = self;
113 MalaAction
114 mala_action_new_actioninit (MalaActionInit init, MalaEngine engine)
116 ACOGC_STACK_ENTER (&engine->gcroot);
117 ACOGC_STACK_PTR (MalaString, name);
118 ACOGC_STACK_PTR (MalaAction, self);
120 name.ptr = mala_string_new_cstr (init->name, engine->words);
122 self.ptr = mala_action_new (name.ptr, init->parser, NULL, ACOGC_UNSET, engine);
124 switch (init->type)
126 case MALA_DATA_STRINGLIST:
127 self.ptr->list = mala_stringlist_new (engine);
128 self.ptr->data_alloc_type = ACOGC_GC;
129 mala_stringlist_append_literal_cstrs (self.ptr->list, -1, init->data, engine);
130 break;
131 case MALA_DATA_STRINGPOINTER:
132 self.ptr->string = mala_string_new_literal_cstr (init->data, engine->words);
133 self.ptr->data_alloc_type = ACOGC_GC;
134 break;
135 //case MALA_DATA_UNUSED:
136 default:
137 self.ptr->data = init->data;
138 self.ptr->data_alloc_type = init->data ? ACOGC_STATIC : ACOGC_UNSET;
139 break;
142 if (init->parent)
144 MalaString str = mala_stringbucket_find (engine->words, init->parent);
145 if (str)
146 mala_action_attach_child (str->action, self.ptr);
147 else
148 mala_action_attach_child (engine->common_string[MALA_STRING_WORLD]->action, self.ptr);
150 ACOGC_STACK_LEAVE;
151 return self.ptr;
155 // Local Variables:
156 // mode: C
157 // c-file-style: "gnu"
158 // End:
159 // arch-tag: 5b3b4c3c-09f4-4f2e-a737-1ea6c5df59e9
160 // end_of_file