Update CodeGenImpl.java

master
sunyinqi0508 4 years ago committed by GitHub
parent 443b61a29f
commit 6890230252
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -792,30 +792,8 @@ public class CodeGenImpl extends CodeGenBase
@Override @Override
public Register analyze(IndexExpr node) public Register analyze(IndexExpr node)
{ {
incSp(1); //TODO: Not Implemented
Register listObj = node.list.dispatch(this); return A0;
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;
}
} }
public Register analyze(MemberExpr node) public Register analyze(MemberExpr node)

Loading…
Cancel
Save