version 1.24, 2015/08/16 03:12:09 |
version 1.29, 2015/08/19 05:29:23 |
|
|
/* $OpenXM: OpenXM_contrib2/asir2000/builtin/parif.c,v 1.23 2015/08/07 08:00:30 takayama Exp $ */ |
/* $OpenXM: OpenXM_contrib2/asir2000/builtin/parif.c,v 1.28 2015/08/18 05:35:17 noro Exp $ */ |
#include "ca.h" |
#include "ca.h" |
#include "parse.h" |
#include "parse.h" |
#include "ox.h" |
#include "ox.h" |
|
|
Q ox_pari_stream; |
Q ox_pari_stream; |
int ox_pari_stream_initialized = 0; |
int ox_pari_stream_initialized = 0; |
|
int ox_get_pari_result = 0; |
|
|
typedef void (*mpfr_func)(NODE,Obj *); |
typedef void (*mpfr_func)(NODE,Obj *); |
|
|
Line 48 mpfr_func mpfr_search(char *name) |
|
Line 49 mpfr_func mpfr_search(char *name) |
|
return 0; |
return 0; |
} |
} |
|
|
|
Obj list_to_vect(Obj a) |
|
{ |
|
int len,i; |
|
VECT v; |
|
NODE nd; |
|
|
|
if ( !a || OID(a) != O_LIST ) return a; |
|
len = length(BDY((LIST)a)); |
|
MKVECT(v,len); |
|
for ( i = 0, nd = BDY((LIST)a); nd; nd = NEXT(nd), i++ ) |
|
v->body[i] = (pointer)list_to_vect((Obj)BDY(nd)); |
|
return (Obj)v; |
|
} |
|
|
|
void reset_ox_pari() |
|
{ |
|
NODE nd; |
|
Obj r; |
|
|
|
if ( ox_get_pari_result ) { |
|
nd = mknode(1,ox_pari_stream); |
|
Pox_shutdown(nd,&r); |
|
ox_get_pari_result = 0; |
|
ox_pari_stream_initialized = 0; |
|
} |
|
} |
|
|
pointer evalparif(FUNC f,NODE arg) |
pointer evalparif(FUNC f,NODE arg) |
{ |
{ |
int ac,intarg,opt,prec; |
int ac,intarg,opt,prec; |
Q q,r,narg; |
Q q,r,narg; |
NODE nd,oxarg; |
NODE nd,oxarg,t,t1,n; |
STRING name; |
STRING name; |
USINT ui; |
USINT ui; |
Obj ret,dmy; |
Obj ret,dmy; |
Line 64 pointer evalparif(FUNC f,NODE arg) |
|
Line 92 pointer evalparif(FUNC f,NODE arg) |
|
} |
} |
|
|
if ( !ox_pari_stream_initialized ) { |
if ( !ox_pari_stream_initialized ) { |
MKSTR(name,"ox_pari"); |
MKSTR(name,"ox_pari"); |
nd = mknode(2,NULL,name); |
nd = mknode(2,NULL,name); |
Pox_launch(nd,&r); |
Pox_launch_nox(nd,&r); |
ox_pari_stream = r; |
ox_pari_stream = r; |
ox_pari_stream_initialized = 1; |
ox_pari_stream_initialized = 1; |
} |
} |
switch ( f->type ) { |
|
case 0: /* in/out : integer */ |
|
ac = argc(arg); |
|
if ( ac > 1 ) { |
|
fprintf(stderr,"argument mismatch in %s()\n",NAME(f)); |
|
error(""); |
|
/* NOTREACHED */ |
|
return 0; |
|
} |
|
intarg = ac == 0 ? 0 : QTOS((Q)ARG0(arg)); |
|
MKUSINT(ui,intarg); |
|
oxarg = mknode(2,ox_pari_stream,ui); |
|
Pox_push_cmo(oxarg,&dmy); |
|
MKSTR(name,f->name); |
|
oxarg = mknode(3,ox_pari_stream,name,ONE); |
|
Pox_execute_function(oxarg,&dmy); |
|
oxarg = mknode(1,ox_pari_stream); |
|
Pox_pop_cmo(oxarg,&r); |
|
return r; |
|
|
|
case 1: |
ac = argc(arg); |
ac = argc(arg); |
/* reverse the arg list */ |
if ( !ac || ( ac > 2 ) ) { |
for ( n = arg, t = 0; n; n = NEXT(n) ) { |
fprintf(stderr,"argument mismatch in %s()\n",NAME(f)); |
MKNODE(t1,BDY(n),t); t = t1; |
error(""); |
} |
/* NOTREACHED */ |
/* push the reversed arg list */ |
return 0; |
for ( ; t; t = NEXT(t) ) { |
} |
oxarg = mknode(2,ox_pari_stream,BDY(t)); |
/* arg1 : prec */ |
Pox_push_cmo(oxarg,&dmy); |
prec = ac == 1 ? 0 : QTOS((Q)ARG1(arg)); |
} |
MKUSINT(ui,prec); |
MKSTR(name,f->name); |
oxarg = mknode(2,ox_pari_stream,ui); |
STOQ(ac,narg); |
Pox_push_cmo(oxarg,&dmy); |
oxarg = mknode(3,ox_pari_stream,name,narg); |
|
Pox_execute_function(oxarg,&dmy); |
/* arg0 : arg */ |
oxarg = mknode(1,ox_pari_stream); |
oxarg = mknode(2,ox_pari_stream,ARG0(arg)); |
ox_get_pari_result = 1; |
Pox_push_cmo(oxarg,&dmy); |
Pox_pop_cmo(oxarg,&ret); |
|
ox_get_pari_result = 0; |
MKSTR(name,f->name); |
if ( ret && OID(ret) == O_LIST ) |
STOQ(2,narg); |
ret = list_to_vect(ret); |
oxarg = mknode(3,ox_pari_stream,name,narg); |
return ret; |
Pox_execute_function(oxarg,&dmy); |
|
oxarg = mknode(1,ox_pari_stream); |
|
Pox_pop_cmo(oxarg,&r); |
|
return r; |
|
|
|
case 2: |
|
ac = argc(arg); |
|
if ( !ac || ( ac > 2 ) ) { |
|
fprintf(stderr,"argument mismatch in %s()\n",NAME(f)); |
|
error(""); |
|
/* NOTREACHED */ |
|
return 0; |
|
} |
|
if ( ac == 1 ) |
|
opt = 0; |
|
else |
|
opt = QTOS((Q)ARG1(arg)); |
|
return r; |
|
|
|
default: |
|
error("evalparif : not implemented yet."); |
|
/* NOTREACHED */ |
|
return 0; |
|
} |
|
} |
} |
|
|
struct pariftab { |
struct pariftab { |