[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.12

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

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