-
Notifications
You must be signed in to change notification settings - Fork 4
/
lpeval.pas
884 lines (767 loc) · 50.2 KB
/
lpeval.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
{
Author: Niels A.D
Project: Lape (http://code.google.com/p/la-pe/)
License: GNU Lesser GPL (http://www.gnu.org/licenses/lgpl.html)
Evaluation functions.
}
unit lpeval;
{$I lape.inc}
interface
uses
SysUtils,
lptypes;
type
TLapeToStrArr = array[ELapeBaseType] of TLapeImportedFunc;
TLapeEvalArr = array[EOperator, ELapeBaseType, ELapeBaseType] of TLapeEvalProc;
TLapeEvalRes = array[EOperator, ELapeBaseType, ELapeBaseType] of ELapeBaseType;
TGetEvalRes = function(Op: EOperator; Left, Right: ELapeBaseType): ELapeBaseType;
TGetEvalProc = function(Op: EOperator; Left, Right: ELapeBaseType): TLapeEvalProc;
procedure _LapeWrite(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeWriteLn(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeAssigned(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeRaise(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeRaiseString(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeAssert(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeAssertMsg(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeRangeCheck(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeGetMem(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeAllocMem(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeFreeMem(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeReallocMem(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeFillMem(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeMove(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeCompareMem(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeHigh(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeLength(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeAStr_GetLen(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeWStr_GetLen(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeUStr_GetLen(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeSStr_SetLen(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeAStr_SetLen(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeWStr_SetLen(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeUStr_SetLen(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeSStr_Copy(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeAStr_Copy(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeWStr_Copy(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeUStr_Copy(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeSStr_Delete(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeAStr_Delete(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeWStr_Delete(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeUStr_Delete(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeAStr_Insert(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeWStr_Insert(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeUStr_Insert(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeAStr_Unique(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeWStr_Unique(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeUStr_Unique(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeToString_Unknown(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeToString_UInt8(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeToString_Int8(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeToString_UInt16(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeToString_Int16(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeToString_UInt32(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeToString_Int32(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeToString_UInt64(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeToString_Int64(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeToString_Single(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeToString_Double(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeToString_Currency(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeToString_Extended(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeToString_Boolean(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeToString_ByteBool(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeToString_WordBool(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeToString_LongBool(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeToString_AnsiChar(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeToString_WideChar(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeToString_ShortString(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeToString_AnsiString(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeToString_WideString(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeToString_UnicodeString(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeToString_Variant(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure _LapeToString_Pointer(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
{$I lpeval_headers_math.inc}
{$I lpeval_headers_string.inc}
{$I lpeval_headers_datetime.inc}
{$I lpeval_headers_variant.inc}
procedure ClearToStrArr(var Arr: TLapeToStrArr);
procedure LoadToStrArr(var Arr: TLapeToStrArr);
function ValidEvalFunction(p: Pointer): Boolean; overload; {$IFDEF Lape_Inline}inline;{$ENDIF}
function ValidEvalFunction(p: TLapeEvalProc): Boolean; overload; {$IFDEF Lape_Inline}inline;{$ENDIF}
procedure LapeEval_Error(const Dest, Left, Right: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
procedure ClearEvalRes(var Arr: TLapeEvalRes);
procedure ClearEvalArr(var Arr: TLapeEvalArr);
procedure LoadEvalRes(var Arr: TLapeEvalRes);
procedure LoadEvalArr(var Arr: TLapeEvalArr);
function LapeEval_GetRes(Op: EOperator; Left, Right: ELapeBaseType): ELapeBaseType;
function LapeEval_GetProc(Op: EOperator; Left, Right: ELapeBaseType): TLapeEvalProc;
var
LapeEvalErrorProc: TLapeEvalProc = {$IFDEF FPC}@{$ENDIF}LapeEval_Error;
getEvalRes: TGetEvalRes = {$IFDEF FPC}@{$ENDIF}LapeEval_GetRes;
getEvalProc: TGetEvalProc = {$IFDEF FPC}@{$ENDIF}LapeEval_GetProc;
LapeToStrArr: TLapeToStrArr;
LapeEvalRes: TLapeEvalRes;
LapeEvalArr: TLapeEvalArr;
LapeDelayedFlags: lpString = '{$ASSERTIONS ON}{$BOOLEVAL ON}{$CONSTADDRESS ON}{$RANGECHECKS ON}{$AUTOINVOKE OFF}{$AUTOPROPERTIES OFF}{$LOOSESEMICOLON OFF}{$EXTENDEDSYNTAX OFF}' + LineEnding;
_LapeToString_Enum: lpString =
'function _EnumToString(s: ^const string; Index, Lo, Hi: SizeInt): string;' + LineEnding +
'begin' + LineEnding +
' if (Index >= Lo) and (Index <= Hi) then' + LineEnding +
' Result := s[Index-Lo]^' + LineEnding +
' else ' + LineEnding +
' Result := '#39#39';' + LineEnding +
' if (Result = '#39#39') then' + LineEnding +
' Result := '#39'InvalidEnum('#39'+ToString(Index)+'#39')'#39';' + LineEnding +
'end;';
_LapeToString_Set: lpString =
'function _%sSetToString(ASet: ConstPointer;' + LineEnding +
' AToString: private function(constref Enum): string;' + LineEnding +
' Lo, Hi: SizeInt): string;' + LineEnding +
'type' + LineEnding +
' TEnum = (se0, se1 = %d);' + LineEnding +
' TSet = set of TEnum;' + LineEnding +
' PSet = ^TSet;' + LineEnding +
'var' + LineEnding +
' e: TEnum;' + LineEnding +
'begin' + LineEnding +
' Result := '#39#39';' + LineEnding +
' for e := TEnum(Lo) to TEnum(Hi) do' + LineEnding +
' if (e in PSet(ASet)^) then' + LineEnding +
' begin' + LineEnding +
' if (Result <> '#39#39') then' + LineEnding +
' Result := Result + '#39', '#39';' + LineEnding +
' Result := Result + AToString(e);' + LineEnding +
' end;' + LineEnding +
' Result := '#39'['#39'+Result+'#39']'#39';' + LineEnding +
'end;';
_LapeToString_Array: lpString =
'function _ArrayToString(Arr: Pointer;' + LineEnding +
' AToString: private function(p: ConstPointer): string;' + LineEnding +
' Len, Size: SizeInt): string;' + LineEnding +
'var' + LineEnding +
' i: SizeInt;' + LineEnding +
'begin' + LineEnding +
' Result := '#39#39';' + LineEnding +
' for i := 1 to Len do' + LineEnding +
' begin' + LineEnding +
' if (i > 1) then' + LineEnding +
' Result := Result + '#39', '#39';' + LineEnding +
' Result := Result + AToString(Arr);' + LineEnding +
' Inc(Arr, Size);' + LineEnding +
' end;' + LineEnding +
' Result := '#39'['#39'+Result+'#39']'#39';' + LineEnding +
'end;';
_LapeSwap: lpString =
'procedure _Swap(var a, b; Size: SizeInt);' + LineEnding +
'var' + LineEnding +
' c: Pointer;' + LineEnding +
'begin' + LineEnding +
' c := GetMem(Size);' + LineEnding +
' try' + LineEnding +
' Move(a, c^, Size);' + LineEnding +
' Move(b, a, Size);' + LineEnding +
' Move(c^, b, Size);' + LineEnding +
' finally' + LineEnding +
' FreeMem(c);' + LineEnding +
' end;' + LineEnding +
'end;';
_LapeSetLength: lpString =
'procedure _ArraySetLength(var p: Pointer; NewLen, ElSize: SizeInt;' + LineEnding +
' Dispose: private procedure(p: Pointer);' + LineEnding +
' Copy: private procedure(Src: ConstPointer; Dst: Pointer));' + LineEnding +
'const' + LineEnding +
' HeaderSize = SizeOf(PtrInt) + SizeOf(SizeInt);' + LineEnding +
'var' + LineEnding +
' i, OldLen, NewSize: SizeInt;' + LineEnding +
' NewP: Pointer;' + LineEnding +
' DoFree: EvalBool;' + LineEnding +
'begin' + LineEnding +
' NewSize := NewLen * ElSize;' + LineEnding +
' DoFree := NewSize <= 0;' + LineEnding +
' Inc(NewSize, HeaderSize);' + LineEnding +
'' + LineEnding +
' if (p = nil) then' + LineEnding +
' begin' + LineEnding +
' if DoFree then' + LineEnding +
' Exit;' + LineEnding +
' p := AllocMem(NewSize);' + LineEnding +
'' + LineEnding +
' PtrInt(p^) := 1;' + LineEnding +
' Inc(p, SizeOf(PtrInt));' + LineEnding +
' SizeInt(p^) := NewLen' {$IFDEF FPC}+'-1'{$ENDIF}+';' + LineEnding +
' Inc(p, SizeOf(SizeInt));' + LineEnding +
' Exit;' + LineEnding +
' end;' + LineEnding +
'' + LineEnding +
' Dec(p, SizeOf(SizeInt));' + LineEnding +
' OldLen := p^' {$IFDEF FPC}+'+1'{$ENDIF}+';' + LineEnding +
' Dec(p, SizeOf(PtrInt));' + LineEnding +
'' + LineEnding +
' if (PtrInt(p^) <= 1) then' + LineEnding +
' begin' + LineEnding +
' if (NewLen = OldLen) then' + LineEnding +
' begin' + LineEnding +
' Inc(p, HeaderSize);' + LineEnding +
' Exit;' + LineEnding +
' end;' + LineEnding +
'' + LineEnding +
' if (NewLen < OldLen) and (Pointer(Dispose) <> nil) then' + LineEnding +
' begin' + LineEnding +
' Inc(p, HeaderSize);' + LineEnding +
' for i := NewLen * ElSize to (OldLen - 1) * ElSize with ElSize do' + LineEnding +
' Dispose(p[i]);' + LineEnding +
' Dec(p, HeaderSize);' + LineEnding +
' end;' + LineEnding +
'' + LineEnding +
' if DoFree then' + LineEnding +
' begin' + LineEnding +
' FreeMem(p);' + LineEnding +
' p := nil;' + LineEnding +
' Exit;' + LineEnding +
' end;' + LineEnding +
' ReallocMem(p, NewSize);' + LineEnding +
' PtrInt(p^) := 1;' + LineEnding +
' Inc(p, SizeOf(PtrInt));' + LineEnding +
' SizeInt(p^) := NewLen' {$IFDEF FPC}+'-1'{$ENDIF}+';' + LineEnding +
' Inc(p, SizeOf(SizeInt));' + LineEnding +
'' + LineEnding +
' if (NewLen > OldLen) then' + LineEnding +
' FillMem(p[OldLen * ElSize]^, (NewLen - OldLen) * ElSize);' + LineEnding +
' end' + LineEnding +
' else' + LineEnding +
' begin' + LineEnding +
' Dec(PtrInt(p^));' + LineEnding +
' NewP := nil;' + LineEnding +
' _ArraySetLength(NewP, NewLen, ElSize, Dispose, Copy);' + LineEnding +
'' + LineEnding +
' i := OldLen;' + LineEnding +
' if (NewLen < OldLen) then' + LineEnding +
' i := NewLen;' + LineEnding +
' if (i >= 1) then' + LineEnding +
' begin' + LineEnding +
' Inc(p, HeaderSize);' + LineEnding +
' if (Pointer(Copy) = nil) then' + LineEnding +
' Move(p^, NewP^, i * ElSize)' + LineEnding +
' else for i := (i - 1) * ElSize downto 0 with ElSize do' + LineEnding +
' Copy(p[i], NewP[i]);' + LineEnding +
' end;' + LineEnding +
'' + LineEnding +
' p := NewP;' + LineEnding +
' end;' + LineEnding +
'end;';
_LapeCopy: lpString =
'procedure _ArrayCopy(p: ConstPointer;' + LineEnding +
' Start: SizeInt = 0; Count: SizeInt = High(SizeInt);' + LineEnding +
' Len, ElSize: SizeInt;' + LineEnding +
' Copy: private procedure(Src: ConstPointer; Dst: Pointer);' + LineEnding +
' out Result: Pointer);' + LineEnding +
'var' + LineEnding +
' i: SizeInt;' + LineEnding +
'begin' + LineEnding +
' Result := nil;' + LineEnding +
' if (p = nil) or (Start >= Len) or (Count <= 0) then' + LineEnding +
' Exit;' + LineEnding +
'' + LineEnding +
' if (Start < 0) then' + LineEnding +
' Start := 0' + LineEnding +
' else if (Len - Count < Start) then' + LineEnding +
' Count := Len - Start;' + LineEnding +
'' + LineEnding +
' _ArraySetLength(Result, Count, ElSize, nil, nil);' + LineEnding +
' Inc(p, Start * ElSize);' + LineEnding +
'' + LineEnding +
' if (Pointer(Copy) = nil) then' + LineEnding +
' Move(p^, Result^, Count * ElSize)' + LineEnding +
' else' + LineEnding +
' for i := 0 to (Count - 1) * ElSize with ElSize do' + LineEnding +
' Copy(p[i], Result[i]);' + LineEnding +
'end;';
_LapeDelete: lpString =
'procedure _ArrayDelete(var p: Pointer;' + LineEnding +
' Start: SizeInt; Count: SizeInt = High(SizeInt);' + LineEnding +
' ElSize: SizeInt;' + LineEnding +
' Dispose: private procedure(p: Pointer);' + LineEnding +
' Copy: private procedure(Src: ConstPointer; Dst: Pointer));' + LineEnding +
'type' + LineEnding +
' PSizeInt = ^SizeInt;' + LineEnding +
'var' + LineEnding +
' i, Len: SizeInt;' + LineEnding +
'begin' + LineEnding +
' if (p = nil) or (Count <= 0) then' + LineEnding +
' Exit;' + LineEnding +
'' + LineEnding +
' Len := PSizeInt(p)[-1]^' {$IFDEF FPC}+'+1'{$ENDIF}+';' + LineEnding +
' if (Start < 0) then' + LineEnding +
' Start := 0' + LineEnding +
' else if (Start >= Len) then' + LineEnding +
' Exit' + LineEnding +
' else if (Len - Count < Start) then' + LineEnding +
' Count := Len - Start;' + LineEnding +
'' + LineEnding +
' _ArraySetLength(p, Len, ElSize, Dispose, Copy);' + LineEnding +
' Inc(p, Start * ElSize);' + LineEnding +
'' + LineEnding +
' if (Pointer(Dispose) <> nil) then' + LineEnding +
' for i := 0 to (Count - 1) * ElSize with ElSize do' + LineEnding +
' Dispose(p[i]);' + LineEnding +
'' + LineEnding +
' if (Start + Count < Len) then' + LineEnding +
' Move(p[Count * ElSize]^, p^, (Len - Start - Count) * ElSize);' + LineEnding +
'' + LineEnding +
' Dec(p, Start * ElSize);' + LineEnding +
' _ArraySetLength(p, Len-Count, ElSize, nil, nil);' + LineEnding +
'end;';
_LapeInsert: lpString =
'procedure _ArrayInsert(Src: ConstPointer; var Dst: Pointer;' + LineEnding +
' Start: SizeInt = 0; Count: SizeInt = 0; LenSrc, ElSize: SizeInt;' + LineEnding +
' Dispose: private procedure(p: Pointer);' + LineEnding +
' Copy: private procedure(Src: ConstPointer; Dst: Pointer));' + LineEnding +
'type' + LineEnding +
' PSizeInt = ^SizeInt;' + LineEnding +
'var' + LineEnding +
' i, LenDst: SizeInt;' + LineEnding +
'begin' + LineEnding +
' if (LenSrc < 0) or (Count < 0) then' + LineEnding +
' Exit;' + LineEnding +
'' + LineEnding +
' if (Dst = nil) then' + LineEnding +
' LenDst := 0' + LineEnding +
' else' + LineEnding +
' LenDst := PSizeInt(Dst)[-1]^' {$IFDEF FPC}+'+1'{$ENDIF}+';' + LineEnding +
'' + LineEnding +
' if (Start < 0) then' + LineEnding +
' Start := 0' + LineEnding +
' else if (Start > LenDst) then' + LineEnding +
' Start := LenDst' + LineEnding +
' else if (LenDst - Count < Start) then' + LineEnding +
' Count := LenDst - Start;' + LineEnding +
'' + LineEnding +
' _ArraySetLength(Dst, LenDst + LenSrc, ElSize, Dispose, Copy);' + LineEnding +
' Inc(Dst, Start * ElSize);' + LineEnding +
'' + LineEnding +
' if (Count <> LenSrc) then' + LineEnding +
' begin' + LineEnding +
' if (Count > LenSrc) and (Pointer(Dispose) <> nil) then' + LineEnding +
' for i := LenSrc * ElSize to (Count - 1) * ElSize with ElSize do' + LineEnding +
' Dispose(Dst[i]);' + LineEnding +
'' + LineEnding +
' Move(' + LineEnding +
' Dst[Count * ElSize]^,' + LineEnding +
' Dst[LenSrc * ElSize]^,' + LineEnding +
' (LenDst - Start - Count) * ElSize' + LineEnding +
' );' + LineEnding +
'' + LineEnding +
' if (LenSrc > Count) and (Pointer(Copy) <> nil) then' + LineEnding +
' FillMem(Dst[Count * ElSize]^, (LenSrc - Count) * ElSize);' + LineEnding +
' end;' + LineEnding +
'' + LineEnding +
' if (LenSrc > 0) then' + LineEnding +
' if (Pointer(Copy) = nil) then' + LineEnding +
' Move(Src^, Dst^, LenSrc * ElSize)' + LineEnding +
' else for i := 0 to (LenSrc - 1) * ElSize with ElSize do' + LineEnding +
' Copy(Src[i], Dst[i]);' + LineEnding +
'' + LineEnding +
' Dec(Dst, Start * ElSize);' + LineEnding +
' _ArraySetLength(Dst, LenDst + LenSrc - Count, ElSize, nil, nil);' + LineEnding +
'end;';
implementation
uses
Variants, Math,
{$IFDEF Lape_NeedAnsiStringsUnit}AnsiStrings,{$ENDIF}
{$IFDEF FPC}LCLIntf,{$ELSE}{$IFDEF MSWINDOWS}Windows,{$ENDIF}{$ENDIF}
lpexceptions, lpparser;
{$RangeChecks Off}
{$OverflowChecks Off}
type
PBoolean = ^Boolean; //Make sure it's not ^Byte
procedure _LapeWrite(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
Write(PlpString(Params^[0])^);
end;
procedure _LapeWriteLn(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
WriteLn('');
end;
procedure _LapeAssigned(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PEvalBool(Result)^ := Assigned(Params^[0]) and Assigned(PPointer(Params^[0])^);
end;
procedure _LapeRaise(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
raise Exception(Params^[0]^);
end;
procedure _LapeRaiseString(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
LapeException(PlpString(Params^[0])^);
end;
procedure _LapeAssert(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
if (not PEvalBool(Params^[0])^) then
LapeException(lpeAssertionFailure);
end;
procedure _LapeAssertMsg(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
if (not PEvalBool(Params^[0])^) then
LapeExceptionFmt(lpeAssertionFailureMsg, [PlpString(Params^[1])^]);
end;
procedure _LapeRangeCheck(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
if (PSizeInt(Params^[0])^ < PSizeInt(Params^[1])^) or (PSizeInt(Params^[0])^ > PSizeInt(Params^[2])^) then
LapeExceptionFmt(lpeIndexOutOfRange, [PSizeInt(Params^[0])^, PSizeInt(Params^[1])^, PSizeInt(Params^[2])^]);
end;
procedure _LapeGetMem(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
GetMem(PPointer(Result)^, PSizeInt(Params^[0])^);
end;
procedure _LapeAllocMem(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PPointer(Result)^ := AllocMem(PSizeInt(Params^[0])^);
end;
procedure _LapeFreeMem(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
FreeMem(PPointer(Params^[0])^);
end;
procedure _LapeReallocMem(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
ReallocMem(PPointer(Params^[0])^, PSizeInt(Params^[1])^);
end;
procedure _LapeFillMem(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
FillChar(Params^[0]^, PSizeInt(Params^[1])^, PUInt8(Params^[2])^);
end;
procedure _LapeMove(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
Move(Params^[0]^, Params^[1]^, PSizeInt(Params^[2])^);
end;
procedure _LapeCompareMem(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PEvalBool(Result)^ := CompareMem(Params^[0], Params^[1], PSizeInt(Params^[2])^);
end;
procedure _LapeHigh(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PSizeInt(Result)^ := High(PCodeArray(Params^[0])^);
end;
procedure _LapeLength(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PSizeInt(Result)^ := Length(PCodeArray(Params^[0])^);
end;
procedure _LapeAStr_GetLen(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PSizeInt(Result)^ := Length(PAnsiString(Params^[0])^);
end;
procedure _LapeWStr_GetLen(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PSizeInt(Result)^ := Length(PWideString(Params^[0])^);
end;
procedure _LapeUStr_GetLen(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PSizeInt(Result)^ := Length(PUnicodeString(Params^[0])^);
end;
procedure _LapeSStr_SetLen(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
if (PUInt8(Params^[1])^ > PUInt8(Params^[2])^) then
LapeExceptionFmt(lpeOutOfTypeRangeHigh, [PUInt8(Params^[1])^, PUInt8(Params^[2])^]);
SetLength(PShortString(Params^[0])^, PUInt8(Params^[1])^);
end;
procedure _LapeAStr_SetLen(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
SetLength(PAnsiString(Params^[0])^, PSizeInt(Params^[1])^);
end;
procedure _LapeWStr_SetLen(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
SetLength(PWideString(Params^[0])^, PSizeInt(Params^[1])^);
end;
procedure _LapeUStr_SetLen(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
SetLength(PUnicodeString(Params^[0])^, PSizeInt(Params^[1])^);
end;
procedure _LapeSStr_Copy(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PAnsiString(Params^[3])^ := Copy(PShortString(Params^[0])^, PUInt8(Params^[1])^, Min(Length(PShortString(Params^[0])^), PUInt8(Params^[2])^));
end;
procedure _LapeAStr_Copy(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PAnsiString(Params^[3])^ := Copy(PAnsiString(Params^[0])^, PSizeInt(Params^[1])^, Min(Length(PAnsiString(Params^[0])^), PSizeInt(Params^[2])^));
end;
procedure _LapeWStr_Copy(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PWideString(Params^[3])^ := Copy(PWideString(Params^[0])^, PSizeInt(Params^[1])^, Min(Length(PWideString(Params^[0])^), PSizeInt(Params^[2])^));
end;
procedure _LapeUStr_Copy(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PUnicodeString(Params^[3])^ := Copy(PUnicodeString(Params^[0])^, PSizeInt(Params^[1])^, Min(Length(PUnicodeString(Params^[0])^), PSizeInt(Params^[2])^));
end;
procedure _LapeSStr_Delete(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
Delete(PShortString(Params^[0])^, PUInt8(Params^[1])^, Min(Length(PShortString(Params^[0])^), PUInt8(Params^[2])^));
end;
procedure _LapeAStr_Delete(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
Delete(PAnsiString(Params^[0])^, PSizeInt(Params^[1])^, Min(Length(PAnsiString(Params^[0])^), PSizeInt(Params^[2])^));
end;
procedure _LapeWStr_Delete(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
Delete(PWideString(Params^[0])^, PSizeInt(Params^[1])^, Min(Length(PWideString(Params^[0])^), PSizeInt(Params^[2])^));
end;
procedure _LapeUStr_Delete(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
Delete(PUnicodeString(Params^[0])^, PSizeInt(Params^[1])^, Min(Length(PUnicodeString(Params^[0])^), PSizeInt(Params^[2])^));
end;
procedure _LapeAStr_Insert(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
if (PSizeInt(Params^[3])^ > 0) then
Delete(PAnsiString(Params^[1])^, PSizeInt(Params^[2])^, Min(Length(PAnsiString(Params^[1])^), PSizeInt(Params^[3])^));
Insert(PAnsiString(Params^[0])^, PAnsiString(Params^[1])^, Min(Length(PAnsiString(Params^[1])^)+1, PSizeInt(Params^[2])^));
end;
procedure _LapeWStr_Insert(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
if (PSizeInt(Params^[3])^ > 0) then
Delete(PWideString(Params^[1])^, PSizeInt(Params^[2])^, Min(Length(PWideString(Params^[1])^), PSizeInt(Params^[3])^));
Insert(PWideString(Params^[0])^, PWideString(Params^[1])^, Min(Length(PWideString(Params^[1])^)+1, PSizeInt(Params^[2])^));
end;
procedure _LapeUStr_Insert(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
if (PSizeInt(Params^[3])^ > 0) then
Delete(PUnicodeString(Params^[1])^, PSizeInt(Params^[2])^, Min(Length(PUnicodeString(Params^[1])^), PSizeInt(Params^[3])^));
Insert(PUnicodeString(Params^[0])^, PUnicodeString(Params^[1])^, Min(Length(PUnicodeString(Params^[1])^)+1, PSizeInt(Params^[2])^));
end;
procedure _LapeAStr_Unique(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
UniqueString(PAnsiString(Params^[0])^);
end;
procedure _LapeWStr_Unique(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
UniqueString(PWideString(Params^[0])^);
end;
procedure _LapeUStr_Unique(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
UniqueString(PUnicodeString(Params^[0])^);
end;
procedure _LapeToString_Unknown(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PlpString(Result)^ := '*UNKNOWN*';
end;
procedure _LapeToString_UInt8(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PlpString(Result)^ := lpString(UIntToStr(PUInt8(Params^[0])^));
end;
procedure _LapeToString_Int8(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PlpString(Result)^ := lpString(IntToStr(PInt8(Params^[0])^));
end;
procedure _LapeToString_UInt16(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PlpString(Result)^ := lpString(UIntToStr(PUInt16(Params^[0])^));
end;
procedure _LapeToString_Int16(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PlpString(Result)^ := lpString(IntToStr(PInt16(Params^[0])^));
end;
procedure _LapeToString_UInt32(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PlpString(Result)^ := lpString(UIntToStr(PUInt32(Params^[0])^));
end;
procedure _LapeToString_Int32(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PlpString(Result)^ := lpString(IntToStr(PInt32(Params^[0])^));
end;
procedure _LapeToString_UInt64(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PlpString(Result)^ := lpString(UIntToStr(PUInt64(Params^[0])^));
end;
procedure _LapeToString_Int64(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PlpString(Result)^ := lpString(IntToStr(PInt64(Params^[0])^));
end;
procedure _LapeToString_Single(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PlpString(Result)^ := lpString(FloatToStr(PSingle(Params^[0])^));
end;
procedure _LapeToString_Double(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PlpString(Result)^ := lpString(FloatToStr(PDouble(Params^[0])^));
end;
procedure _LapeToString_Currency(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PlpString(Result)^ := lpString(FloatToStr(PCurrency(Params^[0])^));
end;
procedure _LapeToString_Extended(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PlpString(Result)^ := lpString(FloatToStr(PExtended(Params^[0])^));
end;
procedure _LapeToString_Boolean(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PlpString(Result)^ := lpString(BoolToStr(PBoolean(Params^[0])^, True));
end;
procedure _LapeToString_ByteBool(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PlpString(Result)^ := lpString(BoolToStr(PByteBool(Params^[0])^, True));
end;
procedure _LapeToString_WordBool(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PlpString(Result)^ := lpString(BoolToStr(PWordBool(Params^[0])^, True));
end;
procedure _LapeToString_LongBool(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PlpString(Result)^ := lpString(BoolToStr(PLongBool(Params^[0])^, True));
end;
procedure _LapeToString_AnsiChar(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PlpString(Result)^ := lpString(PAnsiChar(Params^[0])^);
end;
procedure _LapeToString_WideChar(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PlpString(Result)^ := lpString(PWideChar(Params^[0])^);
end;
procedure _LapeToString_ShortString(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PlpString(Result)^ := lpString(PShortString(Params^[0])^);
end;
procedure _LapeToString_AnsiString(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PlpString(Result)^ := lpString(PAnsiString(Params^[0])^);
end;
procedure _LapeToString_WideString(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PlpString(Result)^ := lpString(PWideString(Params^[0])^);
end;
procedure _LapeToString_UnicodeString(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PlpString(Result)^ := lpString(PUnicodeString(Params^[0])^);
end;
procedure _LapeToString_Variant(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
try
{$IF DEFINED(Lape_Unicode) and DEFINED(FPC)}
PlpString(Result)^ := lpString(VarToUnicodeStr(PVariant(Params^[0])^));
{$ELSE}
PlpString(Result)^ := lpString(VarToStr(PVariant(Params^[0])^));
{$IFEND}
except
PlpString(Result)^ := lpString(VarTypeAsText(VarType(PVariant(Params^[0])^)));
end;
end;
procedure _LapeToString_Pointer(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PlpString(Result)^ := PointerToString(Params^[0]);
end;
type
TVariantArray = array of Variant;
PVariantArray = ^TVariantArray;
{$I lpeval_wrappers_math.inc}
{$I lpeval_wrappers_string.inc}
{$I lpeval_wrappers_datetime.inc}
{$I lpeval_wrappers_variant.inc}
procedure ClearToStrArr(var Arr: TLapeToStrArr);
var
BaseType: ELapeBaseType;
begin
for BaseType := Low(BaseType) to High(BaseType) do
Arr[BaseType] := nil;
end;
procedure LoadToStrArr(var Arr: TLapeToStrArr);
begin
Arr[ltUInt8] := @_LapeToString_UInt8;
Arr[ltInt8] := @_LapeToString_Int8;
Arr[ltUInt16] := @_LapeToString_UInt16;
Arr[ltInt16] := @_LapeToString_Int16;
Arr[ltUInt32] := @_LapeToString_UInt32;
Arr[ltInt32] := @_LapeToString_Int32;
Arr[ltUInt64] := @_LapeToString_UInt64;
Arr[ltInt64] := @_LapeToString_Int64;
Arr[ltSingle] := @_LapeToString_Single;
Arr[ltDouble] := @_LapeToString_Double;
Arr[ltCurrency] := @_LapeToString_Currency;
Arr[ltExtended] := @_LapeToString_Extended;
Arr[ltBoolean] := @_LapeToString_Boolean;
Arr[ltByteBool] := @_LapeToString_ByteBool;
Arr[ltWordBool] := @_LapeToString_WordBool;
Arr[ltLongBool] := @_LapeToString_LongBool;
Arr[ltAnsiChar] := @_LapeToString_AnsiChar;
Arr[ltWideChar] := @_LapeToString_WideChar;
Arr[ltShortString] := @_LapeToString_ShortString;
Arr[ltAnsiString] := @_LapeToString_AnsiString;
Arr[ltWideString] := @_LapeToString_WideString;
Arr[ltUnicodeString] := @_LapeToString_UnicodeString;
Arr[ltVariant] := @_LapeToString_Variant;
Arr[ltPointer] := @_LapeToString_Pointer;
end;
function ValidEvalFunction(p: Pointer): Boolean;
begin
Result := (p <> nil) and (p <> Pointer({$IFNDEF FPC}@{$ENDIF}LapeEvalErrorProc));
end;
function ValidEvalFunction(p: TLapeEvalProc): Boolean;
begin
Result := ValidEvalFunction(Pointer({$IFNDEF FPC}@{$ENDIF}p));
end;
procedure LapeEval_Error(const Dest, Left, Right: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
LapeException(lpeInvalidEvaluation);
end;
procedure ClearEvalRes(var Arr: TLapeEvalRes);
var
op: EOperator;
t1, t2: ELapeBaseType;
begin
for op := Low(EOperator) to High(EOperator) do
for t1 := Low(ELapeBaseType) to High(ELapeBaseType) do
for t2 := Low(ELapeBaseType) to High(ELapeBaseType) do
Arr[op][t1][t2] := ltUnknown;
end;
procedure ClearEvalArr(var Arr: TLapeEvalArr);
var
op: EOperator;
BaseTypeLeft, BaseTypeRight: ELapeBaseType;
begin
for op := Low(EOperator) to High(EOperator) do
for BaseTypeLeft := Low(ELapeBaseType) to High(ELapeBaseType) do
for BaseTypeRight := Low(ELapeBaseType) to High(ELapeBaseType) do
Arr[op][BaseTypeLeft][BaseTypeRight] := @LapeEval_Error;
end;
procedure LoadEvalRes(var Arr: TLapeEvalRes);
begin
{$I lpeval_res.inc}
end;
{$WARN COMPARING_SIGNED_UNSIGNED OFF}
{$WARN IMPLICIT_STRING_CAST OFF}
{$WARN IMPLICIT_STRING_CAST_LOSS OFF}
{$I lpeval_functions.inc}
procedure LoadEvalArr(var Arr: TLapeEvalArr);
begin
{$I lpeval_arr.inc}
end;
procedure lpeAddr(const Dest, Left, Right: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PPointer(Dest)^ := Left;
end;
procedure lpeDeref(const Dest, Left, Right: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PPointer(Dest)^ := PPointer(Left)^;
end;
function LapeEval_GetRes(Op: EOperator; Left, Right: ELapeBaseType): ELapeBaseType;
begin
if (Op = op_Addr) then
Result := ltPointer
else
Result := LapeEvalRes[op, Left, Right];
end;
function LapeEval_GetProc(Op: EOperator; Left, Right: ELapeBaseType): TLapeEvalProc;
begin
if (Op = op_Addr) then
Result := @lpeAddr
else if (Op = op_Deref) then
Result := @lpeDeref
else
Result := LapeEvalArr[op, Left, Right];
end;
initialization
ClearToStrArr(LapeToStrArr);
LoadToStrArr(LapeToStrArr);
ClearEvalRes(LapeEvalRes);
ClearEvalArr(LapeEvalArr);
LoadEvalRes(LapeEvalRes);
LoadEvalArr(LapeEvalArr);
finalization
ClearToStrArr(LapeToStrArr);
ClearEvalRes(LapeEvalRes);
ClearEvalArr(LapeEvalArr);
end.