From fa931c0d33db9fe2705186a507318e31329e1712 Mon Sep 17 00:00:00 2001 From: kappa Date: Sat, 30 Nov 2019 20:18:21 +0100 Subject: [PATCH] =?UTF-8?q?=D0=9C=D0=B0=D0=BB=D0=B5=20=D1=81=D1=82=D0=B8?= =?UTF-8?q?=D0=BB=D1=81=D0=BA=D0=B5=20=D0=BF=D1=80=D0=BE=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- print.c | 16 +++++++++------- util.c | 58 ++++++++++++++++++++++++++++++++++----------------------- 2 files changed, 44 insertions(+), 30 deletions(-) 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;