| Replace V with Nim 472eb49 nandithebull 21h ago | 1 | /* 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 |
| 20 | typedef struct NimStrPayload NimStrPayload; |
| 21 | typedef struct NimStringV2 NimStringV2; |
| 22 | struct NimStrPayload { |
| 23 | NI cap; |
| 24 | NIM_CHAR data[SEQ_DECL_SIZE]; |
| 25 | }; |
| 26 | struct NimStringV2 { |
| 27 | NI len; |
| 28 | NimStrPayload* p; |
| 29 | }; |
| 30 | N_LIB_EXPORT N_CDECL(void, nf_init)(void); |
| 31 | N_NIMCALL(void, NimMain)(void); |
| 32 | N_LIB_EXPORT N_CDECL(int, nf_add)(int a_p0, int b_p1); |
| 33 | N_LIB_EXPORT N_CDECL(NCSTRING, nf_greet)(NCSTRING name_p0); |
| 34 | static N_INLINE(void, appendString)(NimStringV2* dest_p0, NimStringV2 src_p1); |
| 35 | static N_INLINE(void, copyMem__system_u1726)(void* dest_p0, void* source_p1, NI size_p2); |
| 36 | static N_INLINE(void, nimCopyMem)(void* dest_p0, void* source_p1, NI size_p2); |
| 37 | N_LIB_PRIVATE N_NIMCALL(NimStringV2, cstrToNimstr)(NCSTRING str_p0); |
| 38 | N_LIB_PRIVATE N_NIMCALL(NimStringV2, rawNewString)(NI space_p0); |
| 39 | N_LIB_PRIVATE N_NOCONV(void*, allocShared0Impl__system_u1757)(NI size_p0); |
| 40 | static N_INLINE(NCSTRING, nimToCStringConv)(NimStringV2 s_p0); |
| 41 | N_LIB_PRIVATE N_NOCONV(void, deallocShared)(void* p_p0); |
| 42 | N_LIB_EXPORT N_CDECL(void, nf_free)(void* p_p0); |
| 43 | N_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); |
| 44 | N_LIB_PRIVATE N_NIMCALL(void, nimTestErrorFlag)(void); |
| 45 | N_LIB_PRIVATE N_NIMCALL(void, atmdotdotatsdotdotatsdotdotatsdotdotatsdotdotatsdotdotatsnimatslibatssystemdotnim_Init000)(void); |
| 46 | N_LIB_PRIVATE N_NIMCALL(void, NimMainModule)(void); |
| 47 | static const struct { |
| 48 | NI cap; NIM_CHAR data[7+1]; |
| 49 | } TM__i7QHfD4JiY9boiF0cHv55ow_2 = { 7 | NIM_STRLIT_FLAG, "Hello, " }; |
| 50 | static const NimStringV2 TM__i7QHfD4JiY9boiF0cHv55ow_3 = {7, (NimStrPayload*)&TM__i7QHfD4JiY9boiF0cHv55ow_2}; |
| 51 | static const struct { |
| 52 | NI cap; NIM_CHAR data[11+1]; |
| 53 | } TM__i7QHfD4JiY9boiF0cHv55ow_4 = { 11 | NIM_STRLIT_FLAG, ", from Nim!" }; |
| 54 | static const NimStringV2 TM__i7QHfD4JiY9boiF0cHv55ow_5 = {11, (NimStrPayload*)&TM__i7QHfD4JiY9boiF0cHv55ow_4}; |
| 55 | N_LIB_PRIVATE NIM_BOOL initialized__nimflutter_u2 = NIM_FALSE; |
| 56 | N_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 | } |
| 62 | LA3_: ; |
| 63 | } |
| 64 | N_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 | } |
| 69 | static 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 | } |
| 74 | static N_INLINE(void, copyMem__system_u1726)(void* dest_p0, void* source_p1, NI size_p2) { |
| 75 | nimCopyMem(dest_p0, source_p1, size_p2); |
| 76 | } |
| 77 | static 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 | } |
| 83 | LA3_: ; |
| 84 | } |
| 85 | static 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_; |
| 92 | LA3_: ; |
| 93 | { |
| 94 | result = ((NCSTRING) ((*s_p0.p).data)); |
| 95 | } |
| 96 | LA1_: ; |
| 97 | return result; |
| 98 | } |
| 99 | N_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); |
| 112 | appendString((&T1_), TM__i7QHfD4JiY9boiF0cHv55ow_3); |
| 113 | appendString((&T1_), colontmpD_); |
| 114 | appendString((&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 | } |
| 129 | N_LIB_EXPORT N_CDECL(void, nf_free)(void* p_p0) { |
| 130 | { |
| 131 | if (!!((p_p0 == NIM_NIL))) goto LA3_; |
| 132 | deallocShared(p_p0); |
| 133 | } |
| 134 | LA3_: ; |
| 135 | } |
| 136 | N_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)); |
| 155 | LA8_: ; |
| 156 | T6_ = T7_; |
| 157 | if (T6_) goto LA9_; |
| 158 | T6_ = (h_p3 <= ((NI32)0)); |
| 159 | LA9_: ; |
| 160 | T5_ = T6_; |
| 161 | if (T5_) goto LA10_; |
| 162 | T5_ = (maxIter_p7 <= ((NI32)0)); |
| 163 | LA10_: ; |
| 164 | T4_ = T5_; |
| 165 | if (T4_) goto LA11_; |
| 166 | T4_ = (y0_p8 < ((NI32)0)); |
| 167 | LA11_: ; |
| 168 | T3_ = T4_; |
| 169 | if (T3_) goto LA12_; |
| 170 | T3_ = (y1_p9 <= y0_p8); |
| 171 | LA12_: ; |
| 172 | if (!T3_) goto LA13_; |
| 173 | goto BeforeRet_; |
| 174 | } |
| 175 | LA13_: ; |
| 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); |
| 183 | LA18_: ; |
| 184 | if (!T17_) goto LA19_; |
| 185 | goto BeforeRet_; |
| 186 | } |
| 187 | LA19_: ; |
| 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 | } |
| 242 | LA32_: ; |
| 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 | } |
| 257 | LA36_: ; |
| 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 | } |
| 276 | LA40_: ; |
| 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 | } |
| 299 | N_LIB_PRIVATE N_CDECL(void, NimDestroyGlobals)(void) { |
| 300 | } |
| 301 | |
| 302 | N_LIB_PRIVATE void PreMainInner(void) { |
| 303 | } |
| 304 | |
| 305 | N_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 | |
| 317 | N_LIB_PRIVATE N_CDECL(void, NimMainInner)(void) { |
| 318 | NimMainModule(); |
| 319 | } |
| 320 | |
| 321 | N_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 | |
| 333 | N_LIB_PRIVATE N_NIMCALL(void, NimMainModule)(void) { |
| 334 | { |
| 335 | } |
| 336 | } |
| 337 | |