BASIC compiler/interpreter for PIC32MX/MZ-80K
修訂 | 248e3318060e4f3fbda9efd2e276a9f65a03b534 (tree) |
---|---|
時間 | 2019-03-17 09:19:35 |
作者 | Katsumi <kmorimatsu@sour...> |
Commiter | Katsumi |
Support loading class file from LIB directory.
SETDIR/GETDIR functions and statement.
@@ -1,5 +1,5 @@ | ||
1 | 1 | REM CSWTIF.BAS ver 0.1 |
2 | -REM Class CSWPNG for MachiKania Type M | |
2 | +REM Class CSWTIF for MachiKania Type M | |
3 | 3 | REM for showing TIFF picture file |
4 | 4 | |
5 | 5 | REM FNAME: file name |
@@ -25,10 +25,22 @@ | ||
25 | 25 | data16: general 16 bit data (short) |
26 | 26 | */ |
27 | 27 | |
28 | +/* | |
29 | + CMPDATA_TEMP structure | |
30 | + type: CMPDATA_TEMP (6) | |
31 | + len: n+1 | |
32 | + data16: id | |
33 | + record[1]: any data | |
34 | + record[2]: any data | |
35 | + ... | |
36 | + record[n]: any data | |
37 | +*/ | |
38 | + | |
28 | 39 | #define g_cmpdata g_objmax |
29 | 40 | |
30 | 41 | static int* g_cmpdata_end; |
31 | 42 | static int* g_cmpdata_point; |
43 | +static unsigned short g_cmpdata_id; | |
32 | 44 | |
33 | 45 | /* |
34 | 46 | Initialize routine must be called when starting compiler. |
@@ -36,6 +48,15 @@ static int* g_cmpdata_point; | ||
36 | 48 | void cmpdata_init(){ |
37 | 49 | g_cmpdata_end=g_objmax; |
38 | 50 | g_cmpdata_point=g_objmax; |
51 | + g_cmpdata_id=1; | |
52 | +} | |
53 | + | |
54 | +/* | |
55 | + Returns ID as 16 bit indivisual number | |
56 | +*/ | |
57 | +unsigned short cmpdata_get_id(){ | |
58 | + if ((++g_cmpdata_id)==0) printstr("CMPDATA: no more ID!\n"); | |
59 | + return g_cmpdata_id; | |
39 | 60 | } |
40 | 61 | |
41 | 62 | /* |
@@ -122,6 +122,9 @@ enum libs{ | ||
122 | 122 | LIB_FILE =LIB_STEP*48, |
123 | 123 | LIB_PLAYWAVE =LIB_STEP*49, |
124 | 124 | LIB_PLAYWAVEFUNC =LIB_STEP*50, |
125 | + LIB_SETDIR =LIB_STEP*51, | |
126 | + LIB_SETDIRFUNC =LIB_STEP*52, | |
127 | + LIB_GETDIR =LIB_STEP*53, | |
125 | 128 | LIB_DEBUG =LIB_STEP*127, |
126 | 129 | }; |
127 | 130 |
@@ -321,6 +324,7 @@ void blue_screen(void); | ||
321 | 324 | char* get_float(); |
322 | 325 | |
323 | 326 | void cmpdata_init(); |
327 | +unsigned short cmpdata_get_id(); | |
324 | 328 | char* cmpdata_insert(unsigned char type, short data16, int* data, unsigned char num); |
325 | 329 | void cmpdata_reset(); |
326 | 330 | int* cmpdata_find(unsigned char type); |
@@ -401,6 +405,7 @@ char* resolve_unresolved(int class); | ||
401 | 405 | #define CMPDATA_FIELD 3 |
402 | 406 | #define CMPDATA_STATIC 4 |
403 | 407 | #define CMPDATA_UNSOLVED 5 |
408 | +#define CMPDATA_TEMP 6 | |
404 | 409 | // Sub types follow |
405 | 410 | #define CMPTYPE_PUBLIC_FIELD 0 |
406 | 411 | #define CMPTYPE_PRIVATE_FIELD 1 |
@@ -227,22 +227,12 @@ static const char initext[]= | ||
227 | 227 | "#PRINT\n" |
228 | 228 | "#PRINT\n"; |
229 | 229 | |
230 | - | |
231 | 230 | static const char bastext[]= |
232 | -"USECLASS CLASS1\n" | |
233 | -"CLS\n" | |
234 | -"dim o(9)\n" | |
235 | -"for j=1 to 100\n" | |
236 | -" cursor 0,0\n" | |
237 | -" for i=1 to 9\n" | |
238 | -" o(i)=new(CLASS1)\n" | |
239 | -" next\n" | |
240 | -" for i=1 to 9\n" | |
241 | -" a=o(i)\n" | |
242 | -" print hex$(a),\n" | |
243 | -" delete a\n" | |
244 | -" next\n" | |
245 | -"next\n" | |
231 | +"print getdir$()\n" | |
232 | +"end\n" | |
233 | +"\n" | |
234 | +"\n" | |
235 | +"\n" | |
246 | 236 | "\n" |
247 | 237 | "\n" |
248 | 238 | "\n"; |
@@ -280,7 +270,14 @@ static const void* debugjumptable[]={ | ||
280 | 270 | |
281 | 271 | int _debug_test(int a0, int a1, int a2, int a3, int param4, int param5){ |
282 | 272 | asm volatile(".set noreorder"); |
283 | - asm volatile("lw $a0,-8($s5)"); | |
273 | + asm volatile("lw $a0,4($s5)"); | |
274 | + asm volatile("lw $a1,8($s5)"); | |
275 | + asm volatile("lw $a2,12($s5)"); | |
276 | + asm volatile("lw $a3,16($s5)"); | |
277 | + asm volatile("nop"); | |
278 | + asm volatile("nop"); | |
279 | + asm volatile("nop"); | |
280 | + asm volatile("nop"); | |
284 | 281 | asm volatile("nop"); |
285 | 282 | asm volatile("nop"); |
286 | 283 | asm volatile("nop"); |
@@ -170,11 +170,14 @@ int compile_and_link_file(char* buff,char* appname){ | ||
170 | 170 | } |
171 | 171 | |
172 | 172 | int compile_and_link_class(char* buff,int class){ |
173 | - int i; | |
173 | + int i,j; | |
174 | 174 | char* err; |
175 | 175 | char* classname; |
176 | 176 | char classfile[13]; |
177 | + char classdir[11]; | |
177 | 178 | int data[2]; |
179 | + unsigned short cwd_id; | |
180 | + int* record; | |
178 | 181 | while(1){ |
179 | 182 | // Begin compiling class |
180 | 183 | err=begin_compiling_class(class); |
@@ -187,9 +190,41 @@ int compile_and_link_class(char* buff,int class){ | ||
187 | 190 | classfile[i++]='A'; |
188 | 191 | classfile[i++]='S'; |
189 | 192 | classfile[i]=0; |
190 | - // Compile it | |
191 | - i=compile_and_link_file(buff,&classfile[0]); | |
192 | - if (i) break; | |
193 | + // Check if file exists in current directory | |
194 | + err=init_file(buff,&classfile[0]); | |
195 | + if (!err) { | |
196 | + // Class file found in current directory | |
197 | + close_file(); | |
198 | + // Compile it | |
199 | + i=compile_and_link_file(buff,&classfile[0]); | |
200 | + if (i) break; | |
201 | + } else { | |
202 | + // Class file not found in current directory. | |
203 | + // Try library directory, for example, \LIB\CLASS1\CLASS1.BAS | |
204 | + // Store current directory, first | |
205 | + if (!FSgetcwd(buff,256)) break; | |
206 | + for(i=0;buff[i];i++); | |
207 | + cwd_id=cmpdata_get_id(); | |
208 | + if (!cwd_id) break; | |
209 | + err=cmpdata_insert(CMPDATA_TEMP,cwd_id,(int*)(&buff[0]),(i+1+3)>>2); | |
210 | + if (err) break; | |
211 | + // Change current directory to class library directory | |
212 | + for(i=0;classdir[i]="\\LIB\\"[i];i++); | |
213 | + for(j=0;classdir[i++]=classname[j];j++); | |
214 | + classdir[i]=0; | |
215 | + FSchdir(classdir); | |
216 | + // Compile class file | |
217 | + i=compile_and_link_file(buff,&classfile[0]); | |
218 | + // Restore current dirctory | |
219 | + cmpdata_reset(); | |
220 | + while(record=cmpdata_find(CMPDATA_TEMP)){ | |
221 | + if (cwd_id=(record[0]&0xffff)) break; | |
222 | + } | |
223 | + if (!record) break; | |
224 | + FSchdir((char*)(&record[1])); | |
225 | + cmpdata_delete(record); | |
226 | + if (i) break; | |
227 | + } | |
193 | 228 | // End compiling class |
194 | 229 | err=end_compiling_class(class); |
195 | 230 | if (err) break; |
@@ -379,6 +379,19 @@ char* playwave_function(){ | ||
379 | 379 | return 0; |
380 | 380 | } |
381 | 381 | |
382 | +char* setdir_function(){ | |
383 | + char* err; | |
384 | + err=get_string(); | |
385 | + if (err) return err; | |
386 | + call_lib_code(LIB_SETDIRFUNC); | |
387 | + return 0; | |
388 | +} | |
389 | + | |
390 | +char* getdir_function(){ | |
391 | + call_lib_code(LIB_GETDIR); | |
392 | + return 0; | |
393 | +} | |
394 | + | |
382 | 395 | char* float_constant(float val){ |
383 | 396 | volatile int i; |
384 | 397 | ((float*)(&i))[0]=val; |
@@ -498,6 +511,7 @@ static const void* str_func_list[]={ | ||
498 | 511 | "FLOAT$(",floatstr_function, |
499 | 512 | "SYSTEM$(",system_function, |
500 | 513 | "FINPUT$(",finput_function, |
514 | + "GETDIR$(",getdir_function, | |
501 | 515 | // Additional functions follow |
502 | 516 | ADDITIONAL_STR_FUNCTIONS |
503 | 517 | }; |
@@ -582,6 +596,7 @@ static const void* int_func_list[]={ | ||
582 | 596 | "FEOF(",feof_function, |
583 | 597 | "PLAYWAVE(",playwave_function, |
584 | 598 | "NEW(",new_function, |
599 | + "SETDIR(",setdir_function, | |
585 | 600 | // Additional functions follow |
586 | 601 | ADDITIONAL_INT_FUNCTIONS |
587 | 602 | }; |
@@ -25,6 +25,20 @@ static int g_gcolor=7; | ||
25 | 25 | static int g_prev_x=0; |
26 | 26 | static int g_prev_y=0; |
27 | 27 | |
28 | +int lib_setdir(int mode,char* path){ | |
29 | + int ret; | |
30 | + ret=FSchdir(path); | |
31 | + if (mode==LIB_SETDIR && ret) err_file(); | |
32 | + return ret; | |
33 | +} | |
34 | + | |
35 | +int lib_getdir(){ | |
36 | + char* path; | |
37 | + path=calloc_memory(32,-1); | |
38 | + FSgetcwd (path,128); | |
39 | + return (int)path; | |
40 | +} | |
41 | + | |
28 | 42 | int lib_read(int mode, unsigned int label){ |
29 | 43 | unsigned int i,code,code2; |
30 | 44 | static unsigned int pos=0; |
@@ -1016,6 +1030,11 @@ int _call_library(int a0,int a1,int v0,enum libs a3){ | ||
1016 | 1030 | case LIB_SETDRAWCOUNT: |
1017 | 1031 | drawcount=(v0&0x0000FFFF); |
1018 | 1032 | return v0; |
1033 | + case LIB_GETDIR: | |
1034 | + return lib_getdir(); | |
1035 | + case LIB_SETDIRFUNC: | |
1036 | + case LIB_SETDIR: | |
1037 | + return lib_setdir(a3,(char*)v0); | |
1019 | 1038 | case LIB_DRAWCOUNT: |
1020 | 1039 | return drawcount; |
1021 | 1040 | case LIB_SYSTEM: |
@@ -88,6 +88,7 @@ var namearray=[ | ||
88 | 88 | 'FSEEK', |
89 | 89 | 'GCLS', |
90 | 90 | 'GCOLOR', |
91 | + 'GETDIR', | |
91 | 92 | 'GOSUB', |
92 | 93 | 'GOTO', |
93 | 94 | 'GPRINT', |
@@ -128,6 +129,7 @@ var namearray=[ | ||
128 | 129 | 'RETURN', |
129 | 130 | 'RND', |
130 | 131 | 'SCROLL', |
132 | + 'SETDIR', | |
131 | 133 | 'SGN', |
132 | 134 | 'SIN', |
133 | 135 | 'SINH', |
@@ -1542,6 +1542,14 @@ char* useclass_statement(){ | ||
1542 | 1542 | return 0; |
1543 | 1543 | } |
1544 | 1544 | |
1545 | +char* setdir_statement(){ | |
1546 | + char* err; | |
1547 | + err=get_string(); | |
1548 | + if (err) return err; | |
1549 | + call_lib_code(LIB_SETDIR); | |
1550 | + return 0; | |
1551 | +} | |
1552 | + | |
1545 | 1553 | #ifdef __DEBUG |
1546 | 1554 | char* debug_statement(){ |
1547 | 1555 | call_lib_code(LIB_DEBUG); |
@@ -1689,6 +1697,7 @@ static const void* statement_list[]={ | ||
1689 | 1697 | "DELETE ",delete_statement, |
1690 | 1698 | "CALL ",call_statement, |
1691 | 1699 | "STATIC ",static_statement, |
1700 | + "SETDIR ",setdir_statement, | |
1692 | 1701 | // List of additional statements follows |
1693 | 1702 | ADDITIONAL_STATEMENTS |
1694 | 1703 | }; |
@@ -69,6 +69,7 @@ static const int reserved_var_names[]={ | ||
69 | 69 | 0x00aefdec, /*FSEEK*/ |
70 | 70 | 0x00063b90, /*GCLS*/ |
71 | 71 | 0x1a808bcb, /*GCOLOR*/ |
72 | + 0x1ab733b3, /*GETDIR*/ | |
72 | 73 | 0x00c60f03, /*GOSUB*/ |
73 | 74 | 0x0006796c, /*GOTO*/ |
74 | 75 | 0x1bcfcc39, /*GPRINT*/ |
@@ -109,6 +110,7 @@ static const int reserved_var_names[]={ | ||
109 | 110 | 0x425c9703, /*RETURN*/ |
110 | 111 | 0x00015e69, /*RND*/ |
111 | 112 | 0x45c26d49, /*SCROLL*/ |
113 | + 0x45f6e3b3, /*SETDIR*/ | |
112 | 114 | 0x00016287, /*SGN*/ |
113 | 115 | 0x000162cf, /*SIN*/ |
114 | 116 | 0x000ee52d, /*SINH*/ |