[BACK]Return to primitive.c CVS log [TXT][DIR] Up to [local] / OpenXM / src / kan96xx / Kan

Annotation of OpenXM/src/kan96xx/Kan/primitive.c, Revision 1.16

1.16    ! takayama    1: /* $OpenXM: OpenXM/src/kan96xx/Kan/primitive.c,v 1.15 2004/09/12 10:22:50 takayama Exp $ */
1.1       maekawa     2: /*   primitive.c */
                      3: /*  The functions in this module were in stackmachine.c */
                      4:
                      5: #include <stdio.h>
1.5       takayama    6: #include <signal.h>
1.1       maekawa     7: #include "datatype.h"
                      8: #include "stackm.h"
                      9: #include "extern.h"
                     10: #include "gradedset.h"
                     11: #include "kclass.h"
                     12: #include <sys/types.h>
                     13: #include <sys/times.h>
                     14:
                     15: int PrintDollar = 1;         /* flag for printObject() */
                     16: int PrintComma  = 1;         /* flag for printObject() */
1.10      takayama   17: int InSendmsg2 = 0;
1.1       maekawa    18: #define OB_ARRAY_MAX   (AGLIMIT+100)
                     19:
                     20: extern int GotoP;
                     21: extern char *GotoLabel;
                     22: extern int Osp;
                     23: extern int Sdp;
                     24: extern int ClassTypes[];   /* kclass.c */
                     25: extern struct context *PrimitiveContextp;
                     26: extern struct context *CurrentContextp;
                     27: extern struct dictionary *SystemDictionary;
1.8       takayama   28: extern int QuoteMode;
1.1       maekawa    29:
                     30: static char *operatorType(int i);
                     31:
                     32: static char *operatorType(type)
1.4       takayama   33:      int type;
1.1       maekawa    34: { int i;
1.4       takayama   35:  for (i=0; i<Sdp; i++) {
                     36:    if (type == (SystemDictionary[i]).obj.lc.ival) {
                     37:      return((SystemDictionary[i]).key);
                     38:    }
                     39:  }
                     40:  return("Unknown operator");
1.1       maekawa    41: }
                     42:
1.16    ! takayama   43: #define evalEA(ob1) if (ob1.tag == SexecutableArray) {\
        !            44:          executeExecutableArray(ob1,(char *)NULL,0); ob1 = Kpop();}
        !            45:
1.1       maekawa    46: /****** primitive functions *****************************************
                     47:   the values must be greater than 1. 0 is used for special purposes.*/
                     48: #define Sadd              1
                     49: #define Ssub              2
                     50: #define Smult             3
                     51: #define Sset_up_ring      4
                     52: #define Soptions          6
                     53: #define Sgroebner       7
                     54: #define Sdef              8
                     55: #define Spop              9
                     56: #define Sput              10
                     57: #define Sprint            11
                     58: #define Spstack           12
                     59: #define Sshow_ring        13
                     60: #define Sshow_systemdictionary 15
                     61: #define Slength            16
                     62: #define Sfor               17
                     63: #define Sroll              18
                     64: #define Squit              19
                     65: #define Stest              20      /* this is used for test of new function*/
                     66: #define Sfileopen      23
                     67: #define Sclosefile 24
                     68: #define Sidiv      25
                     69: #define Sdup       26
                     70: #define Smap       27
                     71: #define Sreduction 28
                     72: #define Sreplace 29
                     73: #define SleftBrace 30       /* primitive [ */
                     74: #define SrightBrace 31      /* primitive ] */
                     75: #define Srun 32            /* run from a file */
                     76: #define Sloop 33
                     77: #define Saload 34
                     78: #define Sifelse 35
                     79: #define Sequal 36
                     80: #define Sexec 37
                     81: #define Sset 38
                     82: #define Sget 41
                     83: #define Scopy 43
                     84: #define Sindex 44
                     85: #define Ssystem 45
                     86: #define Sset_order_by_matrix 50
                     87: #define Sshow_user_dictionary 54
                     88: #define Selimination_order 55
                     89: #define Sswitch_function 58
                     90: #define Sprint_switch_status 59
                     91: #define Scat_n 62
                     92: #define Sless  63
                     93: #define Sgreater  64
                     94: #define Swritestring  66
                     95: #define Sset_timer 67
                     96: #define Sspol 68
                     97: #define Susage 69
                     98: #define Sto_records 70
                     99: #define Scoefficients 71
                    100: #define Ssystem_variable 72
                    101: #define Sdata_conversion 73
                    102: #define Sdegree 74
                    103: #define Sinit 75
                    104: #define Sload 76
                    105: #define Seval 77
                    106: #define Shomogenize 78
                    107: #define Sprincipal 79
                    108: #define Spushfile 80
                    109: #define Sdiv 81
                    110: #define Sgoto 82
                    111: #define Sextension 83
                    112: #define Snewstack 84
                    113: #define Ssetstack 85
                    114: #define Sstdstack 86
                    115: #define Slc 87
                    116: #define Src 88
                    117: #define Sgbext 89
                    118: #define Snewcontext 90
                    119: #define Ssetcontext 91
                    120: #define Ssupercontext 92
                    121: #define Ssendmsg 93
                    122: #define Serror 94
                    123: #define Smpzext 95
                    124: #define Ssendmsg2 96
                    125: #define Sprimmsg 97
                    126: #define Ssupmsg2 98
                    127: #define Scclass 99
                    128: #define Scoeff2 100
1.5       takayama  129: #define Stlimit 101
1.9       takayama  130: #define Soxshell 102
1.1       maekawa   131: /***********************************************/
                    132: void printObject(ob,nl,fp)
1.4       takayama  133:      struct object ob;
                    134:      int nl;
                    135:      FILE *fp;
                    136:      /* print the object on the top of the stack. */
1.1       maekawa   137: {
                    138:
                    139:   int size;
                    140:   int i;
                    141:   struct tokens *ta;
                    142:
                    143:   if (VerboseStack >= 2) {
                    144:     /*fprintf(fp,"@@@");*/
                    145:     switch (ob.tag) {
                    146:     case 0:
                    147:       fprintf(fp,"<null> "); /* null object */
                    148:       break;
                    149:     case Sinteger:
                    150:       fprintf(fp,"<integer> ");
                    151:       break;
                    152:     case Sstring:
                    153:       fprintf(fp,"<literal-string> ");
                    154:       break;
                    155:     case Soperator:
                    156:       fprintf(fp,"<operator> ");
                    157:       break;
                    158:     case Sdollar:
                    159:       fprintf(fp,"<string(dollar)> ");
                    160:       break;
                    161:     case SexecutableArray:
                    162:       fprintf(fp,"<executable array> ");
                    163:       break;
                    164:     case Sarray:
                    165:       fprintf(fp,"<array> ");
                    166:       break;
                    167:     case SleftBraceTag:
                    168:       fprintf(fp,"<leftBraceTag> ");
                    169:       break;
                    170:     case SrightBraceTag:
                    171:       fprintf(fp,"<rightBraceTag> ");
                    172:       break;
                    173:     case Spoly:
                    174:       fprintf(fp,"<poly> ");
                    175:       break;
                    176:     case SarrayOfPOLY:
                    177:       fprintf(fp,"<arrayOfPOLY> ");
                    178:       break;
                    179:     case SmatrixOfPOLY:
                    180:       fprintf(fp,"<matrixOfPOLY> ");
                    181:       break;
                    182:     case Slist:
                    183:       fprintf(fp,"<list> ");
                    184:       break;
                    185:     case Sfile:
                    186:       fprintf(fp,"<file> ");
                    187:       break;
                    188:     case Sring:
                    189:       fprintf(fp,"<ring> ");
                    190:       break;
                    191:     case SuniversalNumber:
                    192:       fprintf(fp,"<universalNumber> ");
                    193:       break;
                    194:     case Sclass:
                    195:       fprintf(fp,"<class> ");
                    196:       break;
                    197:     case SrationalFunction:
                    198:       fprintf(fp,"<rationalFunction> ");
                    199:       break;
                    200:     case Sdouble:
                    201:       fprintf(fp,"<double> ");
                    202:       break;
                    203:     default:
                    204:       fprintf(fp,"<Unknown object tag. %d >",ob.tag);
                    205:       break;
                    206:     }
                    207:   }
                    208:   switch (ob.tag) {
                    209:   case 0:
                    210:     fprintf(fp,"%%[null]"); /* null object */
                    211:     break;
                    212:   case Sinteger:
                    213:     fprintf(fp,"%d",ob.lc.ival);
                    214:     break;
                    215:   case Sstring:
                    216:     fprintf(fp,"%s",ob.lc.str);
                    217:     break;
                    218:   case Soperator:
                    219:     fprintf(fp,"%s %%[operator] ",operatorType(ob.lc.ival));
                    220:     break;
                    221:   case Sdollar:
                    222:     if (PrintDollar == 2) {
                    223:       fprintf(fp,"(%s)",ob.lc.str);
                    224:     } else if (PrintDollar == 0 ) {
                    225:       fprintf(fp,"%s",ob.lc.str);
                    226:     } else {
                    227:       fprintf(fp,"$%s$",ob.lc.str);
                    228:     }
                    229:     break;
                    230:   case SexecutableArray:
                    231:     size = ob.rc.ival;
                    232:     ta = ob.lc.tokenArray;
                    233:     fprintf(fp,"{ ");
                    234:     for (i=0; i<size; i++) {
                    235:       switch ((ta[i]).kind) {
                    236:       case ID:
1.4       takayama  237:         fprintf(fp,"<<ID>>%s ",(ta[i]).token);
                    238:         break;
1.1       maekawa   239:       case EXECUTABLE_STRING:
1.4       takayama  240:         fprintf(fp,"<<EXECUTABLE_STRING>>{%s} ",(ta[i]).token);
                    241:         break;
1.1       maekawa   242:       case EXECUTABLE_ARRAY:
1.4       takayama  243:         printObject((ta[i]).object,nl,fp);
                    244:         break;
1.1       maekawa   245:       case DOLLAR:
1.4       takayama  246:         fprintf(fp,"<<STRING(DOLLAR)>>%s ",(ta[i]).token);
                    247:         break;
1.1       maekawa   248:       default:
1.4       takayama  249:         fprintf(fp,"Unknown token type\n");
                    250:         break;
1.1       maekawa   251:       }
                    252:     }
                    253:     fprintf(fp," }");
                    254:     break;
                    255:   case Sarray:
                    256:     printObjectArray(ob,0,fp);
                    257:     break;
                    258:   case SleftBraceTag:
                    259:     fprintf(fp,"[ ");
                    260:     break;
                    261:   case SrightBraceTag:
                    262:     fprintf(fp,"] ");
                    263:     break;
                    264:   case Spoly:
                    265:     fprintf(fp,"%s",KPOLYToString(ob.lc.poly));
                    266:     break;
                    267:   case SarrayOfPOLY:
                    268:     fprintf(fp,"Sorry! The object arrayOfPOLY cannot be printed.");
                    269:     break;
                    270:   case SmatrixOfPOLY:
                    271:     fprintf(fp,"Sorry! The object matrixOfPOLY cannot be printed.");
                    272:     break;
                    273:   case Slist:
                    274:     printObjectList(&ob);
                    275:     break;
                    276:   case Sfile:
                    277:     fprintf(fp,"Name=%s, FILE *=%x ",ob.lc.str,(int) ob.rc.file);
                    278:     break;
                    279:   case Sring:
                    280:     fprintf(fp,"Ring."); KshowRing(KopRingp(ob));
                    281:     break;
                    282:   case SuniversalNumber:
                    283:     fprintf(fp,"%s",coeffToString(ob.lc.universalNumber));
                    284:     break;
                    285:   case SrationalFunction:
                    286:     fprintf(fp,"("); printObject(*(Knumerator(ob)),nl,fp);
                    287:     fprintf(fp,")/(");printObject(*(Kdenominator(ob)),nl,fp);
                    288:     fprintf(fp,")");
                    289:     break;
                    290:   case Sclass:
                    291:     /* fprintf(fp,"Class: "); */
                    292:     fprintClass(fp,ob);
                    293:     break;
                    294:   case Sdouble:
                    295:     fprintf(fp,"%f",KopDouble(ob));
                    296:     break;
                    297:   default:
                    298:     fprintf(fp,"[Unknown object tag.]");
                    299:     break;
                    300:   }
                    301:   if (nl) fprintf(fp,"\n");
                    302: }
                    303:
                    304: void printObjectArray(ob,nl,fp)
