Skip to content

Commit 50776eb

Browse files
authored
Merge pull request #52 from ForAeons/vm-fix-call
bug: call micro_code pop order
2 parents 9a87865 + 2155262 commit 50776eb

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

.github/workflows/test.yml

+8
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,11 @@ jobs:
2222
- run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }}
2323
- run: cargo build --verbose
2424
- run: cargo test --verbose
25+
26+
build_script:
27+
name: Rust project - build script
28+
runs-on: ubuntu-latest
29+
steps:
30+
- uses: actions/checkout@v3
31+
- run: chmod +x build.sh
32+
- run: ./build.sh

vm/ignite/src/micro_code/call.rs

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ use super::apply_builtin;
99

1010
/// Call a function with the given number of arguments.
1111
/// First it pops n values from the operand stack where n is the arity of the function.
12+
/// The values will be the arguments to the function and they are pushed to a vector and reversed.
13+
/// i.e. the last argument is the top value of the operand stack.
1214
/// Then it pops the closure from the operand stack.
1315
/// It checks that the closure is a closure and that the arity of the closure matches the number of arguments.
1416
/// If the closure is a builtin function it applies the builtin function and returns.
@@ -28,6 +30,7 @@ use super::apply_builtin;
2830
/// If the closure is not of type closure or the arity of the closure does not match the number of arguments.
2931
pub fn call(mut rt: Runtime, arity: usize) -> Result<Runtime> {
3032
let mut args = Vec::new();
33+
args.reserve_exact(arity);
3134

3235
for _ in 0..arity {
3336
args.push(
@@ -38,6 +41,8 @@ pub fn call(mut rt: Runtime, arity: usize) -> Result<Runtime> {
3841
);
3942
}
4043

44+
args.reverse();
45+
4146
let value = rt
4247
.current_thread
4348
.operand_stack

0 commit comments

Comments
 (0)