Преправљена ламбда функција
This commit is contained in:
parent
916d3683ff
commit
93969f9588
2
Makefile
2
Makefile
|
@ -9,7 +9,7 @@ PREFIX = /usr/local
|
||||||
# флегови за C компајлер и линкер
|
# флегови за C компајлер и линкер
|
||||||
CPPFLAGS = -D_POSIX_C_SOURCE=200809L
|
CPPFLAGS = -D_POSIX_C_SOURCE=200809L
|
||||||
# CFLAGS = -g -std=c99 -pedantic -Wall -O0
|
# CFLAGS = -g -std=c99 -pedantic -Wall -O0
|
||||||
CFLAGS = -std=c99 -pedantic -Wall -O1
|
CFLAGS = -std=c99 -pedantic -Wall -O2
|
||||||
LDFLAGS = -lm -lc
|
LDFLAGS = -lm -lc
|
||||||
|
|
||||||
CC = cc
|
CC = cc
|
||||||
|
|
41
internals.c
41
internals.c
|
@ -1,3 +1,5 @@
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "symtable.h"
|
#include "symtable.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "eval.h"
|
#include "eval.h"
|
||||||
|
@ -30,6 +32,11 @@ int allSyms(object list)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
object ifStatement(object parameters)
|
||||||
|
{
|
||||||
|
*/
|
||||||
|
|
||||||
object add(object parameters)
|
object add(object parameters)
|
||||||
{
|
{
|
||||||
object result;
|
object result;
|
||||||
|
@ -206,6 +213,36 @@ object quote(object parameters)
|
||||||
return result;
|
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 lambda(object parameters)
|
||||||
{
|
{
|
||||||
object result;
|
object result;
|
||||||
|
@ -214,8 +251,7 @@ object lambda(object parameters)
|
||||||
TYPE(result) = errorObject;
|
TYPE(result) = errorObject;
|
||||||
ERR(result) = argumentNumberError;
|
ERR(result) = argumentNumberError;
|
||||||
}
|
}
|
||||||
else if (!(TYPE(CAR(parameters)) == consObject &&
|
else if (!validArgumentList(CAR(parameters)))
|
||||||
allSyms(CAR(parameters))))
|
|
||||||
{
|
{
|
||||||
TYPE(result) = errorObject;
|
TYPE(result) = errorObject;
|
||||||
ERR(result) = typeError;
|
ERR(result) = typeError;
|
||||||
|
@ -227,6 +263,7 @@ object lambda(object parameters)
|
||||||
PROC_TYPE(result) = compoundProc;
|
PROC_TYPE(result) = compoundProc;
|
||||||
PROC_COMP_ARGS(result) = copyObject(CAR(parameters));
|
PROC_COMP_ARGS(result) = copyObject(CAR(parameters));
|
||||||
PROC_COMP_BODY(result) = copyObject(CDR(parameters));
|
PROC_COMP_BODY(result) = copyObject(CDR(parameters));
|
||||||
|
PROC_COMP_TABLE(result) = currentTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
1
read.c
1
read.c
|
@ -347,7 +347,6 @@ object dispatchedChar(wchar_t c)
|
||||||
case L'|':
|
case L'|':
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
|
|
||||||
if ((c = scanwc(stdin)) == L'|' &&
|
if ((c = scanwc(stdin)) == L'|' &&
|
||||||
(c = scanwc(stdin)) == L'#')
|
(c = scanwc(stdin)) == L'#')
|
||||||
{
|
{
|
||||||
|
|
3
util.h
3
util.h
|
@ -26,6 +26,7 @@
|
||||||
#define PROC_BUILTIN(x) ((x).value.proc->value.builtin)
|
#define PROC_BUILTIN(x) ((x).value.proc->value.builtin)
|
||||||
#define PROC_COMP_ARGS(x) ((x).value.proc->value.compound.args)
|
#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_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(x) ((x).value.num)
|
||||||
#define NUM_TYPE(x) ((x).value.num.type)
|
#define NUM_TYPE(x) ((x).value.num.type)
|
||||||
|
@ -125,6 +126,7 @@ struct procedure
|
||||||
{
|
{
|
||||||
object args;
|
object args;
|
||||||
object body;
|
object body;
|
||||||
|
int table;
|
||||||
} compound;
|
} compound;
|
||||||
} value;
|
} value;
|
||||||
};
|
};
|
||||||
|
@ -135,6 +137,7 @@ int listLength(object list);
|
||||||
void deleteObject(object input);
|
void deleteObject(object input);
|
||||||
object copyObject(object input);
|
object copyObject(object input);
|
||||||
|
|
||||||
|
object list
|
||||||
|
|
||||||
object longlongToNumber(long long int input);
|
object longlongToNumber(long long int input);
|
||||||
object shortenFractionNum(object a);
|
object shortenFractionNum(object a);
|
||||||
|
|
Loading…
Reference in a new issue