File: header.h

package info (click to toggle)
gp2c 0.0.5pl2-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,508 kB
  • ctags: 1,114
  • sloc: ansic: 8,284; sh: 544; lex: 337; yacc: 158; makefile: 135
file content (419 lines) | stat: -rw-r--r-- 11,535 bytes parent folder | download
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
/*
Copyright (C) 2000-2005  The PARI group.

This file is part of the GP2C package.

PARI/GP is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation. It is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY WHATSOEVER.

Check the License for details. You should have received a copy of it, along
with the package; see the file 'COPYING'. If not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */

#include "stack.h"
int debug;
char *nameparse, *namelib;
int currfunc;
int lastpass;
int autogc;
int warn;

#define STACKSZ (1024)
#define GNIL    (0)
#define GNOARG  (1)
static   inline int min(int x, int y) { return (x<=y)?x:y; }    
static   inline int max(int x, int y) { return (x>=y)?x:y; }    

typedef struct
{
  char *txt;
  long lineno;
} error_string;

typedef struct
{
  stack s;
  char *txt;
} comment;

typedef struct
{
  char *s;
  int c;
} strcom;
typedef enum {Fseq,
	      Fmatrix,FmatrixL,FmatrixR,
	      Faffect,
	      Ffacteurmat,
	      Fmatrixelts,Fmatrixlines,
	      Fmat,Fvec,
	      Flistarg,
	      Frefarg,

	      Fconst,Fsmall,Fgnil,
	      Ftag,
	      Fentry,Fentryfunc,Fdeffunc,

	      /*This node is generated by genblock, not by parser*/
	      Fblock, Ffunction
} Ffunc;
#define FneedENTRY (Fconst)
#define Flastfunc  (Fblock)

/*see parse.y for definition.
Fblock x: block number y:seq
Fgnil   : it's a noop, but if evaluated leads to 0.
*/
extern const char *Ffuncname[];


#include "type.h"
#include "optable.h"
typedef enum {Cuser,Cauto,Cglobal,Cconst,Carg,Ccompo,
              Cimmutable,Cdefmarker,Cundeclared} Vtype;
/*
  Cuser: Variable defined by user in the source
  Cauto: Variable get type of initialisation
  Cglobal: Global variable for this module.
  Cconst:  Variable affected exactly once in the code.
  Cargs:   Variable is a function's parameter.
  Ccompo:  Variable components are updated.
  Creturn: Variable is to be passed to return.
  Cimmutable: Variable affected exactly once in the run.
  Cdefmarker: Variable initialised to the default marker.
  Cundeclared: Variable was not declared.
 */
typedef struct node_s
{
  Ffunc f;          /*node function*/
  int x;            /*node left child*/
  int y;            /*node right child*/
  int t;            /*node type*/
  int m;            /*node mode bitmask*/
  int lineno;       /*linenumber of corresponding code*/
  int comment;
} node;

/* Automatic variables GP names are <number1>.
 * Automatic variables C names are {p,l}<number2>
 * with number2<=number1 since we remove unused variables.
 */

#define varstr(y) (value[tree[(y).node].x].val.str)
#define vartype(x) (tree[(x).node].t)

typedef struct
{
  int flag;         /*context type, Vtype bitmask*/
  int key;          /*context hashkey*/
  const char *cvar; /*context var C name*/
  int node;
  int initval;      /*context initial value of var*/
  int val;          /*context value, if constant*/
} ctxvar;

typedef struct
{
  enum {AFaccess,AFaffect,AFaffectcompo,AFaffectcopy,AFrefarg, AFhide, AFclone} f;
  int idx;
} affnode;

enum {GCneeded, GCupto, GCglobal, GCreturn} GCenum;
typedef struct
{
  ctxvar *c;       /*context stack*/
  stack s;        
  int ret;         /*if not -1 , node number of var holding return
                     value*/
  affnode *var;    /*Data about variable*/
  stack v;
  int savb;
  int egc;         /*Extra var to be gerepiled*/
  long gc;         /*garbage collecting attribute, bitmask of GCenum*/
  int *gcvar;      /*List of var that need to be gerepiled*/
  stack g;
} context;

typedef struct
{
  enum {AAtype,AActype,AAnoarg,AAsmall,AAstring,AAreftype,AAherevalue,AAlvalue,AAmulti,AAstdarg,AAoptsmall,AAopttype} t;
  int misc;
  int type;
  int mode;
  char *str;
} descargatom;

