file copied from ming 0.3alpha2
[swftools.git] / lib / action / compile.h
1 /* compile.h
2  * 
3  * $Id: compile.h,v 1.1 2004/02/02 10:12:34 kramm Exp $
4  * 
5  * Notice: This header file contains declarations of functions and types that
6  * are just used internally. All library functions and types that are supposed
7  * to be publicly accessable are defined in ./src/ming.h.
8  */
9
10 #ifndef SWF_COMPILE_H_INCLUDED
11 #define SWF_COMPILE_H_INCLUDED
12
13 #include "ming.h"
14
15 typedef struct _buffer *Buffer;
16
17 /* shut up bison.simple */
18 void yyerror(char *msg);
19 int yylex();
20
21 #ifndef max
22   #define max(x,y)      (((x)>(y))?(x):(y))
23 #endif
24
25 enum
26 {
27   PUSH_STRING = 0,
28   PUSH_PROPERTY = 1,
29   PUSH_NULL = 2,
30   PUSH_UNDEF = 3,
31   PUSH_REGISTER = 4,
32   PUSH_BOOLEAN = 5,
33   PUSH_DOUBLE = 6,
34   PUSH_INT = 7,
35   PUSH_CONSTANT = 8,
36   PUSH_CONSTANT16 = 9
37 };
38
39 typedef enum
40 {
41   FUNCTION_RANDOM,
42   FUNCTION_LENGTH,
43   FUNCTION_TIME,
44   FUNCTION_INT,
45   FUNCTION_CONCAT,
46   FUNCTION_DUPLICATECLIP
47 } SWFActionFunction;
48
49 typedef enum
50 {
51   GETURL_METHOD_NOSEND = 0,
52   GETURL_METHOD_GET    = 1,
53   GETURL_METHOD_POST   = 2
54 } SWFGetUrl2Method;
55
56 #define GETURL_LOADMOVIE 0x40
57 #define GETURL_LOADVARIABLES 0x80
58
59 #define MAGIC_CONTINUE_NUMBER 0x7FFE
60 #define MAGIC_BREAK_NUMBER    0x7FFF
61
62 #define MAGIC_CONTINUE_NUMBER_LO 0xFE
63 #define MAGIC_CONTINUE_NUMBER_HI 0x7F
64 #define MAGIC_BREAK_NUMBER_LO    0xFF
65 #define MAGIC_BREAK_NUMBER_HI    0x7F
66
67 #define BUFFER_INCREMENT 128
68
69 struct _buffer
70 {
71   byte *buffer;
72   byte *pos;
73   int buffersize;
74   int free;
75   byte *pushloc;
76 };
77
78 #define BUFFER_SIZE sizeof(struct _buffer)
79
80 struct switchcase
81 {       Buffer cond, action;
82         int condlen, actlen, isbreak;
83 };
84
85 struct switchcases
86 {
87         struct switchcase *list;
88         int count;
89 };
90
91 enum ctx
92 {
93         CTX_FUNCTION = 1,
94         CTX_LOOP,
95         CTX_FOR_IN,
96         CTX_SWITCH,
97
98         CTX_BREAK,
99         CTX_CONTINUE
100 };
101
102 void addctx(enum ctx val);
103 void delctx(enum ctx val);
104 int chkctx(enum ctx val);
105
106 void checkByteOrder();
107
108 /* create/destroy buffer object */
109 Buffer newBuffer();
110 void destroyBuffer(Buffer out);
111 int bufferConcat(Buffer a, Buffer b);        /* destroys b. */
112 int bufferWriteBuffer(Buffer a, Buffer b);   /* doesn't. */
113
114 /* utilities for writing */
115 void bufferGrow(Buffer out);
116 void bufferCheckSize(Buffer out, int bytes);
117
118 int bufferLength(Buffer out);
119
120 /* constant pool stuff */
121 int addConstant(const char *s);
122 int bufferWriteConstants(Buffer out);
123 #define MAXCONSTANTPOOLSIZE 65533
124
125 /* write data to buffer */
126 int bufferWriteOp(Buffer out, int data);
127 int bufferWritePushOp(Buffer out);
128 int bufferWriteU8(Buffer out, int data);
129 int bufferWriteS16(Buffer out, int data);
130 int bufferWriteData(Buffer out, const byte *buffer, int bytes);
131 int bufferWriteHardString(Buffer out, byte *string, int length);
132 int bufferWriteConstantString(Buffer out, byte *string, int length);
133 int bufferWriteString(Buffer out, byte *string, int length);
134 #ifdef __cplusplus
135 /* helper function to avoid many casts */
136 inline int bufferWriteString(Buffer out, char *string, int length) {
137         return bufferWriteString(out,(byte*) string, length); }
138 #endif
139 int bufferWriteInt(Buffer out, int i);
140 int bufferWriteDouble(Buffer out, double d);
141 int bufferWriteNull(Buffer out);
142 int bufferWriteBoolean(Buffer out, int val);
143 int bufferWriteRegister(Buffer out, int num);
144 int bufferWriteSetRegister(Buffer out, int num);
145 int bufferWriteGetProperty(Buffer out, char *string);
146 int bufferWriteSetProperty(Buffer out, char *string);
147 int bufferWriteWTHITProperty(Buffer out);
148
149 /* concat b to a, destroy b */
150 char *stringConcat(char *a, char *b);
151
152 /* resolve magic number standins to relative offsets */
153 void bufferResolveJumps(Buffer out);
154 void bufferResolveSwitch(Buffer buffer, struct switchcases *slp);
155
156 /* rather than setting globals... */
157 void swf4ParseInit(const char *string, int debug);
158 void swf5ParseInit(const char *string, int debug);
159
160 int swf4parse(void *b);
161 int swf5parse(void *b);
162
163 #endif /* SWF_COMPILE_H_INCLUDED */