Overview
Comment: | More parsing of .class file |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
e049e8ed331faa2517b6ac69352f5bc5 |
User & Date: | user on 2018-05-19 19:23:52 |
Other Links: | manifest | tags |
Context
2018-05-19
| ||
22:31 | Add shell script to compile everything; support $CFLAGS and $EXE environment variables check-in: f833310c79 user: user tags: trunk | |
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 | |
Changes
Modified class.c from [10cd656230] to [aa9b29b498].
︙ | |||
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | + + + | typedef struct { const char*txt; Uint32 num; } Op_Names; #include "instruc.h" #define Tokenf(x) (tokent&(x)) Value globals[0x800]; Value initglobals[0x800]; Class*classes[0x4000]; const char*messages[0x4000]; Uint16 functions[0x4000]; int max_animation=32; Sint32 max_volume=10000; Uint8 back_color=1; char**stringpool; #define HASH_SIZE 8888 #define LOCAL_HASH_SIZE 5555 typedef struct { Uint16 id; char*txt; } Hash; |
︙ | |||
77 78 79 80 81 82 83 84 85 86 87 88 89 90 | 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | + + | 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 int num_strings=0; static char pushback=0; static Hash*glohash; static InputStack*inpstack; static MacroStack*macstack; static TokenList**macros; #define ParseError(a,...) fatal("On line %d: " a,linenum,##__VA_ARGS__) |
︙ | |||
217 218 219 220 221 222 223 | 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | - + | if(!cl) fatal("Allocation failed\n"); cl->name=strdup(name); if(!cl->name) fatal("Allocation failed\n"); cl->edithelp=cl->gamehelp=0; cl->codes=cl->messages=cl->images=0; cl->height=cl->weight=cl->climb=cl->density=cl->volume=cl->strength=cl->arrivals=cl->departures=0; cl->temperature=cl->misc4=cl->misc5=cl->misc6=cl->misc7=0; |
︙ | |||
584 585 586 587 588 589 590 591 592 593 594 595 596 597 | 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 | + + + + | *ap=add_macro(); ap=&((*ap)->next); } } } static void nxttok(void) { if(pushback) { pushback=0; return; } again: nxttok1(); if(tokent&TF_EOF) { if(inpstack) { InputStack s=*inpstack; free(inpstack); fclose(classfp); |
︙ | |||
771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 | 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 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | break; default: ParseError("Strange macro token: 0x%04X\n",glohash[tokenv].id); } } } } static int pool_string(const char*s) { int i; for(i=0;i<num_strings;i++) if(!strcmp(s,stringpool[i])) return i; i=num_strings++; if(i>32768) ParseError("Too many string literals\n"); stringpool=realloc(stringpool,num_strings*sizeof(stringpool)); if(!stringpool) fatal("Allocation failed\n"); stringpool[i]=strdup(s); if(!stringpool[i]) fatal("Allocation failed\n"); return i; } static Value parse_constant_value(void) { if(tokent==TF_INT) { return NVALUE(tokenv); } else if(Tokenf(TF_NAME)) { switch(tokenv) { case 0x0000 ... 0x00FF: return NVALUE(tokenv); case 0x0100 ... 0x01FF: return NVALUE(tokenv-0x0200); case 0x0200 ... 0x02FF: return MVALUE(tokenv&255); case 0x0300 ... 0x03FF: return UVALUE(0,TY_SOUND); case 0x0400 ... 0x04FF: return UVALUE(0,TY_USOUND); case 0x4000 ... 0x7FFF: return CVALUE(tokenv-0x4000); case OP_STRING: return UVALUE(pool_string(tokenstr),TY_STRING); case OP_BITCONSTANT ... OP_BITCONSTANT_LAST: return NVALUE(1<<(tokenv&31)); case 0xC000 ... 0xFFFF: return MVALUE(tokenv-0xBF00); } } ParseError("Constant value expected\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)) static int parse_instructions(int cla,int ptr,Hash*hash) { int peep=ptr; int prflag=0; Class*cl=classes[cla]; cl->codes=realloc(cl->codes,0x10000*sizeof(Uint16)); if(!cl->codes) fatal("Allocation failed\n"); for(;;) { nxttok(); if(Tokenf(TF_MACRO)) ParseError("Unexpected macro\n"); if(Tokenf(TF_INT)) { } else if(Tokenf(TF_NAME)) { switch(tokenv) { default: if(Tokenf(TF_ABNORMAL)) ParseError("Invalid instruction token\n"); AddInstF(tokenv,tokent); } } else if(Tokenf(TF_FUNCTION)) { AddInst2(OP_FUNCTION,tokenv&0x3FFF); } else if(tokent==TF_OPEN) { nxttok(); if(Tokenf(TF_MACRO) || !Tokenf(TF_NAME)) ParseError("Invalid parenthesized instruction\n"); switch(tokenv) { default: ParseError("Invalid parenthesized instruction\n"); } } else if(tokent==TF_CLOSE) { if(peep<ptr && cl->codes[ptr-1]<0x0100) cl->codes[ptr-1]+=0x1E00; else AddInst(OP_RET); break; } else { ParseError("Invalid instruction token\n"); } if(ptr>=0xFFEF) ParseError("Out of code space\n"); } cl->codes=realloc(cl->codes,ptr*sizeof(Uint16))?:cl->codes; return ptr; } void load_classes(void) { int i; int gloptr=0; Hash*glolocalhash; 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"); glolocalhash=calloc(LOCAL_HASH_SIZE,sizeof(Hash)); if(!glolocalhash) 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; |
︙ | |||
807 808 809 810 811 812 813 | 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 | + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | if(tokenstr[i]<32 || tokenstr[i]>126) printf("<%02X>",tokenstr[i]&255); else putchar(tokenstr[i]); } printf("\"\n"); if(Tokenf(TF_EOF)) goto done; } } *classes=malloc(sizeof(Class)); if(!*classes) fatal("Allocation failed\n"); classes[0]->name=classes[0]->edithelp=classes[0]->gamehelp=0; classes[0]->codes=classes[0]->messages=classes[0]->images=0; classes[0]->nmsg=0; memset(functions,-1,sizeof(functions)); for(;;) { nxttok(); if(tokent==TF_EOF) goto done; if(tokent!=TF_OPEN) ParseError("Expected open parenthesis\n"); nxttok(); if(Tokenf(TF_FUNCTION)) { |
Modified heromesh.h from [27851ceca3] to [6804915000].
︙ | |||
19 20 21 22 23 24 25 26 27 28 29 30 31 32 | 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | + + + + + + | typedef struct { union { Sint32 s; Uint32 u; }; Uint32 t; // Type 0-15, or a generation_number of an object } Value; #define UVALUE(x,y) ((Value){.u=x,.t=y}) #define SVALUE(x,y) ((Value){.s=x,.t=y}) #define NVALUE(x) SVALUE(x,TY_NUMBER) #define CVALUE(x) UVALUE(x,TY_CLASS) #define MVALUE(x) UVALUE(x,TY_MESSAGE) #define ZVALUE(x) UVALUE(x,TY_STRING) extern const char*const standard_message_names[]; extern const char*const standard_sound_names[]; extern const char*const heromesh_key_names[256]; extern sqlite3*userdb; extern xrm_db*resourcedb; |
︙ | |||
72 73 74 75 76 77 78 | 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 | - + + + + | const char*edithelp; // not present if CF_GROUP const char*gamehelp; // not present if CF_GROUP Uint16*codes; // if this is CF_GROUP, then instead a zero-terminated list of classes Uint16*messages; // use 0xFFFF if no such message block; not present if CF_GROUP Uint16*images; // high bit is set if available to editor; not present if CF_GROUP Sint32 height,weight,climb,density,volume,strength,arrivals,departures; Sint32 temperature,misc4,misc5,misc6,misc7; |
︙ |
Modified instruc from [ef77bce557] to [0dc50cbad6].
︙ | |||
51 52 53 54 55 56 57 | 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | - + | #bit24 #bit25 #bit26 #bit27 #bit28 #bit29 #bit30 |
︙ | |||
231 232 233 234 235 236 237 238 | 231 232 233 234 235 236 237 238 239 240 | + + | ,YDir ; Specials *Function *Local *Label *String *Int16 *Int32 |
Modified instruc.h from [a3dc22f64a] to [834265d374].
1 2 3 4 5 6 7 8 | 1 2 3 4 5 6 7 8 9 | + | #define OP_BITCONSTANT 34792 #define OP_BITCONSTANT_LAST 34815 #define OP_STOP 0 #define OP_ONCE 1 #define OP_LOOP 2 #define OP_OSC 8 #define OP_OSCLOOP 10 #define OP_DROP 32768 #define OP_DROP_D 40960 |
︙ | |||
338 339 340 341 342 343 344 345 346 347 348 349 350 351 | 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 | + + | #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 #define OP_INT16 32934 #define OP_INT32 32935 #ifdef HEROMESH_CLASS static const Op_Names op_names[]={ {"*",8486933}, {"+",8421395}, {"-",8421396}, {".",10518528}, {"/",8486934}, |
︙ |