-
Notifications
You must be signed in to change notification settings - Fork 0
/
cr.h
2007 lines (1789 loc) · 88.4 KB
/
cr.h
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
/* Made By: Thimo Böhmer
* Date: November 2022 - December 2022
* Copyright by: Thimo Böhmer
*/
/* I did not try my best at making something clean.
* Also I did not care, in its current state it is very modular.
* Well, modular for me at least.
*
* If you think you can improve it, or help me improve it.
* I am open to suggestions!
*/
#ifndef CR_CORE_META_FUNCTION_HEADER_CR_H
#define CR_CORE_META_FUNCTION_HEADER_CR_H
#include <type_traits>
#include <utility>
#include <iostream>
namespace cr
{
struct str { const char *text; };
}
namespace cr::meta
{
[[noreturn]] inline void unreachable()
{
#ifdef __GNUC__ // GCC, Clang, ICC
__builtin_unreachable();
#else
#ifdef _MSC_VER // MSVC
__assume(false);
#endif
#endif
}
template<typename... Ts>
struct FirstOfVariadic
{
using type = void;
};
template<typename T, typename... Ts>
struct FirstOfVariadic<T, Ts...>
{
using type = T;
};
template<int count, typename... Ts>
struct NthOfVariadic
{
using type = void;
};
template<int count, typename T, typename... Ts>
struct NthOfVariadic<count, T, Ts...>
{
using type = typename NthOfVariadic<count - 1, Ts...>::type;
};
template<typename T, typename... Ts>
struct NthOfVariadic<0, T, Ts...>
{
using type = T;
};
template<typename... Ts>
struct VariadicTypenameCache
{
template<typename T>
static constexpr bool contains_base_of()
{
return false;
}
template<typename T>
static constexpr bool contains()
{
return false;
}
};
template<typename T, typename... Ts>
struct VariadicTypenameCache<T, Ts...>
{
template<typename T_>
static constexpr bool contains_base_of()
{
if constexpr (::std::is_base_of_v<T, T_>)
{
return true;
}
else
{
return VariadicTypenameCache<Ts...>::template contains_base_of<T_>();
}
}
template<typename T_>
static constexpr bool contains()
{
if constexpr (::std::is_same_v<T, T_>)
{
return true;
}
else
{
return VariadicTypenameCache<Ts...>::template contains<T_>();
}
}
};
template<template<typename...> typename target, typename... finiteArgs>
struct extract_variadic
{
template<typename... variadic>
static auto forward(::cr::meta::VariadicTypenameCache<variadic...>)
{
using new_forwarded_type = target<finiteArgs..., variadic...>;
return new_forwarded_type{};
//return std::declval<new_forwarded_type>();
}
template<typename... infiniteArgs_>
struct insert_tmp
{
template<typename... variadic>
static auto forward(::cr::meta::VariadicTypenameCache<variadic...>)
{
using new_forwarded_type = target<finiteArgs..., infiniteArgs_..., variadic...>;
return new_forwarded_type{};
}
};
template<typename org, typename... variadic>
static auto forward_p(org, ::cr::meta::VariadicTypenameCache<variadic...>)
{
using new_forwarded_type = decltype(insert_tmp<variadic...>::template forward(std::declval<org>()));
return new_forwarded_type{};
}
template<typename first, typename... variadic>
static auto forward_skip_first(::cr::meta::VariadicTypenameCache<first, variadic...>)
{
using new_forwarded_type = target<finiteArgs..., variadic...>;
return new_forwarded_type{};
//return std::declval<new_forwarded_type>();
}
template<typename blacklistedTypes, typename first, typename... variadic>
static auto forward_skip_until_not_of(::cr::meta::VariadicTypenameCache<first, variadic...>)
{
if constexpr (blacklistedTypes
::template contains<first>())
{
return forward_skip_until_not_of<blacklistedTypes>(::cr::meta::VariadicTypenameCache<variadic...>{});
}
else
{
using new_forwarded_type = target<finiteArgs..., first, variadic...>;
return new_forwarded_type{};
}
}
template<typename blacklistedBases, typename first, typename... variadic>
static auto forward_skip_until_not_sub_of(::cr::meta::VariadicTypenameCache<first, variadic...>)
{
if constexpr (blacklistedBases
::template contains_base_of<first>())
{
return forward_skip_until_not_sub_of<blacklistedBases>(::cr::meta::VariadicTypenameCache<variadic...>{});
}
else
{
using new_forwarded_type = target<finiteArgs..., first, variadic...>;
return new_forwarded_type{};
}
}
template<typename variadic>
using forward_t = decltype(forward(std::declval<variadic>()));
template<typename variadic>
using forward_skip_first_t = decltype(forward_skip_first(std::declval<variadic>()));
template<typename blacklistedBases, typename variadic>
using forward_skip_until_not_sub_of_t = decltype(forward_skip_until_not_sub_of<blacklistedBases>(std::declval<variadic>()));
template<typename blacklistedBases, typename variadic>
using forward_skip_until_not_of_t = decltype(forward_skip_until_not_of<blacklistedBases>(std::declval<variadic>()));
};
}
namespace cr::gen
{
template<typename returnType_, typename... statements>
struct logic
{
using returnType = returnType_;
using stmts = typename ::cr::meta::VariadicTypenameCache<statements...>;
};
// Used to avoid issues with return type evaluation with recursive functions.
struct stop_evaluation_base {};
struct stop_evaluation : stop_evaluation_base
{};
struct noop_base {};
struct noop : noop_base
{};
struct end_function_base {};
struct end_function : end_function_base
{};
struct scope_base {};
template<typename... scope_stmts>
struct scope : scope_base
{
using type = ::cr::meta::VariadicTypenameCache<scope_stmts...>;
};
struct echo_base {};
template<typename echo_stmt>
struct echo : echo_base
{
using type = echo_stmt;
};
// Temporary ID
struct tid_base {};
template<int id>
struct tid : tid_base
{
static constexpr int value = id;
};
struct vid_base {};
template<int id>
struct vid : vid_base
{
static constexpr int value = id;
};
struct uid_base {};
template<int id>
struct uid : uid_base
{
static constexpr int value = id;
};
struct id_base {};
template<typename expr>
struct id : id_base
{
using type = expr;
};
struct create_variable_base {};
template<typename... Ts>
struct create_variable : create_variable_base
{
};
// Automatically deduce the type given the initialize statement
template<typename T>
struct create_variable<T> : create_variable_base
{
using initialize_stmt = T;
};
template<typename T, typename Q>
struct create_variable<T, Q> : create_variable_base
{
using type = T;
using initialize_stmt = Q;
};
struct return_variable_base {};
template<typename T>
struct return_variable : return_variable_base
{
using return_stmt = T;
};
struct create_int_base {};
template<int val_>
struct create_int : create_int_base
{
static constexpr int value = val_;
};
struct create_bool_base {};
template<bool val_>
struct create_bool : create_bool_base
{
static constexpr bool value = val_;
};
// Represents this pointer
struct this_base {};
struct thi : this_base
{
};
// Accesses user + temporary variables
// Variable reference, where id == variable id
struct var_base {};
template<int id>
struct var : var_base
{
static constexpr int value = id;
};
// Temporary Variable reference, where id == variable id
struct tvar_base {};
template<int id>
struct tvar : tvar_base
{
static constexpr int value = id;
};
// User Variable reference, where id == variable id
struct uvar_base {};
template<int id>
struct uvar : uvar_base
{
static constexpr int value = id;
};
// Assign and continue
struct asc_base {};
template<typename LHS_, typename RHS_>
struct asc : asc_base
{
using lhs = LHS_;
using rhs = RHS_;
};
struct ass_base {};
template<typename LHS_, typename RHS_>
struct ass : ass_base
{
using lhs = LHS_;
using rhs = RHS_;
};
struct add_base {};
template<typename LHS_, typename RHS_>
struct add : add_base
{
using lhs = LHS_;
using rhs = RHS_;
};
struct min_base {};
template<typename LHS_, typename RHS_>
struct min : min_base
{
using lhs = LHS_;
using rhs = RHS_;
};
struct mul_base {};
template<typename LHS_, typename RHS_>
struct mul : mul_base
{
using lhs = LHS_;
using rhs = RHS_;
};
struct div_base {};
template<typename LHS_, typename RHS_>
struct div : div_base
{
using lhs = LHS_;
using rhs = RHS_;
};
struct mod_base {};
template<typename LHS_, typename RHS_>
struct mod : mod_base
{
using lhs = LHS_;
using rhs = RHS_;
};
struct eq_base {};
template<typename LHS_, typename RHS_>
struct eq : eq_base
{
using lhs = LHS_;
using rhs = RHS_;
};
struct gt_base {};
template<typename LHS_, typename RHS_>
struct gt : gt_base
{
using lhs = LHS_;
using rhs = RHS_;
};
struct gteq_base {};
template<typename LHS_, typename RHS_>
struct gteq : gteq_base
{
using lhs = LHS_;
using rhs = RHS_;
};
struct lt_base {};
template<typename LHS_, typename RHS_>
struct lt : lt_base
{
using lhs = LHS_;
using rhs = RHS_;
};
struct lteq_base {};
template<typename LHS_, typename RHS_>
struct lteq : lteq_base
{
using lhs = LHS_;
using rhs = RHS_;
};
struct if_base {};
template<typename conditional_stmt_, typename action_stmt_>
struct iff : if_base
{
using conditional_stmt = conditional_stmt_;
using action_stmt = action_stmt_;
};
struct elif_base {};
template<typename conditional_stmt_, typename action_stmt_>
struct elif : elif_base
{
using conditional_stmt = conditional_stmt_;
using action_stmt = action_stmt_;
};
struct while_base {};
template<typename conditional_stmt_, typename action_stmt_>
struct whil : while_base
{
using conditional_stmt = conditional_stmt_;
using action_stmt = action_stmt_;
};
struct else_base {};
template<typename action_stmt_>
struct els : else_base
{
using action_stmt = action_stmt_;
};
struct forc_base {};
template<int count, typename for_count_stmt_>
struct forc : forc_base
{
static constexpr int value = count;
using action_stmt = for_count_stmt_;
};
}
namespace cr::gen
{
namespace interpreter
{
template<typename originalDatastructure, typename memberFunction, typename... stmts>
struct parse_stmts
{
template<int user_argument_count, typename... Arguments>
static inline typename memberFunction::returnType function_impl(Arguments... args [[maybe_unused]])
{
return typename memberFunction::returnType{};
}
};
template<typename originalDatastructure, typename memberFunction, typename stmt, typename... stmts>
struct parse_stmts<originalDatastructure, memberFunction, stmt, stmts...>
{
template<int user_argument_count, typename... Arguments>
static inline typename memberFunction::returnType function_start(Arguments&&... args [[maybe_unused]])
{
return function_impl<user_argument_count>(args...);
}
template<int user_argument_count, typename... Arguments>
static inline auto function_impl(Arguments&&... args [[maybe_unused]])
{
return function_impl_dispatcher<user_argument_count>(args...);
}
template<int user_argument_count, typename... Arguments>
static inline auto function_impl_dispatcher(Arguments&&... args [[maybe_unused]])
{
// Dispatcher for stmt resolvement
// Uses a concrete base check, to validate the type of stmt
if constexpr(std::is_base_of_v<stop_evaluation_base, stmt>)
{
return ::cr::gen::interpreter
::parse_stmts<originalDatastructure, memberFunction, stmts...>::template function_impl<user_argument_count>(args...);
}
else if constexpr(std::is_base_of_v<end_function_base, stmt>)
{
return;
}
else if constexpr (std::is_base_of_v<scope_base, stmt>)
{
// Find something to extract 2 variadic statements
using inlined_scope = decltype(::cr::meta::extract_variadic<parse_stmts, originalDatastructure, memberFunction>::forward_p(
::cr::meta::VariadicTypenameCache<stmts...>{},
typename stmt::type{}
));
return inlined_scope::template function_impl<user_argument_count>(args...);
}
else if constexpr (std::is_base_of_v<tid_base, stmt>)
{
return ::cr::gen::interpreter
::parse_stmts<originalDatastructure, memberFunction, stmt, stmts...>
::template function_temporary_id<user_argument_count>(args...);
}
else if constexpr (std::is_base_of_v<echo_base, stmt>)
{
return ::cr::gen::interpreter
::parse_stmts<originalDatastructure, memberFunction, stmt, stmts...>
::template function_echo<user_argument_count>(args...);
}
else if constexpr (std::is_base_of_v<create_variable_base, stmt>)
{
return ::cr::gen::interpreter
::parse_stmts<originalDatastructure, memberFunction, stmt, stmts...>
::template function_create_variable<user_argument_count>(args...);
}
else if constexpr(std::is_base_of_v<create_int_base, stmt>)
{
return ::cr::gen::interpreter
::parse_stmts<originalDatastructure, memberFunction, stmt, stmts...>
::template function_create_int<user_argument_count>(args...);
}
else if constexpr(std::is_base_of_v<create_bool_base, stmt>)
{
return ::cr::gen::interpreter
::parse_stmts<originalDatastructure, memberFunction, stmt, stmts...>
::template function_create_bool<user_argument_count>(args...);
}
else if constexpr(std::is_base_of_v<return_variable_base, stmt>)
{
return ::cr::gen::interpreter
::parse_stmts<originalDatastructure, memberFunction, stmt, stmts...>
::template function_return_variable<user_argument_count>(args...);
}
else if constexpr(std::is_base_of_v<var_base, stmt>)
{
return ::cr::gen::interpreter
::parse_stmts<originalDatastructure, memberFunction, stmt, stmts...>
::template function_var<user_argument_count>(args...);
}
else if constexpr(std::is_base_of_v<tvar_base, stmt>)
{
return ::cr::gen::interpreter
::parse_stmts<originalDatastructure, memberFunction, stmt, stmts...>
::template function_tvar<user_argument_count>(args...);
}
else if constexpr(std::is_base_of_v<uvar_base, stmt>)
{
return ::cr::gen::interpreter
::parse_stmts<originalDatastructure, memberFunction, stmt, stmts...>
::template function_uvar<user_argument_count>(args...);
}
else if constexpr(std::is_base_of_v<add_base, stmt>)
{
return ::cr::gen::interpreter
::parse_stmts<originalDatastructure, memberFunction, stmt, stmts...>
::template function_add<user_argument_count>(args...);
}
else if constexpr(std::is_base_of_v<min_base, stmt>)
{
return ::cr::gen::interpreter
::parse_stmts<originalDatastructure, memberFunction, stmt, stmts...>
::template function_subtract<user_argument_count>(args...);
}
else if constexpr(std::is_base_of_v<mul_base, stmt>)
{
return ::cr::gen::interpreter
::parse_stmts<originalDatastructure, memberFunction, stmt, stmts...>
::template function_multiply<user_argument_count>(args...);
}
else if constexpr(std::is_base_of_v<div_base, stmt>)
{
return ::cr::gen::interpreter
::parse_stmts<originalDatastructure, memberFunction, stmt, stmts...>
::template function_divide<user_argument_count>(args...);
}
else if constexpr(std::is_base_of_v<mod_base, stmt>)
{
return ::cr::gen::interpreter
::parse_stmts<originalDatastructure, memberFunction, stmt, stmts...>
::template function_mod<user_argument_count>(args...);
}
else if constexpr(std::is_base_of_v<eq_base, stmt>)
{
return ::cr::gen::interpreter
::parse_stmts<originalDatastructure, memberFunction, stmt, stmts...>
::template function_eq<user_argument_count>(args...);
}
else if constexpr(std::is_base_of_v<gteq_base, stmt>)
{
return ::cr::gen::interpreter
::parse_stmts<originalDatastructure, memberFunction, stmt, stmts...>
::template function_gteq<user_argument_count>(args...);
}
else if constexpr(std::is_base_of_v<lteq_base, stmt>)
{
return ::cr::gen::interpreter
::parse_stmts<originalDatastructure, memberFunction, stmt, stmts...>
::template function_lteq<user_argument_count>(args...);
}
else if constexpr(std::is_base_of_v<gt_base, stmt>)
{
return ::cr::gen::interpreter
::parse_stmts<originalDatastructure, memberFunction, stmt, stmts...>
::template function_gt<user_argument_count>(args...);
}
else if constexpr(std::is_base_of_v<lt_base, stmt>)
{
return ::cr::gen::interpreter
::parse_stmts<originalDatastructure, memberFunction, stmt, stmts...>
::template function_lt<user_argument_count>(args...);
}
else if constexpr(std::is_base_of_v<if_base, stmt>)
{
return ::cr::gen::interpreter
::parse_stmts<originalDatastructure, memberFunction, stmt, stmts...>
::template function_if<user_argument_count>(args...);
}
else if constexpr(std::is_base_of_v<elif_base, stmt>)
{
return ::cr::gen::interpreter
::parse_stmts<originalDatastructure, memberFunction, stmt, stmts...>
::template function_elif<user_argument_count>(args...);
}
else if constexpr(std::is_base_of_v<else_base, stmt>)
{
return ::cr::gen::interpreter
::parse_stmts<originalDatastructure, memberFunction, stmt, stmts...>
::template function_else<user_argument_count>(args...);
}
else if constexpr(std::is_base_of_v<forc_base, stmt>)
{
return ::cr::gen::interpreter
::parse_stmts<originalDatastructure, memberFunction, stmt, stmts...>
::template function_forc<user_argument_count>(args...);
}
else if constexpr(std::is_base_of_v<while_base, stmt>)
{
if constexpr(!std::is_same_v<typename ::cr::meta::FirstOfVariadic<stmts...>::type, stop_evaluation>)
{
return ::cr::gen::interpreter
::parse_stmts<originalDatastructure, memberFunction, stmt, stmts...>
::template function_while<user_argument_count>(args...);
}
else
{
if constexpr (sizeof...(stmts) == 0)
{
::cr::gen::interpreter
::parse_stmts<originalDatastructure, memberFunction, stmt, stmts...>
::template function_while_void<user_argument_count>(args...);
return typename memberFunction::returnType{};
}
else
{
return ::cr::gen::interpreter
::parse_stmts<originalDatastructure, memberFunction, stmt, stmts...>
::template function_while_next<user_argument_count>(args...);
}
}
}
else if constexpr(std::is_base_of_v<ass_base, stmt>)
{
return ::cr::gen::interpreter
::parse_stmts<originalDatastructure, memberFunction, stmt, stmts...>
::template function_assign<user_argument_count>(args...);
}
else if constexpr(std::is_base_of_v<asc_base, stmt>)
{
return ::cr::gen::interpreter
::parse_stmts<originalDatastructure, memberFunction, stmt, stmts...>
::template function_assign_and_continue<user_argument_count>(args...);
}
else
{
return typename memberFunction::returnType{};
}
}
template<int user_argument_count, typename... Arguments>
static inline auto function_echo(Arguments&&... args [[maybe_unused]])
{
auto val = ::cr::gen::interpreter
::parse_stmts<originalDatastructure, memberFunction, typename stmt::type>
::template function_impl<user_argument_count>(args...);
std::cout << val << "\n";
return ::cr::gen::interpreter
::parse_stmts<originalDatastructure, memberFunction, stmts...>
::template function_impl<user_argument_count>(args...);
}
template<int user_argument_count, typename... Arguments>
static inline auto function_create_variable(Arguments&&... args [[maybe_unused]])
{
typename stmt::type new_tmp_variable = ::cr::gen::interpreter
::parse_stmts<originalDatastructure, memberFunction, typename stmt::initialize_stmt>
::template function_impl<user_argument_count>(args...);
return ::cr::gen::interpreter
::parse_stmts<originalDatastructure, memberFunction, stmts...>
::template function_impl<user_argument_count, Arguments..., typename stmt::type&>(args..., new_tmp_variable);
}
template<int count, typename Argument, typename... Arguments>
static inline auto& get_argument(Argument&& arg [[maybe_unused]], Arguments&&... args [[maybe_unused]])
{
if constexpr(count <= 0)
{
return (Argument&)arg;
}
else
{
if constexpr (sizeof...(Arguments) == 0)
{
// Error, not possible to expand
return ::cr::meta::unreachable();
}
else
{
return get_argument<count - 1>(args...);
}
}
}
template<int user_limit, int count, typename Argument, typename... Arguments>
static inline auto& get_user_argument(Argument&& arg [[maybe_unused]], Arguments&&... args [[maybe_unused]])
{
// We reached the end
if constexpr (count == user_limit + 1)
{
// Error, not possible to expand
return ::cr::meta::unreachable();
}
if constexpr (count <= 0)
{
return (Argument&)arg;
}
else
{
if constexpr (sizeof...(Arguments) == 0)
{
// Error, not possible to expand
return ::cr::meta::unreachable();
}
else
{
return get_user_argument<user_limit, count - 1>(args...);
}
}
}
template<int count, typename Argument, typename... Arguments>
static inline auto& get_temporary_argument(Argument&& arg [[maybe_unused]], Arguments&&... args [[maybe_unused]])
{
if constexpr(count <= 0)
{
return (Argument&)arg;
}
else
{
if constexpr (sizeof...(Arguments) == 0)
{
// Error, not possible to expand
return ::cr::meta::unreachable();
}
else
{
return get_temporary_argument<count - 1>(args...);
}
}
}
template<int user_argument_count, typename... Arguments>
static inline auto function_var(Arguments&&... args [[maybe_unused]])
{
if constexpr (sizeof...(Arguments) == 0)
{
// Error, nothing to retrieve
return;
}
else if constexpr (stmt::value >= sizeof...(Arguments))
{
// Tried to access argument that does not exist
return;
}
else
{
return get_argument<stmt::value + 1>(args...);
}
}
template<int user_argument_count, typename... Arguments>
static inline auto function_uvar(Arguments&&... args [[maybe_unused]])
{
if constexpr (sizeof...(Arguments) == 0)
{
// Error, nothing to retrieve
return;
}
else if constexpr (stmt::value >= sizeof...(Arguments))
{
// Tried to access argument that does not exist
return;
}
else
{
return get_user_argument<user_argument_count, stmt::value + 1>(args...);
}
}
template<int user_argument_count, typename... Arguments>
static inline int function_uid(Arguments&&... args [[maybe_unused]])
{
return stmt::value;
}
template<int user_argument_count, typename... Arguments>
static inline int function_temporary_id(Arguments&&... args [[maybe_unused]])
{
return user_argument_count + stmt::value;
}
template<int user_argument_count, typename... Arguments>
static inline auto function_tvar(Arguments&&... args [[maybe_unused]])
{
if constexpr (sizeof...(Arguments) == 0)
{
// Error, nothing to retrieve
return;
}
else if constexpr (stmt::value >= sizeof...(Arguments))
{
// Tried to access argument that does not exist
return;
}
else
{
return get_temporary_argument<stmt::value + 1 + user_argument_count>(args...);
}
}
template<int user_argument_count, typename... Arguments>
static inline int function_create_int(Arguments&&... args [[maybe_unused]])
{
return stmt::value;
}
template<int user_argument_count, typename... Arguments>
static inline bool function_create_bool(Arguments&&... args [[maybe_unused]])
{
return stmt::value;
}
template<int user_argument_count, typename... Arguments>
static inline auto function_add(Arguments&&... args [[maybe_unused]])
{
return ::cr::gen::interpreter
::parse_stmts<originalDatastructure, memberFunction, typename stmt::lhs>
::template function_impl<user_argument_count, Arguments...>(args...)
+
::cr::gen::interpreter
::parse_stmts<originalDatastructure, memberFunction, typename stmt::rhs>
::template function_impl<user_argument_count, Arguments...>(args...);
}
template<int user_argument_count, typename... Arguments>
static inline auto function_multiply(Arguments&&... args [[maybe_unused]])
{
return ::cr::gen::interpreter
::parse_stmts<originalDatastructure, memberFunction, typename stmt::lhs>
::template function_impl<user_argument_count, Arguments...>(args...)
*
::cr::gen::interpreter
::parse_stmts<originalDatastructure, memberFunction, typename stmt::rhs>
::template function_impl<user_argument_count, Arguments...>(args...);
}
template<int user_argument_count, typename... Arguments>
static inline auto function_divide(Arguments&&... args [[maybe_unused]])
{
return ::cr::gen::interpreter
::parse_stmts<originalDatastructure, memberFunction, typename stmt::lhs>
::template function_impl<user_argument_count, Arguments...>(args...)
/
::cr::gen::interpreter
::parse_stmts<originalDatastructure, memberFunction, typename stmt::rhs>
::template function_impl<user_argument_count, Arguments...>(args...);
}
template<int user_argument_count, typename... Arguments>
static inline auto function_mod(Arguments&&... args [[maybe_unused]])
{
return ::cr::gen::interpreter
::parse_stmts<originalDatastructure, memberFunction, typename stmt::lhs>
::template function_impl<user_argument_count, Arguments...>(args...)
%
::cr::gen::interpreter
::parse_stmts<originalDatastructure, memberFunction, typename stmt::rhs>
::template function_impl<user_argument_count, Arguments...>(args...);
}
template<int user_argument_count, typename... Arguments>
static inline auto function_assign(Arguments&&... args [[maybe_unused]])
{
return ::cr::gen::interpreter
::parse_stmts<originalDatastructure, memberFunction, typename stmt::lhs>
::template function_impl<user_argument_count, Arguments...>(args...)
=
::cr::gen::interpreter
::parse_stmts<originalDatastructure, memberFunction, typename stmt::rhs>
::template function_impl<user_argument_count, Arguments...>(args...);
}
template<int user_argument_count, typename... Arguments>
static inline auto function_assign_and_continue(Arguments&&... args [[maybe_unused]])
{
// Assign and continue to the next statement.
if constexpr(std::is_base_of_v<tid_base, typename stmt::lhs>)
{
get_argument<stmt::lhs::value + user_argument_count + 1>(args...)
=
::cr::gen::interpreter
::parse_stmts<originalDatastructure, memberFunction, typename stmt::rhs>
::template function_impl<user_argument_count>(args...);
}
else if constexpr(std::is_base_of_v<uid_base, typename stmt::lhs>)
{
get_argument<stmt::lhs::value + 1>(args...)
=
::cr::gen::interpreter
::parse_stmts<originalDatastructure, memberFunction, typename stmt::rhs>
::template function_impl<user_argument_count>(args...);
}
return ::cr::gen::interpreter
::parse_stmts<originalDatastructure, memberFunction, stmts...>
::template function_impl<user_argument_count>(args...);
}
template<int user_argument_count, typename... Arguments>
static inline auto function_eq(Arguments&&... args [[maybe_unused]])
{
return ::cr::gen::interpreter
::parse_stmts<originalDatastructure, memberFunction, typename stmt::lhs>
::template function_impl<user_argument_count, Arguments...>(args...)
==
::cr::gen::interpreter
::parse_stmts<originalDatastructure, memberFunction, typename stmt::rhs>
::template function_impl<user_argument_count, Arguments...>(args...);
}
template<int user_argument_count, typename... Arguments>
static inline auto function_gt(Arguments&&... args [[maybe_unused]])
{
return ::cr::gen::interpreter
::parse_stmts<originalDatastructure, memberFunction, typename stmt::lhs>
::template function_impl<user_argument_count, Arguments...>(args...)
>
::cr::gen::interpreter
::parse_stmts<originalDatastructure, memberFunction, typename stmt::rhs>
::template function_impl<user_argument_count, Arguments...>(args...);
}
template<int user_argument_count, typename... Arguments>
static inline auto function_gteq(Arguments&&... args [[maybe_unused]])
{
return ::cr::gen::interpreter
::parse_stmts<originalDatastructure, memberFunction, typename stmt::lhs>
::template function_impl<user_argument_count, Arguments...>(args...)
>=
::cr::gen::interpreter
::parse_stmts<originalDatastructure, memberFunction, typename stmt::rhs>
::template function_impl<user_argument_count, Arguments...>(args...);
}