From: karim hamidou Date: Wed, 24 Apr 2013 07:58:29 +0000 (+0200) Subject: fixed a slew of condition bugs X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=08285dc5e49fa7a9ea895720b4e203158de5b351;p=mojo.git fixed a slew of condition bugs --- diff --git a/Makefile b/Makefile index 22788de..74cce36 100644 --- 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` diff --git a/interp.c b/interp.c index 94906c3..70630bb 100644 --- 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 d442641..ed1700e 100644 --- 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 5972ccf..ec20f31 100644 --- a/main.c +++ b/main.c @@ -5,6 +5,7 @@ main() { init_object_system(); + puts("this is mojo."); compile_image(stdin); }