From bd3629073564cd08cd861d048b330527e9969407 Mon Sep 17 00:00:00 2001 From: kappa Date: Sun, 3 Nov 2019 14:02:03 +0100 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B4=D0=B0=D1=82=D0=B5=20=D1=84?= =?UTF-8?q?=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D1=98=D0=B5=20=D1=83=20=D1=81?= =?UTF-8?q?=D0=B2=D1=80=D1=85=D1=83=20=D0=B4=D0=B5=D0=B1=D0=B0=D0=B3=D0=B8?= =?UTF-8?q?=D1=80=D0=B0=D1=9A=D0=B0,=20=D0=B8=20=D0=BC=D0=B0=D1=9A=D0=B5?= =?UTF-8?q?=20=D1=81=D1=82=D0=B8=D0=BB=D1=81=D0=BA=D0=B5=20=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D0=BC=D0=B5=D0=BD=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile.unix | 2 +- cirilisp.c | 5 +++-- print.c | 29 ++++++++++++++++++++++++++++- 3 files changed, 32 insertions(+), 4 deletions(-) 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