|  |  |  | @ -263,18 +263,6 @@ public class CodeGenImpl extends CodeGenBase | 
			
		
	
		
			
				
					|  |  |  |  |             { | 
			
		
	
		
			
				
					|  |  |  |  |                 //object create
 | 
			
		
	
		
			
				
					|  |  |  |  |                 ClassInfo cls = (ClassInfo) ty; | 
			
		
	
		
			
				
					|  |  |  |  |                 /** | 
			
		
	
		
			
				
					|  |  |  |  |                     la a0, $DoublingVector$prototype         # Load pointer to prototype of: DoublingVector | 
			
		
	
		
			
				
					|  |  |  |  |                     jal alloc                                # Allocate new object in A0 | 
			
		
	
		
			
				
					|  |  |  |  |                     sw a0, -12(fp)                           # Push on stack slot 3 | 
			
		
	
		
			
				
					|  |  |  |  |                     sw a0, -16(fp)                           # Push argument 0 from last. | 
			
		
	
		
			
				
					|  |  |  |  |                     addi sp, fp, -16                         # Set SP to last argument. | 
			
		
	
		
			
				
					|  |  |  |  |                     lw a1, 8(a0)                             # Load address of object's dispatch table | 
			
		
	
		
			
				
					|  |  |  |  |                     lw a1, 0(a1)                             # Load address of method: DoublingVector.__init__ | 
			
		
	
		
			
				
					|  |  |  |  |                     jalr a1                                  # Invoke method: DoublingVector.__init__ | 
			
		
	
		
			
				
					|  |  |  |  |                     addi sp, fp, -@..main.size               # Set SP to stack frame top. | 
			
		
	
		
			
				
					|  |  |  |  |                     lw a0, -12(fp)                           # Pop stack slot 3 | 
			
		
	
		
			
				
					|  |  |  |  |                  */ | 
			
		
	
		
			
				
					|  |  |  |  |                 backend.emitLA(A0, cls.getPrototypeLabel(), String.format("Load pointer to prototype of: %s", cls.getClassName())); | 
			
		
	
		
			
				
					|  |  |  |  |                 backend.emitJAL(objectAllocLabel, "Allocate new object in A0"); | 
			
		
	
		
			
				
					|  |  |  |  |                 backend.emitSW(A0, FP, -sp_off*wordSize, String.format("Push on stack slot %d", sp_off)); | 
			
		
	
	
		
			
				
					|  |  |  | @ -319,7 +307,6 @@ public class CodeGenImpl extends CodeGenBase | 
			
		
	
		
			
				
					|  |  |  |  |                 { | 
			
		
	
		
			
				
					|  |  |  |  | 	        		backend.emitSW(FP, FP, -(sp_off+1) * wordSize, "Push static link onto active frame."); | 
			
		
	
		
			
				
					|  |  |  |  | 	    		} | 
			
		
	
		
			
				
					|  |  |  |  |                 int origsp = sp_off; | 
			
		
	
		
			
				
					|  |  |  |  |                 incSp(1); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |      			List<Expr> args = node.args; | 
			
		
	
	
		
			
				
					|  |  |  | @ -327,8 +314,6 @@ public class CodeGenImpl extends CodeGenBase | 
			
		
	
		
			
				
					|  |  |  |  |                 for (int i = 0; i < args.size(); i++)  | 
			
		
	
		
			
				
					|  |  |  |  |                 { | 
			
		
	
		
			
				
					|  |  |  |  |                 		incSp(1); | 
			
		
	
		
			
				
					|  |  |  |  | 	        		int argNum = i + 1; | 
			
		
	
		
			
				
					|  |  |  |  | 	        		int slotNum = argNum + 1; // We have extra slot for static link
 | 
			
		
	
		
			
				
					|  |  |  |  | 	        			Expr expr = args.get(i); | 
			
		
	
		
			
				
					|  |  |  |  | 	        			expr.dispatch(this); | 
			
		
	
		
			
				
					|  |  |  |  | 	        		 | 
			
		
	
	
		
			
				
					|  |  |  | @ -374,6 +359,7 @@ public class CodeGenImpl extends CodeGenBase | 
			
		
	
		
			
				
					|  |  |  |  | 	        		backend.emitADDI(SP, FP, "-"+size_label, "Set SP to stack frame top."); | 
			
		
	
		
			
				
					|  |  |  |  |                 sp_off-=spaceRequiredForArgs/wordSize; | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |              | 
			
		
	
		
			
				
					|  |  |  |  |             return A0; | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |          | 
			
		
	
	
		
			
				
					|  |  |  | @ -404,7 +390,7 @@ public class CodeGenImpl extends CodeGenBase | 
			
		
	
		
			
				
					|  |  |  |  |                 String.format("Load address of method: %s.%s", objectClass.getClassName(), node.method.member.name)); | 
			
		
	
		
			
				
					|  |  |  |  |             backend.emitADDI(SP, FP, -sp_off * wordSize, "Set SP to last argument."); | 
			
		
	
		
			
				
					|  |  |  |  |             backend.emitJALR(A1, String.format("Invoke method: %s.%s", objectClass.getClassName(), node.method.member.name)); | 
			
		
	
		
			
				
					|  |  |  |  |             backend.emitInsn(String.format("addi sp, fp, -%s", size_label), "Set SP to stack frame top."); | 
			
		
	
		
			
				
					|  |  |  |  |             backend.emitADDI(SP, FP, "-" + size_label, "Set SP to stack frame top"); | 
			
		
	
		
			
				
					|  |  |  |  |             sp_off -= n_args+1; | 
			
		
	
		
			
				
					|  |  |  |  |      | 
			
		
	
		
			
				
					|  |  |  |  |             return A0; | 
			
		
	
	
		
			
				
					|  |  |  | @ -415,11 +401,13 @@ public class CodeGenImpl extends CodeGenBase | 
			
		
	
		
			
				
					|  |  |  |  |         public Register analyze(ReturnStmt stmt)  | 
			
		
	
		
			
				
					|  |  |  |  |         { | 
			
		
	
		
			
				
					|  |  |  |  |         		Expr expr = stmt.value; | 
			
		
	
		
			
				
					|  |  |  |  |             if(expr == null)  | 
			
		
	
		
			
				
					|  |  |  |  |             if (expr == null) { | 
			
		
	
		
			
				
					|  |  |  |  |                 backend.emitMV(A0, ZERO, "Return None"); | 
			
		
	
		
			
				
					|  |  |  |  |     	    else  | 
			
		
	
		
			
				
					|  |  |  |  |             } else { | 
			
		
	
		
			
				
					|  |  |  |  |                 // All expressions should save their end result in A0
 | 
			
		
	
		
			
				
					|  |  |  |  |            	    expr.dispatch(this); | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |              | 
			
		
	
		
			
				
					|  |  |  |  |         		backend.emitJ(this.epilogue, "Jump to function epilogue"); | 
			
		
	
		
			
				
					|  |  |  |  |             return A0; | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
	
		
			
				
					|  |  |  | @ -906,28 +894,37 @@ public class CodeGenImpl extends CodeGenBase | 
			
		
	
		
			
				
					|  |  |  |  |                 Label startLoop = generateLocalLabel(); | 
			
		
	
		
			
				
					|  |  |  |  |                 Label endLoop = generateLocalLabel(); | 
			
		
	
		
			
				
					|  |  |  |  |                 Label temp = generateLocalLabel(); | 
			
		
	
		
			
				
					|  |  |  |  |                  | 
			
		
	
		
			
				
					|  |  |  |  |                 r=getRegister(); | 
			
		
	
		
			
				
					|  |  |  |  |                 regs.add(r); | 
			
		
	
		
			
				
					|  |  |  |  |                 Register iden = registerPool[r]; | 
			
		
	
		
			
				
					|  |  |  |  |                  | 
			
		
	
		
			
				
					|  |  |  |  |                 node.iterable.dispatch(this); | 
			
		
	
		
			
				
					|  |  |  |  |                  | 
			
		
	
		
			
				
					|  |  |  |  |                 r=getRegister(); | 
			
		
	
		
			
				
					|  |  |  |  |                 regs.add(r); | 
			
		
	
		
			
				
					|  |  |  |  |                 Register l = registerPool[r]; | 
			
		
	
		
			
				
					|  |  |  |  |                  | 
			
		
	
		
			
				
					|  |  |  |  |                 r=getRegister(); | 
			
		
	
		
			
				
					|  |  |  |  |                 regs.add(r); | 
			
		
	
		
			
				
					|  |  |  |  |                 Register ln = registerPool[r]; | 
			
		
	
		
			
				
					|  |  |  |  |                  | 
			
		
	
		
			
				
					|  |  |  |  |                 backend.emitBNEZ(Register.A0, temp, "Ensure not none"); | 
			
		
	
		
			
				
					|  |  |  |  |                 backend.emitJ(errorNone, "Empty List"); | 
			
		
	
		
			
				
					|  |  |  |  |                 backend.emitLocalLabel(temp, "Continue execution for for-loop"); | 
			
		
	
		
			
				
					|  |  |  |  |                 backend.emitMV(l,Register.A0,"Location of list"); | 
			
		
	
		
			
				
					|  |  |  |  |                  | 
			
		
	
		
			
				
					|  |  |  |  |                 r=getRegister(); | 
			
		
	
		
			
				
					|  |  |  |  |                 regs.add(r); | 
			
		
	
		
			
				
					|  |  |  |  |                 Register iter = registerPool[r]; | 
			
		
	
		
			
				
					|  |  |  |  |                  | 
			
		
	
		
			
				
					|  |  |  |  |                 backend.emitSW(l, Register.FP, -sp_off*wordSize, "Store location on stack"); | 
			
		
	
		
			
				
					|  |  |  |  |                 incSp(1); | 
			
		
	
		
			
				
					|  |  |  |  |                  | 
			
		
	
		
			
				
					|  |  |  |  |                 backend.emitMV(iter, Register.ZERO, "Initialize index variable"); | 
			
		
	
		
			
				
					|  |  |  |  |                 backend.emitSW(iter, Register.FP, -sp_off*wordSize, "Store index on stack"); | 
			
		
	
		
			
				
					|  |  |  |  |                 incSp(1); | 
			
		
	
		
			
				
					|  |  |  |  |                  | 
			
		
	
		
			
				
					|  |  |  |  |                 backend.emitLocalLabel(startLoop, "Start for loop"); | 
			
		
	
		
			
				
					|  |  |  |  |                 backend.emitLW(iter, Register.FP, -(sp_off-1)*wordSize, "Load index from stack"); | 
			
		
	
		
			
				
					|  |  |  |  |                 backend.emitLW(l, Register.FP, -(sp_off-2)*wordSize, "Store list location from stack"); | 
			
		
	
	
		
			
				
					|  |  |  | @ -1018,10 +1015,10 @@ public class CodeGenImpl extends CodeGenBase | 
			
		
	
		
			
				
					|  |  |  |  |             { | 
			
		
	
		
			
				
					|  |  |  |  |                 backend.emitJAL(errorNI, "Operator not implemented"); | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |             for(int n:regs) | 
			
		
	
		
			
				
					|  |  |  |  |             for(int n:regs) { | 
			
		
	
		
			
				
					|  |  |  |  |                 freeRegister(n); | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |             return null; | 
			
		
	
		
			
				
					|  |  |  |  |              | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |           | 
			
		
	
		
			
				
					|  |  |  |  |         @Override | 
			
		
	
	
		
			
				
					|  |  |  | 
 |