Overview
Comment: | Implement preprocessor, and add some more opcode names, and a few bug fixed |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
79caf678bea49b5def8f814d94e5f7b9 |
User & Date: | user on 2018-05-05 23:58:56 |
Other Links: | manifest | tags |
Context
2018-05-19
| ||
19:23 | More parsing of .class file check-in: e049e8ed33 user: user tags: trunk | |
2018-05-05
| ||
23:58 | Implement preprocessor, and add some more opcode names, and a few bug fixed check-in: 79caf678be user: user tags: trunk | |
2018-04-27
| ||
20:25 | More codes and testing in class codes parser check-in: 02b262b608 user: user tags: trunk | |
Changes
Modified class.c from [c8671ac4ba] to [10cd656230].
︙ | ︙ | |||
24 25 26 27 28 29 30 | #define TF_DROP 0x0020 // add 0x2000 to opcode if followed by OP_DROP #define TF_NAME 0x0080 // token is a name or opcode #define TF_KEY 0x0100 // token is a Hero Mesh key name #define TF_OPEN 0x0400 // token is ( #define TF_CLOSE 0x0800 // token is ) #define TF_INT 0x1000 // token is a number #define TF_FUNCTION 0x2000 // token is a user function | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | #define TF_DROP 0x0020 // add 0x2000 to opcode if followed by OP_DROP #define TF_NAME 0x0080 // token is a name or opcode #define TF_KEY 0x0100 // token is a Hero Mesh key name #define TF_OPEN 0x0400 // token is ( #define TF_CLOSE 0x0800 // token is ) #define TF_INT 0x1000 // token is a number #define TF_FUNCTION 0x2000 // token is a user function #define TF_MACRO 0x4000 // token is a macro #define TF_EOF 0x8000 // end of file typedef struct { const char*txt; Uint32 num; } Op_Names; #include "instruc.h" #define Tokenf(x) (tokent&(x)) Class*classes[0x4000]; const char*messages[0x4000]; Uint16 functions[0x4000]; int max_animation=32; Sint32 max_volume=10000; Uint8 back_color=1; #define HASH_SIZE 8888 #define LOCAL_HASH_SIZE 5555 typedef struct { Uint16 id; char*txt; } Hash; typedef struct InputStack { FILE*classfp; int linenum; struct InputStack*next; } InputStack; typedef struct TokenList { Uint16 t; Uint32 v; char*str; Uint16 ref; struct TokenList*next; } TokenList; typedef struct MacroStack { TokenList*tok; Sint16 n; TokenList**args; struct MacroStack*next; } MacroStack; static FILE*classfp; static Uint16 tokent; static Uint32 tokenv; static int linenum=1; static char tokenstr[0x2000]; static int undef_class=1; static int undef_message=0; static int num_globals=0; static int num_functions=0; static Hash*glohash; static InputStack*inpstack; static MacroStack*macstack; static TokenList**macros; #define ParseError(a,...) fatal("On line %d: " a,linenum,##__VA_ARGS__) static const unsigned char chkind[256]={ ['$']=1, ['!']=1, ['\'']=1, ['#']=1, ['@']=1, ['%']=1, ['&']=1, [':']=1, ['0'...'9']=2, ['-']=2, ['+']=2, ['A'...'Z']=3, ['a'...'z']=3, ['_']=3, ['?']=3, ['.']=3, ['*']=3, ['/']=3, }; #define MIN_VERSION 0 #define MAX_VERSION 0 #define MAX_MACRO 0x3FC0 #define MAC_ADD 0xFFC0 #define MAC_SUB 0xFFC1 #define MAC_MUL 0xFFC2 #define MAC_DIV 0xFFC3 #define MAC_MOD 0xFFC4 #define MAC_BAND 0xFFC5 #define MAC_BOR 0xFFC6 #define MAC_BXOR 0xFFC7 #define MAC_BNOT 0xFFC8 #define MAC_CAT 0xFFC9 #define MAC_VERSION 0xFFE0 #define MAC_DEFINE 0xFFE1 #define MAC_INCLUDE 0xFFE2 #define MAC_CALL 0xFFE3 #define MAC_UNDEFINED 0xFFFF static TokenList*add_macro(void) { TokenList*o=malloc(sizeof(TokenList)); if(!o) fatal("Allocation failed\n"); o->t=tokent; o->v=tokenv; o->str=0; o->ref=0; o->next=0; if(*tokenstr) { o->str=strdup(tokenstr); if(!o->str) fatal("Allocation failed\n"); } return o; } static void ref_macro(TokenList*o) { while(o) { if(++o->ref==65000) ParseError("Reference count of macro token list overflowed\n"); o=o->next; } } static void free_macro(TokenList*o) { TokenList*p; while(o && !o->ref--) { free(o->str); o=(p=o)->next; free(p); } } static inline TokenList*step_macro(TokenList*o) { TokenList*p=o->next; if(!o->ref--) { free(o->str); free(o); } return p; } static void read_quoted_string(void) { int c,i,n; int isimg=0; for(i=0;i<0x1FFD;) { c=fgetc(classfp); if(c==EOF) { |
︙ | ︙ | |||
193 194 195 196 197 198 199 200 201 | tbl[h].id=newv; return 0; } h=(h+1)%size; if(h==m) ParseError("Hash table full\n"); } } #define ReturnToken(x,y) do{ tokent=x; tokenv=y; return; }while(0) | > > > > > > > > > > > > > > > > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | | 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 | tbl[h].id=newv; return 0; } h=(h+1)%size; if(h==m) ParseError("Hash table full\n"); } } static Uint16 look_hash_mac(void) { int h,i,m; for(h=i=0;tokenstr[i];i++) h=(13*h+tokenstr[i])%HASH_SIZE; m=h; for(;;) { if(glohash[h].id>=0xC000 && !strcmp(tokenstr,glohash[h].txt)) return h; if(!glohash[h].id) { glohash[h].txt=strdup(tokenstr); if(!glohash[h].txt) ParseError("Out of string space in hash table\n"); glohash[h].id=0xFFFF; return h; } h=(h+1)%HASH_SIZE; if(h==m) ParseError("Hash table full\n"); } } #define ReturnToken(x,y) do{ tokent=x; tokenv=y; return; }while(0) static void nxttok1(void) { int c,i,fl,n,pr; magain: if(macstack) { TokenList*tl=0; pr=0; tokent=macstack->tok->t; if(tokent&TF_EOF) ParseError("Unexpected end of file in macro expansion\n"); tokenv=macstack->tok->v; *tokenstr=0; if(macstack->tok->str) strcpy(tokenstr,macstack->tok->str); if(tokent==TF_MACRO+TF_INT && macstack->n>=0) { if(tokenv&~0xFF) { tokenv-=0x100; } else { if(tokenv<macstack->n) tl=macstack->args[tokenv]; if(tl) ref_macro(tl); pr=1; } } macstack->tok=step_macro(macstack->tok); if(!macstack->tok) { MacroStack*ms=macstack->next; for(i=0;i<macstack->n;i++) free_macro(macstack->args[i]); free(macstack->args); free(macstack); macstack=ms; } if(pr) { if(tl) { MacroStack*ms=malloc(sizeof(MacroStack)); if(!ms) fatal("Allocation failed\n"); ms->tok=tl; ms->n=-1; ms->args=0; ms->next=macstack; macstack=ms; } goto magain; } return; } fl=n=pr=0; tokent=tokenv=0; *tokenstr=0; again: c=fgetc(classfp); while(c==' ' || c=='\t' || c=='\r' || c=='\n') { if(c=='\n') ++linenum; c=fgetc(classfp); } if(c==EOF) ReturnToken(TF_EOF,0); if(c==';') { |
︙ | ︙ | |||
227 228 229 230 231 232 233 234 235 236 237 238 239 240 | if(c=='=') { fl|=TF_EQUAL; c=fgetc(classfp); } if(c==',') { fl|=TF_COMMA; c=fgetc(classfp); } if(c==EOF) ParseError("Unexpected end of file\n"); if(chkind[c]==1) { pr=c; c=fgetc(classfp); if(c==EOF) ParseError("Unexpected end of file\n"); } | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 | if(c=='=') { fl|=TF_EQUAL; c=fgetc(classfp); } if(c==',') { fl|=TF_COMMA; c=fgetc(classfp); } if(c=='{') { c=fgetc(classfp); while(c==' ' || c=='\t' || c=='\r' || c=='\n') { if(c=='\n') ++linenum; c=fgetc(classfp); } while(c>0 && (chkind[c]&2)) { if(n==256) { tokenstr[256]=0; ParseError("Identifier too long: %s\n",tokenstr); } tokenstr[n++]=c; c=fgetc(classfp); } tokenstr[n]=0; if(!n) fatal("Expected macro name\n"); if(c!=EOF) ungetc(c,classfp); ReturnToken(TF_MACRO|TF_OPEN,look_hash_mac()); } if(c=='}') ReturnToken(TF_MACRO|TF_CLOSE,0); if(c=='|') ReturnToken(TF_MACRO,1); if(c=='\\') { i=0; while((c=fgetc(classfp))=='\\') i+=0x100; tokenv=0; for(;c>='0' && c<='9';c=fgetc(classfp)) tokenv=10*tokenv+c-'0'; --tokenv; if(tokenv&~255) ParseError("Macro parameter reference out of range\n"); if(c!=EOF) ungetc(c,classfp); tokent=TF_MACRO|TF_INT; tokenv|=i; return; } if(c==EOF) ParseError("Unexpected end of file\n"); if(chkind[c]==1) { pr=c; c=fgetc(classfp); if(c==EOF) ParseError("Unexpected end of file\n"); } |
︙ | ︙ | |||
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 | return; } } ParseError("Invalid Hero Mesh key name: %s\n",tokenstr); break; } } void load_classes(void) { int i; char*nam=sqlite3_mprintf("%s.class",basefilename); if(!nam) fatal("Allocation failed\n"); classfp=fopen(nam,"r"); sqlite3_free(nam); if(!classfp) fatal("Cannot open class file '%s': %m\n",nam); glohash=calloc(HASH_SIZE,sizeof(Hash)); if(!glohash) fatal("Allocation failed\n"); if(main_options['L']) { for(;;) { nxttok(); printf("** %5d %04X %08X \"",linenum,tokent,tokenv); for(i=0;tokenstr[i];i++) { if(tokenstr[i]<32 || tokenstr[i]>126) printf("<%02X>",tokenstr[i]&255); else putchar(tokenstr[i]); } printf("\"\n"); if(Tokenf(TF_EOF)) goto done; } } done: fclose(classfp); for(i=0;i<HASH_SIZE;i++) free(glohash[i].txt); free(glohash); | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > | 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 | return; } } ParseError("Invalid Hero Mesh key name: %s\n",tokenstr); break; } } static void define_macro(Uint16 name) { int i; TokenList**t; if(glohash[name].id<0xC000) fatal("Confusion\n"); if(glohash[name].id<MAX_MACRO+0xC000) { free_macro(macros[i=glohash[name].id-0xC000]); macros[i]=0; } else { for(i=0;i<MAX_MACRO;i++) if(!macros[i]) break; if(i==MAX_MACRO) ParseError("Too many macro definitions\n"); } glohash[name].id=i+0xC000; t=macros+i; i=1; for(;;) { nxttok1(); if(tokent==TF_MACRO+TF_OPEN && ++i>65000) ParseError("Too much macro nesting\n"); if(tokent==TF_MACRO+TF_CLOSE && !--i) break; *t=add_macro(); t=&(*t)->next; } } static void begin_include_file(const char*name) { InputStack*nxt=inpstack; inpstack=malloc(sizeof(InputStack)); if(!inpstack) fatal("Allocation failed\n"); inpstack->classfp=classfp; inpstack->linenum=linenum; inpstack->next=nxt; linenum=1; //TODO: Use the correct directory to load the include file classfp=fopen(name,"r"); if(!classfp) ParseError("Cannot open include file \"%s\": %m\n",name); } static void begin_macro(TokenList*mac) { MacroStack*ms=malloc(sizeof(MacroStack)); TokenList**ap=0; int a=0; int b=0; int c=0; ref_macro(mac); if(!ms) fatal("Allocation failed\n"); ms->tok=mac; ms->n=0; ms->args=0; for(;;) { nxttok1(); if(tokent&TF_EOF) ParseError("Unexpected end of file in macro argument\n"); if(tokent&TF_OPEN) { ++a; if(tokent&TF_MACRO) ++c; } if(tokent&TF_CLOSE) { --a; if(tokent&TF_MACRO) --c; } if(c==-1) { if(a!=-1 && !b) ParseError("Misnested macro argument\n"); ms->next=macstack; macstack=ms; return; } else if(a==-1 && !b) { ParseError("Misnested macro argument\n"); } else if(tokent==TF_MACRO && tokenv==1 && !a && !b) { if(c) ParseError("Misnested macro argument\n"); b=1; ms->args=realloc(ms->args,++ms->n*sizeof(TokenList*)); if(!ms->args) fatal("Allocation failed\n"); ap=ms->args+ms->n-1; *ap=0; } else { if(!b && !(tokent&TF_CLOSE) && a==(tokent&TF_OPEN?1:0)) { ms->args=realloc(ms->args,++ms->n*sizeof(TokenList*)); if(!ms->args) fatal("Allocation failed\n"); ap=ms->args+ms->n-1; *ap=0; } *ap=add_macro(); ap=&((*ap)->next); } } } static void nxttok(void) { again: nxttok1(); if(tokent&TF_EOF) { if(inpstack) { InputStack s=*inpstack; free(inpstack); fclose(classfp); classfp=s.classfp; linenum=s.linenum; inpstack=s.next; goto again; } } else if(tokent&TF_MACRO) { Uint32 n; char*s; if(tokent&TF_OPEN) { call: switch(glohash[tokenv].id) { case 0xC000 ... MAX_MACRO+0xC000-1: begin_macro(macros[glohash[tokenv].id-0xC000]); goto again; case MAC_ADD: n=0; for(;;) { nxttok(); if(tokent==TF_MACRO+TF_CLOSE) break; if(tokent!=TF_INT) ParseError("Number expected\n"); n+=tokenv; } tokent=TF_INT; tokenv=n; break; case MAC_SUB: nxttok(); if(tokent!=TF_INT) ParseError("Number expected\n"); n=tokenv; nxttok(); if(tokent!=TF_INT) ParseError("Number expected\n"); n-=tokenv; nxttok(); if(tokent!=TF_MACRO+TF_CLOSE) ParseError("Too many macro arguments\n"); tokent=TF_INT; tokenv=n; break; case MAC_MUL: n=1; for(;;) { nxttok(); if(tokent==TF_MACRO+TF_CLOSE) break; if(tokent!=TF_INT) ParseError("Number expected\n"); n*=tokenv; } tokent=TF_INT; tokenv=n; break; case MAC_DIV: nxttok(); if(tokent!=TF_INT) ParseError("Number expected\n"); n=tokenv; nxttok(); if(tokent!=TF_INT) ParseError("Number expected\n"); if(!tokenv) ParseError("Division by zero\n"); n/=tokenv; nxttok(); if(tokent!=TF_MACRO+TF_CLOSE) ParseError("Too many macro arguments\n"); tokent=TF_INT; tokenv=n; break; case MAC_MOD: nxttok(); if(tokent!=TF_INT) ParseError("Number expected\n"); n=tokenv; nxttok(); if(tokent!=TF_INT) ParseError("Number expected\n"); if(!tokenv) ParseError("Division by zero\n"); n%=tokenv; nxttok(); if(tokent!=TF_MACRO+TF_CLOSE) ParseError("Too many macro arguments\n"); tokent=TF_INT; tokenv=n; break; case MAC_BAND: n=-1; for(;;) { nxttok(); if(tokent==TF_MACRO+TF_CLOSE) break; if(tokent!=TF_INT) ParseError("Number expected\n"); n&=tokenv; } tokent=TF_INT; tokenv=n; break; case MAC_BOR: n=0; for(;;) { nxttok(); if(tokent==TF_MACRO+TF_CLOSE) break; if(tokent!=TF_INT) ParseError("Number expected\n"); n|=tokenv; } tokent=TF_INT; tokenv=n; break; case MAC_BXOR: n=0; for(;;) { nxttok(); if(tokent==TF_MACRO+TF_CLOSE) break; if(tokent!=TF_INT) ParseError("Number expected\n"); n^=tokenv; } tokent=TF_INT; tokenv=n; break; case MAC_BNOT: nxttok(); if(tokent!=TF_INT) ParseError("Number expected\n"); n=~tokenv; nxttok(); if(tokent!=TF_MACRO+TF_CLOSE) ParseError("Too many macro arguments\n"); tokent=TF_INT; tokenv=n; break; case MAC_CAT: s=malloc(0x2000); if(!s) fatal("Allocation failed\n"); n=0; for(;;) { nxttok(); if(tokent==TF_MACRO+TF_CLOSE) { break; } else if(tokent==TF_INT) { sprintf(tokenstr,"%d",tokenv); goto isname; } else if(tokent&TF_NAME) { isname: if(strlen(tokenstr)+n>=0x1FFE) ParseError("Concatenated string too long\n"); strcpy(s+n,tokenstr); n+=strlen(tokenstr); } else if(tokent!=TF_MACRO || tokenv!=1) { ParseError("Number or string or name expected\n"); } } s[n]=0; strcpy(tokenstr,s); free(s); ReturnToken(TF_NAME|TF_ABNORMAL,OP_STRING); case MAC_VERSION: nxttok1(); if(tokent!=TF_INT) ParseError("Number expected\n"); if(tokenv<MIN_VERSION || tokenv>MAX_VERSION) ParseError("Version number out of range\n"); nxttok1(); if(tokent!=TF_MACRO+TF_CLOSE) ParseError("Too many macro arguments\n"); goto again; case MAC_DEFINE: if(!macros) { macros=calloc(MAX_MACRO,sizeof(TokenList*)); if(!macros) fatal("Allocation failed\n"); } nxttok(); if(!(tokent&TF_NAME) || tokenv!=OP_STRING) ParseError("String literal expected\n"); define_macro(look_hash_mac()); goto again; case MAC_INCLUDE: if(macstack) ParseError("Cannot use {include} inside of a macro\n"); nxttok1(); if(tokent==TF_MACRO && tokenv==1) ReturnToken(TF_EOF,0); if(!(tokent&TF_NAME) || tokenv!=OP_STRING) ParseError("String literal expected\n"); n=look_hash_mac(); nxttok1(); if(tokent!=TF_MACRO+TF_CLOSE) ParseError("Too many macro arguments\n"); begin_include_file(glohash[n].txt); goto again; case MAC_CALL: nxttok(); if(!(tokent&TF_NAME) || tokenv!=OP_STRING) ParseError("String literal expected\n"); tokenv=look_hash_mac(); goto call; case MAC_UNDEFINED: ParseError("Undefined macro: {%s}\n",tokenstr); break; default: ParseError("Strange macro token: 0x%04X\n",glohash[tokenv].id); } } } } void load_classes(void) { int i; char*nam=sqlite3_mprintf("%s.class",basefilename); if(!nam) fatal("Allocation failed\n"); classfp=fopen(nam,"r"); sqlite3_free(nam); if(!classfp) fatal("Cannot open class file '%s': %m\n",nam); glohash=calloc(HASH_SIZE,sizeof(Hash)); if(!glohash) fatal("Allocation failed\n"); strcpy(tokenstr,"+"); glohash[look_hash_mac()].id=MAC_ADD; strcpy(tokenstr,"-"); glohash[look_hash_mac()].id=MAC_SUB; strcpy(tokenstr,"*"); glohash[look_hash_mac()].id=MAC_MUL; strcpy(tokenstr,"/"); glohash[look_hash_mac()].id=MAC_DIV; strcpy(tokenstr,"mod"); glohash[look_hash_mac()].id=MAC_MOD; strcpy(tokenstr,"band"); glohash[look_hash_mac()].id=MAC_BAND; strcpy(tokenstr,"bor"); glohash[look_hash_mac()].id=MAC_BOR; strcpy(tokenstr,"bxor"); glohash[look_hash_mac()].id=MAC_BXOR; strcpy(tokenstr,"bnot"); glohash[look_hash_mac()].id=MAC_BNOT; strcpy(tokenstr,"cat"); glohash[look_hash_mac()].id=MAC_CAT; strcpy(tokenstr,"version"); glohash[look_hash_mac()].id=MAC_VERSION; strcpy(tokenstr,"define"); glohash[look_hash_mac()].id=MAC_DEFINE; strcpy(tokenstr,"include"); glohash[look_hash_mac()].id=MAC_INCLUDE; strcpy(tokenstr,"call"); glohash[look_hash_mac()].id=MAC_CALL; if(main_options['L']) { for(;;) { nxttok(); printf("** %5d %04X %08X \"",linenum,tokent,tokenv); for(i=0;tokenstr[i];i++) { if(tokenstr[i]<32 || tokenstr[i]>126) printf("<%02X>",tokenstr[i]&255); else putchar(tokenstr[i]); } printf("\"\n"); if(Tokenf(TF_EOF)) goto done; } } done: fclose(classfp); if(main_options['H']) { for(i=0;i<HASH_SIZE;i++) if(glohash[i].id) printf("\"%s\": %04X\n",glohash[i].txt,glohash[i].id); } for(i=0;i<HASH_SIZE;i++) free(glohash[i].txt); free(glohash); for(i=1;i<undef_class;i++) if(classes[i] && (classes[i]->cflags&CF_NOCLASS1)) fatal("Class $%s mentioned but not defined\n",classes[i]->name); if(macros) for(i=0;i<MAX_MACRO;i++) if(macros[i]) free_macro(macros[i]); free(macros); } |
Modified heromesh.h from [0030d49afe] to [27851ceca3].
︙ | ︙ | |||
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | Uint16 sharp[4]; Uint16 hard[4]; Uint8 cflags,shape,shovable,collisionLayers,nimages; } Class; extern Class*classes[0x4000]; // 0 isn't a real class extern const char*messages[0x4000]; // index is 256 less than message number extern int max_animation; // max steps in animation queue (default 32) extern Sint32 max_volume; // max total volume to allow moving diagonally (default 10000) void load_classes(void); // == bindings == typedef struct { char cmd; | > > | 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | Uint16 sharp[4]; Uint16 hard[4]; Uint8 cflags,shape,shovable,collisionLayers,nimages; } Class; extern Class*classes[0x4000]; // 0 isn't a real class extern const char*messages[0x4000]; // index is 256 less than message number extern Uint16 functions[0x4000]; extern int max_animation; // max steps in animation queue (default 32) extern Sint32 max_volume; // max total volume to allow moving diagonally (default 10000) extern Uint8 back_color; void load_classes(void); // == bindings == typedef struct { char cmd; |
︙ | ︙ |
Modified instruc from [97418ba69b] to [ef77bce557].
︙ | ︙ | |||
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | ,=Departed ,=Arrivals ,=Departures ,=Busy ,=Invisible ,=KeyCleared ,=UserSignal ,=VisualOnly ,=Stealthy ,=Moved ,Player ,Compatible Self Msg From =Arg1 =Arg2 =Arg3 MoveNumber Level Key ; Class definitions -Input -Quiz -InPlace -DefaultImage -Help -EditorHelp -SUBS | > > > | 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | ,=Departed ,=Arrivals ,=Departures ,=Busy ,=Invisible ,=KeyCleared ,=UserSignal ,=UserState ,=VisualOnly ,=Stealthy ,=Moved ,Destroyed ,Player ,Compatible Self Msg From =Arg1 =Arg2 =Arg3 MoveNumber Level Key ; Class definitions -Background ; used at top level only; not in a class -Input -Quiz -InPlace -DefaultImage -Help -EditorHelp -SUBS |
︙ | ︙ | |||
205 206 207 208 209 210 211 | MaxInventory ; error if more than that many slots in inventory .,Move .,MovePlus "Move+" ; obj.Inertia+=Strength instead of obj.Inertia=Strength .,MoveTo ; the internal MoveTo() function NewX NewY ,ObjAbove | < > > > | 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | MaxInventory ; error if more than that many slots in inventory .,Move .,MovePlus "Move+" ; obj.Inertia+=Strength instead of obj.Inertia=Strength .,MoveTo ; the internal MoveTo() function NewX NewY ,ObjAbove ,ObjBelow ObjBottomAt ObjClassAt ,ObjDir ObjTopAt PopUp *PopUpArgs ; for (PopUp [number]) QueueTurn ; queue another turn that automatically occurs after this one .,Send .,SendEx ; send with three arguments SetInventory Sound |
︙ | ︙ |
Modified instruc.h from [2460412a09] to [a3dc22f64a].
︙ | ︙ | |||
215 216 217 218 219 220 221 | #define OP_KEYCLEARED_C 34907 #define OP_KEYCLEARED_E 36955 #define OP_KEYCLEARED_EC 39003 #define OP_USERSIGNAL 32860 #define OP_USERSIGNAL_C 34908 #define OP_USERSIGNAL_E 36956 #define OP_USERSIGNAL_EC 39004 | > > > > | | | | | | | | | | | | > > | | | | | | | | | | | | | | | | > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | < | | > > | | > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | > | | | | | | | | | | > | | | | | | | | | | | | | | | | | | | | | | | | | | | | > | | > | | | | | | | | | | | | > | | | | | | 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 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 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 | #define OP_KEYCLEARED_C 34907 #define OP_KEYCLEARED_E 36955 #define OP_KEYCLEARED_EC 39003 #define OP_USERSIGNAL 32860 #define OP_USERSIGNAL_C 34908 #define OP_USERSIGNAL_E 36956 #define OP_USERSIGNAL_EC 39004 #define OP_USERSTATE 32861 #define OP_USERSTATE_C 34909 #define OP_USERSTATE_E 36957 #define OP_USERSTATE_EC 39005 #define OP_VISUALONLY 32862 #define OP_VISUALONLY_C 34910 #define OP_VISUALONLY_E 36958 #define OP_VISUALONLY_EC 39006 #define OP_STEALTHY 32863 #define OP_STEALTHY_C 34911 #define OP_STEALTHY_E 36959 #define OP_STEALTHY_EC 39007 #define OP_MOVED 32864 #define OP_MOVED_C 34912 #define OP_MOVED_E 36960 #define OP_MOVED_EC 39008 #define OP_DESTROYED 32865 #define OP_DESTROYED_C 34913 #define OP_PLAYER 32866 #define OP_PLAYER_C 34914 #define OP_COMPATIBLE 32867 #define OP_COMPATIBLE_C 34915 #define OP_SELF 32868 #define OP_MSG 32869 #define OP_FROM 32870 #define OP_ARG1 32871 #define OP_ARG1_E 36967 #define OP_ARG2 32872 #define OP_ARG2_E 36968 #define OP_ARG3 32873 #define OP_ARG3_E 36969 #define OP_MOVENUMBER 32874 #define OP_LEVEL 32875 #define OP_KEY 32876 #define OP_BACKGROUND 32877 #define OP_INPUT 32878 #define OP_QUIZ 32879 #define OP_INPLACE 32880 #define OP_DEFAULTIMAGE 32881 #define OP_HELP 32882 #define OP_EDITORHELP 32883 #define OP_SUBS 32884 #define OP_ANIMATE 32885 #define OP_ASSASSINATE 32886 #define OP_ASSASSINATE_C 34934 #define OP_BROADCAST 32887 #define OP_BROADCAST_D 41079 #define OP_BROADCASTCLASS 32888 #define OP_BROADCASTEX 32889 #define OP_BROADCASTEX_D 41081 #define OP_BROADCASTSUM 32890 #define OP_BROADCASTSUMEX 32891 #define OP_CREATE 32892 #define OP_CREATE_D 41084 #define OP_DELINVENTORY 32893 #define OP_DELTA 32894 #define OP_DESTROY 32895 #define OP_DESTROY_C 34943 #define OP_DESTROY_D 41087 #define OP_DESTROY_CD 43135 #define OP_FLUSHCLASS 32896 #define OP_FLUSHOBJ 32897 #define OP_GETINVENTORY 32898 #define OP_HEIGHTAT 32899 #define OP_IGNOREKEY 32900 #define OP_INTMOVE 32901 #define OP_INTMOVE_C 34949 #define OP_INTMOVE_D 41093 #define OP_INTMOVE_CD 43141 #define OP_JUMPTO 32902 #define OP_JUMPTO_C 34950 #define OP_LOC 32903 #define OP_LOC_C 34951 #define OP_LOCATEME 32904 #define OP_LOSELEVEL 32905 #define OP_MAXINVENTORY 32906 #define OP_MOVE 32907 #define OP_MOVE_C 34955 #define OP_MOVE_D 41099 #define OP_MOVE_CD 43147 #define OP_MOVEPLUS 32908 #define OP_MOVEPLUS_C 34956 #define OP_MOVEPLUS_D 41100 #define OP_MOVEPLUS_CD 43148 #define OP_MOVETO 32909 #define OP_MOVETO_C 34957 #define OP_MOVETO_D 41101 #define OP_MOVETO_CD 43149 #define OP_NEWX 32910 #define OP_NEWY 32911 #define OP_OBJABOVE 32912 #define OP_OBJABOVE_C 34960 #define OP_OBJBELOW 32913 #define OP_OBJBELOW_C 34961 #define OP_OBJBOTTOMAT 32914 #define OP_OBJCLASSAT 32915 #define OP_OBJDIR 32916 #define OP_OBJDIR_C 34964 #define OP_OBJTOPAT 32917 #define OP_POPUP 32918 #define OP_POPUPARGS 32919 #define OP_QUEUETURN 32920 #define OP_SEND 32921 #define OP_SEND_C 34969 #define OP_SEND_D 41113 #define OP_SEND_CD 43161 #define OP_SENDEX 32922 #define OP_SENDEX_C 34970 #define OP_SENDEX_D 41114 #define OP_SENDEX_CD 43162 #define OP_SETINVENTORY 32923 #define OP_SOUND 32924 #define OP_TRACE 32925 #define OP_VOLUMEAT 32926 #define OP_WINLEVEL 32927 #define OP_XDIR 32928 #define OP_XDIR_C 34976 #define OP_YDIR 32929 #define OP_YDIR_C 34977 #define OP_FUNCTION 32930 #define OP_LOCAL 32931 #define OP_LABEL 32932 #define OP_STRING 32933 #ifdef HEROMESH_CLASS static const Op_Names op_names[]={ {"*",8486933}, {"+",8421395}, {"-",8421396}, {".",10518528}, {"/",8486934}, {"ANHH",8389394}, {"ARRIVED",8389124}, {"Animate",8421493}, {"Arg1",8552551}, {"Arg2",8552552}, {"Arg3",8552553}, {"Arrivals",8618071}, {"Arrived",8618069}, {"Assassinate",8487030}, {"B",9437196}, {"BANG",8389380}, {"BEDOINGNG",8389406}, {"BEEDEEP",8389404}, {"BEGIN_TURN",8389123}, {"BOOOM",8389410}, {"BOUNCE",8389415}, {"BRRREEET",8389396}, {"BRRRT",8389395}, {"BUZZER",8389420}, {"BWEEP",8389397}, {"Background",8683629}, {"Broadcast",10518647}, {"BroadcastEx",10518649}, {"BroadcastSum",8421498}, {"BroadcastSumEx",8421499}, {"Busy",8618073}, {"CHEEP",8389393}, {"CHYEW",8389392}, {"CLEANUP",8389140}, {"CLICK",8389388}, {"COLLIDE",8389142}, {"COLLIDING",8389141}, {"CREATE",8389121}, {"CREATED",8389137}, {"Class",8486955}, {"Climb",9142335}, {"Compatible",8487011}, {"Create",10518652}, {"DEEP_POP",8389417}, {"DEPARTED",8389125}, {"DESTROY",8389122}, {"DESTROYED",8389136}, {"DINK",8389390}, {"DOOR",8389378}, {"DRLRLRINK",8389398}, {"DYUPE",8389413}, {"DefaultImage",8683633}, {"DelInventory",8421501}, {"Delta",8421502}, {"Density",9142327}, {"Departed",8618070}, {"Departures",8618072}, {"Destroy",10584191}, {"Destroyed",8487009}, {"Dir",8618033}, {"Distance",9142325}, {"E",9437184}, {"END_TURN",8389139}, {"EditorHelp",8683635}, {"F",9437192}, {"FAROUT",8389421}, {"FFFFTT",8389399}, {"FLOATED",8389132}, {"FROG",8389383}, {"FlushClass",8421504}, {"FlushObj",8421505}, {"From",8421478}, {"GLASS",8389379}, {"GLISSANT",8389419}, {"GetInventory",8421506}, {"HAWK",8389425}, {"HEARTBEAT",8389407}, {"HIT",8389134}, {"HITBY",8389135}, {"Hard",8618051}, {"Height",9142333}, {"HeightAt",8421507}, {"Help",8683634}, {"INIT",8389120}, {"IgnoreKey",8421508}, {"Image",8618034}, {"InPlace",8683632}, {"Inertia",9142323}, {"Input",8683630}, {"IntMove",10584197}, {"Invisible",8618074}, {"JAYAYAYNG",8389416}, {"JUMPED",8389128}, {"JumpTo",8487046}, {"KEWEL",8389422}, {"KEY",8389129}, {"KLECK",8389387}, {"KLINKK",8389385}, {"Key",8421484}, {"KeyCleared",8618075}, {"L",9437194}, {"LASTIMAGE",8389126}, {"LB",9437195}, {"LF",9437193}, {"LOCK",8389408}, {"LOOP",8388610}, {"Level",8421483}, {"Loc",8487047}, {"LocateMe",8421512}, {"LoseLevel",8421513}, {"MOVED",8389127}, {"MOVING",8389130}, {"MaxInventory",8421514}, {"Misc1",9142343}, {"Misc2",9142345}, {"Misc3",9142347}, {"Misc4",9142349}, {"Misc5",9142351}, {"Misc6",9142353}, {"Misc7",9142355}, {"Move",10584203}, {"Move+",10584204}, {"MoveNumber",8421482}, {"MoveTo",10584205}, {"Moved",8618080}, {"Msg",8421477}, {"N",9437186}, {"NE",9437185}, {"NW",9437187}, {"NewX",8421518}, {"NewY",8421519}, {"OLDPHONE",8389402}, {"ONCE",8388609}, {"OSC",8388616}, {"OSCLOOP",8388618}, {"ObjAbove",8487056}, {"ObjBelow",8487057}, {"ObjBottomAt",8421522}, {"ObjClassAt",8421523}, {"ObjDir",8487060}, {"ObjTopAt",8421525}, {"PLAYERMOVING",8389133}, {"POSTINIT",8389138}, {"POUR",8389377}, {"POWER",8389386}, {"Player",8487010}, {"PopUp",8421526}, {"QueueTurn",8421528}, {"Quiz",8683631}, {"R",9437198}, {"RATCHET1",8389418}, {"RATCHET2",8389412}, {"RATTLE",8389403}, {"RB",9437197}, {"RF",9437199}, {"S",9437190}, {"SE",9437191}, {"SMALL_POP",8389389}, {"SPLASH",8389376}, {"STEAM",8389424}, {"STOP",8388608}, {"SUBS",8683636}, {"SUNK",8389131}, {"SW",9437189}, {"Self",8421476}, {"Send",10584217}, {"SendEx",10584218}, {"SetInventory",8421531}, {"Shape",8618030}, {"ShapeDir",8618053}, {"Sharp",8618052}, {"Shovable",8618054}, {"Sound",8421532}, {"Stealthy",8618079}, {"Strength",9142337}, {"TAHTASHH",8389409}, {"THMP_thmp",8389405}, {"THWIT",8389384}, {"TICK",8389391}, {"Temperature",9142316}, {"Trace",8421533}, {"UH_OH",8389382}, {"UNCORK",8389414}, {"UNHH",8389381}, {"UserSignal",8618076}, {"UserState",8618077}, {"VACUUM",8389411}, {"VisualOnly",8618078}, {"Volume",9142329}, {"VolumeAt",8421534}, {"W",9437188}, {"WAHOO",8389400}, {"WHACK",8389423}, {"Weight",9142331}, {"WinLevel",8421535}, {"XDir",8487072}, {"Xloc",8486959}, {"YDir",8487073}, {"YEEHAW",8389401}, {"Yloc",8486960}, {"again",8683530}, {"band",8421403}, {"begin",8683529}, {"bit",8683551}, {"bit0",8388609}, |
︙ | ︙ | |||
595 596 597 598 599 600 601 | {"rsh",8486938}, {"swap",8421378}, {"then",8683527}, {"tuck",8421380}, {"until",8683531}, {"while",8683532}, }; | | | 609 610 611 612 613 614 615 616 617 | {"rsh",8486938}, {"swap",8421378}, {"then",8683527}, {"tuck",8421380}, {"until",8683531}, {"while",8683532}, }; #define N_OP_NAMES 268 #endif |
Modified main.c from [03fb7ee697] to [2e8581e7e0].
︙ | ︙ | |||
253 254 255 256 257 258 259 | exit(0); break; } } int main(int argc,char**argv) { int optind=1; | < > > > > > | 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 | exit(0); break; } } int main(int argc,char**argv) { int optind=1; while(argc>optind && argv[optind][0]=='-') { int i; const char*s=argv[optind++]; if(s[1]=='-' && !s[2]) break; for(i=1;s[i];i++) main_options[s[i]&127]=1; } if(!main_options['c']) fprintf(stderr,"FREE HERO MESH\n"); if(argc<=optind) fatal("usage: %s [switches] [--] basename [options...]\n",argc?argv[0]:"heromesh"); if(xrm_init(realloc)) fatal("Failed to initialize resource manager\n"); if(xrm_init_quarks(global_quarks)) fatal("Failed to initialize resource manager\n"); resourcedb=xrm_create(); if(!resourcedb) fatal("Allocation of resource database failed\n"); basefilename=argv[optind++]; if(argc>optind && argv[1][0]=='=') { globalclassname=argv[optind++]+1; } else if(find_globalclassname()) { globalclassname=strrchr(basefilename,'/'); globalclassname=globalclassname?globalclassname+1:basefilename; } if(main_options['c']) { load_classes(); return 0; } load_options(); if(argc>optind) read_options(argc-optind,argv+optind); *optionquery=xrm_make_quark(globalclassname,0)?:xrm_anyq; init_sql(); load_key_bindings(); init_screen(); |
︙ | ︙ |