1 /// Copyright: Copyright (c) 2017-2019 Andrey Penechko.
2 /// License: $(WEB boost.org/LICENSE_1_0.txt, Boost License 1.0).
3 /// Authors: Andrey Penechko.
4 module tests.stashed;
5 
6 import tester;
7 
8 immutable input1 = q{
9 	i32 a;
10 	struct structWIP {
11 		i64 e;
12 		i32 member(i32 param) {
13 			i32 c;
14 			i32 d;
15 			a = b + c + d + e + g;
16 		}
17 		i32 g;
18 	}
19 	i32 b;
20 };
21 
22 immutable input2 = q{void e() {
23 	i32 a;
24 	i32 b;
25 	i32 c;
26 
27 	void f() {
28 		i32 a;
29 		i32 b;
30 		i32 c;
31 		a = b + c;
32 	}
33 
34 	void g() {
35 		i32 a;
36 		i32 b;
37 
38 		void h() {
39 			i32 c;
40 			i32 d;
41 			c = a + d;
42 		}
43 
44 		void i() {
45 			i32 b;
46 			i32 d;
47 			b = a + c;
48 		}
49 
50 		b = a + c;
51 	}
52 
53 	a = b + c;
54 }};
55 
56 immutable input3 = q{
57 	A b;
58 	struct A{
59 		void fun(i32 param) {
60 			//a = 1;
61 			i32 a;
62 			a = (param + 1) - var + fun42();
63 		}
64 	}
65 	A a;
66 	i32 var;
67 	i32 fun42() { return 42; }
68 };
69 
70 immutable input4 = q{
71 	struct A {
72 		int x;
73 		struct B { int y; }
74 		B b;
75 	}
76 
77 	int i=0;
78 	int j=0;
79 
80 	void f() {
81 		A a;
82 		a.x = 1+i*j;
83 		a.b.y = 2;
84 		bool b = 3 == a.x;
85 		if ( i < j ) f();
86 	}
87 };
88 
89 // test implicit casting
90 immutable input5 = q{void f() {
91 	//struct A{}
92 	//A a;
93 	//if (a){} // error
94 	f32 var_f32;
95 	f64 var_f64;
96 	//var_f32 = var_f64; // error
97 	var_f64 = var_f32;
98 
99 	i8 var_i8;
100 	if (var_i8){}
101 	i16 var_i16;
102 	if (var_i16){}
103 	i32 var_i32;
104 	if (var_i32){}
105 	i64 var_i64;
106 	if (var_i64){}
107 
108 	u8 var_u8;
109 	if (var_u8){}
110 	u16 var_u16;
111 	if (var_u16){}
112 	u32 var_u32;
113 	if (var_u32){}
114 	u64 var_u64;
115 	if (var_u64){}
116 }};
117 
118 immutable input6 = q{void f() {
119 	f32 var_f32;
120 	f64 var_f64;
121 	var_f64 = var_f32;
122 	i8 var_i8;
123 	i16 var_i16;
124 	i32 var_i32;
125 	i64 var_i64;
126 	u8 var_u8;
127 	u16 var_u16;
128 	u32 var_u32;
129 	u64 var_u64;
130 
131 	var_i8 + var_i16;
132 	var_i8 + var_i32;
133 	var_i8 + var_i64;
134 	var_i8 + var_u8;
135 	var_i8 + var_u16;
136 	var_i8 + var_u32;
137 	var_i8 + var_u64;
138 	var_i8 + var_f32;
139 	var_i8 + var_f64;
140 
141 	var_i16 + var_i32;
142 	var_i16 + var_i64;
143 	var_i16 + var_u8;
144 	var_i16 + var_u16;
145 	var_i16 + var_u32;
146 	var_i16 + var_u64;
147 	var_i16 + var_f32;
148 	var_i16 + var_f64;
149 
150 	var_i32 + var_i32;
151 	var_i32 + var_i64;
152 	var_i32 + var_u8;
153 	var_i32 + var_u16;
154 	var_i32 + var_u32;
155 	var_i32 + var_u64;
156 	var_i32 + var_f32;
157 	var_i32 + var_f64;
158 
159 	var_i64 + var_i64;
160 	var_i64 + var_u8;
161 	var_i64 + var_u16;
162 	var_i64 + var_u32;
163 	var_i64 + var_u64;
164 	var_i64 + var_f32;
165 	var_i64 + var_f64;
166 
167 	var_u8 + var_u8;
168 	var_u8 + var_u16;
169 	var_u8 + var_u32;
170 	var_u8 + var_u64;
171 	var_u8 + var_f32;
172 	var_u8 + var_f64;
173 
174 	var_u16 + var_u16;
175 	var_u16 + var_u32;
176 	var_u16 + var_u64;
177 	var_u16 + var_f32;
178 	var_u16 + var_f64;
179 
180 	var_u32 + var_u32;
181 	var_u32 + var_u64;
182 	var_u32 + var_f32;
183 	var_u32 + var_f64;
184 
185 	var_u64 + var_u64;
186 	var_u64 + var_f32;
187 	var_u64 + var_f64;
188 
189 	var_f32 + var_f32;
190 	var_f32 + var_f64;
191 }};
192 
193 immutable inputX = q{
194 	#pragma(lib, "kernel32")
195 	u8 WriteConsoleA(
196 		void* hConsoleOutput,
197 		void* lpBuffer,
198 		u32 nNumberOfCharsToWrite,
199 		u32* lpNumberOfCharsWritten,
200 		void* lpReserved
201 	);
202 	#pragma(lib, "kernel32")
203 	void* GetStdHandle(u32 nStdHandle);
204 	enum : u32 {
205 		STD_INPUT_HANDLE  = 0xFFFFFFF6,
206 		STD_OUTPUT_HANDLE = 0xFFFFFFF5,
207 		STD_ERROR_HANDLE  = 0xFFFFFFF4
208 	}
209 	void main(void* hInstance, void* hPrevInstance, u8* lpCmdLine, i32 nShowCmd) {
210 		u8[] array = "Hello world";
211 		u32 numWritten;
212 		void* handle = GetStdHandle(STD_OUTPUT_HANDLE);
213 		WriteConsoleA(handle, array.ptr, array.length, &numWritten, null);
214 	}
215 };
216 
217 immutable input30 = q{--- test30
218 	void SDL_SetMainReady();
219 	i32 SDL_Init(u32);
220 	void SDL_Quit();
221 	void* SDL_CreateWindow(u8* title, i32 x, i32 y, i32 w, i32 h, u32 flags);
222 	void* SDL_CreateRenderer(void* window, i32 index, u32 flags);
223 	void SDL_DestroyRenderer(void* renderer);
224 	void SDL_DestroyWindow(void* renderer);
225 	i32 SDL_PollEvent(SDL_Event* event);
226 	struct SDL_Event
227 	{
228 		u32 type;
229 		u8[52] padding;
230 	}
231 	void ExitProcess(u32 uExitCode);
232 
233 	i32 main(void* hInstance, void* hPrevInstance, u8* lpCmdLine, i32 nShowCmd) {
234 		SDL_SetMainReady();
235 		if(SDL_Init(0x00000020) < 0) return 1;
236 		void* window = SDL_CreateWindow("SDL test via tiny_jit", 0x1FFF0000, 0x1FFF0000, 300, 100, 4);
237 		void* renderer = SDL_CreateRenderer(window, 0xFFFF_FFFF, 2);
238 		SDL_Event e;
239 		while (1)
240 		{
241 			SDL_PollEvent(&e);
242 			if (e.type == 0x100) // SDL_QUIT
243 				break;
244 		}
245 		SDL_DestroyRenderer(renderer);
246 		SDL_DestroyWindow(window);
247 		SDL_Quit();
248 		ExitProcess(0);
249 		return 0;
250 	}
251 };