typedef struct
{
  const char *cname;        /* C code */
  int type;                 /*return type*/
  int mode;                 /*return mode*/
  int nargs;                /*nb args*/
  descargatom *args;        /*type of args*/
} gpdescarg;

typedef struct
{
  int nb;          /*nb of description*/
  gpdescarg *a;    /*array of description*/
} gpdesc;

typedef struct
{
  const char *cname;  	/* C name */
  const char *code;	/* GP code */
  const char *origin;	/* library name of the symbol, NULL for gp/libpari*/
  const char *help;
} gpproto;

typedef struct
{
  int pdefnode;
  int defnode;
  int bl;
  int sarg;
  int narg;
  int bctx;
  affnode *var;        /*Data about variable*/
  stack v;
  int savb;
  int *gcvar;      /*List of var that need to be gerepiled*/
  stack g;
} userfunc;

/*Positive enum are private to funcspec.c/patchfunc.h*/
typedef enum {GPinstalled=-2,GPpari=-1,GPuser=0} GPspec;

typedef struct
{
  const char *gpname;    /*name for GP*/ 
  int node;              /*Ffunction node*/
  GPspec spec;     /*Spec name for spec function*/
  gpproto proto;
  gpdesc *dsc;     /*Description or NULL*/
  userfunc *user;
} gpfunc;

#define functype(x) (tree[(x).node].t)
#define funcmode(x) (tree[(x).node].m)

int FC_badtype, FC_formatcode, FC_tovec, FC_cast;
int FC_decl_base,FC_decl_ext;
int FC_gerepileupto, FC_gerepileall;
int FC_const_smallreal, FC_const_real, FC_const_expr;
int FC_proto_ret, FC_proto_code;
int FC_default_check, FC_default_marker;
int FC_copy, FC_avma, FC_low_stack_lim;
int FC_forprime_next, FC_matrixrow;

int Vgen;
int Ggptr;
int Gpari_sp, Gbptr;

typedef enum {CSTsmall, CSTsmallreal, CSTint, CSTreal, CSTstr} CSTtype;

typedef struct
{
  CSTtype type;     /*type of data*/
  union value_u  
  {
    long small;
    const char *str;
  } val;
} value_t;

typedef struct
{
  const char *name;
} Ctype_t;

typedef struct
{
  const char *name;
} GPtype_t;

typedef struct
{
  const char *name;
} Mmode_t;

typedef struct
{
  int ok;
  int num;
  int go;
  int ne;
} label_t;

node *tree;
value_t *value;
gpfunc *lfunc;
ctxvar *ctxstack;
affnode *affstack;
context *block;
comment *com;
error_string *errors;
Ctype_t *Ctype;
GPtype_t *GPtype;
Mmode_t *Mmode;
label_t *label;

stack s_node,s_value,s_func,s_ctx,s_aff,s_bloc,s_comment,s_errors;
stack s_Ctype, s_GPtype, s_Mmode, s_label;

typedef enum { err_func=-1,err_parse=-2,err_desc=-3 } err_name;

char *xstrndup(const char *s, size_t n);

#ifdef __GNUC__
/*Avoid spurious warning*/
void die(int n, const char *format, ...) __attribute__ ((noreturn));
#else
void die(int n, const char *format, ...);
#endif
void warning(int n, const char *format, ...);

int listtostack(int n, int f, int *stack, int nbmax, const char *error,int nerr);
int listcalltostack(int n, int fnum, int *stack, int nbmax, const char *error,int nerr);
int listtostackparent(int n, int f, int *stack, int nbmax, const char *error,int nerr);
int genlistargs(int n,int *stack,int min,int max);
int genlistcats(int y,int *stack,int max);

int newcomment(void);
void pushcomment(int n, char x);
void gencomment(FILE *fout, int n, int flag);

typedef enum {PPend,PPstd,PPdefault,PPdefaultmulti,PPmultiarg,PPsep} PPproto;

PPproto parseproto(char const **q, char *c);

int newnode(Ffunc f, int x, int y);
int newnodecom(Ffunc f, int x, int y, int com);
int newsmall(int n);
int newdotnode(const char *s, int c);
int newrealnode(const char *s, int c);
int newintnode(const char *s, int c);
int newstringnode(const char *s, int c);
int newquotenode(const char *s, int c);
int newsmallrealvalue(long small);
int newentry(const char *s);
int newmember(const char *s);
int newleaf(int n);
int newopcall(OPerator s, int x, int y);
int newtag(int x, char *s, int c);
int newcoeff(int n, int x, int y);
int newlabel(int n);

const char *usercname(const char *s);

