macros.inc 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. Legal:
  3. Version: MPL 1.1
  4. The contents of this file are subject to the Mozilla Public License Version
  5. 1.1 the "License"; you may not use this file except in compliance with
  6. the License. You may obtain a copy of the License at
  7. http://www.mozilla.org/MPL/
  8. Software distributed under the License is distributed on an "AS IS" basis,
  9. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  10. for the specific language governing rights and limitations under the
  11. License.
  12. The Original Code is the YSI framework.
  13. The Initial Developer of the Original Code is Alex "Y_Less" Cole.
  14. Portions created by the Initial Developer are Copyright C 2011
  15. the Initial Developer. All Rights Reserved.
  16. Contributors:
  17. Y_Less
  18. koolk
  19. JoeBullet/Google63
  20. g_aSlice/Slice
  21. Misiur
  22. samphunter
  23. tianmeta
  24. maddinat0r
  25. spacemud
  26. Crayder
  27. Dayvison
  28. Ahmad45123
  29. Zeex
  30. irinel1996
  31. Yiin-
  32. Chaprnks
  33. Konstantinos
  34. Masterchen09
  35. Southclaws
  36. PatchwerkQWER
  37. m0k1
  38. paulommu
  39. udan111
  40. Thanks:
  41. JoeBullet/Google63 - Handy arbitrary ASM jump code using SCTRL.
  42. ZeeX - Very productive conversations.
  43. koolk - IsPlayerinAreaEx code.
  44. TheAlpha - Danish translation.
  45. breadfish - German translation.
  46. Fireburn - Dutch translation.
  47. yom - French translation.
  48. 50p - Polish translation.
  49. Zamaroht - Spanish translation.
  50. Los - Portuguese translation.
  51. Dracoblue, sintax, mabako, Xtreme, other coders - Producing other modes for
  52. me to strive to better.
  53. Pixels^ - Running XScripters where the idea was born.
  54. Matite - Pestering me to release it and using it.
  55. Very special thanks to:
  56. Thiadmer - PAWN, whose limits continue to amaze me!
  57. Kye/Kalcor - SA:MP.
  58. SA:MP Team past, present and future - SA:MP.
  59. Optional plugins:
  60. Gamer_Z - GPS.
  61. Incognito - Streamer.
  62. Me - sscanf2, fixes2, Whirlpool.
  63. */
  64. #if 0
  65. // This:
  66. inline func(a, &b, c[100])
  67. {
  68. // Inline function code.
  69. }
  70. // Becomes:
  71. static const func[]="func:.....";if(I@E(func))for(new a, b, c[100];I@F();)while(I@L(0,-1,100))
  72. {
  73. // Inline function code.
  74. }
  75. // Which is:
  76. static const
  77. func[] = "func:.....";
  78. if (I@E(func))
  79. {
  80. for (new a, b, c[100]; I@F(); )
  81. {
  82. while (I@L(0, -1, 100))
  83. {
  84. // Inline function code.
  85. }
  86. }
  87. }
  88. // Translated:
  89. static const
  90. func[] = "func\02;" #FUNC_ADDRESS #PARAMETERS #INTERNAL_RETURN #PREVIOUS_FUNC_NAME #PARENT_SCOPE_START;
  91. if (Inline_Entry(func))
  92. {
  93. for (new a, b, c[100]; Inline_Allocator(); )
  94. {
  95. while (Inline_Main(INLINE_TYPE_VAR, INLINE_TYPE_REF, INLINE_TYPE_ARR(100)))
  96. {
  97. // Inline function code.
  98. }
  99. }
  100. }
  101. // Run-time modified to something like:
  102. goto somewhere_after_this_func;
  103. func(parent, parameteters, a, b, c[100])
  104. {
  105. new parent, local, variables;
  106. // Inline function code.
  107. }
  108. // Multiple inlines in a row are combined in to one big jump.
  109. somewhere_after_this_func:
  110. #endif
  111. #define LAMBDA_i<%9>{%0}(%1)%8; _DO_LAMBDA|||new _0|||,0|||<%9>{%0}(%1)%8;
  112. #define LAMBDA_ii<%9>{%0}(%1)%8; _DO_LAMBDA|||new _0,_1|||,0,0|||<%9>{%0}(%1)%8;
  113. #define LAMBDA_iii<%9>{%0}(%1)%8; _DO_LAMBDA|||new _0,_1,_2|||,0,0,0|||<%9>{%0}(%1)%8;
  114. #define LAMBDA_iiii<%9>{%0}(%1)%8; _DO_LAMBDA|||new _0,_1,_2,_3|||,0,0,0,0|||<%9>{%0}(%1)%8;
  115. #define LAMBDA_iiiii<%9>{%0}(%1)%8; _DO_LAMBDA|||new _0,_1,_2,_3,_4|||,0,0,0,0,0|||<%9>{%0}(%1)%8;
  116. #define _DO_LAMBDA|||%6|||%5|||<%9>{%0}(%1)%8; LAM@0()%8;{LAM@1();static const YSII[]="@:....";if(I@E(YSII))for(%6;I@F();)while(I@L(I@K()%5))YSI_gInlineRet+=(%0);LAM@2(%9(callback_tag:YSII%1));}
  117. #define inline%0(%1) static %0[_:I@E:32]=#%0":....";if(I@E(_:_YI@CP:%0))for(new%1,,;I@F();)while(I@L(I@K(1)))
  118. #define I@E:32]=#%9const%7\32;%8":....";if(I@E(_:_YI@CP:%9const%7\32;%8))for(%1)while(I@L(I@K(1))) 32]=#%8":....";if(I@E(_:_YI@CP:%8))for(%1)while(I@L(I@K()))
  119. #define _YI@CP:%8))for(new%0,%1; @Ia:@Ib:@Ic:@Id:@Iz:%8))for(new|||%0|||%1;
  120. // Detect 0 parameters.
  121. #define @Ia:@Ib:@Ic:@Id:@Iz:%8))for(new||||||,; %8))for(;
  122. // Detect arrays. Get the size, defaulting to YSI_MAX_STRING (passing cellmax).
  123. #define @Ib:@Ic:@Id:@Iz:%8))for(new%0|||%2[%3]|||%4,%5;I@F();)while(I@L(%7)) @Ib:@Ic:@Id:@Iz:%8))for(new%0,%2[_:@Iy:%3]|||%4|||%5;I@F();)while(I@L(%7,@Ix&&&sizeof %2&&&))
  124. #define @Iy:]%0)while(I@L(%1&&&%2&&&%3)) YSI_MAX_INLINE_STRING]%0)while(I@L(%1%3))
  125. #define @Ix&&&%0&&& %0 // Remove this variable when the size is used correctly.
  126. // Default for passing strings, not arrays.
  127. stock const
  128. @Ix = cellmax;
  129. // Detect references.
  130. #define @Ic:@Id:@Iz:%8))for(new%0|||%1&%2|||%4,%5;I@F();)while(I@L(%7)) @Ib:@Ic:@Id:@Iz:%8))for(new%0,%2|||%4|||%5;I@F();)while(I@L(%7,-1))
  131. // Detect normal variables.
  132. #define @Id:@Iz:%8))for(new%0|||%2|||%4,%5;I@F();)while(I@L(%7)) @Ib:@Ic:@Id:@Iz:%8))for(new%0,%2|||%4|||%5;I@F();)while(I@L(%7,0))
  133. // Detect end of line.
  134. #define @Iz:%8))for(new%1,%0||||||; %8))for(new %0;
  135. // Drop support for anonymous functions.
  136. #define anonymous%0(%1) anonymous_no_longer_supported;for(new %1;FALSE;)
  137. // Parameter type for passing callbacks about.
  138. #define callback:%0) const callback_tag:callback_check:%0$$$
  139. #define callback_tag:callback_check:%0,%1$$$ callback_tag:%0[],%1)
  140. #define callback_check:%0$$$ %0[])
  141. #define using%0\10;%1 callback_tag:@Ik:@Il:%0
  142. // Get ONLY this ONE parameter (this is a VERY important stage)!
  143. #define @Ik:@Il:%0, @Ip:@Iq:@Io:@Iu:@Iw:|||%0|||,
  144. #define @Il:%0) @Ip:@Iq:@Io:@Iu:@Iw:|||%0|||)
  145. #define @Ip:%9|||%0callback%1||| @Ir:@Is:"\03;"#%1||||
  146. #define @Iq:%9|||%0public%1||| @Ir:@Is:"\03;"#%1||||
  147. #define @Io:%9|||%0inline%1||| @In:@It:%0%1||||
  148. #define @Iu:%9|||%0resolved%1||| @In:@It:%1[E_CALLBACK_DATA:0]||||
  149. #define @Iw:|||%1||| @In:@It:#%1||||
  150. // Callbacks with "On" in the name (often overidden by y_hooks and ALS).
  151. #define @Ir:@Is:%0On%1|||| @In:@It:%0"On"#%1||||
  152. #define @Is:%0|||| @In:@It:#%0|||| //Using_unknown_callback
  153. // Callbacks with additional parameters (MUST have matching parameters (y_ini)).
  154. #define @In:@It:%0(%1)%3||||%2) %0%3%2,.bExtra=true,.extra=%1)
  155. #define @It:%0|||| %0
  156. // Defer adding the close bracket till after other macros have run.
  157. #define _Y_INLINE_END )