ns-eel-int.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /*
  2. Nullsoft Expression Evaluator Library (NS-EEL)
  3. Copyright (C) 1999-2003 Nullsoft, Inc.
  4. ns-eel-int.h: internal code definition header.
  5. This software is provided 'as-is', without any express or implied
  6. warranty. In no event will the authors be held liable for any damages
  7. arising from the use of this software.
  8. Permission is granted to anyone to use this software for any purpose,
  9. including commercial applications, and to alter it and redistribute it
  10. freely, subject to the following restrictions:
  11. 1. The origin of this software must not be misrepresented; you must not
  12. claim that you wrote the original software. If you use this software
  13. in a product, an acknowledgment in the product documentation would be
  14. appreciated but is not required.
  15. 2. Altered source versions must be plainly marked as such, and must not be
  16. misrepresented as being the original software.
  17. 3. This notice may not be removed or altered from any source distribution.
  18. */
  19. #ifndef __NS_EELINT_H__
  20. #define __NS_EELINT_H__
  21. #ifdef _WIN32
  22. #include <windows.h>
  23. #else
  24. #include "../wdltypes.h"
  25. #endif
  26. #include "ns-eel.h"
  27. #include "ns-eel-addfuncs.h"
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. #define FN_ASSIGN 0
  32. #define FN_MULTIPLY 1
  33. #define FN_DIVIDE 2
  34. #define FN_MODULO 3
  35. #define FN_ADD 4
  36. #define FN_SUB 5
  37. #define FN_AND 6
  38. #define FN_OR 7
  39. #define FN_UMINUS 8
  40. #define FN_UPLUS 9
  41. #define MATH_SIMPLE 0
  42. #define MATH_FN 1
  43. #define YYSTYPE INT_PTR
  44. #define NSEEL_CLOSEFACTOR 0.00001
  45. typedef struct
  46. {
  47. int srcByteCount;
  48. int destByteCount;
  49. } lineRecItem;
  50. typedef struct _compileContext
  51. {
  52. EEL_F **varTable_Values;
  53. char **varTable_Names;
  54. int varTable_numBlocks;
  55. int errVar;
  56. int colCount;
  57. INT_PTR result;
  58. char last_error_string[256];
  59. YYSTYPE yylval;
  60. int yychar; /* the lookahead symbol */
  61. int yynerrs; /* number of parse errors so far */
  62. char yytext[256];
  63. char lastVar[256];
  64. char *llsave[16]; /* Look ahead buffer */
  65. char llbuf[100]; /* work buffer */
  66. char *llp1;// = &llbuf[0]; /* pointer to next avail. in token */
  67. char *llp2;// = &llbuf[0]; /* pointer to end of lookahead */
  68. char *llend;// = &llbuf[0]; /* pointer to end of token */
  69. char *llebuf;// = &llbuf[sizeof llbuf];
  70. int lleof;
  71. int yyline;// = 0;
  72. void *tmpblocks_head,*blocks_head;
  73. int computTableTop; // make it abort on potential overflow =)
  74. int l_stats[4]; // source bytes, static code bytes, call code bytes, data bytes
  75. lineRecItem *compileLineRecs;
  76. int compileLineRecs_size;
  77. int compileLineRecs_alloc;
  78. void *ram_blocks; // this needs to be immediately followed by
  79. int ram_needfree;
  80. void *gram_blocks;
  81. void *caller_this;
  82. }
  83. compileContext;
  84. #define NSEEL_VARS_PER_BLOCK 64
  85. typedef struct {
  86. const char *name;
  87. void *afunc;
  88. void *func_e;
  89. int nParams;
  90. void *replptrs[4];
  91. NSEEL_PPPROC pProc;
  92. } functionType;
  93. extern functionType *nseel_getFunctionFromTable(int idx);
  94. INT_PTR nseel_createCompiledValue(compileContext *ctx, EEL_F value, EEL_F *addrValue);
  95. INT_PTR nseel_createCompiledFunction1(compileContext *ctx, int fntype, INT_PTR fn, INT_PTR code);
  96. INT_PTR nseel_createCompiledFunction2(compileContext *ctx, int fntype, INT_PTR fn, INT_PTR code1, INT_PTR code2);
  97. INT_PTR nseel_createCompiledFunction3(compileContext *ctx, int fntype, INT_PTR fn, INT_PTR code1, INT_PTR code2, INT_PTR code3);
  98. extern EEL_F nseel_globalregs[100];
  99. void nseel_resetVars(compileContext *ctx);
  100. EEL_F *nseel_getVarPtr(compileContext *ctx, char *varName);
  101. EEL_F *nseel_registerVar(compileContext *ctx, char *varName);
  102. INT_PTR *EEL_GLUE_set_immediate(void *_p, void *newv);
  103. // other shat
  104. INT_PTR nseel_setVar(compileContext *ctx, INT_PTR varNum);
  105. INT_PTR nseel_getVar(compileContext *ctx, INT_PTR varNum);
  106. void *nseel_compileExpression(compileContext *ctx, char *txt);
  107. #define VALUE 258
  108. #define IDENTIFIER 259
  109. #define FUNCTION1 260
  110. #define FUNCTION2 261
  111. #define FUNCTION3 262
  112. #define UMINUS 263
  113. #define UPLUS 264
  114. INT_PTR nseel_translate(compileContext *ctx, int type);
  115. void nseel_count(compileContext *ctx);
  116. void nseel_setLastVar(compileContext *ctx);
  117. INT_PTR nseel_lookup(compileContext *ctx, int *typeOfObject);
  118. int nseel_yyerror(compileContext *ctx);
  119. int nseel_yylex(compileContext *ctx, char **exp);
  120. int nseel_yyparse(compileContext *ctx, char *exp);
  121. void nseel_llinit(compileContext *ctx);
  122. int nseel_gettoken(compileContext *ctx, char *lltb, int lltbsiz);
  123. struct lextab {
  124. int llendst; /* Last state number */
  125. char *lldefault; /* Default state table */
  126. char *llnext; /* Next state table */
  127. char *llcheck; /* Check table */
  128. int *llbase; /* Base table */
  129. int llnxtmax; /* Last in next table */
  130. int (*llmove)(); /* Move between states */
  131. char *llfinal; /* Final state descriptions */
  132. int (*llactr)(); /* Action routine */
  133. int *lllook; /* Look ahead vector if != NULL */
  134. char *llign; /* Ignore char vec if != NULL */
  135. char *llbrk; /* Break char vec if != NULL */
  136. char *llill; /* Illegal char vec if != NULL */
  137. };
  138. extern struct lextab nseel_lextab;
  139. EEL_F * NSEEL_CGEN_CALL __NSEEL_RAMAlloc(EEL_F ***blocks, int w);
  140. EEL_F * NSEEL_CGEN_CALL __NSEEL_RAMAllocGMEM(EEL_F ***blocks, int w);
  141. EEL_F * NSEEL_CGEN_CALL __NSEEL_RAM_MemSet(EEL_F ***blocks,EEL_F *dest, EEL_F *v, EEL_F *lenptr);
  142. EEL_F * NSEEL_CGEN_CALL __NSEEL_RAM_MemFree(EEL_F ***blocks, EEL_F *which);
  143. EEL_F * NSEEL_CGEN_CALL __NSEEL_RAM_MemCpy(EEL_F ***blocks,EEL_F *dest, EEL_F *src, EEL_F *lenptr);
  144. #ifndef max
  145. #define max(x,y) ((x)<(y)?(y):(x))
  146. #define min(x,y) ((x)<(y)?(x):(y))
  147. #endif
  148. #ifdef __ppc__
  149. #define EEL_F2int(x) ((int)(x))
  150. #elif defined (_WIN64)
  151. // todo: AMD64 version?
  152. #define EEL_F2int(x) ((int)(x))
  153. #elif defined(_MSC_VER)
  154. static __inline int EEL_F2int(EEL_F d)
  155. {
  156. int tmp;
  157. __asm {
  158. fld d
  159. fistp tmp
  160. }
  161. return tmp;
  162. }
  163. #else
  164. static inline int EEL_F2int(EEL_F d)
  165. {
  166. int tmp;
  167. __asm__ __volatile__ ("fistpl %0" : "=m" (tmp) : "t" (d) : "st") ;
  168. return tmp;
  169. }
  170. #endif
  171. #ifdef __cplusplus
  172. }
  173. #endif
  174. #endif//__NS_EELINT_H__