]> khamidou — GitHub mirrors - mojo.git/commitdiff
fixed a slew of condition bugs
authorkarim hamidou <khamidou@gmail.com>
Wed, 24 Apr 2013 07:58:29 +0000 (09:58 +0200)
committerkarim hamidou <khamidou@gmail.com>
Wed, 24 Apr 2013 07:58:29 +0000 (09:58 +0200)
Makefile
interp.c
list.c
main.c

index 22788de6cea7ae67e19a5b8d906f1c386e99b191..74cce364da48d69d0e9ff367321065c9f03f6c5f 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -17,7 +17,6 @@ error.o: error.h error.c
 
 clean:
        rm *.o
-       rm *~
 
 count:
        wc -l `ls *.[chl] -1 | grep -v lex.yy.c | grep -v queue`
index 94906c3acc3de91acc378d13c66a757033145ef3..70630bbe1ee42a6a2e58d4799a561e53b5002189 100644 (file)
--- a/interp.c
+++ b/interp.c
@@ -27,10 +27,10 @@ int compile_image(FILE *fp)
 int expression(struct Object *ast) {
 
        int r = yylex();
+    struct Object *obj;
     switch(r) {
         case NUMBER:
-            puts("number here bro");
-            struct Object* obj = clone_object(number_object);
+            obj = clone_object(number_object);
             list_append(ast, obj);
             return message(ast);
             break;
@@ -42,10 +42,10 @@ int expression(struct Object *ast) {
 
 int message(struct Object *ast) {
     int r = yylex();
+    struct Object *obj;
     switch(r) {
         case SYMBOL:
-            printf("message : %s\n", yytext);
-            struct Object* obj = clone_object(base_object);
+            obj = clone_object(base_object);
             obj->type = T_MESSAGE;
             obj->name = strdup(yytext);
             list_append(ast, obj);
@@ -67,5 +67,14 @@ void display_ast(struct Object *ast) {
     
     int length = mojo_list_length(ast->value.l_value);
     
-    printf("ast->value.lv: %x, ast len: %d\n", ast->value.l_value, length);
+    printf("ast len: %d\n", length);
+    int i = 0;
+    for(i = 0; i < length; i++) {
+        struct Object *o = list_nth(ast, i);
+        printf("type: %d name: %s\n", o->type, o->name);
+    }
+}
+
+void execute(struct Object *ast) {
+
 }
diff --git a/list.c b/list.c
index d44264117b19aef0a8f33aff2948c22e46189338..ed1700eab80db6fe7e122db596985cf1b25ec6c6 100644 (file)
--- a/list.c
+++ b/list.c
@@ -153,12 +153,13 @@ struct Object* create_list_object(void)
 
 struct Object* list_append(struct Object *list, struct Object *o)
 {
-       if (list == NULL || list->type != T_LIST || list->type != T_BLOCK || list->value.l_value == NULL)
+       if (list == NULL || (list->type != T_LIST && list->type != T_BLOCK) || list->value.l_value == NULL) {
                return nil_object;
+    }
 
-       if (o == NULL)
+       if (o == NULL) {
                return NULL;
-
+    }
        mojo_list_append(list->value.l_value, o);
 
        return o;
@@ -166,7 +167,7 @@ struct Object* list_append(struct Object *list, struct Object *o)
 
 struct Object* list_remove(struct Object *list)
 {
-       if (list == NULL || list->type != T_LIST || list->type != T_BLOCK || list->value.l_value == NULL)
+       if (list == NULL || (list->type != T_LIST && list->type != T_BLOCK) || list->value.l_value == NULL)
                return nil_object;
 
        mojo_list_remove(list->value.l_value);
@@ -176,7 +177,7 @@ struct Object* list_remove(struct Object *list)
 
 struct Object* list_nth(struct Object *list, int n)
 {
-       if (list == NULL || list->type != T_LIST || list->type != T_BLOCK || list->value.l_value == NULL)
+       if (list == NULL || (list->type != T_LIST && list->type != T_BLOCK) || list->value.l_value == NULL)
                return nil_object;
 
        struct Object *o = mojo_list_nth(list->value.l_value, n);
@@ -191,7 +192,7 @@ struct Object* list_nth(struct Object *list, int n)
 
 struct Object* list_last(struct Object *list)
 {
-       if (list == NULL || list->type != T_LIST || list->type != T_BLOCK || list->value.l_value == NULL)
+       if (list == NULL || (list->type != T_LIST && list->type != T_BLOCK) || list->value.l_value == NULL)
                return nil_object;
 
        struct Object *o = mojo_list_last(list->value.l_value);
@@ -205,7 +206,7 @@ struct Object* list_last(struct Object *list)
 
 struct Object* list_length(struct Object *list)
 {
-       if (list == NULL || list->type != T_LIST || list->type != T_BLOCK || list->value.l_value == NULL)
+       if (list == NULL || (list->type != T_LIST && list->type != T_BLOCK) || list->value.l_value == NULL)
                return nil_object;
 
        struct Object *o = clone_object(number_object);
diff --git a/main.c b/main.c
index 5972ccf5a2f08ba9ea498d4e9f04e68ecb939ae1..ec20f31d19b1ae5fd2bc0d2bb734a6c8d6b324dd 100644 (file)
--- a/main.c
+++ b/main.c
@@ -5,6 +5,7 @@
 main() {
 
        init_object_system();
+    puts("this is mojo.");
        compile_image(stdin);
 
 }