1.4       takayama  305:      struct object ob;
                    306:      int nl;
                    307:      FILE *fp;
1.1       maekawa   308: {
                    309:   int size;
                    310:   int i;
1.2       takayama  311:   extern char *LeftBracket, *RightBracket;
1.1       maekawa   312:   size = ob.lc.ival;
1.2       takayama  313:   fprintf(fp,"%s  ",LeftBracket);
1.1       maekawa   314:   for (i=0; i<size; i++) {
                    315:     if (PrintComma && (i != 0)) {
                    316:       fprintf(fp," , ");
                    317:     }else{
                    318:       fprintf(fp,"  ");
                    319:     }
                    320:     printObject((ob.rc.op)[i],0,fp);
                    321:   }
1.2       takayama  322:   fprintf(fp," %s ",RightBracket);
1.1       maekawa   323:   if (nl) fprintf(fp,"\n");
                    324: }
                    325:
                    326: void  KdefinePrimitiveFunctions() {
                    327:   /* It is recommended to sort the follows for performance */
                    328:   putPrimitiveFunction("mul",Smult);
                    329:   putPrimitiveFunction("add",Sadd);
                    330:   putPrimitiveFunction("sub",Ssub);
                    331:   putPrimitiveFunction("lt",Sless);
                    332:   putPrimitiveFunction("set",Sset);
                    333:   putPrimitiveFunction("eq",Sequal);
                    334:   putPrimitiveFunction("gt",Sgreater);
                    335:   putPrimitiveFunction("QUIT",Squit);
                    336:   putPrimitiveFunction("[",SleftBrace);
                    337:   putPrimitiveFunction("]",SrightBrace);
                    338:   putPrimitiveFunction("bye",Squit);
                    339:   putPrimitiveFunction("length",Slength);
                    340:   putPrimitiveFunction("for",Sfor);
                    341:   putPrimitiveFunction("roll",Sroll);
                    342:   putPrimitiveFunction("cat_n",Scat_n);
                    343:   putPrimitiveFunction("coefficients",Scoefficients);
                    344:   putPrimitiveFunction("copy",Scopy);
                    345:   putPrimitiveFunction("data_conversion",Sdata_conversion);
                    346:   putPrimitiveFunction("aload",Saload);
                    347:   putPrimitiveFunction("def",Sdef);
                    348:   putPrimitiveFunction("degree",Sdegree);
                    349:   putPrimitiveFunction("elimination_order",Selimination_order);
                    350:   putPrimitiveFunction("exec",Sexec);
                    351:   putPrimitiveFunction("exit",Squit);
                    352:   putPrimitiveFunction("get",Sget);
                    353:   putPrimitiveFunction("groebner",Sgroebner);
                    354:   putPrimitiveFunction("ifelse",Sifelse);
                    355:   putPrimitiveFunction("index",Sindex);
                    356:   putPrimitiveFunction("dup",Sdup);
                    357:   putPrimitiveFunction("init",Sinit);
                    358:   putPrimitiveFunction("loop",Sloop);
                    359:   putPrimitiveFunction("options",Soptions);
                    360:   putPrimitiveFunction("pop",Spop);
                    361:   putPrimitiveFunction("put",Sput);
                    362:   putPrimitiveFunction("print",Sprint);
                    363:   putPrimitiveFunction("pstack",Spstack);
                    364:   putPrimitiveFunction("print_switch_status",Sprint_switch_status);
                    365:   putPrimitiveFunction("quit",Squit);
                    366:   putPrimitiveFunction("file",Sfileopen);
                    367:   putPrimitiveFunction("closefile",Sclosefile);
                    368:   putPrimitiveFunction("idiv",Sidiv);
                    369:   putPrimitiveFunction("reduction",Sreduction);
                    370:   putPrimitiveFunction("replace",Sreplace);
                    371:   putPrimitiveFunction("run",Srun);
                    372:   putPrimitiveFunction("set_order_by_matrix",Sset_order_by_matrix);
                    373:   putPrimitiveFunction("set_timer",Sset_timer);
                    374:   putPrimitiveFunction("set_up_ring@",Sset_up_ring);
                    375:   putPrimitiveFunction("show_ring",Sshow_ring);
                    376:   putPrimitiveFunction("show_systemdictionary",Sshow_systemdictionary);
                    377:   putPrimitiveFunction("show_user_dictionary",Sshow_user_dictionary);
                    378:   putPrimitiveFunction("spol",Sspol);
                    379:   putPrimitiveFunction("switch_function",Sswitch_function);
                    380:   putPrimitiveFunction("system",Ssystem);
                    381:   putPrimitiveFunction("system_variable",Ssystem_variable);
                    382:   putPrimitiveFunction("test",Stest);
1.5       takayama  383:   putPrimitiveFunction("tlimit",Stlimit);
1.9       takayama  384:   putPrimitiveFunction("oxshell",Soxshell);
1.1       maekawa   385:   putPrimitiveFunction("map",Smap);
                    386:   putPrimitiveFunction("to_records",Sto_records);
                    387:   putPrimitiveFunction("Usage",Susage);
                    388:   putPrimitiveFunction("load",Sload);
                    389:   putPrimitiveFunction("writestring",Swritestring);
                    390:   putPrimitiveFunction("eval",Seval);
                    391:   putPrimitiveFunction("homogenize",Shomogenize);
                    392:   putPrimitiveFunction("principal",Sprincipal);
                    393:   putPrimitiveFunction("pushfile",Spushfile);
                    394:   putPrimitiveFunction("div",Sdiv);
                    395:   putPrimitiveFunction("goto",Sgoto);
                    396:   putPrimitiveFunction("extension",Sextension);
                    397:   putPrimitiveFunction("newstack",Snewstack);
                    398:   putPrimitiveFunction("setstack",Ssetstack);
                    399:   putPrimitiveFunction("stdstack",Sstdstack);
                    400:   putPrimitiveFunction("lc",Slc);
                    401:   putPrimitiveFunction("rc",Src);
                    402:   putPrimitiveFunction("gbext",Sgbext);
                    403:   putPrimitiveFunction("newcontext",Snewcontext);
                    404:   putPrimitiveFunction("setcontext",Ssetcontext);
                    405:   putPrimitiveFunction("supercontext",Ssupercontext);
                    406:   putPrimitiveFunction("sendmsg",Ssendmsg);
                    407:   putPrimitiveFunction("error",Serror);
                    408:   putPrimitiveFunction("mpzext",Smpzext);
                    409:   putPrimitiveFunction("sendmsg2",Ssendmsg2);
                    410:   putPrimitiveFunction("primmsg",Sprimmsg);
                    411:   putPrimitiveFunction("supmsg2",Ssupmsg2);
                    412:   putPrimitiveFunction("cclass",Scclass);
                    413:   putPrimitiveFunction("coeff",Scoeff2);
                    414: }
                    415:
                    416: int executePrimitive(ob)
