=================================================================== RCS file: /home/cvs/OpenXM_contrib2/asir2000/io/ox_asir.c,v retrieving revision 1.57 retrieving revision 1.68 diff -u -p -r1.57 -r1.68 --- OpenXM_contrib2/asir2000/io/ox_asir.c 2004/06/15 00:56:52 1.57 +++ OpenXM_contrib2/asir2000/io/ox_asir.c 2010/12/12 07:38:00 1.68 @@ -44,7 +44,7 @@ * OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. - * $OpenXM: OpenXM_contrib2/asir2000/io/ox_asir.c,v 1.56 2004/03/11 07:40:42 noro Exp $ + * $OpenXM: OpenXM_contrib2/asir2000/io/ox_asir.c,v 1.67 2010/04/23 04:44:52 noro Exp $ */ #include "ca.h" #include "parse.h" @@ -70,11 +70,13 @@ extern JMP_BUF ox_env; extern MATHCAP my_mathcap; extern int little_endian,ox_sock_id; +extern char LastError[]; +extern LIST LastStackTrace; int ox_sock_id; int lib_ox_need_conv; -void create_error(ERR *,unsigned int ,char *); +void create_error(ERR *,unsigned int ,char *,LIST trace); int asir_OperandStackSize; Obj *asir_OperandStack; @@ -106,6 +108,7 @@ char *name_of_id(int); static void asir_do_cmd(int,unsigned int); static void asir_executeFunction(int); +static void asir_executeFunctionSync(int); #if defined(MPI) /* XXX : currently MPI version supports only a homogeneous cluster. */ @@ -119,7 +122,7 @@ void ox_mpi_master_init() { /* ordering information is not exchanged */ /* idx should be equal to i */ idx = get_iofp(i,0,0); - register_server(0,idx,idx); + register_server(0,idx,idx,-1); } } @@ -132,7 +135,7 @@ void ox_mpi_slave_init() { /* ordering information is not exchanged */ /* idx should be equal to i */ idx = get_iofp(i,0,0); - register_server(0,idx,idx); + register_server(0,idx,idx,-1); } asir_OperandStackSize = BUFSIZ; asir_OperandStack = (Obj *)CALLOC(asir_OperandStackSize,sizeof(Obj)); @@ -147,7 +150,6 @@ void ox_main(int argc,char **argv) { ERR err; unsigned int serial; int ret; - extern char LastError[]; ox_asir_init(argc,argv,"ox_asir"); if ( do_message ) @@ -186,10 +188,11 @@ void ox_main(int argc,char **argv) { fprintf(stderr," %s\n",name_of_cmd(cmd)); if ( ret = SETJMP(main_env) ) { if ( ret == 1 ) { - create_error(&err,serial,LastError); + create_error(&err,serial,LastError,LastStackTrace); asir_push_one((Obj)err); while ( NEXT(asir_infile) ) closecurrentinput(); + resetpvs(); } break; } @@ -256,6 +259,9 @@ static void asir_do_cmd(int cmd,unsigned int serial) case SM_executeFunction: asir_executeFunction(serial); break; + case SM_executeFunctionSync: + asir_executeFunctionSync(serial); + break; case SM_shutdown: asir_terminate(2); break; @@ -386,6 +392,9 @@ char *name_of_cmd(int cmd) case SM_reduce_102: return "SM_reduce_102"; break; + case SM_executeFunctionSync: + return "SM_executeFunctionSync"; + break; default: return "Unknown cmd"; break; @@ -434,7 +443,7 @@ void asir_popCMO(unsigned int serial) if ( valid_as_cmo(obj) ) ox_send_data(0,obj); else { - create_error(&err,serial,"cannot convert to CMO object"); + create_error(&err,serial,"cannot convert to CMO object",0); ox_send_data(0,err); asir_push_one(obj); } @@ -460,7 +469,7 @@ void asir_reduce_102(unsigned int serial) else if ( !strcmp(opname,"*") ) func = arf_mul; if ( !func ) { - create_error(&err,serial,"Invalid opration in ox_reduce_102"); + create_error(&err,serial,"Invalid opration in ox_reduce_102",0); asir_push_one(obj); } else ox_reduce_102(root,func); @@ -513,7 +522,7 @@ void asir_set_rank_102(unsigned int serial) } if ( !stat ) return; else { - create_error(&err,serial,"Invalid argument(s) in ox_set_rank_102"); + create_error(&err,serial,"Invalid argument(s) in ox_set_rank_102",0); asir_push_one(obj); } } @@ -541,7 +550,7 @@ void asir_tcp_accept_102(unsigned int serial) rank = QTOS((Q)r); if ( register_102(s,rank,1) < 0 ) { create_error(&err,serial, - "failed to bind or accept in ox_tcp_accept_102"); + "failed to bind or accept in ox_tcp_accept_102",0); asir_push_one((Obj)err); } } @@ -573,7 +582,7 @@ void asir_tcp_connect_102(unsigned int serial) rank = QTOS((Q)r); if ( register_102(s,rank,1) < 0 ) { create_error(&err,serial, - "failed to connect in ox_tcp_connect_102"); + "failed to connect in ox_tcp_connect_102",0); asir_push_one((Obj)err); } } @@ -590,11 +599,19 @@ void asir_pushCMOtag(unsigned int serial) MKUSINT(ui,tag); asir_push_one((Obj)ui); } else { - create_error(&err,serial,"cannot convert to CMO object"); + create_error(&err,serial,"cannot convert to CMO object",0); asir_push_one((Obj)err); } } +void print_to_wfep(Obj obj) +{ + asir_push_one(obj); + asir_popString(); +} + +extern int wfep_mode; + void asir_popString() { Obj val; @@ -605,7 +622,10 @@ void asir_popString() val = asir_pop_one(); if ( !val ) buf = "0"; - else { + else if ( wfep_mode && OID(val) == O_ERR ) { + /* XXX : for wfep */ + ox_send_data(0,val); return; + } else { l = estimate_length(CO,val); buf = (char *)ALLOCA(l+1); soutput_init(buf); @@ -637,7 +657,7 @@ void asir_setName(unsigned int serial) parse_strp = (char *)ALLOCA(n); sprintf(parse_strp,"%s%s",name,dummy); if ( mainparse(&snode) ) { - create_error(&err,serial,"cannot set to variable"); + create_error(&err,serial,"cannot set to variable",0); asir_push_one((Obj)err); } else { FA1((FNODE)FA0(snode)) = (pointer)mkfnode(1,I_FORMULA,asir_pop_one()); @@ -659,7 +679,7 @@ void asir_evalName(unsigned int serial) parse_strp = (char *)ALLOCA(n); sprintf(parse_strp,"%s;",name); if ( mainparse(&snode) ) { - create_error(&err,serial,"no such variable"); + create_error(&err,serial,"no such variable",0); val = (pointer)err; } else val = evalstat(snode); @@ -696,7 +716,13 @@ int asir_executeString() # endif #endif cmd = ((STRING)asir_pop_one())->body; +/* XXX : probably this is useless */ +#if 0 parse_strp = augment_backslash(cmd); +#else + parse_strp = cmd; +#endif + asir_infile->ln = 1; if ( mainparse(&snode) ) { return -1; } @@ -749,6 +775,7 @@ static void asir_executeFunction(int serial) if ( n ) NEXT(n1) = 0; +#if 0 if ( !strcmp(func,"load") ) { fname = (STRING)BDY(n); if ( OID(fname) == O_STR ) { @@ -763,6 +790,7 @@ static void asir_executeFunction(int serial) } result = 0; } else { +#endif searchf(noargsysf,func,&f); if ( !f ) searchf(sysf,func,&f); @@ -776,16 +804,97 @@ static void asir_executeFunction(int serial) } else { result = (Obj)bevalf(f,n); } +#if 0 } +#endif + printf("executeFunction done\n"); asir_push_one(result); return; error: - create_error(&err,serial,buf); + create_error(&err,serial,buf,0); result = (Obj)err; asir_push_one(result); } +static void asir_executeFunctionSync(int serial) +{ + char *func; + int argc,i; + FUNC f; + Obj result=0; + NODE n,n1; + STRING fname; + char *path; + ERR err; + Obj arg; + static char buf[BUFSIZ]; + + arg = asir_pop_one(); + if ( !arg || OID(arg) != O_STR ) { + sprintf(buf,"executeFunction : invalid function name"); + goto error; + } else + func = ((STRING)arg)->body; + + arg = asir_pop_one(); + if ( !arg || OID(arg) != O_USINT ) { + sprintf(buf,"executeFunction : invalid argc"); + goto error; + } else + argc = (int)(((USINT)arg)->body); + + for ( n = 0; argc; argc-- ) { + NEXTNODE(n,n1); + BDY(n1) = (pointer)asir_pop_one(); + } + if ( n ) + NEXT(n1) = 0; + + ox_send_data(0,ONE); + +#if 0 + if ( !strcmp(func,"load") ) { + fname = (STRING)BDY(n); + if ( OID(fname) == O_STR ) { + searchasirpath(BDY(fname),&path); + if ( path ) { + if ( do_message ) + fprintf(stderr,"loading %s\n",path); + execasirfile(path); + } else + if ( do_message ) + fprintf(stderr,"load : %s not found in the search path\n",BDY(fname)); + } + result = 0; + } else { +#endif + searchf(noargsysf,func,&f); + if ( !f ) + searchf(sysf,func,&f); + if ( !f ) + searchf(ubinf,func,&f); + if ( !f ) + searchf(usrf,func,&f); + if ( !f ) { + sprintf(buf,"executeFunction : the function %s not found",func); + goto error; + } else { + result = (Obj)bevalf(f,n); + } +#if 0 + } +#endif + printf("executeFunctionSync done\n"); + ox_send_data(0,result); + return; + +error: + create_error(&err,serial,buf,0); + result = (Obj)err; + ox_send_data(0,result); +} + void asir_end_flush() { ox_flushing = 0; @@ -840,7 +949,6 @@ void ox_asir_init(int argc,char **argv,char *servernam { char ifname[BUFSIZ]; extern int GC_dont_gc; - extern int read_exec_file; extern int do_asirrc; extern int do_server_in_X11; extern char displayname[]; @@ -849,6 +957,7 @@ void ox_asir_init(int argc,char **argv,char *servernam FILE *ifp; char *homedir; char *ptr; + int do_server_sav; #if !defined(VISUAL) int tmp; #endif @@ -882,6 +991,7 @@ void ox_asir_init(int argc,char **argv,char *servernam pf_init(); sysf_init(); parif_init(); + order_init(); #if defined(VISUAL) init_socket(); #endif @@ -901,16 +1011,19 @@ void ox_asir_init(int argc,char **argv,char *servernam } sprintf(ifname,"%s/.asirrc",homedir); } + + /* the bottom of the input stack */ + input_init(0,"string"); + if ( do_asirrc && (ifp = fopen(ifname,"r")) ) { - input_init(ifp,ifname); - if ( !SETJMP(main_env) ) { - read_exec_file = 1; - read_eval_loop(); - read_exec_file = 0; - } fclose(ifp); + do_server_sav = do_server_in_X11; + do_server_in_X11 = 0; + if ( !SETJMP(main_env) ) + execasirfile(ifname); + do_server_in_X11 = do_server_sav; } - input_init(0,"string"); + /* XXX Windows compatibility */ ox_io_init(); create_my_mathcap(servername); @@ -968,7 +1081,7 @@ void ox_io_init() { read_char(iofp[0].in,&rc); iofp[0].conv = c == rc ? 0 : 1; /* XXX; for raw I/O */ - register_server(0,0,0); + register_server(0,0,0,-1); } #if !defined(VISUAL) @@ -1004,7 +1117,7 @@ int asir_ox_pop_cmo(void *cmo, int limit) obj = asir_pop_one(); if ( !valid_as_cmo(obj) ) { asir_push_one(obj); - create_error(&err,0,"The object at the stack top is invalid as a CMO."); + create_error(&err,0,"The object at the stack top is invalid as a CMO.",0); obj = (Obj)err; } len = count_as_cmo(obj); @@ -1053,7 +1166,7 @@ void asir_ox_push_cmd(int cmd) if ( ret = SETJMP(main_env) ) { asir_reset_handler(); if ( ret == 1 ) { - create_error(&err,0,LastError); /* XXX */ + create_error(&err,0,LastError,LastStackTrace); /* XXX */ asir_push_one((Obj)err); } } else { @@ -1080,7 +1193,7 @@ void asir_ox_execute_string(char *s) if ( ret = SETJMP(main_env) ) { asir_reset_handler(); if ( ret == 1 ) { - create_error(&err,0,LastError); /* XXX */ + create_error(&err,0,LastError,LastStackTrace); /* XXX */ asir_push_one((Obj)err); } } else { @@ -1135,7 +1248,6 @@ int asir_ox_init(int byteorder) int tmp; char ifname[BUFSIZ]; extern int GC_dont_gc; - extern int read_exec_file; extern int do_asirrc; extern int do_server_in_X11; char *getenv(); @@ -1172,17 +1284,13 @@ int asir_ox_init(int byteorder) #if defined(UINIT) reg_sysf(); #endif + input_init(0,"string"); sprintf(ifname,"%s/.asirrc",getenv("HOME")); if ( do_asirrc && (ifp = fopen(ifname,"r")) ) { - input_init(ifp,ifname); - if ( !SETJMP(main_env) ) { - read_exec_file = 1; - read_eval_loop(); - read_exec_file = 0; - } fclose(ifp); + if ( !SETJMP(main_env) ) + execasirfile(ifname); } - input_init(0,"string"); asir_OperandStackSize = BUFSIZ; asir_OperandStack = (Obj *)CALLOC(asir_OperandStackSize,sizeof(Obj));