• R/O
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

BASIC compiler/interpreter for PIC32MX/MZ-80K (suspended)


Commit MetaInfo

Revision154 (tree)
Time2016-08-24 06:18:08
Authorkmorimatsu

Log Message

Implement CONTINUE statement.

Change Summary

Incremental Difference

--- mips/branches/zoea/compiler.h (revision 153)
+++ mips/branches/zoea/compiler.h (revision 154)
@@ -168,6 +168,7 @@
168168 extern unsigned char* g_pcg_font;
169169 extern char g_use_graphic;
170170 extern unsigned short* g_graphic_area;
171+extern int g_temp;
171172
172173 /* Prototypes */
173174 int get_gp(void);
--- mips/branches/zoea/debug.c (revision 153)
+++ mips/branches/zoea/debug.c (revision 154)
@@ -139,12 +139,11 @@
139139
140140 static const char bastext[]=
141141 "CLS\n"
142-"T#=10\n"
143-"T#=-10\n"
144-"T#=0\n"
145-"IF INT(T#=0) THEN X=1\n"
146-"T#=-10\n"
147-"PRINT T#\n"
142+"for i=1 to 10\n"
143+" print i;\n"
144+" continue\n"
145+" print \"NG\";\n"
146+"next\n"
148147 "\n";
149148
150149 /*
--- mips/branches/zoea/globalvars.c (revision 153)
+++ mips/branches/zoea/globalvars.c (revision 154)
@@ -69,3 +69,5 @@
6969 // Pointer to graphic RAM
7070 unsigned short* g_graphic_area;
7171
72+// General purpose integer used for asigning value with pointer
73+int g_temp;
--- mips/branches/zoea/linker.c (revision 153)
+++ mips/branches/zoea/linker.c (revision 154)
@@ -122,7 +122,7 @@
122122 }
123123 }
124124
125-void* search_breakout(unsigned int start){
125+void* search_breakout(unsigned int start, int* prevcode){
126126 unsigned int pos,code1,depth;
127127 // Start search from start point where BREAK statement is used.
128128 depth=0;
@@ -147,6 +147,8 @@
147147 break;
148148 }
149149 // Destination found.
150+ // Previous code will be also set if required for CONTINUE statement.
151+ if (prevcode) prevcode[0]=g_object[pos-1];
150152 return (void*)&g_object[pos];
151153 default:
152154 break;
@@ -194,6 +196,7 @@
194196 0x0814xxxx, 0x0815xxxx: SOUND etc, for setting v0 as pointer to DATA array.
195197 0x0816xxxx: BREAK statemant and relatives
196198 0x08160000: BREAK
199+ 0x08160008: CONTINUE
197200 0x08160100: Jump to next ELSE, ELSEIF or ENDIF
198201 0x082xyyyy: Begin block (FOR/DO/WHILE)
199202 0x083xyyyy: End block (NEXT/LOOP/WEND)
@@ -202,6 +205,7 @@
202205 MLB 2 bits show skip byte length in DATA.
203206 0x30000000: Begin block (IF-THEN-ELSEIF-ELSE-ENDIF)
204207 0x30008000: End block (IF-THEN-ELSEIF-ELSE-ENDIF)
208+ 0x3000Fxxx: General purpose NOP with value 0x0000-0x0FFF.
205209
206210 IF-THEN-ELSEIF-ELSE-ENDIF is written as follows:
207211 IF-THEN: 0x30000000 0x10400000 0x30000000
@@ -280,7 +284,7 @@
280284 // BREAK statement
281285 // Find next the NEXT or WHILE statement and insert jump code after this.
282286 g_label=g_line;
283- code1=(int)search_breakout(pos);
287+ code1=(int)search_breakout(pos,0);
284288 if (!code1) return ERR_INVALID_BREAK;
285289 code1&=0x0FFFFFFF;
286290 code1>>=2;
@@ -287,6 +291,24 @@
287291 code1|=0x08000000; // j xxxx
288292 g_object[pos]=code1;
289293 break;
294+ case 0x0008:
295+ // CONTINUE statement
296+ // Find next the NEXT or WHILE statement and insert jump code after this.
297+ g_label=g_line;
298+ code1=(int)search_breakout(pos,&g_temp);
299+ if (!code1) return ERR_INVALID_BREAK;
300+ if (0x3000F000 == (g_temp&0xFFFFF000)) {
301+ // WEND or LOOP statement found
302+ code1-=(g_temp&0x0FFF)<<2;
303+ } else {
304+ // NEXT statement found
305+ code1-=3<<2;
306+ }
307+ code1&=0x0FFFFFFF;
308+ code1>>=2;
309+ code1|=0x08000000; // j xxxx
310+ g_object[pos]=code1;
311+ break;
290312 case 0x0100:
291313 // Jump to next ENDIF
292314 g_label=g_line;
--- mips/branches/zoea/statement.c (revision 153)
+++ mips/branches/zoea/statement.c (revision 154)
@@ -717,6 +717,13 @@
717717 return 0;
718718 }
719719
720+char* continue_statement(){
721+ check_obj_space(2);
722+ g_object[g_objpos++]=0x08160008; // j xxxx (See link() function)
723+ g_object[g_objpos++]=0x00000000; // nop
724+ return 0;
725+}
726+
720727 char* for_statement(){
721728 char* err;
722729 char b1;
@@ -776,7 +783,9 @@
776783
777784 char* next_statement(){
778785 // Return to address stored in 4($sp)
779- // while set $v0 to 8($sp) (see for_statement)
786+ // while set $v0 to 8($sp) (see for_statement)
787+ // Following assembly must be 4 words.
788+ // If the number of words will be changed, link.c must be reviced for CONTINUE statement.
780789 check_obj_space(4);
781790 g_object[g_objpos++]=0x8FBF0004; // lw ra,4(sp)
782791 g_object[g_objpos++]=0x03E00008; // jr ra
@@ -821,6 +830,8 @@
821830
822831 char* loop_statement(){
823832 char* err;
833+ int opos;
834+ opos=g_objpos;
824835 if (nextCodeIs("WHILE ")) {
825836 // LOOP WHILE
826837 err=get_floatOrValue();
@@ -837,11 +848,12 @@
837848 // LOOP statement without WHILE/UNTIL
838849 }
839850 check_obj_space(4);
840- g_object[g_objpos++]=0x8FBF0004; // lw ra,4(sp)
841- g_object[g_objpos++]=0x03E00008; // jr ra
842- g_object[g_objpos++]=0x00000000; // nop
843- // label1:
844- g_object[g_objpos++]=0x08320004; // addiu sp,sp,4 (See link() function)
851+ g_object[g_objpos++]=0x8FBF0004; // lw ra,4(sp)
852+ g_object[g_objpos++]=0x03E00008; // jr ra
853+ opos=g_objpos+1-opos;
854+ g_object[g_objpos++]=0x3000F000|opos; // nop (See linker, used for CONTINUE statement)
855+ // label1:
856+ g_object[g_objpos++]=0x08320004; // addiu sp,sp,4 (See link() function)
845857 return 0;
846858 }
847859
@@ -865,9 +877,9 @@
865877 check_obj_space(4);
866878 g_object[g_objpos++]=0x8FBF0004; // lw ra,4(sp)
867879 g_object[g_objpos++]=0x03E00008; // jr ra
868- g_object[g_objpos++]=0x00000000; // nop
880+ g_object[g_objpos++]=0x3000F003; // nop (See linker, used for CONTINUE statement)
869881 // label1:
870- g_object[g_objpos++]=0x08310004; // addiu sp,sp,4 (See link() function)
882+ g_object[g_objpos++]=0x08310004; // addiu sp,sp,4 (See link() function)
871883 return 0;
872884 }
873885
@@ -1357,6 +1369,8 @@
13571369 err=wend_statement();
13581370 } else if (nextCodeIs("BREAK")) {
13591371 err=break_statement();
1372+ } else if (nextCodeIs("CONTINUE")) {
1373+ err=continue_statement();
13601374 } else if (nextCodeIs("SYSTEM")) {
13611375 err=system_statement();
13621376 #ifdef __DEBUG