BASIC compiler/interpreter for PIC32MX/MZ-80K
修訂 | ba72515e68910844bfb8a94d0a3e0d90e5eb1ac7 (tree) |
---|---|
時間 | 2019-02-12 04:54:56 |
作者 | Katsumi <kmorimatsu@sour...> |
Commiter | Katsumi |
Use 10 deleted pointers for new object if possible.
@@ -228,9 +228,26 @@ static const char initext[]= | ||
228 | 228 | static const char bastext[]= |
229 | 229 | "USECLASS CLASS1\n" |
230 | 230 | "CLS\n" |
231 | -"print CLASS1::T3()\n" | |
232 | -"\n" | |
233 | -"\n" | |
231 | +"dim o(95),v(95)\n" | |
232 | +"for i=1 to 85\n" | |
233 | +" o(i)=new(CLASS1)\n" | |
234 | +"next\n" | |
235 | +"for i=1 to 100\n" | |
236 | +" for j=1 to 85\n" | |
237 | +" v(j)=rnd()\n" | |
238 | +" o(j).T1=v(j)\n" | |
239 | +" next\n" | |
240 | +" for j=86 to 95\n" | |
241 | +" o(j)=new(CLASS1)\n" | |
242 | +" next\n" | |
243 | +" for j=86 to 95\n" | |
244 | +" DELETE o(j)\n" | |
245 | +" next\n" | |
246 | +" for j=1 to 85\n" | |
247 | +" if v(j)!=o(j).T1 then print \"ERR\":end\n" | |
248 | +" next\n" | |
249 | +"next\n" | |
250 | +"print \"OK\"\n" | |
234 | 251 | "\n" |
235 | 252 | "\n" |
236 | 253 | "\n" |
@@ -238,6 +255,7 @@ static const char bastext[]= | ||
238 | 255 | |
239 | 256 | |
240 | 257 | static const char classtext[]= |
258 | +"FIELD T1,T2\n" | |
241 | 259 | "METHOD T3\n" |
242 | 260 | " return 123\n" |
243 | 261 | "\n" |
@@ -26,22 +26,31 @@ | ||
26 | 26 | */ |
27 | 27 | |
28 | 28 | static int g_temp_var_num_candidate=ALLOC_PERM_BLOCK; |
29 | -static int g_last_deleted_pointer; | |
30 | -static int g_last_deleted_size=0; | |
29 | + | |
30 | +#define DELETE_LIST_SIZE 10 | |
31 | +static int g_deleted_num; | |
32 | +static int g_deleted_pointer[DELETE_LIST_SIZE]; | |
33 | +static int g_deleted_size[DELETE_LIST_SIZE]; | |
34 | + | |
31 | 35 | |
32 | 36 | #define register_deleted_block(x,y) \ |
33 | 37 | do {\ |
34 | - g_last_deleted_pointer=(x);\ | |
35 | - g_last_deleted_size=(y);\ | |
38 | + if (g_deleted_num<DELETE_LIST_SIZE) {\ | |
39 | + g_deleted_pointer[g_deleted_num]=(x);\ | |
40 | + g_deleted_size[g_deleted_num]=(y);\ | |
41 | + g_deleted_num++;\ | |
42 | + }\ | |
36 | 43 | } while(0) |
37 | 44 | |
38 | 45 | void set_free_area(void* begin, void* end){ |
46 | + // Initialize heap area | |
39 | 47 | int i; |
40 | 48 | for(i=0;i<ALLOC_BLOCK_NUM;i++){ |
41 | 49 | g_var_size[i]=0; |
42 | 50 | } |
43 | 51 | g_heap_mem=(int*)begin; |
44 | 52 | g_max_mem=(int)((end-begin)/4); |
53 | + g_deleted_num=0; | |
45 | 54 | } |
46 | 55 | |
47 | 56 | void* calloc_memory(int size, int var_num){ |
@@ -98,13 +107,19 @@ void* _alloc_memory_main(int size, int var_num){ | ||
98 | 107 | g_var_pointer[var_num]=0; |
99 | 108 | while(1){ |
100 | 109 | // Try the block previously deleted |
101 | - if (size<=g_last_deleted_size) { | |
102 | - g_last_deleted_size=0; | |
103 | - candidate=g_last_deleted_pointer; | |
110 | + candidate=0; | |
111 | + while(g_deleted_num){ | |
112 | + // Check if the last deleted block fits | |
113 | + // If not, these cannot be used anymore | |
114 | + g_deleted_num--; | |
115 | + if (size<=g_deleted_size[g_deleted_num]) { | |
116 | + candidate=g_deleted_pointer[g_deleted_num]; | |
117 | + break; | |
118 | + } | |
119 | + } | |
120 | + if (candidate || g_deleted_num) { | |
121 | + // Candidate found | |
104 | 122 | break; |
105 | - } else { | |
106 | - // Last deleted block is a candidate only once | |
107 | - g_last_deleted_size=0; | |
108 | 123 | } |
109 | 124 | // Try the block after last block |
110 | 125 | candidate=0; |