-
Notifications
You must be signed in to change notification settings - Fork 0
/
n.c
15756 lines (9394 loc) · 339 KB
/
n.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 NEO - 15/05/2023
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <stdarg.h>
#include <inttypes.h>
#ifdef __linux__
#include <pthread.h>
#endif
#ifdef __APPLE__
#endif
#ifdef _WIN32#include <windows.h>
//#include <WinSock2.h>
#endif
//==================================typedefS ================================*/
typedef unsigned char byte;
typedef unsigned int uint;
typedef int64_t i64;
typedef int32_t i32;
typedef int16_t i16;
typedef int8_t i8;
typedef uint64_t u64;
typedef uint32_t u32;
typedef uint16_t u16;
typedef uint8_t u8;
typedef uint32_t rune;
typedef float f32;
typedef double f64;
typedef unsigned char * byteptr;
typedef int * intptr;
typedef void * voidptr;
typedef struct array array;
typedef struct map map;
typedef array array_string;
typedef array array_int;
typedef array array_byte;
typedef array array_uint;
typedef array array_float;
typedef map map_int;
typedef map map_string;
#ifndef bool
typedef int bool;
#define true 1
#define false 0
#endif
//============================== HELPER C MACROS =============================*/
#define _PUSH(arr, val, tmp, tmp_typ) {
tmp_typ tmp = (val);
array__push(arr, & tmp);
}
#define _IN(typ, val, arr) array_ # #typ # #_contains(arr, val)
#define ALLOC_INIT(type, ...)(type * ) memdup((type[]) {
__VA_ARGS__
}, sizeof(type))
#define UTF8_CHAR_LEN(byte)((0xE5000000 >> ((byte >> 3) & 0x1e)) & 3) + 1
//================================== GLOBALS =================================*/
//int V_ZERO = 0;
byteptr g_str_buf;
int load_so(byteptr);
void reload_so();
void init_consts();
i64 total_m = 0; // For counting total RAM allocated
int g_test_ok = 1;
/*================================== FNS =================================*/
#include <sys/stat.h>
#include <signal.h>
#include <unistd.h>
#include <dirent.h>
#include <errno.h>
#include <time.h>
#include <time.h>
typedef struct array array;
typedef array array_int;
typedef array array_string;
typedef struct string string;
typedef struct ustring ustring;
typedef array array_byte;
typedef struct map map;
typedef array array_Entry;
typedef struct Entry Entry;
typedef struct Entry2 Entry2;
typedef struct smap smap;
typedef array array_Entry2;
typedef struct Option Option;
typedef struct StringBuilder StringBuilder;
typedef struct os__FILE os__FILE;
typedef struct os__File os__File;
typedef array array_ustring;
typedef struct os__Reader os__Reader;
typedef struct os__FileInfo os__FileInfo;
typedef struct time__Time time__Time;
typedef struct CGen CGen;
typedef struct Fn Fn;
typedef array array_Var;
typedef int BuildMode;
typedef int Os;
typedef int Pass;
typedef struct V V;
typedef struct Var Var;
typedef struct Parser Parser;
typedef struct Scanner Scanner;
typedef struct ScanRes ScanRes;
typedef struct Table Table;
typedef array array_Type;
typedef array array_Fn;
typedef int AccessMod;
typedef int TypeCategory;
typedef struct Type Type;
typedef int Token;
typedef array array_Token;
typedef int BuildMode;
typedef int Os;
typedef int Pass;
typedef int AccessMod;
typedef int TypeCategory;
typedef int Token;
struct array {
void * data;
int len;
int cap;
int element_size;
};
struct string {
byte * str;
int len;
};
struct ustring {
string s;
array_int runes;
int len;
};
struct map {
int element_size;
array_Entry entries;
bool is_sorted;
};
struct Entry {
string key;
void * val;
};
struct Entry2 {
string key;
string val;
};
struct smap {
array_Entry2 entries;
bool is_sorted;
};
struct Option {
void * data;
string error;
bool ok;
};
struct StringBuilder {
array_byte buf;
int len;
};
struct os__FILE {};
struct os__File {
os__FILE * cfile;
};
struct os__Reader {
os__FILE * fp;
};
struct os__FileInfo {
string name;
int size;
};
struct time__Time {
int year;
int day;
int month;
int hour;
int minute;
int second;
int uni;
};
struct CGen {
os__File out;
string out_path;
array_stringtypedefs;
array_string type_aliases;
array_string includes;
array_string types;
array_string thread_args;
array_string thread_fns;
array_string consts;
array_string fns;
array_string so_fns;
array_string consts_init;
array_string lines;
bool is_user;
Pass run;
bool nogen;
string tmp_line;
string cur_line;
string prev_line;
bool is_tmp;
string fn_main;
string stash;
};
struct Fn {
string pkg;
array_Var local_vars;
int var_idx;
array_Var args;
bool is_interface;
int scope_level;
string typ;
string name;
bool is_c;
string receiver_typ;
bool is_private;
bool is_method;
bool returns_error;
bool is_decl;
string defer;
};
struct V {
BuildMode build_mode;
Os os;
bool nofmt;
string out_name_c;
array_string files;
string dir;
Table * table;
CGen * cgen;
bool is_test;
bool is_script;
bool is_so;
bool is_live;
bool is_prof;
bool translated;
bool obfuscate;
string lang_dir;
bool is_verbose;
bool is_run;
bool is_play;
bool show_c_cmd;
bool sanitize;
string out_name;
bool is_prod;
bool is_repl;
string vroot;
};
struct Var {
string typ;
string name;
bool is_arg;
bool is_const;
bool is_import_const;
array_Var args;
string attr;
bool is_mut;
bool ptr;
bool ref;
string parent_fn;
string pkg;
int line_nr;
AccessMod access_mod;
bool is_global;
bool is_used;
int scope_level;
};
struct Parser {
string file_path;
string file_name;
Scanner * scanner;
int token_idx;
Token tok;
Token prev_tok;
Token prev_tok2;
string lit;
CGen * cgen;
Table * table;
Pass run;
Os os;
string pkg;
bool inside_const;
Var expr_var;
string assigned_type;
int tmp_cnt;
bool is_test;
bool is_script;
bool is_live;
bool is_so;
bool is_prof;
bool translated;
bool is_prod;
bool is_verbose;
bool obfuscate;
bool is_play;
bool is_repl;
bool builtin_pkg;
BuildMode build_mode;
array_string vh_lines;
bool inside_if_expr;
bool is_struct_init;
int if_expr_cnt;
int for_expr_cnt;
bool ptr_cast;
bool calling_c;
Fn * cur_fn;
bool returns;
string vroot;
};
struct Scanner {
string file_path;
string text;
int pos;
int line_nr;
bool inside_string;
bool dollar_start;
bool dollar_end;
bool debug;
string line_comment;
bool started;
bool is_fmt;
StringBuilder fmt_out;
int fmt_indent;
bool fmt_line_empty;
};
struct ScanRes {
Token tok;
string lit;
};
struct Table {
array_Type types;
array_Var consts;
array_Fn fns;
map_int obf_ids;
array_string packages;
array_string imports;
array_string flags;
_Atomic
int fn_cnt;
bool obfuscate;
};
struct Type {
string pkg;
string name;
array_Var fields;
array_Fn methods;
string parent;
TypeCategory cat;
array_string gen_types;
Fn func;
bool is_c;
bool is_interface;
bool is_enum;
bool is_placeholder;
};
string _STR(const char * , ...);
string _STR_TMP(const char * , ...);
array new_array(int mylen, int cap, int elm_size);
array new_array_from_c_array(int len, int cap, int elm_size, void * c_array);
array new_array_from_c_array_no_alloc(int len, int cap, int elm_size, void * c_array);
array array_repeat(void * val, int nr_repeats, int elm_size);
void array_append_array(array * a, array b);
void array_sort_with_compare(array * a, void * compare);
void array_insert(array * a, int i, void * val);
void array_prepend(array * a, void * val);
void array_delete(array * a, int idx);
void * array__get(array a, int i);
void * array_first(array a);
void * array_last(array a);
array array_left(array s, int n);
array array_right(array s, int n);
array array_slice(array s, int start, int _end);
void array_set(array * a, int idx, void * val);
void array__push(array * arr, void * val);
void array__push_many(array * arr, void * val, int size);
string array_int_str(array_int a);
void v_array_int_free(array_int a);
string array_string_str(array_string a);
void v_free(void * a);
string tos_clone(byte * s);
string tos2(byte * s);
string tos_no_len(byte * s);
string string_clone(string a);
byte * string_cstr(string s);
string string_replace(string s, string rep, string with);
int string_int(string s);
f32 string_f32(string s);
bool string_eq(string s, string a);
bool string_ne(string s, string a);
bool string_lt(string s, string a);
bool string_le(string s, string a);
bool string_gt(string s, string a);
bool string_ge(string s, string a);
string string_add(string s, string a);
array_string string_split(string s, string delim);
array_string string_split_single(string s, byte delim);
array_string string_split_into_lines(string s);
string string_left(string s, int n);
string string_right(string s, int n);
string string_substr(string s, int start, int end);
int string_index(string s, string p);
int string_last_index(string s, string p);
int string_index_after(string s, string p, int start);
bool string_contains(string s, string p);
bool string_starts_with(string s, string p);
bool string_ends_with(string s, string p);
string string_to_lower(string s);
string string_to_upper(string s);
string string_find_between(string s, string start, string end);
bool array_string_contains(array_string ar, string val);
bool array_int_contains(array_int ar, int val);
void * array_string_to_c(array_string a);
bool is_space(byte c);
bool byte_is_space(byte c);
string string_trim_space(string s);
string string_trim(string s, byte c);
string string_trim_left(string s, string cutset);
string string_trim_right(string s, string cutset);
int compare_strings(string * a, string * b);
int compare_strings_by_len(string * a, string * b);
int compare_lower_strings(string * a, string * b);
void array_string_sort(array_string * s);
void array_string_sort_ignore_case(array_string * s);
void array_string_sort_by_len(array_string * s);
ustring string_ustring(string s);
ustring string_ustring_tmp(string s);
string ustring_substr(ustring u, int start, int end);
string ustring_left(ustring u, int pos);
string ustring_right(ustring u, int pos);
byte string_at(string s, int idx);
string ustring_at(ustring u, int idx);
void v_ustring_free(ustring u);
int abs(int a);
bool byte_is_digit(byte c);
bool byte_is_letter(byte c);
void v_string_free(string s);
void v_array_string_free(array_string arr);
string string_all_before(string s, string dot);
string string_all_before_last(string s, string dot);
string string_all_after(string s, string dot);
string array_string_join(array_string a, string del);
string array_string_join_lines(array_string s);
string string_limit(string s, int max);
bool byte_is_white(byte c);
string repeat_char(byte c, int n);
int string_hash(string s);
void v_exit(int code);
bool isnil(void * v);
void on_panic(int( * f)(int /*FFF*/ ));
void print_backtrace();
void v_panic(string s);
void println(string s);
void eprintln(string s);
void v_print(string s);
byte * v_malloc(int n);
byte * v_calloc(int n);
int _strlen(byte * s);
Option opt_ok(void * data);
void * memdup(void * src, int sz);
Option v_error(string s);
array_int range_int(int start, int end);
string double_str(double d);
string float_str(float d);
string f64_str(f64 d);
string f32_str(f32 d);
string ptr_str(void * ptr);
string int_str(int nn);
string u8_str(u8 nn);
string i64_str(i64 nn);
string bool_str(bool b);
string int_hex(int n);
string i64_hex(i64 n);
bool array_byte_contains(array_byte a, byte val);
string byte_str(byte c);
int string_is_utf8(string s);
string utf32_to_str(u32 code);
string utf32_to_str_no_malloc(u32 code, void * buf);
int string_utf32_code(string _rune);
map new_map(int cap, int elm_size);
Entry map_new_entry(map * m, string key, void * val);
void map__set(map * m, string key, void * val);
int volt_abs(int n);
void map_bs(map m, string query, int start, int end, void * out);
int compare_map(Entry * a, Entry * b);
void map_sort(map * m);
array_string map_keys(map m);
bool map_get(map m, string key, void * out);
bool map_exists(map m, string key);
void v_map_print(map m);
void v_map_free(map m);
string map_string_str(map_string m);
smap new_smap();
void smap_set(smap * m, string key, string val);
string smap_get(smap m, string key);
string smap_bs(smap m, string query, int start, int end);
int compare_smap(Entry2 * a, Entry2 * b);
void smap_sort(smap * m);
void v_smap_free(smap m);
string smap_str(smap m);
StringBuilder new_string_builder(int initial_size);
void StringBuilder_write(StringBuilder * b, string s);
void StringBuilder_writeln(StringBuilder * b, string s);
string StringBuilder_str(StringBuilder b);
void StringBuilder_cut(StringBuilder b, int n);
void v_StringBuilder_free(StringBuilder * b);
array_string os__init_os_args(int argc, void * c);
void os__parse_windows_cmd_line(byte * cmd);
string os__read_file(string path);
string os__File_read_rune(os__File f);
int os__file_size(string path);
int os__file_last_mod_unix(string path);
array_string os__read_lines(string path);
array_ustring os__read_file_into_ulines(string path);
void os__append_to_file(string file, string s);
os__File os__open(string path);
os__File os__open_file(string file);
os__File os__create(string path);
os__File os__open_append(string path);
os__File os__create_file(string file);
os__File os__create_file_a(string file);
os__File os__open_file_a(string file);
os__File os__create_file2(string file, string mode);
void os__File_append(os__File f, string s);
void os__File_write(os__File f, void * data, int size);
void os__File_write_at(os__File f, void * data, int size, int pos);
void os__File_appendln(os__File f, string s);
void os__File_close(os__File f);
void os__close_file(os__FILE * fp);
int os__system2(string cmd);
os__FILE * os__popen(string path);
string os__system(string cmd);
array_string os__system_into_lines(string s);
string os__getenv(string key);
void os__exit(int code);
bool os__file_exists(string path);
bool os__dir_exists(string path);
void os__mkdir(string path);
void os__rm(string path);
void os__print_c_errno();
string os__basedir(string path);
string os__filename(string path);
string os__get_line();
string os__user_os();
string os__home_dir();
void os__write_file(string path, string text);
void os__on_segfault(void * f);
void os__log(string s);
bool os__is_dir(string path);
void os__chdir(string path);
string os__getwd();
array_string os__ls(string path);
void os__print_backtrace();
void time__remove_me_when_c_bug_is_fixed();
time__Time time__now();
time__Time time__random();
time__Time time__unix(string u);
time__Time time__convert_ctime(struct tm t);
time__Time time__unixn(int uni);
string time__Time_format_ss(time__Time t);
string time__Time_format(time__Time t);
string time__Time_smonth(time__Time t);
string time__Time_hhmm(time__Time t);
string time__Time_hhmm_tmp(time__Time t);
string time__Time_hhmm12(time__Time t);
string time__Time_hhmmss(time__Time t);
string time__Time_ymmdd(time__Time t);
string time__Time_md(time__Time t);
string time__Time_clean(time__Time t);
string time__Time_clean12(time__Time t);
time__Time time__parse(string s);
time__Time time__new_time(time__Time t);
int time__Time_calc_unix(time__Time * t);
time__Time time__Time_add_seconds(time__Time t, int seconds);
int time__since(time__Time t);
string time__Time_relative(time__Time t);
int time__day_of_week(int y, int m, int d);
int time__Time_day_of_week(time__Time t);
string time__Time_weekday_str(time__Time t);
double time__ticks();
void time__sleep(int seconds);
void time__sleep_ms(int seconds);
int rand__next(int max);
CGen * new_cgen(string out_name_c);
void CGen_genln(CGen * g, string s);
void CGen_gen(CGen * g, string s);
void CGen_save(CGen * g);
void CGen_start_tmp(CGen * g);
string CGen_end_tmp(CGen * g);
int CGen_add_placeholder(CGen * g);
void CGen_set_placeholder(CGen * g, int pos, string val);
int CGen_add_placeholder2(CGen * g);
void CGen_set_placeholder2(CGen * g, int pos, string val);
void CGen_insert_before(CGen * g, string val);
void CGen_register_thread_fn(CGen * g, string wrapper_name, string wrapper_text, string struct_text);
string V_prof_counters(V * c);
string Parser_print_prof_counters(Parser * p);
void Parser_gen_type(Parser * p, string s);
void Parser_gen_typedef(Parser * p, string s);
void Parser_gen_type_alias(Parser * p, string s);
void CGen_add_to_main(CGen * g, string s);
Var Fn_find_var(Fn * f, string name);
void Fn_open_scope(Fn * f);
void Fn_close_scope(Fn * f);
void Fn_mark_var_used(Fn * f, Var v);
bool Fn_known_var(Fn * f, string name);
void Fn_register_var(Fn * f, Var v);
bool Parser_is_sig(Parser * p);
Fn * new_fn(string pkg);
void Parser_fn_decl(Parser * p);
void Parser_async_fn_call(Parser * p, Fn f, int method_ph, string receiver_var, string receiver_type);
void Parser_fn_call(Parser * p, Fn f, int method_ph, string receiver_var, string receiver_type);
void Parser_fn_args(Parser * p, Fn * f);
Fn * Parser_fn_call_args(Parser * p, Fn * f);
bool contains_capital(string s);
string Fn_typ_str(Fn f);
string Fn_str_args(Fn * f, Table * table);
void Parser_gen_json_for_type(Parser * p, Type typ);
bool is_js_prim(string typ);
string Parser_decode_array(Parser * p, string typ);
string js_enc_name(string typ);
string js_dec_name(string typ);
string Parser_encode_array(Parser * p, string typ);
string vtmp_path();
void V_compile(V * c);
void V_cc(V * c);
array_string V_v_files_from_dir(V * c, string dir);
void V_add_user_v_files(V * c);
string get_arg(string joined_args, string arg, string def);
void V_log(V * c, string s);
V * new_v(array_string args);
array_string run_repl();
Parser V_new_parser(V * c, string path, Pass run);
void Parser_next(Parser * p);
void Parser_log(Parser * p, string s);
void Parser_parse(Parser * p);
void Parser_import_statement(Parser * p);
void Parser_const_decl(Parser * p);
void Parser_type_decl(Parser * p);
void Parser_struct_decl(Parser * p);
void Parser_enum_decl(Parser * p, string _enum_name);
string Parser_check_name(Parser * p);
string Parser_check_string(Parser * p);
string Parser_strtok(Parser * p);
void Parser_check_space(Parser * p, Token expected);
void Parser_check(Parser * p, Token expected);
void Parser_error(Parser * p, string s);
bool Parser_first_run(Parser * p);
string Parser_get_type(Parser * p);
void Parser_print_tok(Parser * p);
string Parser_statements(Parser * p);
string Parser_statements_no_curly_end(Parser * p);
void Parser_genln(Parser * p, string s);
void Parser_gen(Parser * p, string s);
void Parser_vh_genln(Parser * p, string s);
void Parser_fmt_inc(Parser * p);
void Parser_fmt_dec(Parser * p);
string Parser_statement(Parser * p, bool add_semi);
void Parser_assign_statement(Parser * p, Var v, int ph, bool is_map);
void Parser_var_decl(Parser * p);
string Parser_bool_expression(Parser * p);
string Parser_bterm(Parser * p);
string Parser_name_expr(Parser * p);
string Parser_var_expr(Parser * p, Var v);
bool Parser_fileis(Parser * p, string s);
string Parser_dot(Parser * p, string str_typ, int method_ph);
string Parser_index_expr(Parser * p, string typ, int fn_ph);
string Parser_expression(Parser * p);
string Parser_term(Parser * p);
string Parser_unary(Parser * p);
string Parser_factor(Parser * p);
string Parser_assoc(Parser * p);
void Parser_char_expr(Parser * p);
string format_str(string str);
string Parser_typ_to_fmt(Parser * p, string typ);
void Parser_string_expr(Parser * p);
string Parser_map_init(Parser * p);
string Parser_array_init(Parser * p);
void Parser_register_array(Parser * p, string typ);
string Parser_struct_init(Parser * p, bool is_c_struct_init);
string Parser_cast(Parser * p, string typ);
string Parser_get_tmp(Parser * p);
int Parser_get_tmp_counter(Parser * p);
string os_name_to_ifdef(string name);
void Parser_comp_time(Parser * p);
void Parser_chash(Parser * p);
bool is_c_pre(string hash);
string Parser_if_st(Parser * p, bool is_expr);
void Parser_for_st(Parser * p);
void Parser_switch_statement(Parser * p);
void Parser_assert_statement(Parser * p);
void Parser_return_st(Parser * p);
string prepend_pkg(string pkg, string name);
string Parser_prepend_pkg(Parser * p, string name);
void Parser_go_statement(Parser * p);
void Parser_register_var(Parser * p, Var v);
string Parser_js_decode(Parser * p);
bool is_compile_time_const(string s);
void Scanner_fgen(Scanner * scanner, string s);
void Scanner_fgenln(Scanner * scanner, string s);
void Parser_fgen(Parser * p, string s);
void Parser_fspace(Parser * p);
void Parser_fgenln(Parser * p, string s);
Scanner * new_scanner(string file_path);
ScanRes scan_res(Token tok, string lit);
bool is_white(byte c);
bool is_nl(byte c);
string Scanner_ident_name(Scanner * s);
string Scanner_ident_number(Scanner * s);
void Scanner_skip_whitespace(Scanner * s);
string Scanner_get_until_start(Scanner * s, int pos);
void Scanner_cao_change(Scanner * s, string operator);
ScanRes Scanner_scan(Scanner * s);
void Scanner_error(Scanner * s, string msg);
string Scanner_ident_string(Scanner * s);
string Scanner_ident_char(Scanner * s);
Token Parser_peek(Parser * p);
Token Scanner_peek(Scanner * s);
void Scanner_debug_tokens(Scanner * s);
bool is_name_char(byte c);
string Type_str(Type t);
string Fn_str(Fn f);
bool is_number_type(string typ);
bool is_float_type(string typ);
Table * new_table(bool obfuscate);
string Table_var_cgen_name(Table * t, string name);
void Table_register_package(Table * t, string pkg);
bool Table_known_pkg(Table * table, string pkg);
void Table_register_const(Table * t, string name, string typ, string pkg, bool is_imported);
void Parser_register_global(Parser * p, string name, string typ);
void Table_register_fn(Table * t, Fn f);
bool Table_known_type(Table * table, string typ);
Fn Table_find_fn(Table * t, string name);
bool Table_known_fn(Table * t, string name);
bool Table_known_const(Table * t, string name);
void Table_register_type(Table * t, string typ);
void Parser_register_type_with_parent(Parser * p, string strtyp, string parent);
void Table_register_type_with_parent(Table * t, string typ, string parent);
void Table_register_type2(Table * t, Type typ);
void Type_add_field(Type * t, string name, string typ, bool is_mut, string attr, AccessMod access_mod);
bool Type_has_field(Type * t, string name);
Var Type_find_field(Type * t, string name);
bool Table_type_has_field(Table * table, Type * typ, string name);
Var Table_find_field(Table * table, Type * typ, string name);
void Type_add_method(Type * t, Fn f);
bool Type_has_method(Type * t, string name);
bool Table_type_has_method(Table * table, Type * typ, string name);
Fn Table_find_method(Table * table, Type * typ, string name);
Fn Type_find_method(Type * t, string name);
void Type_add_gen_type(Type * t, string type_name);
Type * Parser_find_type(Parser * p, string name);
Type * Table_find_type(Table * t, string name);
bool Parser__check_types(Parser * p, string got, string expected, bool
throw);
bool Parser_check_types(Parser * p, string got, string expected);
bool Parser_check_types_no_throw(Parser * p, string got, string expected);
bool Parser_satisfies_interface(Parser * p, string interface_name, string _typ, bool
throw);
string type_default(string typ);
bool Table_is_interface(Table * t, string name);
bool Table_main_exists(Table * t);
Var Table_find_const(Table * t, string name);
string Table_cgen_name(Table * table, Fn * f);
string Table_cgen_name_type_pair(Table * table, string name, string typ);
map_int build_keys();
array_string build_token_str();
Token key_to_token(string key);
bool is_key(string key);
string Token_str(Token t);
bool Token_is_decl(Token t);
bool Token_is_assign(Token t);
bool array_Token_contains(array_Token t, Token val);
array_string os__args;
#define os__BUF_SIZE 5000
string time__Months;
string time__Days;
#define main__MaxLocalVars 50
string main__Version;
#define DEFAULT_MODE 0
#define EMBED_VLIB 1
#define BUILD 2
array_string main__SupportedPlatforms;
string main__TmpPath;
#define MAC 0
#define LINUX 1
#define WINDOWS 2
#define RUN_IMPORTS 0
#define RUN_DECLS 1
#define RUN_MAIN 2
#define main__HelpText tos2("\n- Build a V program:\nv file.v\n\n- Get current V version:\nv version\n\n- Build an optimized executable:\nv -prod file.v\n\n- Specify the executable\'s name:\nv -o program file.v \n\n- Build and execute a V program:\nv run file.v\n\n- Obfuscate the resulting binary:\nv -obf -prod build file.v\n\n- Test: \nv string_test.v \n")
Fn * main__EmptyFn;
#define main__SINGLE_QUOTE '\''
#define main__QUOTE '"'
#define PRIVATE 0
#define PRIVET_MUT 1
#define PUBLIC 2
#define PUBLIC_MUT 3
#define PUBLIC_MUT_MUT 4
#define TYPE_STRUCT 0
#define T_CAT_FN 1
array_string main__CReserved;
array_string main__NUMBER_TYPES;
array_string main__FLOAT_TYPES;
#define EOF 0
#define NAME 1
#define INT 2
#define STRING 3
#define CHAR 4
#define FLOAT 5
#define PLUS 6
#define MINUS 7
#define MUL 8
#define DIV 9
#define MOD 10
#define XOR 11
#define PIPE 12
#define INC 13
#define DEC 14
#define AND 15
#define OR 16
#define NOT 17
#define BIT_NOT 18
#define QUESTION 19
#define COMMA 20
#define SEMICOLON 21
#define COLON 22
#define AMP 23
#define HASH 24
#define AT 25
#define DOLLAR 26
#define LEFT_SHIFT 27
#define RIGHT_SHIFT 28
#define ASSIGN 29
#define DECL_ASSIGN 30
#define PLUS_ASSIGN 31
#define MINUS_ASSIGN 32
#define DIV_ASSIGN 33
#define MULT_ASSIGN 34
#define XOR_ASSIGN 35
#define MOD_ASSIGN 36
#define OR_ASSIGN 37
#define AND_ASSIGN 38
#define RIGHT_SHIFT_ASSIGN 39
#define LEFT_SHIFT_ASSIGN 40
#define LCBR 41
#define RCBR 42
#define LPAR 43
#define RPAR 44
#define LSBR 45
#define RSBR 46
#define EQ 47
#define NE 48
#define GT 49
#define LT 50
#define GE 51
#define LE 52
#define LINE_COM 53
#define MLINE_COM 54
#define NL 55
#define DOT 56
#define DOTDOT 57
#define keyword_beg 58
#define PACKAGE 59
#define STRUCT 60
#define IF 61
#define ELSE 62
#define RETURN 63
#define GO 64
#define CONST 65
#define IMPORT_CONST 66
#define MUT 67
#define TIP 68
#define ENUM 69
#define FOR 70
#define SWITCH 71
#define MATCH 72
#define CASE 73
#define FUNC 74
#define TRUE 75
#define FALSE 76
#define CONTINUE 77
#define BREAK 78
#define EMBED 79
#define IMPORT 80
#define TYPEOF 81
#define DEFAULT 82
#define ENDIF 83
#define ASSERT 84
#define SIZEOF 85
#define IN 86
#define ATOMIC 87
#define INTERFACE 88
#define OR_ELSE 89
#define GLOBAL 90
#define UNION 91
#define PUB 92
#define GOTO 93
#define STATIC 94
#define keyword_end 95
array_string main__TOKENSTR;
map_int main__KEYWORDS;
array_Token main__AssignTokens;
array new_array(int mylen, int cap, int elm_size) {
array arr = (array) {
.len = mylen, .cap = cap, .element_size = elm_size, .data = v_malloc(cap * elm_size)
};
return arr;
}
array new_array_from_c_array(int len, int cap, int elm_size, void * c_array) {
array arr = (array) {
.len = len, .cap = cap, .element_size = elm_size, .data = v_malloc(cap * elm_size)
};
memcpy(arr.data, c_array, len * elm_size);
return arr;
}
array new_array_from_c_array_no_alloc(int len, int cap, int elm_size, void * c_array) {
array arr = (array) {
.len = len, .cap = cap, .element_size = elm_size, .data = c_array
};
return arr;
}
array array_repeat(void * val, int nr_repeats, int elm_size) {
array arr = (array) {
.len = nr_repeats, .cap = nr_repeats, .element_size = elm_size, .data = v_malloc(nr_repeats * elm_size)
};
for (
int i = 0; i < nr_repeats; i++) {
memcpy(arr.data + i * elm_size, val, elm_size);
};
return arr;
}
void array_append_array(array * a, array b) {
for (
int i = 0; i < b.len; i++) {
void * val = ( * (void ** ) array__get(b, i));
array__push(a, val);
};
}
void array_sort_with_compare(array * a, void * compare) {
qsort(a -> data, a -> len, a -> element_size, compare);