=================================================================== RCS file: /home/cvs/OpenXM/src/kan96xx/Kan/stackmachine.c,v retrieving revision 1.1.1.1 retrieving revision 1.13 diff -u -p -r1.1.1.1 -r1.13 --- OpenXM/src/kan96xx/Kan/stackmachine.c 1999/10/08 02:12:01 1.1.1.1 +++ OpenXM/src/kan96xx/Kan/stackmachine.c 2003/11/20 09:20:36 1.13 @@ -1,3 +1,4 @@ +/* $OpenXM: OpenXM/src/kan96xx/Kan/stackmachine.c,v 1.12 2002/11/07 23:35:23 takayama Exp $ */ /* stackmachin.c */ #include @@ -13,7 +14,8 @@ /* #define OPERAND_STACK_SIZE 2000 */ #define OPERAND_STACK_SIZE 30000 #define SYSTEM_DICTIONARY_SIZE 200 -#define USER_DICTIONARY_SIZE 1223 +/* #define USER_DICTIONARY_SIZE 1223, 3581, 27449 */ +#define USER_DICTIONARY_SIZE 59359 /* The value of USER_DICTIONARY_SIZE must be prime number, because of hashing method */ #define ARGV_WORK_MAX (AGLIMIT+100) @@ -72,6 +74,7 @@ static void pstack(void); static struct object executableStringToExecutableArray(char *str); extern int SerialCurrent; +extern int QuoteMode; int SGClock = 0; int UserCtrlC = 0; @@ -90,7 +93,7 @@ struct object * newObject() } struct object newObjectArray(size) -int size; + int size; { struct object rob; struct object *op; @@ -108,15 +111,15 @@ int size; } isNullObject(obj) -struct object obj; + struct object obj; { if (obj.tag == 0) return(1); else return(0); } int putSystemDictionary(str,ob) -char *str; /* key */ -struct object ob; /* value */ + char *str; /* key */ + struct object ob; /* value */ { int i; int j; @@ -126,8 +129,8 @@ struct object ob; /* value */ /*printf("Add %d %s\n",i,str);*/ if (strcmp(str,(SystemDictionary[i]).key) > 0) { for (j=Sdp-1; j>=i+1; j--) { - (SystemDictionary[j+1]).key = (SystemDictionary[j]).key; - (SystemDictionary[j+1]).obj = (SystemDictionary[j]).obj; + (SystemDictionary[j+1]).key = (SystemDictionary[j]).key; + (SystemDictionary[j+1]).obj = (SystemDictionary[j]).obj; } (SystemDictionary[i+1]).key = str; (SystemDictionary[i+1]).obj = ob; @@ -167,15 +170,15 @@ int findSystemDictionary(str) return(0); } else if (first == last) { if (strcmp(str,(SystemDictionary[first]).key) == 0) { - return((SystemDictionary[first]).obj.lc.ival); + return((SystemDictionary[first]).obj.lc.ival); }else { - return(0); + return(0); } } else if (last - first == 1) { /* This case is necessary */ if (strcmp(str,(SystemDictionary[first]).key) == 0) { - return((SystemDictionary[first]).obj.lc.ival); + return((SystemDictionary[first]).obj.lc.ival); }else if (strcmp(str,(SystemDictionary[last]).key) == 0) { - return((SystemDictionary[last]).obj.lc.ival); + return((SystemDictionary[last]).obj.lc.ival); }else return(0); } @@ -192,10 +195,10 @@ int findSystemDictionary(str) } int putUserDictionary(str,h0,h1,ob,dic) -char *str; /* key */ -int h0,h1; /* Hash values of the key */ -struct object ob; /* value */ -struct dictionary *dic; + char *str; /* key */ + int h0,h1; /* Hash values of the key */ + struct object ob; /* value */ + struct dictionary *dic; { int x,r; extern int Strict2; @@ -240,10 +243,10 @@ struct object KputUserDictionary(char *str,struct obje } struct object findUserDictionary(str,h0,h1,cp) -/* returns NoObject, if there is no item. */ -char *str; /* key */ -int h0,h1; /* The hashing values of the key. */ -struct context *cp; + /* returns NoObject, if there is no item. */ + char *str; /* key */ + int h0,h1; /* The hashing values of the key. */ + struct context *cp; { int x; struct dictionary *dic; @@ -269,10 +272,10 @@ struct object KfindUserDictionary(char *str) { } int putUserDictionary2(str,h0,h1,attr,dic) -char *str; /* key */ -int h0,h1; /* Hash values of the key */ -int attr; /* attribute field */ -struct dictionary *dic; + char *str; /* key */ + int h0,h1; /* Hash values of the key */ + int attr; /* attribute field */ + struct dictionary *dic; { int x; int i; @@ -300,8 +303,8 @@ struct dictionary *dic; int putPrimitiveFunction(str,number) -char *str; -int number; + char *str; + int number; { struct object ob; ob.tag = Soperator; @@ -310,7 +313,7 @@ int number; } struct tokens lookupTokens(t) -struct tokens t; + struct tokens t; { struct object *left; struct object *right; @@ -326,7 +329,7 @@ struct tokens t; } struct object lookupLiteralString(s) -char *s; /* s must be a literal string */ + char *s; /* s must be a literal string */ { struct object ob; ob.tag = Slist; @@ -340,7 +343,7 @@ char *s; /* s must be a literal string */ int hash0(str) -char *str; + char *str; { int h=0; while (*str != '\0') { @@ -351,7 +354,7 @@ char *str; } int hash1(str) -char *str; + char *str; { return(8-(str[0]%8)); } @@ -365,7 +368,7 @@ void hashInitialize(struct dictionary *dic) } static isInteger(str) -char *str; + char *str; { int i; int n; @@ -386,7 +389,7 @@ char *str; } static strToInteger(str) -char *str; + char *str; { int i; int n; @@ -407,15 +410,15 @@ char *str; } static power(s,i) -int s; -int i; + int s; + int i; { if (i == 0) return 1; else return( s*power(s,i-1) ); } int Kpush(ob) -struct object ob; + struct object ob; { OperandStack[Osp++] = ob; if (Osp >= OspMax) { @@ -436,7 +439,7 @@ struct object Kpop() } struct object peek(k) -int k; + int k; { if ((Osp-k-1) < 0) { return( NullObject ); @@ -585,7 +588,7 @@ void contextControl(actionOfContextControl ctl) { int isLiteral(str) -char *str; + char *str; { if (strlen(str) <2) return(0); else { @@ -610,7 +613,7 @@ void printOperandStack() { static initSystemDictionary() - { +{ StandardStack.ostack = StandardStackA; StandardStack.sp = StandardStackP; StandardStack.size = OPERAND_STACK_SIZE; @@ -625,7 +628,7 @@ static initSystemDictionary() KdefinePrimitiveFunctions(); - } +} struct object showSystemDictionary(int f) { int i; @@ -676,7 +679,7 @@ int showUserDictionary() for (i=0; imaxl) - maxl = strlen((dic[i]).key); + maxl = strlen((dic[i]).key); } } maxl += 3; @@ -687,12 +690,12 @@ int showUserDictionary() if ((dic[i]).key != EMPTY) { fprintf(Fstack,format,(dic[i]).key); /*{ char *sss; int ii,h0,h1; - sss = dic[i].key; - h0 = dic[i].h0; - h1 = dic[i].h1; - for (ii=0; ii= 1) { - fprintf(Fstack,"\nscanner> "); + fprintf(Fstack,"\nscanner> "); } KSexecuteString(" ctrlC-hook "); /* Execute User Defined functions. */ + KSexecuteString(" (Computation is interrupted.) "); /* move to ctrlC-hook? */ + continue ; } else { } if (DebugStack >= 1) { printOperandStack(); } token = getokenSM(GET); @@ -816,7 +829,7 @@ void scanner() { void ctrlC(sig) -int sig; + int sig; { extern void ctrlC(); extern int ErrorMessageMode; @@ -826,11 +839,15 @@ int sig; signal(sig,SIG_IGN); /* see 133p */ + cancelAlarm(); + if (sig == SIGALRM) { + fprintf(stderr,"ctrlC by SIGALRM\n"); + } if (SGClock) { UserCtrlC = 1; fprintf(stderr,"ctrl-c is locked because of gc.\n"); - signal(SIGINT,ctrlC); + signal(sig,ctrlC); if (sig == SIGALRM) alarm((unsigned int)10); return; } if (OXlock) { @@ -843,7 +860,7 @@ int sig; unlockCtrlCForOx(); } fprintf(stderr,"ctrl-c is locked because of ox lock %d.\n",UserCtrlC); - signal(SIGINT,ctrlC); + signal(sig,ctrlC); if (sig == SIGALRM) alarm((unsigned int)10); return; } if (ErrorMessageMode != 1) { @@ -864,11 +881,15 @@ int sig; */ getokenSM(INIT); /* It might fix the bug above. 1992/11/14 */ signal(SIGINT,ctrlC); +#if defined(__CYGWIN__) + siglongjmp(EnvOfStackMachine,2); +#else longjmp(EnvOfStackMachine,2); /* returns 2 for ctrl-C */ +#endif } int executeToken(token) -struct tokens token; + struct tokens token; { struct object ob; int primitive; @@ -882,8 +903,8 @@ struct tokens token; if (GotoP) { /* for goto */ if (token.kind == ID && isLiteral(token.token)) { if (strcmp(&((token.token)[1]),GotoLabel) == 0) { - GotoP = 0; - return(0); /* normal exit */ + GotoP = 0; + return(0); /* normal exit */ } } return(0); /* normal exit */ @@ -905,8 +926,8 @@ struct tokens token; strcpy(ob.lc.str, &((token.token)[1])); if (token.object.tag != Slist) { - fprintf(Fstack,"\n%%Warning: The hashing values for the <<%s>> are not set.\n",token.token); - token.object = lookupLiteralString(token.token); + fprintf(Fstack,"\n%%Warning: The hashing values for the <<%s>> are not set.\n",token.token); + token.object = lookupLiteralString(token.token); } ob.rc.op = token.object.lc.op; Kpush(ob); @@ -917,46 +938,49 @@ struct tokens token; Kpush(ob); } else { if (token.object.tag != Slist) { - fprintf(Fstack,"\n%%Warning: The hashing values for the <<%s>> are not set.\n",token.token); - token = lookupTokens(token); + fprintf(Fstack,"\n%%Warning: The hashing values for the <<%s>> are not set.\n",token.token); + token = lookupTokens(token); } h0 = ((token.object.lc.op)->lc).ival; h1 = ((token.object.lc.op)->rc).ival; ob=findUserDictionary(token.token,h0,h1,CurrentContextp); primitive = ((token.object.rc.op)->lc).ival; if (ob.tag >= 0) { - /* there is a definition in the user dictionary */ - if (ob.tag == SexecutableArray) { - tokenArray = ob.lc.tokenArray; - size = ob.rc.ival; - for (i=0; i> is not in the system dictionary\n%% nor in the user dictionaries. Push NullObject.\n",token.token); - }else {strcpy(tmpc,"Warning: identifier is not in the dictionaries.");} - pushErrorStack(KnewErrorPacket(SerialCurrent,-1,tmpc)); - } - if (WarningMessageMode != 1) { - fprintf(Fstack,"\n%%Warning: The identifier <<%s>> is not in the system dictionary\n%% nor in the user dictionaries. Push NullObject.\n",token.token); - /*fprintf(Fstack,"(%d,%d)\n",h0,h1);*/ - } - if (Strict) { - errorStackmachine("Warning: identifier is not in the dictionaries"); - } - Kpush(NullObject); + if (QuoteMode) { + return(DO_QUOTE); + } + if (WarningMessageMode == 1 || WarningMessageMode == 2) { + char tmpc[1024]; + if (strlen(token.token) < 900) { + sprintf(tmpc,"\n%%Warning: The identifier <<%s>> is not in the system dictionary\n%% nor in the user dictionaries. Push NullObject.\n",token.token); + }else {strcpy(tmpc,"Warning: identifier is not in the dictionaries.");} + pushErrorStack(KnewErrorPacket(SerialCurrent,-1,tmpc)); + } + if (WarningMessageMode != 1) { + fprintf(Fstack,"\n%%Warning: The identifier <<%s>> is not in the system dictionary\n%% nor in the user dictionaries. Push NullObject.\n",token.token); + /*fprintf(Fstack,"(%d,%d)\n",h0,h1);*/ + } + if (Strict) { + errorStackmachine("Warning: identifier is not in the dictionaries"); + } + Kpush(NullObject); } } } else if (token.kind == EXECUTABLE_STRING) { @@ -982,13 +1006,14 @@ struct tokens token; errorStackmachine(str) -char *str; + char *str; { int i,j,k; static char *u="Usage:"; char message0[1024]; char *message; extern int ErrorMessageMode; + cancelAlarm(); if (ErrorMessageMode == 1 || ErrorMessageMode == 2) { pushErrorStack(KnewErrorPacket(SerialCurrent,-1,str)); } @@ -1002,20 +1027,20 @@ char *str; if (i==6) { fprintf(stderr,"ERROR(sm): \n"); while (str[i] != '\0' && str[i] != ' ') { - i++; + i++; } if (str[i] == ' ') { - fprintf(stderr," %s\n",&(str[i+1])); - k = 0; - if (i-6 > 1022) message = (char *)sGC_malloc(sizeof(char)*i); - for (j=6; j 1022) message = (char *)sGC_malloc(sizeof(char)*i); + for (j=6; j