-
Notifications
You must be signed in to change notification settings - Fork 0
/
uPSComponent.pas
1572 lines (1303 loc) · 42.4 KB
/
uPSComponent.pas
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
unit uPSComponent;
{$I PascalScript.inc}
interface
uses
SysUtils, Classes, uPSRuntime, uPSDebugger, uPSUtils,
uPSCompiler, uPSC_dll, uPSR_dll, uPSPreProcessor;
const
{alias to @link(ifps3.cdRegister)}
cdRegister = uPSRuntime.cdRegister;
{alias to @link(ifps3.cdPascal)}
cdPascal = uPSRuntime.cdPascal;
CdCdecl = uPSRuntime.CdCdecl;
CdStdCall = uPSRuntime.CdStdCall;
type
TPSScript = class;
TDelphiCallingConvention = uPSRuntime.TPSCallingConvention;
{Alias to @link(ifps3.TPSRuntimeClassImporter)}
TPSRuntimeClassImporter = uPSRuntime.TPSRuntimeClassImporter;
TPSPlugin = class(TComponent)
public
procedure CompOnUses(CompExec: TPSScript); virtual;
procedure ExecOnUses(CompExec: TPSScript); virtual;
procedure CompileImport1(CompExec: TPSScript); virtual;
procedure CompileImport2(CompExec: TPSScript); virtual;
procedure ExecImport1(CompExec: TPSScript; const ri: TPSRuntimeClassImporter); virtual;
procedure ExecImport2(CompExec: TPSScript; const ri: TPSRuntimeClassImporter); virtual;
end;
TIFPS3Plugin = class(TPSPlugin);
TPSDllPlugin = class(TPSPlugin)
public
procedure CompOnUses(CompExec: TPSScript); override;
procedure ExecOnUses(CompExec: TPSScript); override;
end;
TIFPS3DllPlugin = class(TPSDllPlugin);
TPSPluginItem = class(TCollectionItem)
private
FPlugin: TPSPlugin;
procedure SetPlugin(const Value: TPSPlugin);
protected
function GetDisplayName: string; override;
public
procedure Assign(Source: TPersistent); override; //Birb
published
property Plugin: TPSPlugin read FPlugin write SetPlugin;
end;
TIFPS3CEPluginItem = class(TPSPluginItem);
TPSPlugins = class(TCollection)
private
FCompExec: TPSScript;
protected
function GetOwner: TPersistent; override;
public
constructor Create(CE: TPSScript);
end;
TIFPS3CEPlugins = class(TPSPlugins);
TPSOnGetNotVariant = function (Sender: TPSScript; const Name: tbtstring): Variant of object;
TPSOnSetNotVariant = procedure (Sender: TPSScript; const Name: tbtstring; V: Variant) of object;
TPSCompOptions = set of (icAllowNoBegin, icAllowUnit, icAllowNoEnd, icBooleanShortCircuit);
TPSVerifyProc = procedure (Sender: TPSScript; Proc: TPSInternalProcedure; const Decl: tbtstring; var Error: Boolean) of object;
TPSEvent = procedure (Sender: TPSScript) of object;
TPSOnCompImportEvent = procedure (Sender: TObject; x: TPSPascalCompiler) of object;
TPSOnExecImportEvent = procedure (Sender: TObject; se: TPSExec; x: TPSRuntimeClassImporter) of object;
{Script engine event function}
TPSOnNeedFile = function (Sender: TObject; const OrginFileName: tbtstring; var FileName, Output: tbtstring): Boolean of object;
{ Added by Wizzup }
TPSOnFileAlreadyIncluded = function (Sender: TObject; OrgFileName, FileName: tbtstring): Boolean of object;
TPSOnIncludingFile = function (Sender: TObject; OrgFileName, FileName: tbtstring): Boolean of object;
{ Wizzup out }
TPSOnProcessDirective = procedure (
Sender: TPSPreProcessor;
Parser: TPSPascalPreProcessorParser;
const Active: Boolean;
const DirectiveName, DirectiveParam: tbtstring;
Var Continue: Boolean;
Filename: tbtString) of Object; // jgv
TPSScript = class(TComponent)
private
FOnGetNotificationVariant: TPSOnGetNotVariant;
FOnSetNotificationVariant: TPSOnSetNotVariant;
FCanAdd: Boolean;
FComp: TPSPascalCompiler;
FCompOptions: TPSCompOptions;
FExec: TPSDebugExec;
FSuppressLoadData: Boolean;
FScript: TStrings;
FOnLine: TNotifyEvent;
FUseDebugInfo: Boolean;
FOnAfterExecute, FOnCompile, FOnExecute: TPSEvent;
FOnCompImport: TPSOnCompImportEvent;
FOnExecImport: TPSOnExecImportEvent;
RI: TPSRuntimeClassImporter;
FPlugins: TPSPlugins;
FPP: TPSPreProcessor;
FMainFileName: tbtstring;
FOnNeedFile: TPSOnNeedFile;
{ Added by Wizzup }
FOnFileAlreadyIncluded: TPSOnFileAlreadyIncluded;
FOnIncludingFile: TPSOnIncludingFile;
{ Wizzup out }
FUsePreProcessor: Boolean;
FDefines: TStrings;
FOnVerifyProc: TPSVerifyProc;
FOnProcessDirective: TPSOnProcessDirective;
FOnProcessUnknowDirective: TPSOnProcessDirective;
FOnFindUnknownFile: TPSOnNeedFile;
function GetRunning: Boolean;
procedure SetScript(const Value: TStrings);
function GetCompMsg(i: Integer): TPSPascalCompilerMessage;
function GetCompMsgCount: Longint;
function GetAbout: tbtstring;
function ScriptUses(Sender: TPSPascalCompiler; const Name: tbtstring): Boolean;
function GetExecErrorByteCodePosition: Cardinal;
function GetExecErrorCode: TIFError;
function GetExecErrorParam: tbtstring;
function GetExecErrorProcNo: Cardinal;
function GetExecErrorString: tbtstring;
function GetExecErrorPosition: Cardinal;
function GetExecErrorCol: Cardinal;
function GetExecErrorRow: Cardinal;
function GetExecErrorFileName: tbtstring;
procedure SetDefines(const Value: TStrings);
protected
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
protected
//jgv move where private before - not very usefull
procedure OnLineEvent; virtual;
procedure SetMainFileName(const Value: tbtstring); virtual;
//--jgv new
function DoOnNeedFile (Sender: TObject; const OrginFileName: tbtstring; var FileName, Output: tbtstring): Boolean; virtual;
{ Added by Wizzup }
function DoOnFileAlreadyIncluded (Sender: TObject; OrgFileName, FileName: tbtstring): Boolean; virtual;
function DoOnIncludingFile (Sender: TObject; OrgFileName, FileName: tbtstring): Boolean; virtual;
{ Wizzup out }
function DoOnUnknowUses (Sender: TPSPascalCompiler; const Name: tbtstring): Boolean; virtual; // return true if processed
procedure DoOnCompImport; virtual;
procedure DoOnCompile; virtual;
function DoVerifyProc (Sender: TPSScript; Proc: TPSInternalProcedure; const Decl: tbtstring): Boolean; virtual;
procedure DoOnExecImport (RunTimeImporter: TPSRuntimeClassImporter); virtual;
procedure DoOnExecute (RunTimeImporter: TPSRuntimeClassImporter); virtual;
procedure DoAfterExecute; virtual;
function DoOnGetNotificationVariant (const Name: tbtstring): Variant; virtual;
procedure DoOnSetNotificationVariant (const Name: tbtstring; V: Variant); virtual;
procedure DoOnProcessDirective (Sender: TPSPreProcessor;
Parser: TPSPascalPreProcessorParser;
const Active: Boolean;
const DirectiveName, DirectiveParam: tbtstring;
Var Continue: Boolean;
Filename: tbtString); virtual;
procedure DoOnProcessUnknowDirective (Sender: TPSPreProcessor;
Parser: TPSPascalPreProcessorParser;
const Active: Boolean;
const DirectiveName, DirectiveParam: tbtstring;
Var Continue: Boolean;
Filename: tbtString); virtual;
public
property RuntimeImporter: TPSRuntimeClassImporter read RI;
function FindNamedType(const Name: tbtstring): TPSTypeRec;
function FindBaseType(Bt: TPSBaseType): TPSTypeRec;
property SuppressLoadData: Boolean read FSuppressLoadData write FSuppressLoadData;
function LoadExec: Boolean;
procedure Stop; virtual;
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function Compile: Boolean; virtual;
function Execute: Boolean; virtual;
property Running: Boolean read GetRunning;
procedure GetCompiled(var data: tbtstring);
procedure SetCompiled(const Data: tbtstring);
property Comp: TPSPascalCompiler read FComp;
property Exec: TPSDebugExec read FExec;
property CompilerMessageCount: Longint read GetCompMsgCount;
property CompilerMessages[i: Longint]: TPSPascalCompilerMessage read GetCompMsg;
function CompilerErrorToStr(I: Longint): tbtstring;
property ExecErrorCode: TIFError read GetExecErrorCode;
property ExecErrorParam: tbtstring read GetExecErrorParam;
property ExecErrorToString: tbtstring read GetExecErrorString;
property ExecErrorProcNo: Cardinal read GetExecErrorProcNo;
property ExecErrorByteCodePosition: Cardinal read GetExecErrorByteCodePosition;
property ExecErrorPosition: Cardinal read GetExecErrorPosition;
property ExecErrorRow: Cardinal read GetExecErrorRow;
property ExecErrorCol: Cardinal read GetExecErrorCol;
property ExecErrorFileName: tbtstring read GetExecErrorFileName;
function AddFunctionEx(Ptr: Pointer; const Decl: tbtstring; CallingConv: TDelphiCallingConvention): Boolean;
function AddFunction(Ptr: Pointer; const Decl: tbtstring): Boolean;
function AddMethodEx(Slf, Ptr: Pointer; const Decl: tbtstring; CallingConv: TDelphiCallingConvention): Boolean;
function AddMethod(Slf, Ptr: Pointer; const Decl: tbtstring): Boolean;
function AddRegisteredVariable(const VarName, VarType: tbtstring): Boolean;
function AddNotificationVariant(const VarName: tbtstring): Boolean;
function AddRegisteredPTRVariable(const VarName, VarType: tbtstring): Boolean;
function GetVariable(const Name: tbtstring): PIFVariant;
function SetVarToInstance(const VarName: tbtstring; cl: TObject): Boolean;
procedure SetPointerToData(const VarName: tbtstring; Data: Pointer; aType: TIFTypeRec);
function TranslatePositionPos(Proc, Position: Cardinal; var Pos: Cardinal; var fn: tbtstring): Boolean;
function TranslatePositionRC(Proc, Position: Cardinal; var Row, Col: Cardinal; var fn: tbtstring): Boolean;
function GetProcMethod(const ProcName: tbtstring): TMethod;
function ExecuteFunction(const Params: array of Variant; const ProcName: tbtstring): Variant;
published
property About: tbtstring read GetAbout stored false;
property Script: TStrings read FScript write SetScript;
property CompilerOptions: TPSCompOptions read FCompOptions write FCompOptions;
property OnLine: TNotifyEvent read FOnLine write FOnLine;
property OnCompile: TPSEvent read FOnCompile write FOnCompile;
property OnExecute: TPSEvent read FOnExecute write FOnExecute;
property OnAfterExecute: TPSEvent read FOnAfterExecute write FOnAfterExecute;
property OnCompImport: TPSOnCompImportEvent read FOnCompImport write FOnCompImport;
property OnExecImport: TPSOnExecImportEvent read FOnExecImport write FOnExecImport;
property UseDebugInfo: Boolean read FUseDebugInfo write FUseDebugInfo default True;
property Plugins: TPSPlugins read FPlugins write FPlugins;
property MainFileName: tbtstring read FMainFileName write SetMainFileName;
property UsePreProcessor: Boolean read FUsePreProcessor write FUsePreProcessor;
property OnNeedFile: TPSOnNeedFile read FOnNeedFile write FOnNeedFile;
{ Added by Wizzup }
property OnFileAlreadyIncluded: TPSOnFileAlreadyIncluded read FOnFileAlreadyIncluded write FOnFileAlreadyIncluded;
property OnIncludingFile: TPSOnIncludingFile read FOnIncludingFile write FOnIncludingFile;
{ Wizzup out }
property Defines: TStrings read FDefines write SetDefines;
property OnVerifyProc: TPSVerifyProc read FOnVerifyProc write FOnVerifyProc;
property OnGetNotificationVariant: TPSOnGetNotVariant read FOnGetNotificationVariant write FOnGetNotificationVariant;
property OnSetNotificationVariant: TPSOnSetNotVariant read FOnSetNotificationVariant write FOnSetNotificationVariant;
property OnFindUnknownFile: TPSOnNeedFile read FOnFindUnknownFile write FOnFindUnknownFile;
published
//-- jgv
property OnProcessDirective: TPSOnProcessDirective read FOnProcessDirective write FOnProcessDirective;
property OnProcessUnknowDirective: TPSOnProcessDirective read FOnProcessUnknowDirective write FOnProcessUnknowDirective;
end;
TIFPS3CompExec = class(TPSScript);
TPSBreakPointInfo = class
private
FLine: Longint;
FFileNameHash: Longint;
FFileName: tbtstring;
procedure SetFileName(const Value: tbtstring);
public
property FileName: tbtstring read FFileName write SetFileName;
property FileNameHash: Longint read FFileNameHash;
property Line: Longint read FLine write FLine;
end;
TPSOnLineInfo = procedure (Sender: TObject; const FileName: tbtstring; Position, Row, Col: Cardinal) of object;
TPSScriptDebugger = class(TPSScript)
private
FOnIdle: TNotifyEvent;
FBreakPoints: TIFList;
FOnLineInfo: TPSOnLineInfo;
FLastRow: Cardinal;
FOnBreakpoint: TPSOnLineInfo;
function GetBreakPoint(I: Integer): TPSBreakPointInfo;
function GetBreakPointCount: Longint;
protected
procedure SetMainFileName(const Value: tbtstring); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Pause; virtual;
procedure Resume; virtual;
procedure StepInto; virtual;
procedure StepOver; virtual;
procedure SetBreakPoint(const Fn: tbtstring; Line: Longint);
procedure ClearBreakPoint(const Fn: tbtstring; Line: Longint);
property BreakPointCount: Longint read GetBreakPointCount;
property BreakPoint[I: Longint]: TPSBreakPointInfo read GetBreakPoint;
function HasBreakPoint(const Fn: tbtstring; Line: Longint): Boolean;
procedure ClearBreakPoints;
function GetVarContents(const Name: tbtstring): tbtstring;
published
property OnIdle: TNotifyEvent read FOnIdle write FOnIdle;
property OnLineInfo: TPSOnLineInfo read FOnLineInfo write FOnLineInfo;
property OnBreakpoint: TPSOnLineInfo read FOnBreakpoint write FOnBreakpoint;
end;
TIFPS3DebugCompExec = class(TPSScriptDebugger);
TPSCustomPlugin = class(TPSPlugin)
private
FOnCompileImport2: TPSEvent;
FOnExecOnUses: TPSEvent;
FOnCompOnUses: TPSEvent;
FOnCompileImport1: TPSEvent;
FOnExecImport1: TPSOnExecImportEvent;
FOnExecImport2: TPSOnExecImportEvent;
public
procedure CompOnUses(CompExec: TPSScript); override;
procedure ExecOnUses(CompExec: TPSScript); override;
procedure CompileImport1(CompExec: TPSScript); override;
procedure CompileImport2(CompExec: TPSScript); override;
procedure ExecImport1(CompExec: TPSScript; const ri: TPSRuntimeClassImporter); override;
procedure ExecImport2(CompExec: TPSScript; const ri: TPSRuntimeClassImporter); override;
public
published
property OnCompOnUses : TPSEvent read FOnCompOnUses write FOnCompOnUses;
property OnExecOnUses: TPSEvent read FOnExecOnUses write FOnExecOnUses;
property OnCompileImport1: TPSEvent read FOnCompileImport1 write FOnCompileImport1;
property OnCompileImport2: TPSEvent read FOnCompileImport2 write FOnCompileImport2;
property OnExecImport1: TPSOnExecImportEvent read FOnExecImport1 write FOnExecImport1;
property OnExecImport2: TPSOnExecImportEvent read FOnExecImport2 write FOnExecImport2;
end;
implementation
{$IFDEF DELPHI3UP }
resourceString
{$ELSE }
const
{$ENDIF }
RPS_UnableToReadVariant = 'Unable to read variant';
RPS_UnableToWriteVariant = 'Unable to write variant';
RPS_ScripEngineAlreadyRunning = 'Script engine already running';
RPS_ScriptNotCompiled = 'Script is not compiled';
RPS_NotRunning = 'Not running';
RPS_UnableToFindVariable = 'Unable to find variable';
RPS_UnknownIdentifier = 'Unknown Identifier';
RPS_NoScript = 'No script';
function MyGetVariant(Sender: TPSExec; const Name: tbtstring): Variant;
begin
Result := TPSScript (Sender.Id).DoOnGetNotificationVariant(Name);
end;
procedure MySetVariant(Sender: TPSExec; const Name: tbtstring; V: Variant);
begin
TPSScript (Sender.Id).DoOnSetNotificationVariant(Name, V);
end;
function CompScriptUses(Sender: TPSPascalCompiler; const Name: tbtstring): Boolean;
begin
Result := TPSScript(Sender.ID).ScriptUses(Sender, Name);
end;
procedure ExecOnLine(Sender: TPSExec);
begin
if assigned(TPSScript(Sender.ID).FOnLine) then
begin
TPSScript(Sender.ID).OnLineEvent;
end;
end;
function CompExportCheck(Sender: TPSPascalCompiler; Proc: TPSInternalProcedure; const ProcDecl: tbtstring): Boolean;
begin
Result := TPSScript(Sender.ID).DoVerifyProc (Sender.ID, Proc, ProcDecl);
end;
procedure callObjectOnProcessDirective (
Sender: TPSPreProcessor;
Parser: TPSPascalPreProcessorParser;
const Active: Boolean;
const DirectiveName, DirectiveParam: tbtstring;
Var Continue: Boolean; Filename: tbtstring);
begin
TPSScript (Sender.ID).DoOnProcessDirective(Sender, Parser, Active, DirectiveName, DirectiveParam, Continue, Filename);
end;
procedure callObjectOnProcessUnknowDirective (
Sender: TPSPreProcessor;
Parser: TPSPascalPreProcessorParser;
const Active: Boolean;
const DirectiveName, DirectiveParam: tbtstring;
Var Continue: Boolean; Filename: tbtString);
begin
TPSScript (Sender.ID).DoOnProcessUnknowDirective(Sender, Parser, Active, DirectiveName, DirectiveParam, Continue, Filename);
end;
{ TPSPlugin }
procedure TPSPlugin.CompileImport1(CompExec: TPSScript);
begin
// do nothing
end;
procedure TPSPlugin.CompileImport2(CompExec: TPSScript);
begin
// do nothing
end;
procedure TPSPlugin.CompOnUses(CompExec: TPSScript);
begin
// do nothing
end;
procedure TPSPlugin.ExecImport1(CompExec: TPSScript; const ri: TPSRuntimeClassImporter);
begin
// do nothing
end;
procedure TPSPlugin.ExecImport2(CompExec: TPSScript; const ri: TPSRuntimeClassImporter);
begin
// do nothing
end;
procedure TPSPlugin.ExecOnUses(CompExec: TPSScript);
begin
// do nothing
end;
{ TPSScript }
function TPSScript.AddFunction(Ptr: Pointer;
const Decl: tbtstring): Boolean;
begin
Result := AddFunctionEx(Ptr, Decl, cdRegister);
end;
function TPSScript.AddFunctionEx(Ptr: Pointer; const Decl: tbtstring;
CallingConv: TDelphiCallingConvention): Boolean;
var
P: TPSRegProc;
begin
if not FCanAdd then begin Result := False; exit; end;
p := Comp.AddDelphiFunction(Decl);
if p <> nil then
begin
Exec.RegisterDelphiFunction(Ptr, p.Name, CallingConv);
Result := True;
end else Result := False;
end;
function TPSScript.AddRegisteredVariable(const VarName,
VarType: tbtstring): Boolean;
var
FVar: TPSVar;
begin
if not FCanAdd then begin Result := False; exit; end;
FVar := FComp.AddUsedVariableN(varname, vartype);
if fvar = nil then
result := False
else begin
fvar.exportname := fvar.Name;
Result := True;
end;
end;
function CENeedFile(Sender: TPSPreProcessor; const callingfilename: tbtstring; var FileName, Output: tbtstring): Boolean;
begin
Result := TPSScript (Sender.ID).DoOnNeedFile(Sender.ID, CallingFileName, FileName, Output);
end;
{ Added by Wizzup }
function CEOnFileAlreadyIncluded(Sender: TPSPreProcessor; OrgFileName, FileName: tbtstring): Boolean;
begin
Result := TPSScript (Sender.ID).DoOnFileAlreadyIncluded(Sender.ID, OrgFileName, Filename);
end;
function CEOnIncludingFile(Sender: TPSPreProcessor; OrgFileName, FileName: tbtstring): Boolean;
begin
Result := TPSScript (Sender.ID).DoOnIncludingFile(Sender.ID, OrgFileName, Filename);
end;
{ Wizzup out }
procedure CompTranslateLineInfo(Sender: TPSPascalCompiler; var Pos, Row, Col: Cardinal; var Name: tbtstring);
var
res: TPSLineInfoResults;
begin
if TPSScript(Sender.ID).FPP.CurrentLineInfo.GetLineInfo(Name, Pos, Res) then
begin
Pos := Res.Pos;
Row := Res.Row;
Col := Res.Col;
Name := Res.Name;
end;
end;
function TPSScript.Compile: Boolean;
var
i: Longint;
dta: tbtstring;
begin
FExec.Clear;
FExec.CMD_Err(erNoError);
FExec.ClearspecialProcImports;
FExec.ClearFunctionList;
if ri <> nil then
begin
RI.Free;
RI := nil;
end;
RI := TPSRuntimeClassImporter.Create;
for i := 0 to FPlugins.Count -1 do
begin
if (TPSPluginItem(FPlugins.Items[i]) <> nil) and (TPSPluginItem(FPlugins.Items[i]).Plugin <> nil) then
TPSPluginItem(FPlugins.Items[i]).Plugin.ExecImport1(Self, ri);
end;
DoOnExecImport (RI);
for i := 0 to FPlugins.Count -1 do
begin
if (TPSPluginItem(FPlugins.Items[i]) <> nil)and (TPSPluginItem(FPlugins.Items[i]).Plugin <> nil) then
TPSPluginItem(FPlugins.Items[i]).Plugin.ExecImport2(Self, ri);
end;
RegisterClassLibraryRuntime(Exec, RI);
for i := 0 to FPlugins.Count -1 do
begin
if (TPSPluginItem(FPlugins.Items[i]) <> nil)and (TPSPluginItem(FPlugins.Items[i]).Plugin <> nil) then
TPSPluginItem(FPlugins.Items[i]).Plugin.ExecOnUses(Self);
end;
FCanAdd := True;
FComp.BooleanShortCircuit := icBooleanShortCircuit in FCompOptions;
FComp.AllowNoBegin := icAllowNoBegin in FCompOptions;
FComp.AllowUnit := icAllowUnit in FCompOptions;
FComp.AllowNoEnd := icAllowNoEnd in FCompOptions;
if FUsePreProcessor then
begin
FPP.Clear;
FPP.Defines.Assign(FDefines);
FComp.OnTranslateLineInfo := CompTranslateLineInfo;
Fpp.OnProcessDirective := callObjectOnProcessDirective;
Fpp.OnProcessUnknowDirective := callObjectOnProcessUnknowDirective;
Fpp.MainFile := FScript.Text;
Fpp.MainFileName := FMainFileName;
Fpp.PreProcess(FMainFileName, dta);
if FComp.Compile(dta) then
begin
FCanAdd := False;
if (not SuppressLoadData) and (not LoadExec) then
begin
Result := False;
end else
Result := True;
end else Result := False;
Fpp.AdjustMessages(Comp);
end else
begin
FComp.OnTranslateLineInfo := nil;
if FComp.Compile(FScript.Text) then
begin
FCanAdd := False;
if not LoadExec then
begin
Result := False;
end else
Result := True;
end else Result := False;
end;
end;
function TPSScript.CompilerErrorToStr(I: Integer): tbtstring;
begin
Result := CompilerMessages[i].MessageToString;
end;
constructor TPSScript.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FComp := TPSPascalCompiler.Create;
FExec := TPSDebugExec.Create;
FScript := TStringList.Create;
FPlugins := TPSPlugins.Create(self);
FComp.ID := Self;
FComp.OnUses := CompScriptUses;
FComp.OnExportCheck := CompExportCheck;
FExec.Id := Self;
FExec.OnRunLine:= ExecOnLine;
FExec.OnGetNVariant := MyGetVariant;
FExec.OnSetNVariant := MySetVariant;
FUseDebugInfo := True;
FPP := TPSPreProcessor.Create;
FPP.Id := Self;
FPP.OnNeedFile := CENeedFile;
{ Added by Wizzup }
FPP.OnFileAlreadyIncluded:= CEOnFileAlreadyIncluded;
FPP.OnIncludingFile:= CEOnIncludingFile;
{ Wizzup out }
FDefines := TStringList.Create;
end;
destructor TPSScript.Destroy;
begin
FDefines.Free;
FPP.Free;
RI.Free;
FPlugins.Free;
FPlugins := nil;
FScript.Free;
FExec.Free;
FComp.Free;
inherited Destroy;
end;
function TPSScript.Execute: Boolean;
begin
if Running then raise Exception.Create(RPS_ScripEngineAlreadyRunning);
if SuppressLoadData then
LoadExec;
DoOnExecute (RI);
FExec.DebugEnabled := FUseDebugInfo;
Result := FExec.RunScript and (FExec.ExceptionCode = erNoError) ;
DoAfterExecute;
end;
function TPSScript.GetAbout: tbtstring;
begin
Result := TPSExec.About;
end;
procedure TPSScript.GetCompiled(var data: tbtstring);
begin
if not FComp.GetOutput(Data) then
raise Exception.Create(RPS_ScriptNotCompiled);
end;
function TPSScript.GetCompMsg(i: Integer): TPSPascalCompilerMessage;
begin
Result := FComp.Msg[i];
end;
function TPSScript.GetCompMsgCount: Longint;
begin
Result := FComp.MsgCount;
end;
function TPSScript.GetExecErrorByteCodePosition: Cardinal;
begin
Result := Exec.ExceptionPos;
end;
function TPSScript.GetExecErrorCode: TIFError;
begin
Result := Exec.ExceptionCode;
end;
function TPSScript.GetExecErrorParam: tbtstring;
begin
Result := Exec.ExceptionString;
end;
function TPSScript.GetExecErrorPosition: Cardinal;
begin
Result := FExec.TranslatePosition(Exec.ExceptionProcNo, Exec.ExceptionPos);
end;
function TPSScript.GetExecErrorProcNo: Cardinal;
begin
Result := Exec.ExceptionProcNo;
end;
function TPSScript.GetExecErrorString: tbtstring;
begin
Result := TIFErrorToString(Exec.ExceptionCode, Exec.ExceptionString);
end;
function TPSScript.GetVariable(const Name: tbtstring): PIFVariant;
begin
Result := FExec.GetVar2(name);
end;
function TPSScript.LoadExec: Boolean;
var
s: tbtstring;
begin
if (not FComp.GetOutput(s)) or (not FExec.LoadData(s)) then
begin
Result := False;
exit;
end;
if FUseDebugInfo then
begin
FComp.GetDebugOutput(s);
FExec.LoadDebugData(s);
end;
Result := True;
end;
function TPSScript.ScriptUses(Sender: TPSPascalCompiler;
const Name: tbtstring): Boolean;
var
i: Longint;
begin
if Name = 'SYSTEM' then
begin
for i := 0 to FPlugins.Count -1 do
begin
if (TPSPluginItem(FPlugins.Items[i]) <> nil)and (TPSPluginItem(FPlugins.Items[i]).Plugin <> nil) then
TPSPluginItem(FPlugins.Items[i]).Plugin.CompOnUses(Self);
end;
for i := 0 to FPlugins.Count -1 do
begin
if (TPSPluginItem(FPlugins.Items[i]) <> nil)and (TPSPluginItem(FPlugins.Items[i]).Plugin <> nil) then
TPSPluginItem(FPlugins.Items[i]).Plugin.CompileImport1(self);
end;
DoOnCompImport;
for i := 0 to FPlugins.Count -1 do
begin
if (TPSPluginItem(FPlugins.Items[i]) <> nil)and (TPSPluginItem(FPlugins.Items[i]).Plugin <> nil) then
TPSPluginItem(FPlugins.Items[i]).Plugin.CompileImport2(Self);
end;
DoOnCompile;
Result := true;
for i := 0 to Sender.MsgCount -1 do begin
if Sender.Msg[i] is TPSPascalCompilerError then Result := false;
end;
end
else begin
Result := DoOnUnknowUses (Sender, Name);
{ If Not Result then
Sender.MakeError('', ecUnknownIdentifier, Name);}
end;
end;
procedure TPSScript.SetCompiled(const Data: tbtstring);
var
i: Integer;
begin
FExec.Clear;
FExec.ClearspecialProcImports;
FExec.ClearFunctionList;
if ri <> nil then
begin
RI.Free;
RI := nil;
end;
RI := TPSRuntimeClassImporter.Create;
for i := 0 to FPlugins.Count -1 do
begin
if (TPSPluginItem(FPlugins.Items[i]) <> nil)and (TPSPluginItem(FPlugins.Items[i]).Plugin <> nil) then
TPSPluginItem(FPlugins.Items[i]).Plugin.ExecImport1(Self, ri);
end;
DoOnExecImport(RI);
for i := 0 to FPlugins.Count -1 do
begin
if (TPSPluginItem(FPlugins.Items[i]) <> nil)and (TPSPluginItem(FPlugins.Items[i]).Plugin <> nil) then
TPSPluginItem(FPlugins.Items[i]).Plugin.ExecImport2(Self, ri);
end;
RegisterClassLibraryRuntime(Exec, RI);
for i := 0 to FPlugins.Count -1 do
begin
if (TPSPluginItem(FPlugins.Items[i]) <> nil)and (TPSPluginItem(FPlugins.Items[i]).Plugin <> nil) then
TPSPluginItem(FPlugins.Items[i]).Plugin.ExecOnUses(Self);
end;
if not FExec.LoadData(Data) then
raise Exception.Create(GetExecErrorString);
end;
function TPSScript.SetVarToInstance(const VarName: tbtstring; cl: TObject): Boolean;
var
p: PIFVariant;
begin
p := GetVariable(VarName);
if p <> nil then
begin
SetVariantToClass(p, cl);
result := true;
end else result := false;
end;
procedure TPSScript.SetScript(const Value: TStrings);
begin
FScript.Assign(Value);
end;
function TPSScript.AddMethod(Slf, Ptr: Pointer;
const Decl: tbtstring): Boolean;
begin
Result := AddMethodEx(Slf, Ptr, Decl, cdRegister);
end;
function TPSScript.AddMethodEx(Slf, Ptr: Pointer; const Decl: tbtstring;
CallingConv: TDelphiCallingConvention): Boolean;
var
P: TPSRegProc;
begin
if not FCanAdd then begin Result := False; exit; end;
p := Comp.AddDelphiFunction(Decl);
if p <> nil then
begin
Exec.RegisterDelphiMethod(Slf, Ptr, p.Name, CallingConv);
Result := True;
end else Result := False;
end;
procedure TPSScript.OnLineEvent;
begin
if @FOnLine <> nil then FOnLine(Self);
end;
function TPSScript.GetRunning: Boolean;
begin
Result := FExec.Status = isRunning;
end;
function TPSScript.GetExecErrorCol: Cardinal;
var
s: tbtstring;
D1: Cardinal;
begin
if not TranslatePositionRC(Exec.ExceptionProcNo, Exec.ExceptionPos, D1, Result, s) then
Result := 0;
end;
function TPSScript.TranslatePositionPos(Proc, Position: Cardinal;
var Pos: Cardinal; var fn: tbtstring): Boolean;
var
D1, D2: Cardinal;
begin
Result := Exec.TranslatePositionEx(Exec.ExceptionProcNo, Exec.ExceptionPos, Pos, D1, D2, fn);
end;
function TPSScript.TranslatePositionRC(Proc, Position: Cardinal;
var Row, Col: Cardinal; var fn: tbtstring): Boolean;
var
d1: Cardinal;
begin
Result := Exec.TranslatePositionEx(Proc, Position, d1, Row, Col, fn);
end;
function TPSScript.GetExecErrorRow: Cardinal;
var
D1: Cardinal;
s: tbtstring;
begin
if not TranslatePositionRC(Exec.ExceptionProcNo, Exec.ExceptionPos, Result, D1, s) then
Result := 0;
end;
procedure TPSScript.Stop;
begin
if (FExec.Status = isRunning) or (Fexec.Status = isPaused) then
FExec.Stop
else
raise Exception.Create(RPS_NotRunning);
end;
function TPSScript.GetProcMethod(const ProcName: tbtstring): TMethod;
begin
Result := FExec.GetProcAsMethodN(ProcName)
end;
procedure TPSScript.SetMainFileName(const Value: tbtstring);
begin
FMainFileName := Value;
end;
function TPSScript.GetExecErrorFileName: tbtstring;
var
D1, D2: Cardinal;
begin
if not TranslatePositionRC(Exec.ExceptionProcNo, Exec.ExceptionPos, D1, D2, Result) then
Result := '';
end;
procedure TPSScript.SetPointerToData(const VarName: tbtstring;
Data: Pointer; aType: TIFTypeRec);
var
v: PIFVariant;
t: TPSVariantIFC;
begin
v := GetVariable(VarName);
if (Atype = nil) or (v = nil) then raise Exception.Create(RPS_UnableToFindVariable);
t.Dta := @PPSVariantData(v).Data;
t.aType := v.FType;
t.VarParam := false;
VNSetPointerTo(t, Data, aType);
end;
function TPSScript.AddRegisteredPTRVariable(const VarName,
VarType: tbtstring): Boolean;
var
FVar: TPSVar;
begin
if not FCanAdd then begin Result := False; exit; end;
FVar := FComp.AddUsedVariableN(varname, vartype);
if fvar = nil then