1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
|
ParseError("Unexpected end of file\n");
} else {
ParseError("Improper token in pattern\n");
}
if(ptr>=0xFFEF) ParseError("Out of code space\n");
}
}
#define AddInst(x) (cl->codes[ptr++]=(x),prflag=0)
#define AddInst2(x,y) (cl->codes[ptr++]=(x),cl->codes[ptr++]=(y),prflag=0,peep=ptr)
#define AddInstF(x,y) (cl->codes[ptr++]=(x),prflag=(y))
#define ChangeInst(x) (cl->codes[ptr-1]x,prflag=0)
#define InstFlag(x) (peep<ptr && (prflag&(x)))
#define Inst7bit() (peep<ptr && cl->codes[ptr-1]<0x0080)
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
|
ParseError("Unexpected end of file\n");
} else {
ParseError("Improper token in pattern\n");
}
if(ptr>=0xFFEF) ParseError("Out of code space\n");
}
}
#define CaseT0(t) do{ if(t0!=-1 && t0!=t) ParseError("Type mismatch in case block\n"); t0=t; }while(0)
#define CaseT1(t) do{ if(t1!=-1 && t1!=t) ParseError("Type mismatch in case block\n"); t1=t; }while(0)
static int case_block(int cla,int ptr,Hash*hash) {
Class*cl=classes[cla];
int sptr=ptr++;
Sint8 t0=-1;
Sint8 t1=-1;
Uint16 n=0;
Uint8 e=1;
Uint8 z=0;
for(;;) {
nxttok();
if(Tokenf(TF_MACRO)) ParseError("Unexpected macro\n");
if(tokent==TF_OPEN) {
nxttok();
if(Tokenf(TF_MACRO)) ParseError("Unexpected macro\n");
if(n>=256 && tokenv!=OP_ELSE && !Tokenf(TF_NAME)) ParseError("Too many cases\n");
if(!e) ParseError("Cannot add more cases after the default block\n");
n++;
if(Tokenf(TF_INT) || Tokenf(TF_DIR)) {
if(tokenv) CaseT0(TY_NUMBER);
cl->codes[ptr++]=tokenv;
} else if(Tokenf(TF_NAME)) {
switch(tokenv) {
case OP_ELSE:
e=0;
n--;
break;
case 0x0200 ... 0x02FF:
CaseT0(TY_MESSAGE);
cl->codes[ptr++]=tokenv+1-0x0200;
break;
case 0x4000 ... 0x7FFF:
CaseT0(TY_CLASS);
cl->codes[ptr++]=tokenv-0x4000;
break;
case 0xC000 ... 0xFFFF:
CaseT0(TY_MESSAGE);
cl->codes[ptr++]=(tokenv&0x3FFF)+257;
break;
default:
ParseError("Improper token in case block\n");
break;
}
} else if(Tokenf(TF_EOF)) {
ParseError("Unexpected end of file\n");
} else {
ParseError("Improper token in case block\n");
}
nxttok();
if(Tokenf(TF_MACRO)) ParseError("Unexpected macro\n");
if(Tokenf(TF_INT) || Tokenf(TF_DIR)) {
if(tokenv) CaseT1(TY_NUMBER); else z=1;
if(tokenv&~0xFFFF) ParseError("Number in case block out of range\n");
cl->codes[ptr++]=tokenv;
} else if(Tokenf(TF_NAME)) {
switch(tokenv) {
case OP_LABEL:
CaseT1(TY_CODE);
if(Tokenf(TF_COMMA|TF_EQUAL)) ParseError("Improper token in case block\n");
tokenv=look_hash(hash,LOCAL_HASH_SIZE,0x8000,0xFFFF,*labelptr,"labels");
if(!tokenv) tokenv=*labelptr,++*labelptr;
tokenv-=0x8000;
cl->codes[ptr++]=labelptr[tokenv];
if(labelptr[tokenv]==0xFFFF) {
LabelStack*s=malloc(sizeof(LabelStack));
if(!s) fatal("Allocation failed\n");
s->id=tokenv|0x8000;
s->addr=ptr-1;
s->next=labelstack;
labelstack=s;
}
break;
case OP_STRING:
CaseT1(TY_STRING);
cl->codes[ptr++]=pool_string(tokenstr)+1;
break;
case 0x0200 ... 0x02FF:
CaseT1(TY_MESSAGE);
cl->codes[ptr++]=tokenv+1-0x0200;
break;
case 0x4000 ... 0x7FFF:
CaseT1(TY_CLASS);
cl->codes[ptr++]=tokenv-0x4000;
break;
case 0xC000 ... 0xFFFF:
CaseT1(TY_MESSAGE);
cl->codes[ptr++]=(tokenv&0x3FFF)+257;
break;
default:
ParseError("Improper token in case block\n");
break;
}
} else if(Tokenf(TF_EOF)) {
ParseError("Unexpected end of file\n");
} else {
ParseError("Improper token in case block\n");
}
nxttok();
} else if(tokent==TF_CLOSE) {
if(!n) ParseError("Empty case block\n");
if(z && t1==TY_CODE) ParseError("Type mismatch in case block\n");
if(e) {
cl->codes[ptr]=(t1==TY_CODE?ptr+1:0);
ptr++;
}
if(t0==-1) t0=TY_NUMBER;
if(t1==-1) t1=TY_NUMBER;
cl->codes[sptr]=(t0<<12)|(t1<<8)|(n-1);
return ptr;
} else if(Tokenf(TF_EOF)) {
ParseError("Unexpected end of file\n");
} else {
ParseError("Improper token in case block\n");
}
if(ptr>=0xFFEF) ParseError("Out of code space\n");
}
}
#define AddInst(x) (cl->codes[ptr++]=(x),prflag=0)
#define AddInst2(x,y) (cl->codes[ptr++]=(x),cl->codes[ptr++]=(y),prflag=0,peep=ptr)
#define AddInstF(x,y) (cl->codes[ptr++]=(x),prflag=(y))
#define ChangeInst(x) (cl->codes[ptr-1]x,prflag=0)
#define InstFlag(x) (peep<ptr && (prflag&(x)))
#define Inst7bit() (peep<ptr && cl->codes[ptr-1]<0x0080)
|
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
|
nxttok();
if(tokent==TF_CLOSE) break;
if(Tokenf(TF_MACRO) || !Tokenf(TF_INT)) ParseError("Number or close parenthesis expected\n");
x|=1<<tokenv;
}
tokenv=x;
goto numeric;
default:
ParseError("Invalid parenthesized instruction\n");
}
} else if(tokent==TF_CLOSE) {
if(flowdepth) ParseError("Unterminated flow control structure\n");
if(peep<ptr && cl->codes[ptr-1]==OP_RET) break;
if(peep<ptr && (cl->codes[ptr-1]&0xFF00)==0x1E00) break;
|
>
>
>
>
|
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
|
nxttok();
if(tokent==TF_CLOSE) break;
if(Tokenf(TF_MACRO) || !Tokenf(TF_INT)) ParseError("Number or close parenthesis expected\n");
x|=1<<tokenv;
}
tokenv=x;
goto numeric;
case OP_CASE:
cl->codes[ptr++]=OP_CASE;
ptr=peep=case_block(cla,ptr,hash);
break;
default:
ParseError("Invalid parenthesized instruction\n");
}
} else if(tokent==TF_CLOSE) {
if(flowdepth) ParseError("Unterminated flow control structure\n");
if(peep<ptr && cl->codes[ptr-1]==OP_RET) break;
if(peep<ptr && (cl->codes[ptr-1]&0xFF00)==0x1E00) break;
|