Overview
Comment: | More class loading code |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
9d448767e434ec04a33a4335cbda3918 |
User & Date: | user on 2018-05-27 22:33:21 |
Other Links: | manifest | tags |
Context
2018-06-03
| ||
22:43 | The syntax of for/next loops has been changed; also added some codes for dealing with user cache data check-in: 8b26cd42e7 user: user tags: trunk | |
2018-05-27
| ||
22:33 | More class loading code check-in: 9d448767e4 user: user tags: trunk | |
2018-05-19
| ||
22:31 | Add shell script to compile everything; support $CFLAGS and $EXE environment variables check-in: f833310c79 user: user tags: trunk | |
Changes
Modified class.c from [8167e45e03] to [d60d73f095].
︙ | |||
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 | 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 | + + + + + + + + | typedef struct MacroStack { TokenList*tok; Sint16 n; TokenList**args; struct MacroStack*next; } MacroStack; typedef struct LabelStack { Uint16 id; Uint16 addr; struct LabelStack*next; } LabelStack; 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 int num_strings=0; static char pushback=0; static Hash*glohash; static InputStack*inpstack; static MacroStack*macstack; static TokenList**macros; static LabelStack*labelstack; static Uint16*labelptr; #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, |
︙ | |||
228 229 230 231 232 233 234 235 236 237 238 239 240 241 | 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 | + + + + + + + + + + + + + + + | cl->temperature=cl->misc4=cl->misc5=cl->misc6=cl->misc7=0; cl->uservars=cl->hard[0]=cl->hard[1]=cl->hard[2]=cl->hard[3]=cl->nmsg=0; cl->oflags=cl->sharp[0]=cl->sharp[1]=cl->sharp[2]=cl->sharp[3]=0; cl->shape=cl->shovable=cl->collisionLayers=cl->nimages=0; cl->cflags=f; if(undef_class<=n) undef_class=n+1; } Uint16 get_message_ptr(int c,int m) { if(!classes[c]) return 0xFFFF; if(classes[c]->nmsg<=m) return 0xFFFF; return classes[c]->messages[m]; } static void set_message_ptr(int c,int m,int p) { if(m>classes[c]->nmsg) { classes[c]->messages=realloc(classes[c]->messages,(m+1)*sizeof(Uint16)); if(!classes[c]->messages) fatal("Allocation failed\n"); while(m>classes[c]->nmsg) classes[c]->messages[classes[c]->nmsg++]=0xFFFF; } classes[c]->messages[m]=p; } static int look_class_name(void) { int i; int u=undef_class; for(i=1;i<undef_class;i++) { if(classes[i]) { if(!strcmp(classes[i]->name,tokenstr)) { |
︙ | |||
487 488 489 490 491 492 493 | 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 | - + | case ':': tokent=TF_NAME|TF_ABNORMAL|fl; tokenv=OP_LABEL; break; case '&': if(fl) ParseError("Invalid use of , and = in token\n"); tokent=TF_FUNCTION|TF_ABNORMAL; |
︙ | |||
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 | 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 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + | 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"); } static void begin_label_stack(void) { labelstack=0; labelptr=malloc(0x8000*sizeof(Uint16)); if(!labelptr) fatal("Allocation failed\n"); memset(labelptr,255,0x8000*sizeof(Uint16)); *labelptr=0x8001; } static void end_label_stack(Uint16*codes,Hash*hash) { LabelStack*s; while(labelstack) { s=labelstack; if(labelptr[s->id-0x8000]==0xFFFF) { int i; for(i=0;i<LOCAL_HASH_SIZE;i++) { if(hash[i].id==s->id) ParseError("Label :%s mentioned but never defined\n",hash[i].txt); } ParseError("Label mentioned but never defined\n"); } codes[s->addr]=labelptr[s->id-0x8000]; 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) #define Inst8bit() (peep<ptr && cl->codes[ptr-1]<0x0100) #define AbbrevOp(x,y) case x: if(Inst7bit()) ChangeInst(+=0x1000|((y)<<4)); else AddInstF(x,tokent); break #define FlowPush(x) do{ if(flowdepth==64) ParseError("Too much flow control nesting\n"); flowop[flowdepth]=x; flowptr[flowdepth++]=ptr; }while(0) #define FlowPop(x) do{ if(!flowdepth || flowop[--flowdepth]!=(x)) ParseError("Flow control mismatch\n"); }while(0) static int parse_instructions(int cla,int ptr,Hash*hash) { int peep=ptr; int prflag=0; Class*cl=classes[cla]; int flowdepth=0; Uint16 flowop[64]; Uint16 flowptr[64]; int x,y; 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)) { |
︙ | |||
857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 | 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 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 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 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + | AbbrevOp(OP_GT,0x88); AbbrevOp(OP_LE,0x90); AbbrevOp(OP_GE,0x98); AbbrevOp(OP_LT_C,0xA0); AbbrevOp(OP_GT_C,0xA8); AbbrevOp(OP_LE_C,0xB0); AbbrevOp(OP_GE_C,0xB8); AbbrevOp(OP_RET,0xE0); case OP_DROP: if(InstFlag(TF_DROP)) ChangeInst(+=0x2000); else AddInst(OP_DROP); break; case OP_LOCAL: if(!cla) ParseError("Cannot use local variable in a global definition\n"); tokenv=look_hash(hash,LOCAL_HASH_SIZE,0x2000,0x27FF,cl->uservars+0x2000,"user local variables")?:(cl->uservars++)+0x2000; if(Tokenf(TF_EQUAL)) tokenv+=0x1000; AddInst(tokenv); break; case OP_LABEL: tokenv=look_hash(hash,LOCAL_HASH_SIZE,0x8000,0xFFFF,*labelptr,"labels"); if(!tokenv) tokenv=*labelptr,++*labelptr; tokenv-=0x8000; if(Tokenf(TF_COMMA)) { AddInst2(OP_CALLSUB,labelptr[tokenv]); } else if(Tokenf(TF_EQUAL)) { AddInst2(OP_GOTO,labelptr[tokenv]); } else { if(labelptr[tokenv]!=0xFFFF) ParseError("Duplicate definition of label :%s\n",tokenstr); labelptr[tokenv]=ptr; peep=ptr; break; } 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_IF: AddInst(OP_IF); FlowPush(OP_IF); peep=++ptr; break; case OP_THEN: FlowPop(OP_IF); cl->codes[flowptr[flowdepth]]=peep=ptr; break; case OP_ELSE: FlowPop(OP_IF); x=flowptr[flowdepth]; AddInst(OP_GOTO); FlowPush(OP_IF); cl->codes[x]=peep=++ptr; break; case OP_EL: AddInst(OP_GOTO); y=++ptr; FlowPop(OP_IF); x=flowptr[flowdepth]; AddInst(OP_GOTO); FlowPush(OP_IF); cl->codes[x]=peep=++ptr; flowptr[flowdepth-1]=y; break; case OP_BEGIN: FlowPush(OP_BEGIN); peep=ptr; break; case OP_AGAIN: FlowPop(OP_BEGIN); AddInst2(OP_GOTO,flowptr[flowdepth]); break; case OP_UNTIL: FlowPop(OP_BEGIN); AddInst2(OP_IF,flowptr[flowdepth]); break; case OP_WHILE: AddInst(OP_IF); FlowPush(OP_WHILE); peep=++ptr; break; case OP_REPEAT: FlowPop(OP_WHILE); x=flowptr[flowdepth]; FlowPop(OP_BEGIN); AddInst2(OP_GOTO,flowptr[flowdepth]); cl->codes[x]=ptr; break; case OP_NEXT: FlowPop(OP_FOR); AddInst(OP_NEXT); cl->codes[flowptr[flowdepth]]=ptr; break; 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) { case OP_FOR: nxttok(); if(Tokenf(TF_MACRO|TF_EQUAL) || !Tokenf(TF_NAME)) ParseError("Global or local variable expected\n"); if(tokenv==OP_LOCAL) { if(!cla) ParseError("Cannot use local variable in a global definition\n"); tokenv=look_hash(hash,LOCAL_HASH_SIZE,0x2000,0x27FF,cl->uservars+0x2000,"user local variables")?:(cl->uservars++)+0x2000; } else if(tokenv<0x2000 || tokenv>0x2FFF) { ParseError("Global or local variable expected\n"); |
︙ | |||
940 941 942 943 944 945 946 | 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 | - + + + + - + - + + + + | 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 [6804915000] to [a6cc7a9107].
︙ | |||
94 95 96 97 98 99 100 101 102 103 104 105 106 107 | 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | + | 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; extern char**stringpool; Uint16 get_message_ptr(int c,int m); void load_classes(void); // == bindings == typedef struct { char cmd; union { |
︙ |