=================================================================== RCS file: /home/cvs/OpenXM/src/kan96xx/Kan/primitive.c,v retrieving revision 1.15 retrieving revision 1.26 diff -u -p -r1.15 -r1.26 --- OpenXM/src/kan96xx/Kan/primitive.c 2004/09/12 10:22:50 1.15 +++ OpenXM/src/kan96xx/Kan/primitive.c 2020/10/06 11:33:46 1.26 @@ -1,16 +1,22 @@ -/* $OpenXM: OpenXM/src/kan96xx/Kan/primitive.c,v 1.14 2004/09/12 08:55:36 takayama Exp $ */ +/* $OpenXM: OpenXM/src/kan96xx/Kan/primitive.c,v 1.25 2018/09/07 00:15:44 takayama Exp $ */ /* primitive.c */ /* The functions in this module were in stackmachine.c */ #include +#include +#include #include +#include +#include #include "datatype.h" #include "stackm.h" #include "extern.h" +#include "extern2.h" #include "gradedset.h" #include "kclass.h" #include #include +#include "mysig.h" int PrintDollar = 1; /* flag for printObject() */ int PrintComma = 1; /* flag for printObject() */ @@ -40,6 +46,9 @@ static char *operatorType(type) return("Unknown operator"); } +#define evalEA(ob1) if (ob1.tag == SexecutableArray) {\ + executeExecutableArray(ob1,(char *)NULL,0); ob1 = Kpop();} + /****** primitive functions ***************************************** the values must be greater than 1. 0 is used for special purposes.*/ #define Sadd 1 @@ -197,6 +206,9 @@ void printObject(ob,nl,fp) case Sdouble: fprintf(fp," "); break; + case SbyteArray: + fprintf(fp," "); + break; default: fprintf(fp,"",ob.tag); break; @@ -271,7 +283,7 @@ void printObject(ob,nl,fp) printObjectList(&ob); break; case Sfile: - fprintf(fp,"Name=%s, FILE *=%x ",ob.lc.str,(int) ob.rc.file); + fprintf(fp,"Name=%s, FILE *=%p ",ob.lc.str,ob.rc.file); break; case Sring: fprintf(fp,"Ring."); KshowRing(KopRingp(ob)); @@ -291,6 +303,9 @@ void printObject(ob,nl,fp) case Sdouble: fprintf(fp,"%f",KopDouble(ob)); break; + case SbyteArray: + printObject(byteArrayToArray(ob),nl,fp); /* Todo: I should save memory.*/ + break; default: fprintf(fp,"[Unknown object tag.]"); break; @@ -413,12 +428,12 @@ void KdefinePrimitiveFunctions() { int executePrimitive(ob) struct object ob; { - struct object ob1; - struct object ob2; - struct object ob3; - struct object ob4; - struct object ob5; - struct object rob; + struct object ob1 = OINIT; + struct object ob2 = OINIT; + struct object ob3 = OINIT; + struct object ob4 = OINIT; + struct object ob5 = OINIT; + struct object rob = OINIT; struct object obArray[OB_ARRAY_MAX]; struct object obArray2[OB_ARRAY_MAX]; int size; @@ -431,18 +446,19 @@ int executePrimitive(ob) FILE *fp; char *fname; int rank; - struct object oMat; + struct object oMat = OINIT; static int timerStart = 1; static struct tms before, after; static time_t before_real, after_real; - struct object oInput; + struct object oInput = OINIT; char *str; int ccflag = 0; extern int KeepInput; extern int History; extern struct ring *CurrentRingp; - extern TimerOn; - extern SecureMode; + extern int TimerOn; + extern int SecureMode; + extern int RestrictedMode; infixOn = 0; @@ -450,6 +466,18 @@ int executePrimitive(ob) fprintf(Fstack,"In execute %d\n",ob.lc.ival); printOperandStack(); } + if (RestrictedMode) { + switch(ob.lc.ival) { + case SleftBrace: + case SrightBrace: + case Sexec: + break; + default: + fprintf(stderr,"primitive No = %d : ", ob.lc.ival); + errorStackmachine("You cannot use this primitive in the RestrictedMode.\n"); + } + } + if (GotoP) return(0); switch (ob.lc.ival) { /* Postscript primitives :stack */ @@ -498,6 +526,11 @@ int executePrimitive(ob) } Kpush(ob3); break; + case SbyteArray: + n = getByteArraySize(ob2); + ob3 = newByteArray(n,ob2); + Kpush(ob3); + break; default: Kpush(ob2); break; @@ -540,31 +573,36 @@ int executePrimitive(ob) /* Postscript primitives :arithmetic */ case Sadd: - ob1 = Kpop(); + ob1 = Kpop(); ob2 = Kpop(); + evalEA(ob1); evalEA(ob2); rob = KooAdd(ob1,ob2); Kpush(rob); break; case Ssub: ob2 = Kpop(); ob1 = Kpop(); + evalEA(ob1); evalEA(ob2); rob = KooSub(ob1,ob2); Kpush(rob); break; case Smult: ob2 = Kpop(); ob1 = Kpop(); + evalEA(ob1); evalEA(ob2); rob = KooMult(ob1,ob2); Kpush(rob); break; case Sidiv: ob2 = Kpop(); ob1 = Kpop(); + evalEA(ob1); evalEA(ob2); rob = KooDiv(ob1,ob2); Kpush(rob); break; case Sdiv: ob2 = Kpop(); ob1 = Kpop(); + evalEA(ob1); evalEA(ob2); rob = KooDiv2(ob1,ob2); Kpush(rob); break; @@ -609,6 +647,8 @@ int executePrimitive(ob) /* Or; [[a_00 ....] [a_10 ....] ....] [1 0] any put. MultiIndex. */ ob1 = Kpop(); ob2 = Kpop(); ob3 = Kpop(); switch(ob2.tag) { + case SuniversalNumber: + ob2 = Kto_int32(ob2); /* do not break and go to Sinteger */ case Sinteger: switch(ob3.tag) { case Sarray: @@ -633,6 +673,17 @@ int executePrimitive(ob) errorStackmachine("Index is out of bound. (put)\n"); } break; + case SbyteArray: + i = ob2.lc.ival; + size = getByteArraySize(ob3); + if ((0 <= i) && (i 0) { - signal(SIGALRM,ctrlC); alarm((unsigned int) n); + mysignal(SIGALRM,ctrlC); alarm((unsigned int) n); status = executeExecutableArray(ob1,(char *)NULL,0); cancelAlarm(); }else{