Skip to content

Commit

Permalink
[Bugfix] Subscript Op ptr increment properly
Browse files Browse the repository at this point in the history
  • Loading branch information
rdtscp committed Aug 17, 2020
1 parent d989c69 commit 792722f
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/targets/GenerateX64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -655,8 +655,7 @@ atl::shared_ptr<X64::Operand> GenerateX64::visit(MemberAccess &ma) {
}
const unsigned int objByteOffset = memberDecl->bpOffset;
// Handle Pointer Access
if (ma.accessType == SourceToken::Class::PTRDOT ||
ma.object->exprType->astClass() == "ReferenceType") {
if (ma.accessType == SourceToken::Class::PTRDOT) {
x64.mov(x64.rax, objAddr, "Move objects address into rax");
return addrOffset(x64.rax, objByteOffset);
} else {
Expand Down Expand Up @@ -843,16 +842,17 @@ atl::shared_ptr<X64::Operand> GenerateX64::visit(SubscriptOp &so) {
// Get a pointer to the variable.
const atl::shared_ptr<X64::Operand> this_ptr = so.variable->accept(*this);
x64.mov(x64.rax, this_ptr, "Pointer to subscript variable.");
x64.push(x64.rax);
x64.push(x64.rax, "Save ptr to subscript var to stack.");

// Get the index to offset.
const atl::shared_ptr<X64::Operand> index = so.index->accept(*this);
x64.pop(x64.rcx);
x64.add(x64.rcx, index);
x64.mov(x64.rax, x64.rcx);
const atl::shared_ptr<X64::AddrOffset> valueAtIndex(
new X64::AddrOffset(x64.rax, 0));
return valueAtIndex;
const atl::shared_ptr<X64::Register> indexReg =
copyToRegister(index, so.index->exprType->getBytes());
x64.pop(x64.rcx, "Restore ptr to subscript var from stack.");
x64.add(x64.rcx, indexReg, "Increment the ptr by appropriate amount.");
x64.mov(x64.rax, x64.rcx, "Move the new address into RAX");

return addrOffset(x64.rax, 0);
}

return atl::shared_ptr<X64::None>();
Expand Down

0 comments on commit 792722f

Please sign in to comment.