-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHTLL.cpp
More file actions
9181 lines (9148 loc) · 429 KB
/
HTLL.cpp
File metadata and controls
9181 lines (9148 loc) · 429 KB
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
#if __has_include("srell.hpp")
#include "srell.hpp"
#define USE_POWERFUL_REGEX 1
#pragma message("SUCCESS: Compiling with powerful SRELL regex engine. Lookbehinds will work.")
#else
#include <regex>
#define USE_POWERFUL_REGEX 0
#pragma message("WARNING: srell.hpp not found. Falling back to limited std::regex. Lookbehinds will NOT work.")
#endif
#include <algorithm>
#include <any>
#include <cctype>
#include <cstdint>
#include <cstdio>
#include <fstream>
#include <iostream>
#include <optional>
#include <regex>
#include <sstream>
#include <stdexcept>
#include <string>
#include <type_traits>
#include <vector>
// Function to escape special characters for regex
std::string escapeRegex(const std::string& str) {
static const std::regex specialChars{R"([-[\]{}()*+?.,\^$|#\s])"};
return std::regex_replace(str, specialChars, R"(\$&)");
}
// Function to split a string based on delimiters
std::vector<std::string> LoopParseFunc(const std::string& var, const std::string& delimiter1 = "", const std::string& delimiter2 = "") {
std::vector<std::string> items;
if (delimiter1.empty() && delimiter2.empty()) {
// If no delimiters are provided, return a list of characters
for (char c : var) {
items.push_back(std::string(1, c));
}
} else {
// Escape delimiters for regex
std::string escapedDelimiters = escapeRegex(delimiter1 + delimiter2);
// Construct the regular expression pattern for splitting the string
std::string pattern = "[" + escapedDelimiters + "]+";
std::regex regexPattern(pattern);
std::sregex_token_iterator iter(var.begin(), var.end(), regexPattern, -1);
std::sregex_token_iterator end;
while (iter != end) {
items.push_back(*iter++);
}
}
return items;
}
// Print function for const char*
void print(const char* value) {
std::cout << std::string(value) << std::endl;
}
// Handle signed 8-bit integers
void print(int8_t value) {
std::cout << static_cast<int>(value) << std::endl;
}
// Handle unsigned 8-bit integers
void print(uint8_t value) {
std::cout << static_cast<unsigned int>(value) << std::endl;
}
// Generic print function fallback
template <typename T>
void print(const T& value) {
std::cout << value << std::endl;
}
// Convert std::string to int
int INT(const std::string& str) {
std::istringstream iss(str);
int value;
iss >> value;
return value;
}
// Convert various types to std::string
std::string STR(int value) {
return std::to_string(value);
}
// Convert various types to std::string
std::string STR(long long value) {
return std::to_string(value);
}
std::string STR(float value) {
return std::to_string(value);
}
std::string STR(double value) {
return std::to_string(value);
}
std::string STR(size_t value) {
return std::to_string(value);
}
std::string STR(bool value) {
return value ? "1" : "0";
}
std::string STR(const char* value) {
return std::string(value);
}
std::string STR(const std::string& value) {
return value;
}
// Function to find the position of needle in haystack (std::string overload)
int InStr(const std::string& haystack, const std::string& needle) {
size_t pos = haystack.find(needle);
return (pos != std::string::npos) ? static_cast<int>(pos) + 1 : 0;
}
std::string FileRead(const std::string& path) {
// This function relies on <fstream>, which is already in your global includes.
std::ifstream file(path);
if (!file.is_open()) {
throw std::runtime_error("Error: Could not open the file: " + path);
}
std::string content;
std::string line;
while (std::getline(file, line)) {
content += line + '\n';
}
file.close();
return content;
}
bool FileAppend(const std::string& content, const std::string& path) {
std::ofstream file;
// Open the file in append mode
file.open(path, std::ios::app);
if (!file.is_open()) {
std::cerr << "Error: Could not open the file for appending." << std::endl;
return false;
}
// Append the content to the file
file << content;
// Close the file
file.close();
return true;
}
bool FileDelete(const std::string& path) {
return std::remove(path.c_str()) == 0;
}
size_t StrLen(const std::string& str) {
return str.length();
}
int Asc(const std::string& str) {
if (!str.empty()) {
return static_cast<int>(str[0]);
}
return -1; // Return -1 if the string is empty
}
std::string SubStr(const std::string& str, int startPos, int length = -1) {
std::string result;
size_t strLen = str.size();
// Handle negative starting positions (counting from the end)
if (startPos < 0) {
startPos = strLen + startPos;
if (startPos < 0) startPos = 0; // Ensure it doesn't go beyond the start of the string
}
else {
startPos -= 1; // Convert to 0-based index for internal operations
}
// Handle length
if (length < 0) {
length = strLen - startPos; // Length to the end of the string
} else if (startPos + length > static_cast<int>(strLen)) {
length = strLen - startPos; // Adjust length to fit within the string
}
// Extract the substring
result = str.substr(startPos, length);
return result;
}
std::string Trim(const std::string &inputString) {
if (inputString.empty()) return "";
size_t start = inputString.find_first_not_of(" \t\n\r\f\v");
size_t end = inputString.find_last_not_of(" \t\n\r\f\v");
return (start == std::string::npos) ? "" : inputString.substr(start, end - start + 1);
}
std::string StrReplace(const std::string &originalString, const std::string &find, const std::string &replaceWith) {
std::string result = originalString;
size_t pos = 0;
while ((pos = result.find(find, pos)) != std::string::npos) {
result.replace(pos, find.length(), replaceWith);
pos += replaceWith.length();
}
return result;
}
std::string StringTrimLeft(const std::string &input, int numChars) {
return (numChars <= input.length()) ? input.substr(numChars) : input;
}
std::string StringTrimRight(const std::string &input, int numChars) {
return (numChars <= input.length()) ? input.substr(0, input.length() - numChars) : input;
}
std::string StrLower(const std::string &string) {
std::string result = string;
std::transform(result.begin(), result.end(), result.begin(), ::tolower);
return result;
}
std::string StrSplit(const std::string &inputStr, const std::string &delimiter, int num) {
size_t start = 0, end = 0, count = 0;
while ((end = inputStr.find(delimiter, start)) != std::string::npos) {
if (++count == num) {
return inputStr.substr(start, end - start);
}
start = end + delimiter.length();
}
if (count + 1 == num) {
return inputStr.substr(start);
}
return "";
}
std::string Chr(int number) {
return (number >= 0 && number <= 0x10FFFF) ? std::string(1, static_cast<char>(number)) : "";
}
int Mod(int dividend, int divisor) {
return dividend % divisor;
}
// Function to check if the operating system is Windows
bool isWindows() {
#ifdef _WIN32
return true;
#else
return false;
#endif
}
#ifdef _WIN32
#define ARGC __argc
#define ARGV __argv
#else
extern char **environ;
int ARGC;
char** ARGV;
__attribute__((constructor)) void init_args(int argc, char* argv[], char* envp[]) {
ARGC = argc;
ARGV = argv;
}
#endif
std::string GetParams() {
// [FIX] This function is now safe as it does not use std::filesystem.
std::vector<std::string> params;
for (int i = 1; i < ARGC; ++i) {
params.push_back(ARGV[i]);
}
std::string result;
for (const auto& param : params) {
result += param + "\n";
}
return result;
}
std::string RegExReplace(std::string_view inputStr, std::string_view regexPattern, std::string_view replacement) {
#if USE_POWERFUL_REGEX
// --- SRELL PATH ---
try {
const srell::regex re = srell::regex(regexPattern.data(), regexPattern.size());
return srell::regex_replace(std::string(inputStr), re, std::string(replacement));
} catch (const srell::regex_error& e) {
// ERROR IS CAUGHT, BUT WE DO NOTHING. NO MORE MESSAGE.
return std::string(inputStr); // Return original string on failure
}
#else
// --- FALLBACK PATH ---
try {
const std::regex re{std::string(regexPattern)};
return std::regex_replace(std::string(inputStr), re, std::string(replacement));
} catch (const std::regex_error& e) {
// ERROR IS CAUGHT, BUT WE DO NOTHING. NO MORE MESSAGE.
return std::string(inputStr); // Return original string on failure
}
#endif
}
int RegExMatch(std::string_view haystack, std::string_view needle) {
#if USE_POWERFUL_REGEX
// --- SRELL PATH ---
try {
const srell::regex re = srell::regex(needle.data(), needle.size());
srell::cmatch match;
if (srell::regex_search(haystack.data(), haystack.data() + haystack.size(), match, re)) {
return match.position(0) + 1;
}
} catch (const srell::regex_error& e) {
// ERROR IS CAUGHT, BUT WE DO NOTHING. NO MORE MESSAGE.
}
#else
// --- FALLBACK PATH ---
try {
const std::regex re{std::string(needle)};
std::match_results<std::string_view::const_iterator> match;
if (std::regex_search(haystack.begin(), haystack.end(), match, re)) {
return match.position(0) + 1;
}
} catch (const std::regex_error& e) {
// ERROR IS CAUGHT, BUT WE DO NOTHING. NO MORE MESSAGE.
}
#endif
return 0; // Return 0 on failure
}
// Overload for counting a single character
int countChars(const std::string& str, char theChar) {
int count = 0;
for (char c : str) {
if (c == theChar) {
count++;
}
}
return count;
}
// Overload for counting a substring
int countChars(const std::string& str, const std::string& substring) {
if (substring.empty()) return 0; // Avoid infinite loop
int count = 0;
size_t pos = 0;
// Find occurrences of the substring
while ((pos = str.find(substring, pos)) != std::string::npos) {
count++;
pos += substring.length(); // Move past the found substring
}
return count;
}
void HTVM_Append(std::vector<std::string>& arr, const std::string& value) {
arr.push_back(value);
}
void HTVM_Append(std::vector<std::string>& arr, const char* value) {
arr.push_back(std::string(value));
}
void HTVM_Append(std::vector<int>& arr, int value) {
arr.push_back(value);
}
void HTVM_Append(std::vector<float>& arr, float value) {
arr.push_back(value);
}
void HTVM_Append(std::vector<bool>& arr, bool value) {
arr.push_back(value);
}
void HTVM_Pop(std::vector<std::string>& arr) {
if (!arr.empty()) arr.pop_back();
}
void HTVM_Pop(std::vector<int>& arr) {
if (!arr.empty()) arr.pop_back();
}
void HTVM_Pop(std::vector<float>& arr) {
if (!arr.empty()) arr.pop_back();
}
void HTVM_Pop(std::vector<bool>& arr) {
if (!arr.empty()) arr.pop_back();
}
size_t HTVM_Size(const std::vector<std::string>& arr) {
return arr.size();
}
size_t HTVM_Size(const std::vector<int>& arr) {
return arr.size();
}
size_t HTVM_Size(const std::vector<float>& arr) {
return arr.size();
}
size_t HTVM_Size(const std::vector<bool>& arr) {
return arr.size();
}
// start of HT-Lib.htvm
// HT-Lib - A Library for Creating Programming Languages
// Copyright (C) 2025 TheMaster1127
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// global vars NEEDED
int HT_LIB_theIdNumOfThe34 = 0;
std::vector<std::string> HT_Lib_theIdNumOfThe34theVar;
//;;;;;;;;;;;;;;;;;;;;;;;;;
std::string preserveStrings(std::string code, std::string keyWordEscpaeChar = "\\") {
std::vector<std::string> getAllCharForTheFurtureSoIcanAddEscapeChar;
std::string ReplaceFixWhitOutFixDoubleQuotesInsideDoubleQuotes = "";
std::string str21 = "";
std::string htCodeOUT754754 = "";
std::string OutFixDoubleQuotesInsideDoubleQuotes = "";
int fixOutFixDoubleQuotesInsideDoubleQuotesFIXok = 0;
int removeNexFixkeyWordEscpaeChar = 0;
int areWEinSome34sNum = 0;
std::vector<std::string> items1 = LoopParseFunc(code);
for (size_t A_Index1 = 0; A_Index1 < items1.size(); A_Index1++) {
std::string A_LoopField1 = items1[A_Index1 - 0];
HTVM_Append(HT_Lib_theIdNumOfThe34theVar, "");
HTVM_Append(HT_Lib_theIdNumOfThe34theVar, "");
}
std::vector<std::string> items2 = LoopParseFunc(code);
for (size_t A_Index2 = 0; A_Index2 < items2.size(); A_Index2++) {
std::string A_LoopField2 = items2[A_Index2 - 0];
HT_Lib_theIdNumOfThe34theVar[A_Index2] = HT_Lib_theIdNumOfThe34theVar[A_Index2] + Chr(34);
HTVM_Append(getAllCharForTheFurtureSoIcanAddEscapeChar, A_LoopField2);
}
HTVM_Append(getAllCharForTheFurtureSoIcanAddEscapeChar, " ");
ReplaceFixWhitOutFixDoubleQuotesInsideDoubleQuotes = Chr(34) + "ihuiuuhuuhtheidFor" + str21 + "--" + str21 + "asds" + str21 + "as--" + str21 + "theuhtuwaesphoutr" + Chr(34);
std::vector<std::string> items3 = LoopParseFunc(code);
for (size_t A_Index3 = 0; A_Index3 < items3.size(); A_Index3++) {
std::string A_LoopField3 = items3[A_Index3 - 0];
if (A_LoopField3 == keyWordEscpaeChar && getAllCharForTheFurtureSoIcanAddEscapeChar[A_Index3 + 1] == Chr(34)) {
fixOutFixDoubleQuotesInsideDoubleQuotesFIXok = 1;
OutFixDoubleQuotesInsideDoubleQuotes += ReplaceFixWhitOutFixDoubleQuotesInsideDoubleQuotes;
} else {
if (fixOutFixDoubleQuotesInsideDoubleQuotesFIXok != 1) {
OutFixDoubleQuotesInsideDoubleQuotes += A_LoopField3;
} else {
fixOutFixDoubleQuotesInsideDoubleQuotesFIXok = 0;
}
}
}
code = OutFixDoubleQuotesInsideDoubleQuotes;
if (keyWordEscpaeChar != Chr(92)) {
code = StrReplace(code, Chr(92), Chr(92) + Chr(92));
}
if (keyWordEscpaeChar == Chr(92)) {
std::vector<std::string> items4 = LoopParseFunc(code);
for (size_t A_Index4 = 0; A_Index4 < items4.size(); A_Index4++) {
std::string A_LoopField4 = items4[A_Index4 - 0];
if (A_LoopField4 == Chr(34)) {
areWEinSome34sNum++;
}
if (areWEinSome34sNum == 1) {
if (A_LoopField4 != Chr(34)) {
if (A_LoopField4 == keyWordEscpaeChar) {
HT_Lib_theIdNumOfThe34theVar[HT_LIB_theIdNumOfThe34] = HT_Lib_theIdNumOfThe34theVar[HT_LIB_theIdNumOfThe34] + Chr(92);
} else {
HT_Lib_theIdNumOfThe34theVar[HT_LIB_theIdNumOfThe34] = HT_Lib_theIdNumOfThe34theVar[HT_LIB_theIdNumOfThe34] + A_LoopField4;
}
} else {
HT_LIB_theIdNumOfThe34++;
htCodeOUT754754 += "VYIGUOYIYVIUCFCYIUCFCYIGCYGICFHYFHCTCFTFDFGYGFC" + Chr(65) + Chr(65) + STR(HT_LIB_theIdNumOfThe34) + Chr(65) + Chr(65);
}
}
if (areWEinSome34sNum == 2 || areWEinSome34sNum == 0) {
if (A_LoopField4 != Chr(34)) {
htCodeOUT754754 += A_LoopField4;
}
areWEinSome34sNum = 0;
}
}
} else {
std::vector<std::string> items5 = LoopParseFunc(code);
for (size_t A_Index5 = 0; A_Index5 < items5.size(); A_Index5++) {
std::string A_LoopField5 = items5[A_Index5 - 0];
if (A_LoopField5 == Chr(34)) {
areWEinSome34sNum++;
}
if (areWEinSome34sNum == 1) {
if (A_LoopField5 != Chr(34)) {
if (A_LoopField5 == keyWordEscpaeChar && keyWordEscpaeChar == getAllCharForTheFurtureSoIcanAddEscapeChar[A_Index5 + 1]) {
HT_Lib_theIdNumOfThe34theVar[HT_LIB_theIdNumOfThe34] = HT_Lib_theIdNumOfThe34theVar[HT_LIB_theIdNumOfThe34] + keyWordEscpaeChar;
removeNexFixkeyWordEscpaeChar = 1;
}
else if (A_LoopField5 == keyWordEscpaeChar) {
if (removeNexFixkeyWordEscpaeChar != 1) {
HT_Lib_theIdNumOfThe34theVar[HT_LIB_theIdNumOfThe34] = HT_Lib_theIdNumOfThe34theVar[HT_LIB_theIdNumOfThe34] + Chr(92);
} else {
removeNexFixkeyWordEscpaeChar = 0;
}
} else {
HT_Lib_theIdNumOfThe34theVar[HT_LIB_theIdNumOfThe34] = HT_Lib_theIdNumOfThe34theVar[HT_LIB_theIdNumOfThe34] + A_LoopField5;
}
} else {
HT_LIB_theIdNumOfThe34++;
htCodeOUT754754 += "VYIGUOYIYVIUCFCYIUCFCYIGCYGICFHYFHCTCFTFDFGYGFC" + Chr(65) + Chr(65) + STR(HT_LIB_theIdNumOfThe34) + Chr(65) + Chr(65);
}
}
if (areWEinSome34sNum == 2 || areWEinSome34sNum == 0) {
if (A_LoopField5 != Chr(34)) {
htCodeOUT754754 += A_LoopField5;
}
areWEinSome34sNum = 0;
}
}
}
code = htCodeOUT754754;
for (int A_Index6 = 0; A_Index6 < HT_LIB_theIdNumOfThe34; A_Index6++) {
HT_Lib_theIdNumOfThe34theVar[A_Index6] = HT_Lib_theIdNumOfThe34theVar[A_Index6] + Chr(34);
}
HTVM_Append(HT_Lib_theIdNumOfThe34theVar, Chr(34));
return code;
}
//;;;;;;;;;;;;;;;;;;;;;;;;;;
//;;;;;;;;;;;;;;;;;;;;;;;;;;
std::string restoreStrings(std::string codeOUT, std::string keyWordEscpaeChar = Chr(92)) {
for (int A_Index7 = 0; A_Index7 < HT_LIB_theIdNumOfThe34; A_Index7++) {
if (HT_LIB_theIdNumOfThe34 == A_Index7 + 1) {
codeOUT = StrReplace(codeOUT, "VYIGUOYIYVIUCFCYIUCFCYIGCYGICFHYFHCTCFTFDFGYGFC" + Chr(65) + Chr(65) + STR(A_Index7 + 1) + Chr(65) + Chr(65), StrReplace(HT_Lib_theIdNumOfThe34theVar[A_Index7 + 1], keyWordEscpaeChar, "\\") + Chr(34));
} else {
codeOUT = StrReplace(codeOUT, "VYIGUOYIYVIUCFCYIUCFCYIGCYGICFHYFHCTCFTFDFGYGFC" + Chr(65) + Chr(65) + STR(A_Index7 + 1) + Chr(65) + Chr(65), StrReplace(HT_Lib_theIdNumOfThe34theVar[A_Index7 + 1], keyWordEscpaeChar, "\\"));
}
}
return codeOUT;
}
std::string cleanUpFirst(std::string code) {
code = StrReplace(code, Chr(13), "");
std::string out = "";
std::vector<std::string> items8 = LoopParseFunc(code, "\n", "\r");
for (size_t A_Index8 = 0; A_Index8 < items8.size(); A_Index8++) {
std::string A_LoopField8 = items8[A_Index8 - 0];
out += Trim(A_LoopField8) + Chr(10);
}
out = StringTrimRight(out, 1);
return out;
}
std::string getLangParams(std::string binName, std::string langExtension, std::string extra = "") {
std::string params = Trim(GetParams());
std::string paramsTemp = "";
if (params == "") {
if (isWindows()) {
print("Usage:" + Chr(10) + Trim(binName) + " your_file." + Trim(langExtension) + " " + Trim(extra));
} else {
print("Usage:" + Chr(10) + "./" + Trim(binName) + " your_file." + Trim(langExtension) + " " + Trim(extra));
}
return "";
} else {
return params;
}
return "MASSIVE ERROR";
}
void saveOutput(std::string outCode, std::string fileName) {
FileDelete(Trim(fileName));
FileAppend(Trim(outCode), Trim(fileName));
print("Generation finished: " + Trim(fileName) + " generated.");
}
bool beginning(std::string line, std::string what) {
if (SubStr(line, 1, StrLen(what)) == what) {
return true;
}
return false;
}
std::string formatCurlyBracesForParsing(std::string code, std::string openBrace = "{", std::string closeBrace = "}") {
code = StrReplace(code, openBrace, Chr(10) + "{" + Chr(10));
code = StrReplace(code, closeBrace, Chr(10) + "}" + Chr(10));
code = cleanUpFirst(code);
return code;
}
std::string handleComments(std::string code, std::string commentKeyword = ";") {
std::string str1 = "";
std::vector<std::string> items9 = LoopParseFunc(code, "\n", "\r");
for (size_t A_Index9 = 0; A_Index9 < items9.size(); A_Index9++) {
std::string A_LoopField9 = items9[A_Index9 - 0];
str1 += StrSplit(A_LoopField9, commentKeyword, 1) + Chr(10);
}
code = StringTrimRight(str1, 1);
return code;
}
// Define the function to check odd spaces at the beginning
std::string CheckOddLeadingSpaces(std::string string123) {
// Initialize a variable to count the spaces
int spaceCount = 0;
// Loop through the string one character at a time
std::vector<std::string> items10 = LoopParseFunc(string123);
for (size_t A_Index10 = 0; A_Index10 < items10.size(); A_Index10++) {
std::string A_LoopField10 = items10[A_Index10 - 0];
// Check if the current character is a space
if (A_LoopField10 == Chr(32)) {
spaceCount++;
} else {
// When we hit a non-space character, break the loop
break;
}
}
// Return true if the number of spaces is odd, false otherwise
std::string sdsfawasd = STR(Mod(spaceCount, 2) == 1);
//MsgBox, % sdsfawasd
return sdsfawasd;
}
std::string RepeatSpaces(int count) {
std::string spaces = "";
for (int A_Index11 = 0; A_Index11 < count; A_Index11++) {
spaces += Chr(32);
}
return spaces;
}
// if you wanna convert to python, nim etc... indentation style we set modeCurlyBracesOn to 0
std::string indent_nested_curly_braces(std::string input_string, int modeCurlyBracesOn = 1) {
int indent_size = 4;
int current_indent = 0;
std::string result = "";
std::string trimmed_line = "";
std::string resultOut = "";
std::string culyOpenFix = "{";
std::string culyCloseFix = "}";
//MsgBox, % input_string
std::vector<std::string> items12 = LoopParseFunc(input_string, "\n", "\r");
for (size_t A_Index12 = 0; A_Index12 < items12.size(); A_Index12++) {
std::string A_LoopField12 = items12[A_Index12 - 0];
trimmed_line = Trim(A_LoopField12);
if (trimmed_line == Chr(123)) {
result += Chr(32) + RepeatSpaces(current_indent) + trimmed_line + Chr(10);
current_indent = current_indent + indent_size;
}
else if (trimmed_line == Chr(125)) {
current_indent = current_indent - indent_size;
result += Chr(32) + RepeatSpaces(current_indent) + trimmed_line + Chr(10);
} else {
result += Chr(32) + RepeatSpaces(current_indent) + trimmed_line + Chr(10);
}
}
if (modeCurlyBracesOn == 0) {
std::string resultOut = "";
std::vector<std::string> items13 = LoopParseFunc(result, "\n", "\r");
for (size_t A_Index13 = 0; A_Index13 < items13.size(); A_Index13++) {
std::string A_LoopField13 = items13[A_Index13 - 0];
if (Trim(A_LoopField13) != "{" && Trim(A_LoopField13) != "}") {
resultOut += A_LoopField13 + Chr(10);
}
}
result = StringTrimRight(resultOut, 1);
} else {
// format curly braces in a K&R style
std::vector<std::string> lookIntoFurture;
std::vector<std::string> items14 = LoopParseFunc(result, "\n", "\r");
for (size_t A_Index14 = 0; A_Index14 < items14.size(); A_Index14++) {
std::string A_LoopField14 = items14[A_Index14 - 0];
HTVM_Append(lookIntoFurture, Trim(A_LoopField14));
}
HTVM_Append(lookIntoFurture, " ");
std::string resultOut = "";
int skipNext = 0;
std::vector<std::string> items15 = LoopParseFunc(result, "\n", "\r");
for (size_t A_Index15 = 0; A_Index15 < items15.size(); A_Index15++) {
std::string A_LoopField15 = items15[A_Index15 - 0];
skipNext--;
if (skipNext <= 0) {
skipNext = 0;
}
if (Trim(lookIntoFurture[A_Index15 + 1]) == "{") {
resultOut += A_LoopField15 + " " + culyOpenFix + Chr(10);
skipNext = 2;
}
if (skipNext == 0) {
resultOut += A_LoopField15 + Chr(10);
}
}
result = StringTrimRight(resultOut, 1);
std::vector<std::string> lookIntoFurture2;
std::vector<std::string> items16 = LoopParseFunc(result, "\n", "\r");
for (size_t A_Index16 = 0; A_Index16 < items16.size(); A_Index16++) {
std::string A_LoopField16 = items16[A_Index16 - 0];
HTVM_Append(lookIntoFurture2, Trim(A_LoopField16));
}
HTVM_Append(lookIntoFurture2, " ");
resultOut = "";
skipNext = 0;
std::string addSpacesAtTheBegginig = "";
std::vector<std::string> items17 = LoopParseFunc(result, "\n", "\r");
for (size_t A_Index17 = 0; A_Index17 < items17.size(); A_Index17++) {
std::string A_LoopField17 = items17[A_Index17 - 0];
skipNext--;
if (skipNext <= 0) {
skipNext = 0;
}
if (Trim(A_LoopField17) == "}" && Trim(lookIntoFurture2[A_Index17 + 1]) == "else {") {
skipNext = 2;
addSpacesAtTheBegginig = "";
std::vector<std::string> items18 = LoopParseFunc(A_LoopField17);
for (size_t A_Index18 = 0; A_Index18 < items18.size(); A_Index18++) {
std::string A_LoopField18 = items18[A_Index18 - 0];
if (A_LoopField18 == " ") {
if (A_LoopField18 != " ") {
break;
}
addSpacesAtTheBegginig += StrReplace(A_LoopField18, "}", culyCloseFix);
}
}
resultOut += addSpacesAtTheBegginig + culyCloseFix + " else " + culyOpenFix + Chr(10);
}
if (skipNext == 0) {
resultOut += A_LoopField17 + Chr(10);
}
}
result = StringTrimRight(resultOut, 1);
}
resultOut = "";
std::string ALoopField = "";
std::vector<std::string> items19 = LoopParseFunc(result, "\n", "\r");
for (size_t A_Index19 = 0; A_Index19 < items19.size(); A_Index19++) {
std::string A_LoopField19 = items19[A_Index19 - 0];
if (CheckOddLeadingSpaces(A_LoopField19) == "1") {
ALoopField = StringTrimLeft(A_LoopField19, 1);
resultOut += ALoopField + Chr(10);
} else {
resultOut += A_LoopField19 + Chr(10);
}
}
result = StringTrimRight(resultOut, 1);
// Return the result
return result;
}
// end of HT-Lib.htvm
std::string str0 = "";
std::string str1 = "";
std::string str2 = "";
std::string str3 = "";
std::string str4 = "";
std::string str5 = "";
std::string str6 = "";
std::string str7 = "";
std::string str8 = "";
std::string str9 = "";
std::string str10 = "";
std::string str11 = "";
std::string str12 = "";
std::string str13 = "";
std::string str14 = "";
std::string str15 = "";
std::string str16 = "";
std::string str17 = "";
std::string str18 = "";
std::string str19 = "";
std::string str20 = "";
int is_arm = 0;
int is_oryx = 0;
int ring0 = 0;
std::vector<std::string> nintArr;
std::string SubStrLastChars(std::string text, int numOfChars) {
std::string LastOut = "";
int NumOfChars = 0;
std::vector<std::string> items20 = LoopParseFunc(text);
for (size_t A_Index20 = 0; A_Index20 < items20.size(); A_Index20++) {
std::string A_LoopField20 = items20[A_Index20 - 0];
NumOfChars++;
}
for (int A_Index21 = 0; A_Index21 < numOfChars; A_Index21++) {
NumOfChars--;
}
std::vector<std::string> items22 = LoopParseFunc(text);
for (size_t A_Index22 = 0; A_Index22 < items22.size(); A_Index22++) {
std::string A_LoopField22 = items22[A_Index22 - 0];
if (A_Index22 >= NumOfChars) {
LastOut += A_LoopField22;
}
}
return LastOut;
}
std::string transformBracesToHTLL(std::string code) {
std::string out = "";
std::vector<std::string> blockStack;
int ifNestLevel = 0;
int loopNestLevel = 0;
std::vector<std::string> items23 = LoopParseFunc(code, "\n", "\r");
for (size_t A_Index23 = 0; A_Index23 < items23.size(); A_Index23++) {
std::string A_LoopField23 = items23[A_Index23 - 0];
std::string currentLine = A_LoopField23;
std::string trimmedLine = StrLower(Trim(currentLine));
if (SubStr(trimmedLine, 1, 5) == "func ") {
HTVM_Append(blockStack, "func:0");
out += currentLine + Chr(10);
continue;
}
// ===================================================================
// IF BLOCKS
// ===================================================================
if (SubStr(trimmedLine, 1, 4) == "if (") {
ifNestLevel++;
HTVM_Append(blockStack, "if:" + STR(ifNestLevel));
std::string newIfKeyword = "if";
if (ifNestLevel > 1) {
newIfKeyword += STR(ifNestLevel);
}
std::string conditionPart = SubStr(Trim(currentLine), 4);
std::string modifiedIfLine = newIfKeyword + " " + conditionPart;
int indentLen = InStr(StrLower(currentLine), "if") - 1;
std::string indentation = SubStr(currentLine, 1, indentLen);
out += indentation + modifiedIfLine + Chr(10);
continue;
}
// ===================================================================
// LOOP BLOCKS
// ===================================================================
if (SubStr(trimmedLine, 1, 5) == "loop,") {
loopNestLevel++;
HTVM_Append(blockStack, "loop:" + STR(loopNestLevel));
std::string newLoopKeyword = "loop";
if (loopNestLevel > 1) {
newLoopKeyword += STR(loopNestLevel);
}
std::string loopParams = SubStr(Trim(currentLine), 6);
std::string modifiedLoopLine = newLoopKeyword + "," + loopParams;
int indentLen = InStr(StrLower(currentLine), "loop,") - 1;
std::string indentation = SubStr(currentLine, 1, indentLen);
out += indentation + modifiedLoopLine + Chr(10);
continue;
}
// ===================================================================
// AUTO-NUMBERING BREAK & CONTINUE
// ===================================================================
if (trimmedLine == "break") {
std::string breakCmd = "break";
if (loopNestLevel > 1) {
breakCmd += STR(loopNestLevel);
}
int indentLen = InStr(StrLower(currentLine), "break") - 1;
std::string indentation = SubStr(currentLine, 1, indentLen);
out += indentation + breakCmd + Chr(10);
continue;
}
if (trimmedLine == "continue") {
std::string contCmd = "continue";
if (loopNestLevel > 1) {
contCmd += STR(loopNestLevel);
}
int indentLen = InStr(StrLower(currentLine), "continue") - 1;
std::string indentation = SubStr(currentLine, 1, indentLen);
out += indentation + contCmd + Chr(10);
continue;
}
// ===================================================================
// BRACES HANDLING
// ===================================================================
if (trimmedLine == "{") {
continue;
}
if (trimmedLine == "}") {
if (HTVM_Size(blockStack) == 0) {
out += "; SYNTAX ERROR: Unmatched closing brace found." + Chr(10);
continue;
}
std::string blockInfo = blockStack[HTVM_Size(blockStack) - 1];
HTVM_Pop(blockStack);
std::string blockType = StrSplit(blockInfo, ":", 1);
int level = INT(StrSplit(blockInfo, ":", 2));
int indentLen = InStr(currentLine, "}") - 1;
std::string indentation = SubStr(currentLine, 1, indentLen);
if (blockType == "func") {
out += indentation + "funcend" + Chr(10);
}
else if (blockType == "if") {
std::string ender = "ifend";
if (level > 1) {
ender += STR(level);
}
out += indentation + ender + Chr(10);
ifNestLevel--;
}
else if (blockType == "loop") {
std::string ender = "endloop";
if (level > 1) {
ender += STR(level);
}
out += indentation + ender + Chr(10);
loopNestLevel--;
}
continue;
}
out += currentLine + Chr(10);
}
if (HTVM_Size(blockStack) > 0) {
out += "; SYNTAX ERROR: " + STR(HTVM_Size(blockStack)) + " unclosed blocks at end of file." + Chr(10);
}
return Trim(out);
}
std::string HTLL_Lang(std::string code) {
std::string out = "";
code = cleanUpFirst(code);
code = preserveStrings(code);
code = handleComments(code);
code = formatCurlyBracesForParsing(code);
//print(code)
if (InStr(code, "{")) {
code = transformBracesToHTLL(code);
}
// VYIGUOYIYVIUCFCYIUCFCYIGCYGICFHYFHCTCFTFDFGYGFCAA
//print(code)
//Loop, % HT_Lib_theIdNumOfThe34theVar.size() {
//if (Trim(HT_Lib_theIdNumOfThe34theVar[A_Index]) != "") {
//print(A_Index)
//print(HT_Lib_theIdNumOfThe34theVar[A_Index])
//}
//if (A_Index = 50) {
//break
//}
//}
std::vector<std::string> items24 = LoopParseFunc(code, "\n", "\r");
for (size_t A_Index24 = 0; A_Index24 < items24.size(); A_Index24++) {
std::string A_LoopField24 = items24[A_Index24 - 0];
if (SubStr(A_LoopField24, 1, 4) == "str ") {
str1 = Trim(StringTrimLeft(A_LoopField24, 4));
} else {
out += A_LoopField24 + Chr(10);
}
}
out = Trim(out);
out = restoreStrings(out);
return out;
}
//;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
//;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
//;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
//;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
//;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
//;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
//;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
//;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
//;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
//;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
bool isNint(std::string name) {
for (int A_Index25 = 0; A_Index25 < HTVM_Size(nintArr); A_Index25++) {
if (Trim(name) == Trim(nintArr[A_Index25])) {
return true;
}
}
return false;
}
std::string compiler(std::string code) {
code = HTLL_Lang(code);
std::string out = "";
std::vector<std::string> oryx_param_map;
std::string main_syntax = "";
if (is_arm == 1) {
if (RegExMatch(code, "\\bargs_array\\b")) {
main_syntax = "_start:" + Chr(10);
// FIXED: Removed parens and comments that confuse the parser
main_syntax += " ldr x19, [sp]" + Chr(10);
main_syntax += " stp x29, x30, [sp, #-32]!" + Chr(10);
main_syntax += " mov x29, sp" + Chr(10);
main_syntax += " ldr x0, =args_array" + Chr(10);
main_syntax += " bl array_clear" + Chr(10);
main_syntax += " add x20, sp, #40" + Chr(10);
main_syntax += " mov x21, #1" + Chr(10);
main_syntax += ".arg_loop:" + Chr(10);
main_syntax += " cmp x21, x19" + Chr(10);
main_syntax += " b.ge .args_done" + Chr(10);
// Load argv[x21]
main_syntax += " ldr x22, [x20, x21, lsl #3]" + Chr(10);
main_syntax += ".unpack_byte_loop:" + Chr(10);
main_syntax += " ldrb w1, [x22], #1" + Chr(10);
main_syntax += " cmp w1, #0" + Chr(10);
main_syntax += " b.eq .unpack_byte_done" + Chr(10);
main_syntax += " ldr x0, =args_array" + Chr(10);
main_syntax += " bl array_append" + Chr(10);
main_syntax += " b .unpack_byte_loop" + Chr(10);
main_syntax += ".unpack_byte_done:" + Chr(10);
main_syntax += " mov x1, #10" + Chr(10);
main_syntax += " ldr x0, =args_array" + Chr(10);
main_syntax += " bl array_append" + Chr(10);
main_syntax += " add x21, x21, #1" + Chr(10);
main_syntax += " b .arg_loop" + Chr(10);
main_syntax += ".args_done:" + Chr(10) + Chr(10);
} else {
// --- THE FIX IS HERE ---
main_syntax = "_start:" + Chr(10);
main_syntax += " stp x29, x30, [sp, #-16]!" + Chr(10);
main_syntax += " mov x29, sp" + Chr(10) + Chr(10);
}
}
else if (is_oryx == 1) {
// --- ORYX IR ENTRY ---
// Oryx is a VM, so it handles stack alignment automatically.
// We just need the entry label to tell the VM where to begin.
main_syntax = "_start:" + Chr(10);
if (RegExMatch(code, "\\bargs_array\\b")) {
// In Oryx IR, we assume the VM environment populates 'args_array'
// automatically if it exists, or we add a specific sys-call later.
// We don't need manual stack walking code here.
main_syntax += " ; args_array handling" + Chr(10);
}
} else {
// --- YOUR EXISTING X86 CODE - UNCHANGED AND CORRECT ---
if (RegExMatch(code, "\\bargs_array\\b")) {
main_syntax = Chr(10) + "_start:" + Chr(10) + "push rbp" + Chr(10) + "mov rbp, rsp" + Chr(10) + "and rsp, -16" + Chr(10) + "mov rdi, args_array" + Chr(10) + "call array_clear" + Chr(10) + "mov r12, [rbp+8]" + Chr(10) + "lea r13, [rbp+16]" + Chr(10) + "mov r14, 1" + Chr(10) + ".arg_loop:" + Chr(10) + "cmp r14, r12" + Chr(10) + "jge .args_done" + Chr(10) + "mov r15, [r13 + r14*8]" + Chr(10) + ".unpack_byte_loop:" + Chr(10) + "movzx rbx, byte [r15]" + Chr(10) + "cmp rbx, 0" + Chr(10) + "je .unpack_byte_done" + Chr(10) + "mov rdi, args_array" + Chr(10) + "mov rsi, rbx" + Chr(10) + "call array_append" + Chr(10) + "inc r15" + Chr(10) + "jmp .unpack_byte_loop" + Chr(10) + ".unpack_byte_done:" + Chr(10) + "mov rdi, args_array" + Chr(10) + "mov rsi, 10" + Chr(10) + "call array_append" + Chr(10) + "inc r14" + Chr(10) + "jmp .arg_loop" + Chr(10) + ".args_done:" + Chr(10) + Chr(10);
} else {
main_syntax = Chr(10) + "_start:" + Chr(10) + "push rbp" + Chr(10) + "mov rbp, rsp" + Chr(10) + "and rsp, -16 " + Chr(10) + Chr(10);
}
}
std::string HTLL_Libs_x86 = "";
if (ring0 == 0) {
HTLL_Libs_x86 = FileRead("HTLL_Libs_x86.txt");
} else {