CFLAGS=-c -g
-OBJS=interp.o lex.yy.o main.o object.o
+OBJS=interp.o lex.yy.o main.o object.o list.o
mojo: $(OBJS)
cc -o mojo $(OBJS) -lfl
object.o: object.h object.c
interp.o: interp.c interp.h
+list.o: list.c
main.o: main.c
clean:
-mojo is a smalltalk without smalltalk.
\ No newline at end of file
+mojo is a smalltalk without smalltalk.
+
+Coding conventions
+==================
+
+All the names beginning with mojo_ are internal.
\ No newline at end of file
--- /dev/null
+#include "list.h"
+#include "zalloc.h"
+
+struct mojo_list* list_init(void)
+{
+ struct mojo_list *l = zalloc(sizeof(struct mojo_list));
+ TAILQ_INIT(&l->mojo_list_head);
+
+ return l;
+}
+
+void list_append(struct Object *list, struct Object *o)
+{
+ if (list == NULL || o == NULL || list->type != T_LIST)
+ return;
+
+ struct list_elem *e = zalloc(sizeof(struct list_elem));
+ e->obj = o;
+
+ TAILQ_INSERT_TAIL(&list->mojo_list_head, e, mojo_lists);
+}
+
+void list_remove(struct Object * list, struct Object *o)
+{
+ struct list_elem *e = TAILQ_LAST(&list->mojo_list_head, mojo_lists);
+ TAILQ_REMOVE(&list->mojo_list_head, e, mojo_lists);
+
+ /* Also free the associated object : */
+ free(e->obj);
+ free(e);
+}
+
+struct Object* list_nth(struct Object *list, int n)
+{
+ if (list == NULL)
+ return NULL;
+
+ struct Object *o = TAILQ_FIRST(&list->mojo_list_head);
+ int i = 0;
+
+ for (i = 0; i < n && o != NULL; i++) {
+ o = TAILQ_NEXT(o);
+ }
+
+ return o;
+}
+
+struct Object* list_last(struct Object *list)
+{
+ struct list_elem *e = TAILQ_LAST(&mojo_list_head, lists);
+ return e->obj;
+}
+
+/*
+ Here begins the public facing list api.
+
+ */
+
+struct Object* create_list(void)
+{
+ /* init base object */
+ struct Object *list_object
+ base_object = new_object();
+ base_object->super = nil_object;
+ base_object->type = T_OBJECT;
+ base_object->name = "Object";
+
+}
--- /dev/null
+#ifndef __LIST_H__
+#define __LIST_H__
+
+#include "object.h"
+#include "queue.h"
+
+struct mojo_list_elem {
+ Object *obj;
+ TAILQ_ENTRY(mojo_list_elem) mojo_lists;
+};
+
+struct mojo_list {
+ TAILQ_HEAD(Lists_head, mojo_list_elem) mojo_list_head;
+};
+
+struct mojo_list* list_init(void);
+void list_append(struct Object *list, struct Object *o);
+void list_remove(struct Object *list, struct Object *o);
+struct Object* list_nth(struct Object *list, int n);
+struct Object* list_last(struct Object *list);
+
+#endif
number_object->name = "Number";
number_object->value.i_value = 0;
add_method(number_object, &Plus_method, "+");
+
+ /* init list object */
+ list_object = new_object();
+ list_object->super = base_object;
+ list_object->type = T_LIST;
+ list_object->name = "List";
+
}
union {
int i_value;
char c_value;
+ struct mojo_list *l_value;
} value;
TAILQ_HEAD(Methods_head, Method) methods_head;
struct Object *nil_object;
struct Object *base_object;
struct Object *number_object;
+struct Object *list_object;
+
#endif
+++ /dev/null
-#include "stack.h"
-#include "zalloc.h"
-
-void stack_push(struct Object *o)
-{
- if (o == NULL)
- return;
-
- struct stack_elem *e = zalloc(sizeof(struct stack_elem));
- e->obj = o;
-
- TAILQ_INSERT_TAIL(&stack_head, e, stacks);
-}
-
-struct Object *stack_pop(void)
-{
- struct stack_elem *e = TAILQ_LAST(&stack_head, stacks);
- TAILQ_REMOVE(&stack_head, e, stacks);
-
- /* Also free the associated object : */
- free(e->obj);
- free(e);
-}
-struct Object* stack_top(void)
-{
- struct stack_elem *e = TAILQ_LAST(&stack_head, stacks);
- return e->obj;
-}
+++ /dev/null
-#ifndef __STACK_H__
-#define __STACK_H__
-
-#include "object.h"
-#include "queue.h"
-
-struct stack_elem {
- Object *obj;
- TAILQ_ENTRY(stack_elem) stacks;
-};
-
-TAILQ_HEAD(Stacks_head, stack_elem) stack_head;
-
-void stack_push(struct Object *o);
-void stack_pop(struct Object *o);
-struct Object* stack_top(void);
-
-#endif