nandi/vflutter_ffipublic Fork 0
4506a586d7400b00d732dcb97167be75ab41cab1
Commits
Clone
git clone https://git.rickub.com/nandi/vflutter_ffi.git
git clone ssh://git@rickub.com/nandi/vflutter_ffi.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

nimflutter_00.c · 337 lines · 9.4 KBC Blame HistoryRaw
Replace V with Nim 472eb49 nandithebull 21h ago1/* Generated by Nim Compiler v2.2.0 */
2#define NIM_INTBITS 64
3
4#include "nimbase.h"
5#include <string.h>
6#include <math.h>
7#undef LANGUAGE_C
8#undef MIPSEB
9#undef MIPSEL
10#undef PPC
11#undef R3000
12#undef R4000
13#undef i386
14#undef linux
15#undef mips
16#undef near
17#undef far
18#undef powerpc
19#undef unix
20typedef struct NimStrPayload NimStrPayload;
21typedef struct NimStringV2 NimStringV2;
22struct NimStrPayload {
23 NI cap;
24 NIM_CHAR data[SEQ_DECL_SIZE];
25};
26struct NimStringV2 {
27 NI len;
28 NimStrPayload* p;
29};
30N_LIB_EXPORT N_CDECL(void, nf_init)(void);
31N_NIMCALL(void, NimMain)(void);
32N_LIB_EXPORT N_CDECL(int, nf_add)(int a_p0, int b_p1);
33N_LIB_EXPORT N_CDECL(NCSTRING, nf_greet)(NCSTRING name_p0);
34static N_INLINE(void, appendString)(NimStringV2* dest_p0, NimStringV2 src_p1);
35static N_INLINE(void, copyMem__system_u1726)(void* dest_p0, void* source_p1, NI size_p2);
36static N_INLINE(void, nimCopyMem)(void* dest_p0, void* source_p1, NI size_p2);
37N_LIB_PRIVATE N_NIMCALL(NimStringV2, cstrToNimstr)(NCSTRING str_p0);
38N_LIB_PRIVATE N_NIMCALL(NimStringV2, rawNewString)(NI space_p0);
39N_LIB_PRIVATE N_NOCONV(void*, allocShared0Impl__system_u1757)(NI size_p0);
40static N_INLINE(NCSTRING, nimToCStringConv)(NimStringV2 s_p0);
41N_LIB_PRIVATE N_NOCONV(void, deallocShared)(void* p_p0);
42N_LIB_EXPORT N_CDECL(void, nf_free)(void* p_p0);
43N_LIB_EXPORT N_CDECL(void, nf_mandelbrot)(NU8* buf_p0, size_t bufLen_p1, int w_p2, int h_p3, double cx_p4, double cy_p5, double scale_p6, int maxIter_p7, int y0_p8, int y1_p9);
44N_LIB_PRIVATE N_NIMCALL(void, nimTestErrorFlag)(void);
45N_LIB_PRIVATE N_NIMCALL(void, atmdotdotatsdotdotatsdotdotatsdotdotatsdotdotatsdotdotatsnimatslibatssystemdotnim_Init000)(void);
46N_LIB_PRIVATE N_NIMCALL(void, NimMainModule)(void);
47static const struct {
48 NI cap; NIM_CHAR data[7+1];
49} TM__i7QHfD4JiY9boiF0cHv55ow_2 = { 7 | NIM_STRLIT_FLAG, "Hello, " };
50static const NimStringV2 TM__i7QHfD4JiY9boiF0cHv55ow_3 = {7, (NimStrPayload*)&TM__i7QHfD4JiY9boiF0cHv55ow_2};
51static const struct {
52 NI cap; NIM_CHAR data[11+1];
53} TM__i7QHfD4JiY9boiF0cHv55ow_4 = { 11 | NIM_STRLIT_FLAG, ", from Nim!" };
54static const NimStringV2 TM__i7QHfD4JiY9boiF0cHv55ow_5 = {11, (NimStrPayload*)&TM__i7QHfD4JiY9boiF0cHv55ow_4};
55N_LIB_PRIVATE NIM_BOOL initialized__nimflutter_u2 = NIM_FALSE;
56N_LIB_EXPORT N_CDECL(void, nf_init)(void) {
57 {
58 if (!!(initialized__nimflutter_u2)) goto LA3_;
59 NimMain();
60 initialized__nimflutter_u2 = NIM_TRUE;
61 }
62LA3_: ;
63}
64N_LIB_EXPORT N_CDECL(int, nf_add)(int a_p0, int b_p1) {
65 int result;
66 result = (NI32)(a_p0 + b_p1);
67 return result;
68}
69static N_INLINE(void, nimCopyMem)(void* dest_p0, void* source_p1, NI size_p2) {
70 void* T1_;
71 T1_ = (void*)0;
72 T1_ = memcpy(dest_p0, source_p1, ((size_t) (size_p2)));
73}
74static N_INLINE(void, copyMem__system_u1726)(void* dest_p0, void* source_p1, NI size_p2) {
75 nimCopyMem(dest_p0, source_p1, size_p2);
76}
77static N_INLINE(void, appendString)(NimStringV2* dest_p0, NimStringV2 src_p1) {
78 {
79 if (!(((NI)0) < src_p1.len)) goto LA3_;
80 copyMem__system_u1726(((void*) ((&(*(*dest_p0).p).data[(*dest_p0).len]))), ((void*) ((&(*src_p1.p).data[((NI)0)]))), ((NI)(src_p1.len + ((NI)1))));
81 (*dest_p0).len += src_p1.len;
82 }
83LA3_: ;
84}
85static N_INLINE(NCSTRING, nimToCStringConv)(NimStringV2 s_p0) {
86 NCSTRING result;
87 {
88 if (!(s_p0.len == ((NI)0))) goto LA3_;
89 result = "";
90 }
91 goto LA1_;
92LA3_: ;
93 {
94 result = ((NCSTRING) ((*s_p0.p).data));
95 }
96LA1_: ;
97 return result;
98}
99N_LIB_EXPORT N_CDECL(NCSTRING, nf_greet)(NCSTRING name_p0) {
100 NCSTRING result;
101 NimStringV2 greeting;
102 NimStringV2 colontmpD_;
103 NimStringV2 T1_;
104 NCSTRING buf;
105 void* T2_;
106 result = (NCSTRING)0;
107 greeting.len = 0; greeting.p = NIM_NIL;
108 colontmpD_.len = 0; colontmpD_.p = NIM_NIL;
109 T1_.len = 0; T1_.p = NIM_NIL;
110 colontmpD_ = cstrToNimstr(name_p0);
111 T1_ = rawNewString(colontmpD_.len + 18);
112appendString((&T1_), TM__i7QHfD4JiY9boiF0cHv55ow_3);
113appendString((&T1_), colontmpD_);
114appendString((&T1_), TM__i7QHfD4JiY9boiF0cHv55ow_5);
115 greeting = T1_;
116 T2_ = (void*)0;
117 T2_ = allocShared0Impl__system_u1757(((NI)(greeting.len + ((NI)1))));
118 buf = ((NCSTRING) (T2_));
119 copyMem__system_u1726(((void*) (buf)), ((void*) (nimToCStringConv(greeting))), (greeting.len));
120 result = buf;
121 if (colontmpD_.p && !(colontmpD_.p->cap & NIM_STRLIT_FLAG)) {
122 deallocShared(colontmpD_.p);
123}
124 if (greeting.p && !(greeting.p->cap & NIM_STRLIT_FLAG)) {
125 deallocShared(greeting.p);
126}
127 return result;
128}
129N_LIB_EXPORT N_CDECL(void, nf_free)(void* p_p0) {
130 {
131 if (!!((p_p0 == NIM_NIL))) goto LA3_;
132 deallocShared(p_p0);
133 }
134LA3_: ;
135}
136N_LIB_EXPORT N_CDECL(void, nf_mandelbrot)(NU8* buf_p0, size_t bufLen_p1, int w_p2, int h_p3, double cx_p4, double cy_p5, double scale_p6, int maxIter_p7, int y0_p8, int y1_p9) {
137 NI64 needed;
138 NF aspect;
139 NF invW;
140 NF invH;
141{ {
142 NIM_BOOL T3_;
143 NIM_BOOL T4_;
144 NIM_BOOL T5_;
145 NIM_BOOL T6_;
146 NIM_BOOL T7_;
147 T3_ = (NIM_BOOL)0;
148 T4_ = (NIM_BOOL)0;
149 T5_ = (NIM_BOOL)0;
150 T6_ = (NIM_BOOL)0;
151 T7_ = (NIM_BOOL)0;
152 T7_ = (buf_p0 == ((NU8*) NIM_NIL));
153 if (T7_) goto LA8_;
154 T7_ = (w_p2 <= ((NI32)0));
155LA8_: ;
156 T6_ = T7_;
157 if (T6_) goto LA9_;
158 T6_ = (h_p3 <= ((NI32)0));
159LA9_: ;
160 T5_ = T6_;
161 if (T5_) goto LA10_;
162 T5_ = (maxIter_p7 <= ((NI32)0));
163LA10_: ;
164 T4_ = T5_;
165 if (T4_) goto LA11_;
166 T4_ = (y0_p8 < ((NI32)0));
167LA11_: ;
168 T3_ = T4_;
169 if (T3_) goto LA12_;
170 T3_ = (y1_p9 <= y0_p8);
171LA12_: ;
172 if (!T3_) goto LA13_;
173 goto BeforeRet_;
174 }
175LA13_: ;
176 needed = (NI64)((NI64)(((NI64) ((NI32)(y1_p9 - y0_p8))) * ((NI64) (w_p2))) * IL64(4));
177 {
178 NIM_BOOL T17_;
179 T17_ = (NIM_BOOL)0;
180 T17_ = (needed <= IL64(0));
181 if (T17_) goto LA18_;
182 T17_ = (((NI64) (bufLen_p1)) < needed);
183LA18_: ;
184 if (!T17_) goto LA19_;
185 goto BeforeRet_;
186 }
187LA19_: ;
188 aspect = ((NF)(((NF) (w_p2))) / (NF)(((NF) (h_p3))));
189 invW = ((NF)(1.0) / (NF)(((NF) (w_p2))));
190 invH = ((NF)(1.0) / (NF)(((NF) (h_p3))));
191 {
192 NI32 y;
193 NI32 res;
194 y = (NI32)0;
195 res = y0_p8;
196 {
197 while (1) {
198 NF im;
199 NI32 row;
200 if (!(res < y1_p9)) goto LA23;
201 y = res;
202 im = ((NF)(cy_p5) + (NF)(((NF)(((NF)(((NF)(((NF) (y))) * (NF)(invH))) - (NF)(0.5))) * (NF)(scale_p6))));
203 row = (NI32)((NI32)((NI32)(y - y0_p8) * w_p2) * ((NI32)4));
204 {
205 NI32 x;
206 NI32 res_2;
207 x = (NI32)0;
208 res_2 = ((NI32)0);
209 {
210 while (1) {
211 if (!(res_2 < w_p2)) goto LA26;
212 x = res_2;
213 {
214 NF re;
215 NF zr;
216 NF zi;
217 NF zr2;
218 NF zi2;
219 int i;
220 NI32 idx;
221 NF mag;
222 NF nu;
223 NF t;
224 NF T46_;
225 NF T47_;
226 NF T48_;
227 re = ((NF)(cx_p4) + (NF)(((NF)(((NF)(((NF)(((NF)(((NF) (x))) * (NF)(invW))) - (NF)(0.5))) * (NF)(scale_p6))) * (NF)(aspect))));
228 zr = 0.0;
229 zi = 0.0;
230 zr2 = 0.0;
231 zi2 = 0.0;
232 i = ((int)0);
233 {
234 while (1) {
235 if (!(i < maxIter_p7)) goto LA29;
236 zr2 = ((NF)(zr) * (NF)(zr));
237 zi2 = ((NF)(zi) * (NF)(zi));
238 {
239 if (!(4.0 < ((NF)(zr2) + (NF)(zi2)))) goto LA32_;
240 goto LA28;
241 }
242LA32_: ;
243 zi = ((NF)(((NF)(((NF)(2.0) * (NF)(zr))) * (NF)(zi))) + (NF)(im));
244 zr = ((NF)(((NF)(zr2) - (NF)(zi2))) + (NF)(re));
245 i += ((NI)1);
246 } LA29: ;
247 } LA28: ;
248 idx = (NI32)(row + (NI32)(x * ((NI32)4)));
249 {
250 if (!(maxIter_p7 <= i)) goto LA36_;
251 buf_p0[idx] = ((NU8)0);
252 buf_p0[(NI32)(idx + ((NI32)1))] = ((NU8)0);
253 buf_p0[(NI32)(idx + ((NI32)2))] = ((NU8)0);
254 buf_p0[(NI32)(idx + ((NI32)3))] = ((NU8)255);
255 goto LA27;
256 }
257LA36_: ;
258 mag = sqrt(((NF)(zr2) + (NF)(zi2)));
259 nu = ((NF) (i));
260 {
261 NF T42_;
262 NF T43_;
263 NF T44_;
264 NF T45_;
265 if (!(1.0 < mag)) goto LA40_;
266 T42_ = (NF)0;
267 T42_ = log(mag);
268 T43_ = (NF)0;
269 T43_ = log(2.0);
270 T44_ = (NF)0;
271 T44_ = log(((NF)(T42_) / (NF)(T43_)));
272 T45_ = (NF)0;
273 T45_ = log(2.0);
274 nu = ((NF)(((NF)(((NF) (i))) + (NF)(1.0))) - (NF)(((NF)(T44_) / (NF)(T45_))));
275 }
276LA40_: ;
277 t = ((NF)(nu) / (NF)(((NF) (maxIter_p7))));
278 T46_ = (NF)0;
279 T46_ = sin(((NF)(3.0) + (NF)(((NF)(t) * (NF)(18.0)))));
280 buf_p0[idx] = ((NU8) (((NF)(255.0) * (NF)(((NF)(0.5) + (NF)(((NF)(0.5) * (NF)(T46_))))))));
281 T47_ = (NF)0;
282 T47_ = sin(((NF)(3.6) + (NF)(((NF)(t) * (NF)(18.0)))));
283 buf_p0[(NI32)(idx + ((NI32)1))] = ((NU8) (((NF)(255.0) * (NF)(((NF)(0.5) + (NF)(((NF)(0.5) * (NF)(T47_))))))));
284 T48_ = (NF)0;
285 T48_ = sin(((NF)(4.2) + (NF)(((NF)(t) * (NF)(18.0)))));
286 buf_p0[(NI32)(idx + ((NI32)2))] = ((NU8) (((NF)(255.0) * (NF)(((NF)(0.5) + (NF)(((NF)(0.5) * (NF)(T48_))))))));
287 buf_p0[(NI32)(idx + ((NI32)3))] = ((NU8)255);
288 } LA27: ;
289 res_2 += ((NI)1);
290 } LA26: ;
291 }
292 }
293 res += ((NI)1);
294 } LA23: ;
295 }
296 }
297 }BeforeRet_: ;
298}
299N_LIB_PRIVATE N_CDECL(void, NimDestroyGlobals)(void) {
300}
301
302N_LIB_PRIVATE void PreMainInner(void) {
303}
304
305N_LIB_PRIVATE void PreMain(void) {
306#if 0
307 void (*volatile inner)(void);
308 inner = PreMainInner;
309 atmdotdotatsdotdotatsdotdotatsdotdotatsdotdotatsdotdotatsnimatslibatssystemdotnim_Init000();
310 (*inner)();
311#else
312 atmdotdotatsdotdotatsdotdotatsdotdotatsdotdotatsdotdotatsnimatslibatssystemdotnim_Init000();
313 PreMainInner();
314#endif
315}
316
317N_LIB_PRIVATE N_CDECL(void, NimMainInner)(void) {
318 NimMainModule();
319}
320
321N_CDECL(void, NimMain)(void) {
322#if 0
323 void (*volatile inner)(void);
324 PreMain();
325 inner = NimMainInner;
326 (*inner)();
327#else
328 PreMain();
329 NimMainInner();
330#endif
331}
332
333N_LIB_PRIVATE N_NIMCALL(void, NimMainModule)(void) {
334{
335}
336}
337