Testing latest pari + WASM + node.js... and it works?! Wow.
License: GPL3
ubuntu2004
/* Copyright (C) 2000 The PARI group.12This file is part of the PARI/GP package.34PARI/GP is free software; you can redistribute it and/or modify it under the5terms of the GNU General Public License as published by the Free Software6Foundation; either version 2 of the License, or (at your option) any later7version. It is distributed in the hope that it will be useful, but WITHOUT8ANY WARRANTY WHATSOEVER.910Check the License for details. You should have received a copy of it, along11with the package; see the file 'COPYING'. If not, write to the Free Software12Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */1314/* This file contains memory and I/O management definitions */1516typedef struct {17long s, us;18} pari_timer;1920typedef struct pari_str {21char *string; /* start of the output buffer */22char *end; /* end of the output buffer */23char *cur; /* current writing place in the output buffer */24size_t size; /* buffer size */25int use_stack; /* use stack_malloc instead of malloc ? */26} pari_str;2728typedef unsigned char *byteptr;29typedef ulong pari_sp;3031struct pari_sieve32{33ulong start, end, maxpos;34ulong c, q;35unsigned char* sieve;36};3738/* iterator over primes */39typedef struct {40int strategy; /* 1 to 4 */41GEN bb; /* iterate through primes <= bb */42ulong c, q; /* congruent to c (mod q) */4344/* strategy 1: private prime table */45byteptr d; /* diffptr + n */46ulong p; /* current p = n-th prime */47ulong b; /* min(bb, ULONG_MAX) */4849/* strategy 2: sieve, use p */50struct pari_sieve *psieve;51unsigned char *sieve, *isieve;52ulong cache[9]; /* look-ahead primes already computed */53ulong chunk; /* # of odd integers in sieve */54ulong a, end, sieveb; /* [a,end] interval currently being sieved,55* end <= sieveb = min(bb, maxprime^2, ULONG_MAX) */56ulong pos, maxpos; /* current cell and max cell */5758/* strategy 3: unextprime, use p */5960/* strategy 4: nextprime */61GEN pp;62} forprime_t;6364typedef struct {65int first;66GEN b, n, p;67forprime_t T;68} forcomposite_t;6970typedef struct forvec_t {71long first;72GEN *a, *m, *M; /* current n-uplet, minima, Maxima */73long n; /* length */74GEN (*next)(struct forvec_t *);75} forvec_t;7677/* Iterate over partitions */78typedef struct79{80long k;81long amax, amin, nmin, nmax, strip;82GEN v;83} forpart_t;8485/* Iterate over permutations */86typedef struct87{88long k, first;89GEN v;90} forperm_t;9192/* Iterate over subsets */93typedef struct94{95long n, k, all, first;96GEN v;97} forsubset_t;9899/* Plot engines */100typedef struct PARI_plot {101void (*draw)(struct PARI_plot *T, GEN w, GEN x, GEN y);102long width;103long height;104long hunit;105long vunit;106long fwidth;107long fheight;108long dwidth;109long dheight;110} PARI_plot;111112/* binary I/O */113typedef struct GENbin {114size_t len; /* gsizeword(x) */115GEN x; /* binary copy of x */116GEN base; /* base address of p->x */117void (*rebase)(GEN,long);118} GENbin;119120struct pari_mainstack121{122pari_sp top, bot, vbot;123size_t size, rsize, vsize, memused;124};125126typedef struct pariFILE {127FILE *file;128int type;129const char *name;130struct pariFILE* prev;131struct pariFILE* next;132} pariFILE;133/* pariFILE.type */134enum { mf_IN = 1, mf_PIPE = 2, mf_FALSE = 4, mf_OUT = 8, mf_PERM = 16 };135136typedef struct entree {137const char *name;138ulong valence;139void *value;140long menu;141const char *code;142const char *help;143void *pvalue;144long arity;145ulong hash;146struct entree *next;147} entree;148149struct pari_parsestate150{151long node;152int once;153long discarded;154const char *lex_start;155GEN lasterror;156};157158struct pari_compilestate159{160long opcode, operand, accesslex, data, localvars, frames, dbginfo;161long offset, nblex;162const char *dbgstart;163};164165struct pari_mtstate166{167long pending_threads;168long is_thread;169long trace_level;170};171172struct pari_evalstate173{174pari_sp avma;175long sp;176long rp;177long var;178long lvars;179long locks;180long prec;181long trace;182struct pari_mtstate mt;183struct pari_compilestate comp;184};185186struct pari_varstate187{188long nvar, max_avail, min_priority, max_priority;189};190191struct pari_filestate192{193pariFILE *file;194long serial;195};196197struct gp_context198{199long listloc;200long prettyp;201struct pari_varstate var;202struct pari_evalstate eval;203struct pari_parsestate parse;204struct pari_filestate file;205jmp_buf *iferr_env;206GEN err_data;207};208209extern THREAD struct pari_mainstack *pari_mainstack;210211struct pari_global_state212{213long bitprec;214GEN primetab;215GEN seadata;216long *varpriority;217struct pari_varstate varstate;218};219220struct pari_thread221{222struct pari_mainstack st;223struct pari_global_state gs;224GEN data;225};226227struct mt_state228{229GEN worker;230GEN pending;231long workid;232};233234struct pari_mt235{236struct mt_state mt;237GEN (*get)(struct mt_state *mt, long *workid, long *pending);238void (*submit)(struct mt_state *mt, long workid, GEN work);239void (*end)(void);240};241242struct parfor_iter243{244long pending;245GEN worker;246struct pari_mt pt;247};248249typedef struct250{251GEN a, b;252struct parfor_iter iter;253} parfor_t;254255typedef struct256{257GEN x, W;258long i, l;259struct parfor_iter iter;260} parforeach_t;261262typedef struct263{264GEN v;265forprime_t forprime;266struct parfor_iter iter;267} parforprime_t;268269typedef struct270{271GEN v;272forvec_t forvec;273struct parfor_iter iter;274} parforvec_t;275276typedef struct PariOUT {277void (*putch)(char);278void (*puts)(const char*);279void (*flush)(void);280} PariOUT;281282/* hashtables */283typedef struct hashentry {284void *key, *val;285ulong hash; /* hash(key) */286struct hashentry *next;287} hashentry;288289typedef struct hashtable {290ulong len; /* table length */291hashentry **table; /* the table */292ulong nb, maxnb; /* number of entries stored and max nb before enlarging */293ulong pindex; /* prime index */294ulong (*hash) (void *k); /* hash function */295int (*eq) (void *k1, void *k2); /* equality test */296int use_stack; /* use stack_malloc instead of malloc ? */297} hashtable;298299typedef struct {300void **data;301long n;302long alloc;303size_t size;304} pari_stack;305306/* GP_DATA */307typedef struct {308GEN z; /* result */309time_t t; /* time to obtain result */310time_t r; /* realtime to obtain result */311} gp_hist_cell;312typedef struct {313gp_hist_cell *v; /* array of previous results, FIFO */314size_t size; /* # res */315ulong total; /* # of results computed since big bang */316} gp_hist; /* history */317318typedef struct {319pariFILE *file;320char *cmd;321} gp_pp; /* prettyprinter */322323typedef struct {324char *PATH;325char **dirs;326} gp_path; /* path */327typedef struct {328char format; /* e,f,g */329long sigd; /* -1 (all) or number of significant digits printed */330int sp; /* 0 = suppress whitespace from output */331int prettyp; /* output style: raw, prettyprint, etc */332int TeXstyle;333} pariout_t; /* output format */334335enum { gpd_QUIET=1, gpd_TEST=2, gpd_EMACS=256, gpd_TEXMACS=512};336enum { DO_MATCHED_INSERT = 2, DO_ARGS_COMPLETE = 4 };337typedef struct {338gp_hist *hist;339gp_pp *pp;340gp_path *path, *sopath;341pariout_t *fmt;342ulong lim_lines, flags, linewrap, readline_state, echo;343int breakloop, recover, use_readline;344char *help, *histfile, *prompt, *prompt_cont, *prompt_comment;345GEN colormap, graphcolors, plothsizes;346347int secure, simplify, strictmatch, strictargs, chrono;348pari_timer *T, *Tw;349ulong primelimit; /* deprecated */350ulong threadsizemax, threadsize;351} gp_data;352extern gp_data *GP_DATA;353354/* Common global variables: */355356extern PariOUT *pariOut, *pariErr;357extern FILE *pari_outfile, *pari_logfile, *pari_infile, *pari_errfile;358extern ulong pari_logstyle;359360enum pari_logstyles {361logstyle_none, /* 0 */362logstyle_plain, /* 1 */363logstyle_color, /* 2 */364logstyle_TeX /* 3 */365};366367enum { c_ERR, c_HIST, c_PROMPT, c_INPUT, c_OUTPUT, c_HELP, c_TIME, c_LAST,368c_NONE = 0xffffUL };369370enum { TEXSTYLE_PAREN=2, TEXSTYLE_BREAK=4 };371372extern THREAD pari_sp avma;373#define DISABLE_MEMUSED (size_t)-1374extern byteptr diffptr;375extern char *current_psfile, *pari_datadir;376377#define gcopyifstack(x,y) STMT_START {pari_sp _t=(pari_sp)(x); \378(y)=(_t>=pari_mainstack->bot &&_t<pari_mainstack->top)? \379gcopy((GEN)_t): (GEN)_t;} STMT_END380#define copyifstack(x,y) STMT_START {pari_sp _t=(pari_sp)(x); \381(y)=(_t>=pari_mainstack->bot &&_t<pari_mainstack->top)? \382gcopy((GEN)_t): (GEN)_t;} STMT_END383#define icopyifstack(x,y) STMT_START {pari_sp _t=(pari_sp)(x); \384(y)=(_t>=pari_mainstack->bot &&_t<pari_mainstack->top)? \385icopy((GEN)_t): (GEN)_t;} STMT_END386387/* Define this to thoroughly check "random" garbage collecting */388#ifdef DEBUG_LOWSTACK389# define low_stack(x,l) 1390# define gc_needed(av,n) 1391#else392# define low_stack(x,l) ((void)(x),avma < (pari_sp)(l))393# define gc_needed(av,n) (avma < (pari_sp)stack_lim(av,n))394#endif395396#define stack_lim(av,n) (pari_mainstack->bot+(((av)-pari_mainstack->bot)>>(n)))397398#ifndef SIG_IGN399# define SIG_IGN (void(*)())1400#endif401#ifndef SIGINT402# define SIGINT 2403#endif404405406