Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

385 lines
12 KiB

  1. /* pp.h
  2. *
  3. * Copyright (c) 1991-2001, Larry Wall
  4. *
  5. * You may distribute under the terms of either the GNU General Public
  6. * License or the Artistic License, as specified in the README file.
  7. *
  8. */
  9. #ifdef USE_THREADS
  10. #define ARGS thr
  11. #define dARGS struct perl_thread *thr;
  12. #else
  13. #define ARGS
  14. #define dARGS
  15. #endif /* USE_THREADS */
  16. #define PP(s) OP * Perl_##s(pTHX)
  17. /*
  18. =for apidoc AmU||SP
  19. Stack pointer. This is usually handled by C<xsubpp>. See C<dSP> and
  20. C<SPAGAIN>.
  21. =for apidoc AmU||MARK
  22. Stack marker variable for the XSUB. See C<dMARK>.
  23. =for apidoc Ams||PUSHMARK
  24. Opening bracket for arguments on a callback. See C<PUTBACK> and
  25. L<perlcall>.
  26. =for apidoc Ams||dSP
  27. Declares a local copy of perl's stack pointer for the XSUB, available via
  28. the C<SP> macro. See C<SP>.
  29. =for apidoc Ams||dMARK
  30. Declare a stack marker variable, C<mark>, for the XSUB. See C<MARK> and
  31. C<dORIGMARK>.
  32. =for apidoc Ams||dORIGMARK
  33. Saves the original stack mark for the XSUB. See C<ORIGMARK>.
  34. =for apidoc AmU||ORIGMARK
  35. The original stack mark for the XSUB. See C<dORIGMARK>.
  36. =for apidoc Ams||SPAGAIN
  37. Refetch the stack pointer. Used after a callback. See L<perlcall>.
  38. =cut
  39. */
  40. #undef SP /* Solaris 2.7 i386 has this in /usr/include/sys/reg.h */
  41. #define SP sp
  42. #define MARK mark
  43. #define TARG targ
  44. #define PUSHMARK(p) if (++PL_markstack_ptr == PL_markstack_max) \
  45. markstack_grow(); \
  46. *PL_markstack_ptr = (p) - PL_stack_base
  47. #define TOPMARK (*PL_markstack_ptr)
  48. #define POPMARK (*PL_markstack_ptr--)
  49. #define dSP register SV **sp = PL_stack_sp
  50. #define djSP dSP
  51. #define dMARK register SV **mark = PL_stack_base + POPMARK
  52. #define dORIGMARK I32 origmark = mark - PL_stack_base
  53. #define SETORIGMARK origmark = mark - PL_stack_base
  54. #define ORIGMARK (PL_stack_base + origmark)
  55. #define SPAGAIN sp = PL_stack_sp
  56. #define MSPAGAIN sp = PL_stack_sp; mark = ORIGMARK
  57. #define GETTARGETSTACKED targ = (PL_op->op_flags & OPf_STACKED ? POPs : PAD_SV(PL_op->op_targ))
  58. #define dTARGETSTACKED SV * GETTARGETSTACKED
  59. #define GETTARGET targ = PAD_SV(PL_op->op_targ)
  60. #define dTARGET SV * GETTARGET
  61. #define GETATARGET targ = (PL_op->op_flags & OPf_STACKED ? sp[-1] : PAD_SV(PL_op->op_targ))
  62. #define dATARGET SV * GETATARGET
  63. #define dTARG SV *targ
  64. #define NORMAL PL_op->op_next
  65. #define DIE return Perl_die
  66. /*
  67. =for apidoc Ams||PUTBACK
  68. Closing bracket for XSUB arguments. This is usually handled by C<xsubpp>.
  69. See C<PUSHMARK> and L<perlcall> for other uses.
  70. =for apidoc Amn|SV*|POPs
  71. Pops an SV off the stack.
  72. =for apidoc Amn|char*|POPp
  73. Pops a string off the stack.
  74. =for apidoc Amn|NV|POPn
  75. Pops a double off the stack.
  76. =for apidoc Amn|IV|POPi
  77. Pops an integer off the stack.
  78. =for apidoc Amn|long|POPl
  79. Pops a long off the stack.
  80. =cut
  81. */
  82. #define PUTBACK PL_stack_sp = sp
  83. #define RETURN return PUTBACK, NORMAL
  84. #define RETURNOP(o) return PUTBACK, o
  85. #define RETURNX(x) return x, PUTBACK, NORMAL
  86. #define POPs (*sp--)
  87. #define POPp (SvPVx(POPs, PL_na)) /* deprecated */
  88. #define POPpx (SvPVx(POPs, n_a))
  89. #define POPn (SvNVx(POPs))
  90. #define POPi ((IV)SvIVx(POPs))
  91. #define POPu ((UV)SvUVx(POPs))
  92. #define POPl ((long)SvIVx(POPs))
  93. #define POPul ((unsigned long)SvIVx(POPs))
  94. #ifdef HAS_QUAD
  95. #define POPq ((Quad_t)SvIVx(POPs))
  96. #define POPuq ((Uquad_t)SvUVx(POPs))
  97. #endif
  98. #define TOPs (*sp)
  99. #define TOPm1s (*(sp-1))
  100. #define TOPp1s (*(sp+1))
  101. #define TOPp (SvPV(TOPs, PL_na)) /* deprecated */
  102. #define TOPpx (SvPV(TOPs, n_a))
  103. #define TOPn (SvNV(TOPs))
  104. #define TOPi ((IV)SvIV(TOPs))
  105. #define TOPu ((UV)SvUV(TOPs))
  106. #define TOPl ((long)SvIV(TOPs))
  107. #define TOPul ((unsigned long)SvUV(TOPs))
  108. #ifdef HAS_QUAD
  109. #define TOPq ((Quad_t)SvIV(TOPs))
  110. #define TOPuq ((Uquad_t)SvUV(TOPs))
  111. #endif
  112. /* Go to some pains in the rare event that we must extend the stack. */
  113. /*
  114. =for apidoc Am|void|EXTEND|SP|int nitems
  115. Used to extend the argument stack for an XSUB's return values. Once
  116. used, guarantees that there is room for at least C<nitems> to be pushed
  117. onto the stack.
  118. =for apidoc Am|void|PUSHs|SV* sv
  119. Push an SV onto the stack. The stack must have room for this element.
  120. Does not handle 'set' magic. See C<XPUSHs>.
  121. =for apidoc Am|void|PUSHp|char* str|STRLEN len
  122. Push a string onto the stack. The stack must have room for this element.
  123. The C<len> indicates the length of the string. Handles 'set' magic. See
  124. C<XPUSHp>.
  125. =for apidoc Am|void|PUSHn|NV nv
  126. Push a double onto the stack. The stack must have room for this element.
  127. Handles 'set' magic. See C<XPUSHn>.
  128. =for apidoc Am|void|PUSHi|IV iv
  129. Push an integer onto the stack. The stack must have room for this element.
  130. Handles 'set' magic. See C<XPUSHi>.
  131. =for apidoc Am|void|PUSHu|UV uv
  132. Push an unsigned integer onto the stack. The stack must have room for this
  133. element. See C<XPUSHu>.
  134. =for apidoc Am|void|XPUSHs|SV* sv
  135. Push an SV onto the stack, extending the stack if necessary. Does not
  136. handle 'set' magic. See C<PUSHs>.
  137. =for apidoc Am|void|XPUSHp|char* str|STRLEN len
  138. Push a string onto the stack, extending the stack if necessary. The C<len>
  139. indicates the length of the string. Handles 'set' magic. See
  140. C<PUSHp>.
  141. =for apidoc Am|void|XPUSHn|NV nv
  142. Push a double onto the stack, extending the stack if necessary. Handles
  143. 'set' magic. See C<PUSHn>.
  144. =for apidoc Am|void|XPUSHi|IV iv
  145. Push an integer onto the stack, extending the stack if necessary. Handles
  146. 'set' magic. See C<PUSHi>.
  147. =for apidoc Am|void|XPUSHu|UV uv
  148. Push an unsigned integer onto the stack, extending the stack if necessary.
  149. See C<PUSHu>.
  150. =cut
  151. */
  152. #define EXTEND(p,n) STMT_START { if (PL_stack_max - p < (n)) { \
  153. sp = stack_grow(sp,p, (int) (n)); \
  154. } } STMT_END
  155. /* Same thing, but update mark register too. */
  156. #define MEXTEND(p,n) STMT_START {if (PL_stack_max - p < (n)) { \
  157. int markoff = mark - PL_stack_base; \
  158. sp = stack_grow(sp,p,(int) (n)); \
  159. mark = PL_stack_base + markoff; \
  160. } } STMT_END
  161. #define PUSHs(s) (*++sp = (s))
  162. #define PUSHTARG STMT_START { SvSETMAGIC(TARG); PUSHs(TARG); } STMT_END
  163. #define PUSHp(p,l) STMT_START { sv_setpvn(TARG, (p), (l)); PUSHTARG; } STMT_END
  164. #define PUSHn(n) STMT_START { sv_setnv(TARG, (NV)(n)); PUSHTARG; } STMT_END
  165. #define PUSHi(i) STMT_START { sv_setiv(TARG, (IV)(i)); PUSHTARG; } STMT_END
  166. #define PUSHu(u) STMT_START { sv_setuv(TARG, (UV)(u)); PUSHTARG; } STMT_END
  167. #define XPUSHs(s) STMT_START { EXTEND(sp,1); (*++sp = (s)); } STMT_END
  168. #define XPUSHTARG STMT_START { SvSETMAGIC(TARG); XPUSHs(TARG); } STMT_END
  169. #define XPUSHp(p,l) STMT_START { sv_setpvn(TARG, (p), (l)); XPUSHTARG; } STMT_END
  170. #define XPUSHn(n) STMT_START { sv_setnv(TARG, (NV)(n)); XPUSHTARG; } STMT_END
  171. #define XPUSHi(i) STMT_START { sv_setiv(TARG, (IV)(i)); XPUSHTARG; } STMT_END
  172. #define XPUSHu(u) STMT_START { sv_setuv(TARG, (UV)(u)); XPUSHTARG; } STMT_END
  173. #define XPUSHundef STMT_START { SvOK_off(TARG); XPUSHs(TARG); } STMT_END
  174. #define SETs(s) (*sp = s)
  175. #define SETTARG STMT_START { SvSETMAGIC(TARG); SETs(TARG); } STMT_END
  176. #define SETp(p,l) STMT_START { sv_setpvn(TARG, (p), (l)); SETTARG; } STMT_END
  177. #define SETn(n) STMT_START { sv_setnv(TARG, (NV)(n)); SETTARG; } STMT_END
  178. #define SETi(i) STMT_START { sv_setiv(TARG, (IV)(i)); SETTARG; } STMT_END
  179. #define SETu(u) STMT_START { sv_setuv(TARG, (UV)(u)); SETTARG; } STMT_END
  180. #define dTOPss SV *sv = TOPs
  181. #define dPOPss SV *sv = POPs
  182. #define dTOPnv NV value = TOPn
  183. #define dPOPnv NV value = POPn
  184. #define dTOPiv IV value = TOPi
  185. #define dPOPiv IV value = POPi
  186. #define dTOPuv UV value = TOPu
  187. #define dPOPuv UV value = POPu
  188. #ifdef HAS_QUAD
  189. #define dTOPqv Quad_t value = TOPu
  190. #define dPOPqv Quad_t value = POPu
  191. #define dTOPuqv Uquad_t value = TOPuq
  192. #define dPOPuqv Uquad_t value = POPuq
  193. #endif
  194. #define dPOPXssrl(X) SV *right = POPs; SV *left = CAT2(X,s)
  195. #define dPOPXnnrl(X) NV right = POPn; NV left = CAT2(X,n)
  196. #define dPOPXiirl(X) IV right = POPi; IV left = CAT2(X,i)
  197. #define USE_LEFT(sv) \
  198. (SvOK(sv) || SvGMAGICAL(sv) || !(PL_op->op_flags & OPf_STACKED))
  199. #define dPOPXnnrl_ul(X) \
  200. NV right = POPn; \
  201. SV *leftsv = CAT2(X,s); \
  202. NV left = USE_LEFT(leftsv) ? SvNV(leftsv) : 0.0
  203. #define dPOPXiirl_ul(X) \
  204. IV right = POPi; \
  205. SV *leftsv = CAT2(X,s); \
  206. IV left = USE_LEFT(leftsv) ? SvIV(leftsv) : 0
  207. #define dPOPPOPssrl dPOPXssrl(POP)
  208. #define dPOPPOPnnrl dPOPXnnrl(POP)
  209. #define dPOPPOPnnrl_ul dPOPXnnrl_ul(POP)
  210. #define dPOPPOPiirl dPOPXiirl(POP)
  211. #define dPOPPOPiirl_ul dPOPXiirl_ul(POP)
  212. #define dPOPTOPssrl dPOPXssrl(TOP)
  213. #define dPOPTOPnnrl dPOPXnnrl(TOP)
  214. #define dPOPTOPnnrl_ul dPOPXnnrl_ul(TOP)
  215. #define dPOPTOPiirl dPOPXiirl(TOP)
  216. #define dPOPTOPiirl_ul dPOPXiirl_ul(TOP)
  217. #define RETPUSHYES RETURNX(PUSHs(&PL_sv_yes))
  218. #define RETPUSHNO RETURNX(PUSHs(&PL_sv_no))
  219. #define RETPUSHUNDEF RETURNX(PUSHs(&PL_sv_undef))
  220. #define RETSETYES RETURNX(SETs(&PL_sv_yes))
  221. #define RETSETNO RETURNX(SETs(&PL_sv_no))
  222. #define RETSETUNDEF RETURNX(SETs(&PL_sv_undef))
  223. #define ARGTARG PL_op->op_targ
  224. /* See OPpTARGET_MY: */
  225. #define MAXARG (PL_op->op_private & 15)
  226. #define SWITCHSTACK(f,t) \
  227. STMT_START { \
  228. AvFILLp(f) = sp - PL_stack_base; \
  229. PL_stack_base = AvARRAY(t); \
  230. PL_stack_max = PL_stack_base + AvMAX(t); \
  231. sp = PL_stack_sp = PL_stack_base + AvFILLp(t); \
  232. PL_curstack = t; \
  233. } STMT_END
  234. #define EXTEND_MORTAL(n) \
  235. STMT_START { \
  236. if (PL_tmps_ix + (n) >= PL_tmps_max) \
  237. tmps_grow(n); \
  238. } STMT_END
  239. #define AMGf_noright 1
  240. #define AMGf_noleft 2
  241. #define AMGf_assign 4
  242. #define AMGf_unary 8
  243. #define tryAMAGICbinW(meth,assign,set) STMT_START { \
  244. if (PL_amagic_generation) { \
  245. SV* tmpsv; \
  246. SV* right= *(sp); SV* left= *(sp-1);\
  247. if ((SvAMAGIC(left)||SvAMAGIC(right))&&\
  248. (tmpsv=amagic_call(left, \
  249. right, \
  250. CAT2(meth,_amg), \
  251. (assign)? AMGf_assign: 0))) {\
  252. SPAGAIN; \
  253. (void)POPs; set(tmpsv); RETURN; } \
  254. } \
  255. } STMT_END
  256. #define tryAMAGICbin(meth,assign) tryAMAGICbinW(meth,assign,SETsv)
  257. #define tryAMAGICbinSET(meth,assign) tryAMAGICbinW(meth,assign,SETs)
  258. #define AMG_CALLun(sv,meth) amagic_call(sv,&PL_sv_undef, \
  259. CAT2(meth,_amg),AMGf_noright | AMGf_unary)
  260. #define AMG_CALLbinL(left,right,meth) \
  261. amagic_call(left,right,CAT2(meth,_amg),AMGf_noright)
  262. #define tryAMAGICunW(meth,set,shift,ret) STMT_START { \
  263. if (PL_amagic_generation) { \
  264. SV* tmpsv; \
  265. SV* arg= sp[shift]; \
  266. am_again: \
  267. if ((SvAMAGIC(arg))&&\
  268. (tmpsv=AMG_CALLun(arg,meth))) {\
  269. SPAGAIN; if (shift) sp += shift; \
  270. set(tmpsv); ret; } \
  271. } \
  272. } STMT_END
  273. #define FORCE_SETs(sv) STMT_START { sv_setsv(TARG, (sv)); SETTARG; } STMT_END
  274. #define tryAMAGICun(meth) tryAMAGICunW(meth,SETsvUN,0,RETURN)
  275. #define tryAMAGICunSET(meth) tryAMAGICunW(meth,SETs,0,RETURN)
  276. #define tryAMAGICunTARGET(meth, shift) \
  277. { dSP; sp--; /* get TARGET from below PL_stack_sp */ \
  278. { dTARGETSTACKED; \
  279. { dSP; tryAMAGICunW(meth,FORCE_SETs,shift,RETURN);}}}
  280. #define setAGAIN(ref) sv = ref; \
  281. if (!SvROK(ref)) \
  282. Perl_croak(aTHX_ "Overloaded dereference did not return a reference"); \
  283. if (ref != arg && SvRV(ref) != SvRV(arg)) { \
  284. arg = ref; \
  285. goto am_again; \
  286. }
  287. #define tryAMAGICunDEREF(meth) tryAMAGICunW(meth,setAGAIN,0,(void)0)
  288. #define opASSIGN (PL_op->op_flags & OPf_STACKED)
  289. #define SETsv(sv) STMT_START { \
  290. if (opASSIGN || (SvFLAGS(TARG) & SVs_PADMY)) \
  291. { sv_setsv(TARG, (sv)); SETTARG; } \
  292. else SETs(sv); } STMT_END
  293. #define SETsvUN(sv) STMT_START { \
  294. if (SvFLAGS(TARG) & SVs_PADMY) \
  295. { sv_setsv(TARG, (sv)); SETTARG; } \
  296. else SETs(sv); } STMT_END
  297. /* newSVsv does not behave as advertised, so we copy missing
  298. * information by hand */
  299. /* SV* ref causes confusion with the member variable
  300. changed SV* ref to SV* tmpRef */
  301. #define RvDEEPCP(rv) STMT_START { SV* tmpRef=SvRV(rv); \
  302. if (SvREFCNT(tmpRef)>1) { \
  303. SvREFCNT_dec(tmpRef); \
  304. SvRV(rv)=AMG_CALLun(rv,copy); \
  305. } } STMT_END
  306. /*
  307. =for apidoc mU||LVRET
  308. True if this op will be the return value of an lvalue subroutine
  309. =cut */
  310. #define LVRET ((PL_op->op_private & OPpMAYBE_LVSUB) && is_lvalue_sub())