-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCodeGen.dpr
More file actions
5493 lines (4961 loc) · 139 KB
/
CodeGen.dpr
File metadata and controls
5493 lines (4961 loc) · 139 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
library CodeGen;
uses
Windows,
kol,
MD5 in '..\FTCG\MD5.pas',
CGTShare in '..\CGTShare.pas',
Errors in 'Errors.pas';
{$define debug}
{define called_func} // òðåéñ íà âûçîâû ô-öèé
{define called_func_sec} // òðåéñ íà âûçîâû ô-öèé, êîòîðûå óäîâëåòâîðÿþò òðåáîâàíèþ òåêóùåé ñåêöèè
{define processed_func} // òðåéñ íà ïðîõîä òåëà ô-öèè
{define print_lexem} // âûâîä ñîäåðæèìîãî print
{define call_func} // âûçîâ ïîëüçîâàòåëüñêîé ô-öèè
{define event_call} // òðåéñ âûâîäà èìåí ñîáûòèé
{define processed_unit} // âûâîä èìåíè îáðàáàòûâàåìîãî unit-à
{define init_section} // âûâîä èìåíè êîìïîíåíòà, ÷üÿ init ñåêöèÿ âûçûâàåòñÿ â äàííûé ìîìåíò
{define _blocks_} // ðàáîòà ñ áëîêàìè êîäà
{define OP_CALL} // âûâîä âñåõ îïåðàòîðîâ
{define _damped_} // äàìï òðàíñëÿöèè êîäà ìåæäó ÿçûêàìè
(*
** todo
** - ïîòåðÿ ïàìÿòè äëÿ data_array
**
**
*)
type
TLangRec = record
entry:PChar;
name:PChar;
str_del_o:PChar;
str_del_c:PChar;
op_del:PChar;
var_mask:PChar;
tostr_proc:procedure(var s:string);
end;
type
TCGrec = record
Code:PStrList;
end;
PCGrec = ^TCGrec;
PSubType = ^TSubType;
TData = record
// òèï äàííûõ
data_type:byte;
// êîíòåéíåðû äàííûõ
idata:integer;
sdata:string;
rdata:real;
// ÿçûê äàííûõ
lang:byte;
level:integer; // óðîâåíü âëîæåííîñòè ÿçûêà
// ïîäòèï òèïà code
sub_type:PSubType;
// ôëàãè
flags:cardinal;
end;
TSubType = record
// òèï äàííûõ
data_type:byte;
// ïîäòèï
sub_type:PSubType;
end;
PScData = ^TScData;
PScArray = ^TScArray;
TScData = object
private
value:TData;
ldata:PScData;
procedure Clear;
public
procedure SetValue(const val:string); overload;
procedure SetValue(val:integer); overload;
procedure SetValue(val:real); overload;
procedure SetValue(val:boolean); overload;
procedure SetValue(const val:TData); overload;
procedure SetValue(const val:string; tp:byte); overload;
procedure AddValue(val:PScData; wo_op:boolean = false);
procedure AddNormalize(BaseLang:byte; BaseLevel:integer; data:PScData);
procedure GetValue(var val:TData);
procedure mtAttach(dt:PScData);
function mtGetCount:integer;
function mtGetItem(ind:integer):PScData;
function mtPop:PScData;
procedure SetAsMT;
function GetType:byte;
procedure SetType(tp:byte);
function GetLang:byte;
procedure SetLang(lang, level:byte);
function GetLevel:byte;
function GetSubType:byte;
procedure SetSubType(stype:byte);
function printDebug:string;
function toStr:string;
function toInt:integer;
function toReal:real;
function toCode:string;
function toBool:boolean;
function toArray:PScArray;
function isEmpty:boolean;
function isValue(const val:string):boolean;
function ReadItem(ind:integer):PScData;
procedure BuildArray;
//____ MATH _____
procedure mathAdd(val:PScData); overload;
procedure mathAdd(val:integer); overload;
procedure mathAdd(val:real); overload;
procedure mathAdd(const val:string); overload;
procedure mathSub(val:PScData);
procedure mathMul(val:PScData);
procedure mathDiv(val:PScData);
//function isStr:boolean;
//function isInt:boolean;
//function isReal:boolean;
end;
TScArray = record
Items:array of PScData;
Count:integer;
end;
TBlockStack = class
private
Items:array of record
LType:word;
skip:boolean;
userdata:pointer;
end;
Count:word;
public
procedure Push(_skip:boolean; _Type:word; _userdata:pointer);
function Pop(var _Skip:boolean;var _Type:word; var _userdata:pointer):boolean;
procedure Clear;
end;
TCodeBlockRec = record
StrList:PList;
level:integer;
FLevelEn:boolean;
end;
PCodeBlockRec = ^TCodeBlockRec;
TCodeBlock = class
private
FItems:PStrListEx;
CurItem:PCodeBlockRec;
Current:PList;
FCurName:string;
FGen:integer;
function Find(const Name:string):PCodeBlockRec;
function GetItems(Index:integer):PCodeBlockRec;
function GetCount:integer;
function GetLevel:integer;
procedure SetLevel(Value:integer);
function GenSpaces:string;
public
lsize:integer;
constructor Create;
destructor Destroy; override;
procedure LevelEnabled(value:boolean);
procedure Reg(const Name:string);
function RegGen:string;
function Select(const Name:string):string;
procedure Delete(const Name:string);
procedure CopyTo(const Source, Dest:string);
procedure Merge(List:PStrList);
procedure Add(text:PScData);
procedure Paste(text:PScData);
procedure AddStrings(list:PList);
procedure MergeFromFile(const FileName:string);
function Empty:boolean;
function isEmpty(const Name:string):boolean;
function AsText:TScData; // ïðåîáðàçîâàíèå ñ ó÷åòîì ÿçûêà
function AsCode:string; // ïðîñòîé ïåðåâîä âñåõ óçëîâ â Code
procedure SaveToFile(const fname, name:string; lang:byte; _asCode:boolean = false; checkHash:boolean = false);
property Items[Index:integer]:PCodeBlockRec read GetItems;
property Count:integer read GetCount;
property CurBlockName:string read FCurName;
property Level:integer read GetLevel write SetLevel;
property CurList:PList read Current;
end;
TArgs = class;
TFuncData = record
name:string;
Line:integer;
Skeep,fskeep:boolean;
inFunc:boolean;
fsection:integer;
_args_:TArgs;
_vars_:TArgs; // ëîêàëüíûå ïåðåìåííûå äëÿ îäíîé ô-öèè
_data_saved_:TScData;
end;
PFuncData = ^TFuncData;
TFuncState = record
Line:string;
LineIndex,LPos:integer;
Token,RToken:string;
TokType:byte;
fData:PFuncData;
end;
PFuncState = ^TFuncState;
TArgs = class
private
FItems:PStrListEx;
function GetValues(index:integer):PScData;
function GetNames(index:integer):string;
procedure SetNames(index:integer; const Value:string);
function GetCount:integer;
procedure SetValue(index:integer; value:PScData);
public
FIndex:integer;
constructor Create;
destructor Destroy; override;
function AddArg(const Name:string):PScData;
function find(const name:string):PScData;
procedure Remove(const name:string);
property Names[Index:integer]:string read GetNames write SetNames;
property Values[Index:integer]:PScData read GetValues write SetValue;
property Count:integer read GetCount;
end;
TWhileData = record
index:integer;
for_cond:string;
end;
PWhileData = ^TWhileData;
TElementData = record
VarList:TArgs;
LangList:TArgs;
end;
PElementData = ^TElementData;
TParser = class
private
VarList:TArgs; // ñïèñîê ëîêàëüíûõ ïåðåìåííûõ
LangList:TArgs; // ñïèñîê ïåðåìåííûõ öåëåâîãî ÿçûêà
funcList:PStrListEx;
_for_cond:string; // çàïëàòî÷êà...
_state_stack:PList;
function regGVar(const name:string):PScData;
procedure Debug(const text:string; color:TColor = clBlack);
function ToSection(var sec:integer):boolean;
procedure SaveState;
procedure LoadState;
function _points_count_(ptype:byte):integer;
function findProperty(const name:string):integer;
procedure LineInsert(index:integer; const line:string);
function ToType(const token:string; var tp:integer):boolean;
function CheckSkipped:boolean;
function CheckOpenArgs(const op:string):boolean;
function CheckCloseArgs(const op:string):boolean;
function CheckSymbol(const sym:string):boolean;
procedure Print(const Text:string);
procedure PrintLine;
protected
fData:PFuncData;
_data_return_:TScData;
Token,RToken:string;
TokType:byte;
uname:string;
Line:string;
Lines:PStrList;
LineIndex,LPos:integer;
oldLineIndex,oldLPos:integer;
cgt:PCodeGenTools;
el:id_element;
BlockStack:TBlockStack;
codeb:TCodeBlock;
_err_:boolean;
section:integer; // òåêóùàÿ ñåêöèÿ äëÿ èñõîäíèêà
function ReadLine:boolean;
procedure AddError(const Error:string);
procedure Start(const fname:string; Args:TArgs);
function ReadPoint(lp:id_point):PScData;
function ReadID:string;
procedure ReadValue(const Name:string; var _var_:PScData; null_data:boolean = true);
function Level1(var _var_:PScData; flag:integer = 0):boolean;
function Level2(var _var_:PScData; flag:integer):boolean; // ^
function Level2a(var _var_:PScData; flag:integer):boolean; // &, &&
function Level3(var _var_:PScData; flag:integer):boolean; // or, and
function Level4a(var _var_:PScData; flag:integer):boolean; // _or_, _and_
function Level4(var _var_:PScData; flag:integer):boolean; // =,<,>,<=,>=,!=
function Level5(var _var_:PScData; flag:integer):boolean; // - +
function Level6(var _var_:PScData; flag:integer):boolean; // * /
function Level7(var _var_:PScData; flag:integer):boolean; // ?
function Level8(var _var_:PScData; flag:integer):boolean; // !, not, -
function Level9(var _var_:PScData; flag:integer):boolean; // ++, --
function Level10(var _var_:PScData; flag:integer):boolean; // []
function Level11(var _var_:PScData; flag:integer):boolean; // @
function Level12(var _var_:PScData; flag:integer):boolean;
procedure FuncLexem(const fname:string; Args:TArgs);
function EndLexem:boolean;
procedure IncludeLexem;
procedure InlineLexem;
procedure SubLexem;
procedure SectionLexem;
procedure FVarLexem;
procedure VarLexem;
procedure GVarLexem;
procedure LangLexem;
procedure FreeLexem;
procedure ReturnLexem;
procedure ForLexem;
procedure WhileLexem;
procedure IfLexem;
procedure ElseIfLexem;
procedure ElseLexem;
procedure SwitchLexem;
procedure CaseLexem;
procedure IncSecLexem;
procedure DecSecLexem;
function EventLexem:PScData;
function mtEventLexem:PScData;
procedure PrintLexem;
procedure PrintLnLexem;
procedure VarOpLexem(var_int:PScData);
function ReadCustomValue:PScData;
function getInternalVar(const name:string; var int_var:PScData):boolean;
function getElementVar(const name:string; var el_var:PScData):boolean;
function getGlobalVar(const name:string; var gbl_var:PScData):boolean;
function getLangVar(const name:string; var lng_var:PScData):boolean;
function isFunction(const name:string; var ind:integer):boolean;
function isInternalFunction(const name:string; var ind:integer):boolean;
function isObject(const name:string; var ind:integer):boolean;
function LinkedLexem:boolean;
function IsDefLexem:boolean;
function IsSetLexem:boolean;
function IsPropLexem:boolean;
function StrLexem:PScData;
function CodeLexem:PScData;
function lCodeLexem:PScData;
function CvtLexem(toType:byte):PScData;
function CountLexem:PScData;
function IsSecLexem:boolean;
function TypeOfLexem:PScData;
function ExpOfLexem:PScData;
function SubLexem_res:PScData;
function CallFunc(ind:integer):PScData;
function CallIntFunc(ind:integer):PScData;
function CallObject(ind:integer):PScData;
function CallTypeConvertion(ind:integer):PScData;
function CallEvent(const event:string; data:TScData):PScData;
function CallEventMt(const event:string; args:TArgs):PScData;
public
constructor Create;
destructor Destroy; override;
procedure SetElement(e:id_element);
function GetToken:boolean;
procedure PutToken;
procedure Parse(_cgt:PCodeGenTools; e:id_element; const fname:string; _codeb:TCodeBlock; Args:TArgs; ret_data:PScData);
procedure ReadFuncList(list:PStrList; _cgt:PCodeGenTools; e:id_element; const fname:string);
function readSection(const s:string):integer;
end;
TMapProc = function (parser:TParser; args:TArgs):TScData;
TObjProc = function (parser:TParser; obj:pointer; index:integer; args:TArgs):TScData;
TFuncMap = record
name:string;
count:integer; // ïðè -1 êîëè÷åñòâî àðãóìåíòîâ íå ôèêñèðîâàííî
proc:TMapProc;
ainfo:string;
end;
TObjField = record
name:string;
end;
TObjMethod = record
name:string;
count:integer; // ïðè -1 êîëè÷åñòâî àðãóìåíòîâ íå ôèêñèðîâàííî
ainfo:string;
end;
TAObjMethod = array of TObjMethod;
TObjMap = record
name:string;
obj:pointer;
fields_count:integer; // êîëè÷åñòâî ïîëåé îáúåêòà
methods_count:integer; // êîëè÷åñòâî ìåòîäîâ îáúåêòà
fields:array of TObjField;
methods:TAObjMethod;
method_proc:TObjProc;
end;
const
data_object = 100; // íà÷àëüíîå çíà÷åíèå ïîëüçîâàòåëüñêèõ òèïîâ
// òèïû òîêåíîâ, âîçâðàùàåìûõ ïî GetTok
TokName = 1;
TokNumber = 2;
TokReal = 3;
TokString = 4;
TokSymbol = 5;
TokMath = 6;
TokCode = 7;
TokProp = 8;
// òèïû áëîêîâûõ îïåðàòîðîâ
BLK_FUNC = 0;
BLK_IF = 1;
BLK_ELSEIF = 2;
BLK_WHILE = 3;
BLK_SWITCH = 4;
BLK_CASE = 5;
MATH_ASSIGN = $01; // ðàñïîçíàíèå áåç ó÷åòà àðèôìåòèêè
DT_FLG_DIRECT = $01;
var el_cnt:integer;
nsection:integer; // òðåáóåìàÿ ñåêöèÿ
lang_level:integer; // óðîâåíü âëîæåííîñòè ÿçûêà
GVarList:TArgs; // ñïèñîê ãëîáàëüíûõ ïåðåìåííûõ
LngUserTypes:PStrListEx; // ñïèñîê ïîëüçîâàòåëüñêèõ òèïîâ êîíå÷íîãî ÿçûêà
LngTypeCounter:integer; // àâòîãåíåðàöèÿ ID äëÿ ïîëüçîâàòåëüñêèõ òèïîâ
hnt_point:id_point;
hnt_this:boolean;
hnt_message:string;
readCustomProperty:procedure(Result:PScData; e:id_element; cgt:PCodeGenTools; prop:id_prop);
{$ifdef _damped_}
list:PStrList;
{$endif}
procedure initAllFreeElements(cgt:PCodeGenTools; sdk:id_sdk); forward;
procedure call_init(cgt:PCodeGenTools; e:id_element; const proc:string); forward;
function MakeData(const str:string; code:boolean = false):PScData; overload;
begin
New(Result);
FillChar(Result^, sizeof(TScData), 0);
if code then
Result.SetValue(str, data_code)
else Result.SetValue(str);
end;
function MakeData(num:integer):PScData; overload;
begin
New(Result);
FillChar(Result^, sizeof(TScData), 0);
Result.SetValue(num);
end;
function MakeData(num:real):PScData; overload;
begin
New(Result);
FillChar(Result^, sizeof(TScData), 0);
Result.SetValue(num);
end;
function MakeData(value:boolean):PScData; overload;
begin
New(Result);
FillChar(Result^, sizeof(TScData), 0);
Result.SetValue(value);
end;
function MakeData(const value:TData):PScData; overload;
begin
New(Result);
FillChar(Result^, sizeof(TScData), 0);
Result.SetValue(value);
end;
function MakeData(data:PScData):PScData; overload;
var i:integer;
arr:PScArray;
begin
New(Result);
FillChar(Result^, sizeof(TScData), 0);
Result^ := data^;
if data.GetType = data_array then
begin
new(arr);
arr.Count := data.toArray().Count;
SetLength(arr.items, arr.count);
for i := 0 to arr.Count-1 do
arr.Items[i] := MakeData(data.toArray().Items[i]);
Result.value.idata := integer(arr);
Result.value.data_type := data_array;
end;
if Result.ldata <> nil then
Result.ldata := MakeData(Result.ldata);
end;
function MakeMethod(const name:string; count:integer; const ainfo:string):TObjMethod;
begin
Result.name := name;
Result.count := count;
Result.ainfo := ainfo;
end;
//____________________
function StrIComp(const Str1, Str2: PChar): Integer; assembler;
asm
PUSH EDI
PUSH ESI
MOV EDI,EDX
MOV ESI,EAX
MOV ECX,0FFFFFFFFH
XOR EAX,EAX
REPNE SCASB
NOT ECX
MOV EDI,EDX
XOR EDX,EDX
@@1: REPE CMPSB
JE @@4
MOV AL,[ESI-1]
CMP AL,'a'
JB @@2
CMP AL,'z'
JA @@2
SUB AL,20H
@@2: MOV DL,[EDI-1]
CMP DL,'a'
JB @@3
CMP DL,'z'
JA @@3
SUB DL,20H
@@3: SUB EAX,EDX
JE @@1
@@4: POP ESI
POP EDI
end;
function RegisterUserType(const Name:string):integer;
begin
Result := 0;
if LngUserTypes = nil then exit;
inc(LngTypeCounter);
LngUserTypes.AddObject(Name, LngTypeCounter);
Result := LngTypeCounter;
end;
function FindUserType(const Name:string; var ind:integer):boolean;
var i:integer;
begin
for i := 0 to LngUserTypes.Count-1 do
if StrIComp(PChar(Name), PChar(LngUserTypes.Items[i])) = 0 then
begin
ind := LngUserTypes.Objects[i];
result := true;
exit;
end;
Result := false;
end;
//*******************************************************
{$i direct.inc}
//*******************************************************
function map_replace(parser:TParser; args:TArgs):TScData;
var s:string;
tp:byte;
begin
s := args.Values[0].toStr();
// parser.cgt._Debug(PChar('Replace...' + args.Values[0].toStr() + ':' + args.Values[1].toStr()),clred);
Replace(s, args.Values[1].toStr(), args.Values[2].toStr());
tp := args.Values[0].GetType;
if tp <> data_code then
tp := data_str;
args.Values[0].SetValue(s, tp);
Result := args.Values[0]^;
end;
function map_lower(parser:TParser; args:TArgs):TScData;
begin
Result.SetValue(LowerCase(args.Values[0].toStr()), args.Values[0].GetType);
end;
function map_upper(parser:TParser; args:TArgs):TScData;
begin
Result.SetValue(UpperCase(args.Values[0].toStr()), args.Values[0].GetType);
end;
function map_pos(parser:TParser; args:TArgs):TScData;
begin
Result.SetValue(pos(args.Values[0].toStr(), args.Values[1].toStr()));
end;
function map_copy(parser:TParser; args:TArgs):TScData;
var tp:byte;
begin
tp := args.Values[0].GetType;
if tp <> data_code then
tp := data_str;
Result.SetValue(copy(args.Values[0].toStr(), args.Values[1].toInt(), args.Values[2].toInt()), tp);
end;
function map_delete(parser:TParser; args:TArgs):TScData;
var s:string;
tp:byte;
begin
s := args.Values[0].toStr();
delete(s, args.Values[1].toInt(), args.Values[2].toInt());
tp := args.Values[0].GetType;
if tp <> data_code then
tp := data_str;
args.Values[0].SetValue(s, tp);
Result := args.Values[0]^;
end;
function map_trace(parser:TParser; args:TArgs):TScData;
begin
Parser.Debug(Args.Values[0].toStr(), clGreen);
Result.SetValue('');
end;
function map_fopen(parser:TParser; args:TArgs):TScData;
var fs:PStream;
md,fname:string;
begin
fname := args.Values[0].toStr();
md := args.Values[1].toCode();
if md = 'r' then
fs := NewReadFileStream(fname)
else fs := NewWriteFileStream(fname);
Result.SetValue(integer(fs));
end;
function map_fputs(parser:TParser; args:TArgs):TScData;
var fs:PStream;
begin
fs := PStream(args.Values[0].toInt());
fs.WriteStr(args.Values[1].toCode() + #13#10);
Result.SetValue('');
end;
function map_fgets(parser:TParser; args:TArgs):TScData;
var fs:PStream;
s:string;
b:char;
begin
fs := PStream(args.Values[0].toInt());
s := '';
while fs.Position < fs.Size do
begin
fs.Read(b,1);
if b = #13 then
begin
fs.Read(b,1);
break;
end
else s := s + b;
end;
Result.SetValue(s);
end;
function map_fclose(parser:TParser; args:TArgs):TScData;
var fs:PStream;
begin
fs := PStream(args.Values[0].toInt());
fs.Free;
Result.SetValue('');
end;
function map_project_dir(parser:TParser; args:TArgs):TScData;
var ppath:array[0..255] of char;
begin
integer(pointer(@ppath)^) := Parser.el;
Parser.cgt.GetParam(PARAM_PROJECT_PATH, @ppath);
Result.SetValue(PChar(@ppath));
end;
function map_project_name(parser:TParser; args:TArgs):TScData;
var ppath:array[0..255] of char;
begin
integer(pointer(@ppath)^) := Parser.el;
Parser.cgt.GetParam(PARAM_PROJECT_NAME, @ppath);
Result.SetValue(ExtractFileNameWOExt(PChar(@ppath)));
end;
function map_error(parser:TParser; args:TArgs):TScData;
begin
Parser.AddError(args.Values[0].toStr());
Result.SetValue('');
end;
function map_lng_lvl(parser:TParser; args:TArgs):TScData;
begin
Result.SetValue(lang_level);
lang_level := lang_level + args.Values[0].toInt();
end;
const
// êàðòà âñòðîåíûõ ô-öèé ÿçûêà
func_map_size = 15;
func_map:array[0..func_map_size-1] of TFuncMap = (
// ------------ STRINGS ----------------------------
(name: 'replace'; count:3; proc:map_replace; ainfo: 'str, dst, src'),
(name: 'lower'; count:1; proc:map_lower; ainfo: 'str'),
(name: 'upper'; count:1; proc:map_upper; ainfo: 'str'),
(name: 'copy'; count:3; proc:map_copy; ainfo: 'str, position, length'),
(name: 'pos'; count:2; proc:map_pos; ainfo: 'substr, str'),
(name: 'delete'; count:3; proc:map_delete; ainfo: 'str, position, length'),
// ------------ SYSTEM -----------------------------
(name: 'trace'; count:1; proc:map_trace; ainfo: 'text'),
(name: 'error'; count:1; proc:map_error; ainfo: 'text'),
(name: 'lng_lvl'; count:1; proc:map_lng_lvl; ainfo: 'increment'),
// ------------ FILES ------------------------------
(name: 'fopen'; count:2; proc:map_fopen; ainfo: 'filename, mode'),
(name: 'fputs'; count:2; proc:map_fputs; ainfo: 'id, str'),
(name: 'fgets'; count:1; proc:map_fgets; ainfo: 'id'),
(name: 'fclose'; count:1; proc:map_fclose; ainfo: 'id'),
// ------------ ENVEROUMENT ------------------------
(name: 'project_dir'; count:0; proc:map_project_dir; ainfo: ''),
(name: 'project_name'; count:0; proc:map_project_name; ainfo: '')
);
var
// êàðòà âñòðîåííûõ îáúåêòîâ ÿçûêà
obj_map_size:integer;
obj_map:array of TObjMap;
function block_proc(parser:TParser; obj:TCodeBlock; index:integer; args:TArgs):TScData;
var s:string;
i:integer;
begin
Result.SetValue('');
case index of
0: obj.Reg(args.Values[0].toStr());
1: Result.SetValue(obj.Select(args.Values[0].toStr()));
2: obj.Delete(args.Values[0].toStr());
3: obj.CopyTo(obj.CurBlockName,args.Values[0].toStr());
4: Result := obj.AsText();
5: if hnt_point = 0 then obj.SaveToFile(args.Values[0].toStr(),obj.CurBlockName, parser.section);
6: Result.SetValue(obj.CurBlockName);
7: Result.SetValue(obj.RegGen());
8: Result.SetValue(obj.empty());
9: obj.level := obj.level + 1;
10: obj.level := obj.level - 1;
11: Result.SetValue(obj.level);
12: obj.LevelEnabled(true);
13: obj.LevelEnabled(false);
14: Result.SetValue(obj.CurItem.FLevelEn);
15: obj.CopyTo(args.Values[0].toStr(),obj.CurBlockName);
16: Result.SetValue(obj.isEmpty(args.Values[0].toStr()));
17:
begin
s := obj.AsCode();
lngs[nsection].tostr_proc(s);
Result.SetValue(s);
end;
18:
begin
Result.SetValue(false);
s := args.Values[0].toStr();
for i := 0 to obj.CurList.Count-1 do
//if s = PScData(obj.CurList.Items[i]).value.sdata then // Èùåò òîëüêî íà ñîâïàäåíèå öåëîé ñòðîêè (NetSpirit)
if IndexOfStr(PScData(obj.CurList.Items[i]).value.sdata, s) > -1 then
begin
Result.SetValue(true);
break;
end;
end;
19: obj.SaveToFile(args.Values[0].toStr(),obj.CurBlockName, parser.section, true, true);
20: obj.MergeFromFile(args.Values[0].toStr());
end;
end;
function ReadPointByTypeIndex(parser:TParser; ind:integer; ptype:byte):id_point;
var i,c:integer;
begin
Result := 0;
c := 0;
with parser do
for i := 0 to cgt.elGetPtCount(el)-1 do
if cgt.ptGetType(cgt.elGetPt(el, i)) = ptype then
if c = ind then
begin
Result := cgt.elGetPt(el, i);
exit;
end
else inc(c)
end;
const
CGT_pt_get_parent = 0;
CGT_pt_get_link_point = CGT_pt_get_parent + 1;
CGT_pt_get_rlink_point= CGT_pt_get_link_point + 1;
CGT_pt_get_name = CGT_pt_get_rlink_point + 1;
CGT_pt_get_name_byid = CGT_pt_get_name + 1;
CGT_pt_arr_work = CGT_pt_get_name_byid + 1;
CGT_pt_arr_event = CGT_pt_arr_work + 1;
CGT_pt_arr_var = CGT_pt_arr_event + 1;
CGT_pt_arr_data = CGT_pt_arr_var + 1;
CGT_pt_get_type = CGT_pt_arr_data + 1;
CGT_pt_get_data_type = CGT_pt_get_type + 1;
CGT_el_get_class_name = CGT_pt_get_data_type + 1;
CGT_el_get_code_name = CGT_el_get_class_name + 1;
CGT_el_get_child_id = CGT_el_get_code_name + 1;
CGT_el_get_parent_id = CGT_el_get_child_id + 1;
CGT_el_get_point_name = CGT_el_get_parent_id + 1;
CGT_el_link_is = CGT_el_get_point_name + 1;
CGT_el_link_main = CGT_el_link_is + 1;
CGT_el_get_parent = CGT_el_link_main + 1;
CGT_get_point_id = CGT_el_get_parent + 1;
CGT_sdk_get_count = CGT_get_point_id + 1;
CGT_sdk_get_element = CGT_sdk_get_count + 1;
CGT_sdk_get_element_name = CGT_sdk_get_element + 1;
CGT_res_add_file = CGT_sdk_get_element_name + 1;
function cgt_proc(parser:TParser; obj:pointer; index:integer; args:TArgs):TScData;
begin
with parser do
case index of
CGT_pt_get_parent: Result.SetValue(cgt.ptGetParent(args.Values[0].toInt()));
CGT_pt_get_link_point: Result.SetValue(cgt.ptGetLinkPoint(args.Values[0].toInt()));
CGT_pt_get_rlink_point: Result.SetValue(cgt.ptGetRLinkPoint(args.Values[0].toInt()));
CGT_pt_get_name: Result.SetValue(cgt.ptGetName(cgt.elGetPt(Parser.el, args.Values[0].toInt())));
CGT_pt_get_name_byid: Result.SetValue(cgt.ptGetName(args.Values[0].toInt()));
CGT_pt_arr_work..CGT_pt_arr_data: Result.SetValue(ReadPointByTypeIndex(parser,args.Values[0].toInt(), index - CGT_pt_arr_work + 1));
CGT_pt_get_type: Result.SetValue(cgt.ptGetType(args.Values[0].toInt()));
CGT_pt_get_data_type: Result.SetValue(cgt.ptGetDataType(args.Values[0].toInt()));
CGT_el_get_class_name: Result.SetValue(cgt.elGetClassName(args.Values[0].toInt()));
CGT_el_get_code_name: Result.SetValue(cgt.elGetCodeName(args.Values[0].toInt()));
CGT_el_get_child_id: Result.SetValue(cgt.sdkGetElement(cgt.elGetSDK(el),args.Values[0].toInt()));
CGT_el_get_parent_id: Result.SetValue(cgt.elGetSDK(parser.el));
CGT_el_get_point_name: Result.SetValue(cgt.elGetPtName(args.Values[0].toInt(), PChar(args.Values[1].toStr())));
CGT_el_link_is: Result.SetValue(cgt.elLinkIs(parser.el));
CGT_el_link_main: Result.SetValue(cgt.elLinkMain(parser.el));
CGT_el_get_parent: Result.SetValue(cgt.elGetParent(args.Values[0].toInt()));
CGT_get_point_id: Result.SetValue(cgt.elGetPtName(el,PChar(args.Values[0].toStr())));
CGT_sdk_get_count: Result.SetValue(cgt.sdkGetCount(args.Values[0].toInt()));
CGT_sdk_get_element: Result.SetValue(cgt.sdkGetElement(args.Values[0].toInt(), args.Values[1].toInt()));
CGT_sdk_get_element_name: Result.SetValue(cgt.sdkGetElementName(args.Values[0].toInt(), PChar(args.Values[1].toStr)));
CGT_res_add_file:
begin
if hnt_point = 0 then Result.SetValue(cgt.resAddFile(PChar(args.Values[0].toStr())));
end;
end;
end;
function TimeToStr(const Format:string; const t:TSystemTime):string;
const namstr:string = 'YMWDhms';
type TTimeValue = array[0..6] of WORD;
PTimeValue = ^TTimeValue;
var
i:byte;
function TwoDigit(value:integer):string;
begin
if Value < 10 then
Result := '0' + Int2Str(value)
else Result := Int2Str(value);
end;
begin
Result := Format;
for i := 0 to 6 do
Replace(Result,namstr[i+1],TwoDigit(PTimeValue(@t)^[i]));
end;
function sys_proc(parser:TParser; obj:pointer; index:integer; args:TArgs):TScData;
var ind:integer;
buf:array[0..128] of char;
SystemTime: TSystemTime;
e:id_element;
pars:TParser;
pargs:TArgs;
begin
case index of
0:
begin
Result.SetValue(parser.el);
e := args.Values[0].toInt();
if parser.cgt.elGetData(e) = nil then
call_init(parser.cgt, e, 'initFree');
parser.SetElement(e);
end;
1: Result.SetValue(GVarList.Count);
2:
if GVarList.find(args.Values[0].toStr()) <> nil then
Result.SetValue(GVarList.FIndex)
else Result.SetValue(-1);
3,4,5,6:
begin
ind := args.Values[0].toInt();
if(ind >= 0)and(ind < GVarList.Count)then
case index of
3: Result.SetValue(GVarList.Names[ind]);
4: Result := GVarList.Values[ind]^;
5: GVarList.Values[ind]^ := args.Values[1]^;
6: GVarList.Remove(GVarList.Names[ind]);
end;
end;
7: Result.SetValue(obj_map_size);
8:
begin
ind := args.Values[0].toInt;
if(ind >= 0)and(ind < obj_map_size)then
Result.SetValue(obj_map[ind].name)
else Result.SetValue('Unknown');
end;
9: Result.SetValue(Parser.el);
10:
begin
StrCopy(buf, PChar(args.Values[0].toStr()));
Parser.cgt.GetParam(PARAM_HIASM_VERSION, @buf);
Result.SetValue(PChar(@buf[0]));
end;
11:
begin
GetLocalTime(SystemTime);
Result.SetValue(TimeToStr(args.Values[0].toStr(),SystemTime));
end;
12:
begin
Result.SetValue(el_cnt);
el_cnt := args.Values[0].toInt();
end;
13: initAllFreeElements(parser.cgt, parser.cgt.elGetParent(parser.el));
14: Result.SetValue(parser.cgt.ReadCodeDir(parser.el));
15:
begin
pars := TParser.create;
pargs:= TArgs.create;
for ind := 2 to args.count-1 do
begin
pargs.AddArg('');
pargs.Values [ind-2] := args.Values [ind];
end;
pars.Parse(parser.cgt, args.Values[0].toInt(), args.Values[1].toStr(), parser.codeb, pargs, @result);
pars.destroy;
pargs.destroy;
end;
end;
end;
function array_proc(parser:TParser; obj:pointer; index:integer; args:TArgs):TScData;
var i:integer;
s,d,nv:string;
dt:PScData;
begin
case index of
0: // count
if args.Values[0].GetType = data_array then
Result.SetValue(args.Values[0].toArray().count)
else Result.SetValue(1);
1: // join
if args.Values[0].GetType = data_array then
begin
s := '';
d := args.Values[1].toStr;
for i := 0 to args.Values[0].toArray().count-1 do
begin
case args.Values[1].GetType of
data_str: nv := args.Values[0].toArray().Items[i].toStr;
data_code: nv := args.Values[0].toArray().Items[i].toCode;
else nv := args.Values[0].toArray().Items[i].toStr;
end;
if i = 0 then
s := nv
else s := s + d + nv;
end;
Result.SetValue(s, args.Values[1].GetType);
end