Skip to content

Commit

Permalink
fix: indirect subscript
Browse files Browse the repository at this point in the history
  • Loading branch information
ajlekcahdp4 committed Dec 15, 2024
1 parent a60d862 commit 4196ae7
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/llvm_codegen/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class codegen_visitor final
);
builder.CreateMemSet(
arr, Constant::getIntegerValue(Type::getInt8Ty(get_ctx()), APInt(8, 0)),
array_type.size, MaybeAlign()
array_type.size * 4, MaybeAlign()
);
return arr;
} else
Expand Down
1 change: 1 addition & 0 deletions src/pclc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ int main(int argc, char *argv[]) try {
});

exec->finalizeObject();
exec->setVerifyModules(true);
exec->runFunction(module_ref.getFunction("main"), {});

auto &Err = exec->getErrorMessage();
Expand Down
1 change: 1 addition & 0 deletions test/array/subscript-var.ans
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
6 changes: 6 additions & 0 deletions test/array/subscript-var.pcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
int[5] arr = 0;
arr[1] = 1;
b = (arr[1] + arr[1]) / 2;
print arr[b];
}
3 changes: 3 additions & 0 deletions test/array/subscript.ans
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
0
2
0
7 changes: 7 additions & 0 deletions test/array/subscript.pcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
int[2] arr = 0;
print arr[1];
arr[1] = 2;
print arr[1];
print arr[0];
}

0 comments on commit 4196ae7

Please sign in to comment.