1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
|
/* Global definitions of limits and constants */
#define MAX_LINE_LENGTH 1024
#define MAX_LINE_TOKENS 1024
typedef enum
{
ArrayTag,
FunctionTag,
HybridTag,
MonadicOpTag,
DyadicOpTag,
BoundFunctionTag, /* Function with left arg bound */
LParTag,
RParTag,
LBracketTag,
RBracketTag,
ArrowTag,
AssignmentTag,
NameTag,
} datumTag;
typedef enum
{
AtypeInt,
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;
typedef struct Symtab Symtab;
struct Array
{
arrayDataType type;
int rank;
int *shape;
int size;
int stranded; /* 1 if build directly by stranding */
int refs; /* reference counting */
union {
char *rawdata;
vlong *intdata;
Array **arraydata;
};
};
struct Statement
{
int ntoks;
Datum *toks;
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;
};
struct Datum
{
datumTag tag;
int shy;
union {
Array *array;
Statement stmt;
Function func;
Operator operator;
Symbol *symbol;
};
};
struct Symbol
{
int undefined;
Rune *name;
Datum value;
};
struct Symtab
{
int nsyms;
Symbol **syms;
};
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 */
Datum *evalline(Rune *);
/* print.c */
Rune *ppdatum(Datum);
Rune *ppdatums(Datum *, int);
Rune *pparray(Array *);
Rune *ppoperator(Operator);
/* lexer.c */
Statement *lexline(Rune *);
/* array.c */
Array *mkscalarint(vlong);
Array *duparray(Array *);
int simplearray(Array *);
int simplescalar(Array *);
Array *extend(Array *, Array *);
int scalarextend(Array *, Array *, Array **, Array **);
/* eval.c */
Datum *eval(Statement *);
/* symbol.c */
Symbol *getsym(Symtab *, Rune *);
Symtab *newsymtab(void);
void freesymtab(Symtab *);
vlong globalIO(void);
/* memory.c */
Array *allocarray(int, int, int);
void freearray(Array *);
void incref(Array *);
/* functions.c */
Array *runfunc(Function, Array *,Array *);
/* Monadic functions from function.c */
Array *fnSame(Array *);
Array *fnTally(Array *);
Array *fnEnclose(Array *);
Array *fnNest(Array *);
Array *fnIndexGenerator(Array *);
Array *fnRavel(Array *);
Array *fnShape(Array *);
/* Dyadic functions from function.c */
Array *fnPlus(Array *, Array *);
Array *fnMinus(Array *, Array *);
Array *fnTimes(Array *, Array *);
Array *fnDivide(Array *, Array *);
Array *fnPower(Array *, Array *);
Array *fnLogarithm(Array *, Array *);
Array *fnLeft(Array *, Array *);
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[]; /* functions.c */
extern Rune primmonopnames[]; /* operators.c */
extern Rune primdyadopnames[]; /* operators.c */
extern Rune primhybridnames[]; /* lexer.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 */
|