diff --git a/print.c b/print.c index 8c80a6f..92574d9 100644 --- a/print.c +++ b/print.c @@ -6,19 +6,21 @@ void printValue(object input); int Print(object input) { - if (TYPE(input) == errorObject) + switch (TYPE(input)) { + case errorObject: fprintf(stderr, "\nГРЕШКА: %s\n\n", ERR(input)); - } - else if (TYPE(input) == EOFObject) - { + break; + case EOFObject: return 0; - } - else if (TYPE(input) != unspecifiedObject) - { + break; + case unspecifiedObject: + break; + default: printf("\n"); printValue(input); printf("\n\n"); + break; } return 1; diff --git a/util.c b/util.c index 11f31a7..6aabe54 100644 --- a/util.c +++ b/util.c @@ -179,23 +179,15 @@ int improperListLength(object list) void deleteObject(object input) { - if (TYPE(input) == symbolObject && SYM(input) != NULL) - { - free(SYM(input)); - SYM(input) = NULL; - } - else if (TYPE(input) == stringObject && STR(input) != NULL) - { - free(STR(input)); - STR(input) = NULL; - } - else if (TYPE(input) == errorObject && ERR(input) != NULL) - { - free(ERR(input)); - ERR(input) = NULL; - } - else if (TYPE(input) == procedureObject) + switch (TYPE(input)) { + case consObject: + deleteObject(CAR(input)); + deleteObject(CDR(input)); + free(CONS(input)); + CONS(input) = NULL; + break; + case procedureObject: if (PROC_TYPE(input) == compoundProc) { deleteObject(PROC_COMP_ARGS(input)); @@ -203,13 +195,33 @@ void deleteObject(object input) } free(PROC(input)); PROC(input) = NULL; - } - else if (TYPE(input) == consObject) - { - deleteObject(CAR(input)); - deleteObject(CDR(input)); - free(CONS(input)); - CONS(input) = NULL; + break; + case symbolObject: + if (SYM(input) == NULL) + { + break; + } + free(SYM(input)); + SYM(input) = NULL; + break; + case stringObject: + if (STR(input) == NULL) + { + break; + } + free(STR(input)); + STR(input) = NULL; + break; + case errorObject: + if (ERR(input) == NULL) + { + break; + } + free(ERR(input)); + ERR(input) = NULL; + break; + default: + break; } TYPE(input) = nilObject;