aboutsummaryrefslogtreecommitdiff
path: root/test/cases/new_stack_call.zig
blob: 5912550d545aa6b8369afcabf8995574d8541616 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const std = @import("std");
const assert = std.debug.assert;

var new_stack_bytes: [1024]u8 = undefined;

test "calling a function with a new stack" {
    const arg = 1234;

    const a = @newStackCall(new_stack_bytes[0..512], targetFunction, arg);
    const b = @newStackCall(new_stack_bytes[512..], targetFunction, arg);
    _ = targetFunction(arg);

    assert(arg == 1234);
    assert(a < b);
}

fn targetFunction(x: i32) usize {
    assert(x == 1234);

    var local_variable: i32 = 42;
    const ptr = &local_variable;
    ptr.* += 1;

    assert(local_variable == 43);
    return @ptrToInt(ptr);
}