]> khamidou — GitHub mirrors - mojo.git/commitdiff
defining object system
authorkhamidou <khamidou@gmail.com>
Sun, 20 Dec 2009 18:44:45 +0000 (19:44 +0100)
committerkhamidou <khamidou@gmail.com>
Sun, 20 Dec 2009 18:44:45 +0000 (19:44 +0100)
object.c
object.h

index 605fff643bc4123728cee55e2bca6d3354915992..1b5a3b5d6228e8645fe1f6447ed1891a28eed25d 100644 (file)
--- a/object.c
+++ b/object.c
@@ -14,3 +14,59 @@ struct Method *lookup_method(struct Object *o, char *name)
 
        return NULL;
 }
+
+struct Object *clone_object(struct Object *o)
+{
+       if (o == NULL)
+               return NULL;
+
+       struct Object *new = zalloc(sizeof(struct Object *));
+       new->super = o->super;
+       new->type = o->type;
+       new->name = strndup(o->name, 255); /* FIXME : test the value of strdup */
+
+       struct Method *m;
+       struct Method *new_method;
+       TAILQ_INIT(new->methods_head);
+       TAILQ_FOREACH(m, &o->methods_head, methods) {
+               new_method = clone_method(m);
+               TAILQ_INSERT_TAIL(&new->methods_head, new_method, methods);
+       }
+       
+}
+
+void free_object(struct Object *o)
+{
+       if (o == NULL)
+               return;
+
+       free(o->name);
+
+       struct Method *m;
+       TAILQ_FOREACH(m, &o->methods_head, methods) {
+               free_method(m);
+       }
+}
+
+struct Method *clone_method(struct Method *m)
+{
+       if (m == NULL)
+               return NULL;
+
+       struct Method *new = zalloc(sizeof(struct Method));
+       
+       new->name = strndup(m->name, 255);
+       new->c_method = m->c_method;
+       new->parent = m->parent;
+
+       return new;
+}
+
+void free_method(struct Method *m)
+{
+       if (m == NULL)
+               return;
+       TAILQ_REMOVE(m->parent->methods_head, m, methods); 
+       free(m->name);
+       free(m);
+}
index d5717db73a8e14e938a6b952b8b0cef31a3311ed..3bf1b04165eaa3d0d094f2a2f4c9a4c4685185f8 100644 (file)
--- a/object.h
+++ b/object.h
@@ -21,9 +21,12 @@ enum {
 */
 
 struct Method {
-       struct Object *arg1, *arg2;
+       char *name;
+       struct Object *parent;
+       struct Object * (*c_method)(struct Object *arg1, struct Object *arg2); 
+       
        TAILQ_ENTRY(Method) methods;
-       Object * (*c_method)(arg1, arg2); 
+
 };
 
 struct Object {