diff --git a/Makefile.unix b/Makefile.unix index b567d9f..4d6d178 100644 --- a/Makefile.unix +++ b/Makefile.unix @@ -4,7 +4,7 @@ LIBPREFIX = $(PREFIX)/lib # флегови за C компајлер и линкер CPPFLAGS = -D_POSIX_C_SOURCE=2 -DDESTDIR=\"$(DESTDIR)\" -DVERSION=\"$(VERSION)\" -# CFLAGS = -g -std=c99 -pedantic -Wall -Wextra -Wno-maybe-uninitialized -O0 +# CFLAGS = -DDEBUG -g -std=c99 -pedantic -Wall -Wextra -Wno-maybe-uninitialized -O0 CFLAGS = -std=c99 -pedantic -Wall -Wextra -Wno-maybe-uninitialized -O3 LDFLAGS = -lm diff --git a/cirilisp.c b/cirilisp.c index 8429c87..d06835d 100644 --- a/cirilisp.c +++ b/cirilisp.c @@ -168,8 +168,9 @@ int main(int argc, char **argv) } printf("Добродошли у ЋИРИЛИСП ЧПШП окружење, верзија: " VERSION "\n"); - while (Print(Eval(Read("Ћ> ", stdin), globalEnv))) - ; + object current; + while (Print(current = Eval(Read("Ћ> ", stdin), globalEnv))) + deleteObject(current); printf("\nДостигнут крај улазног тока.\nЗбогом и дођите нам опет!\n"); exitCirilisp(0); diff --git a/print.c b/print.c index 3e75a61..8c80a6f 100644 --- a/print.c +++ b/print.c @@ -20,7 +20,7 @@ int Print(object input) printValue(input); printf("\n\n"); } - deleteObject(input); + return 1; } @@ -101,3 +101,30 @@ void printValue(object input) break; } } + +#ifdef DEBUG +void PrintEntry(entry *e) +{ + if (e == NULL) + { + return; + } + PrintEntry(e->left); + printf("%s: ", e->name); + Print(e->value); + PrintEntry(e->right); +} + +void PrintEnv(env environment) +{ + printf("%p", (void *) environment); + env enclosings = environment->enclosing; + while (enclosings != NULL) + { + printf(" <-- %p", (void *) enclosings); + enclosings = enclosings->enclosing; + } + printf("\n"); + PrintEntry(environment->table); +} +#endif