Free Hero Mesh

Check-in [646aebd36a]
Login
This is a mirror of the main repository for Free Hero Mesh. New tickets and changes will not be accepted at this mirror.
Overview
Comment:Start to implement parsing for pattern matching. Execution of pattern matching is not yet implemented.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 646aebd36a462345f74fa4d312a6033a781d8877
User & Date: user on 2021-04-17 05:52:17
Other Links: manifest | tags
Context
2021-04-17
05:53
Check for unterminated flow control structures check-in: 288e31e44b user: user tags: trunk
05:52
Start to implement parsing for pattern matching. Execution of pattern matching is not yet implemented. check-in: 646aebd36a user: user tags: trunk
2021-04-16
00:19
Update the TODO file. check-in: fb7252b349 user: user tags: trunk
Changes

Modified class.c from [42fb9875e1] to [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");

Modified class.doc from [59627fa4c6] to [1027896695].

2070
2071
2072
2073
2074
2075
2076





2077
2078
2079
2080
2081
2082
2083
  Available for your own use.

The return value of HITBY can also be an object instead of a number. In
this case, a warp occurs. The movement is restarted, using the specified
object as the origin of the movement, and that object's direction as the
direction of movement.







=== Compatibility ===

Compatible objects have the following differences from the default:

* VisualOnly implies Stealthy.








>
>
>
>
>







2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
  Available for your own use.

The return value of HITBY can also be an object instead of a number. In
this case, a warp occurs. The movement is restarted, using the specified
object as the origin of the movement, and that object's direction as the
direction of movement.


=== Pattern matching ===

(TODO)


=== Compatibility ===

Compatible objects have the following differences from the default:

* VisualOnly implies Stealthy.

Modified instruc from [3d7b149248] to [aef07dfcc7].

275
276
277
278
279
280
281






282
283
284
285
286
287
288
289
290
291
292

; Arrays
-Array
GetArray
InitArray
SetArray
ArrayCell







; Specials
*Function
*Local
*Label
*String
*Int16
*Int32
*Dispatch
*UserFlag








>
>
>
>
>
>











275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298

; Arrays
-Array
GetArray
InitArray
SetArray
ArrayCell

; Pattern matching
-,=Pattern "P"
-,=PatternS "P*"
-Four
-Eight

; Specials
*Function
*Local
*Label
*String
*Int16
*Int32
*Dispatch
*UserFlag

Modified instruc.h from [caec67b4a9] to [b4a8f7dc1b].

403
404
405
406
407
408
409










410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
#define OP_MBEGIN 32967
#define OP_FLIP 32968
#define OP_ARRAY 32969
#define OP_GETARRAY 32970
#define OP_INITARRAY 32971
#define OP_SETARRAY 32972
#define OP_ARRAYCELL 32973










#define OP_FUNCTION 32974
#define OP_LOCAL 32975
#define OP_LABEL 32976
#define OP_STRING 32977
#define OP_INT16 32978
#define OP_INT32 32979
#define OP_DISPATCH 32980
#define OP_USERFLAG 32981
#ifdef HEROMESH_CLASS
static const Op_Names op_names[]={
{"*",8486937},
{"+",8421399},
{"+Move",10584230},
{"-",8421400},
{"-Move",10584231},







>
>
>
>
>
>
>
>
>
>
|
|
|
|
|
|
|
|







403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
#define OP_MBEGIN 32967
#define OP_FLIP 32968
#define OP_ARRAY 32969
#define OP_GETARRAY 32970
#define OP_INITARRAY 32971
#define OP_SETARRAY 32972
#define OP_ARRAYCELL 32973
#define OP_PATTERN 32974
#define OP_PATTERN_C 35022
#define OP_PATTERN_E 37070
#define OP_PATTERN_EC 39118
#define OP_PATTERNS 32975
#define OP_PATTERNS_C 35023
#define OP_PATTERNS_E 37071
#define OP_PATTERNS_EC 39119
#define OP_FOUR 32976
#define OP_EIGHT 32977
#define OP_FUNCTION 32978
#define OP_LOCAL 32979
#define OP_LABEL 32980
#define OP_STRING 32981
#define OP_INT16 32982
#define OP_INT32 32983
#define OP_DISPATCH 32984
#define OP_USERFLAG 32985
#ifdef HEROMESH_CLASS
static const Op_Names op_names[]={
{"*",8486937},
{"+",8421399},
{"+Move",10584230},
{"-",8421400},
{"-Move",10584231},
489
490
491
492
493
494
495

496
497
498
499
500
501
502
503

504
505
506
507
508
509
510
{"Destroyed",8487026},
{"Dir",8618048},
{"Distance",9142340},
{"Done",8618097},
{"E",9437184},
{"END_TURN",8389139},
{"EditorHelp",8683654},

{"F",9437192},
{"FAROUT",8389421},
{"FFFFTT",8389399},
{"FLOATED",8389132},
{"FROG",8389383},
{"Finished",8552575},
{"FlushClass",8421527},
{"FlushObj",8487064},

{"From",8421496},
{"GLASS",8389379},
{"GLISSANT",8389419},
{"GetArray",8421578},
{"GetInventory",8421529},
{"HAWK",8389425},
{"HEARTBEAT",8389407},







>








>







499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
{"Destroyed",8487026},
{"Dir",8618048},
{"Distance",9142340},
{"Done",8618097},
{"E",9437184},
{"END_TURN",8389139},
{"EditorHelp",8683654},
{"Eight",8683729},
{"F",9437192},
{"FAROUT",8389421},
{"FFFFTT",8389399},
{"FLOATED",8389132},
{"FROG",8389383},
{"Finished",8552575},
{"FlushClass",8421527},
{"FlushObj",8487064},
{"Four",8683728},
{"From",8421496},
{"GLASS",8389379},
{"GLISSANT",8389419},
{"GetArray",8421578},
{"GetInventory",8421529},
{"HAWK",8389425},
{"HEARTBEAT",8389407},
574
575
576
577
578
579
580


581
582
583
584
585
586
587
{"ObjBelow",8487084},
{"ObjBottomAt",8421549},
{"ObjClassAt",8421550},
{"ObjDir",8487087},
{"ObjLayerAt",8421552},
{"ObjMovingTo",8421553},
{"ObjTopAt",8421554},


{"PLAYERMOVING",8389133},
{"POSTINIT",8389138},
{"POUR",8389377},
{"POWER",8389386},
{"Player",8487027},
{"PopUp",8421555},
{"Quiz",8683650},







>
>







586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
{"ObjBelow",8487084},
{"ObjBottomAt",8421549},
{"ObjClassAt",8421550},
{"ObjDir",8487087},
{"ObjLayerAt",8421552},
{"ObjMovingTo",8421553},
{"ObjTopAt",8421554},
{"P",8880334},
{"P*",8880335},
{"PLAYERMOVING",8389133},
{"POSTINIT",8389138},
{"POUR",8389377},
{"POWER",8389386},
{"Player",8487027},
{"PopUp",8421555},
{"Quiz",8683650},
728
729
730
731
732
733
734
735
736
{"swap",8421378},
{"then",8683531},
{"tmark",8421572},
{"tuck",8421380},
{"until",8683535},
{"while",8683536},
};
#define N_OP_NAMES 314
#endif







|

742
743
744
745
746
747
748
749
750
{"swap",8421378},
{"then",8683531},
{"tmark",8421572},
{"tuck",8421380},
{"until",8683535},
{"while",8683536},
};
#define N_OP_NAMES 318
#endif