Free Hero Mesh

Diff
Login
This is a mirror of the main repository for Free Hero Mesh. New tickets and changes will not be accepted at this mirror.

Differences From Artifact [42fb9875e1]:

To Artifact [79db9f5b70]:


967
968
969
970
971
972
973
















































































974
975
976
977
978
979
980
    labelstack=s->next;
    free(s);
  }
  free(labelptr);
  labelstack=0;
  labelptr=0;
}

















































































#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)







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
    labelstack=s->next;
    free(s);
  }
  free(labelptr);
  labelstack=0;
  labelptr=0;
}

static int parse_pattern(int cla,int ptr,Hash*hash) {
  Class*cl=classes[cla];
  Uint8 depth=0;
  Uint16 nest[32];
  int x,y;
  for(;;) {
    nxttok();
    if(Tokenf(TF_MACRO)) ParseError("Unexpected macro\n");
    if(Tokenf(TF_DIR)) {
      cl->codes[ptr++]=tokenv&15;
    } else if(Tokenf(TF_NAME)) {
      switch(tokenv) {
        case OP_ADD: case OP_CLIMB: case OP_EIGHT: case OP_FOUR:
        case OP_HEIGHT: case OP_LOC: case OP_MARK: case OP_SUB:
        case OP_DIR: case OP_DIR_C: case OP_DIR_E: case OP_DIR_EC:
        case 0x0200 ... 0x02FF: // message
        case 0x4000 ... 0x7FFF: // class
        case 0xC000 ... 0xFFFF: // message
          cl->codes[ptr++]=tokenv;
          break;
        case OP_BEGIN: case OP_IF:
          if(depth==31) ParseError("Too much pattern nesting\n");
          nest[depth++]=ptr;
          cl->codes[ptr++]=tokenv;
          cl->codes[ptr++]=0;
          break;
        case OP_ELSE:
          if(!depth) ParseError("Premature end of subpattern\n");
          cl->codes[nest[depth-1]+1]=ptr;
          cl->codes[ptr++]=cl->codes[nest[depth-1]];
          cl->codes[nest[depth-1]]=OP_ELSE;
          cl->codes[ptr++]=0;
          break;
        case OP_THEN:
          if(!depth) ParseError("Premature end of subpattern\n");
          cl->codes[nest[--depth]+1]=ptr;
          break;
        case OP_AGAIN:
          if(!depth) ParseError("Premature end of subpattern\n");
          cl->codes[ptr++]=OP_GOTO;
          cl->codes[ptr++]=nest[depth-1];
          cl->codes[nest[--depth]+1]=ptr;
          break;
        case OP_USERFLAG:
          x=look_hash(glohash,HASH_SIZE,0x1000,0x10FF,0,"user flags");
          if(!x) ParseError("User flag ^%s not defined\n",tokenstr);
          if(Tokenf(TF_COMMA)) x+=0x100;
          if(Tokenf(TF_EQUAL)) ParseError("Improper token in pattern\n");
          cl->codes[ptr++]=x;
          break;
        default: ParseError("Improper token in pattern\n");
      }
    } else if(tokent==TF_OPEN) {
      nxttok();
      if(Tokenf(TF_MACRO) || !Tokenf(TF_NAME)) ParseError("Improper token in pattern\n");
      switch(tokenv) {
        case OP_HEIGHT: case OP_CLIMB:
          cl->codes[ptr++]=tokenv+0x0800; // OP_HEIGHT_C or OP_CLIMB_C
          nxttok();
          if(tokent!=TF_INT) ParseError("Number expected\n");
          if(tokenv&~0xFFFF) ParseError("Number out of range\n");
          cl->codes[ptr++]=tokenv;
          nxttok();
          if(tokent!=TF_CLOSE) ParseError("Close parentheses expected\n");
          break;
        default: ParseError("Improper token in pattern\n");
      }
    } else if(tokent==TF_CLOSE) {
      if(depth) ParseError("Premature end of pattern\n");
      cl->codes[ptr++]=OP_RET;
      return ptr;
    } else if(Tokenf(TF_EOF)) {
      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)
1176
1177
1178
1179
1180
1181
1182







1183
1184
1185
1186
1187
1188
1189
      switch(tokenv) {
        case OP_POPUP:
          nxttok();
          if(tokent!=TF_INT || tokenv<0 || tokenv>32) ParseError("Expected number from 0 to 32");
          if(tokenv) AddInst2(OP_POPUPARGS,tokenv); else AddInst(OP_POPUP);
          nxttok();
          if(tokent!=TF_CLOSE) ParseError("Unterminated (PopUp)\n");







          break;
        case OP_BROADCAST:
          nxttok();
          if(Tokenf(TF_MACRO) || !Tokenf(TF_NAME) || tokenv<0x4000 || tokenv>0x7FFF) ParseError("Class name expected\n");
          AddInst2(OP_BROADCASTCLASS,tokenv-0x4000);
          nxttok();
          if(tokent!=TF_CLOSE) ParseError("Unterminated (Broadcast)\n");







>
>
>
>
>
>
>







1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
      switch(tokenv) {
        case OP_POPUP:
          nxttok();
          if(tokent!=TF_INT || tokenv<0 || tokenv>32) ParseError("Expected number from 0 to 32");
          if(tokenv) AddInst2(OP_POPUPARGS,tokenv); else AddInst(OP_POPUP);
          nxttok();
          if(tokent!=TF_CLOSE) ParseError("Unterminated (PopUp)\n");
          break;
        case OP_PATTERN: case OP_PATTERNS:
        case OP_PATTERN_C: case OP_PATTERNS_C:
        case OP_PATTERN_E: case OP_PATTERNS_E:
          AddInst(tokenv);
          cl->codes[ptr]=peep=parse_pattern(cla,ptr+1,hash);
          ptr=peep;
          break;
        case OP_BROADCAST:
          nxttok();
          if(Tokenf(TF_MACRO) || !Tokenf(TF_NAME) || tokenv<0x4000 || tokenv>0x7FFF) ParseError("Class name expected\n");
          AddInst2(OP_BROADCASTCLASS,tokenv-0x4000);
          nxttok();
          if(tokent!=TF_CLOSE) ParseError("Unterminated (Broadcast)\n");