specials.c
Go to the documentation of this file.
00001 /*****************************************************************
00002 /*      specials.c
00003 /*      special-forms (let,let*,catch,throw,unwind-protect,...)
00004 /*      control structures,
00005 /*      macros ...
00006 /*
00007 /*      Copyright: Toshihiro Matsui  ETL, Umezono, Sakura-mura
00008 /*        
00009 /*      1986
00010 /*      1986-Dec        let*
00011 /*      1987-Mar        special binding declaration
00012 *****************************************************************/
00013 static char *rcsid="@(#)$Id$";
00014 
00015 #include "eus.h"
00016 extern pointer MACRO,LAMBDA,LAMCLOSURE;
00017 extern pointer K_FUNCTION_DOCUMENTATION;
00018 extern struct bindframe  *declare();
00019 
00020 #ifdef EVAL_DEBUG
00021 extern int evaldebug;
00022 #endif
00023 
00024 /*gensym*/
00025 static pointer genhead;
00026 static int     genindex,tempindex=0;
00027 static pointer QRETFROM,QEVAL,QPROGN,QIF;
00028 
00029 /****************************************************************/
00030 /* special forms
00031 /****************************************************************/
00032 
00033 pointer quote(ctx,arg)
00034 register context *ctx;
00035 register pointer arg;
00036 {
00037 #ifdef SPEC_DEBUG
00038     printf( "quote:" ); hoge_print(arg);
00039 #endif
00040  return(carof(arg,E_MISMATCHARG));
00041 }
00042 
00043 pointer EVAL(ctx,n,argv)
00044 register context *ctx;
00045 int n;
00046 register pointer argv[];
00047 { pointer env;
00048   ckarg2(1,2);
00049   if (n==2) env=argv[1]; else env=NULL;
00050 #ifdef SPEC_DEBUG
00051   printf( "EVAL:" );
00052   hoge_print_sub(argv[0]);
00053   if( env != NULL )
00054     hoge_print_sub( env );
00055   printf( "\n" );
00056 #endif
00057   return(eval2(ctx,argv[0],env));}
00058 
00059 pointer PROGN(ctx,arg)
00060 register context *ctx;
00061 register pointer arg;
00062 {
00063 #ifdef SPEC_DEBUG
00064     printf( "PROGN:" ); hoge_print( arg );
00065 #endif
00066  return(progn(ctx,arg));}
00067 
00068 pointer PROG1(ctx,n,argv)
00069 register context *ctx;
00070 int n;
00071 pointer *argv;
00072 {
00073 #ifdef SPEC_DEBUG
00074     printf( "PROG1:" );
00075     if( n >= 0 ) hoge_print_sub( argv[0] );
00076     printf( "\n" );
00077 #endif
00078  return((n>=1)?argv[0]:NIL);}
00079 
00080 pointer APPLY(ctx,n,argv)
00081 register context *ctx;
00082 int n;
00083 register pointer argv[];
00084 { register pointer a,*spsave=ctx->vsp,fun=argv[0];
00085   register int i=1,argc=n-2;
00086 
00087   if (n<2) error(E_MISMATCHARG);
00088 #ifdef SPEC_DEBUG
00089   printf( "APPLY:" );
00090   { int i;
00091     for( i = 0; i < n; i++ )
00092       hoge_print_sub( argv[i] );
00093 }
00094   printf( "\n" );
00095 #endif
00096   if (issymbol(fun)) {
00097     if (fun->c.sym.spefunc==UNBOUND) error(E_UNDEF,argv[0]);}
00098   while (i<n-1) ckpush(argv[i++]);
00099   a=argv[i];
00100   while (islist(a)) {
00101     ckpush(ccar(a));
00102     a=ccdr(a);
00103     argc++;}
00104   a=(pointer)ufuncall(ctx,(ctx->callfp?ctx->callfp->form:NIL),
00105                         fun,(pointer)spsave,NULL,argc);
00106   ctx->vsp=spsave;
00107 #ifdef SAFETY
00108   take_care(a);
00109 #endif
00110   return(a);}
00111 
00112 pointer FUNCALL(ctx,n,argv)
00113 register context *ctx;
00114 int n;
00115 register pointer argv[];
00116 { register pointer fun=argv[0];
00117   if (n<1) error(E_MISMATCHARG);
00118 #if SPEC_DEBUG
00119   printf( "FUNCALL:" );
00120   {
00121       int i;
00122       for( i = 0; i < n; i++ )
00123         hoge_print_sub( argv[i] );
00124   }
00125   printf( "\n" );
00126 #endif
00127   if (issymbol(fun)) {
00128     if (fun->c.sym.spefunc==UNBOUND) error(E_UNDEF,fun);}
00129   pointer_update(Spevalof(QEVALHOOK),NIL);
00130   return((pointer)ufuncall(ctx,ctx->callfp->form,fun,(pointer)&argv[1],NULL,n-1));}
00131 
00132 pointer FUNCTION_CLOSURE(ctx,arg)
00133 register context *ctx;
00134 pointer arg;
00135 { pointer funcname;
00136   if (!islist(arg)) error(E_MISMATCHARG);
00137   if (ccdr(arg)!=NIL) error(E_MISMATCHARG);
00138 #ifdef SPEC_DEBUG
00139   printf( "FUNCTION_CLOSURE:" );
00140   hoge_print( arg );
00141 #endif
00142   arg=ccar(arg);
00143   if (issymbol(arg)) { funcname=arg; arg=getfunc(ctx,arg);}
00144   else funcname=NIL;
00145   if (iscode(arg)) return(arg);
00146   else if (ccar(arg)==LAMCLOSURE) return(arg);
00147   else if (ccar(arg)==LAMBDA) {
00148     arg=cons(ctx,makeint(hide_ptr((pointer)(ctx->fletfp))),ccdr(arg));
00149     arg=cons(ctx,makeint(hide_ptr((pointer)(ctx->bindfp))),arg);
00150     arg=cons(ctx,funcname,arg);
00151     return(cons(ctx,LAMCLOSURE,arg));}
00152   else error(E_ILLFUNC);}
00153 
00154 pointer MACEXPAND2(ctx,n,argv)
00155 register context *ctx;
00156 int n;
00157 register pointer argv[];
00158 { pointer mac,args,expander,*argp,result;
00159   int noarg=0;
00160   ckarg(1);
00161 #ifdef SPEC_DEBUG
00162   printf( "MACEXPAND2:" ); hoge_print( argv[0] );
00163 #endif
00164   if (!islist(argv[0])) return(argv[0]);
00165   mac=ccar(argv[0]); args=ccdr(argv[0]);
00166   if (issymbol(mac)) mac=getfunc(ctx,mac);
00167   if (iscode(mac)) {
00168 #if ARM
00169     eusinteger_t addr = (eusinteger_t)(mac->c.code.entry);
00170 #if (WORD_SIZE == 64)
00171     addr &= ~3L;  /*0xfffffffc; ???? */
00172 #else
00173     addr &= ~3;  /*0xfffffffc; ???? */
00174 #endif
00175 #if (WORD_SIZE == 64)
00176     addr = addr | (intval(mac->c.code.entry2)&0x00000000ffffffff);
00177 #else
00178     addr = addr | (intval(mac->c.code.entry2)&0x0000ffff);
00179 #endif
00180 #endif // ARM
00181     if (mac->c.code.subrtype!=(pointer)SUBR_MACRO) return(argv[0]);
00182 #if ARM
00183     expander=makecode(mac,(pointer (*)())addr,SUBR_FUNCTION);
00184     pointer_update(expander->c.code.entry2,mac->c.code.entry2)
00185 #else
00186     expander=makecode(mac,(pointer (*)())mac->c.code.entry,SUBR_FUNCTION);
00187 #endif
00188     pointer_update(expander->c.code.entry,mac->c.code.entry);}
00189   else if (carof(mac,E_NOLIST)==MACRO) expander=cons(ctx,LAMBDA,ccdr(mac));
00190   else return(argv[0]);
00191   vpush(expander);
00192   argp=ctx->vsp; 
00193   while (islist(args)) { vpush(ccar(args)); args=ccdr(args); noarg++;}
00194   GC_POINT;
00195   mac=ufuncall(ctx,ctx->callfp->form,expander,(pointer)argp,NULL,noarg);
00196   /* ???? ctx->lastalloc=mac; ????*/
00197   ctx->vsp=argp-1;
00198   return(mac);}
00199 
00200 /****************************************************************/
00201 /* mapping
00202 /****************************************************************/
00203 pointer MAPC(ctx,n,argv)
00204 register context *ctx;
00205 int n;
00206 register pointer *argv;
00207 { register pointer a;
00208   register int i;
00209   if (n<2) error(E_MISMATCHARG);
00210 #ifdef SPEC_DEBUG
00211   printf( "MAPC:" );
00212   { int i;
00213     for( i = 0; i < n; i++ )
00214       hoge_print_sub( argv[i] );
00215 }
00216   printf( "\n" );
00217 #endif
00218   while (islist(argv[1])) {
00219     i=1;
00220     while (i<n) {
00221       a=argv[i];
00222       if (!islist(a)) error(E_NOLIST);
00223       ckpush(ccar(a));
00224       argv[i]=ccdr(a);
00225       i++;}
00226     i--;
00227     GC_POINT;
00228     ufuncall(ctx,ctx->callfp->form,argv[0],(pointer)(ctx->vsp - i),NULL,i);
00229     ctx->vsp -= i;}
00230   return(argv[1]);}
00231 
00232 pointer MAPCAR(ctx,n,argv)
00233 register context *ctx;
00234 register int n;
00235 register pointer *argv;
00236 { register pointer a,r;
00237   register int rcount=0,i;
00238   pointer (*subr)();
00239 
00240   if (n<2) error(E_MISMATCHARG);
00241 #ifdef SPEC_DEBUG
00242   printf( "MAPCAR:" );
00243   { int i;
00244     for( i = 0; i < n; i++ )
00245       hoge_print_sub( argv[i] );
00246 }
00247   printf( "\n" );
00248 #endif
00249   while (islist(argv[1])) {
00250     i=1;
00251     while (i<n) {
00252       a=argv[i];
00253       if (!islist(a)) error(E_NOLIST);
00254       ckpush(ccar(a));
00255       argv[i]=ccdr(a);
00256       i++;}
00257     i--;
00258     GC_POINT;
00259     r=ufuncall(ctx,ctx->callfp->form,argv[0],(pointer)(ctx->vsp - i),NULL,i);
00260     ctx->vsp -=i;
00261     vpush(r);
00262     rcount++;}
00263     GC_POINT;
00264   r=(pointer)stacknlist(ctx,rcount);
00265   return(r);}
00266 
00267 pointer MAPCAN(ctx,n,argv)
00268 register context *ctx;
00269 int n;
00270 register pointer *argv;
00271 { register pointer a,r;
00272   register int i,rcount=0;
00273   pointer *spsave=ctx->vsp;
00274   if (n<2) error(E_MISMATCHARG);
00275 #ifdef SPEC_DEBUG
00276   printf( "MAPCAN:" );
00277   { int i;
00278     for( i = 0; i < n; i++ )
00279       hoge_print_sub( argv[i] );
00280 }
00281   printf( "\n" );
00282 #endif
00283   while (islist(argv[1])) {
00284     i=1;
00285     while (i<n) {
00286       a=argv[i];
00287       if (!islist(a)) error(E_NOLIST);
00288       ckpush(ccar(a));
00289       argv[i]=ccdr(a);
00290       i++;}
00291     i--;
00292     GC_POINT;
00293     r=ufuncall(ctx,ctx->callfp->form,argv[0],(pointer)(ctx->vsp -i),NULL,i);
00294     ctx->vsp -=i;
00295     vpush(r);
00296     rcount++;}
00297     GC_POINT;
00298   a=(pointer)NCONC(ctx,rcount,spsave);
00299   ctx->vsp=spsave;
00300   return(a);}
00301 
00302 /****************************************************************/
00303 /* SETQ
00304 /****************************************************************/
00305 pointer SETQ(ctx,arg)
00306 register context *ctx;
00307 register pointer arg;
00308 { register pointer var,val=NIL, *p;
00309 #ifdef SPEC_DEBUG
00310   printf( "SETQ:" );  hoge_print( arg );
00311 #endif
00312   while (iscons(arg)) {
00313     var=ccar(arg); arg=ccdr(arg);
00314     if (!islist(arg)) error(E_MISMATCHARG);
00315     GC_POINT;
00316     val=eval(ctx,ccar(arg)); arg=ccdr(arg);
00317     if (issymbol(var)) setval(ctx,var,val);
00318     else if (islist(var) && issymbol(ccdr(var)) && ccdr(var)!=NIL) {
00319       vpush(val);
00320       p=(pointer *)ovafptr(eval(ctx,ccar(var)),ccdr(var)); pointer_update(*p,vpop());}
00321     else error(E_NOSYMBOL,var);}
00322   return(val);}
00323 
00324 
00325 /****************************************************************/
00326 /* control structures
00327 /****************************************************************/
00328 
00329 pointer IF(ctx,arg)
00330 register context *ctx;
00331 register pointer arg;
00332 { register pointer rest;
00333   rest=cdrof(arg, E_MISMATCHARG);
00334   if (!iscons(rest)) return(NIL);
00335 #ifdef SPEC_DEBUG
00336   printf( "IF:" ); hoge_print( arg );
00337 #endif
00338   GC_POINT;
00339   if (eval(ctx,ccar(arg))!=NIL) return(eval(ctx,ccar(rest)));
00340   else {
00341     rest=ccdr(rest);
00342     if (iscons(rest)) return(eval(ctx,ccar(rest)));
00343     else return(NIL);  } }
00344 
00345 pointer WHEN(ctx,n,argv)
00346 register context *ctx;
00347 int n;
00348 pointer *argv;
00349 { pointer form=NIL;
00350   int i;
00351   if (n<1) error(E_MISMATCHARG);
00352 #ifdef SPEC_DEBUG
00353   printf( "WHEN:" );
00354   { int i;
00355     for( i = 0; i < n; i++ )
00356       hoge_print_sub( argv[i] );
00357 }
00358   printf( "\n" );
00359 #endif
00360   while (n>1) form=cons(ctx,argv[--n],form);
00361   form=cons(ctx,QPROGN,form);
00362   form=cons(ctx,argv[0],cons(ctx,form,NIL));
00363   return(cons(ctx,QIF,form));}
00364 
00365 pointer WHILE(ctx,arg)
00366 register context *ctx;
00367 pointer arg;
00368 { pointer cond,body,*spsave=ctx->vsp,result;
00369   struct blockframe *myblock;
00370   struct bindframe *bfp=ctx->bindfp;
00371   jmp_buf whilejmp;
00372   int i;
00373 
00374 #ifdef SPEC_DEBUG
00375   printf( "WHILE:" );   hoge_print(arg);
00376 #endif
00377   if (!islist(arg)) return(NIL);
00378   cond=ccar(arg); body=ccdr(arg);
00379   myblock=(struct blockframe *)
00380                 makeblock(ctx,BLOCKFRAME,NIL,&whilejmp,ctx->blkfp); /* ???? */
00381   if ((result=(pointer)eussetjmp(whilejmp))==0) {
00382     while (eval(ctx,cond)!=NIL) {GC_POINT;progn(ctx,body);}
00383     result=NIL;}
00384   else if ((eusinteger_t)result==1) result=makeint(0);
00385   ctx->blkfp=myblock->dynklink;
00386   ctx->vsp=spsave;
00387   ctx->bindfp=bfp;
00388   return(result);}
00389 
00390 pointer COND(ctx,arg)
00391 register context *ctx;
00392 pointer arg;
00393 { register pointer clause,cond;
00394 
00395 #ifdef SPEC_DEBUG
00396   printf( "COND:" );    hoge_print(arg);
00397 #endif
00398   while (islist(arg)) {
00399     clause=ccar(arg);
00400     if (!islist(clause)) error(E_NOLIST);
00401     GC_POINT;
00402     cond=eval(ctx,ccar(clause));
00403     if (cond!=NIL) if (islist(ccdr(clause))) return(progn(ctx,ccdr(clause)));
00404                    else return(cond);
00405     arg=ccdr(arg);}
00406   return(NIL);}
00407 
00408 pointer PARLET(ctx,args)        /*let special form*/
00409 register context *ctx;
00410 pointer args;
00411 { pointer vlist,vlistsave,var,init,body,result,decl,*spsave=ctx->vsp,*vinits;
00412   register struct bindframe *env, *bfsave=ctx->bindfp, *declenv;
00413   struct specialbindframe *sbfps=ctx->sbindfp;
00414   int i=0,vcount=0;
00415 #if defined(PARLET_DEBUG) || defined(DEBUG_COUNT)
00416   static int count = 0;
00417 
00418   count++;
00419 #endif
00420 
00421 #if defined(SPEC_DEBUG) || defined(PARLET_DEBUG)
00422   printf( "PARLET:%d",count );  hoge_print(args);
00423 #endif
00424 
00425   vlist=carof(args,E_MISMATCHARG);
00426   body=ccdr(args);
00427   env=bfsave;
00428 
00429   /*declaration*/
00430   while (islist(body)) {
00431     decl=ccar(body);
00432     if (!islist(decl) || (ccar(decl)!=QDECLARE)) break;
00433     env=declare(ctx,ccdr(decl),env);    /*add special decl. to current env*/
00434     body=ccdr(body);}
00435 
00436   GC_POINT;
00437   /*evaluate variable initializers*/
00438   vlistsave=vlist;
00439   vinits=ctx->vsp;
00440   while (islist(vlist)) {
00441     var=ccar(vlist); vlist=ccdr(vlist);
00442     if (islist(var)) {
00443       init=ccdr(var); var=ccar(var);
00444       if (islist(init)) init=eval(ctx,ccar(init));
00445       else init=NIL;}
00446     else init=NIL;
00447     vpush(init); vcount++;}
00448   /*update bindings at once*/
00449   GC_POINT;
00450   vlist=vlistsave;
00451   while (i<vcount)  {
00452     var=ccar(vlist); vlist=ccdr(vlist);
00453     if (islist(var)) var=ccar(var);
00454     env=vbind(ctx,var,vinits[i++],env,bfsave);}
00455 
00456   result=progn(ctx,body);       /*evaluate body*/
00457   ctx->bindfp=bfsave;           /*restore environments*/
00458   ctx->vsp=spsave;
00459   unbindspecial(ctx,(struct specialbindframe *)ctx->vsp);
00460   /* unbindspecial(ctx,sbfps+1); */
00461   return(result);}
00462 
00463 pointer SEQLET(ctx,args)        /* let* special form*/
00464 register context *ctx;
00465 pointer args;
00466 { pointer vlist,var,init,body,result,decl,*spsave=ctx->vsp;
00467   register struct bindframe *bf=ctx->bindfp, *env;
00468   struct specialbindframe *sbfps=ctx->sbindfp;
00469 
00470 #ifdef SPEC_DEBUG
00471   printf( "SEQLET:" );  hoge_print(args);
00472 #endif
00473 
00474   GC_POINT;
00475   vlist=carof(args,E_MISMATCHARG);
00476   body=ccdr(args);
00477   env=bf;       /*inherit lexical variable scope*/
00478 
00479   /*declaration*/
00480   while (islist(body)) {
00481     decl=ccar(body);
00482     if (!islist(decl) || (ccar(decl)!=QDECLARE)) break;
00483     env=declare(ctx,ccdr(decl),env);
00484     body=ccdr(body);}
00485 
00486   /*bind let* variables*/
00487   while (islist(vlist)) {
00488     GC_POINT;
00489     var=ccar(vlist); vlist=ccdr(vlist);
00490     if (islist(var)) {
00491       init=ccdr(var); var=ccar(var);
00492       if (islist(init)) init=eval(ctx,ccar(init));
00493       else init=NIL;}
00494     else init=NIL;
00495     env=vbind(ctx,var,init,env,bf);
00496     }
00497 
00498   /*evaluate body*/
00499   result=progn(ctx,body);
00500   /*restore environments*/
00501   ctx->bindfp=bf;
00502   ctx->vsp=spsave;
00503   unbindspecial(ctx,(struct specialbindframe *)ctx->vsp); 
00504 /*  unbindspecial(ctx,sbfps+1); */
00505   return(result);}
00506 
00507 pointer CATCH(ctx,arg)  /*special form*/
00508 register context *ctx;
00509 pointer arg;
00510 { pointer tag,body,val;
00511   jmp_buf catchbuf;
00512   int i;
00513 
00514 #ifdef SPEC_DEBUG
00515   printf( "CATCH:" );   hoge_print(arg);
00516 #endif
00517 
00518   tag=carof(arg,E_MISMATCHARG); tag=eval(ctx,tag);
00519   body=ccdr(arg);
00520   mkcatchframe(ctx,tag,&catchbuf);
00521   if ((val=(pointer)eussetjmp(catchbuf))==0) val=progn(ctx,body);
00522   else if ((eusinteger_t)val==1) val=makeint(0);        /*longjmp cannot return 0*/
00523   ctx->callfp=ctx->catchfp->cf;
00524   ctx->bindfp=ctx->catchfp->bf;
00525   ctx->fletfp=ctx->catchfp->ff;
00526   ctx->vsp=(pointer *)ctx->catchfp;
00527   ctx->catchfp=(struct catchframe *)*ctx->vsp;
00528 #ifdef __RETURN_BARRIER
00529   check_return_barrier(ctx);
00530 #endif
00531   return(val);}
00532 
00533 void throw(ctx,tag,result)
00534 register context *ctx;
00535 register pointer tag,result;
00536 { register struct catchframe *cfp=ctx->catchfp;
00537   while (cfp!=NULL) 
00538     if (cfp->label==tag) {
00539       ctx->catchfp=cfp;
00540       unwind(ctx,(pointer *)ctx->catchfp);
00541       euslongjmp(*(ctx->catchfp->jbp),result);}
00542     else cfp=cfp->nextcatch;}
00543 
00544 pointer THROW(ctx,arg)
00545 register context *ctx;
00546 register pointer arg;
00547 {
00548   pointer tag,result;
00549 #ifdef SPEC_DEBUG
00550   printf( "THROW:" ); hoge_print(arg);
00551 #endif
00552   tag=carof(arg,E_MISMATCHARG);
00553   arg=ccdr(arg);
00554   result=carof(arg,E_MISMATCHARG);
00555   GC_POINT;
00556   tag=eval(ctx,tag); 
00557   GC_POINT;
00558   result=eval(ctx,result);
00559   throw(ctx,tag,result);
00560   error(E_NOCATCHER,tag);}
00561 
00562 pointer FLET(ctx,arg)
00563 register context *ctx;
00564 register pointer arg;
00565 { register pointer fns, fn;
00566   register struct fletframe *ffp=ctx->fletfp;
00567   pointer result;
00568 #ifdef SPEC_DEBUG
00569   printf( "FLET:" ); hoge_print(arg);
00570 #endif
00571   GC_POINT;
00572   fns=ccar(arg);
00573   while (iscons(fns)) {
00574     fn=ccar(fns); fns=ccdr(fns);
00575     makeflet(ctx,ccar(fn),ccdr(fn),ffp,ctx->fletfp);}
00576   result=progn(ctx,ccdr(arg));
00577   ctx->fletfp=ffp;
00578   return(result);}
00579 
00580 pointer LABELS(ctx,arg)
00581 register context *ctx;
00582 register pointer arg;
00583 { register pointer fns, fn;
00584   register struct fletframe *ffp=ctx->fletfp, *ffpp;
00585   pointer result;
00586 #ifdef SPEC_DEBUG
00587   printf( "LABELS:" ); hoge_print(arg);
00588 #endif
00589   GC_POINT;
00590   fns=ccar(arg);
00591   while (iscons(fns)) {
00592     fn=ccar(fns); fns=ccdr(fns);
00593     makeflet(ctx,ccar(fn),ccdr(fn),ctx->fletfp,ctx->fletfp);}
00594   fns=ccar(arg); ffpp=ctx->fletfp;
00595   while (iscons(fns)) { /*allow mutual references between labels functions*/
00596     fn=ffpp->fclosure;
00597     fn=ccdr(fn); fn=ccdr(fn); fn=ccdr(fn); ccar(fn)=makeint(hide_ptr((pointer)(ctx->fletfp)));
00598     fns=ccdr(fns); ffpp=ffpp->lexlink;}
00599   result=progn(ctx,ccdr(arg));
00600   ctx->fletfp=ffp;
00601   return(result);}
00602 
00603 pointer RESET(ctx,n,argv)
00604 register context *ctx;
00605 int n;
00606 pointer *argv;
00607 {
00608 #ifdef SPEC_DEBUG
00609   printf( "RESET:" );
00610   { int i;
00611     for( i = 0; i < n; i++ )
00612       hoge_print_sub(argv[i] );
00613 }
00614   printf( "\n" );
00615 #endif
00616  throw(ctx,makeint(0),T);
00617   error(E_USER,(pointer)"cannot reset");}
00618 
00619 pointer EVALHOOK(ctx,n,argv)
00620 register context *ctx;
00621 int n;
00622 pointer *argv;
00623 { pointer form,val,env, *vspsave=ctx->vsp;
00624   struct specialbindframe *sbfps=ctx->sbindfp;
00625 
00626   ckarg2(2,3);
00627 #ifdef SPEC_DEBUG
00628   printf( "EVALHOOK:" );
00629   { int i;
00630     for( i = 0; i < n; i++ )
00631       hoge_print_sub(argv[i] );
00632 }
00633   printf( "\n" );
00634 #endif
00635   if (n==3) env=argv[2]; else env=NULL;
00636   form=argv[0];
00637   GC_POINT;
00638   if (islist(form)) {
00639     ehbypass=1;
00640     bindspecial(ctx,QEVALHOOK,argv[1]);
00641     val=eval2(ctx,form,env);
00642     unbindspecial(ctx,(struct specialbindframe *)vspsave);
00643 /*    unbindspecial(ctx,sbfps+1); */
00644     return(val);}
00645   else return(eval2(ctx,form,env));}
00646 
00647 pointer BLOCK(ctx,arg)  /*special form*/
00648 register context *ctx;
00649 register pointer arg;           /*must be called via ufuncall*/
00650 { pointer name,result,*spsave=ctx->vsp;
00651   struct blockframe *myblock;
00652   struct bindframe *bfp=ctx->bindfp;
00653   jmp_buf blkjmp;
00654 #ifdef SPEC_DEBUG
00655   printf( "BLOCK:" ); hoge_print(arg);
00656 #endif
00657 
00658   GC_POINT;
00659   name=carof(arg,E_MISMATCHARG); arg=ccdr(arg);
00660   if (!issymbol(name)) error(E_NOSYMBOL);
00661   myblock=(struct blockframe *)makeblock(ctx,BLOCKFRAME,name,&blkjmp,ctx->blkfp); /* ???? */
00662   if ((result=(pointer)eussetjmp(blkjmp))==0) result=progn(ctx,arg);
00663   else if ((eusinteger_t)result==1) result=makeint(0);
00664   ctx->blkfp=myblock->dynklink;
00665   /*restorations of bindfp and callfp are caller's responsibility???*/
00666   ctx->bindfp=bfp;
00667   ctx->vsp=spsave;
00668   return(result);}
00669 
00670 pointer RETFROM(ctx,arg)        /*special-form*/
00671 register context *ctx;
00672 pointer arg;
00673 { pointer name,result;
00674  struct blockframe *blkfp_old, *blkfp_new; 
00675 #ifdef SPEC_DEBUG
00676   printf( "RETFROM:" ); hoge_print(arg);
00677 #endif
00678   GC_POINT;
00679   name=carof(arg,E_MISMATCHARG); arg=ccdr(arg);
00680   blkfp_old = ctx->blkfp;
00681   while (ctx->blkfp!=NULL) 
00682     if (ctx->blkfp->kind==BLOCKFRAME && ctx->blkfp->name==name) {
00683       blkfp_new = ctx->blkfp;
00684       ctx->blkfp = blkfp_old;
00685       if (islist(arg)) result=eval(ctx,ccar(arg)); else result=NIL;
00686       if (result==makeint(0)) result=(pointer)1;
00687       ctx->blkfp = blkfp_new;
00688       unwind(ctx,(pointer *)ctx->blkfp);
00689       euslongjmp(*ctx->blkfp->jbp,result);}
00690     else ctx->blkfp=ctx->blkfp->lexklink;
00691   error(E_NOBLOCK);}
00692   
00693 pointer RETURN(ctx,n,argv)
00694 register context *ctx;
00695 int n;
00696 pointer argv[];
00697 { pointer result=NIL;
00698   if (n==1) result=argv[0];
00699   if (n>1) error(E_MISMATCHARG);
00700 #ifdef SPEC_DEBUG
00701   printf( "RETURN:" ); hoge_print(result);
00702 #endif
00703   return(cons(ctx,QRETFROM,cons(ctx,NIL,cons(ctx,result,NIL))));}
00704 
00705 pointer UNWINDPROTECT(ctx,arg)
00706 register context *ctx;
00707 pointer arg;
00708 { pointer *spsave=ctx->vsp;
00709   struct protectframe *oldprotfp=ctx->protfp;
00710   pointer protform,cleanupform,cleaner,result;
00711 
00712   if (!islist(arg)) error(E_NOLIST);
00713 #ifdef SPEC_DEBUG
00714   printf( "UNWINDPROTECT:" );   hoge_print(arg);
00715 #endif
00716   GC_POINT;
00717   protform=ccar(arg);
00718   if (islist(arg)) cleanupform=ccdr(arg); else cleanupform=NIL;
00719   cleaner=cons(ctx,NIL,cleanupform);
00720   cleaner=cons(ctx,makeint(hide_ptr((pointer)(ctx->fletfp))),cleaner);
00721   cleaner=cons(ctx,makeint(hide_ptr((pointer)(ctx->bindfp))),cleaner);
00722   cleaner=cons(ctx,NIL,cleaner);
00723   cleaner=cons(ctx,LAMCLOSURE,cleaner);
00724   /*(LAMDA-CLOSURE bindfp fletfp () . body) */
00725   /*bug...blocks and special variable bindings are not saved*/
00726   vpush(ctx->protfp); vpush(cleaner);
00727   ctx->protfp=(struct protectframe *)spsave;
00728   GC_POINT;
00729   result=eval(ctx,protform);
00730   ctx->vsp=spsave;
00731   ctx->protfp=oldprotfp;
00732   progn(ctx,cleanupform);
00733   return(result);
00734 }
00735 
00736 pointer TAGBODY(ctx,arg)
00737 register context *ctx;
00738 pointer arg;
00739 { pointer p,golist=NIL,forms;
00740   jmp_buf tagjmp;
00741   struct blockframe *tagblock;
00742   pointer *spsave=ctx->vsp, *tagspsave;
00743   struct bindframe *bfpsave=ctx->bindfp;
00744 #ifdef SPEC_DEBUG
00745   printf( "TAGBODY:" ); hoge_print(arg);
00746 #endif
00747   GC_POINT;
00748   p=forms=arg;
00749   while (iscons(p)) {
00750     if (!iscons(ccar(p))) golist=cons(ctx,p,golist);
00751     p=ccdr(p);}
00752   tagblock=(struct blockframe *)
00753         makeblock(ctx,TAGBODYFRAME,golist,&tagjmp,ctx->blkfp); /* ???? */
00754   tagspsave=ctx->vsp;
00755 repeat:
00756   if ((p=(pointer)eussetjmp(tagjmp))==0) 
00757     {
00758     ctx->vsp=tagspsave;
00759     ctx->bindfp=bfpsave;
00760     while (iscons(forms)) {
00761       GC_POINT;
00762       p=ccar(forms);
00763       if (iscons(p)) eval(ctx,p);
00764       forms=ccdr(forms);} }
00765   else { forms=ccdr(p); goto repeat;}
00766   ctx->blkfp=tagblock->dynklink;
00767   ctx->vsp=spsave;
00768   return(NIL);}
00769 
00770 pointer GO(ctx,arg)
00771 register context *ctx;
00772 pointer arg;
00773 { pointer tag,body;
00774 #ifdef SPEC_DEBUG
00775   printf( "GO:" ); hoge_print( arg );
00776 #endif
00777   tag=carof(arg,"GO TAG?");
00778   while (ctx->blkfp!=NULL) {
00779     if (ctx->blkfp->kind==TAGBODYFRAME &&
00780         (body=(pointer)assq(tag,ctx->blkfp->name))!=NIL) {
00781       unwind(ctx,(pointer *)ctx->blkfp);
00782       euslongjmp(*(ctx->blkfp->jbp),body);}/* ???? */
00783       /* euslongjmp(*(ctx->blkfp->jbp),body);} *//* ??? eus_rbar */
00784     ctx->blkfp=ctx->blkfp->lexklink;}
00785   error(E_USER,(pointer)"go tag not found");}
00786 
00787 pointer EVALWHEN(ctx,arg)
00788 register context *ctx;
00789 pointer arg;
00790 { pointer situation,forms;
00791 #ifdef SPEC_DEBUG
00792   printf( "EVALWHEN:" ); hoge_print( arg );
00793 #endif
00794   situation=carof(arg,E_MISMATCHARG); forms=ccdr(arg);
00795   while (islist(situation)) 
00796     if (ccar(situation)==QEVAL) return(progn(ctx,forms));
00797     else situation=ccdr(situation);
00798   return(NIL);}
00799 
00800 pointer THE(ctx,arg)
00801 register context *ctx;
00802 pointer arg;
00803 { pointer typeid,form,result;
00804 #ifdef SPEC_DEBUG
00805   printf( "THE:" ); hoge_print( arg );
00806 #endif
00807   typeid=carof(arg,E_MISMATCHARG); arg=ccdr(arg);
00808   form=carof(arg,E_MISMATCHARG);
00809   if (islist(ccdr(arg))) error(E_MISMATCHARG);
00810   GC_POINT;
00811   result=eval(ctx,form);
00812   if (typeid==QINTEGER || typeid==QFIXNUM)
00813     if (!isint(result)) error(E_NOINT);
00814     else return(result);
00815   else if (typeid==QFLOAT)
00816     if (!isflt(result)) error(E_NONUMBER);
00817     else return(result);
00818   else if (typeid==QNUMBER)
00819     if (!isnum(result)) error(E_NONUMBER);
00820     else return(result);
00821   else {
00822     if (isnum(result)) error(E_NOOBJECT);
00823     if (speval(typeid)!=classof(result)) error(E_TYPEMISMATCH);
00824     else return(result);} }
00825 
00826 pointer AND(ctx,arg)    /*special form (should be macro)*/
00827 register context *ctx;
00828 register pointer arg;
00829 { register pointer r;
00830 #ifdef SPEC_DEBUG
00831   printf( "AND:" ); hoge_print( arg );
00832 #endif
00833   while (islist(arg)) {
00834     GC_POINT;
00835     if ((r=eval(ctx,ccar(arg)))==NIL) return(r);
00836     arg=ccdr(arg); }
00837   return(r);}
00838 
00839 pointer OR(ctx,arg)     /*special form (should be macro)*/
00840 register context *ctx;
00841 register pointer arg;
00842 { register pointer r;
00843 #ifdef SPEC_DEBUG
00844   printf( "OR:" );      hoge_print( arg );
00845 #endif
00846   while (islist(arg)) {
00847     GC_POINT;
00848     if ((r=eval(ctx,ccar(arg)))!=NIL) return(r);
00849     arg=ccdr(arg);    }
00850   return(NIL);}
00851 
00852 pointer PROCLAIM(ctx,n,argv)
00853 register context *ctx;
00854 int n;
00855 pointer argv[];
00856 { pointer decl,var,curval;
00857   int i=0,vt;
00858 #ifdef SPEC_DEBUG
00859   printf( "PROCLAIM:" );
00860   { int i;
00861     for( i = 0; i < n; i++ )
00862       hoge_print_sub( argv[i] );}
00863   printf( "\n" );
00864 #endif
00865   GC_POINT;
00866   while (i<n) {
00867     decl=argv[i++];
00868     if (!islist(decl)) error(E_DECLFORM);
00869     if (ccar(decl)==QSPECIAL) {
00870       decl=ccdr(decl);
00871       while (islist(decl)) {
00872         var=ccar(decl); decl=ccdr(decl);
00873         if (!issymbol(var)) error(E_NOSYMBOL);
00874         if (var->c.sym.vtype==V_CONSTANT) error(E_SETCONST);
00875         else if (var->c.sym.vtype>=V_SPECIAL) {
00876           if (debug)
00877              fprintf(stderr, "%s has already been declared as special\n",
00878                         var->c.sym.pname->c.str.chars);}
00879         else {
00880           /*first time to change to a special var*/
00881           curval=speval(var);
00882           var->c.sym.vtype=makeint(special_index());
00883           vt=intval(var->c.sym.vtype);
00884           ctx->specials->c.vec.v[vt]=curval;}
00885         /*V_SPECIAL*/}
00886       } } 
00887   return(NIL);}
00888 
00889 pointer DECLARE(arg)
00890 pointer arg;
00891 { error(E_DECLARE); }           /*just ignore when interpretting*/
00892 
00893 /****************************************************************/
00894 /* package
00895 /****************************************************************/
00896 pointer ALLPACKAGES(ctx,n,argv)
00897 register context *ctx;
00898 int n;
00899 pointer argv[];
00900 { ckarg(0);
00901 #ifdef SPEC_DEBUG
00902   printf( "ALLPACKAGES:\n" );
00903 #endif
00904  return(pkglist);}
00905 
00906 pointer FINDPACKAGE(ctx,n,argv)
00907 register context *ctx;
00908 int n;
00909 register pointer *argv;
00910 { pointer pkg;
00911   ckarg(1);
00912 #ifdef SPEC_DEBUG
00913   printf( "FINDPACKAGE:" ); hoge_print( argv[0] );
00914 #endif
00915   pkg=findpkg(argv[0]);
00916   if (pkg) return(pkg); else return(NIL);}
00917 
00918 pointer MAKEPACKAGE(ctx,n,argv)
00919 register context *ctx;
00920 int n;
00921 pointer *argv;
00922 { pointer pkg,name,nick,use;
00923   int i=0;
00924   ckarg2(1,3);
00925 #ifdef SPEC_DEBUG
00926   printf( "MAKEPACKAGE:" );
00927   { int i;
00928     for( i = 0; i < n; i++ )
00929       hoge_print_sub( argv[i] );
00930 }
00931 #endif
00932   name=argv[0];
00933   if (n>1) nick=argv[1]; else nick=NIL;
00934   if (n>2) use=argv[2]; else use=NIL;
00935   pkg=makepkg(ctx,name,nick,use);       /*pkg is protected from gc in pkglist*/
00936   return(pkg);}
00937 
00938 eusinteger_t sxhash(x)
00939 pointer x;
00940 { 
00941   eusinteger_t h=0;
00942   int s,i;
00943   numunion nu;
00944 
00945   if (isstring(x)) return(rehash(x));
00946   else if (issymbol(x)) return(rehash(x->c.sym.pname));
00947   else if (isint(x)) return(intval(x));
00948   else if (isflt(x)) {
00949     nu.fval=fltval(x);  return(nu.ival);}
00950   else if (islist(x)) {
00951     while (islist(x)) { h += sxhash(ccar(x)); x=ccdr(x);}}
00952   else if (isvector(x)) {
00953     s=vecsize(x);
00954     switch( elmtypeof(x)) {
00955       case ELM_BIT:  s /= 8*sizeof(pointer); break;
00956       case ELM_CHAR:
00957       case ELM_BYTE: s /= sizeof(pointer); break;
00958       case ELM_POINTER: 
00959         for (i=0; i<s; i++) h += sxhash(x->c.vec.v[i]);
00960         return(h);}
00961     for (i=0; i<s; i++) h += x->c.ivec.iv[i]; } 
00962   else {  h=(eusinteger_t)x >> 2;}
00963   return(h);}  
00964 
00965 
00966 pointer SXHASH(ctx,n,argv)
00967 register context *ctx;
00968 int n;
00969 pointer argv[];
00970 { pointer h;
00971   eusinteger_t m;
00972   if (n==1) m=(eusinteger_t)1  << (WORD_SIZE-3);
00973   else if (n==2) m=ckintval(argv[1]);
00974   else error(E_MISMATCHARG);
00975 #ifdef SPEC_DEBUG
00976   printf( "SXHASH:" );
00977   { int i;
00978     for( i = 0; i < n; i++ )
00979       hoge_print_sub( argv[i] );
00980 }
00981   printf( "\n" );
00982 #endif
00983   m=(sxhash(argv[0]) & MAXPOSFIXNUM) % m;
00984   return(makeint(m));}
00985 
00986 /****************************************************************/
00987 /* symbol attributes
00988 /****************************************************************/
00989 pointer SYMVALUE(ctx,n,argv)
00990 register context *ctx;
00991 int n;
00992 register pointer argv[];
00993 { register pointer sy=argv[0],val;
00994   ckarg(1);
00995   if (!issymbol(sy)) error(E_NOSYMBOL);
00996   val=speval(sy);
00997   if (val==UNBOUND) error(E_UNBOUND,sy);
00998 #ifdef SPEC_DEBUG
00999   printf( "SYMVALUE:" );
01000   { int i;
01001     for( i =0; i < n; i++ )
01002       hoge_print_sub(argv[i] );
01003 }
01004   printf( "\n" );
01005 #endif
01006   return(val);}
01007 
01008 pointer SYMBNDVALUE(ctx,n,argv)
01009 register context *ctx;
01010 int n;
01011 register pointer argv[];
01012 { register pointer sy=argv[0],val;
01013   ckarg(1);
01014   if (!issymbol(sy)) error(E_NOSYMBOL);
01015   val=SPEVALOF(sy);
01016   if (val==UNBOUND) error(E_UNBOUND,sy);
01017   return(val);}
01018 
01019 pointer SETFUNC(ctx,n,argv)
01020 register context *ctx;
01021 int n;
01022 register pointer *argv;
01023 { if (n!=2) error(E_MISMATCHARG);
01024   if (!issymbol(argv[0])) error(E_NOSYMBOL);
01025 #ifdef SPEC_DEBUG
01026   printf( "SETFUNC:" ); hoge_print_sub(argv[0]); hoge_print(argv[1]);
01027 #endif
01028   setfunc(argv[0],argv[1]);
01029   return(argv[1]);}
01030 
01031 pointer SYMFUNC(ctx,n,argv)
01032 register context *ctx;
01033 int n;
01034 pointer *argv;
01035 { ckarg(1);
01036   if (!issymbol(argv[0])) error(E_NOSYMBOL);
01037 #ifdef SPEC_DEBUG
01038   printf( "SYMFUNC:" ); hoge_print( argv[0] );
01039 #endif
01040   return(getfunc(ctx,argv[0]));}
01041 
01042 pointer MAKUNBOUND(ctx,n,argv)
01043 register context *ctx;
01044 int n;
01045 pointer *argv;
01046 { ckarg(1);
01047   if (!issymbol(argv[0])) error(E_NOSYMBOL);
01048 #ifdef SPEC_DEBUG
01049   printf( "MAKEUNBOUND:" ); hoge_print( argv[0] );
01050 #endif
01051   pointer_update(argv[0]->c.sym.speval,UNBOUND);
01052   return(T);}
01053 
01054 void set_special(ctx, var, val)
01055 context *ctx;
01056 pointer var, val;
01057 { pointer vt;
01058   int x;
01059   vt=var->c.sym.vtype;
01060   if (vt==V_CONSTANT) error(E_SETCONST);
01061   else if (vt==V_VARIABLE || vt==V_GLOBAL) {pointer_update(speval(var),val);}
01062   else {
01063     x=intval(vt);
01064     pointer_update(ctx->specials->c.vec.v[x],val);} }
01065 
01066 pointer SETSPECIAL(ctx,n,argv)
01067 context *ctx;
01068 int n;
01069 pointer *argv;
01070 { pointer var, val;
01071   ckarg(2);
01072   var=argv[0]; val=argv[1];
01073   if (!issymbol(var)) error(E_NOSYMBOL);
01074 #ifdef SPEC_DEBUG
01075   printf( "SETSPECIAL:" ); hoge_print_sub(var); hoge_print(val);
01076 #endif
01077   set_special(ctx, var, val);
01078   return(val);}
01079 
01080 pointer DEFUN(ctx,arg)
01081 register context *ctx;
01082 pointer arg;
01083 { pointer funcname;
01084   extern pointer putprop();
01085 #ifdef SPEC_DEBUG
01086   printf( "DEFUN:" ); hoge_print( arg );
01087 #endif
01088   funcname=carof(arg,E_MISMATCHARG);
01089   arg=ccdr(arg);
01090   if (issymbol(funcname)) {pointer_update(funcname->c.sym.spefunc,cons(ctx,LAMBDA,arg));}
01091   else error(E_NOSYMBOL);
01092   putprop(ctx,funcname,
01093          (isstring(ccar(ccdr(arg))))?(ccar(ccdr(arg))):(ccar(arg)),
01094          K_FUNCTION_DOCUMENTATION);
01095   return(funcname);}
01096  
01097 pointer DEFMACRO(ctx,arg)
01098 register context *ctx;
01099 pointer arg;
01100 { pointer macname;
01101 #ifdef SPEC_DEBUG
01102   printf("DEFMACRO:" ); hoge_print(arg);
01103 #endif
01104   macname=carof(arg,E_MISMATCHARG);
01105   arg=ccdr(arg);
01106   if (issymbol(macname)) {pointer_update(macname->c.sym.spefunc,cons(ctx,MACRO,arg));}
01107   else error(E_NOSYMBOL);
01108   return(macname);}
01109 
01110 pointer FINDSYMBOL(ctx,n,argv)
01111 register context *ctx;
01112 int n;
01113 pointer argv[];
01114 { pointer str,sym,pkg;
01115   ckarg2(1,2);
01116   str=argv[0];
01117   if (n==2) {
01118     pkg=findpkg(argv[1]);
01119     if (pkg==NULL)  error(E_NOPACKAGE);}
01120   else pkg=Spevalof(PACKAGE);
01121   if (!ispackage(pkg)) error(E_NOPACKAGE);
01122   if (!isstring(str)) error(E_NOSTRING);
01123 #ifdef SPEC_DEBUG
01124   printf( "FINDSYMBOL:" );
01125   { int i;
01126     for( i = 0; i < n; i++ )
01127       hoge_print_sub( argv[i] );
01128 }
01129   printf( "\n" );
01130 #endif
01131   sym=(pointer)findsymbol(str->c.str.chars,intval(str->c.str.length),
01132                           pkg->c.pkg.intsymvector,&n);
01133   if (sym) return(sym);
01134   else return(NIL);}
01135 
01136 pointer INTERN(ctx,n,argv)
01137 register context *ctx;
01138 int n;
01139 register pointer argv[];
01140 { register pointer str,sym,pkg;
01141   int x;
01142   ckarg2(1,3);
01143   str=argv[0];
01144   if (n>=2) pkg=findpkg(argv[1]);
01145   else pkg=Spevalof(PACKAGE);
01146   if (!isstring(str)) error(E_NOSTRING);
01147 #ifdef SPEC_DEBUG
01148   printf( "INTERN:" );
01149   { int i;
01150     for( i = 0; i < n; i++ )
01151       hoge_print_sub( argv[i] );
01152 }
01153   printf( "\n" );
01154 #endif
01155   return((pointer)intern(ctx,(char *)str->c.str.chars, strlength(str),pkg));}
01156 
01157 pointer gensym(ctx)
01158 register context *ctx;
01159 { byte buf[64];
01160   sprintf((char *)buf,"%s%d",genhead->c.str.chars,genindex++);
01161   return(makesymbol(ctx,(char *)buf,strlen(buf),NIL));}
01162 
01163 pointer GENSYM(ctx,n,argv)
01164 register context *ctx;
01165 int n;
01166 pointer argv[];
01167 { 
01168 #ifdef SPEC_DEBUG
01169     printf( "GENSYM:" );
01170     { int i;
01171       for( i =0 ; i<n; i++ )
01172         hoge_print_sub(argv[i] );
01173   }
01174     printf( "\n" );
01175 #endif
01176 
01177     if (n==1) {
01178     n--;
01179     if (isstring(argv[0])) {
01180       if (intval(argv[0]->c.str.length)>50) error(E_LONGSTRING);
01181       genhead=argv[0];}
01182     else if (isint(argv[0])) genindex=intval(argv[0]);
01183     else error(E_NOSTRING);
01184     }
01185   ckarg(0);
01186   return(gensym(ctx));}
01187 
01188 pointer GETPROP(ctx,n,argv)
01189 register context *ctx;
01190 int n;
01191 register pointer argv[];
01192 { register pointer p,attr=argv[1];
01193   ckarg2(2,3);
01194   if (!ispropobj(argv[0]) || !ispropobj(attr)) error(E_NOSYMBOL);
01195 #ifdef SPEC_DEBUG
01196   printf( "GETPROP:" );
01197   { int i;
01198     for( i = 0; i < n; i++ )
01199       hoge_print_sub(argv[i] );
01200 }
01201   printf( "\n" );
01202 #endif
01203   p=argv[0]->c.sym.plist;
01204   while (iscons(p))
01205     if (ccar(ccar(p))==attr) return(ccdr(ccar(p)));
01206     else p=ccdr(p);
01207   if (n==3) return(argv[2]); else return(NIL);}
01208 
01209 pointer EXPORT (ctx,n,argv)     /*further name conflict checks should be
01210                                   performed by EusLisp*/
01211 register context *ctx;
01212 int n;
01213 register pointer argv[];
01214 { pointer sym, pkg;
01215   ckarg2(1,2);
01216 #ifdef SPEC_DEBUG
01217   printf( "EXPORT:" );
01218   { int i;
01219     for( i =0; i< n; i++ )
01220       hoge_print_sub(argv[i]);
01221 }
01222   printf( "\n" );
01223 #endif
01224   sym=argv[0];
01225   if (n==2)  pkg = findpkg(argv[1]);
01226   else pkg=Spevalof(PACKAGE);
01227   if (!ispackage(pkg)) error(E_NOPACKAGE);
01228   if (issymbol(sym)) export(sym,pkg);
01229   else if (iscons(sym)) 
01230     while (iscons(sym)) {
01231       export(ccar(sym),pkg); sym=ccdr(sym);}
01232   else error(E_NOSYMBOL);
01233   return(T);}
01234 
01235 pointer putprop(ctx,sym,val,attr)
01236 register context *ctx;
01237 register pointer sym,val,attr;
01238 { register pointer p;
01239   p=sym->c.sym.plist;
01240   while (iscons(p))
01241     if (ccar(ccar(p))==attr) { pointer_update(ccdr(ccar(p)),val); return(val);}
01242     else p=ccdr(p);
01243   /* no such a property; create it */
01244   p=cons(ctx,attr,val);
01245   pointer_update(sym->c.sym.plist,cons(ctx,p,sym->c.sym.plist));
01246   return(val);}
01247 
01248 pointer PUTPROP(ctx,n,argv)     /*(putprop sym val attr)*/
01249 register context *ctx;
01250 int n;
01251 register pointer argv[];
01252 { register pointer p,pp;
01253   ckarg(3);
01254   if (!ispropobj(argv[0]) || !ispropobj(argv[2])) error(E_NOSYMBOL);
01255 #ifdef SPEC_DEBUG
01256   printf( "PUTPROP:" );
01257   { int i;
01258     for( i =0 ; i < n; i++ )
01259       hoge_print_sub(argv[i]);
01260 }
01261   printf( "\n" );
01262 #endif
01263   return(putprop(ctx,argv[0],argv[1],argv[2]));}
01264 
01265 #ifdef EVAL_DEBUG
01266 pointer EVALDEBUG(ctx,n,argv)
01267 register context *ctx;
01268 int n;
01269 register pointer argv[];
01270 {
01271     ckarg2(0,1);
01272     if( n == 1 ) {
01273         evaldebug = ( argv[0] != NIL );
01274     }
01275     return evaldebug ? T : NIL;
01276 }
01277 #endif
01278 
01279 
01280 
01281 /****************************************************************/
01282 /* initialize
01283 /****************************************************************/
01284 void specials(ctx,mod)
01285 register context *ctx;
01286 pointer mod;
01287 {
01288   genindex=0;
01289   genhead=makestring("G",1);
01290   sysobj=cons(ctx,genhead,sysobj);
01291 
01292   QUOTE=defspecial(ctx,"QUOTE",mod,quote);
01293   QEVAL=defun(ctx,"EVAL",mod,EVAL,NULL);
01294   defun(ctx,"APPLY",mod,APPLY,NULL);
01295   defun(ctx,"FUNCALL",mod,FUNCALL,NULL);
01296   QPROGN=defspecial(ctx,"PROGN",mod,progn);
01297   defun(ctx,"PROG1",mod,PROG1,NULL);
01298   FUNCTION=defspecial(ctx,"FUNCTION",mod,FUNCTION_CLOSURE);
01299   defun(ctx,"MAPC",mod,MAPC,NULL);
01300   defun(ctx,"MAPCAR",mod,MAPCAR,NULL);
01301   defun(ctx,"MAPCAN",mod,MAPCAN,NULL);
01302   defspecial(ctx,"SETQ",mod,SETQ);
01303   QIF=defspecial(ctx,"IF",mod,IF);
01304   defmacro(ctx,"WHEN",mod,WHEN);
01305   defspecial(ctx,"COND",mod,COND);
01306   defspecial(ctx,"WHILE",mod,WHILE);
01307   defspecial(ctx,"LET",mod,PARLET);
01308   defspecial(ctx,"LET*",mod,SEQLET);
01309   defspecial(ctx,"UNWIND-PROTECT",mod,UNWINDPROTECT);
01310   defspecial(ctx,"CATCH",mod,CATCH);
01311   defspecial(ctx,"THROW",mod,THROW);
01312   defspecial(ctx,"FLET",mod,FLET);
01313   defspecial(ctx,"LABELS",mod,LABELS);
01314   defspecial(ctx,"BLOCK",mod,BLOCK);
01315   QRETFROM=defspecial(ctx,"RETURN-FROM",mod,RETFROM);
01316   defmacro(ctx,"RETURN",mod,RETURN);
01317   defspecial(ctx,"TAGBODY",mod,TAGBODY);
01318   defspecial(ctx,"GO",mod,GO);
01319   defun(ctx,"RESET",mod,RESET,NULL);
01320   defun(ctx,"EVALHOOK",mod,EVALHOOK,NULL);
01321   defun(ctx,"MACROEXPAND2",mod,MACEXPAND2,NULL);
01322   defspecial(ctx,"EVAL-WHEN",mod,EVALWHEN);
01323   defspecial(ctx,"THE",mod,THE);
01324   QAND=defspecial(ctx,"AND",mod,AND);
01325   QOR=defspecial(ctx,"OR",mod,OR);
01326   defun(ctx,"PROCLAIM",mod,PROCLAIM,NULL);
01327   defspecial(ctx,"DECLARE",mod,DECLARE);
01328   defun(ctx,"SETFUNC",mod,SETFUNC,NULL);
01329   defun(ctx,"SYMBOL-VALUE",mod,SYMVALUE,NULL);
01330   defun(ctx,"SYMBOL-BOUND-VALUE",mod,SYMBNDVALUE,NULL);
01331   defun(ctx,"SYMBOL-FUNCTION",mod,SYMFUNC,NULL);
01332   defun(ctx,"MAKUNBOUND",mod,MAKUNBOUND,NULL);
01333   defun(ctx,"SET",mod,SETSPECIAL,NULL);
01334   defspecial(ctx,"DEFUN",mod,DEFUN);
01335   defspecial(ctx,"DEFMACRO",mod,DEFMACRO);
01336   defun(ctx,"FIND-SYMBOL",mod,FINDSYMBOL,NULL);
01337   defun(ctx,"INTERN",mod,INTERN,NULL);
01338   defun(ctx,"GENSYM",mod,GENSYM,NULL);
01339   defun(ctx,"LIST-ALL-PACKAGES",mod,ALLPACKAGES,NULL);
01340   defun(ctx,"FIND-PACKAGE",mod,FINDPACKAGE,NULL);
01341   defunpkg(ctx,"MAKEPACKAGE",mod,MAKEPACKAGE,syspkg);
01342 /*  defun(ctx,"IN-PACKAGE",mod,INPACKAGE,NULL); */
01343   defun(ctx,"SXHASH",mod,SXHASH,NULL);
01344   defun(ctx,"GET",mod,GETPROP,NULL);
01345   defun(ctx,"EXPORT",mod,EXPORT,NULL);
01346   defun(ctx,"PUTPROP",mod,PUTPROP,NULL);
01347 
01348 #ifdef EVAL_DEBUG
01349   defun(ctx,"EVALDEBUG",mod,EVALDEBUG,NULL);
01350 #endif
01351   }
01352 
01353 


euslisp
Author(s): Toshihiro Matsui
autogenerated on Thu Jun 6 2019 18:05:53