From cee90aee74b3b11e9ea37185e1d51e11d382adf5 Mon Sep 17 00:00:00 2001 From: kappa Date: Sat, 19 Jan 2019 20:30:52 +0100 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=BC=D0=BF=D0=BB=D0=B5=D0=BC=D0=B5?= =?UTF-8?q?=D0=BD=D1=82=D0=B8=D1=80=D0=B0=D0=BD=20quote=20=D0=BD=D0=B0?= =?UTF-8?q?=D0=B2=D0=BE=D0=B4=20=D0=BE=D0=BF=D0=B5=D1=80=D0=B0=D1=82=D0=B5?= =?UTF-8?q?=D1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- eval.c | 48 ++++++++++++++++++++++++++---------------------- init.c | 1 + internals.c | 15 +++++++++++++++ internals.h | 1 + 4 files changed, 43 insertions(+), 22 deletions(-) diff --git a/eval.c b/eval.c index 8f17980..080fd48 100644 --- a/eval.c +++ b/eval.c @@ -14,17 +14,16 @@ object eval(object input) if (TYPE(input) == nilObject || TYPE(input) == numberObject || TYPE(input) == errorObject) { - result = input; + result = copyObject(input); } else if (TYPE(input) == symbolObject) { if (symbolExists(SYM(input))) { - result = input; + result = copyObject(input); } else { - deleteObject(input); TYPE(result) = errorObject; ERR(result) = unrecognizedSymbolError; } @@ -33,34 +32,39 @@ object eval(object input) { if (!properList(input)) { - deleteObject(input); TYPE(result) = errorObject; ERR(result) = improperListError; } - - object *currentCell = &input; - int noErrors = 1; - while (TYPE(*currentCell) != nilObject) + else { - CAR(*currentCell) = eval(CAR(*currentCell)); - - if (TYPE(CAR(*currentCell)) == errorObject) + object *currentCell = &input; + int noErrors = 1; + while (TYPE(*currentCell) != nilObject) { - noErrors = 0; - TYPE(result) = errorObject; - ERR(result) = ERR(CAR(*currentCell)); - break; - } - currentCell = &CDR(*currentCell); - } + if (strcmp(SYM(CAR(input)), "навод") != 0) + { + CAR(*currentCell) = + eval(CAR(*currentCell)); + } - if (noErrors) - { - result = apply(CAR(input), CDR(input)); + if (TYPE(CAR(*currentCell)) == errorObject) + { + noErrors = 0; + TYPE(result) = errorObject; + ERR(result) = ERR(CAR(*currentCell)); + break; + } + currentCell = &CDR(*currentCell); + } + + if (noErrors) + { + result = apply(CAR(input), CDR(input)); + } } - deleteObject(input); } + deleteObject(input); return result; } diff --git a/init.c b/init.c index 8fa1f17..c608d4d 100644 --- a/init.c +++ b/init.c @@ -20,4 +20,5 @@ void init() addSymbolInternal("-", &subtract); addSymbolInternal("*", &multiply); addSymbolInternal("/", ÷); + addSymbolInternal("навод", "e); } diff --git a/internals.c b/internals.c index eb36f51..4242420 100644 --- a/internals.c +++ b/internals.c @@ -135,3 +135,18 @@ object divide(object parameters) return result; } + +object quote(object parameters) +{ + object result; + if (listLength(parameters) != 1) + { + TYPE(result) = errorObject; + ERR(result) = argumentNumberError; + } + else + { + result = copyObject(CAR(parameters)); + } + return result; +} diff --git a/internals.h b/internals.h index 0895f28..3a6fa3b 100644 --- a/internals.h +++ b/internals.h @@ -4,3 +4,4 @@ object add(object parameters); object subtract(object parameters); object multiply(object parameters); object divide(object parameters); +object quote(object parameters);