-#define SAVEt_ITEM 0
-#define SAVEt_SV 1
-#define SAVEt_AV 2
-#define SAVEt_HV 3
-#define SAVEt_INT 4
-#define SAVEt_LONG 5
-#define SAVEt_I32 6
-#define SAVEt_IV 7
-#define SAVEt_SPTR 8
-#define SAVEt_APTR 9
-#define SAVEt_HPTR 10
-#define SAVEt_PPTR 11
-#define SAVEt_NSTAB 12
-#define SAVEt_SVREF 13
-#define SAVEt_GP 14
-#define SAVEt_FREESV 15
-#define SAVEt_FREEOP 16
-#define SAVEt_FREEPV 17
-#define SAVEt_CLEARSV 18
-#define SAVEt_DELETE 19
-#define SAVEt_DESTRUCTOR 20
-#define SAVEt_REGCONTEXT 21
-#define SAVEt_STACK_POS 22
-#define SAVEt_I16 23
-#define SAVEt_OP 24
-
-#define SSCHECK(need) if (savestack_ix + need > savestack_max) savestack_grow()
-#define SSPUSHINT(i) (savestack[savestack_ix++].any_i32 = (I32)(i))
-#define SSPUSHLONG(i) (savestack[savestack_ix++].any_long = (long)(i))
-#define SSPUSHIV(i) (savestack[savestack_ix++].any_iv = (IV)(i))
-#define SSPUSHPTR(p) (savestack[savestack_ix++].any_ptr = (void*)(p))
-#define SSPUSHDPTR(p) (savestack[savestack_ix++].any_dptr = (p))
-#define SSPOPINT (savestack[--savestack_ix].any_i32)
-#define SSPOPLONG (savestack[--savestack_ix].any_long)
-#define SSPOPIV (savestack[--savestack_ix].any_iv)
-#define SSPOPPTR (savestack[--savestack_ix].any_ptr)
-#define SSPOPDPTR (savestack[--savestack_ix].any_dptr)
-
-#define SAVETMPS save_int((int*)&tmps_floor), tmps_floor = tmps_ix
-#define FREETMPS if (tmps_ix > tmps_floor) free_tmps()
+/* scope.h
+ *
+ * Copyright (C) 1993, 1994, 1996, 1997, 1998, 1999, 2000, 2001,
+ * 2002, 2004, 2005, 2006, 2007, 2008 by Larry Wall and others
+ *
+ * You may distribute under the terms of either the GNU General Public
+ * License or the Artistic License, as specified in the README file.
+ *
+ */
+
+#include "scope_types.h"
+
+#define SAVEf_SETMAGIC 1
+#define SAVEf_KEEPOLDELEM 2
+
+#define SAVE_TIGHT_SHIFT 6
+#define SAVE_MASK 0x3F
+
+#define save_aelem(av,idx,sptr) save_aelem_flags(av,idx,sptr,SAVEf_SETMAGIC)
+#define save_helem(hv,key,sptr) save_helem_flags(hv,key,sptr,SAVEf_SETMAGIC)
+
+#ifndef SCOPE_SAVES_SIGNAL_MASK
+#define SCOPE_SAVES_SIGNAL_MASK 0
+#endif
+
+/* the maximum number of entries that might be pushed using the SS_ADD*
+ * macros */
+#define SS_MAXPUSH 4
+
+#define SSGROW(need) if (UNLIKELY(PL_savestack_ix + (I32)(need) > PL_savestack_max)) savestack_grow_cnt(need)
+#define SSCHECK(need) SSGROW(need) /* legacy */
+#define SSPUSHINT(i) (PL_savestack[PL_savestack_ix++].any_i32 = (I32)(i))
+#define SSPUSHLONG(i) (PL_savestack[PL_savestack_ix++].any_long = (long)(i))
+#define SSPUSHBOOL(p) (PL_savestack[PL_savestack_ix++].any_bool = (p))
+#define SSPUSHIV(i) (PL_savestack[PL_savestack_ix++].any_iv = (IV)(i))
+#define SSPUSHUV(u) (PL_savestack[PL_savestack_ix++].any_uv = (UV)(u))
+#define SSPUSHPTR(p) (PL_savestack[PL_savestack_ix++].any_ptr = (void*)(p))
+#define SSPUSHDPTR(p) (PL_savestack[PL_savestack_ix++].any_dptr = (p))
+#define SSPUSHDXPTR(p) (PL_savestack[PL_savestack_ix++].any_dxptr = (p))
+
+/* SS_ADD*: newer, faster versions of the above. Don't mix the two sets of
+ * macros. These are fast because they save reduce accesses to the PL_
+ * vars and move the size check to the end. Doing the check last means
+ * that values in registers will have been pushed and no longer needed, so
+ * don't need saving around the call to grow. Also, tail-call elimination
+ * of the grow() can be done. These changes reduce the code of something
+ * like save_pushptrptr() to half its former size.
+ * Of course, doing the size check *after* pushing means we must always
+ * ensure there are SS_MAXPUSH free slots on the savestack. This is ensured by
+ * savestack_grow_cnt always allocating SS_MAXPUSH slots
+ * more than asked for, or that it sets PL_savestack_max to
+ *
+ * These are for internal core use only and are subject to change */
+
+#define dSS_ADD \
+ I32 ix = PL_savestack_ix; \
+ ANY *ssp = &PL_savestack[ix]
+
+#define SS_ADD_END(need) \
+ assert((need) <= SS_MAXPUSH); \
+ ix += (need); \
+ PL_savestack_ix = ix; \
+ assert(ix <= PL_savestack_max + SS_MAXPUSH); \
+ if (UNLIKELY(ix > PL_savestack_max)) savestack_grow_cnt(ix - PL_savestack_max); \
+ assert(PL_savestack_ix <= PL_savestack_max);
+
+#define SS_ADD_INT(i) ((ssp++)->any_i32 = (I32)(i))
+#define SS_ADD_LONG(i) ((ssp++)->any_long = (long)(i))
+#define SS_ADD_BOOL(p) ((ssp++)->any_bool = (p))
+#define SS_ADD_IV(i) ((ssp++)->any_iv = (IV)(i))
+#define SS_ADD_UV(u) ((ssp++)->any_uv = (UV)(u))
+#define SS_ADD_PTR(p) ((ssp++)->any_ptr = (void*)(p))
+#define SS_ADD_DPTR(p) ((ssp++)->any_dptr = (p))
+#define SS_ADD_DXPTR(p) ((ssp++)->any_dxptr = (p))
+
+#define SSPOPINT (PL_savestack[--PL_savestack_ix].any_i32)
+#define SSPOPLONG (PL_savestack[--PL_savestack_ix].any_long)
+#define SSPOPBOOL (PL_savestack[--PL_savestack_ix].any_bool)
+#define SSPOPIV (PL_savestack[--PL_savestack_ix].any_iv)
+#define SSPOPUV (PL_savestack[--PL_savestack_ix].any_uv)
+#define SSPOPPTR (PL_savestack[--PL_savestack_ix].any_ptr)
+#define SSPOPDPTR (PL_savestack[--PL_savestack_ix].any_dptr)
+#define SSPOPDXPTR (PL_savestack[--PL_savestack_ix].any_dxptr)
+
+
+/*
+=for apidoc_section $callback
+
+=for apidoc Amn;||SAVETMPS
+Opening bracket for temporaries on a callback. See C<L</FREETMPS>> and
+L<perlcall>.