|
|
|
@ -792,30 +792,8 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
|
@Override
|
|
|
|
|
public Register analyze(IndexExpr node)
|
|
|
|
|
{
|
|
|
|
|
incSp(1);
|
|
|
|
|
Register listObj = node.list.dispatch(this);
|
|
|
|
|
backend.emitSW(listObj, FP, -sp_off * wordSize, String.format("Push on stack slot %d", sp_off));
|
|
|
|
|
Register index = node.index.dispatch(this);
|
|
|
|
|
Register vacantReg = (index != A0) ? A0 : A1;
|
|
|
|
|
|
|
|
|
|
if (node.list.getInferredType().isListType()) {
|
|
|
|
|
backend.emitLW(vacantReg, FP, -sp_off * wordSize, String.format("Pop stack slot %d", sp_off));
|
|
|
|
|
|
|
|
|
|
this.d(vacantReg);
|
|
|
|
|
return this.a(vacantReg, index, A0, false);
|
|
|
|
|
}else{
|
|
|
|
|
this.a(0, vacantReg);
|
|
|
|
|
Register a = a(index);
|
|
|
|
|
Label ch = generateLocalLabel();
|
|
|
|
|
backend.emitLW(a, vacantReg, getAttrOffset(strClass, "__len__"), "Load attribute: __len__");
|
|
|
|
|
backend.emitBLTU(index, a, ch, "Ensure 0 <= idx < len");
|
|
|
|
|
backend.emitJ(f, "Go to error handler");
|
|
|
|
|
backend.emitLocalLabel(ch, "Index within bounds");
|
|
|
|
|
this.c(index);
|
|
|
|
|
Register a2 = this.a(false);
|
|
|
|
|
this.a(1);
|
|
|
|
|
return a2;
|
|
|
|
|
}
|
|
|
|
|
//TODO: Not Implemented
|
|
|
|
|
return A0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Register analyze(MemberExpr node)
|
|
|
|
|