-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHTLL.htvm
More file actions
10138 lines (9629 loc) · 425 KB
/
HTLL.htvm
File metadata and controls
10138 lines (9629 loc) · 425 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
include "HT-Lib.htvm"
str str0 := ""
str str1 := ""
str str2 := ""
str str3 := ""
str str4 := ""
str str5 := ""
str str6 := ""
str str7 := ""
str str8 := ""
str str9 := ""
str str10 := ""
str str11 := ""
str str12 := ""
str str13 := ""
str str14 := ""
str str15 := ""
str str16 := ""
str str17 := ""
str str18 := ""
str str19 := ""
str str20 := ""
int is_arm := 0
int is_oryx := 0
int ring0 := 0
arr str nintArr
str langToConvertTo := ""
arr str programmingBlock_InTheTranspiledLang
arr str programmingBlock_CPP
arr str programmingBlock_PY
arr str programmingBlock_JS
arr str programmingBlock_GO
str keyWordCodeInTheTranspiledLangStart := "___start asm"
str keyWordCodeInTheTranspiledLangStartCPP := "___start x86-64"
str keyWordCodeInTheTranspiledLangStartPY := "___start arm"
str keyWordCodeInTheTranspiledLangStartJS := "___start oryx"
str keyWordCodeInTheTranspiledLangStartGO := "___start x86-64-ring0"
str keyWordCodeInTheTranspiledLangEnd := "___end asm"
str keyWordCodeInTheTranspiledLangEndCPP := "___end x86-64"
str keyWordCodeInTheTranspiledLangEndPY := "___end arm"
str keyWordCodeInTheTranspiledLangEndJS := "___end oryx"
str keyWordCodeInTheTranspiledLangEndGO := "___end x86-64-ring0"
int COUNT_programmingBlock_InTheTranspiledLang := 0
int COUNT_programmingBlock_CPP := 0
int COUNT_programmingBlock_PY := 0
int COUNT_programmingBlock_JS := 0
int COUNT_programmingBlock_GO := 0
str programmingBlocksTemp := ""
int inProgarmmingBlock := 0
str holdTempDataProgrammingBlockThenPutInArr := ""
func str SubStrLastChars(str text, int numOfChars) {
str LastOut := ""
int NumOfChars := 0
Loop, Parse, text {
NumOfChars++
}
Loop, % numOfChars {
NumOfChars--
}
Loop, Parse, text {
if (A_Index >= NumOfChars) {
LastOut .= A_LoopField
}
}
return LastOut
}
func str transformBracesToHTLL(str code) {
str out := ""
arr str blockStack
int ifNestLevel := 0
int loopNestLevel := 0
Loop, Parse, code, `n, `r {
str currentLine := A_LoopField
str trimmedLine := StrLower(Trim(currentLine))
if (SubStr(trimmedLine, 1, 5) = "func ") {
blockStack.add("func:0")
out .= currentLine . Chr(10)
continue
}
; ===================================================================
; IF BLOCKS
; ===================================================================
if (SubStr(trimmedLine, 1, 4) = "if (") {
ifNestLevel++
blockStack.add("if:" . STR(ifNestLevel))
str newIfKeyword := "if"
if (ifNestLevel > 1) {
newIfKeyword .= STR(ifNestLevel)
}
str conditionPart := SubStr(Trim(currentLine), 4)
str modifiedIfLine := newIfKeyword . " " . conditionPart
int indentLen := InStr(StrLower(currentLine), "if") - 1
str indentation := SubStr(currentLine, 1, indentLen)
out .= indentation . modifiedIfLine . Chr(10)
continue
}
; ===================================================================
; LOOP BLOCKS
; ===================================================================
if (SubStr(trimmedLine, 1, 5) = "loop,") {
loopNestLevel++
blockStack.add("loop:" . STR(loopNestLevel))
str newLoopKeyword := "loop"
if (loopNestLevel > 1) {
newLoopKeyword .= STR(loopNestLevel)
}
str loopParams := SubStr(Trim(currentLine), 6)
str modifiedLoopLine := newLoopKeyword . "," . loopParams
int indentLen := InStr(StrLower(currentLine), "loop,") - 1
str indentation := SubStr(currentLine, 1, indentLen)
out .= indentation . modifiedLoopLine . Chr(10)
continue
}
; ===================================================================
; AUTO-NUMBERING BREAK & CONTINUE
; ===================================================================
if (trimmedLine = "break") {
str breakCmd := "break"
if (loopNestLevel > 1) {
breakCmd .= STR(loopNestLevel)
}
int indentLen := InStr(StrLower(currentLine), "break") - 1
str indentation := SubStr(currentLine, 1, indentLen)
out .= indentation . breakCmd . Chr(10)
continue
}
if (trimmedLine = "continue") {
str contCmd := "continue"
if (loopNestLevel > 1) {
contCmd .= STR(loopNestLevel)
}
int indentLen := InStr(StrLower(currentLine), "continue") - 1
str indentation := SubStr(currentLine, 1, indentLen)
out .= indentation . contCmd . Chr(10)
continue
}
; ===================================================================
; BRACES HANDLING
; ===================================================================
if (trimmedLine = "{") {
continue
}
if (trimmedLine = "}") {
if (blockStack.size() = 0) {
out .= "; SYNTAX ERROR: Unmatched closing brace found." . Chr(10)
continue
}
str blockInfo := blockStack[blockStack.size() - 1]
blockStack.pop()
str blockType := StrSplit(blockInfo, ":", 1)
int level := INT(StrSplit(blockInfo, ":", 2))
int indentLen := InStr(currentLine, "}") - 1
str indentation := SubStr(currentLine, 1, indentLen)
if (blockType = "func") {
out .= indentation . "funcend" . Chr(10)
} else if (blockType = "if") {
str ender := "ifend"
if (level > 1) { ender .= STR(level) }
out .= indentation . ender . Chr(10)
ifNestLevel--
} else if (blockType = "loop") {
str ender := "endloop"
if (level > 1) { ender .= STR(level) }
out .= indentation . ender . Chr(10)
loopNestLevel--
}
continue
}
out .= currentLine . Chr(10)
}
if (blockStack.size() > 0) {
out .= "; SYNTAX ERROR: " . STR(blockStack.size()) . " unclosed blocks at end of file." . Chr(10)
}
return Trim(out)
}
func bool isFuncRetARR(str line) {
if (InStr(line, "__HTLL_param_")) {
return true
}
return false
}
func bool isFuncRetARR2(str line) {
if (InStr(line, "__HTLL_flocal_")) {
return true
}
return false
}
func bool isFuncRetARR3(str line, arr str arrays_from_global_scope_ARR) {
Loop, arrays_from_global_scope_ARR.size() {
if (Trim(StringTrimLeft(Trim(line), 7)) = arrays_from_global_scope_ARR[A_Index]) {
return true
}
}
return false
}
func bool doseHaveInclude(str TheCodeThatMightHaveInclude) {
str keyWordInclude := "include"
Loop, Parse, TheCodeThatMightHaveInclude, `n, `r {
if (SubStr(StrLower(Trim(A_LoopField)), 1, StrLen(StrLower(keyWordInclude . " "))) = StrLower(keyWordInclude . " "))
{
return true
}
}
return false
}
func str HTLL_Lang(str code) {
str out := ""
; PROGRAMMING BLOCK
; PROGRAMMING BLOCK
; PROGRAMMING BLOCK
; PROGRAMMING BLOCK
Loop, Parse, code, `n, `r
{
if (Trim(StrLower(A_LoopField)) = StrLower(keyWordCodeInTheTranspiledLangEnd))
{
COUNT_programmingBlock_InTheTranspiledLang++
StringTrimRight, holdTempDataProgrammingBlockThenPutInArr, holdTempDataProgrammingBlockThenPutInArr, 1
programmingBlocksTemp .= "programmingBlock_InTheTranspiledLang-programmingBlock_InTheTranspiledLang-AA" . STR(COUNT_programmingBlock_InTheTranspiledLang) . "AA" . Chr(10)
programmingBlock_InTheTranspiledLang.add(holdTempDataProgrammingBlockThenPutInArr)
holdTempDataProgrammingBlockThenPutInArr := ""
inProgarmmingBlock := 0
}
else if (Trim(StrLower(A_LoopField)) = StrLower(keyWordCodeInTheTranspiledLangEndCPP))
{
COUNT_programmingBlock_CPP++
StringTrimRight, holdTempDataProgrammingBlockThenPutInArr, holdTempDataProgrammingBlockThenPutInArr, 1
programmingBlocksTemp .= "programmingBlock_CPP-programmingBlock_CPP-AA" . STR(COUNT_programmingBlock_CPP) . "AA" . Chr(10)
programmingBlock_CPP.add(holdTempDataProgrammingBlockThenPutInArr)
holdTempDataProgrammingBlockThenPutInArr := ""
inProgarmmingBlock := 0
}
else if (Trim(StrLower(A_LoopField)) = StrLower(keyWordCodeInTheTranspiledLangEndPY))
{
COUNT_programmingBlock_PY++
StringTrimRight, holdTempDataProgrammingBlockThenPutInArr, holdTempDataProgrammingBlockThenPutInArr, 1
programmingBlocksTemp .= "programmingBlock_PY-programmingBlock_PY-AA" . STR(COUNT_programmingBlock_PY) . "AA" . Chr(10)
programmingBlock_PY.add(holdTempDataProgrammingBlockThenPutInArr)
holdTempDataProgrammingBlockThenPutInArr := ""
inProgarmmingBlock := 0
}
else if (Trim(StrLower(A_LoopField)) = StrLower(keyWordCodeInTheTranspiledLangEndJS))
{
COUNT_programmingBlock_JS++
StringTrimRight, holdTempDataProgrammingBlockThenPutInArr, holdTempDataProgrammingBlockThenPutInArr, 1
programmingBlocksTemp .= "programmingBlock_JS-programmingBlock_JS-AA" . STR(COUNT_programmingBlock_JS) . "AA" . Chr(10)
programmingBlock_JS.add(holdTempDataProgrammingBlockThenPutInArr)
holdTempDataProgrammingBlockThenPutInArr := ""
inProgarmmingBlock := 0
}
else if (Trim(StrLower(A_LoopField)) = StrLower(keyWordCodeInTheTranspiledLangEndGO))
{
COUNT_programmingBlock_GO++
StringTrimRight, holdTempDataProgrammingBlockThenPutInArr, holdTempDataProgrammingBlockThenPutInArr, 1
programmingBlocksTemp .= "programmingBlock_GO-programmingBlock_GO-AA" . STR(COUNT_programmingBlock_GO) . "AA" . Chr(10)
programmingBlock_GO.add(holdTempDataProgrammingBlockThenPutInArr)
holdTempDataProgrammingBlockThenPutInArr := ""
inProgarmmingBlock := 0
}
else if (inProgarmmingBlock = 1)
{
holdTempDataProgrammingBlockThenPutInArr .= A_LoopField . Chr(10)
}
else if (Trim(StrLower(A_LoopField)) = StrLower(keyWordCodeInTheTranspiledLangStart))
{
holdTempDataProgrammingBlockThenPutInArr := ""
inProgarmmingBlock := 1
}
else if (Trim(StrLower(A_LoopField)) = StrLower(keyWordCodeInTheTranspiledLangStartCPP))
{
holdTempDataProgrammingBlockThenPutInArr := ""
inProgarmmingBlock := 1
}
else if (Trim(StrLower(A_LoopField)) = StrLower(keyWordCodeInTheTranspiledLangStartPY))
{
holdTempDataProgrammingBlockThenPutInArr := ""
inProgarmmingBlock := 1
}
else if (Trim(StrLower(A_LoopField)) = StrLower(keyWordCodeInTheTranspiledLangStartJS))
{
holdTempDataProgrammingBlockThenPutInArr := ""
inProgarmmingBlock := 1
}
else if (Trim(StrLower(A_LoopField)) = StrLower(keyWordCodeInTheTranspiledLangStartGO))
{
holdTempDataProgrammingBlockThenPutInArr := ""
inProgarmmingBlock := 1
}
else
{
programmingBlocksTemp .= A_LoopField . Chr(10)
}
}
StringTrimRight, code, programmingBlocksTemp, 1
;programmingBlock_InTheTranspiledLang
;programmingBlock_CPP
;programmingBlock_PY
;programmingBlock_JS
;programmingBlock_GO
; PROGRAMMING BLOCK
; PROGRAMMING BLOCK
; PROGRAMMING BLOCK
; PROGRAMMING BLOCK
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; this is the start of include
; this is the start of include
; this is the start of include
; this is the start of include
arr str includedFilePaths
bool includesWereFoundInPass := false
str reconstructedCode := ""
str currentLine := ""
str filePathToInclude := ""
bool isAlreadyIncluded := false
str fileContent := ""
str keyWordInclude := "include"
str keyWordComment := ";"
if (doseHaveInclude(code))
{
; Loop up to 10000 times to resolve nested includes. Each pass processes one level of includes.
Loop, 10000 {
; Reset the flag and the temporary code string for this pass.
includesWereFoundInPass := false
reconstructedCode := ""
; Iterate through each line of the current code.
Loop, Parse, code, `n, `r {
currentLine := A_LoopField
; Check if the current line is an 'include' directive.
if (SubStr(StrLower(Trim(currentLine)), 1, StrLen(keyWordInclude . " ")) = StrLower(keyWordInclude . " "))
{
includesWereFoundInPass := true
filePathToInclude := StrReplace(StringTrimLeft(Trim(currentLine), StrLen(keyWordInclude . " ")), Chr(34), "")
; Reset flag for the inner loop.
isAlreadyIncluded := false
; NOTE: Both this loop's A_Index and the array access are 0-based, which is correct.
Loop, % includedFilePaths.size() {
if (filePathToInclude = includedFilePaths[A_Index]) {
isAlreadyIncluded := true
break
}
}
if (isAlreadyIncluded = false) {
fileContent := Trim(FileRead(filePathToInclude))
; The 'include' line is replaced by the file's content in the reconstructed code.
reconstructedCode := reconstructedCode . Chr(10) . keyWordComment . " start of " . filePathToInclude + Chr(10) . fileContent . Chr(10) . keyWordComment . " end of " . filePathToInclude . Chr(10) . Chr(10)
includedFilePaths.add(filePathToInclude)
}
}
else {
; If it's not an include directive, just copy the line as is.
reconstructedCode := reconstructedCode . currentLine . Chr(10)
}
}
; --- Cleanup and Preparation for Next Pass ---
; Replace the old code with the newly reconstructed code. This "clears up" the processed includes.
code := reconstructedCode
; If no includes were found in this entire pass, all directives are resolved. Exit the loop.
if (includesWereFoundInPass = false) {
break
}
}
}
; this is the end of include
;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;
programmingBlocksTemp := ""
inProgarmmingBlock := 0
holdTempDataProgrammingBlockThenPutInArr := ""
Loop, Parse, code, `n, `r
{
if (Trim(StrLower(A_LoopField)) = StrLower(keyWordCodeInTheTranspiledLangEnd))
{
COUNT_programmingBlock_InTheTranspiledLang++
StringTrimRight, holdTempDataProgrammingBlockThenPutInArr, holdTempDataProgrammingBlockThenPutInArr, 1
programmingBlocksTemp .= "programmingBlock_InTheTranspiledLang-programmingBlock_InTheTranspiledLang-AA" . STR(COUNT_programmingBlock_InTheTranspiledLang) . "AA" . Chr(10)
programmingBlock_InTheTranspiledLang.add(holdTempDataProgrammingBlockThenPutInArr)
holdTempDataProgrammingBlockThenPutInArr := ""
inProgarmmingBlock := 0
}
else if (Trim(StrLower(A_LoopField)) = StrLower(keyWordCodeInTheTranspiledLangEndCPP))
{
COUNT_programmingBlock_CPP++
StringTrimRight, holdTempDataProgrammingBlockThenPutInArr, holdTempDataProgrammingBlockThenPutInArr, 1
programmingBlocksTemp .= "programmingBlock_CPP-programmingBlock_CPP-AA" . STR(COUNT_programmingBlock_CPP) . "AA" . Chr(10)
programmingBlock_CPP.add(holdTempDataProgrammingBlockThenPutInArr)
holdTempDataProgrammingBlockThenPutInArr := ""
inProgarmmingBlock := 0
}
else if (Trim(StrLower(A_LoopField)) = StrLower(keyWordCodeInTheTranspiledLangEndPY))
{
COUNT_programmingBlock_PY++
StringTrimRight, holdTempDataProgrammingBlockThenPutInArr, holdTempDataProgrammingBlockThenPutInArr, 1
programmingBlocksTemp .= "programmingBlock_PY-programmingBlock_PY-AA" . STR(COUNT_programmingBlock_PY) . "AA" . Chr(10)
programmingBlock_PY.add(holdTempDataProgrammingBlockThenPutInArr)
holdTempDataProgrammingBlockThenPutInArr := ""
inProgarmmingBlock := 0
}
else if (Trim(StrLower(A_LoopField)) = StrLower(keyWordCodeInTheTranspiledLangEndJS))
{
COUNT_programmingBlock_JS++
StringTrimRight, holdTempDataProgrammingBlockThenPutInArr, holdTempDataProgrammingBlockThenPutInArr, 1
programmingBlocksTemp .= "programmingBlock_JS-programmingBlock_JS-AA" . STR(COUNT_programmingBlock_JS) . "AA" . Chr(10)
programmingBlock_JS.add(holdTempDataProgrammingBlockThenPutInArr)
holdTempDataProgrammingBlockThenPutInArr := ""
inProgarmmingBlock := 0
}
else if (Trim(StrLower(A_LoopField)) = StrLower(keyWordCodeInTheTranspiledLangEndGO))
{
COUNT_programmingBlock_GO++
StringTrimRight, holdTempDataProgrammingBlockThenPutInArr, holdTempDataProgrammingBlockThenPutInArr, 1
programmingBlocksTemp .= "programmingBlock_GO-programmingBlock_GO-AA" . STR(COUNT_programmingBlock_GO) . "AA" . Chr(10)
programmingBlock_GO.add(holdTempDataProgrammingBlockThenPutInArr)
holdTempDataProgrammingBlockThenPutInArr := ""
inProgarmmingBlock := 0
}
else if (inProgarmmingBlock = 1)
{
holdTempDataProgrammingBlockThenPutInArr .= A_LoopField . Chr(10)
}
else if (Trim(StrLower(A_LoopField)) = StrLower(keyWordCodeInTheTranspiledLangStart))
{
holdTempDataProgrammingBlockThenPutInArr := ""
inProgarmmingBlock := 1
}
else if (Trim(StrLower(A_LoopField)) = StrLower(keyWordCodeInTheTranspiledLangStartCPP))
{
holdTempDataProgrammingBlockThenPutInArr := ""
inProgarmmingBlock := 1
}
else if (Trim(StrLower(A_LoopField)) = StrLower(keyWordCodeInTheTranspiledLangStartPY))
{
holdTempDataProgrammingBlockThenPutInArr := ""
inProgarmmingBlock := 1
}
else if (Trim(StrLower(A_LoopField)) = StrLower(keyWordCodeInTheTranspiledLangStartJS))
{
holdTempDataProgrammingBlockThenPutInArr := ""
inProgarmmingBlock := 1
}
else if (Trim(StrLower(A_LoopField)) = StrLower(keyWordCodeInTheTranspiledLangStartGO))
{
holdTempDataProgrammingBlockThenPutInArr := ""
inProgarmmingBlock := 1
}
else
{
programmingBlocksTemp .= A_LoopField . Chr(10)
}
}
StringTrimRight, code, programmingBlocksTemp, 1
;programmingBlock_InTheTranspiledLang
;programmingBlock_CPP
;programmingBlock_PY
;programmingBlock_JS
;programmingBlock_GO
; PROGRAMMING BLOCK
; PROGRAMMING BLOCK
; PROGRAMMING BLOCK
; PROGRAMMING BLOCK
code := cleanUpFirst(code)
code := preserveStrings(code)
code := handleComments(code)
code := formatCurlyBracesForParsing(code)
int doWeEverSeeExprestion := 0
out := ""
Loop, Parse, code, `n, `r {
if (InStr(A_LoopField, " := ")) or (InStr(A_LoopField, " += ")) or (InStr(A_LoopField, " -= ")) or (InStr(A_LoopField, " *= ")) or (InStr(A_LoopField, " //= ")) or (InStr(A_LoopField, " %= ")) or (InStr(A_LoopField, " <<= ")) or (InStr(A_LoopField, " >>= ")) or (InStr(A_LoopField, " &= ")) or (InStr(A_LoopField, " |= ")) or (InStr(A_LoopField, " ^= ")) {
str1 := Trim(A_LoopField)
if (InStr(A_LoopField, " + ")) or (InStr(A_LoopField, " - ")) or (InStr(A_LoopField, " * ")) or (InStr(A_LoopField, " // ")) or (InStr(A_LoopField, " % ")) or (InStr(A_LoopField, " << ")) or (InStr(A_LoopField, " >> ")) or (InStr(A_LoopField, " & ")) or (InStr(A_LoopField, " | ")) or (InStr(A_LoopField, " ^ ")) {
if (InStr(A_LoopField, " := ")) {
str10 := ":="
}
else if (InStr(A_LoopField, " += ")) {
str10 := "+="
}
else if (InStr(A_LoopField, " -= ")) {
str10 := "-="
}
else if (InStr(A_LoopField, " *= ")) {
str10 := "*="
}
else if (InStr(A_LoopField, " //= ")) {
str10 := "//="
}
else if (InStr(A_LoopField, " %= ")) {
str10 := "%="
}
else if (InStr(A_LoopField, " <<= ")) {
str10 := "<<="
}
else if (InStr(A_LoopField, " >>= ")) {
str10 := ">>="
}
else if (InStr(A_LoopField, " &= ")) {
str10 := "&="
}
else if (InStr(A_LoopField, " |= ")) {
str10 := "|="
}
else if (InStr(A_LoopField, " ^= ")) {
str10 := "^="
}
doWeEverSeeExprestion := 1
;;;;; code here
;;;;; code here
; x := x + 5 * 7 // var1
; ___HTLL_expression_helper___
str2 := Trim(StrSplit(str1, str10, 1))
str3 := Trim(StrSplit(str1, str10, 2))
Loop, Parse, str3, " " {
if (Trim(A_LoopField) != "") {
if (A_Index = 0) {
out .= "___HTLL_expression_helper___ := " . Trim(A_LoopField) . Chr(10)
}
else {
if (InStr(A_LoopField, "+")) or (InStr(A_LoopField, "-")) or (InStr(A_LoopField, "*")) or (InStr(A_LoopField, "//")) or (InStr(A_LoopField, "%")) or (InStr(A_LoopField, "<<")) or (InStr(A_LoopField, ">>")) or (InStr(A_LoopField, "&")) or (InStr(A_LoopField, "|")) or (InStr(A_LoopField, "^")) {
out .= "___HTLL_expression_helper___ " . Trim(A_LoopField) . "= "
}
else {
out .= Trim(A_LoopField) . Chr(10)
}
}
}
}
out .= str2 . " " . str10 . " ___HTLL_expression_helper___" . Chr(10)
;;;;; code here
;;;;; code here
}
else {
out .= A_LoopField . Chr(10)
}
}
else if (SubStr(StrLower(Trim(A_LoopField)), 1, 7) = "return ") {
;;;;;;;;;;;;;; return
str1 := Trim(StringTrimLeft(Trim(A_LoopField), 7))
if (InStr(A_LoopField, " + ")) or (InStr(A_LoopField, " - ")) or (InStr(A_LoopField, " * ")) or (InStr(A_LoopField, " // ")) or (InStr(A_LoopField, " % ")) or (InStr(A_LoopField, " << ")) or (InStr(A_LoopField, " >> ")) or (InStr(A_LoopField, " & ")) or (InStr(A_LoopField, " | ")) or (InStr(A_LoopField, " ^ ")) {
;;;;;;;;;;;;;; return return
;;;;;;;;;;;;;; return return
doWeEverSeeExprestion := 1
str3 := str1
Loop, Parse, str3, " " {
if (Trim(A_LoopField) != "") {
if (A_Index = 0) {
out .= "___HTLL_expression_helper___ := " . Trim(A_LoopField) . Chr(10)
}
else {
if (InStr(A_LoopField, "+")) or (InStr(A_LoopField, "-")) or (InStr(A_LoopField, "*")) or (InStr(A_LoopField, "//")) or (InStr(A_LoopField, "%")) or (InStr(A_LoopField, "<<")) or (InStr(A_LoopField, ">>")) or (InStr(A_LoopField, "&")) or (InStr(A_LoopField, "|")) or (InStr(A_LoopField, "^")) {
out .= "___HTLL_expression_helper___ " . Trim(A_LoopField) . "= "
}
else {
out .= Trim(A_LoopField) . Chr(10)
}
}
}
}
out .= "return ___HTLL_expression_helper___" . Chr(10)
;;;;;;;;;;;;;; return return
;;;;;;;;;;;;;; return return
}
else {
out .= A_LoopField . Chr(10)
}
;;;;;;;;;;;;;; return
}
else {
out .= A_LoopField . Chr(10)
}
}
StringTrimRight, code, out, 1
if (doWeEverSeeExprestion = 1) {
code := "int ___HTLL_expression_helper___ := 0" . Chr(10) . code
}
out := ""
Loop, Parse, code, `n, `r {
if (SubStr(StrLower(Trim(A_LoopField)), 1, 6) = "loop, ") {
str1 := Trim(A_LoopField)
str2 := Trim(StrSplit(str1, ",", 2))
if (InStr(str2, ".size")) {
out .= Trim(str2) . Chr(10) . "Loop, rax" . Chr(10)
} else {
out .= A_LoopField . Chr(10)
}
}
else if (StrLower(Trim(A_LoopField)) = "loop") {
out .= "Loop, -1" . Chr(10)
} else {
out .= A_LoopField . Chr(10)
}
}
StringTrimRight, code, out, 1
out := ""
if (InStr(code, "{")) {
code := transformBracesToHTLL(code)
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
int dose_func_exist := 0
Loop, Parse, code, `n, `r {
if (SubStr(StrLower(Trim(A_LoopField)), 1, 5) = "func ") {
dose_func_exist := 1
break
}
}
int is_in_func := 0
int is_in_main := 0
arr str arrays_from_global_scope
arr str func_arrs_params
arr str func_arrs_params_ORIGINAL_NAME
arr str func_vars_and_arrs
arr str main_vars_and_arrs
arr str funcs_and_what_types
str ALoopField := ""
int AIndex := 0
int AAIndex := 0
int it_macth_arr_name := 0
out := ""
Loop, Parse, code, `n, `r {
if (SubStr(StrLower(Trim(A_LoopField)), 1, 5) = "func ") {
str1 := Trim(StringTrimLeft(Trim(A_LoopField), 5))
is_in_func := 1
str2 := ""
str3 := ""
str4 := ""
str5 := ""
str6 := ""
str7 := ""
str8 := ""
str9 := ""
func_arrs_params := []
str2 := Trim(StrSplit(str1, "(", 1))
str4 := Trim(StrSplit(str1, "(", 2))
str4 := StringTrimRight(str4, 1)
if (InStr(str2, " ")) {
; is an array func return
; get name of func
str3 := Trim(StrSplit(str2, " ", 2))
str8 := ""
str6 .= "arr __HTLL_ret_" . str3 . Chr(10)
str5 := ""
if (InStr(str1, "()") = false) {
Loop, Parse, str4, "," {
if (InStr(Trim(A_LoopField), " ")) {
; its an array param
func_arrs_params.add("__HTLL_param_" . str3 . "_" . Trim(StrSplit(Trim(A_LoopField), " ", 2)))
str8 .= Trim(StrSplit(Trim(A_LoopField), " ", 2)) . ","
func_arrs_params_ORIGINAL_NAME.add(Trim(StrSplit(Trim(A_LoopField), " ", 2)))
}
else {
str8 .= "__000_NOT-ARRAY_000__,"
str5 .= Trim(A_LoopField) . ", "
}
}
str8 := StringTrimRight(str8, 1)
funcs_and_what_types.add("yes|" . str3 . "|" . Trim(str8))
str5 := Trim(str5)
str5 := StringTrimRight(str5, 1)
}
else {
str5 := ""
funcs_and_what_types.add("yes|" . str3 . "|")
}
}
else {
; get name of func
str3 := Trim(str2)
str8 := ""
str5 := ""
if (InStr(str1, "()") = false) {
Loop, Parse, str4, "," {
if (InStr(Trim(A_LoopField), " ")) {
; its an array param
func_arrs_params.add("__HTLL_param_" . str3 . "_" . Trim(StrSplit(Trim(A_LoopField), " ", 2)))
str8 .= Trim(StrSplit(Trim(A_LoopField), " ", 2)) . ","
func_arrs_params_ORIGINAL_NAME.add(Trim(StrSplit(Trim(A_LoopField), " ", 2)))
}
else {
str8 .= "__000_NOT-ARRAY_000__,"
str5 .= Trim(A_LoopField) . ", "
}
}
str8 := StringTrimRight(str8, 1)
funcs_and_what_types.add("no|" . str3 . "|" . Trim(str8))
str5 := Trim(str5)
str5 := StringTrimRight(str5, 1)
}
else {
str5 := ""
funcs_and_what_types.add("no|" . str3 . "|")
}
}
Loop, func_arrs_params.size() {
str6 .= "arr " . func_arrs_params[A_Index] . Chr(10)
}
str6 .= "func " . str3 . "(" . str5 . ")"
out .= str6 . Chr(10)
str14 := str3
}
else if (Trim(A_LoopField) = "funcend") {
is_in_func := 0
str1 := ""
str2 := ""
str3 := ""
str4 := ""
str5 := ""
out .= A_LoopField . Chr(10)
}
else if (Trim(A_LoopField) = "main") {
is_in_main := 1
str1 := ""
str2 := ""
str3 := ""
str4 := ""
str5 := ""
out .= A_LoopField . Chr(10)
}
else {
if (is_in_func = 1) and (is_in_main = 0) {
; in a func
str1 := ""
str2 := ""
str4 := ""
str5 := ""
str1 := A_LoopField
if (SubStr(StrLower(Trim(A_LoopField)), 1, 4) = "arr ") or (SubStr(StrLower(Trim(A_LoopField)), 1, 4) = "int ") {
if (SubStr(StrLower(Trim(A_LoopField)), 1, 4) = "arr ") {
out .= "__HTLL_flocal_" . str3 . "_" . Trim(StringTrimLeft(Trim(A_LoopField), 4)) . ".clear" . Chr(10)
}
if (InStr(A_LoopField, " := ")) {
str2 := Trim(StrSplit(A_LoopField, ":=", 1))
str4 := Trim(StrSplit(A_LoopField, " ", 2))
}
else {
str2 := Trim(A_LoopField)
str4 := Trim(StrSplit(A_LoopField, " ", 2))
}
func_vars_and_arrs.add(str4)
}
Loop, func_arrs_params_ORIGINAL_NAME.size() {
str1 := RegExReplace(str1, "\b" . func_arrs_params_ORIGINAL_NAME[A_Index] . "\b", "__HTLL_param_" . str14 . "_" . func_arrs_params_ORIGINAL_NAME[A_Index])
}
Loop, func_vars_and_arrs.size() {
str1 := RegExReplace(str1, "\b" . func_vars_and_arrs[A_Index] . "\b", "__HTLL_flocal_" . str14 . "_" . func_vars_and_arrs[A_Index])
}
;::::::::::::::::::::::
;::::::::::::::::::::::
;::::::::::::::::::::::
;::::::::::::::::::::::
;::::::::::::::::::::::
;::::::::::::::::::::::
str6 := str1
Loop, funcs_and_what_types.size() {
if (InStr(A_LoopField, ")")) and (RegExMatch(A_LoopField, "\b" . StrSplit(funcs_and_what_types[A_Index], "|", 2) . "\b")) {
if (InStr(A_LoopField, " := ")) {
if (StrSplit(funcs_and_what_types[A_Index], "|", 1) = "no") {
throw ErrorMsg("ERROR You cannot use the assignment operator and save the function " . StrSplit(funcs_and_what_types[A_Index], "|", 2) . " please use rax.")
}
; for arrays
; for arrays
str1 := Trim(StrSplit(str6, " := ", 1))
str2 := Trim(StrSplit(str6, " := ", 2))
str3 := Trim(StrSplit(str2, "(", 1))
str4 := Trim(StrSplit(str2, "(", 2))
str4 := StringTrimRight(str4, 1)
; str1 = arrName
; str2 WE DONT CARE
; str3 = func name
; str4 = all params if any
if (Trim(str4) = "") {
; no param handle here
str5 := StrSplit(funcs_and_what_types[A_Index], "|", 2) . "()" . Chr(10)
str5 .= str1 . ".copy __HTLL_ret_" . StrSplit(funcs_and_what_types[A_Index], "|", 2) . Chr(10)
}
else {
; there are params so handle here
str7 := ""
str5 := ""
str8 := StrSplit(funcs_and_what_types[A_Index], "|", 3)
AAIndex := A_Index
Loop, Parse, str4, "," {
ALoopField := Trim(A_LoopField)
AIndex := A_Index
it_macth_arr_name := 0
Loop, Parse, str8, "," {
if (Trim(A_LoopField) != "__000_NOT-ARRAY_000__") and (AIndex = A_Index) {
ALoopField := Trim(A_LoopField)
if (Trim(ALoopField) != "") {
it_macth_arr_name := 1
}
break
}
}