@@ -72,8 +72,8 @@ public int getMainPc() {
7272 }
7373
7474 /**
75- * U <code>rs.etf.pp1.mj.runtime.Code.buf</code> dodaje mašinski kod za MikroJava virtuelnu mašinu
76- * koji bi se dobio prevođenjem sledeće MikroJava funkcije :
75+ * Appends the MicroJava Virtual Machine bytecode equivalent of the following function to the
76+ * <code>rs.etf.pp1.mj.runtime.Code.buf</code> buffer :
7777 *
7878 * <pre>
7979 * <b>void</b> printBool (bool b, int width1) int width2; int blank; {
@@ -104,8 +104,6 @@ public static void generatePrintBoolMethod() {
104104 Code .put (2 );
105105 Code .put (4 );
106106
107- // if (b) {
108- // width2 = 4;
109107 Code .put (Code .load_n );
110108 Code .put (Code .const_n + 1 );
111109 Code .put (Code .jcc + Code .ne );
@@ -114,52 +112,47 @@ public static void generatePrintBoolMethod() {
114112 Code .put (Code .store_2 );
115113 Code .put (Code .jmp );
116114 Code .put2 (5 );
117- // } else { // b == false;
118- // width2 = 5;
119- // }
115+
120116 Code .put (Code .const_5 );
121117 Code .put (Code .store_2 );
122- // blank = width1 - width2;
118+
123119 Code .put (Code .load_1 );
124120 Code .put (Code .load_2 );
125121 Code .put (Code .sub );
126122 Code .put (Code .store_3 );
127- // if (blank > 0) {
123+
128124 Code .put (Code .load_3 );
129125 Code .put (Code .const_n );
130126 Code .put (Code .jcc + Code .le );
131127 Code .put2 (21 );
132- // do {
133- // print(' ');
128+
134129 Code .put (Code .const_ );
135130 Code .put4 (32 );
136131 Code .put (Code .const_1 );
137132 Code .put (Code .bprint );
138- // blank--;
133+
139134 Code .put (Code .inc );
140135 Code .put (3 );
141136 Code .put (-1 );
142- // } while (blank > 0);
137+
143138 Code .put (Code .load_3 );
144139 Code .put (Code .const_n );
145140 Code .put (Code .jcc + Code .le );
146141 Code .put2 (6 );
147142 Code .put (Code .jmp );
148143 Code .put2 (-15 );
149- // if (b) {
144+
150145 Code .put (Code .load_n );
151146 Code .put (Code .const_n + 1 );
152147 Code .put (Code .jcc + Code .ne );
153148 Code .put2 (34 );
154- // print('t'); print('r'); print('u'); print('e');
149+
155150 for (var i = 0 ; i < MJTab .TRUE .length (); i ++) {
156151 Code .load (new Obj (Obj .Con , "charValue" , Tab .charType , MJTab .TRUE .charAt (i ), 0 ));
157152 Code .load (new Obj (Obj .Con , "width" , Tab .intType , 1 , 0 ));
158153 Code .put (Code .bprint );
159154 }
160- // } else { // b == false
161- // print('f'); print('a'); print('l'); print('s'); print('e');
162- // }
155+
163156 Code .put (Code .jmp );
164157 Code .put2 (38 );
165158 for (var i = 0 ; i < MJTab .FALSE .length (); i ++) {
@@ -172,8 +165,8 @@ public static void generatePrintBoolMethod() {
172165 }
173166
174167 /**
175- * U <code>rs.etf.pp1.mj.runtime.Code.buf</code> dodaje mašinski kod za MikroJava virtuelnu mašinu
176- * koji bi se dobio prevođenjem sledeće MikroJava funkcije :
168+ * Appends the MicroJava Virtual Machine bytecode equivalent of the following function to the
169+ * <code>rs.etf.pp1.mj.runtime.Code.buf</code> buffer :
177170 *
178171 * <pre>
179172 * bool readBool() char inp[]; int i; char skip; bool result; {
@@ -311,8 +304,8 @@ public static void generateReadBoolMethod() {
311304 }
312305
313306 /**
314- * U <code>rs.etf.pp1.mj.runtime.Code.buf</code> dodaje mašinski kod za MikroJava virtuelnu mašinu
315- * koji bi se dobio prevođenjem sledeće MikroJava funkcije :
307+ * Appends the MicroJava Virtual Machine bytecode equivalent of the following function to the
308+ * <code>rs.etf.pp1.mj.runtime.Code.buf</code> buffer :
316309 *
317310 * <pre>
318311 * int vecTimesVec(int a[], int b[]) int la; int i; int result; {
@@ -339,8 +332,7 @@ public static void generateVecTimesVecMethod() {
339332 Code .put (Code .enter );
340333 Code .put (2 );
341334 Code .put (5 );
342- // if (a != null && b != null) {
343- // la = len(a);
335+
344336 Code .put (Code .load_n );
345337 Code .put (Code .const_n );
346338 Code .put (Code .jcc + Code .eq );
@@ -352,8 +344,7 @@ public static void generateVecTimesVecMethod() {
352344 Code .put (Code .load_n );
353345 Code .put (Code .arraylength );
354346 Code .put (Code .store_2 );
355- // if (la == len(b)) {
356- // result = 0;
347+
357348 Code .put (Code .load_2 );
358349 Code .put (Code .load_1 );
359350 Code .put (Code .arraylength );
@@ -362,19 +353,14 @@ public static void generateVecTimesVecMethod() {
362353 Code .put (Code .const_n );
363354 Code .put (Code .store );
364355 Code .put (4 );
365- // if (la > 0) {
366- // i = 0;
356+
367357 Code .put (Code .load_2 );
368358 Code .put (Code .const_n );
369359 Code .put (Code .jcc + Code .le );
370360 Code .put2 (28 );
371361 Code .put (Code .const_n );
372362 Code .put (Code .store_3 );
373- // do {
374- // result = result + a[i] * b[i];
375- // i++;
376- // } while (i < la);
377- // }
363+
378364 Code .put (Code .load );
379365 Code .put (4 );
380366 Code .put (Code .load_n );
@@ -396,9 +382,7 @@ public static void generateVecTimesVecMethod() {
396382 Code .put2 (6 );
397383 Code .put (Code .jmp );
398384 Code .put2 (-20 );
399- // return result;
400- // }
401- // }
385+
402386 Code .put (Code .load );
403387 Code .put (4 );
404388 Code .put (Code .exit );
@@ -408,8 +392,8 @@ public static void generateVecTimesVecMethod() {
408392 }
409393
410394 /**
411- * U <code>rs.etf.pp1.mj.runtime.Code.buf</code> dodaje mašinski kod za MikroJava virtuelnu mašinu
412- * koji bi se dobio prevođenjem sledeće MikroJava funkcije :
395+ * Appends the MicroJava Virtual Machine bytecode equivalent of the following function to the
396+ * <code>rs.etf.pp1.mj.runtime.Code.buf</code> buffer :
413397 *
414398 * <pre>
415399 * int[] vecTimesScalar(int a[], int s) int la; int i; int result[]; {
@@ -434,9 +418,7 @@ public static void generateVecTimesScalarMethod() {
434418 Code .put (Code .enter );
435419 Code .put (2 );
436420 Code .put (5 );
437- // if (a != null) {
438- // la = len(a);
439- // result = new int[la];
421+
440422 Code .put (Code .load_n );
441423 Code .put (Code .const_n );
442424 Code .put (Code .jcc + Code .eq );
@@ -449,8 +431,7 @@ public static void generateVecTimesScalarMethod() {
449431 Code .put (1 );
450432 Code .put (Code .store );
451433 Code .put (4 );
452- // if (la > 0) {
453- // i = 0;
434+
454435 Code .put (Code .load_2 );
455436 Code .put (Code .const_n );
456437 Code .put (Code .jcc + Code .le );
@@ -486,8 +467,8 @@ public static void generateVecTimesScalarMethod() {
486467 }
487468
488469 /**
489- * U <code>rs.etf.pp1.mj.runtime.Code.buf</code> dodaje mašinski kod za MikroJava virtuelnu mašinu
490- * koji bi se dobio prevođenjem sledeće MikroJava funkcije :
470+ * Appends the MicroJava Virtual Machine bytecode equivalent of the following function to the
471+ * <code>rs.etf.pp1.mj.runtime.Code.buf</code> buffer :
491472 *
492473 * <pre>
493474 * int[] scalarTimesVec(int s, int a[]) int la; int i; int result[]; {
@@ -512,9 +493,7 @@ public static void generateScalarTimesVectorMethod() {
512493 Code .put (Code .enter );
513494 Code .put (2 );
514495 Code .put (5 );
515- // if (a != null) {
516- // la = len(a);
517- // result = new int[la];
496+
518497 Code .put (Code .load_1 );
519498 Code .put (Code .const_n );
520499 Code .put (Code .jcc + Code .eq );
@@ -527,8 +506,7 @@ public static void generateScalarTimesVectorMethod() {
527506 Code .put (1 );
528507 Code .put (Code .store );
529508 Code .put (4 );
530- // if (la > 0) {
531- // i = 0;
509+
532510 Code .put (Code .load_2 );
533511 Code .put (Code .const_n );
534512 Code .put (Code .jcc + Code .le );
@@ -554,9 +532,7 @@ public static void generateScalarTimesVectorMethod() {
554532 Code .put2 (6 );
555533 Code .put (Code .jmp );
556534 Code .put2 (-17 );
557- // }
558- // return result[0];
559- // }
535+
560536 Code .put (Code .load );
561537 Code .put (4 );
562538 Code .put (Code .exit );
@@ -566,8 +542,8 @@ public static void generateScalarTimesVectorMethod() {
566542 }
567543
568544 /**
569- * U <code>rs.etf.pp1.mj.runtime.Code.buf</code> dodaje mašinski kod za MikroJava virtuelnu mašinu
570- * koji bi se dobio prevođenjem sledeće MikroJava funkcije :
545+ * Appends the MicroJava Virtual Machine bytecode equivalent of the following function to the
546+ * <code>rs.etf.pp1.mj.runtime.Code.buf</code> buffer :
571547 *
572548 * <pre>
573549 * int[] vecPlusVec(int a[], int b[]) int la; int i; int result[]; {
@@ -593,8 +569,7 @@ public static void generateVecPlusVecMethod() {
593569 Code .put (Code .enter );
594570 Code .put (2 );
595571 Code .put (5 );
596- // if (a != null && b != null) {
597- // la = len(a);
572+
598573 Code .put (Code .load_n );
599574 Code .put (Code .const_n );
600575 Code .put (Code .jcc + Code .eq );
@@ -606,8 +581,7 @@ public static void generateVecPlusVecMethod() {
606581 Code .put (Code .load_n );
607582 Code .put (Code .arraylength );
608583 Code .put (Code .store_2 );
609- // if (la == len(b)) {
610- // result = new int[la];
584+
611585 Code .put (Code .load_2 );
612586 Code .put (Code .load_1 );
613587 Code .put (Code .arraylength );
@@ -618,19 +592,14 @@ public static void generateVecPlusVecMethod() {
618592 Code .put (1 );
619593 Code .put (Code .store );
620594 Code .put (4 );
621- // if (la > 0) {
622- // i = 0;
595+
623596 Code .put (Code .load_2 );
624597 Code .put (Code .const_n );
625598 Code .put (Code .jcc + Code .le );
626599 Code .put2 (27 );
627600 Code .put (Code .const_n );
628601 Code .put (Code .store_3 );
629- // do {
630- // result[i] = a[i] + b[i];
631- // i++;
632- // } while (i < la);
633- // }
602+
634603 Code .put (Code .load );
635604 Code .put (4 );
636605 Code .put (Code .load_3 );
@@ -651,9 +620,7 @@ public static void generateVecPlusVecMethod() {
651620 Code .put2 (6 );
652621 Code .put (Code .jmp );
653622 Code .put2 (-19 );
654- // return result;
655- // }
656- // }
623+
657624 Code .put (Code .load );
658625 Code .put (4 );
659626 Code .put (Code .exit );
@@ -715,7 +682,7 @@ public void generateMethodInvocationCode(Obj overriddenMethod) {
715682 Code .put2 (0 );
716683 Code .fixup (jccAddress );
717684 }
718- // methodDesignator.traverseBottomUp(new ThisParameterLoader());
685+
719686 Code .put (Code .getfield );
720687 Code .put2 (0 );
721688
@@ -928,17 +895,11 @@ public void visit(IncrDesignatorStatement incrDesignatorStatement) {
928895 incrDesignatorStatement .getDesignator ().traverseBottomUp (this );
929896 } else if (incrDesignatorStatement .getDesignator () instanceof MemberAccessDesignator ) {
930897 Code .put (Code .dup );
931- // Napravi repliku pokazivaca na tekuci objekat (sada se na vrhu steka izraza nalaze dva
932- // ovakva pokazivaca, P1 i P2)
933898 }
934899 Code .load (designatorObj );
935- // U slucaju da se inkrementira polje objekta, generise se instrukcija getfield koja "pojede"
936- // prvi pokazivac, P1
937900 Code .put (Code .const_1 );
938901 Code .put (Code .add );
939902 Code .store (designatorObj );
940- // U slucaju da se inkrementira polje objekta, generise se instrukcija putfield koja "pojede"
941- // drugi pokazivac, P2
942903 }
943904 }
944905
@@ -954,17 +915,11 @@ public void visit(DecrDesignatorStatement decrDesignatorStatement) {
954915 decrDesignatorStatement .getDesignator ().traverseBottomUp (this );
955916 } else if (decrDesignatorStatement .getDesignator () instanceof MemberAccessDesignator ) {
956917 Code .put (Code .dup );
957- // Napravi repliku pokazivaca na tekuci objekat (sada se na vrhu steka izraza nalaze dva
958- // ovakva pokazivaca, P1 i P2)
959918 }
960919 Code .load (designatorObj );
961- // U slucaju da se dekrementira polje objekta, generise se instrukcija getfield koja "pojede"
962- // prvi pokazivac, P1
963920 Code .put (Code .const_1 );
964921 Code .put (Code .sub );
965922 Code .store (designatorObj );
966- // U slucaju da se dekrementira polje objekta, generise se instrukcija putfield koja "pojede"
967- // drugi pokazivac, P2
968923 }
969924 }
970925
@@ -1133,8 +1088,8 @@ public void visit(IdentDesignator identDesignator) {
11331088 }
11341089
11351090 @ Override
1136- public void visit (ArrayElemAcessDesignatorLBracket arrAcessDesignatorLBracket ) {
1137- var parent = arrAcessDesignatorLBracket .getParent ();
1091+ public void visit (ArrayElemAccessDesignatorLBracket arrAccessDesignatorLBracket ) {
1092+ var parent = arrAccessDesignatorLBracket .getParent ();
11381093 Code .load (
11391094 (parent instanceof ArrayElemAccessDesignator )
11401095 ? ((ArrayElemAccessDesignator ) parent ).getDesignatorStart ().obj
0 commit comments