-
Notifications
You must be signed in to change notification settings - Fork 0
/
forkmon.c
2272 lines (2272 loc) · 91.2 KB
/
forkmon.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Generated by Nelua 0.2.0-dev */
/* Compile command: gcc -x c "forkmon.c" -x none -pipe -fwrapv -fno-strict-aliasing -g -ldl -lm -o "forkmon" */
/* Compile hash: 2V1eUQLQzq473NfAwRMge5jig61F */
/* ------------------------------ DIRECTIVES -------------------------------- */
/* Disable some warnings that the generated code can trigger. */
#if defined(__clang__) && __clang_major__ >= 3
#pragma clang diagnostic ignored "-Wtype-limits"
#pragma clang diagnostic ignored "-Wwrite-strings"
#pragma clang diagnostic ignored "-Wunused"
#pragma clang diagnostic ignored "-Wunused-parameter"
#pragma clang diagnostic ignored "-Wmissing-field-initializers"
#pragma clang diagnostic ignored "-Wparentheses-equality"
#pragma clang diagnostic ignored "-Wtautological-compare"
#ifndef __cplusplus
#pragma clang diagnostic ignored "-Wmissing-braces"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#pragma clang diagnostic error "-Wimplicit-function-declaration"
#pragma clang diagnostic error "-Wimplicit-int"
#else
#pragma clang diagnostic ignored "-Wnarrowing"
#endif
#elif defined(__GNUC__) && __GNUC__ >= 5
#pragma GCC diagnostic ignored "-Wtype-limits"
#pragma GCC diagnostic ignored "-Wwrite-strings"
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wunused-value"
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wunused-function"
#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
#ifndef __cplusplus
#pragma GCC diagnostic ignored "-Wmissing-braces"
#pragma GCC diagnostic ignored "-Wincompatible-pointer-types"
#pragma GCC diagnostic ignored "-Wdiscarded-qualifiers"
#pragma GCC diagnostic error "-Wimplicit-function-declaration"
#pragma GCC diagnostic error "-Wimplicit-int"
#else
#pragma GCC diagnostic ignored "-Wnarrowing"
#endif
#endif
#if defined(_WIN32) && !defined(_CRT_SECURE_NO_WARNINGS)
#define _CRT_SECURE_NO_WARNINGS
#endif
#define _GNU_SOURCE
#include <dlfcn.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <time.h>
#include <signal.h>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/inotify.h>
#include <fcntl.h>
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include <string.h>
/* Macro used to force inlining a function. */
#ifdef __GNUC__
#define NELUA_INLINE __attribute__((always_inline)) inline
#elif defined(_MSC_VER)
#define NELUA_INLINE __forceinline
#elif __STDC_VERSION__ >= 199901L
#define NELUA_INLINE inline
#else
#define NELUA_INLINE
#endif
/* Macro used for branch prediction. */
#if defined(__GNUC__) || defined(__clang__)
#define NELUA_UNLIKELY(x) __builtin_expect(x, 0)
#else
#define NELUA_UNLIKELY(x) (x)
#endif
#define NELUA_NIL (nlniltype){}
/* Macro used for branch prediction. */
#if defined(__GNUC__) || defined(__clang__)
#define NELUA_LIKELY(x) __builtin_expect(x, 1)
#else
#define NELUA_LIKELY(x) (x)
#endif
/* Macro used to import/export extern C functions. */
#ifdef __cplusplus
#define NELUA_EXTERN extern "C"
#else
#define NELUA_EXTERN extern
#endif
/* Macro used to generate traceback on aborts when sanitizing. */
#if defined(__clang__) && defined(__has_feature)
#if __has_feature(undefined_behavior_sanitizer)
#define NELUA_UBSAN_UNREACHABLE __builtin_unreachable
#endif
#elif defined(__gnu_linux__) && defined(__GNUC__) && __GNUC__ >= 5
NELUA_EXTERN void __ubsan_handle_builtin_unreachable(void*) __attribute__((weak));
#define NELUA_UBSAN_UNREACHABLE() {if(&__ubsan_handle_builtin_unreachable) __builtin_unreachable();}
#endif
#ifndef NELUA_UBSAN_UNREACHABLE
#define NELUA_UBSAN_UNREACHABLE()
#endif
/* Macro used to specify a function that never returns. */
#if __STDC_VERSION__ >= 201112L
#define NELUA_NORETURN _Noreturn
#elif defined(__GNUC__)
#define NELUA_NORETURN __attribute__((noreturn))
#elif defined(_MSC_VER)
#define NELUA_NORETURN __declspec(noreturn)
#else
#define NELUA_NORETURN
#endif
/* Macro used sign that a type punning cast may alias (related to strict aliasing). */
#ifdef __GNUC__
#define NELUA_MAYALIAS __attribute__((may_alias))
#else
#define NELUA_MAYALIAS
#endif
/* Macro used to force not inlining a function. */
#ifdef __GNUC__
#define NELUA_NOINLINE __attribute__((noinline))
#elif defined(_MSC_VER)
#define NELUA_NOINLINE __declspec(noinline)
#else
#define NELUA_NOINLINE
#endif
#include <stdarg.h>
/* Macro used to export C functions. */
#ifdef _WIN32
#define NELUA_CEXPORT NELUA_EXTERN __declspec(dllexport)
#elif defined(__GNUC__)
#define NELUA_CEXPORT NELUA_EXTERN __attribute__((visibility("default")))
#else
#define NELUA_CEXPORT NELUA_EXTERN
#endif
/* ------------------------------ DECLARATIONS ------------------------------ */
typedef struct nlstring nlstring;
typedef uint8_t* nluint8_arr0_ptr;
struct nlstring {
nluint8_arr0_ptr data;
uintptr_t size;
};
static nlstring sys_Colors_Yellow = {(uint8_t*)"\033[33m", 5};
static nlstring sys_Colors_Red = {(uint8_t*)"\033[31m", 5};
static nlstring sys_Colors_Reset = {(uint8_t*)"\033[0m", 4};
static void sys_usleep(uint64_t ms);
typedef struct timespec timespec;
typedef timespec* timespec_ptr;
static uint64_t sys_uticks(void);
static int sys_killwait(int pid, int sig);
typedef int* nlcint_ptr;
static bool sys_filexists(const char* path);
static nlstring sys_resolvpath(char* path, char* buf, int len);
static NELUA_INLINE void nelua_memory_copy(void* dest, void* src, uintptr_t n);
static NELUA_INLINE void nelua_memory_zero(void* dest, uintptr_t n);
static NELUA_INLINE int32_t nelua_memory_compare(void* a, void* b, uintptr_t n);
static NELUA_INLINE bool nelua_memory_equals(void* a, void* b, uintptr_t n);
static NELUA_INLINE void* nelua_memory_scan(void* src, uint8_t x, uintptr_t n);
static void* nelua_memory_find(void* haystack, uintptr_t haystacksize, void* needle, uintptr_t needlesize);
typedef uint8_t* nluint8_ptr;
typedef struct nelua_span_uint8_ nelua_span_uint8_;
typedef nelua_span_uint8_* nelua_span_uint8__ptr;
struct nelua_span_uint8_ {
nluint8_arr0_ptr data;
uintptr_t size;
};
static NELUA_INLINE bool nelua_span_uint8__empty(nelua_span_uint8__ptr self);
static NELUA_INLINE nluint8_ptr nelua_span_uint8____atindex(nelua_span_uint8__ptr self, uintptr_t i);
typedef uintptr_t* nlusize_ptr;
typedef struct nelua_span_usize_ nelua_span_usize_;
typedef nelua_span_usize_* nelua_span_usize__ptr;
typedef uintptr_t* nlusize_arr0_ptr;
struct nelua_span_usize_ {
nlusize_arr0_ptr data;
uintptr_t size;
};
static NELUA_INLINE nlusize_ptr nelua_span_usize____atindex(nelua_span_usize__ptr self, uintptr_t i);
typedef struct nelua_hashmapnode_string__boolean_ nelua_hashmapnode_string__boolean_;
typedef nelua_hashmapnode_string__boolean_* nelua_hashmapnode_string__boolean__ptr;
struct nelua_hashmapnode_string__boolean_ {
nlstring key;
bool value;
bool filled;
uintptr_t next;
};
typedef struct nelua_span_hashmapnode_string__boolean__ nelua_span_hashmapnode_string__boolean__;
typedef nelua_span_hashmapnode_string__boolean__* nelua_span_hashmapnode_string__boolean___ptr;
typedef nelua_hashmapnode_string__boolean_* nelua_hashmapnode_string__boolean__arr0_ptr;
struct nelua_span_hashmapnode_string__boolean__ {
nelua_hashmapnode_string__boolean__arr0_ptr data;
uintptr_t size;
};
static NELUA_INLINE nelua_hashmapnode_string__boolean__ptr nelua_span_hashmapnode_string__boolean_____atindex(nelua_span_hashmapnode_string__boolean___ptr self, uintptr_t i);
typedef struct nlniltype {} nlniltype;
typedef struct nlniltype nltype;
static NELUA_INLINE void nelua_memory_spanset_1(nelua_span_usize_ dest, uintptr_t x);
typedef struct nelua_GeneralAllocator nelua_GeneralAllocator;
struct nelua_GeneralAllocator {};
static nelua_GeneralAllocator nelua_general_allocator;
typedef nelua_GeneralAllocator* nelua_GeneralAllocator_ptr;
static NELUA_INLINE void* nelua_GeneralAllocator_alloc(nelua_GeneralAllocator_ptr self, uintptr_t size);
static NELUA_INLINE void* nelua_GeneralAllocator_alloc0(nelua_GeneralAllocator_ptr self, uintptr_t size);
static NELUA_INLINE void nelua_GeneralAllocator_dealloc(nelua_GeneralAllocator_ptr self, void* p);
static NELUA_INLINE void* nelua_GeneralAllocator_realloc(nelua_GeneralAllocator_ptr self, void* p, uintptr_t newsize, uintptr_t oldsize);
static void* nelua_GeneralAllocator_xalloc(nelua_GeneralAllocator_ptr self, uintptr_t size);
static NELUA_INLINE void nelua_write_stderr(const char* msg, uintptr_t len, bool flush);
static NELUA_NORETURN void nelua_abort(void);
static NELUA_NORETURN void nelua_panic_string(nlstring s);
static void* nelua_GeneralAllocator_realloc0(nelua_GeneralAllocator_ptr self, void* p, uintptr_t newsize, uintptr_t oldsize);
static nelua_span_usize_ nelua_GeneralAllocator_spanalloc_3(nelua_GeneralAllocator_ptr self, nlniltype T, uintptr_t size);
static nelua_span_uint8_ nelua_GeneralAllocator_spanalloc0_1(nelua_GeneralAllocator_ptr self, nlniltype T, uintptr_t size);
static nelua_span_hashmapnode_string__boolean__ nelua_GeneralAllocator_spanalloc0_2(nelua_GeneralAllocator_ptr self, nlniltype T, uintptr_t size);
static void nelua_GeneralAllocator_spandealloc_1(nelua_GeneralAllocator_ptr self, nelua_span_uint8_ s);
static nelua_span_usize_ nelua_GeneralAllocator_spanrealloc_3(nelua_GeneralAllocator_ptr self, nelua_span_usize_ s, uintptr_t size);
static nelua_span_usize_ nelua_GeneralAllocator_xspanrealloc_3(nelua_GeneralAllocator_ptr self, nelua_span_usize_ s, uintptr_t size);
static nelua_span_uint8_ nelua_GeneralAllocator_spanrealloc0_1(nelua_GeneralAllocator_ptr self, nelua_span_uint8_ s, uintptr_t size);
static nelua_span_hashmapnode_string__boolean__ nelua_GeneralAllocator_spanrealloc0_2(nelua_GeneralAllocator_ptr self, nelua_span_hashmapnode_string__boolean__ s, uintptr_t size);
static nelua_span_hashmapnode_string__boolean__ nelua_GeneralAllocator_xspanrealloc0_1(nelua_GeneralAllocator_ptr self, nelua_span_hashmapnode_string__boolean__ s, uintptr_t size);
static NELUA_INLINE bool nelua_strchar_1_isalpha(uint8_t c);
static NELUA_INLINE bool nelua_strchar_1_islower(uint8_t c);
static NELUA_INLINE bool nelua_strchar_1_isupper(uint8_t c);
static NELUA_INLINE bool nelua_strchar_1_isdigit(uint8_t c);
static NELUA_INLINE bool nelua_strchar_1_isxdigit(uint8_t c);
static NELUA_INLINE bool nelua_strchar_1_iscntrl(uint8_t c);
static NELUA_INLINE bool nelua_strchar_1_isgraph(uint8_t c);
static NELUA_INLINE bool nelua_strchar_1_isspace(uint8_t c);
static NELUA_INLINE bool nelua_strchar_1_isalnum(uint8_t c);
static NELUA_INLINE bool nelua_strchar_1_ispunct(uint8_t c);
static NELUA_INLINE uint8_t nelua_strchar_1_getbasedigit(uint8_t c);
typedef struct NELUA_MAYALIAS nluint8_arr32 {uint8_t v[32];} nluint8_arr32;
typedef union NELUA_MAYALIAS nluint8_arr32_cast {nluint8_arr32 a; uint8_t p[32];} nluint8_arr32_cast;
typedef nluint8_arr32* nluint8_arr32_ptr;
static uintptr_t nelua_scanformat(nluint8_arr0_ptr strfmt, nluint8_arr32_ptr form);
static void nelua_assert_line_1(bool cond, nlstring msg);
static void nelua_assert_line_2(bool cond, nlstring msg);
typedef struct nelua_stringbuilderT nelua_stringbuilderT;
typedef nelua_stringbuilderT* nelua_stringbuilderT_ptr;
struct nelua_stringbuilderT {
nelua_span_uint8_ data;
uintptr_t size;
nelua_GeneralAllocator allocator;
};
static void nelua_stringbuilderT_destroy(nelua_stringbuilderT_ptr self);
static bool nelua_stringbuilderT_grow(nelua_stringbuilderT_ptr self, uintptr_t newsize);
static nelua_span_uint8_ nelua_stringbuilderT_prepare(nelua_stringbuilderT_ptr self, uintptr_t n);
static void nelua_stringbuilderT_commit(nelua_stringbuilderT_ptr self, uintptr_t n);
static bool nelua_stringbuilderT_writebyte_1(nelua_stringbuilderT_ptr self, uint8_t c, nlniltype n);
typedef struct nlmulret_nlboolean_nlisize {
bool r1;
intptr_t r2;
} nlmulret_nlboolean_nlisize;
static nlmulret_nlboolean_nlisize nelua_formatarg_2(nelua_stringbuilderT_ptr self, uint8_t c, nluint8_arr32_ptr form, nlstring arg1);
static void nelua_assert_line_3(bool cond, nlstring msg);
static void nelua_assert_line_4(bool cond, nlstring msg);
typedef struct nlmulret_nlboolean_nlusize {
bool r1;
uintptr_t r2;
} nlmulret_nlboolean_nlusize;
static nlmulret_nlboolean_nlusize nelua_stringbuilderT_writef_2(nelua_stringbuilderT_ptr self, nlstring fmt, nlstring __arg1);
static void nelua_assert_line_5(bool cond, nlstring msg);
static nlmulret_nlboolean_nlusize nelua_stringbuilderT_writef_3(nelua_stringbuilderT_ptr self, nlstring fmt);
static void nelua_assert_line_6(bool cond, nlstring msg);
static nlstring nelua_stringbuilderT_view(nelua_stringbuilderT_ptr self);
typedef nlstring* nlstring_ptr;
static void nelua_nlstring_destroy(nlstring_ptr self);
static nlstring nelua_nlstring_copy(nlstring s);
static NELUA_INLINE intptr_t nelua_nlstring___len(nlstring a);
static bool nelua_nlstring___eq(nlstring a, nlstring b);
typedef struct nelua_StrPattCapture nelua_StrPattCapture;
typedef nelua_StrPattCapture* nelua_StrPattCapture_ptr;
struct nelua_StrPattCapture {
intptr_t init;
intptr_t len;
};
static bool nelua_StrPattCapture_is_unfinished(nelua_StrPattCapture_ptr self);
static bool nelua_StrPattCapture_is_position(nelua_StrPattCapture_ptr self);
static bool nelua_match_has_pattern_specials(nlstring pattern);
static bool nelua_match_has_pattern_anchor(nlstring pattern);
typedef struct nelua_StrPatt_1 nelua_StrPatt_1;
struct nelua_StrPatt_1 {
nlstring source;
nlstring pattern;
intptr_t depth;
intptr_t numcaptures;
nelua_StrPattCapture capture[32];
bool plain;
bool anchor;
};
static nelua_StrPatt_1 nelua_StrPatt_1_create(nlstring source, nlstring pattern, bool plain);
typedef nelua_StrPatt_1* nelua_StrPatt_1_ptr;
static void nelua_StrPatt_1_reset_captures(nelua_StrPatt_1_ptr self);
typedef struct NELUA_MAYALIAS nelua_StrPattCapture_arr32 {nelua_StrPattCapture v[32];} nelua_StrPattCapture_arr32;
typedef union NELUA_MAYALIAS nelua_StrPattCapture_arr32_cast {nelua_StrPattCapture_arr32 a; nelua_StrPattCapture p[32];} nelua_StrPattCapture_arr32_cast;
typedef struct nlmulret_nlboolean_nlstring_nelua_StrPattCapture {
bool r1;
nlstring r2;
nelua_StrPattCapture r3;
} nlmulret_nlboolean_nlstring_nelua_StrPattCapture;
static nlmulret_nlboolean_nlstring_nelua_StrPattCapture nelua_StrPatt_1_get_capture(nelua_StrPatt_1_ptr self, intptr_t i);
static intptr_t nelua_StrPatt_1__match(nelua_StrPatt_1_ptr ms, intptr_t s, intptr_t p);
static bool nelua_match_class(uint8_t c, uint8_t cl);
static intptr_t nelua_match_class_end(nelua_StrPatt_1_ptr ms_1, intptr_t p_1);
static void nelua_assert_line_7(bool cond, nlstring msg);
static void nelua_assert_line_8(bool cond, nlstring msg);
static bool nelua_match_bracket_class(nelua_StrPatt_1_ptr ms_2, uint8_t c, intptr_t p_2, intptr_t ep);
static bool nelua_match_single(nelua_StrPatt_1_ptr ms_3, intptr_t s_1, intptr_t p_3, intptr_t ep);
static intptr_t nelua_match_balance(nelua_StrPatt_1_ptr ms_4, intptr_t s_2, intptr_t p_4);
static void nelua_assert_line_9(bool cond, nlstring msg);
static intptr_t nelua_match_max_expand(nelua_StrPatt_1_ptr ms_5, intptr_t s_3, intptr_t p_5, intptr_t ep);
static intptr_t nelua_match_min_expand(nelua_StrPatt_1_ptr ms_6, intptr_t s_4, intptr_t p_6, intptr_t ep);
static intptr_t nelua_match_start_capture(nelua_StrPatt_1_ptr ms_7, intptr_t s_5, intptr_t p_7, intptr_t what);
static void nelua_assert_line_10(bool cond, nlstring msg);
static intptr_t nelua_match_end_capture(nelua_StrPatt_1_ptr ms_8, intptr_t s_6, intptr_t p_8);
static void nelua_assert_line_11(bool cond, nlstring msg);
static intptr_t nelua_match_capture(nelua_StrPatt_1_ptr ms_9, intptr_t s_7, intptr_t l);
static void nelua_assert_line_12(bool cond, nlstring msg);
static void nelua_assert_line_13(bool cond, nlstring msg);
static void nelua_assert_line_14(bool cond, nlstring msg);
typedef struct nlmulret_nlisize_nlisize {
intptr_t r1;
intptr_t r2;
} nlmulret_nlisize_nlisize;
static nlmulret_nlisize_nlisize nelua_StrPatt_1_match(nelua_StrPatt_1_ptr ms, intptr_t s);
static nlmulret_nlisize_nlisize nelua_nlstring_find_1(nlstring s, nlstring pattern, nlniltype init, nlniltype plain);
typedef struct nelua_span_string_ nelua_span_string_;
typedef nlstring* nlstring_arr0_ptr;
struct nelua_span_string_ {
nlstring_arr0_ptr data;
uintptr_t size;
};
typedef struct nlmulret_nlboolean_nlstring_nelua_span_string_ {
bool r1;
nlstring r2;
nelua_span_string_ r3;
} nlmulret_nlboolean_nlstring_nelua_span_string_;
typedef struct nelua_GMatchState nelua_GMatchState;
typedef nelua_GMatchState* nelua_GMatchState_ptr;
typedef nlmulret_nlboolean_nlstring_nelua_span_string_ (*function_AUXgMx1BRVnTYeGb)(nelua_GMatchState_ptr, nlstring);
struct nelua_GMatchState {
nelua_StrPatt_1 ms;
intptr_t init;
nlstring captures[8];
};
typedef struct nlmulret_function_AUXgMx1BRVnTYeGb_nelua_GMatchState_nlstring {
function_AUXgMx1BRVnTYeGb r1;
nelua_GMatchState r2;
nlstring r3;
} nlmulret_function_AUXgMx1BRVnTYeGb_nelua_GMatchState_nlstring;
static nlmulret_function_AUXgMx1BRVnTYeGb_nelua_GMatchState_nlstring nelua_nlstring_gmatchview_1(nlstring s, nlstring pattern, nlniltype init);
static nlmulret_nlboolean_nlstring_nelua_span_string_ nelua_gmatch_next(nelua_GMatchState_ptr state, nlstring it);
static void nelua_assert_line_15(bool cond, nlstring msg);
static void nelua_assert_line_16(bool cond, nlstring msg);
static void nelua_assert_line_17(bool cond, nlstring msg);
typedef struct NELUA_MAYALIAS nlstring_arr8 {nlstring v[8];} nlstring_arr8;
typedef union NELUA_MAYALIAS nlstring_arr8_cast {nlstring_arr8 a; nlstring p[8];} nlstring_arr8_cast;
typedef struct nlmulret_nlboolean_nlint64 {
bool r1;
int64_t r2;
} nlmulret_nlboolean_nlint64;
static nlmulret_nlboolean_nlint64 nelua_strconv_1_str2int(nlstring s, uint64_t base);
static void nelua_assert_line_18(bool cond, nlstring msg);
static nlstring nelua_strconv_1_int2str_1(uintptr_t x, nlniltype base);
typedef struct NELUA_MAYALIAS nluint8_arr48 {uint8_t v[48];} nluint8_arr48;
typedef union NELUA_MAYALIAS nluint8_arr48_cast {nluint8_arr48 a; uint8_t p[48];} nluint8_arr48_cast;
static nlstring nelua_tostring_1(uint64_t x);
static int64_t nelua_tointeger_1(char* x, nlniltype base);
static NELUA_INLINE nlstring nelua_cstring2string(const char* s);
static void nelua_assert_line_19(bool cond, nlstring msg);
static NELUA_INLINE uintptr_t nelua_lhash(nluint8_arr0_ptr data, uintptr_t len, uintptr_t seed, uintptr_t step);
static NELUA_INLINE uintptr_t nelua_hash_long(nelua_span_uint8_ data);
static uintptr_t nelua_hash_hash_1(nlstring v);
static NELUA_INLINE uintptr_t nelua_ceilidiv(uintptr_t x, uintptr_t y);
static NELUA_INLINE uintptr_t nelua_hashmod(uintptr_t h, uintptr_t n);
static NELUA_INLINE uintptr_t nelua_roundpow2(uintptr_t n);
typedef struct nlmulret_nlusize_nlusize_nlusize {
uintptr_t r1;
uintptr_t r2;
uintptr_t r3;
} nlmulret_nlusize_nlusize_nlusize;
typedef struct nelua_hashmap_string__boolean_ nelua_hashmap_string__boolean_;
typedef nelua_hashmap_string__boolean_* nelua_hashmap_string__boolean__ptr;
struct nelua_hashmap_string__boolean_ {
nelua_span_usize_ buckets;
nelua_span_hashmapnode_string__boolean__ nodes;
uintptr_t size;
uintptr_t free_index;
nelua_GeneralAllocator allocator;
};
static NELUA_INLINE nlmulret_nlusize_nlusize_nlusize nelua_hashmap_string__boolean___find(nelua_hashmap_string__boolean__ptr self, nlstring key);
static NELUA_NOINLINE void nelua_hashmap_string__boolean__rehash(nelua_hashmap_string__boolean__ptr self, uintptr_t bucket_count);
static uintptr_t nelua_hashmap_string__boolean___at(nelua_hashmap_string__boolean__ptr self, nlstring key);
typedef bool* nlboolean_ptr;
static nlboolean_ptr nelua_hashmap_string__boolean____atindex(nelua_hashmap_string__boolean__ptr self, nlstring key);
static nlboolean_ptr nelua_hashmap_string__boolean__peek(nelua_hashmap_string__boolean__ptr self, nlstring key);
typedef FILE* FILE_ptr;
typedef struct nelua_filestream nelua_filestream;
typedef nelua_filestream* nelua_filestream_ptr;
typedef struct nelua_FStream nelua_FStream;
typedef nelua_FStream* nelua_FStream_ptr;
struct nelua_filestream {
nelua_FStream_ptr fs;
};
typedef int (*function_FhC6yq19frq2vAJH)(FILE_ptr);
struct nelua_FStream {
FILE_ptr fp;
function_FhC6yq19frq2vAJH closef;
};
static NELUA_INLINE FILE_ptr nelua_filestream__getfp(nelua_filestream_ptr self);
typedef struct nlmulret_nlstring_nlint64 {
nlstring r1;
int64_t r2;
} nlmulret_nlstring_nlint64;
static nlmulret_nlstring_nlint64 nelua_geterrno(void);
typedef struct nlmulret_nlboolean_nlstring_nlint64 {
bool r1;
nlstring r2;
int64_t r3;
} nlmulret_nlboolean_nlstring_nlint64;
static nlmulret_nlboolean_nlstring_nlint64 nelua_filestream_flush(nelua_filestream_ptr self);
static nlmulret_nlboolean_nlstring_nlint64 nelua_filestream_write_1(nelua_filestream_ptr self, nlstring __arg1);
static nlmulret_nlboolean_nlstring_nlint64 nelua_filestream_writef_1(nelua_filestream_ptr self, nlstring fmt, nlstring __arg1);
static nlmulret_nlboolean_nlstring_nlint64 nelua_filestream_writef_2(nelua_filestream_ptr self, nlstring fmt);
static nelua_FStream nelua_stderrfs;
static nelua_filestream nelua_io_stderr;
static nltype nelua_require_io(nlniltype modname);
typedef va_list* nlcvalist_ptr;
static NELUA_INLINE int nelua_C_va_arg_1(nlcvalist_ptr ap, nlniltype T);
static uint64_t forkmon_restart_delay = 50000U;
static uint64_t forkmon_ignore_delay = 200000U;
static bool forkmon_initialized = false;
static bool forkmon_handling_signal = false;
static bool forkmon_quiet = false;
static bool forkmon_no_colors = false;
static bool forkmon_preload_disabled = false;
static int forkmon_parent_inotify_fd = -1;
static int forkmon_child_pid = 0;
static int forkmon_root_pid;
static uint64_t forkmon_last_restart_ticks;
static int forkmon_filter_patts_count = 0;
typedef struct NELUA_MAYALIAS nlstring_arr32 {nlstring v[32];} nlstring_arr32;
typedef union NELUA_MAYALIAS nlstring_arr32_cast {nlstring_arr32 a; nlstring p[32];} nlstring_arr32_cast;
static nlstring_arr32 forkmon_filter_patts;
static nelua_hashmap_string__boolean_ forkmon_tracked_files;
typedef FILE_ptr (*forkmon_FopenFunc)(char*, char*);
static forkmon_FopenFunc forkmon_orig_fopen;
static forkmon_FopenFunc forkmon_orig_fopen64;
typedef int (*forkmon_OpenFunc)(char*, int, int);
static forkmon_OpenFunc forkmon_orig_open;
static void forkmon_killapp(int code);
static void forkmon_logf_1(nlstring fmt, nlstring __arg1);
static void forkmon_errorf_1(nlstring fmt);
static void forkmon_assertkill(bool cond, nlstring msg);
static bool forkmon_filter_filename(nlstring filename);
typedef struct nlmulret_nlcint_nlcint {
int r1;
int r2;
} nlmulret_nlcint_nlcint;
static nlmulret_nlcint_nlcint forkmon_inotify_init_watch(char* filename, int mask);
static char nelua_strlit_1[85] = "failed to initialize inotify, maybe increase \"user.max_inotify_instances\" in sysctl?";
static bool forkmon_monitor_file(nlstring filename);
static NELUA_INLINE char* nelua_string2cstring(nlstring s);
typedef struct NELUA_MAYALIAS nluint8_arr1024 {uint8_t v[1024];} nluint8_arr1024;
typedef union NELUA_MAYALIAS nluint8_arr1024_cast {nluint8_arr1024 a; uint8_t p[1024];} nluint8_arr1024_cast;
typedef struct inotify_event inotify_event;
typedef inotify_event* inotify_event_ptr;
static bool forkmon_track_file_open(char* name);
typedef struct NELUA_MAYALIAS nlcchar_arr4097 {char v[4097];} nlcchar_arr4097;
typedef union NELUA_MAYALIAS nlcchar_arr4097_cast {nlcchar_arr4097 a; char p[4097];} nlcchar_arr4097_cast;
static void forkmon_signal_handler(int signum);
static void forkmon_parse_env(void);
static char nelua_strlit_2[102] = "the environment variable FORKMON_FILTER is not set, please set one (example FORKMON_FILTER=\"%.lua$\")\n";
NELUA_CEXPORT FILE_ptr fopen(const char* __restrict filename, const char* __restrict mode);
NELUA_CEXPORT FILE_ptr fopen64(const char* __restrict filename, const char* __restrict mode);
NELUA_CEXPORT int open(const char* __restrict path, int flags, ...);
void __attribute__((constructor)) setup(void);
typedef char** nlcstring_ptr;
static int nelua_main(int argc, char** argv);
/* ------------------------------ DEFINITIONS ------------------------------- */
void sys_usleep(uint64_t ms) {
timespec ts = {0};
ts.tv_sec = (long)(ms / 1000000);
ts.tv_nsec = (long)((ms % 1000000) * 1000);
nanosleep((&ts), ((timespec_ptr)NULL));
}
uint64_t sys_uticks(void) {
timespec ts = {0};
clock_gettime(1, (&ts));
return (uint64_t)((ts.tv_sec * 1000000) + (ts.tv_nsec / 1000));
}
int sys_killwait(int pid, int sig) {
kill(pid, sig);
return waitpid(pid, (nlcint_ptr)NULL, 0);
}
bool sys_filexists(const char* path) {
return (access(path, F_OK) == 0);
}
nlstring sys_resolvpath(char* path, char* buf, int len) {
if(((((intptr_t)strlen(path)) < len) && (realpath(path, buf) != NULL))) {
return (nlstring){((nluint8_arr0_ptr)buf), (uintptr_t)((intptr_t)strlen(buf))};
}
return (nlstring){0};
}
void nelua_memory_copy(void* dest, void* src, uintptr_t n) {
if(NELUA_UNLIKELY((n == 0))) {
return;
}
memcpy(dest, src, (size_t)n);
}
void nelua_memory_zero(void* dest, uintptr_t n) {
if(NELUA_UNLIKELY((n == 0))) {
return;
}
memset(dest, 0, (size_t)n);
}
int32_t nelua_memory_compare(void* a, void* b, uintptr_t n) {
if(NELUA_UNLIKELY((n == 0))) {
return 0;
}
return (int32_t)memcmp(a, b, (size_t)n);
}
bool nelua_memory_equals(void* a, void* b, uintptr_t n) {
if(NELUA_UNLIKELY((n == 0))) {
return true;
}
return (memcmp(a, b, (size_t)n) == 0);
}
void* nelua_memory_scan(void* src, uint8_t x, uintptr_t n) {
if(NELUA_UNLIKELY((n == 0))) {
return (void*)NULL;
}
return memchr(src, (int)x, (size_t)n);
}
void* nelua_memory_find(void* haystack, uintptr_t haystacksize, void* needle, uintptr_t needlesize) {
if(NELUA_UNLIKELY(((needlesize == 0) || (haystack == needle)))) {
return haystack;
} else if(NELUA_UNLIKELY((needlesize > haystacksize))) {
return (void*)NULL;
} else {
if((needlesize == 1)) {
return memchr(haystack, (int)(*(nluint8_ptr)needle), (size_t)haystacksize);
}
uintptr_t haystackbegin = (uintptr_t)haystack;
for(uintptr_t i = haystackbegin, _end = (haystackbegin + (haystacksize - needlesize)); i <= _end; i = i + 1) {
void* p = (void*)i;
if((memcmp(p, needle, (size_t)needlesize) == 0)) {
return p;
}
}
return (void*)NULL;
}
}
bool nelua_span_uint8__empty(nelua_span_uint8__ptr self) {
return (self->size == 0);
}
nluint8_ptr nelua_span_uint8____atindex(nelua_span_uint8__ptr self, uintptr_t i) {
return (&self->data[i]);
}
nlusize_ptr nelua_span_usize____atindex(nelua_span_usize__ptr self, uintptr_t i) {
return (&self->data[i]);
}
nelua_hashmapnode_string__boolean__ptr nelua_span_hashmapnode_string__boolean_____atindex(nelua_span_hashmapnode_string__boolean___ptr self, uintptr_t i) {
return (&self->data[i]);
}
void nelua_memory_spanset_1(nelua_span_usize_ dest, uintptr_t x) {
for(uintptr_t i = 0U, _end = dest.size; i < _end; i = i + 1) {
memcpy((void*)(&(*nelua_span_usize____atindex((&dest), i))), (void*)(&x), 8U);
}
}
void* nelua_GeneralAllocator_alloc(nelua_GeneralAllocator_ptr self, uintptr_t size) {
if(NELUA_UNLIKELY((size == 0))) {
return (void*)NULL;
}
return malloc((size_t)size);
}
void* nelua_GeneralAllocator_alloc0(nelua_GeneralAllocator_ptr self, uintptr_t size) {
if(NELUA_UNLIKELY((size == 0))) {
return (void*)NULL;
}
return calloc((size_t)size, 1U);
}
void nelua_GeneralAllocator_dealloc(nelua_GeneralAllocator_ptr self, void* p) {
if(NELUA_UNLIKELY((p == (void*)NULL))) {
return;
}
free(p);
}
void* nelua_GeneralAllocator_realloc(nelua_GeneralAllocator_ptr self, void* p, uintptr_t newsize, uintptr_t oldsize) {
if(NELUA_UNLIKELY((newsize == 0))) {
if(NELUA_LIKELY((p != (void*)NULL))) {
free(p);
}
return (void*)NULL;
} else if(NELUA_UNLIKELY((newsize == oldsize))) {
return p;
}
return realloc(p, (size_t)newsize);
}
void nelua_write_stderr(const char* msg, uintptr_t len, bool flush) {
if(len > 0 && msg) {
fwrite(msg, 1, len, stderr);
}
if(flush) {
fwrite("\n", 1, 1, stderr);
fflush(stderr);
}
}
void nelua_abort(void) {
NELUA_UBSAN_UNREACHABLE();
abort();
}
void nelua_panic_string(nlstring s) {
if(s.size > 0) {
nelua_write_stderr((const char*)s.data, s.size, true);
}
nelua_abort();
}
void* nelua_GeneralAllocator_xalloc(nelua_GeneralAllocator_ptr self, uintptr_t size) {
void* p = nelua_GeneralAllocator_alloc(self, size);
if(NELUA_UNLIKELY(((p == (void*)NULL) && (size > 0)))) {
nelua_panic_string(((nlstring){(uint8_t*)"out of memory", 13}));
}
return p;
}
void* nelua_GeneralAllocator_realloc0(nelua_GeneralAllocator_ptr self, void* p, uintptr_t newsize, uintptr_t oldsize) {
p = nelua_GeneralAllocator_realloc(self, p, newsize, oldsize);
if(NELUA_LIKELY(((newsize > oldsize) && (p != (void*)NULL)))) {
nelua_memory_zero((void*)(&((nluint8_arr0_ptr)p)[oldsize]), (newsize - oldsize));
}
return p;
}
nelua_span_usize_ nelua_GeneralAllocator_spanalloc_3(nelua_GeneralAllocator_ptr self, nlniltype T, uintptr_t size) {
if(NELUA_LIKELY((size > 0))) {
nlusize_arr0_ptr data = ((nlusize_arr0_ptr)nelua_GeneralAllocator_alloc(self, (size * 8)));
if(NELUA_LIKELY((data != ((nlusize_arr0_ptr)NULL)))) {
return (nelua_span_usize_){data, size};
}
}
return (nelua_span_usize_){0};
}
nelua_span_uint8_ nelua_GeneralAllocator_spanalloc0_1(nelua_GeneralAllocator_ptr self, nlniltype T, uintptr_t size) {
if(NELUA_LIKELY((size > 0))) {
nluint8_arr0_ptr data = ((nluint8_arr0_ptr)nelua_GeneralAllocator_alloc0(self, (size * 1)));
if(NELUA_LIKELY((data != ((nluint8_arr0_ptr)NULL)))) {
return (nelua_span_uint8_){data, size};
}
}
return (nelua_span_uint8_){0};
}
nelua_span_hashmapnode_string__boolean__ nelua_GeneralAllocator_spanalloc0_2(nelua_GeneralAllocator_ptr self, nlniltype T, uintptr_t size) {
if(NELUA_LIKELY((size > 0))) {
nelua_hashmapnode_string__boolean__arr0_ptr data = ((nelua_hashmapnode_string__boolean__arr0_ptr)nelua_GeneralAllocator_alloc0(self, (size * 32)));
if(NELUA_LIKELY((data != ((nelua_hashmapnode_string__boolean__arr0_ptr)NULL)))) {
return (nelua_span_hashmapnode_string__boolean__){data, size};
}
}
return (nelua_span_hashmapnode_string__boolean__){0};
}
void nelua_GeneralAllocator_spandealloc_1(nelua_GeneralAllocator_ptr self, nelua_span_uint8_ s) {
if(NELUA_UNLIKELY((s.size == 0))) {
return;
}
nelua_GeneralAllocator_dealloc(self, (void*)s.data);
}
nelua_span_usize_ nelua_GeneralAllocator_spanrealloc_3(nelua_GeneralAllocator_ptr self, nelua_span_usize_ s, uintptr_t size) {
if(NELUA_UNLIKELY(((s.size == 0) && (size > 0)))) {
s = nelua_GeneralAllocator_spanalloc_3(self, NELUA_NIL, size);
return s;
}
nlusize_arr0_ptr p = ((nlusize_arr0_ptr)nelua_GeneralAllocator_realloc(self, (void*)s.data, (size * 8), (s.size * 8)));
if(NELUA_UNLIKELY(((size > 0) && (p == ((nlusize_arr0_ptr)NULL))))) {
return s;
}
s.data = p;
s.size = size;
return s;
}
nelua_span_usize_ nelua_GeneralAllocator_xspanrealloc_3(nelua_GeneralAllocator_ptr self, nelua_span_usize_ s, uintptr_t size) {
s = nelua_GeneralAllocator_spanrealloc_3(self, s, size);
if(NELUA_UNLIKELY((s.size != size))) {
nelua_panic_string(((nlstring){(uint8_t*)"out of memory", 13}));
}
return s;
}
nelua_span_uint8_ nelua_GeneralAllocator_spanrealloc0_1(nelua_GeneralAllocator_ptr self, nelua_span_uint8_ s, uintptr_t size) {
if(NELUA_UNLIKELY(((s.size == 0) && (size > 0)))) {
s = nelua_GeneralAllocator_spanalloc0_1(self, NELUA_NIL, size);
return s;
}
nluint8_arr0_ptr p = ((nluint8_arr0_ptr)nelua_GeneralAllocator_realloc0(self, (void*)s.data, (size * 1), (s.size * 1)));
if(NELUA_UNLIKELY(((size > 0) && (p == ((nluint8_arr0_ptr)NULL))))) {
return s;
}
s.data = p;
s.size = size;
return s;
}
nelua_span_hashmapnode_string__boolean__ nelua_GeneralAllocator_spanrealloc0_2(nelua_GeneralAllocator_ptr self, nelua_span_hashmapnode_string__boolean__ s, uintptr_t size) {
if(NELUA_UNLIKELY(((s.size == 0) && (size > 0)))) {
s = nelua_GeneralAllocator_spanalloc0_2(self, NELUA_NIL, size);
return s;
}
nelua_hashmapnode_string__boolean__arr0_ptr p = ((nelua_hashmapnode_string__boolean__arr0_ptr)nelua_GeneralAllocator_realloc0(self, (void*)s.data, (size * 32), (s.size * 32)));
if(NELUA_UNLIKELY(((size > 0) && (p == ((nelua_hashmapnode_string__boolean__arr0_ptr)NULL))))) {
return s;
}
s.data = p;
s.size = size;
return s;
}
nelua_span_hashmapnode_string__boolean__ nelua_GeneralAllocator_xspanrealloc0_1(nelua_GeneralAllocator_ptr self, nelua_span_hashmapnode_string__boolean__ s, uintptr_t size) {
s = nelua_GeneralAllocator_spanrealloc0_2(self, s, size);
if(NELUA_UNLIKELY((s.size != size))) {
nelua_panic_string(((nlstring){(uint8_t*)"out of memory", 13}));
}
return s;
}
bool nelua_strchar_1_isalpha(uint8_t c) {
return ((((uint32_t)c | 32) - 97U) < 26);
}
bool nelua_strchar_1_islower(uint8_t c) {
return (((uint32_t)c - 97U) < 26);
}
bool nelua_strchar_1_isupper(uint8_t c) {
return (((uint32_t)c - 65U) < 26);
}
bool nelua_strchar_1_isdigit(uint8_t c) {
return (((uint32_t)c - 48U) < 10);
}
bool nelua_strchar_1_isxdigit(uint8_t c) {
return (nelua_strchar_1_isdigit(c) || ((((uint32_t)c | 32) - 97U) < 6));
}
bool nelua_strchar_1_iscntrl(uint8_t c) {
return (((uint32_t)c < 0x20) || (c == 0x7f));
}
bool nelua_strchar_1_isgraph(uint8_t c) {
return (((uint32_t)c - 0x21) < 0x5e);
}
bool nelua_strchar_1_isspace(uint8_t c) {
return ((c == 32U) || (((uint32_t)c - 9U) < 5));
}
bool nelua_strchar_1_isalnum(uint8_t c) {
return (nelua_strchar_1_isalpha(c) || nelua_strchar_1_isdigit(c));
}
bool nelua_strchar_1_ispunct(uint8_t c) {
return (nelua_strchar_1_isgraph(c) && (!nelua_strchar_1_isalnum(c)));
}
uint8_t nelua_strchar_1_getbasedigit(uint8_t c) {
uint8_t d = (c - 48U);
if((d < 10)) {
return d;
}
d = (c - 97U);
if((d < 26)) {
return (d + 10);
}
d = (c - 65U);
if((d < 26)) {
return (d + 10);
}
return 255U;
}
void nelua_assert_line_1(bool cond, nlstring msg) {
if(NELUA_UNLIKELY(!cond)) {
nelua_write_stderr("/home/bart/projects/nelua/nelua-lang/lib/stringbuilder.nelua\033[1m:28:12: \033[31m\033[1mruntime error: \033[0m\033[1m", 104, false);
nelua_write_stderr((const char*)msg.data, msg.size, false);
nelua_write_stderr("\033[0m\n assert(p < L_FMTFLAGS.size + 1, \"invalid format (repeated flags)\")\n \033[1m\033[32m^\033[0m\033[35m~~~~~~~~~~~~~~~~~~~~\033[0m\n", 129, true);
nelua_abort();
}
}
void nelua_assert_line_2(bool cond, nlstring msg) {
if(NELUA_UNLIKELY(!cond)) {
nelua_write_stderr("/home/bart/projects/nelua/nelua-lang/lib/stringbuilder.nelua\033[1m:36:10: \033[31m\033[1mruntime error: \033[0m\033[1m", 104, false);
nelua_write_stderr((const char*)msg.data, msg.size, false);
nelua_write_stderr("\033[0m\n assert(not strchar.isdigit(strfmt[p]), \"invalid format (width or precision too long)\")\n \033[1m\033[32m^\033[0m\033[35m~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\033[0m\n", 156, true);
nelua_abort();
}
}
uintptr_t nelua_scanformat(nluint8_arr0_ptr strfmt, nluint8_arr32_ptr form) {
uintptr_t p = 0U;
while(((strfmt[p] != 0) && (nelua_memory_scan((void*)((nlstring){(uint8_t*)"-+ #0", 5}).data, strfmt[p], 5U) != (void*)NULL))) {
p = (p + 1);
}
nelua_assert_line_1((p < (((nlstring){(uint8_t*)"-+ #0", 5}).size + 1)), ((nlstring){(uint8_t*)"invalid format (repeated flags)", 31}));
if(nelua_strchar_1_isdigit(strfmt[p])) {
p = (p + 1);
}
if(nelua_strchar_1_isdigit(strfmt[p])) {
p = (p + 1);
}
if((strfmt[p] == 46U)) {
p = (p + 1);
if(nelua_strchar_1_isdigit(strfmt[p])) {
p = (p + 1);
}
if(nelua_strchar_1_isdigit(strfmt[p])) {
p = (p + 1);
}
}
nelua_assert_line_2((!nelua_strchar_1_isdigit(strfmt[p])), ((nlstring){(uint8_t*)"invalid format (width or precision too long)", 44}));
form->v[0] = 37U;
nelua_memory_copy((void*)(&form->v[1]), (void*)(&strfmt[0]), (p + 1));
form->v[(p + 2)] = 0U;
return p;
}
void nelua_stringbuilderT_destroy(nelua_stringbuilderT_ptr self) {
nelua_GeneralAllocator_spandealloc_1((&self->allocator), self->data);
self->data = (nelua_span_uint8_){0};
self->size = 0U;
}
bool nelua_stringbuilderT_grow(nelua_stringbuilderT_ptr self, uintptr_t newsize) {
uintptr_t needed = (newsize + 1);
uintptr_t cap = self->data.size;
if((needed <= cap)) {
return true;
}
if((cap == 0)) {
cap = 16U;
}
while((cap < needed)) {
cap = (cap * 2);
if((cap <= 16U)) {
return false;
}
}
self->data = nelua_GeneralAllocator_spanrealloc0_1((&self->allocator), self->data, cap);
if((self->data.size != cap)) {
self->data = nelua_GeneralAllocator_spanrealloc0_1((&self->allocator), self->data, needed);
}
return (needed <= self->data.size);
}
nelua_span_uint8_ nelua_stringbuilderT_prepare(nelua_stringbuilderT_ptr self, uintptr_t n) {
if((!nelua_stringbuilderT_grow(self, (self->size + n)))) {
return (nelua_span_uint8_){0};
}
return (nelua_span_uint8_){.data = ((nluint8_arr0_ptr)(&(*nelua_span_uint8____atindex((&self->data), self->size)))), .size = ((self->data.size - self->size) - 1)};
}
void nelua_stringbuilderT_commit(nelua_stringbuilderT_ptr self, uintptr_t n) {
uintptr_t newsize = (self->size + n);
self->size = newsize;
}
bool nelua_stringbuilderT_writebyte_1(nelua_stringbuilderT_ptr self, uint8_t c, nlniltype n) {
nelua_span_uint8_ p = nelua_stringbuilderT_prepare(self, 1U);
if(NELUA_UNLIKELY(nelua_span_uint8__empty((&p)))) {
return false;
}
p.data[0] = c;
self->size = (self->size + 1);
return true;
}
void nelua_assert_line_3(bool cond, nlstring msg) {
if(NELUA_UNLIKELY(!cond)) {
nelua_write_stderr("/home/bart/projects/nelua/nelua-lang/lib/stringbuilder.nelua\033[1m:344:12: \033[31m\033[1mruntime error: \033[0m\033[1m", 105, false);
nelua_write_stderr((const char*)msg.data, msg.size, false);
nelua_write_stderr("\033[0m\n assert(false, 'invalid format for argument')\n \033[1m\033[32m^\033[0m\033[35m~~~~\033[0m\n", 93, true);
nelua_abort();
}
}
void nelua_assert_line_4(bool cond, nlstring msg) {
if(NELUA_UNLIKELY(!cond)) {
nelua_write_stderr("/home/bart/projects/nelua/nelua-lang/lib/stringbuilder.nelua\033[1m:346:15: \033[31m\033[1mruntime error: \033[0m\033[1m", 105, false);
nelua_write_stderr((const char*)msg.data, msg.size, false);
nelua_write_stderr("\033[0m\n assert(nb >= 0, 'unexpected number of bytes written in sprintf')\n \033[1m\033[32m^\033[0m\033[35m~~~\033[0m\n", 115, true);
nelua_abort();
}
}
nlmulret_nlboolean_nlisize nelua_formatarg_2(nelua_stringbuilderT_ptr self, uint8_t c, nluint8_arr32_ptr form, nlstring arg1) {
nelua_span_uint8_ buf = nelua_stringbuilderT_prepare(self, 128U);
if((buf.size < 128U)) {
return (nlmulret_nlboolean_nlisize){false, 0};
}
intptr_t nb = -1;
if((c == 115U)) {
nlstring s = arg1;
uintptr_t slen = (s.size + 1);
if(((form->v[1] == c) && (form->v[2] == 0))) {
buf = nelua_stringbuilderT_prepare(self, slen);
if((buf.size < slen)) {
return (nlmulret_nlboolean_nlisize){false, 0};
}
nelua_memory_copy((void*)buf.data, (void*)s.data, s.size);
nb = (intptr_t)s.size;
} else {
if((slen < 128U)) {
slen = 128U;
}
buf = nelua_stringbuilderT_prepare(self, slen);
if((buf.size < slen)) {
return (nlmulret_nlboolean_nlisize){false, 0};
}
s = nelua_nlstring_copy(s);
char* cs = (char*)s.data;
if((s.size == 0)) {
cs = "";
}
nb = (intptr_t)snprintf((char*)buf.data, (size_t)buf.size, (char*)(&form->v[0]), cs);
nelua_nlstring_destroy((&s));
}
goto nelua_next_5;
}
nelua_assert_line_3(false, ((nlstring){(uint8_t*)"invalid format for argument", 27}));
nelua_next_5:;
nelua_assert_line_4((nb >= 0), ((nlstring){(uint8_t*)"unexpected number of bytes written in sprintf", 45}));
return (nlmulret_nlboolean_nlisize){true, nb};
}
void nelua_assert_line_5(bool cond, nlstring msg) {
if(NELUA_UNLIKELY(!cond)) {
nelua_write_stderr("/home/bart/projects/nelua/nelua-lang/lib/stringbuilder.nelua\033[1m:384:18: \033[31m\033[1mruntime error: \033[0m\033[1m", 105, false);
nelua_write_stderr((const char*)msg.data, msg.size, false);
nelua_write_stderr("\033[0m\n assert(false, 'bad format argument (no value)')\n \033[1m\033[32m^\033[0m\033[35m~~~~\033[0m\n", 108, true);
nelua_abort();
}
}
nlmulret_nlboolean_nlusize nelua_stringbuilderT_writef_2(nelua_stringbuilderT_ptr self, nlstring fmt, nlstring __arg1) {
uintptr_t pos = 0U;
uintptr_t written = 0U;
int32_t argi = 0;
while((pos < fmt.size)) {
uint8_t c = fmt.data[pos];
pos = (pos + 1);
if((c != 37U)) {
if((!nelua_stringbuilderT_writebyte_1(self, c, NELUA_NIL))) {
return (nlmulret_nlboolean_nlusize){false, written};
}
written = (written + 1);
} else {
c = fmt.data[pos];
if((c == 37U)) {
if((!nelua_stringbuilderT_writebyte_1(self, 37U, NELUA_NIL))) {
return (nlmulret_nlboolean_nlusize){false, written};
}
written = (written + 1);
pos = (pos + 1);
} else {
nluint8_arr32 form = {0};
pos = (pos + nelua_scanformat(((nluint8_arr0_ptr)(&fmt.data[pos])), (&form)));
c = fmt.data[pos];
pos = (pos + 1);
argi = (argi + 1);
bool ok = false;
intptr_t nb = -1;
if((1 == argi)) {
nlmulret_nlboolean_nlisize _asgnret_1 = nelua_formatarg_2(self, c, (&form), __arg1);
ok = _asgnret_1.r1;
nb = _asgnret_1.r2;
goto nelua_next_3;
}
nelua_assert_line_5(false, ((nlstring){(uint8_t*)"bad format argument (no value)", 30}));
nelua_next_3:;
if((!ok)) {
return (nlmulret_nlboolean_nlusize){false, written};
}
nelua_stringbuilderT_commit(self, (uintptr_t)nb);
written = (written + (uintptr_t)nb);
}
}
}
return (nlmulret_nlboolean_nlusize){true, written};
}
void nelua_assert_line_6(bool cond, nlstring msg) {
if(NELUA_UNLIKELY(!cond)) {
nelua_write_stderr("/home/bart/projects/nelua/nelua-lang/lib/stringbuilder.nelua\033[1m:384:18: \033[31m\033[1mruntime error: \033[0m\033[1m", 105, false);
nelua_write_stderr((const char*)msg.data, msg.size, false);
nelua_write_stderr("\033[0m\n assert(false, 'bad format argument (no value)')\n \033[1m\033[32m^\033[0m\033[35m~~~~\033[0m\n", 108, true);
nelua_abort();
}
}
nlmulret_nlboolean_nlusize nelua_stringbuilderT_writef_3(nelua_stringbuilderT_ptr self, nlstring fmt) {
uintptr_t pos = 0U;
uintptr_t written = 0U;
int32_t argi = 0;
while((pos < fmt.size)) {
uint8_t c = fmt.data[pos];
pos = (pos + 1);
if((c != 37U)) {
if((!nelua_stringbuilderT_writebyte_1(self, c, NELUA_NIL))) {
return (nlmulret_nlboolean_nlusize){false, written};
}
written = (written + 1);
} else {
c = fmt.data[pos];
if((c == 37U)) {
if((!nelua_stringbuilderT_writebyte_1(self, 37U, NELUA_NIL))) {
return (nlmulret_nlboolean_nlusize){false, written};
}
written = (written + 1);
pos = (pos + 1);
} else {
nluint8_arr32 form = {0};
pos = (pos + nelua_scanformat(((nluint8_arr0_ptr)(&fmt.data[pos])), (&form)));
c = fmt.data[pos];
pos = (pos + 1);
argi = (argi + 1);
bool ok = false;
intptr_t nb = -1;
nelua_assert_line_6(false, ((nlstring){(uint8_t*)"bad format argument (no value)", 30}));
if((!ok)) {
return (nlmulret_nlboolean_nlusize){false, written};
}
nelua_stringbuilderT_commit(self, (uintptr_t)nb);
written = (written + (uintptr_t)nb);
}
}
}