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