Мале стилске промене

This commit is contained in:
kappa 2019-11-30 20:18:21 +01:00
parent bd36290735
commit fa931c0d33
2 changed files with 44 additions and 30 deletions

16
print.c
View file

@ -6,19 +6,21 @@ void printValue(object input);
int Print(object input) int Print(object input)
{ {
if (TYPE(input) == errorObject) switch (TYPE(input))
{ {
case errorObject:
fprintf(stderr, "\nГРЕШКА: %s\n\n", ERR(input)); fprintf(stderr, "\nГРЕШКА: %s\n\n", ERR(input));
} break;
else if (TYPE(input) == EOFObject) case EOFObject:
{
return 0; return 0;
} break;
else if (TYPE(input) != unspecifiedObject) case unspecifiedObject:
{ break;
default:
printf("\n"); printf("\n");
printValue(input); printValue(input);
printf("\n\n"); printf("\n\n");
break;
} }
return 1; return 1;

58
util.c
View file

@ -179,23 +179,15 @@ int improperListLength(object list)
void deleteObject(object input) void deleteObject(object input)
{ {
if (TYPE(input) == symbolObject && SYM(input) != NULL) switch (TYPE(input))
{
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)
{ {
case consObject:
deleteObject(CAR(input));
deleteObject(CDR(input));
free(CONS(input));
CONS(input) = NULL;
break;
case procedureObject:
if (PROC_TYPE(input) == compoundProc) if (PROC_TYPE(input) == compoundProc)
{ {
deleteObject(PROC_COMP_ARGS(input)); deleteObject(PROC_COMP_ARGS(input));
@ -203,13 +195,33 @@ void deleteObject(object input)
} }
free(PROC(input)); free(PROC(input));
PROC(input) = NULL; PROC(input) = NULL;
} break;
else if (TYPE(input) == consObject) case symbolObject:
{ if (SYM(input) == NULL)
deleteObject(CAR(input)); {
deleteObject(CDR(input)); break;
free(CONS(input)); }
CONS(input) = NULL; 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; TYPE(input) = nilObject;