def destroy_frame(self, out, func, frame): registers, reg_start, args_start, ret_start, allargs = frame destns = self.func.namespace stack_move = out.namespace == destns or destns is None # Restore registers if registers: for i, reg in enumerate(registers): src = LocalStackVariable(reg.type, destns, reg_start + i) if stack_move: # shouldn't need to realign because they're registers, # but just to be safe reg.realign_frame(1) src.clone_to(reg, out) if stack_move: reg.realign_frame(-1) # Mutate pass-by-reference arguments if self.fnargs: for i, (ptype, ppass) in enumerate(self.func.params): if ppass == 'byref': src = LocalStackVariable(ptype, destns, args_start + i) arg = self.fnargs[i] assert isinstance(arg, Variable), "%s passed by value!" % arg # The mutated arguments are on frame 0 # We want to copy them to where they were from (now frame 1) if stack_move: arg.realign_frame(1) src.clone_to(arg, out) if stack_move: arg.realign_frame(-1) # Copy return values into return variables if self.retvars: for i, var in enumerate(self.retvars): if var is None: continue src = LocalStackVariable(var.type, destns, ret_start + i) if stack_move: var.realign_frame(1) src.clone_to(var, out) if stack_move: var.realign_frame(-1) # Pop invocation frame if allargs: out.write( c.DataRemove(c.GlobalNBT(destns), c.StackPath(STACK_HEAD)))
def push_to_stack(self, out): # out-of-bounds stack path out.write(c.DataModifyFrom(c.GlobalNBT(self.namespace), c.StackPath(None), 'append', self.storage, self.root_path))
def storage(self): return c.GlobalNBT(self.namespace)
def get_cmd(self, func): storage = c.GlobalNBT(func.namespace) return c.DataRemove(storage, c.StackPath(STACK_HEAD))
def apply(self, out, func): storage = c.GlobalNBT(func.namespace) out.write(_zt.cmd_set_from(c.StackFrameHead(-1), storage))
def apply(self, out, func): out.write( _zt.cmd_set_from(c.StackPath(STACK_HEAD, None), c.GlobalNBT(func.namespace))) out.write(_zt.clear_last_exec())
def get_cmd(self, func): storage = c.GlobalNBT(func.namespace) return _ut.cmd_set_from(c.StackPath(STACK_HEAD, None), storage)