version 1.12, 2004/09/11 01:00:42 |
version 1.17, 2004/09/16 02:22:03 |
|
|
/* $OpenXM: OpenXM/src/kan96xx/Kan/primitive.c,v 1.11 2003/12/05 23:14:14 takayama Exp $ */ |
/* $OpenXM: OpenXM/src/kan96xx/Kan/primitive.c,v 1.16 2004/09/12 10:58:28 takayama Exp $ */ |
/* primitive.c */ |
/* primitive.c */ |
/* The functions in this module were in stackmachine.c */ |
/* The functions in this module were in stackmachine.c */ |
|
|
Line 40 static char *operatorType(type) |
|
Line 40 static char *operatorType(type) |
|
return("Unknown operator"); |
return("Unknown operator"); |
} |
} |
|
|
|
#define evalEA(ob1) if (ob1.tag == SexecutableArray) {\ |
|
executeExecutableArray(ob1,(char *)NULL,0); ob1 = Kpop();} |
|
|
/****** primitive functions ***************************************** |
/****** primitive functions ***************************************** |
the values must be greater than 1. 0 is used for special purposes.*/ |
the values must be greater than 1. 0 is used for special purposes.*/ |
#define Sadd 1 |
#define Sadd 1 |
Line 424 int executePrimitive(ob) |
|
Line 427 int executePrimitive(ob) |
|
int size; |
int size; |
int i,j,k,n; |
int i,j,k,n; |
int status; |
int status; |
|
int infixOn; |
|
struct tokens infixToken; |
struct tokens *tokenArray; |
struct tokens *tokenArray; |
struct tokens token; |
struct tokens token; |
FILE *fp; |
FILE *fp; |
Line 442 int executePrimitive(ob) |
|
Line 447 int executePrimitive(ob) |
|
extern TimerOn; |
extern TimerOn; |
extern SecureMode; |
extern SecureMode; |
|
|
|
infixOn = 0; |
|
|
if (DebugStack >= 2) { |
if (DebugStack >= 2) { |
fprintf(Fstack,"In execute %d\n",ob.lc.ival); printOperandStack(); |
fprintf(Fstack,"In execute %d\n",ob.lc.ival); printOperandStack(); |
} |
} |
Line 536 int executePrimitive(ob) |
|
Line 543 int executePrimitive(ob) |
|
|
|
/* Postscript primitives :arithmetic */ |
/* Postscript primitives :arithmetic */ |
case Sadd: |
case Sadd: |
ob1 = Kpop(); |
ob1 = Kpop(); |
ob2 = Kpop(); |
ob2 = Kpop(); |
|
evalEA(ob1); evalEA(ob2); |
rob = KooAdd(ob1,ob2); |
rob = KooAdd(ob1,ob2); |
Kpush(rob); |
Kpush(rob); |
break; |
break; |
case Ssub: |
case Ssub: |
ob2 = Kpop(); |
ob2 = Kpop(); |
ob1 = Kpop(); |
ob1 = Kpop(); |
|
evalEA(ob1); evalEA(ob2); |
rob = KooSub(ob1,ob2); |
rob = KooSub(ob1,ob2); |
Kpush(rob); |
Kpush(rob); |
break; |
break; |
case Smult: |
case Smult: |
ob2 = Kpop(); |
ob2 = Kpop(); |
ob1 = Kpop(); |
ob1 = Kpop(); |
|
evalEA(ob1); evalEA(ob2); |
rob = KooMult(ob1,ob2); |
rob = KooMult(ob1,ob2); |
Kpush(rob); |
Kpush(rob); |
break; |
break; |
case Sidiv: |
case Sidiv: |
ob2 = Kpop(); ob1 = Kpop(); |
ob2 = Kpop(); ob1 = Kpop(); |
|
evalEA(ob1); evalEA(ob2); |
rob = KooDiv(ob1,ob2); |
rob = KooDiv(ob1,ob2); |
Kpush(rob); |
Kpush(rob); |
break; |
break; |
|
|
case Sdiv: |
case Sdiv: |
ob2 = Kpop(); ob1 = Kpop(); |
ob2 = Kpop(); ob1 = Kpop(); |
|
evalEA(ob1); evalEA(ob2); |
rob = KooDiv2(ob1,ob2); |
rob = KooDiv2(ob1,ob2); |
Kpush(rob); |
Kpush(rob); |
break; |
break; |
Line 605 int executePrimitive(ob) |
|
Line 617 int executePrimitive(ob) |
|
/* Or; [[a_00 ....] [a_10 ....] ....] [1 0] any put. MultiIndex. */ |
/* Or; [[a_00 ....] [a_10 ....] ....] [1 0] any put. MultiIndex. */ |
ob1 = Kpop(); ob2 = Kpop(); ob3 = Kpop(); |
ob1 = Kpop(); ob2 = Kpop(); ob3 = Kpop(); |
switch(ob2.tag) { |
switch(ob2.tag) { |
|
case SuniversalNumber: |
|
ob2 = Kto_int32(ob2); /* do not break and go to Sinteger */ |
case Sinteger: |
case Sinteger: |
switch(ob3.tag) { |
switch(ob3.tag) { |
case Sarray: |
case Sarray: |
Line 639 int executePrimitive(ob) |
|
Line 653 int executePrimitive(ob) |
|
if (ob5.tag != Sarray) |
if (ob5.tag != Sarray) |
errorStackmachine("Object pointed by the multi-index is not array (put)\n"); |
errorStackmachine("Object pointed by the multi-index is not array (put)\n"); |
ob4 = getoa(ob2,i); |
ob4 = getoa(ob2,i); |
|
if (ob4.tag == SuniversalNumber) ob4 = Kto_int32(ob4); |
if (ob4.tag != Sinteger) |
if (ob4.tag != Sinteger) |
errorStackmachine("Index has to be an integer. (put)\n"); |
errorStackmachine("Index has to be an integer. (put)\n"); |
k = ob4.lc.ival; |
k = ob4.lc.ival; |
Line 740 int executePrimitive(ob) |
|
Line 755 int executePrimitive(ob) |
|
errorStackmachine("Usage:loop"); |
errorStackmachine("Usage:loop"); |
break; |
break; |
} |
} |
tokenArray = ob1.lc.tokenArray; |
|
size = ob1.rc.ival; |
|
i = 0; |
|
while (1) { |
while (1) { |
token = tokenArray[i]; |
status = executeExecutableArray(ob1,(char *)NULL,1); |
/***printf("[token %d]%s\n",i,token.token);*/ |
if ((status & STATUS_BREAK) || GotoP) break; |
i++; |
|
if (i >= size) { |
|
i=0; |
|
} |
|
status = executeToken(token); |
|
if (status || GotoP) break; |
|
/* here, do not return 1. Do not propagate exit signal outside of the |
/* here, do not return 1. Do not propagate exit signal outside of the |
loop. */ |
loop. */ |
} |
} |
Line 789 int executePrimitive(ob) |
|
Line 795 int executePrimitive(ob) |
|
*/ |
*/ |
for ( ; i<=lim; i += inc) { |
for ( ; i<=lim; i += inc) { |
Kpush(KpoInteger(i)); |
Kpush(KpoInteger(i)); |
tokenArray = ob1.lc.tokenArray; |
status = executeExecutableArray(ob1,(char *)NULL,1); |
size = ob1.rc.ival; |
if ((status & STATUS_BREAK) || GotoP) goto xyz; |
for (j=0; j<size; j++) { |
} |
status = executeToken(tokenArray[j]); |
|
if (status || GotoP) goto xyz; |
|
} |
|
} |
|
}else{ |
}else{ |
/* |
/* |
if (lim > i) errorStackmachine("The initial value must not be less than limit value (for).\n"); |
if (lim > i) errorStackmachine("The initial value must not be less than limit value (for).\n"); |
*/ |
*/ |
for ( ; i>=lim; i += inc) { |
for ( ; i>=lim; i += inc) { |
Kpush(KpoInteger(i)); |
Kpush(KpoInteger(i)); |
tokenArray = ob1.lc.tokenArray; |
status = executeExecutableArray(ob1,(char *)NULL,1); |
size = ob1.rc.ival; |
if ((status & STATUS_BREAK) || GotoP) goto xyz; |
for (j=0; j<size; j++) { |
|
status = executeToken(tokenArray[j]); |
|
if (status || GotoP) goto xyz; |
|
} |
|
} |
} |
} |
} |
xyz: ; |
xyz: ; |
Line 838 int executePrimitive(ob) |
|
Line 836 int executePrimitive(ob) |
|
|
|
for (i=0; i<osize; i++) { |
for (i=0; i<osize; i++) { |
Kpush(getoa(ob1,i)); |
Kpush(getoa(ob1,i)); |
tokenArray = ob2.lc.tokenArray; |
status = executeExecutableArray(ob2,(char *)NULL,0); |
size = ob2.rc.ival; |
if (status & STATUS_BREAK) goto foor; |
for (j=0; j<size; j++) { |
|
status = executeToken(tokenArray[j]); |
|
if (status) goto foor; |
|
} |
|
} |
} |
foor: ; |
foor: ; |
/*KSexecuteString("]");*/ |
/*KSexecuteString("]");*/ |
Line 892 int executePrimitive(ob) |
|
Line 886 int executePrimitive(ob) |
|
ob1 = ob2; |
ob1 = ob2; |
} |
} |
/* execute ob1 */ |
/* execute ob1 */ |
tokenArray = ob1.lc.tokenArray; |
status = executeExecutableArray(ob1,(char *)NULL,0); |
size = ob1.rc.ival; |
if (status & STATUS_BREAK) return(status); |
for (i=0; i<size; i++) { |
|
token = tokenArray[i]; |
|
status = executeToken(token); |
|
if (status != 0) return(status); |
|
} |
|
|
|
break; |
break; |
|
|
case Sexec: |
case Sexec: |
Line 909 int executePrimitive(ob) |
|
Line 898 int executePrimitive(ob) |
|
case SexecutableArray: break; |
case SexecutableArray: break; |
default: errorStackmachine("Usage:exec"); |
default: errorStackmachine("Usage:exec"); |
} |
} |
tokenArray = ob1.lc.tokenArray; |
status = executeExecutableArray(ob1,(char *)NULL,0); |
size = ob1.rc.ival; |
|
for (i=0; i<size; i++) { |
|
token = tokenArray[i]; |
|
/***printf("[token %d]%s\n",i,token.token);*/ |
|
status = executeToken(token); |
|
if (status != 0) break; |
|
} |
|
break; |
break; |
|
|
/* Postscript primitives :dictionary */ |
/* Postscript primitives :dictionary */ |
Line 1496 int executePrimitive(ob) |
|
Line 1478 int executePrimitive(ob) |
|
} |
} |
/* normal exec. */ |
/* normal exec. */ |
Kpush(ob2); |
Kpush(ob2); |
tokenArray = ob1.lc.tokenArray; |
status = executeExecutableArray(ob1,(char *)NULL,0); |
size = ob1.rc.ival; |
|
for (i=0; i<size; i++) { |
|
token = tokenArray[i]; |
|
status = executeToken(token); |
|
if (status != 0) break; |
|
} |
|
if (ccflag) { |
if (ccflag) { |
contextControl(CCPOP); ccflag = 0; /* recover the Current context. */ |
contextControl(CCPOP); ccflag = 0; /* recover the Current context. */ |
} |
} |
|
|
break; |
break; |
case Ssendmsg2: |
case Ssendmsg2: |
/* ob2 ob4 { .........} sendmsg2 */ |
/* ob2 ob4 { .........} sendmsg2 */ |
Line 1543 int executePrimitive(ob) |
|
Line 1520 int executePrimitive(ob) |
|
} |
} |
/* normal exec. */ |
/* normal exec. */ |
Kpush(ob2); Kpush(ob4); |
Kpush(ob2); Kpush(ob4); |
|
|
|
/* We cannot use executeExecutableArray(ob1,(char *)NULL) because of |
|
the quote mode. Think about it later. */ |
tokenArray = ob1.lc.tokenArray; |
tokenArray = ob1.lc.tokenArray; |
size = ob1.rc.ival; |
size = ob1.rc.ival; |
for (i=0; i<size; i++) { |
for (i=0; i<size; i++) { |
Line 1550 int executePrimitive(ob) |
|
Line 1530 int executePrimitive(ob) |
|
InSendmsg2 = 1; |
InSendmsg2 = 1; |
status = executeToken(token); |
status = executeToken(token); |
InSendmsg2 = 0; |
InSendmsg2 = 0; |
if (QuoteMode && (status==DO_QUOTE)) { |
|
|
if (status & STATUS_INFIX) { |
|
if (status & DO_QUOTE) errorStackmachine("infix op with DO_QUOTE\n"); |
|
if (i == size-1) errorStackmachine("infix operator at the end(sendmsg2).\n"); |
|
infixOn = 1; infixToken = tokenArray[i]; |
|
infixToken.tflag |= NO_DELAY; continue; |
|
}else if (infixOn) { |
|
infixOn = 0; status = executeToken(infixToken); |
|
if (status & STATUS_BREAK) break; |
|
} |
|
|
|
if (QuoteMode && (status & DO_QUOTE)) { |
/* generate tree object, for kan/k0 */ |
/* generate tree object, for kan/k0 */ |
struct object qob; |
struct object qob; |
struct object qattr; |
struct object qattr; |
Line 1578 int executePrimitive(ob) |
|
Line 1569 int executePrimitive(ob) |
|
putoa(qob,2,ob4); /* Argument */ |
putoa(qob,2,ob4); /* Argument */ |
qob = KpoTree(qob); |
qob = KpoTree(qob); |
Kpush(qob); |
Kpush(qob); |
} else if (status != 0) break; |
} else if (status & STATUS_BREAK) break; |
|
|
} |
} |
if (ccflag) { |
if (ccflag) { |
contextControl(CCPOP); ccflag = 0; |
contextControl(CCPOP); ccflag = 0; |
Line 1598 int executePrimitive(ob) |
|
Line 1590 int executePrimitive(ob) |
|
contextControl(CCPUSH); ccflag = 1; |
contextControl(CCPUSH); ccflag = 1; |
CurrentContextp = PrimitiveContextp; |
CurrentContextp = PrimitiveContextp; |
/* normal exec. */ |
/* normal exec. */ |
tokenArray = ob1.lc.tokenArray; |
status = executeExecutableArray(ob1,(char *)NULL,0); |
size = ob1.rc.ival; |
|
for (i=0; i<size; i++) { |
|
token = tokenArray[i]; |
|
status = executeToken(token); |
|
if (status != 0) break; |
|
} |
|
|
|
contextControl(CCPOP); /* recover the Current context. */ |
contextControl(CCPOP); /* recover the Current context. */ |
break; |
break; |
|
|
Line 1650 int executePrimitive(ob) |
|
Line 1635 int executePrimitive(ob) |
|
} |
} |
/* normal exec. */ |
/* normal exec. */ |
Kpush(ob2); Kpush(ob4); |
Kpush(ob2); Kpush(ob4); |
tokenArray = ob1.lc.tokenArray; |
status = executeExecutableArray(ob1,(char *)NULL,0); |
size = ob1.rc.ival; |
|
for (i=0; i<size; i++) { |
|
token = tokenArray[i]; |
|
status = executeToken(token); |
|
if (status != 0) break; |
|
} |
|
if (ccflag) { |
if (ccflag) { |
contextControl(CCPOP); ccflag = 0; /* recover the Current context. */ |
contextControl(CCPOP); ccflag = 0; /* recover the Current context. */ |
} |
} |
Line 1724 int executePrimitive(ob) |
|
Line 1703 int executePrimitive(ob) |
|
errorStackmachine("Usage:tlimit"); |
errorStackmachine("Usage:tlimit"); |
break; |
break; |
} |
} |
tokenArray = ob1.lc.tokenArray; |
|
size = ob1.rc.ival; |
|
n = ob2.lc.ival; |
n = ob2.lc.ival; |
i = 0; |
|
if (n > 0) { |
if (n > 0) { |
signal(SIGALRM,ctrlC); alarm((unsigned int) n); |
signal(SIGALRM,ctrlC); alarm((unsigned int) n); |
for (i=0; i<size; i++) { |
status = executeExecutableArray(ob1,(char *)NULL,0); |
token = tokenArray[i]; |
|
status = executeToken(token); |
|
} |
|
cancelAlarm(); |
cancelAlarm(); |
}else{ |
}else{ |
before_real = time(&before_real); |
before_real = time(&before_real); |
times(&before); |
times(&before); |
for (i=0; i<size; i++) { |
status = executeExecutableArray(ob1,(char *)NULL,0); |
token = tokenArray[i]; |
|
status = executeToken(token); |
|
} |
|
times(&after); |
times(&after); |
after_real = time(&after_real); |
after_real = time(&after_real); |
ob1 = newObjectArray(3); |
ob1 = newObjectArray(3); |