So, basically the question can be simplified to this...
How do I make this work?
template pop*(): var Value =
SP -= 1
Stack[SP]
# some other template
let x {.inject.} = move stack.pop()
Run
It currently produces:
// let x {.inject.} = move stack.pop()
// SP -= 1
SP__vmZstack_u8 -= ((NI)1);
x = Stack__vmZstack_u7.p->data[SP__vmZstack_u8];
// SP -= 1 <----- This is duplicate!!
SP__vmZstack_u8 -= ((NI)1);
// obj = default(typeof(obj))
eqwasMoved___vmZvaluesZvalue_u2216(&Stack__vmZstack_u7.p->data[SP__vmZstack_u8]);
Run