
use mem

value STACK_ITEMS_MAX (40_000)

global stack_root : [ptr x STACK_ITEMS_MAX]
global stack_top : ptr (@undefined)
global stack_backup : [ptr x STACK_ITEMS_MAX]
global stack_backup_size : uint

fn backup_gc_stack() {
    let size : uint = stack_top - (&stack_root).@cast(ptr)
    mem:copy(stack_root, stack_backup, size)
    stack_backup_size = size
    stack_top = stack_root
}

fn restore_gc_stack() {
    let size = stack_backup_size
    mem:copy(stack_backup, stack_root, size)
    stack_top = (&stack_root).@cast(ptr) + size
    stack_backup_size = 0
}
