From 07082593ab4abfbf9a3dd6729cb2e548ec303115 Mon Sep 17 00:00:00 2001 From: Peter Mikkelsen Date: Fri, 14 Jan 2022 00:31:03 +0000 Subject: =?UTF-8?q?Implement=20code=20for=20running=20operators=20(both=20?= =?UTF-8?q?monadic=20and=20dyadic).=20Also=20implement=20=E2=8D=A8=20and?= =?UTF-8?q?=20=E2=8D=A5=20since=20they=20are=20very=20simple?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apl9.h | 48 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 7 deletions(-) (limited to 'apl9.h') diff --git a/apl9.h b/apl9.h index 63b6d7a..72b8ca2 100644 --- a/apl9.h +++ b/apl9.h @@ -25,15 +25,23 @@ typedef enum AtypeArray, } arrayDataType; +typedef enum +{ + OperatortypeDop, + OperatortypePrim, +} operatorType; + typedef enum { FunctypeDfn, FunctypePrim, + FunctypeOp, } functionType; /* Data types */ typedef struct Array Array; typedef struct Statement Statement; +typedef struct Operator Operator; typedef struct Function Function; typedef struct Datum Datum; typedef struct Symbol Symbol; @@ -61,12 +69,25 @@ struct Statement Statement *next; }; +struct Operator +{ + operatorType type; + int dyadic; + union { + int code; + Rune *dop; + }; + Datum *left; + Datum *right; +}; + struct Function { functionType type; union { int code; Rune *dfn; + Operator operator; }; Array *left; }; @@ -79,6 +100,7 @@ struct Datum Array *array; Statement stmt; Function func; + Operator operator; Symbol *symbol; }; }; @@ -98,6 +120,8 @@ struct Symtab typedef Array* (*fnmonad)(Array*); typedef Array* (*fndyad)(Array*, Array*); +typedef Array* (*opmonad)(Datum *, Array *, Array *); +typedef Array* (*opdyad)(Datum *, Datum *, Array *, Array *); /* Function prototypes for the different source files */ /* main.c */ @@ -107,6 +131,7 @@ Datum *evalline(Rune *); Rune *ppdatum(Datum); Rune *ppdatums(Datum *, int); Rune *pparray(Array *); +Rune *ppoperator(Operator); /* lexer.c */ Statement *lexline(Rune *); @@ -133,7 +158,10 @@ Array *allocarray(int, int, int); void freearray(Array *); void incref(Array *); -/* Monadic functions from functions.h */ +/* functions.c */ +Array *runfunc(Function, Array *,Array *); + +/* Monadic functions from function.c */ Array *fnSame(Array *); Array *fnTally(Array *); Array *fnEnclose(Array *); @@ -142,7 +170,7 @@ Array *fnIndexGenerator(Array *); Array *fnRavel(Array *); Array *fnShape(Array *); -/* Dyadic functions from functions.h */ +/* Dyadic functions from function.c */ Array *fnPlus(Array *, Array *); Array *fnMinus(Array *, Array *); Array *fnTimes(Array *, Array *); @@ -154,16 +182,22 @@ Array *fnRight(Array *, Array *); Array *fnCatenateFirst(Array *, Array *); Array *fnReshape(Array *, Array *); +/* Monadic operators from operators.c */ +Array *opSwitch(Datum *, Array *, Array *); +Array *opOver(Datum *, Datum *, Array *, Array *); + /* Global variables */ extern int traceeval; /* eval.c */ extern Rune *errormsg; /* eval.c */ extern int datasizes[]; /* array.c */ -extern Rune primfuncnames[]; /* function.c */ -extern Rune primmonopnames[]; /* lexer.c */ -extern Rune primdyadopnames[]; /* lexer.c */ +extern Rune primfuncnames[]; /* functions.c */ +extern Rune primmonopnames[]; /* operators.c */ +extern Rune primdyadopnames[]; /* operators.c */ extern Rune primhybridnames[]; /* lexer.c */ -extern fnmonad monadfunctiondefs[]; /* function.c */ -extern fndyad dyadfunctiondefs[]; /* function.c */ +extern fnmonad monadfunctiondefs[]; /* functions.c */ +extern fndyad dyadfunctiondefs[]; /* functions.c */ +extern opmonad monadoperatordefs[]; /* operators.c */ +extern opdyad dyadoperatordefs[]; /* operators.c */ extern Symtab *globalsymtab; /* symbol.c */ extern Symtab *currentsymtab; /* symbol.c */ extern int alloccounts; /* memory.c */ \ No newline at end of file -- cgit v1.2.3