1.4       takayama  417:      struct object ob;
1.1       maekawa   418: {
                    419:   struct object ob1;
                    420:   struct object ob2;
                    421:   struct object ob3;
                    422:   struct object ob4;
                    423:   struct object ob5;
                    424:   struct object rob;
                    425:   struct object obArray[OB_ARRAY_MAX];
                    426:   struct object obArray2[OB_ARRAY_MAX];
                    427:   int size;
                    428:   int i,j,k,n;
                    429:   int status;
1.13      takayama  430:   int infixOn;
                    431:   struct tokens infixToken;
1.1       maekawa   432:   struct tokens *tokenArray;
                    433:   struct tokens token;
                    434:   FILE *fp;
                    435:   char *fname;
                    436:   int rank;
                    437:   struct object oMat;
                    438:   static int timerStart = 1;
                    439:   static struct tms before, after;
                    440:   static time_t before_real, after_real;
                    441:   struct object oInput;
                    442:   char *str;
                    443:   int ccflag = 0;
                    444:   extern int KeepInput;
                    445:   extern int History;
                    446:   extern struct ring *CurrentRingp;
                    447:   extern TimerOn;
1.3       takayama  448:   extern SecureMode;
1.1       maekawa   449:
1.13      takayama  450:   infixOn = 0;
                    451:
1.1       maekawa   452:   if (DebugStack >= 2) {
                    453:     fprintf(Fstack,"In execute %d\n",ob.lc.ival); printOperandStack();
                    454:   }
                    455:
                    456:   if (GotoP) return(0);
                    457:   switch (ob.lc.ival) {
                    458:     /* Postscript primitives :stack */
                    459:   case Sgoto:
                    460:     ob1 = Kpop();
                    461:     if (ob1.tag != Sstring) {
                    462:       if (DebugStack>=2) printObject(ob1,0,Fstack);
                    463:       errorStackmachine("Usage:goto");
                    464:     }
                    465:     GotoLabel = ob1.lc.str;
                    466:     GotoP = 1;
                    467:     break;
                    468:   case Spop:
                    469:     ob1 = Kpop();
                    470:     break;
                    471:
                    472:   case Sdup:
                    473:     ob1 = Kpop();
                    474:     Kpush(ob1); Kpush(ob1);
                    475:     break;
                    476:   case Scopy:  /* copy values. cf. dup */
                    477:     ob1 = Kpop();
                    478:     switch(ob1.tag) {
                    479:     case Sinteger: break;
                    480:     default: errorStackmachine("Usage:copy");
                    481:     }
                    482:     size = ob1.lc.ival;
                    483:     k = 0;
                    484:     for (i=size-1; i>=0; i--) {
                    485:       ob2 = peek(i+k);
                    486:       switch(ob2.tag) {
                    487:       case Sdollar: /* copy by value */
1.4       takayama  488:         str = (char *)sGC_malloc(strlen(ob2.lc.str)+3);
                    489:         if (str == (char *)NULL) errorStackmachine("No memory (copy)");
                    490:         strcpy(str,ob2.lc.str);
                    491:         Kpush(KpoString(str));
                    492:         break;
1.1       maekawa   493:       case Spoly:
1.4       takayama  494:         errorStackmachine("no pCopy (copy)");
                    495:         break;
1.1       maekawa   496:       case Sarray:
1.4       takayama  497:         n = ob2.lc.ival;
                    498:         ob3 = newObjectArray(n);
                    499:         for (j=0; j<n; j++) {
                    500:           putoa(ob3,j,getoa(ob2,j));
                    501:         }
                    502:         Kpush(ob3);
                    503:         break;
1.1       maekawa   504:       default:
1.4       takayama  505:         Kpush(ob2);
                    506:         break;
1.1       maekawa   507:       }
                    508:       k++;
                    509:     }
                    510:     break;
                    511:   case Sroll:
                    512:     ob1 = Kpop();
                    513:     ob2 = Kpop();
                    514:     switch(ob1.tag) {
                    515:     case Sinteger:
                    516:       j = ob1.lc.ival;
                    517:       break;
                    518:     default: errorStackmachine("Usage:roll");
                    519:     }
                    520:     switch(ob2.tag) {
                    521:     case Sinteger:
                    522:       n = ob2.lc.ival;
                    523:       break;
                    524:     default: errorStackmachine("Usage:roll");
                    525:     }
                    526:     for (i=0; i<n; i++) {
                    527:       if (i < OB_ARRAY_MAX) {
1.4       takayama  528:         obArray[i] = Kpop();
1.1       maekawa   529:       }else{
1.4       takayama  530:         errorStackmachine("exceeded OB_ARRAY_MAX (roll)\n");
1.1       maekawa   531:       }
                    532:     }
                    533:     for (i=0; i<n; i++) {
                    534:       k = (j-1)%n;
                    535:       k = (k>=0?k: k+n);
                    536:       Kpush(obArray[k]);
                    537:       j--;
                    538:     }
                    539:     break;
                    540:   case Spstack:
                    541:     printOperandStack();
                    542:     break;
                    543:
                    544:     /* Postscript primitives :arithmetic */
                    545:   case Sadd:
1.16    ! takayama  546:     ob1 = Kpop();
1.1       maekawa   547:     ob2 = Kpop();
1.16    ! takayama  548:     evalEA(ob1); evalEA(ob2);
1.1       maekawa   549:     rob = KooAdd(ob1,ob2);
                    550:     Kpush(rob);
                    551:     break;
                    552:   case Ssub:
                    553:     ob2 = Kpop();
                    554:     ob1 = Kpop();
1.16    ! takayama  555:     evalEA(ob1); evalEA(ob2);
1.1       maekawa   556:     rob = KooSub(ob1,ob2);
                    557:     Kpush(rob);
                    558:     break;
                    559:   case Smult:
                    560:     ob2 = Kpop();
                    561:     ob1 = Kpop();
1.16    ! takayama  562:     evalEA(ob1); evalEA(ob2);
1.1       maekawa   563:     rob = KooMult(ob1,ob2);
                    564:     Kpush(rob);
                    565:     break;
                    566:   case Sidiv:
                    567:     ob2 = Kpop(); ob1 = Kpop();
1.16    ! takayama  568:     evalEA(ob1); evalEA(ob2);
1.1       maekawa   569:     rob = KooDiv(ob1,ob2);
                    570:     Kpush(rob);
                    571:     break;
                    572:
                    573:   case Sdiv:
                    574:     ob2 = Kpop(); ob1 = Kpop();
1.16    ! takayama  575:     evalEA(ob1); evalEA(ob2);
1.1       maekawa   576:     rob = KooDiv2(ob1,ob2);
                    577:     Kpush(rob);
                    578:     break;
                    579:
                    580:     /* Postscript primitives :array */
                    581:   case SleftBrace:
                    582:     rob.tag = SleftBraceTag;
                    583:     Kpush(rob);
                    584:     break;
                    585:
                    586:   case SrightBrace:
                    587:     size = 0;
                    588:     ob1 = peek(size);
                    589:     while (!(Osp-size-1 < 0)) { /* while the stack is not underflow */
                    590:       if (ob1.tag == SleftBraceTag) {
1.4       takayama  591:         rob = newObjectArray(size);
                    592:         for (i=0; i<size; i++) {
                    593:           (rob.rc.op)[i] = peek(size-1-i);
                    594:         }
                    595:         for (i=0; i<size+1; i++) {
                    596:           Kpop();
                    597:         }
                    598:         break;
1.1       maekawa   599:       }
                    600:       size++;
                    601:       ob1 = peek(size);
                    602:     }
                    603:     Kpush(rob);
                    604:     break;
                    605:
                    606:   case Sget:
                    607:     /* [a_0 ... a_{n-1}] i   get a_i */
                    608:     /* ob2               ob1 get     */
                    609:     ob1 = Kpop();
                    610:     ob2 = Kpop();
1.12      takayama  611:     Kpush(Kget(ob2,ob1));
1.1       maekawa   612:     break;
                    613:
                    614:   case Sput:
                    615:     /*    [a_0 ... a_{n-1}] index any put */
                    616:     /* ob3               ob2   ob1 put     */
                    617:     /* Or;  [[a_00 ....] [a_10 ....] ....] [1 0] any put. MultiIndex. */
                    618:     ob1 = Kpop(); ob2 = Kpop(); ob3 = Kpop();
                    619:     switch(ob2.tag) {
                    620:     case Sinteger:
                    621:       switch(ob3.tag) {
                    622:       case Sarray:
1.4       takayama  623:         i = ob2.lc.ival;
                    624:         size = getoaSize(ob3);
                    625:         if ((0 <= i) && (i<size)) {
                    626:           getoa(ob3,i) = ob1;
                    627:         }else{
                    628:           errorStackmachine("Index is out of bound. (put)\n");
                    629:         }
                    630:         break;
1.1       maekawa   631:       case Sdollar:
1.4       takayama  632:         i = ob2.lc.ival;
                    633:         size = strlen(ob3.lc.str);
                    634:         if ((0 <= i) && (i<size)) {
                    635:           if (ob1.tag == Sdollar) {
                    636:             (ob3.lc.str)[i] = (ob1.lc.str)[0];
                    637:           }else{
                    638:             (ob3.lc.str)[i] = ob1.lc.ival;
                    639:           }
                    640:         }else{
                    641:           errorStackmachine("Index is out of bound. (put)\n");
                    642:         }
                    643:         break;
1.1       maekawa   644:       default: errorStackmachine("Usage:put");
                    645:       }
                    646:       break;
                    647:     case Sarray:
                    648:       ob5 = ob3;
                    649:       n = getoaSize(ob2);
                    650:       for (i=0; i<n; i++) {
1.4       takayama  651:         if (ob5.tag != Sarray)
                    652:           errorStackmachine("Object pointed by the multi-index is not array (put)\n");
                    653:         ob4 = getoa(ob2,i);
                    654:         if (ob4.tag != Sinteger)
                    655:           errorStackmachine("Index has to be an integer. (put)\n");
                    656:         k = ob4.lc.ival;
                    657:         size = getoaSize(ob5);
                    658:         if ((0 <= k) && (k<size)) {
                    659:           if (i == n-1) {
                    660:             getoa(ob5,k) = ob1;
                    661:           }else{
                    662:             ob5 = getoa(ob5,k);
                    663:           }
                    664:         }else{
                    665:           errorStackmachine("Index is out of bound for the multi-index. (put)\n");
                    666:         }
1.1       maekawa   667:       }
                    668:       break;
                    669:     default: errorStackmachine("Usage:put");
                    670:     }
                    671:     break;
                    672:
                    673:   case Sindex:
                    674:     ob1 = Kpop();
                    675:     switch(ob1.tag) {
                    676:     case Sinteger: break;
                    677:     default: errorStackmachine("Usage:index");
                    678:     }
                    679:     size = ob1.lc.ival;
                    680:     Kpush(peek(size-1));
                    681:     break;
                    682:
                    683:   case Saload:
                    684:     /* [a1 a2 ... an] aload a1 a2 ... an [a1 ... an] */
                    685:     ob1 = Kpop();
                    686:     switch(ob1.tag) {
                    687:     case Sarray: break;
                    688:     default:
                    689:       errorStackmachine("Usage:aload");
                    690:     }
                    691:     size = getoaSize(ob1);
                    692:     for (i=0; i<size; i++) {
                    693:       Kpush(getoa(ob1,i));
                    694:     }
                    695:     Kpush(ob1);
                    696:
                    697:     break;
                    698:
                    699:   case Slength:
                    700:     /* [a_0 ... a_{n-1}] length n */
                    701:     /*               ob1 length rob */
                    702:     ob1 = Kpop();
                    703:     switch(ob1.tag) {
                    704:     case Sarray:
                    705:       size = getoaSize(ob1);
                    706:       Kpush(KpoInteger(size));
                    707:       break;
                    708:     case Sdollar:
                    709:       Kpush(KpoInteger(strlen(ob1.lc.str)));
                    710:       break;
                    711:     case Spoly:
                    712:       Kpush(KpoInteger(KpolyLength(KopPOLY(ob1))));
                    713:       break;
                    714:     default: errorStackmachine("Usage:length");
                    715:     }
                    716:     break;
                    717:
                    718:     /* Postscript primitives :relation */
                    719:   case Sequal:
                    720:     /* obj1 obj2 == bool */
                    721:     ob2 = Kpop();
                    722:     ob1 = Kpop();
                    723:     if(KooEqualQ(ob1,ob2)) {
                    724:       Kpush(KpoInteger(1));
                    725:     }else{
                    726:       Kpush(KpoInteger(0));
                    727:     }
                    728:     break;
                    729:
                    730:   case Sless:
                    731:     /* obj1 obj2 < bool */
                    732:     ob2 = Kpop();
                    733:     ob1 = Kpop();
                    734:     Kpush(KooLess(ob1,ob2));
                    735:     break;
                    736:
                    737:   case Sgreater:
                    738:     /* obj1 obj2 < bool */
                    739:     ob2 = Kpop();
                    740:     ob1 = Kpop();
                    741:     Kpush(KooGreater(ob1,ob2));
                    742:     break;
                    743:
                    744:
                    745:     /* Postscript primitives :controle */
                    746:   case Sloop:
                    747:     /* { .... exit .....} loop */
                    748:     ob1 = Kpop();
                    749:     switch(ob1.tag) {
                    750:     case SexecutableArray: break;
                    751:     default:
                    752:       errorStackmachine("Usage:loop");
                    753:       break;
                    754:     }
                    755:     while (1) {
1.15      takayama  756:       status = executeExecutableArray(ob1,(char *)NULL,1);
1.13      takayama  757:       if ((status & STATUS_BREAK) || GotoP) break;
1.1       maekawa   758:       /* here, do not return 1. Do not propagate exit signal outside of the
1.4       takayama  759:          loop. */
1.1       maekawa   760:     }
                    761:     break;
                    762:
                    763:   case Sfor:
                    764:     /* init inc limit { } for */
                    765:     /* ob4  ob3 ob2   ob1 */
                    766:     ob1 =Kpop(); ob2 = Kpop(); ob3 = Kpop(); ob4 = Kpop();
                    767:     switch(ob1.tag) {
                    768:     case SexecutableArray: break;
                    769:     default: errorStackmachine("Usage:for");
                    770:     }
                    771:     switch(ob2.tag) {
                    772:     case Sinteger: break;
                    773:     default:
                    774:       errorStackmachine("Usage:for The 3rd argument must be integer.");
                    775:     }
                    776:     switch(ob3.tag) {
                    777:     case Sinteger: break;
                    778:     default: errorStackmachine("Usage:for The 2nd argument must be integer.");
                    779:     }
                    780:     switch(ob4.tag) {
                    781:     case Sinteger: break;
                    782:     default: errorStackmachine("Usage:for The 1st argument must be integer.");
                    783:     }
                    784:     {
                    785:       int i,lim,inc,j;
                    786:       i = ob4.lc.ival;
                    787:       lim = ob2.lc.ival;
                    788:       inc = ob3.lc.ival;
                    789:       if (inc > 0) {
                    790:         /*
1.4       takayama  791:           if (lim < i) errorStackmachine("The initial value must not be greater than limit value (for).\n");
1.1       maekawa   792:         */
1.4       takayama  793:         for ( ; i<=lim; i += inc) {
                    794:           Kpush(KpoInteger(i));
1.15      takayama  795:           status = executeExecutableArray(ob1,(char *)NULL,1);
1.14      takayama  796:           if ((status & STATUS_BREAK) || GotoP) goto xyz;
1.13      takayama  797:                }
1.1       maekawa   798:       }else{
                    799:         /*
1.4       takayama  800:           if (lim > i) errorStackmachine("The initial value must not be less than limit value (for).\n");
1.1       maekawa   801:         */
1.4       takayama  802:         for ( ; i>=lim; i += inc) {
                    803:           Kpush(KpoInteger(i));
1.15      takayama  804:           status = executeExecutableArray(ob1,(char *)NULL,1);
1.14      takayama  805:           if ((status & STATUS_BREAK) || GotoP) goto xyz;
1.4       takayama  806:         }
1.1       maekawa   807:       }
1.4       takayama  808:     xyz:  ;
1.1       maekawa   809:     }
                    810:     break;
                    811:
                    812:   case Smap:
                    813:     ob2 = Kpop(); ob1 = Kpop();
                    814:     switch(ob1.tag) {
                    815:     case Sarray: break;
                    816:     default:
                    817:       errorStackmachine("Usage:map The 1st argument must be an array.");
                    818:       break;
                    819:     }
                    820:     switch(ob2.tag) {
                    821:     case SexecutableArray: break;
                    822:     default:
                    823:       errorStackmachine("Usage:map The 2nd argument must be an executable array.");
                    824:       break;
                    825:     }
                    826:     { int osize,size;
1.4       takayama  827:     int i,j;
                    828:     osize = getoaSize(ob1);
1.1       maekawa   829:
1.4       takayama  830:     /*KSexecuteString("[");*/
                    831:     rob.tag = SleftBraceTag;
                    832:     Kpush(rob);
1.1       maekawa   833:
1.4       takayama  834:     for (i=0; i<osize; i++) {
                    835:       Kpush(getoa(ob1,i));
1.15      takayama  836:       status = executeExecutableArray(ob2,(char *)NULL,0);
                    837:       if (status & STATUS_BREAK) goto foor;
1.4       takayama  838:     }
1.1       maekawa   839:     foor: ;
1.4       takayama  840:     /*KSexecuteString("]");*/
                    841:     {
                    842:       size = 0;
                    843:       ob1 = peek(size);
                    844:       while (!(Osp-size-1 < 0)) { /* while the stack is not underflow */
                    845:         if (ob1.tag == SleftBraceTag) {
                    846:           rob = newObjectArray(size);
                    847:           for (i=0; i<size; i++) {
                    848:             (rob.rc.op)[i] = peek(size-1-i);
                    849:           }
                    850:           for (i=0; i<size+1; i++) {
                    851:             Kpop();
                    852:           }
                    853:           break;
                    854:         }
                    855:         size++;
                    856:         ob1 = peek(size);
1.1       maekawa   857:       }
1.4       takayama  858:       Kpush(rob);
                    859:     }
1.1       maekawa   860:     }
                    861:     break;
                    862:
                    863:
                    864:   case Sifelse:
                    865:     /* bool { } { } ifelse */
                    866:     ob1 = Kpop();
                    867:     ob2 = Kpop();
                    868:     ob3 = Kpop();
                    869:     switch (ob1.tag) {
                    870:     case SexecutableArray: break;
                    871:     default: errorStackmachine("Usage:ifelse");
                    872:     }
                    873:     switch (ob2.tag) {
                    874:     case SexecutableArray: break;
                    875:     default: errorStackmachine("Usage:ifelse");
                    876:     }
                    877:     switch (ob3.tag) {
                    878:     case Sinteger: break;
                    879:     default: errorStackmachine("Usage:ifelse");
                    880:     }
                    881:     if (ob3.lc.ival) {
                    882:       /* execute ob2 */
                    883:       ob1 = ob2;
                    884:     }
                    885:     /* execute ob1 */
1.15      takayama  886:     status = executeExecutableArray(ob1,(char *)NULL,0);
1.14      takayama  887:     if (status & STATUS_BREAK) return(status);
1.13      takayama  888:
1.1       maekawa   889:     break;
                    890:
                    891:   case Sexec:
                    892:     /* { .........} exec */
                    893:     ob1 = Kpop();
                    894:     switch(ob1.tag) {
                    895:     case SexecutableArray: break;
                    896:     default: errorStackmachine("Usage:exec");
                    897:     }
1.15      takayama  898:        status = executeExecutableArray(ob1,(char *)NULL,0);
1.1       maekawa   899:     break;
                    900:
1.4       takayama  901:     /* Postscript primitives :dictionary */
1.1       maekawa   902:   case Sdef:
                    903:     ob2 = Kpop();
                    904:     ob1 = Kpop();
                    905:     /* type check */
                    906:     switch(ob1.tag) {
                    907:     case Sstring: break;
                    908:     default:
                    909:       errorStackmachine("Usage:def");
                    910:       break;
                    911:     }
                    912:     k=putUserDictionary(ob1.lc.str,(ob1.rc.op->lc).ival,
1.4       takayama  913:                         (ob1.rc.op->rc).ival,ob2,
                    914:                         CurrentContextp->userDictionary);
1.1       maekawa   915:     if (k < 0) {
                    916:       str = (char *)sGC_malloc(sizeof(char)*(strlen(ob1.lc.str) + 256));
                    917:       if (str == (char *)NULL) {
1.4       takayama  918:         errorStackmachine("No memory.\n");
1.1       maekawa   919:       }
                    920:       if (k == -PROTECT) {
1.4       takayama  921:         sprintf(str,"You rewrited the protected symbol %s.\n",ob1.lc.str);
                    922:         /*  cf. [(chattr) num sym] extension */
                    923:         warningStackmachine(str);
1.1       maekawa   924:       } else if (k == -ABSOLUTE_PROTECT) {
1.4       takayama  925:         sprintf(str,"You cannot rewrite the protected symbol %s.\n",ob1.lc.str);
                    926:         errorStackmachine(str);
1.1       maekawa   927:       } else errorStackmachine("Unknown return value of putUserDictioanry\n");
                    928:     }
                    929:     break;
                    930:
                    931:   case Sload:
                    932:     ob1 = Kpop();
                    933:     switch(ob1.tag) {
                    934:     case Sstring: break;
                    935:     default: errorStackmachine("Usage:load");
                    936:     }
                    937:     ob1 =  findUserDictionary(ob1.lc.str,
1.4       takayama  938:                               (ob1.rc.op->lc).ival,
                    939:                               (ob1.rc.op->rc).ival,
                    940:                               CurrentContextp);
1.1       maekawa   941:     if (ob1.tag == -1) Kpush(NullObject);
                    942:     else Kpush(ob1);
                    943:
                    944:     break;
                    945:
                    946:   case Sset:
                    947:     ob1 = Kpop();
                    948:     ob2 = Kpop();
                    949:     switch(ob1.tag) {
                    950:     case Sstring: break;
                    951:     default: errorStackmachine("Usage:set");
                    952:     }
                    953:     k= putUserDictionary(ob1.lc.str,(ob1.rc.op->lc).ival,
1.4       takayama  954:                          (ob1.rc.op->rc).ival,ob2,
                    955:                          CurrentContextp->userDictionary);
1.1       maekawa   956:     if (k < 0) {
                    957:       str = (char *)sGC_malloc(sizeof(char)*(strlen(ob1.lc.str) + 256));
                    958:       if (str == (char *)NULL) {
1.4       takayama  959:         errorStackmachine("No memory.\n");
1.1       maekawa   960:       }
                    961:       if (k == -PROTECT) {
1.4       takayama  962:         sprintf(str,"You rewrited the protected symbol %s. \n",ob1.lc.str);
                    963:         warningStackmachine(str);
1.1       maekawa   964:       } else if (k == -ABSOLUTE_PROTECT) {
1.4       takayama  965:         sprintf(str,"You cannot rewrite the protected symbol %s.\n",ob1.lc.str);
                    966:         errorStackmachine(str);
1.1       maekawa   967:       } else errorStackmachine("Unknown return value of putUserDictioanry\n");
                    968:     }
                    969:     break;
                    970:
                    971:
                    972:   case Sshow_systemdictionary:
                    973:     fprintf(Fstack,"------------- system dictionary -------------------\n");
                    974:     showSystemDictionary(0);
                    975:     break;
                    976:
                    977:   case Sshow_user_dictionary:
                    978:     showUserDictionary();
                    979:     break;
                    980:
                    981:
                    982:
                    983:     /* Postscript primitives : convert */
                    984:   case Sdata_conversion:
                    985:     ob2 = Kpop();
                    986:     ob1 = Kpop();
                    987:     switch(ob2.tag) {
                    988:     case Sdollar:
                    989:       if (ob1.tag != Sclass) {
1.4       takayama  990:         rob = KdataConversion(ob1,ob2.lc.str);
1.1       maekawa   991:       }else{
1.4       takayama  992:         rob = KclassDataConversion(ob1,ob2);
1.1       maekawa   993:       }
                    994:       break;
                    995:     case Sarray:
                    996:       rob = KclassDataConversion(ob1,ob2); break;
                    997:     default: errorStackmachine("Usage:data_conversion");
                    998:     }
                    999:     Kpush(rob);
                   1000:     break;
                   1001:
                   1002:
                   1003:     /* Postscript ptimitives :file */
                   1004:   case Srun:
                   1005:     ob1 = Kpop();
                   1006:     switch(ob1.tag) {
                   1007:     case Sdollar: break;
                   1008:     case Sstring: break;
                   1009:     default:
                   1010:       errorStackmachine("Usage:run");
                   1011:       break;
                   1012:     }
                   1013:     getokenSM(OPEN,ob1.lc.str);  /* open the file, $filename$ run */
                   1014:     break;
                   1015:
                   1016:   case Sprint:
                   1017:     ob1 = Kpop();
                   1018:     printObject(ob1,0,Fstack);
                   1019:     break;
                   1020:
                   1021:   case Sfileopen: /* filename  mode   file  descripter */
1.4       takayama 1022:     /* ob2       ob1  */
1.1       maekawa  1023:     ob1 = Kpop();
                   1024:     ob2 = Kpop();
1.4       takayama 1025:     if (SecureMode) errorStackmachine("Security violation: you cannot open a file.");
1.1       maekawa  1026:     switch(ob1.tag) {
                   1027:     case Sdollar: break;
                   1028:     default: errorStackmachine("Usage:file");
                   1029:     }
                   1030:     switch(ob2.tag) {
                   1031:     case Sinteger: break;
                   1032:     case Sdollar: break;
                   1033:     default:errorStackmachine("Usage:file");
                   1034:     }
                   1035:     rob = NullObject;
                   1036:     if (ob2.tag == Sdollar) {
                   1037:       if (strcmp(ob2.lc.str,"%stdin") == 0) {
1.4       takayama 1038:         rob.tag = Sfile; rob.lc.str="%stdin"; rob.rc.file = stdin;
1.1       maekawa  1039:       }else if (strcmp(ob2.lc.str,"%stdout") == 0) {
1.4       takayama 1040:         rob.tag = Sfile; rob.lc.str="%stdout"; rob.rc.file = stdout;
1.1       maekawa  1041:       }else if (strcmp(ob2.lc.str,"%stderr") == 0) {
1.4       takayama 1042:         rob.tag = Sfile; rob.lc.str="%stderr"; rob.rc.file = stderr;
1.1       maekawa  1043:       }else if ( (rob.rc.file = fopen(ob2.lc.str,ob1.lc.str)) != (FILE *)NULL) {
1.4       takayama 1044:         rob.tag = Sfile; rob.lc.str = ob2.lc.str;
1.1       maekawa  1045:       }else {
1.4       takayama 1046:         errorStackmachine("I cannot open the file.");
1.1       maekawa  1047:       }
                   1048:     }else {
                   1049:       rob.rc.file = fdopen(ob2.lc.ival,ob1.lc.str);
                   1050:       if ( rob.rc.file != (FILE *)NULL) {
1.4       takayama 1051:         rob.tag = Sfile; rob.lc.ival = ob2.lc.ival;
1.1       maekawa  1052:       }else{
1.4       takayama 1053:         errorStackmachine("I cannot fdopen the given fd.");
1.1       maekawa  1054:       }
                   1055:     }
                   1056:
                   1057:     Kpush(rob);
                   1058:     break;
                   1059:
                   1060:
                   1061:   case Swritestring:
                   1062:     /* file string writestring
                   1063:        ob2  ob1
                   1064:     */
                   1065:     ob1 = Kpop();
                   1066:     ob2 = Kpop();
                   1067:     switch(ob2.tag) {
                   1068:     case Sfile: break;
                   1069:     default: errorStackmachine("Usage:writestring");
                   1070:     }
                   1071:     switch(ob1.tag) {
                   1072:     case Sdollar: break;
                   1073:     default:  errorStackmachine("Usage:writestring");
                   1074:     }
                   1075:     fprintf(ob2.rc.file,"%s",ob1.lc.str);
                   1076:     break;
                   1077:
                   1078:   case Sclosefile:
                   1079:     ob1 = Kpop();
                   1080:     switch(ob1.tag) {
                   1081:     case Sfile: break;
                   1082:     default: errorStackmachine("Usage:closefile");
                   1083:     }
                   1084:     if (fclose(ob1.rc.file) == EOF) {
                   1085:       errorStackmachine("I couldn't close the file.\n");
                   1086:     }
                   1087:     break;
                   1088:
                   1089:   case Spushfile: /* filename pushfile  string */
1.4       takayama 1090:     /* ob2       */
1.1       maekawa  1091:     ob2 = Kpop();
                   1092:     switch(ob2.tag) {
                   1093:     case Sdollar: break;
                   1094:     default:errorStackmachine("Usage:pushfile");
                   1095:     }
                   1096:     rob = NullObject;
                   1097:     if (strcmp(ob2.lc.str,"%stdin") == 0) {
                   1098:       ob1.tag = Sfile; ob1.lc.str="%stdin"; ob1.rc.file = stdin;
                   1099:     }else if (strcmp(ob2.lc.str,"%stdout") == 0) {
                   1100:       ob1.tag = Sfile; ob1.lc.str="%stdout"; ob1.rc.file = stdout;
                   1101:     }else if (strcmp(ob2.lc.str,"%stderr") == 0) {
                   1102:       ob1.tag = Sfile; ob1.lc.str="%stderr"; ob1.rc.file = stderr;
                   1103:     }else if ( (ob1.rc.file = fopen(ob2.lc.str,"r")) != (FILE *)NULL) {
                   1104:       ob1.tag = Sfile; ob1.lc.str = ob2.lc.str;
                   1105:     }else {
                   1106:       if (ob1.rc.file == (FILE *)NULL) {
1.4       takayama 1107:         char fname2[1024];
                   1108:         strcpy(fname2,getLOAD_SM1_PATH());
                   1109:         strcat(fname2,ob2.lc.str);
                   1110:         ob1.rc.file = fopen(fname2,"r");
                   1111:         if (ob1.rc.file == (FILE *)NULL) {
                   1112:           strcpy(fname2,LOAD_SM1_PATH);
                   1113:           strcat(fname2,ob2.lc.str);
                   1114:           ob1.rc.file = fopen(fname2,"r");
                   1115:           if (ob1.rc.file == (FILE *)NULL) {
                   1116:             fprintf(stderr,"Warning: Cannot open the file <<%s>> for loading in the current directory nor the library directories %s and %s.\n",ob2.lc.str,getLOAD_SM1_PATH(),LOAD_SM1_PATH);
                   1117:             errorStackmachine("I cannot open the file.");
                   1118:           }
                   1119:         }
1.1       maekawa  1120:       }
                   1121:     }
                   1122:
                   1123:     /* read the strings
1.4       takayama 1124:      */
1.1       maekawa  1125:     n = 256; j=0;
                   1126:     rob.tag = Sdollar; rob.lc.str = (char *) sGC_malloc(sizeof(char)*n);
                   1127:     if (rob.lc.str == (char *)NULL) errorStackmachine("No more memory.");
                   1128:     while ((i = fgetc(ob1.rc.file)) != EOF) {
                   1129:       if (j >= n-1) {
1.4       takayama 1130:         n = 2*n;
                   1131:         if (n <= 0) errorStackmachine("Too large file to put on the stack.");
1.1       maekawa  1132:         str = (char *)sGC_malloc(sizeof(char)*n);
1.4       takayama 1133:         if (str == (char *)NULL) errorStackmachine("No more memory.");
                   1134:         for (k=0; k< n/2; k++) str[k] = (rob.lc.str)[k];
                   1135:         rob.lc.str = str;
1.1       maekawa  1136:       }
                   1137:       (rob.lc.str)[j] = i; (rob.lc.str)[j+1] = '\0';
                   1138:       j++;
                   1139:     }
                   1140:
                   1141:     fclose(ob1.rc.file);
                   1142:     Kpush(rob);
                   1143:     break;
                   1144:
                   1145:     /* Postscript primitives :misc */
                   1146:   case Squit:
                   1147:     Kclose(); stackmachine_close();
                   1148:     exit(0);
                   1149:     break;
                   1150:
                   1151:   case Ssystem:
                   1152:     ob1 = Kpop();
                   1153:     switch(ob1.tag) {
                   1154:     case Sdollar: break;
                   1155:     case Sstring: break;
                   1156:     default: errorStackmachine("Usage:system");
                   1157:     }
1.4       takayama 1158:     if (SecureMode) errorStackmachine("Security violation.");
1.1       maekawa  1159:     system( ob1.lc.str );
                   1160:     break;
                   1161:
                   1162:   case Scat_n:
                   1163:     ob1 = Kpop();
                   1164:     switch(ob1.tag) {
                   1165:     case Sinteger: break;
                   1166:     default: errorStackmachine("Usage:cat_n");
                   1167:     }
                   1168:     size = ob1.lc.ival;
                   1169:     k = 0;
                   1170:     for (i=size-1; i>=0; i--) {
                   1171:       ob2 = peek(i);
                   1172:       switch(ob2.tag) {
                   1173:       case Sdollar: break;
1.4       takayama 1174:       default:  errorStackmachine("Usage:cat_n");
1.1       maekawa  1175:       }
                   1176:       k += strlen(ob2.lc.str);
                   1177:     }
                   1178:     ob1.tag = Sdollar;
                   1179:     ob1.lc.str = (char *)sGC_malloc(sizeof(char)*(k+1));
                   1180:     if (ob1.lc.str == (char *)NULL) {
                   1181:       errorStackmachine("No more memory.\n");
                   1182:     }
                   1183:     /* concatnate */
                   1184:     k = 0;
                   1185:     for (i=size-1; i>=0; i--) {
                   1186:       ob2 = peek(i);
                   1187:       strcpy(&((ob1.lc.str)[k]),ob2.lc.str);
                   1188:       k = strlen(ob1.lc.str);
                   1189:     }
                   1190:     /* clear the arguments */
                   1191:     for (i=size-1; i>=0; i--) {
                   1192:       ob2 = Kpop();
                   1193:     }
                   1194:     Kpush(ob1);
                   1195:     break;
                   1196:
                   1197:   case Sset_timer:
                   1198:     /* 118p */
                   1199:     if (timerStart) {
                   1200:       before_real = time(&before_real);
                   1201:       times(&before);
                   1202:       timerStart = 0; TimerOn = 1;
                   1203:     }else{
                   1204:       times(&after);
                   1205:       after_real = time(&after_real);
                   1206:       if (TimerOn) {
1.4       takayama 1207:         printf("User time: %f seconds, System time: %f seconds, Real time: %d s\n",
                   1208:                ((double)(after.tms_utime - before.tms_utime)) /100.0,
                   1209:                ((double)(after.tms_stime - before.tms_stime)) /100.0,
                   1210:                (int) (after_real-before_real));
                   1211:         /* In cases of Solaris and Linux, the unit of tms_utime seems to
                   1212:            be given 0.01 seconds. */
1.1       maekawa  1213:
                   1214:       }
                   1215:       timerStart = 1; TimerOn = 0;
                   1216:     }
                   1217:     break;
                   1218:
                   1219:   case Susage:
                   1220:     ob1 = Kpop();
                   1221:     Kusage(ob1);
                   1222:     break;
                   1223:
                   1224:   case Sto_records:
                   1225:     ob1 = Kpop();
                   1226:     switch(ob1.tag) {
                   1227:     case Sdollar: break;
                   1228:     default:  errorStackmachine("Usage:to_records");
                   1229:     }
                   1230:     ob2 = KtoRecords(ob1);
                   1231:     size = getoaSize(ob2);
                   1232:     for (i=0; i<size; i++) {
                   1233:       Kpush(getoa(ob2,i));
                   1234:     }
                   1235:     rob.tag = Sinteger;
                   1236:     rob.lc.ival = size;
                   1237:     Kpush(rob);
                   1238:     break;
                   1239:
                   1240:   case Ssystem_variable:
                   1241:     ob1 = Kpop();
                   1242:     switch(ob1.tag) {
                   1243:     case Sarray: break;
                   1244:     default: errorStackmachine("Usage:system_variable");
                   1245:     }
                   1246:     Kpush(KsystemVariable(ob1));
                   1247:     break;
                   1248:
                   1249:     /* kan primitives :kan :ring */
                   1250:   case Sset_order_by_matrix:
                   1251:     ob1 = Kpop();
                   1252:     KsetOrderByObjArray(ob1);
                   1253:     break;
                   1254:   case Sset_up_ring:
1.7       takayama 1255:        KresetDegreeShift();
1.1       maekawa  1256:     ob5 = Kpop(); ob4=Kpop(); ob3=Kpop(); ob2=Kpop(); ob1=Kpop();
                   1257:     KsetUpRing(ob1,ob2,ob3,ob4,ob5);
                   1258:     break;
                   1259:   case Sshow_ring:
                   1260:     KshowRing(CurrentRingp);
                   1261:     break;
                   1262:   case Sswitch_function:
                   1263:     ob1 = Kpop();
                   1264:     ob2 = Kpop();
                   1265:     ob3 = KswitchFunction(ob2,ob1);
                   1266:     if (!isNullObject(ob3)) {
                   1267:       Kpush(ob3);
                   1268:     }
                   1269:     break;
                   1270:   case Sprint_switch_status:
                   1271:     KprintSwitchStatus();
                   1272:     break;
                   1273:   case Sreplace:
                   1274:     ob2 = Kpop();
                   1275:     ob1 = Kpop();
                   1276:     Kpush(KoReplace(ob1,ob2));
                   1277:     break;
                   1278:
                   1279:   case Scoefficients:
                   1280:     ob2 = Kpop();
                   1281:     ob1 = Kpop();
                   1282:     Kpush(Kparts(ob1,ob2));
                   1283:     break;
                   1284:
                   1285:   case Scoeff2:
                   1286:     ob2 = Kpop();
                   1287:     ob1 = Kpop();
                   1288:     Kpush(Kparts2(ob1,ob2));
                   1289:     break;
                   1290:
                   1291:   case Sdegree:
                   1292:     ob2 = Kpop();
                   1293:     ob1 = Kpop();
                   1294:     Kpush(Kdegree(ob1,ob2));
                   1295:     break;
                   1296:   case Sspol:
                   1297:     ob2 = Kpop();
                   1298:     ob1 = Kpop();
                   1299:     Kpush(Ksp(ob1,ob2));
                   1300:     break;
                   1301:
                   1302:   case Seval:
                   1303:     ob1 = Kpop();
                   1304:     Kpush(Keval(ob1));
                   1305:     break;
                   1306:
                   1307:   case Sreduction:
                   1308:     ob2 = Kpop();
                   1309:     ob1 = Kpop();
                   1310:     Kpush(Kreduction(ob1,ob2));
                   1311:     break;
                   1312:
                   1313:   case Sgroebner :
                   1314:     ob1 = Kpop();
                   1315:     Kpush(Kgroebner(ob1));
                   1316:     break;
                   1317:
                   1318:   case Shomogenize :
                   1319:     ob1 = Kpop();
                   1320:     Kpush(homogenizeObject(ob1,&i));
                   1321:     break;
                   1322:
                   1323:   case Sprincipal :
                   1324:     ob1 = Kpop();
                   1325:     Kpush(oPrincipalPart(ob1));
                   1326:     break;
                   1327:
                   1328:   case Sinit:
                   1329:     ob2 = Kpop();
                   1330:     if (ob2.tag != Sarray) {
                   1331:       Kpush(Khead(ob2));
                   1332:     }else{
1.6       takayama 1333:       if (getoaSize(ob2) > 0) {
                   1334:         if (getoa(ob2,getoaSize(ob2)-1).tag == Spoly) {
                   1335:           Kpush(oInitW(ob2,newObjectArray(0)));
                   1336:         }else{
                   1337:           ob1 = Kpop();
                   1338:           Kpush(oInitW(ob1,ob2));
                   1339:         }
                   1340:       }else{
                   1341:         ob1 = Kpop();
                   1342:         Kpush(oInitW(ob1,ob2));
                   1343:       }
1.1       maekawa  1344:     }
                   1345:     break;
                   1346:
                   1347:   case Sextension:
                   1348:     ob1 = Kpop();
                   1349:     Kpush(Kextension(ob1));
                   1350:     break;
                   1351:
                   1352:   case Sgbext:
                   1353:     ob1 = Kpop();
                   1354:     Kpush(KgbExtension(ob1));
                   1355:     break;
                   1356:
                   1357:   case Snewstack:
                   1358:     ob1 = Kpop();
                   1359:     switch(ob1.tag) {
                   1360:     case Sinteger:
                   1361:       Kpush(newOperandStack(ob1.lc.ival));
                   1362:       break;
                   1363:     default:
                   1364:       errorStackmachine("Usage:newstack");
                   1365:       break;
                   1366:     }
                   1367:     break;
                   1368:
                   1369:   case Ssetstack:
                   1370:     ob1 = Kpop();
                   1371:     switch(ob1.tag) {
                   1372:     case Sclass:
                   1373:       setOperandStack(ob1);
                   1374:       break;
                   1375:     default:
                   1376:       errorStackmachine("Usage:setstack");
                   1377:       break;
                   1378:     }
                   1379:     break;
                   1380:
                   1381:   case Sstdstack:
                   1382:     stdOperandStack();
                   1383:     break;
                   1384:
                   1385:   case Slc:
                   1386:     ob1 = Kpop();
                   1387:     switch (ob1.tag) {
                   1388:     case Sclass:
                   1389:       Kpush(KpoInteger(ob1.lc.ival));
                   1390:       break;
                   1391:     default:
                   1392:       errorStackmachine("Usage:lc");
                   1393:       break;
                   1394:     }
                   1395:     break;
                   1396:
                   1397:   case Src:
                   1398:     ob1 = Kpop();
                   1399:     switch (ob1.tag) {
                   1400:     case Sclass:
                   1401:       if (ClassTypes[ob1.lc.ival] == CLASS_OBJ) {
1.4       takayama 1402:         Kpush(*(ob1.rc.op));
1.1       maekawa  1403:       }else{
1.4       takayama 1404:         warningStackmachine("<<obj rc >> works only for a class object with CLASS_OBJ attribute.\n");
                   1405:         Kpush(ob1);
1.1       maekawa  1406:       }
                   1407:       break;
                   1408:     default:
                   1409:       errorStackmachine("Usage:rc");
                   1410:       break;
                   1411:     }
                   1412:     break;
                   1413:
                   1414:   case Snewcontext:
                   1415:     ob1 = Kpop();
                   1416:     ob2 = Kpop();
                   1417:     switch(ob1.tag) {
                   1418:     case Sclass:
                   1419:       if (ob2.tag == Sdollar) {
1.4       takayama 1420:         Kpush(KnewContext(ob1,KopString(ob2)));
1.1       maekawa  1421:       }else  errorStackmachine("Usage:newcontext");
                   1422:       break;
                   1423:     default:
                   1424:       errorStackmachine("Usage:newcontext");
                   1425:       break;
                   1426:     }
                   1427:     break;
                   1428:
                   1429:   case Ssetcontext:
                   1430:     ob1 = Kpop();
                   1431:     switch(ob1.tag) {
                   1432:     case Sclass:
                   1433:       KsetContext(ob1);
                   1434:       break;
                   1435:     default:
                   1436:       errorStackmachine("Usage:setcontext");
                   1437:       break;
                   1438:     }
                   1439:     break;
                   1440:
                   1441:   case Ssupercontext:
                   1442:     ob1 = Kpop();
                   1443:     switch(ob1.tag) {
                   1444:     case Sclass:
                   1445:       Kpush(getSuperContext(ob1));
                   1446:       break;
                   1447:     default:
                   1448:       errorStackmachine("Usage:supercontext");
                   1449:       break;
                   1450:     }
                   1451:     break;
                   1452:
                   1453:   case Ssendmsg:
                   1454:     /* ob2 { .........} sendmsg */
                   1455:     /* cf. debug/kobj.sm1    */
                   1456:     ob1 = Kpop();
                   1457:     ob2 = Kpop();
                   1458:     switch(ob1.tag) {
                   1459:     case SexecutableArray: break;
                   1460:     default: errorStackmachine("Usage:sendmsg");
                   1461:     }
                   1462:     ccflag = 0;
                   1463:     if (ob2.tag == Sarray ) {
                   1464:       if (getoaSize(ob2) >= 1) {
1.4       takayama 1465:         ob3 = getoa(ob2,0);
                   1466:         if (ectag(ob3) == CLASSNAME_CONTEXT) {
                   1467:           contextControl(CCPUSH); ccflag = 1; /* push the current context. */
                   1468:           CurrentContextp = (struct context *)ecbody(ob3);
                   1469:         }
1.1       maekawa  1470:       }
                   1471:     }
                   1472:     if (!ccflag) {
                   1473:       contextControl(CCPUSH); ccflag = 1;
                   1474:       CurrentContextp = PrimitiveContextp;
                   1475:     }
                   1476:     /* normal exec. */
                   1477:     Kpush(ob2);
1.15      takayama 1478:     status = executeExecutableArray(ob1,(char *)NULL,0);
1.13      takayama 1479:
1.1       maekawa  1480:     if (ccflag) {
                   1481:       contextControl(CCPOP); ccflag = 0; /* recover the Current context. */
                   1482:     }
1.14      takayama 1483:
1.1       maekawa  1484:     break;
                   1485:   case Ssendmsg2:
                   1486:     /* ob2 ob4 { .........} sendmsg2 */
                   1487:     /* Context is determined by ob2 or ob1 */
                   1488:     ob1 = Kpop();
                   1489:     ob4 = Kpop();
                   1490:     ob2 = Kpop();
                   1491:     switch(ob1.tag) {
                   1492:     case SexecutableArray: break;
                   1493:     default: errorStackmachine("Usage:sendmsg2");
                   1494:     }
                   1495:     ccflag = 0;
                   1496:     if (ob2.tag == Sarray ) {
                   1497:       if (getoaSize(ob2) >= 1) {
1.4       takayama 1498:         ob3 = getoa(ob2,0);
                   1499:         if (ectag(ob3) == CLASSNAME_CONTEXT) {
                   1500:           contextControl(CCPUSH); ccflag = 1; /* push the current context. */
                   1501:           CurrentContextp = (struct context *)ecbody(ob3);
                   1502:         }
1.1       maekawa  1503:       }
                   1504:     }
                   1505:     if (!ccflag && ob4.tag == Sarray) {
                   1506:       if (getoaSize(ob4) >= 1) {
1.4       takayama 1507:         ob3 = getoa(ob4,0);
                   1508:         if (ectag(ob3) == CLASSNAME_CONTEXT) {
                   1509:           contextControl(CCPUSH); ccflag = 1; /* push the current context. */
                   1510:           CurrentContextp = (struct context *)ecbody(ob3);
                   1511:         }
1.1       maekawa  1512:       }
                   1513:     }
                   1514:     if (!ccflag) {
                   1515:       contextControl(CCPUSH); ccflag = 1;
                   1516:       CurrentContextp = PrimitiveContextp;
                   1517:     }
                   1518:     /* normal exec. */
                   1519:     Kpush(ob2); Kpush(ob4);
1.14      takayama 1520:
                   1521:     /* We cannot use executeExecutableArray(ob1,(char *)NULL) because of
                   1522:        the quote mode. Think about it later. */
1.1       maekawa  1523:     tokenArray = ob1.lc.tokenArray;
                   1524:     size = ob1.rc.ival;
                   1525:     for (i=0; i<size; i++) {
                   1526:       token = tokenArray[i];
1.10      takayama 1527:       InSendmsg2 = 1;
1.1       maekawa  1528:       status = executeToken(token);
1.10      takayama 1529:       InSendmsg2 = 0;
1.13      takayama 1530:
                   1531:       if (status & STATUS_INFIX) {
                   1532:                if (status & DO_QUOTE) errorStackmachine("infix op with DO_QUOTE\n");
                   1533:         if (i == size-1) errorStackmachine("infix operator at the end(sendmsg2).\n");
                   1534:         infixOn = 1; infixToken = tokenArray[i];
                   1535:         infixToken.tflag |= NO_DELAY; continue;
                   1536:       }else if (infixOn) {
                   1537:         infixOn = 0; status = executeToken(infixToken);
                   1538:         if (status & STATUS_BREAK) break;
                   1539:       }
                   1540:
                   1541:       if (QuoteMode && (status & DO_QUOTE)) {
1.8       takayama 1542:         /* generate tree object, for kan/k0 */
                   1543:         struct object qob;
                   1544:         struct object qattr;
                   1545:         struct object qattr2;
                   1546:         if (i==0) { Kpop(); Kpop();}
                   1547:         qob = newObjectArray(3);
                   1548:         qattr = newObjectArray(1);
                   1549:         qattr2 = newObjectArray(2);
                   1550:                /* Set the node name of the tree. */
                   1551:         if (token.kind == ID) {
                   1552:           putoa(qob,0,KpoString(token.token));
                   1553:         }else{
                   1554:           putoa(qob,0,KpoString("unknown"));
                   1555:         }
                   1556:         /* Set the attibute list; class=className */
                   1557:         if (ob2.tag == Sdollar) {
1.11      takayama 1558:           putoa(qattr2,0,KpoString("cd"));
1.8       takayama 1559:           putoa(qattr2,1,ob2);
                   1560:         }else{
1.11      takayama 1561:           putoa(qattr2,0,KpoString("class"));
1.8       takayama 1562:           putoa(qattr2,1,KpoString(CurrentContextp->contextName));
                   1563:         }
                   1564:         putoa(qattr,0,qattr2);
                   1565:         putoa(qob,1,qattr);
                   1566:         putoa(qob,2,ob4);  /* Argument */
                   1567:         qob = KpoTree(qob);
                   1568:         Kpush(qob);
1.13      takayama 1569:       } else if (status & STATUS_BREAK) break;
                   1570:
1.1       maekawa  1571:     }
                   1572:     if (ccflag) {
                   1573:       contextControl(CCPOP); ccflag = 0;
                   1574:       /* recover the Current context. */
                   1575:       /* Note that it is not recovered in case of error. */
                   1576:     }
                   1577:
                   1578:     break;
                   1579:   case Sprimmsg:
                   1580:     /* { .........} primmsg */
                   1581:     /* Context is PrimitiveContext. */
                   1582:     ob1 = Kpop();
                   1583:     switch(ob1.tag) {
                   1584:     case SexecutableArray: break;
                   1585:     default: errorStackmachine("Usage:primmsg");
                   1586:     }
                   1587:     contextControl(CCPUSH); ccflag = 1;
                   1588:     CurrentContextp = PrimitiveContextp;
                   1589:     /* normal exec. */
1.15      takayama 1590:     status = executeExecutableArray(ob1,(char *)NULL,0);
1.1       maekawa  1591:     contextControl(CCPOP); /* recover the Current context. */
                   1592:     break;
                   1593:
                   1594:   case Ssupmsg2:
                   1595:     /* ob2 ob4 { .........} supmsg2 */
                   1596:     /* Context is super class of ob2 */
                   1597:     ob1 = Kpop();
                   1598:     ob4 = Kpop();
                   1599:     ob2 = Kpop();
                   1600:     switch(ob1.tag) {
                   1601:     case SexecutableArray: break;
                   1602:     default: errorStackmachine("Usage:supmsg2");
                   1603:     }
                   1604:     ccflag = 0;
                   1605:     if (ob2.tag == Sarray ) {
                   1606:       if (getoaSize(ob2) >= 1) {
1.4       takayama 1607:         ob3 = getoa(ob2,0);
                   1608:         if (ectag(ob3) == CLASSNAME_CONTEXT) {
                   1609:           if (((struct context *)ecbody(ob3))->super == NULL) {
                   1610:             errorStackmachine("supmsg2: SuperClass is NIL.");
                   1611:           }
                   1612:           contextControl(CCPUSH); ccflag = 1; /* push the current context. */
                   1613:           CurrentContextp = ((struct context *)ecbody(ob3))->super;
                   1614:         }
1.1       maekawa  1615:       }
                   1616:     }
                   1617:     if (!ccflag && (ob4.tag == Sarray) ) {
                   1618:       if (getoaSize(ob4) >= 1) {
1.4       takayama 1619:         ob3 = getoa(ob4,0);
                   1620:         if (ectag(ob3) == CLASSNAME_CONTEXT) {
                   1621:           if (((struct context *)ecbody(ob3))->super == NULL) {
                   1622:             errorStackmachine("supmsg2: SuperClass is NIL.");
                   1623:           }
                   1624:           contextControl(CCPUSH); ccflag = 1; /* push the current context. */
                   1625:           CurrentContextp = ((struct context *)ecbody(ob3))->super;
                   1626:         }
1.1       maekawa  1627:       }
                   1628:     }
                   1629:     if (!ccflag) {
                   1630:       contextControl(CCPUSH); ccflag = 1;
                   1631:       CurrentContextp = PrimitiveContextp;
                   1632:     }
                   1633:     /* normal exec. */
                   1634:     Kpush(ob2); Kpush(ob4);
1.15      takayama 1635:     status = executeExecutableArray(ob1,(char *)NULL,0);
1.1       maekawa  1636:     if (ccflag) {
                   1637:       contextControl(CCPOP); ccflag = 0; /* recover the Current context. */
                   1638:     }
                   1639:
                   1640:     break;
                   1641:
                   1642:   case Serror:
                   1643:     ob1 = peek(0);
                   1644:     if (ob1.tag == Sdollar) {
                   1645:       /* compose error message */
                   1646:       ob = Kpop();
                   1647:       str = (char *) sGC_malloc(sizeof(char)*(strlen("error operator : ")+
1.4       takayama 1648:                                               strlen(KopString(ob1))+ 10));
1.1       maekawa  1649:       if (str == NULL) errorStackmachine("No more memory.");
                   1650:       strcpy(str,"error operator : ");
                   1651:       strcat(str,KopString(ob1));
                   1652:       errorStackmachine(str);
                   1653:     }else{
                   1654:       errorStackmachine("error operator.");
                   1655:     }
                   1656:     break;
                   1657:   case Smpzext:
                   1658:     ob1 = Kpop();
                   1659:     Kpush(KmpzExtension(ob1));
                   1660:     break;
                   1661:
                   1662:   case Scclass:
                   1663:     ob3 = Kpop();
                   1664:     ob2 = Kpop();
                   1665:     ob1 = Kpop();
                   1666:     /* [class-tag super-obj] size [class-tag]  cclass */
                   1667:     Kpush(KcreateClassIncetance(ob1,ob2,ob3));
                   1668:     break;
                   1669:
                   1670:   case Stest:
                   1671:     /* test is used for a test of a new function. */
                   1672:     ob2 = Kpop();
                   1673:     ob1 = Kpop();
                   1674:     Kpush(hilberto(ob1,ob2));
                   1675:     /*
1.4       takayama 1676:       {
                   1677:       ob1 = Kpop();
                   1678:       Kpush(test(ob1));
1.1       maekawa  1679:
1.4       takayama 1680:       }
1.1       maekawa  1681:     */
1.9       takayama 1682:     break;
                   1683:
                   1684:   case Soxshell:
                   1685:     ob1 = Kpop();
                   1686:     Kpush(KoxShell(ob1));
1.1       maekawa  1687:     break;
1.5       takayama 1688:
                   1689:   case Stlimit:
                   1690:     /* {   } time tlimit */
                   1691:     ob2 = Kpop();
                   1692:     ob1 = Kpop();
                   1693:     switch(ob2.tag) {
                   1694:        case Sinteger: break;
                   1695:        default: errorStackmachine("Usage:tlimit"); break;
                   1696:        }
                   1697:     switch(ob1.tag) {
                   1698:     case SexecutableArray: break;
                   1699:     default:
                   1700:       errorStackmachine("Usage:tlimit");
                   1701:       break;
                   1702:     }
                   1703:        n = ob2.lc.ival;
                   1704:        if (n > 0) {
                   1705:          signal(SIGALRM,ctrlC); alarm((unsigned int) n);
1.15      takayama 1706:       status = executeExecutableArray(ob1,(char *)NULL,0);
1.5       takayama 1707:          cancelAlarm();
                   1708:        }else{
                   1709:       before_real = time(&before_real);
                   1710:       times(&before);
1.15      takayama 1711:       status = executeExecutableArray(ob1,(char *)NULL,0);
1.5       takayama 1712:       times(&after);
                   1713:       after_real = time(&after_real);
                   1714:          ob1 = newObjectArray(3);
                   1715:          putoa(ob1,0,KpoInteger((int) after.tms_utime - before.tms_utime));
                   1716:          putoa(ob1,1,KpoInteger((int) after.tms_stime - before.tms_stime));
                   1717:          putoa(ob1,2,KpoInteger((int) (after_real-before_real)));
                   1718:          Kpush(ob1);
                   1719:     }
                   1720:        break;
1.1       maekawa  1721:
                   1722:
                   1723:   default:
                   1724:     errorStackmachine("Unknown Soperator type. \n");
                   1725:   }
                   1726:   return(0);  /* normal exit */
                   1727: }
                   1728:
                   1729:

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>