int is_const(int n, CSTtype t);

const char *entryname(int n);
int newuserfunc(const char *gpname);
int newblock(void);
int listtoseq(int *stack, int nb);
int newseq(int x, int y);
int newdecl(int flag, int t, int initval, int *v);
int newcall(const char *s, int y);
int findfunction(const char *name);
int findfunction_len(const char *s, int n);
int findfuncdesc(const char *s);
int findfuncdescopt(const char *s);
int findfunctype(char *s);
void genequal(int aff, const char *func, int *var, int *binf, int *t);
int addseqright(int seq, int n);
int addseqleft(int n, int seq);
int getfunc(const char *gpname);
  
const char *funcname(int f);
const char *GPname(int f);
void printnode(FILE *fout, int n);
void maketree(FILE *fout,int n);
int gentype(int n);
int genblockdeclaration(int args, int n, int flag, int type);

void genheader(FILE *fout);
void gencode(FILE *fout, int n);
void gencodeg(FILE *fout, int n);
void genblock_nolabel(int n, int p);
label_t genblock_label(int n, int p);
void genblock(int n, int p);
void gentoplevel(int n, int p);
int addinitfunc(int n);
void gendeblock(int n, int p, int ps, int *r, int *rs);
void moveblock(int n, int p, int ps, int *r, int *rs);
void pilelist(int n);
void pileclean(int n);
void varlist(int n);

void gensemicomma(FILE *fout,int x);
void genparens(FILE *fout, int x);
void genparensg(FILE *fout, int x);
void genbrace(FILE *fout, int x);
void genindent(FILE *fout);
void genindentseq(FILE *fout, int x);
void genpercent(FILE *fout, int n);

void gencast(FILE *fout, int n, int nt);
void gencastf(FILE *fout, int n, int nt, int f);
void gencastl(FILE *fout, int n, int nt, int f);

void gentypedec(FILE *fout, int t);
void genvarproto(FILE *fout, int n, int nerr);

void genentry(FILE *fout, int n);
void genentryfunc(FILE *fout, int n);
void genprotocode(FILE *fout,int nf);
void genprototype(FILE *fout,int nf, int kb);
void gendeffunc(FILE *fout, int n);
void gendefblock(FILE *fout, int n);

void genblockfuncspec(int n, int p, gpfunc *gp);
int gentypefuncspec(int n, gpfunc *gp);
void genentryspec(FILE *fout, int n, gpfunc *gp);
void gencodenoarg(FILE *fout, int t, int n);

gpdescarg *descfindrules(int nb, int *arg, gpfunc *gp);
gpdescarg *descfindrules1(int arg, int nf);
void gencodedesc(FILE *fout, int nb, int *arg, gpdescarg *rule, int nerr);
int genfuncbydesc(FILE *fout, int nb, int *arg, int nf, int nerr);
int genfuncbydesc1(FILE *fout, int arg, int nf, int nerr);
int genfuncbycode(FILE *fout, int nb, int *arg, int nf, int nerr);
int genfuncbycode1(FILE *fout, int arg, int nf, int nerr);
int genfunc(FILE *fout, int nb, int *arg, int nf, int nerr);
int genfunc1(FILE *fout, int arg, int nf, int nerr);

int detag(int n);
int getlvalue(int n);
int getlvaluerr(int n);
int getvar(int n);
int getvarerr(int n);
int getvarbyname(const char *s);
ctxvar *getvarinblock(int n, context *fc);
int pushvar(int n, int ctype, int t, int initval);
void pushctx(context *fc);
void restorectx(int c);
void copyctx(int n, context *fc);
int newctx(int flag);
int newaff(int func, int idx);
void copyaff(int sava, int savc, context *fc);

int isfunc(int n, const char *s);
int isasmall(const char *s, long *res);
int newctype(const char *s);
int strtoctype(const char *s);
int newtype(const char *s);
int strtotype(const char *s);
int strtotype_len(const char *s, size_t n);
int newmode(const char *s);
int strtomode(char *s);
int geninsertvar(int seq, int ret);
int geninsertvarop(int seq, int ret, OPerator op);
int newgetg(int v, int l, const char *t);
void makeblock(int bl, int n, int aseq, int ret, int savx);
void makeblocks(int bl1, int bl2, int n, int bseq, int aseq, int ret, int savx);
void makeblocks3(int bl1, int bl2, int bl3, int n, int bseq, int aseq, int ret, int sav0, int savx);
int gengerepilelist(context *fc,int **gc);
void gengerepileend(int bl);