Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

Testing latest pari + WASM + node.js... and it works?! Wow.

28495 views
License: GPL3
ubuntu2004
1
#include <stdio.h>
2
#include <pari/pari.h>
3
#include <readline/readline.h>
4
#include <readline/history.h>
5
#include <setjmp.h>
6
7
jmp_buf env;
8
9
int gp_is_interactive(void) { return pari_infile == stdin; }
10
void gp_err_recover(long numerr) { longjmp(env, numerr); }
11
void gp_quit(long exitcode) { exit(exitcode); }
12
13
entree functions_gp[]={
14
{"quit",0,(void*)gp_quit,11,"vD0,L,","quit({status = 0}): quit, return to the system with exit status 'status'."},
15
{NULL,0,NULL,0,NULL,NULL}};
16
17
#define col(a) term_get_color(NULL, a)
18
19
int main(int argc, char **argv)
20
{
21
pari_init(8000000,500000);
22
pari_add_module(functions_gp);
23
cb_pari_err_recover = gp_err_recover;
24
cb_pari_is_interactive = gp_is_interactive;
25
cb_pari_quit = gp_quit;
26
sd_colors("lightbg",d_INITRC);
27
gp_load_gprc();
28
pari_print_version();
29
(void)setjmp(env);
30
while(1)
31
{
32
GEN z;
33
const char *prompt = gp_format_prompt(GP_DATA->prompt);
34
char *in = readline(prompt);
35
pari_timer T, Tw;
36
long time, rtime;
37
38
if (!in) break;
39
if (!*in) continue;
40
41
add_history(in);
42
gp_echo_and_log(prompt,in);
43
timer_start(&T); walltimer_start(&Tw);
44
z = gp_read_str(in);
45
time = timer_delay(&T); rtime = walltimer_delay(&Tw);
46
pari_add_hist(z, time, rtime);
47
if (z != gnil && in[strlen(in)-1] != ';')
48
{
49
pari_printf("%s%%%lu = %s",col(c_HIST),pari_nb_hist(),col(c_OUTPUT));
50
output(z);
51
pari_puts(col(c_NONE));
52
}
53
if (GP_DATA->chrono && time)
54
{
55
if (pari_mt_nbthreads==1)
56
pari_printf("time = %s.\n", gp_format_time(time));
57
else
58
pari_printf("cpu time = %s, real time = %s.\n",
59
gp_format_time(time), gp_format_time(rtime));
60
}
61
free(in); avma = pari_mainstack->top;
62
}
63
return 0;
64
}
65
66