From 93969f9588f483d34beddf374e038685981b16f1 Mon Sep 17 00:00:00 2001 From: kappa Date: Mon, 4 Feb 2019 21:16:35 +0100 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=B5=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D1=99=D0=B5=D0=BD=D0=B0=20=D0=BB=D0=B0=D0=BC=D0=B1=D0=B4=D0=B0?= =?UTF-8?q?=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D1=98=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 2 +- internals.c | 41 +++++++++++++++++++++++++++++++++++++++-- read.c | 3 +-- util.h | 3 +++ 4 files changed, 44 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 26423f1..b7ddf2e 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ PREFIX = /usr/local # флегови за C компајлер и линкер CPPFLAGS = -D_POSIX_C_SOURCE=200809L # CFLAGS = -g -std=c99 -pedantic -Wall -O0 -CFLAGS = -std=c99 -pedantic -Wall -O1 +CFLAGS = -std=c99 -pedantic -Wall -O2 LDFLAGS = -lm -lc CC = cc diff --git a/internals.c b/internals.c index 9871488..027387a 100644 --- a/internals.c +++ b/internals.c @@ -1,3 +1,5 @@ +#include + #include "symtable.h" #include "util.h" #include "eval.h" @@ -30,6 +32,11 @@ int allSyms(object list) return 1; } + +object ifStatement(object parameters) +{ + */ + object add(object parameters) { object result; @@ -206,6 +213,36 @@ object quote(object parameters) return result; } +int validArgumentList(object list) +{ + if (!properList(list) || !allSyms(list)) + { + return 0; + } + else + { + int allUniqueSyms = 1; + object *currentSymbol1 = &list; + while (TYPE(*currentSymbol1) != nilObject) + { + object *currentSymbol2 = &CDR(*currentSymbol1); + while (TYPE(*currentSymbol2) != nilObject) + { + if (!strcmp(SYM(CAR(*currentSymbol1)), + SYM(CAR(*currentSymbol2)))) + { + allUniqueSyms = 0; + goto breakloop; + } + currentSymbol2 = &CDR(*currentSymbol2); + } + currentSymbol1 = &CDR(*currentSymbol1); + } +breakloop: + return allUniqueSyms; + } +} + object lambda(object parameters) { object result; @@ -214,8 +251,7 @@ object lambda(object parameters) TYPE(result) = errorObject; ERR(result) = argumentNumberError; } - else if (!(TYPE(CAR(parameters)) == consObject && - allSyms(CAR(parameters)))) + else if (!validArgumentList(CAR(parameters))) { TYPE(result) = errorObject; ERR(result) = typeError; @@ -227,6 +263,7 @@ object lambda(object parameters) PROC_TYPE(result) = compoundProc; PROC_COMP_ARGS(result) = copyObject(CAR(parameters)); PROC_COMP_BODY(result) = copyObject(CDR(parameters)); + PROC_COMP_TABLE(result) = currentTable; } return result; diff --git a/read.c b/read.c index 1ecdca6..4a9a0c3 100644 --- a/read.c +++ b/read.c @@ -105,7 +105,7 @@ wchar_t *increaseBuffer() wchar_t scanwc(FILE *stream) { wint_t c; - + if ((c = fgetwc(stream)) == WEOF) { printf("\nКрај улазног стрима.\nВоЗдра и дођите нам опет!\n"); @@ -347,7 +347,6 @@ object dispatchedChar(wchar_t c) case L'|': for (;;) { - if ((c = scanwc(stdin)) == L'|' && (c = scanwc(stdin)) == L'#') { diff --git a/util.h b/util.h index 50d3402..6656b0f 100644 --- a/util.h +++ b/util.h @@ -26,6 +26,7 @@ #define PROC_BUILTIN(x) ((x).value.proc->value.builtin) #define PROC_COMP_ARGS(x) ((x).value.proc->value.compound.args) #define PROC_COMP_BODY(x) ((x).value.proc->value.compound.body) +#define PROC_COMP_TABLE(x) ((x).value.proc->value.compound.table) #define NUM(x) ((x).value.num) #define NUM_TYPE(x) ((x).value.num.type) @@ -125,6 +126,7 @@ struct procedure { object args; object body; + int table; } compound; } value; }; @@ -135,6 +137,7 @@ int listLength(object list); void deleteObject(object input); object copyObject(object input); +object list object longlongToNumber(long long int input); object shortenFractionNum(object a);