-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecdfn.c
More file actions
2610 lines (2155 loc) · 105 KB
/
execdfn.c
File metadata and controls
2610 lines (2155 loc) · 105 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
//***************************************************************************
// NARS2000 -- User-Defined Function/Operator Execution Routines
//***************************************************************************
/***************************************************************************
NARS2000 -- An Experimental APL Interpreter
Copyright (C) 2006-2016 Sudley Place Software
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***************************************************************************/
#define STRICT
#include <windows.h>
#include "headers.h"
//***************************************************************************
// $ExecDfnGlbProto_EM_YY
//
// Execute a user-defined function/operator in a prototype context
//***************************************************************************
#ifdef DEBUG
#define APPEND_NAME L" -- ExecDfnGlbProto_EM_YY"
#else
#define APPEND_NAME
#endif
LPPL_YYSTYPE ExecDfnGlbProto_EM_YY
(LPTOKEN lptkLftArg, // Ptr to left arg token (may be NULL if monadic)
LPTOKEN lptkFcnStr, // Ptr to function strand
LPTOKEN lptkRhtArg, // Ptr to right arg token
LPTOKEN lptkAxis) // Ptr to axis token (may be NULL)
{
HGLOBAL hGlbUDFO; // UDFO global memory handle
LPPL_YYSTYPE lpYYRes, // Ptr to the result
lpYYRes2; // Ptr to secondary result
// Get the user-defined function/operator global memory handle
hGlbUDFO = GetGlbHandle (lptkFcnStr);
Assert (GetSignatureGlb_PTB (hGlbUDFO) EQ DFN_HEADER_SIGNATURE);
// Execute the user-defined function/operator on the arg using the []PRO entry point
lpYYRes2 =
ExecDfnGlb_EM_YY (hGlbUDFO, // User-defined function/operator global memory handle
lptkLftArg, // Ptr to left arg token (may be NULL if monadic)
(LPPL_YYSTYPE) lptkFcnStr, // Ptr to function strand
NULL, // Ptr to axis token (may be NULL -- used only if function strand is NULL)
lptkRhtArg, // Ptr to right arg token
LINENUM_PRO); // Starting line # (see LINE_NUMS)
// If the result is valid, ...
if (lpYYRes2 NE NULL)
{
// Check for NoValue
if (IsTokenNoValue (&lpYYRes2->tkToken))
{
// Free the YYRes (but not the storage)
YYFree (lpYYRes2); lpYYRes2 = NULL;
goto VALUE_EXIT;
} // End IF
// Convert the result into a prototype
lpYYRes =
PrimFnMonDownTack_EM_YY (lptkFcnStr, // Ptr to function token
&lpYYRes2->tkToken, // Ptr to right arg token
NULL); // Ptr to axis token (may be NULL)
FreeResult (lpYYRes2); YYFree (lpYYRes2); lpYYRes2 = NULL;
} else
lpYYRes = lpYYRes2;
return lpYYRes;
VALUE_EXIT:
ErrorMessageIndirectToken (ERRMSG_VALUE_ERROR APPEND_NAME,
lptkFcnStr);
return lpYYRes2;
} // End ExecDfnGlbProto_EM_YY
#undef APPEND_NAME
//***************************************************************************
// $ExecDfnGlbIdent_EM_YY
//
// Execute a user-defined function/operator in a identity context
//***************************************************************************
#ifdef DEBUG
#define APPEND_NAME L" -- ExecDfnGlbIdent_EM_YY"
#else
#define APPEND_NAME
#endif
LPPL_YYSTYPE ExecDfnGlbIdent_EM_YY
(LPTOKEN lptkLftArg, // Ptr to left arg token (may be NULL if monadic)
LPTOKEN lptkFcnStr, // Ptr to function strand
LPTOKEN lptkRhtArg, // Ptr to right arg token
LPTOKEN lptkAxis) // Ptr to axis token (may be NULL)
{
HGLOBAL hGlbUDFO; // UDFO global memory handle
LPPL_YYSTYPE lpYYRes; // Ptr to the result
// Get the global memory handle
hGlbUDFO = GetGlbDataToken (lptkFcnStr);
Assert (GetSignatureGlb_PTB (hGlbUDFO) EQ DFN_HEADER_SIGNATURE);
// Execute the user-defined function/operator on the arg using the []ID entry point
lpYYRes =
ExecDfnGlb_EM_YY (hGlbUDFO, // User-defined function/operator global memory handle
NULL, // Ptr to left arg token (may be NULL if monadic)
(LPPL_YYSTYPE) lptkFcnStr, // Ptr to function strand
NULL, // Ptr to axis token (may be NULL -- used only if function strand is NULL)
lptkRhtArg, // Ptr to right arg token
LINENUM_ID); // Starting line # (see LINE_NUMS)
// If the result is valid, ...
if (lpYYRes NE NULL)
{
// Check for NoValue
if (IsTokenNoValue (&lpYYRes->tkToken))
{
// Free the YYRes (but not the storage)
YYFree (lpYYRes); lpYYRes = NULL;
goto VALUE_EXIT;
} // End IF
} // End IF
return lpYYRes;
VALUE_EXIT:
ErrorMessageIndirectToken (ERRMSG_VALUE_ERROR APPEND_NAME,
lptkFcnStr);
return lpYYRes;
} // End ExecDfnGlbIdent_EM_YY
#undef APPEND_NAME
//***************************************************************************
// $ExecDfnGlb_EM_YY
//
// Execute a user-defined function/operator
//***************************************************************************
#ifdef DEBUG
#define APPEND_NAME L" -- ExecDfnGlb_EM_YY"
#else
#define APPEND_NAME
#endif
LPPL_YYSTYPE ExecDfnGlb_EM_YY
(HGLOBAL hGlbDfnHdr, // User-defined function/operator global memory handle
LPTOKEN lptkLftArg, // Ptr to left arg token (may be NULL if niladic/monadic)
LPPL_YYSTYPE lpYYFcnStrOpr, // Ptr to function strand (may be NULL if not an operator and no axis)
LPTOKEN lptkAxisOpr, // Ptr to axis token (may be NULL -- used only if function strand is NULL)
LPTOKEN lptkRhtArg, // Ptr to right arg token (may be NULL if niladic)
LINE_NUMS startLineType) // Starting line type (see LINE_NUMS)
{
LPPL_YYSTYPE lpYYRes, // Ptr to the result
lpYYFcnStrLft, // Ptr to left operand function strand (may be NULL if not an operator)
lpYYFcnStrRht; // Ptr to right operand function strand (may be NULL if monadic operator or not an operator)
UBOOL bTknDel; // TRUE iff the function strand token is a Del
LPTOKEN lptkAxisLcl; // Ptr to local axis token
// Check for local axis operator
lptkAxisLcl = CheckAxisOper (lpYYFcnStrOpr);
// Determine if the token is a Del
bTknDel = (lpYYFcnStrOpr NE NULL
&& lpYYFcnStrOpr->tkToken.tkFlags.TknType EQ TKT_DELAFO);
// If the token is a Del, ...
if (bTknDel)
// Setup left and right operands (if present)
GetOperands (GetGlbHandle (&lpYYFcnStrOpr->tkToken), &lpYYFcnStrLft, &lpYYFcnStrRht);
else
// If this is a monadic operator, ...
if (lpYYFcnStrOpr NE NULL
&& IsTknOp1 (&lpYYFcnStrOpr->tkToken))
{
// Set ptr to left operand
lpYYFcnStrLft = GetMonLftOper (lpYYFcnStrOpr, lptkAxisLcl);
// Zap the right operand
lpYYFcnStrRht = NULL;
} else
// If this is a dyadic operator, ...
if (lpYYFcnStrOpr NE NULL
&& IsTknOp2 (&lpYYFcnStrOpr->tkToken))
{
// Set ptr to right operand
lpYYFcnStrRht = GetDydRhtOper (lpYYFcnStrOpr, lptkAxisLcl);
// Set ptr to left operand
lpYYFcnStrLft = GetDydLftOper (lpYYFcnStrRht);
} else
lpYYFcnStrLft = lpYYFcnStrRht = NULL;
// Only one axis
Assert (lptkAxisOpr EQ lptkAxisLcl || lptkAxisOpr EQ NULL || lptkAxisLcl EQ NULL);
////// Pick the axis
////if (lptkAxisOpr EQ NULL)
//// // Use the local one
//// lptkAxisOpr = lptkAxisLcl;
// Call common routine
lpYYRes =
ExecDfnOprGlb_EM_YY (hGlbDfnHdr, // User-defined function/operator global memory handle
lptkLftArg, // Ptr to left arg token (may be NULL if niladic/monadic)
lpYYFcnStrLft, // Ptr to left operand function strand (may be NULL if not an operator and no axis)
lpYYFcnStrOpr, // Ptr to function strand (may be NULL if not an operator and no axis)
lpYYFcnStrRht, // Ptr to right operand function strand (may be NULL if not an operator and no axis)
lptkAxisOpr, // Ptr to axis token (may be NULL -- used only if function strand is NULL)
lptkRhtArg, // Ptr to right arg token (may be NULL if niladic)
startLineType); // Starting line type (see LINE_NUMS)
// If the token is a Del, ...
if (bTknDel)
{
// If we allocated it, ...
if (lpYYFcnStrLft NE NULL)
// Free the left operand YYRes
YYFree (lpYYFcnStrLft);
// If we allocated it, ...
if (lpYYFcnStrRht NE NULL)
// Free the right operand YYRes
YYFree (lpYYFcnStrRht);
} // End IF
// If the result is valid and not NoValue, ...
if (lpYYRes NE NULL
&& !IsTokenNoValue (&lpYYRes->tkToken))
// Change the SynObj
lpYYRes->tkToken.tkSynObj = soA;
return lpYYRes;
} // End ExecDfnGlb_EM_YY
#undef APPEND_NAME
//***************************************************************************
// $ExecDfnOprGlb_EM_YY
//
// Execute a user-defined function/operator
//***************************************************************************
#ifdef DEBUG
#define APPEND_NAME L" -- ExecDfnOprGlb_EM_YY"
#else
#define APPEND_NAME
#endif
LPPL_YYSTYPE ExecDfnOprGlb_EM_YY
(HGLOBAL hGlbDfnHdr, // User-defined function/operator global memory handle
LPTOKEN lptkLftArg, // Ptr to left arg token (may be NULL if niladic/monadic)
LPPL_YYSTYPE lpYYFcnStrLft, // Ptr to left operand function strand (may be NULL if not an operator and no axis)
LPPL_YYSTYPE lpYYFcnStr, // Ptr to function strand (may be NULL if not an operator and no axis)
LPPL_YYSTYPE lpYYFcnStrRht, // Ptr to right operand function strand (may be NULL if not an operator and no axis)
LPTOKEN lptkAxis, // Ptr to axis token (may be NULL -- used only if function strand is NULL)
LPTOKEN lptkRhtArg, // Ptr to right arg token (may be NULL if niladic)
LINE_NUMS startLineType) // Starting line type (see LINE_NUMS)
{
LPPL_YYSTYPE lpYYRes = NULL; // Ptr to the result
LPDFN_HEADER lpMemDfnHdr; // Ptr to user-defined function/operator header
APLSTYPE aplTypeLft, // Left arg storage type
aplTypeRht; // Right ...
APLNELM aplNELMLft, // Left arg NELM
aplNELMRht; // Right ...
APLRANK aplRankLft, // Left arg rank
aplRankRht; // Right ...
LPSYMENTRY lpSymLftFcn = NULL,// Ptr to original tkSym in the named left operand
lpSymRhtFcn = NULL;// ... right ...
LPPERTABDATA lpMemPTD; // Ptr to PerTabData global memory
LPPL_YYSTYPE lpYYFcnTmpLft, // Ptr to temp left operand function strand (may be NULL if not an operator)
lpYYFcnTmpRht; // Ptr to temp right operand function strand (may be NULL if monadic operator or not an operator)
LPTOKEN lptkLftTmp, // Ptr to temp left arg token
lptkRhtTmp; // ... right
TOKEN tkLftTmp, // Temp left arg token
tkRhtTmp; // ... right ...
SYMENTRY symLftArg, // Temp SYMENTRY for left arg
symLftFcn, // ... left operand
symRhtFcn, // ... right operand
symRhtArg; // ... right arg
UBOOL bNamedLftFcn, // TRUE iff the left operand is a named function
bNamedRhtFcn; // ... right ...
UBOOL bOldExecuting; // Old value of bExecuting
HWND hWndEC; // Edit Ctrl window handle
UINT startLineNum; // Starting line #
LPHSHTABSTR lphtsPTD = NULL; // Save area for old HshTabStr
// Get ptr to PerTabData global memory
lpMemPTD = GetMemPTD ();
// Get the Edit Ctrl window handle
(HANDLE_PTR) hWndEC = GetWindowLongPtrW (lpMemPTD->hWndSM, GWLSF_HWNDEC);
// Indicate that we're executing
bOldExecuting = lpMemPTD->bExecuting; SetExecuting (lpMemPTD, TRUE);
// Lock the memory to get a ptr to it
lpMemDfnHdr = MyGlobalLockDfn (hGlbDfnHdr);
// If we're executing an AFO, ...
if (lpMemDfnHdr->bAFO)
{
// Save the ptr to the old HshTabStr
lphtsPTD = lpMemPTD->lphtsPTD;
// If the source and destin are different, ...
if (lphtsPTD NE &lpMemDfnHdr->htsDFN)
{
// Make a copy of the current system vars so we have up-to-date values
CopySysVars (&lpMemDfnHdr->htsDFN, lphtsPTD);
// Put the new one into effect so that symbol table
// references are made in the new tables
lpMemPTD->lphtsPTD = &lpMemDfnHdr->htsDFN;
} // End IF
} // End IF
// If there's no left arg token and this function requires a left arg,
// and we're not entering at LINENUM_ID,
// signal a VALENCE ERROR
if (lptkLftArg EQ NULL
&& lpMemDfnHdr->FcnValence NE FCNVALENCE_AMB
&& lpMemDfnHdr->numLftArgSTE NE 0
&& startLineType NE LINENUM_ID)
goto VALENCE_EXIT;
// If there's a left arg token and this function has no left arg,
// signal a VALENCE ERROR
if (lptkLftArg NE NULL
&& lpMemDfnHdr->numLftArgSTE EQ 0)
goto VALENCE_EXIT;
// If there is an axis token and this function does not accept
// an axis operator, signal an SYNTAX ERROR
if (lptkAxis NE NULL
&& lpMemDfnHdr->steAxisOpr EQ NULL)
goto AXIS_SYNTAX_EXIT;
// If there's no right arg token and this function requires a right arg,
// signal a SYNTAX ERROR
if (lptkRhtArg EQ NULL
&& lpMemDfnHdr->numRhtArgSTE NE 0)
goto RIGHT_SYNTAX_EXIT;
// Get the attributes (Type, NELM, and Rank)
// of the left & right args
if (lptkLftArg NE NULL)
AttrsOfToken (lptkLftArg, &aplTypeLft, &aplNELMLft, &aplRankLft, NULL);
if (lptkRhtArg NE NULL)
AttrsOfToken (lptkRhtArg, &aplTypeRht, &aplNELMRht, &aplRankRht, NULL);
// If the DFN left arg is present and a list, make sure the left arg token
// is a scalar, or a vector of the proper length
if (lptkLftArg NE NULL && lpMemDfnHdr->ListLft)
{
if (IsMultiRank (aplRankLft))
goto LEFT_RANK_EXIT;
if (IsVector (aplRankLft)
&& lpMemDfnHdr->numLftArgSTE NE aplNELMLft)
goto LEFT_LENGTH_EXIT;
} // End IF
// If the DFN right arg is present and a list, make sure the right arg token
// is a scalar, or a vector of the proper length
if (lptkRhtArg NE NULL && lpMemDfnHdr->ListRht)
{
if (IsMultiRank (aplRankRht))
goto RIGHT_RANK_EXIT;
if (IsVector (aplRankRht)
&& lpMemDfnHdr->numRhtArgSTE NE aplNELMRht)
goto RIGHT_LENGTH_EXIT;
} // End IF
// Split cases based upon the starting line #
switch (startLineType)
{
case LINENUM_ONE:
startLineNum = 1;
break;
case LINENUM_ID:
startLineNum = lpMemDfnHdr->nSysLblId;
break;
case LINENUM_INV:
startLineNum = lpMemDfnHdr->nSysLblInv;
break;
case LINENUM_MS:
startLineNum = lpMemDfnHdr->nSysLblMs;
break;
case LINENUM_PRO:
startLineNum = lpMemDfnHdr->nSysLblPro;
break;
defstop
break;
} // End SWITCH
// Check for non-existant label
if (startLineNum EQ 0)
goto DOMAIN_EXIT;
// Fill in the SIS header for a User-Defined Function/Operator
FillSISNxt (lpMemPTD, // Ptr to PerTabData global memory
NULL, // Semaphore handle (Filled in by ExecuteFunction_EM_YY)
lpMemDfnHdr->DfnType, // DfnType
lpMemDfnHdr->FcnValence, // FcnValence
FALSE, // Suspended
TRUE, // Restartable
FALSE); // LinkIntoChain
// Fill in the non-default SIS header entries
lpMemPTD->lpSISNxt->hGlbDfnHdr = hGlbDfnHdr;
lpMemPTD->lpSISNxt->hGlbFcnName = lpMemDfnHdr->steFcnName->stHshEntry->htGlbName;
lpMemPTD->lpSISNxt->DfnAxis = lpMemDfnHdr->DfnAxis;
lpMemPTD->lpSISNxt->bAFO = lpMemDfnHdr->bAFO;
lpMemPTD->lpSISNxt->bMFO = lpMemDfnHdr->bMFO;
lpMemPTD->lpSISNxt->bLclRL = lpMemDfnHdr->bLclRL;
lpMemPTD->lpSISNxt->CurLineNum = 1;
lpMemPTD->lpSISNxt->NxtLineNum = 2;
lpMemPTD->lpSISNxt->numLabels = lpMemDfnHdr->numLblLines;
lpMemPTD->lpSISNxt->numFcnLines = lpMemDfnHdr->numFcnLines;
////lpMemPTD->lpSISNxt->lpSISNxt = // Filled in by LocalizeAll
lpMemPTD->lpSISNxt->lphtsPrv = lphtsPTD;
dprintfWL9 (L"~~Localize: %p (%s)", lpMemPTD->lpSISNxt, L"ExecDfnGlb_EM_YY");
//***************************************************************
// Errors beyond this point must call Unlocalize
//***************************************************************
lpMemPTD->lpSISCur = lpMemPTD->lpSISNxt;
// In case any of the operands/args is a named var/fcn and that same name
// is local to the function/operator, we need to copy the STE of the name
// or else it'll get wiped out by a call to LocalizeSymEntries before we
// get to use it in InitVarSTEs/InitFcnSTEs
if (lptkLftArg NE NULL)
{
// Copy the token
tkLftTmp = *lptkLftArg;
lptkLftTmp = &tkLftTmp;
// If the token type is named, ...
if (IsTknNamed (lptkLftTmp))
{
// Copy the STE in case its name conflicts with a local
symLftArg = *lptkLftTmp->tkData.tkSym;
lptkLftTmp->tkData.tkSym = &symLftArg;
} // End IF
} else
lptkLftTmp = NULL;
if (lpYYFcnStrLft NE NULL)
{
// Copy the PL_YYSTYPE
lpYYFcnTmpLft = lpYYFcnStrLft;
// If the token type is named, ...
if (bNamedLftFcn = IsTknNamed (&lpYYFcnTmpLft->tkToken))
{
// Copy the STE in case its name conflicts with a local
lpSymLftFcn = lpYYFcnTmpLft->tkToken.tkData.tkSym;
symLftFcn = *lpSymLftFcn;
lpYYFcnTmpLft->tkToken.tkData.tkSym = &symLftFcn;
} // End IF
} else
lpYYFcnTmpLft = NULL;
if (lpYYFcnStrRht NE NULL)
{
// Copy the PL_YYSTYPE
lpYYFcnTmpRht = lpYYFcnStrRht;
// If the token type is named, ...
if (bNamedRhtFcn = IsTknNamed (&lpYYFcnTmpRht->tkToken))
{
// Copy the STE in case its name conflicts with a local
lpSymRhtFcn = lpYYFcnTmpRht->tkToken.tkData.tkSym;
symRhtFcn = *lpSymRhtFcn;
lpYYFcnTmpRht->tkToken.tkData.tkSym = &symRhtFcn;
} // End IF
} else
lpYYFcnTmpRht = NULL;
if (lptkRhtArg NE NULL)
{
// Copy the token
tkRhtTmp = *lptkRhtArg;
lptkRhtTmp = &tkRhtTmp;
// If the token type is named, ...
if (IsTknNamed (lptkRhtTmp))
{
// Copy the STE in case its name conflicts with a local
symRhtArg = *lptkRhtTmp->tkData.tkSym;
lptkRhtTmp->tkData.tkSym = &symRhtArg;
} // End IF
} else
lptkRhtTmp = NULL;
// Localize all arguments, results, and locals
LocalizeAll (lpMemPTD, lpMemDfnHdr);
// Setup the left arg STEs
if (!InitVarSTEs (lptkLftTmp,
lpMemDfnHdr->numLftArgSTE,
(LPAPLHETERO) ByteAddr (lpMemDfnHdr, lpMemDfnHdr->offLftArgSTE)))
goto WSFULL_UNLOCALIZE_EXIT;
// Setup the left operand STE
if (lpYYFcnTmpLft NE NULL
&& lpYYFcnTmpLft->tkToken.tkFlags.TknType NE TKT_FILLJOT)
{
// Split cases based upon fcn vs. var
if (!IsTknFcnOpr (&lpYYFcnTmpLft->tkToken))
{
if (!InitVarSTEs (&lpYYFcnTmpLft->tkToken,
lpMemDfnHdr->steLftOpr NE NULL,
&lpMemDfnHdr->steLftOpr))
goto WSFULL_UNLOCALIZE_EXIT;
} else
if (!InitFcnSTEs (lpYYFcnTmpLft,
lpMemDfnHdr->steLftOpr NE NULL,
&lpMemDfnHdr->steLftOpr))
goto UNLOCALIZE_EXIT;
} // End IF
// Setup the axis operand STE
if (!InitVarSTEs (lptkAxis,
lpMemDfnHdr->steAxisOpr NE NULL,
&lpMemDfnHdr->steAxisOpr))
goto WSFULL_UNLOCALIZE_EXIT;
// Setup the right operand STE
if (lpYYFcnTmpRht NE NULL
&& lpYYFcnTmpRht->tkToken.tkFlags.TknType NE TKT_FILLJOT)
{
// Split cases based upon fcn vs. var
if (!IsTknFcnOpr (&lpYYFcnTmpRht->tkToken))
{
if (!InitVarSTEs (&lpYYFcnTmpRht->tkToken,
lpMemDfnHdr->steRhtOpr NE NULL,
&lpMemDfnHdr->steRhtOpr))
goto WSFULL_UNLOCALIZE_EXIT;
} else
if (!InitFcnSTEs (lpYYFcnTmpRht,
lpMemDfnHdr->steRhtOpr NE NULL,
&lpMemDfnHdr->steRhtOpr))
goto LEFT_UNLOCALIZE_EXIT;
} // End IF
// Setup the right arg STEs
if (!InitVarSTEs (lptkRhtTmp,
lpMemDfnHdr->numRhtArgSTE,
(LPAPLHETERO) ByteAddr (lpMemDfnHdr, lpMemDfnHdr->offRhtArgSTE)))
goto WSFULL_UNLOCALIZE_EXIT;
// We no longer need this ptr
MyGlobalUnlock (hGlbDfnHdr); lpMemDfnHdr = NULL;
__try
{
// Execute the user-defined function/operator
lpYYRes =
ExecuteFunction_EM_YY (startLineNum, &lpYYFcnStr->tkToken);
} __except (CheckException (GetExceptionInformation (), L"ExecDfnOprGlb_EM_YY"))
{
// Unlocalize the STEs on the innermost level
// and strip off one level
UnlocalizeSTEs (hGlbDfnHdr);
// Pass on the exception
RaiseException (MyGetExceptionCode (), 0, 0, NULL);
} // End __try/__except
// Lock the memory to get a ptr to it
lpMemDfnHdr = MyGlobalLockDfn (hGlbDfnHdr);
LEFT_UNLOCALIZE_EXIT:
UNLOCALIZE_EXIT:
// Unlocalize the STEs on the innermost level
// and strip off one level
UnlocalizeSTEs (hGlbDfnHdr);
goto NORMAL_EXIT;
// The RANK, LENGTH, and SYNTAX errors don't point the caret to the
// specific arg because that might confuse the user into thinking
// that the error is with the construction of that arg rather than
// its interaction with this user-defined function/operator.
LEFT_RANK_EXIT:
ErrorMessageIndirectToken (ERRMSG_RANK_ERROR APPEND_NAME,
&lpYYFcnStr->tkToken);
goto ERROR_EXIT;
RIGHT_RANK_EXIT:
ErrorMessageIndirectToken (ERRMSG_RANK_ERROR APPEND_NAME,
&lpYYFcnStr->tkToken);
goto ERROR_EXIT;
LEFT_LENGTH_EXIT:
ErrorMessageIndirectToken (ERRMSG_LENGTH_ERROR APPEND_NAME,
&lpYYFcnStr->tkToken);
goto ERROR_EXIT;
RIGHT_LENGTH_EXIT:
ErrorMessageIndirectToken (ERRMSG_LENGTH_ERROR APPEND_NAME,
&lpYYFcnStr->tkToken);
goto ERROR_EXIT;
DOMAIN_EXIT:
ErrorMessageIndirectToken (ERRMSG_DOMAIN_ERROR APPEND_NAME,
&lpYYFcnStr->tkToken);
goto ERROR_EXIT;
VALENCE_EXIT:
ErrorMessageIndirectToken (ERRMSG_VALENCE_ERROR APPEND_NAME,
&lpYYFcnStr->tkToken);
goto ERROR_EXIT;
AXIS_SYNTAX_EXIT:
ErrorMessageIndirectToken (ERRMSG_SYNTAX_ERROR APPEND_NAME,
lptkAxis);
goto ERROR_EXIT;
RIGHT_SYNTAX_EXIT:
ErrorMessageIndirectToken (ERRMSG_SYNTAX_ERROR APPEND_NAME,
&lpYYFcnStr->tkToken);
goto ERROR_EXIT;
WSFULL_UNLOCALIZE_EXIT:
// Unlocalize the STEs on the innermost level
// and strip off one level
UnlocalizeSTEs (hGlbDfnHdr);
ErrorMessageIndirectToken (ERRMSG_WS_FULL APPEND_NAME,
&lpYYFcnStr->tkToken);
goto ERROR_EXIT;
ERROR_EXIT:
NORMAL_EXIT:
// Restore the previous executing state
SetExecuting (lpMemPTD, bOldExecuting);
// Restore named left operand tkSym
if (lpSymLftFcn NE NULL && bNamedLftFcn)
lpYYFcnTmpLft->tkToken.tkData.tkSym = lpSymLftFcn;
// Restore named right operand tkSym
if (lpSymRhtFcn NE NULL && bNamedRhtFcn)
lpYYFcnTmpRht->tkToken.tkData.tkSym = lpSymRhtFcn;
// If we're executing an AFO, ...
if (lpMemDfnHdr->bAFO)
// Restore the original tables
lpMemPTD->lphtsPTD = lphtsPTD;
if (hGlbDfnHdr NE NULL && lpMemDfnHdr NE NULL)
{
// We no longer need this ptr
MyGlobalUnlock (hGlbDfnHdr); lpMemDfnHdr = NULL;
} // End IF
return lpYYRes;
} // End ExecDfnOprGlb_EM_YY
#undef APPEND_NAME
//***************************************************************************
// $LocalizeAll
//
// Localize all args of a given function
//***************************************************************************
void LocalizeAll
(LPPERTABDATA lpMemPTD, // Ptr to PerTabData global memory
LPDFN_HEADER lpMemDfnHdr) // Ptr to user-defined function/operator header
{
LPSYMENTRY lpSymEntryBeg, // Ptr to start of SYMENTRYs on the SIS
lpSymEntryNxt; // Ptr to next ...
__try
{
// Point to the destination SYMENTRYs
lpSymEntryBeg =
lpSymEntryNxt = (LPSYMENTRY) ByteAddr (lpMemPTD->lpSISNxt, sizeof (SIS_HEADER));
// Copy onto the SIS the current STEs for each local
// and undefine all but the system vars
// Localize and clear the result STEs
lpSymEntryNxt =
LocalizeSymEntries (lpSymEntryNxt,
lpMemDfnHdr->numResultSTE,
(LPAPLHETERO) ByteAddr (lpMemDfnHdr, lpMemDfnHdr->offResultSTE),
lpMemPTD);
// Localize and clear the left arg STEs
lpSymEntryNxt =
LocalizeSymEntries (lpSymEntryNxt,
lpMemDfnHdr->numLftArgSTE,
(LPAPLHETERO) ByteAddr (lpMemDfnHdr, lpMemDfnHdr->offLftArgSTE),
lpMemPTD);
// Localize and clear the left operand STE
lpSymEntryNxt =
LocalizeSymEntries (lpSymEntryNxt,
lpMemDfnHdr->steLftOpr NE NULL,
&lpMemDfnHdr->steLftOpr,
lpMemPTD);
// Localize and clear the axis operand STE
lpSymEntryNxt =
LocalizeSymEntries (lpSymEntryNxt,
lpMemDfnHdr->steAxisOpr NE NULL,
&lpMemDfnHdr->steAxisOpr,
lpMemPTD);
// Localize and clear the right operand STE
lpSymEntryNxt =
LocalizeSymEntries (lpSymEntryNxt,
lpMemDfnHdr->steRhtOpr NE NULL,
&lpMemDfnHdr->steRhtOpr,
lpMemPTD);
// Localize and clear the right arg STEs
lpSymEntryNxt =
LocalizeSymEntries (lpSymEntryNxt,
lpMemDfnHdr->numRhtArgSTE,
(LPAPLHETERO) ByteAddr (lpMemDfnHdr, lpMemDfnHdr->offRhtArgSTE),
lpMemPTD);
// Localize and clear the locals STEs
lpSymEntryNxt =
LocalizeSymEntries (lpSymEntryNxt,
lpMemDfnHdr->numLocalsSTE,
(LPAPLHETERO) ByteAddr (lpMemDfnHdr, lpMemDfnHdr->offLocalsSTE),
lpMemPTD);
// Search for line labels, localize and initialize them
lpSymEntryNxt =
LocalizeLabels (lpSymEntryNxt,
lpMemDfnHdr,
lpMemPTD);
// Save the # LPSYMENTRYs localized
lpMemPTD->lpSISNxt->numSymEntries = (UINT) (lpSymEntryNxt - lpSymEntryBeg);
Assert (lpMemPTD->lpSISNxt->numSymEntries EQ
(lpMemDfnHdr->numResultSTE
+ lpMemDfnHdr->numLftArgSTE
+ (lpMemDfnHdr->steLftOpr NE NULL)
+ (lpMemDfnHdr->steAxisOpr NE NULL)
+ (lpMemDfnHdr->steRhtOpr NE NULL)
+ lpMemDfnHdr->numRhtArgSTE
+ lpMemDfnHdr->numLocalsSTE
+ lpMemDfnHdr->numLblLines));
// Save as new SISNxt ptr
lpMemPTD->lpSISNxt = (LPSIS_HEADER) lpSymEntryNxt;
Assert (lpMemPTD->lpSISNxt NE lpMemPTD->lpSISCur);
} __except (CheckException (GetExceptionInformation (), L"LocalizeAll"))
{
// Save the # LPSYMENTRYs localized
lpMemPTD->lpSISNxt->numSymEntries = (UINT) (lpSymEntryNxt - lpSymEntryBeg);
// Save as new SISNxt ptr
lpMemPTD->lpSISNxt = (LPSIS_HEADER) lpSymEntryNxt;
// Pass on the exception
RaiseException (MyGetExceptionCode (), 0, 0, NULL);
} // End __try/__except
} // End LocalizeAll
//***************************************************************************
// $CheckSymEntries
//
// Debug routine to check on localized SYMENTRYs
//***************************************************************************
void _CheckSymEntries
(LPSTR lpFileName, // Ptr to our caller's filename
UINT uLineNum) // Caller's line #
{
LPPERTABDATA lpMemPTD; // Ptr to PerTabData global memory
LPSIS_HEADER lpSISCur; // Ptr to current SIS header
LPSYMENTRY lpSymEntryNxt; // Ptr to next localized LPSYMENTRY on the SIS
UINT numSymEntries, // # LPSYMENTRYs localized
numSym; // Loop counter
// Get ptr to PerTabData global memory
lpMemPTD = TlsGetValue (dwTlsPerTabData); // Assert (IsValidPtr (lpMemPTD, sizeof (lpMemPTD)));
// If lpMemPTD isn't set, just exit
if (lpMemPTD EQ NULL)
return;
// Get a ptr to the current SIS header
lpSISCur = lpMemPTD->lpSISCur;
while (lpSISCur NE NULL)
{
// Get # LPSYMENTRYs on the stack
numSymEntries = lpSISCur->numSymEntries;
// Point to the start of the localized LPSYMENTRYs
lpSymEntryNxt = (LPSYMENTRY) ByteAddr (lpSISCur, sizeof (SIS_HEADER));
// Point to the end of the localize LPSYMENTRYs
lpSymEntryNxt = &lpSymEntryNxt[numSymEntries - 1];
// Loop through the LPSYMENTRYs on the stack
for (numSym = 0; numSym < numSymEntries; numSym++, lpSymEntryNxt--)
if (lpSymEntryNxt->stFlags.ObjName NE OBJNAME_LOD)
{
__try
{
if (lpSymEntryNxt->stHshEntry EQ NULL)
DbgBrk ();
if (lpSymEntryNxt->stHshEntry->htSymEntry EQ NULL)
DbgBrk ();
} __except (CheckException (GetExceptionInformation (), L"CheckSymEntries"))
{
wsprintfW (lpMemPTD->lpwszTemp,
L"CheckSymEntries was called from <%S> line #%d",
lpFileName,
uLineNum);
AppendLine (lpMemPTD->lpwszTemp, FALSE, TRUE);
FormatSTE (lpSymEntryNxt, lpMemPTD->lpwszTemp, lpMemPTD->iTempMaxSize);
AppendLine (lpMemPTD->lpwszTemp, FALSE, TRUE);
FormatHTE (lpSymEntryNxt->stHshEntry, lpMemPTD->lpwszTemp, lpMemPTD->iTempMaxSize, 0);
AppendLine (lpMemPTD->lpwszTemp, FALSE, TRUE);
// Display message for unhandled exception
DisplayException ();
} // End __try/__except
} // End FOR/IF
// Get a ptr to the previous (if any) entry
lpSISCur = lpSISCur->lpSISPrv;
} // End WHILE
} // End _CheckSymEntries
//***************************************************************************
// $ExecuteFunction_EM_YY
//
// Execute a function, line by line
//***************************************************************************
#ifdef DEBUG
#define APPEND_NAME L" -- ExecuteFunction_EM_YY"
#else
#define APPEND_NAME
#endif
LPPL_YYSTYPE ExecuteFunction_EM_YY
(UINT uLineNum, // Starting line # (origin-1)
LPTOKEN lptkFunc) // Ptr to function token (may be NULL)
{
LPPL_YYSTYPE lpYYRes = NULL; // Ptr to the result
LPDFN_HEADER lpMemDfnHdr; // Ptr to user-defined function/operator header
HGLOBAL hGlbDfnHdr, // User-defined function/operator global memory handle
hGlbTxtLine; // Line text global memory handle
LPPERTABDATA lpMemPTD = NULL; // Ptr to PerTabData global memory
LPFCNLINE lpFcnLines; // Ptr to array of function line structs (FCNLINE[numFcnLines])
HWND hWndSM; // Session Manager window handle
HANDLE hSemaphore; // Semaphore handle
UINT numResultSTE, // # result STEs (may be zero if no result)
numRes, // Loop counter
uTokenCnt, // # tokens in the function line
uTknNum; // Next token # in the line
LPSYMENTRY *lplpSymEntry; // Ptr to 1st result STE
HGLOBAL hGlbTknHdr; // Tokenized header global memory handle
UBOOL bRet, // TRUE iff result is valid
bFirstTime, // TRUE iff this is the first time executing
bStopLine, // TRUE iff we're stopping on this line
bTraceLine, // TRUE iff we're tracing the line
bStopRestart; // TRUE iff we're restarting a []STOPped line
EXIT_TYPES exitType; // Return code from ParseLine
LPTOKEN_HEADER lpMemTknLine; // Ptr to tokenized line global memory
// Get ptr to PerTabData global memory
lpMemPTD = GetMemPTD ();
// Get the user-defined function/operator header global memory handle
hGlbDfnHdr = lpMemPTD->lpSISCur->hGlbDfnHdr;
// Lock the memory to get a ptr to it
lpMemDfnHdr = MyGlobalLockDfn (hGlbDfnHdr);
// If monitoring is on, increment the function counter
if (lpMemDfnHdr->MonOn)
{
LPINTMONINFO lpMemMonInfo; // Ptr to function line monitoring info
// Lock the memory to get a ptr to it
lpMemMonInfo = MyGlobalLock (lpMemDfnHdr->hGlbMonInfo);
// Increment the function counter
lpMemMonInfo[0].Count++;
// We no longer need this ptr
MyGlobalUnlock (lpMemDfnHdr->hGlbMonInfo); lpMemMonInfo = NULL;
} // End IF
// Get the tokenized header global memory handle
hGlbTknHdr = lpMemDfnHdr->hGlbTknHdr;
// Get the SM window handle
hWndSM = lpMemPTD->hWndSM;
// Initialize the exit type in case we fall through
exitType = EXITTYPE_NONE;
// Save current line & token #
lpMemPTD->lpSISCur->CurLineNum = uLineNum;
lpMemPTD->lpSISCur->NxtLineNum = uLineNum + 1;
lpMemPTD->lpSISCur->NxtTknNum = uTknNum = 0;
// Create a semaphore
hSemaphore =
lpMemPTD->lpSISCur->hSemaphore =
MyCreateSemaphoreW (NULL, // No security attrs
0, // Initial count (non-signalled)
64*1024, // Maximum count
NULL); // No name
#ifdef DEBUG
DisplayFcnLine (lpMemDfnHdr->hGlbTxtHdr, lpMemPTD, 0);
#endif
// Mark as not restarting a []STOPped line
bStopRestart = FALSE;
// Mark as the first time executing
bFirstTime = TRUE;
// Loop through the function lines
while (TRUE)
{
// Get ptr to array of function line structs (FCNLINE[numFcnLines])
lpFcnLines = (LPFCNLINE) ByteAddr (lpMemDfnHdr, lpMemDfnHdr->offFcnLines);
// Get the stop & trace flags
bStopLine = lpFcnLines[uLineNum - 1].bStop && !bStopRestart;
bTraceLine = lpFcnLines[uLineNum - 1].bTrace;
// Check for empty line
if (lpFcnLines[uLineNum - 1].bEmpty
&& !bTraceLine)
goto NEXTLINE;
// Get the starting line's token & text global memory handles
hGlbTxtLine = lpFcnLines[uLineNum - 1].hGlbTxtLine;
lpMemTknLine = (LPTOKEN_HEADER) ByteAddr (lpMemDfnHdr, lpFcnLines[uLineNum - 1].offTknLine);
// Get the token count of this line
uTokenCnt = lpMemTknLine->TokenCnt;
// If the starting token # is outside the token count, ...
if (uTknNum >= uTokenCnt)
goto NEXTLINE;
// If this is not the first time,
// and it's an AFO,
// and the current line is a System Label, ...
if (!bFirstTime
&& lpMemDfnHdr->bAFO
&& lpFcnLines[uLineNum - 1].bSysLbl)
{
// Free any past result
EraseAfoResult (lpMemDfnHdr);
// Set the exit type
exitType = EXITTYPE_NONE;
break;
} // End IF
// Mark as no longer the first time
bFirstTime = FALSE;
#ifdef DEBUG
DisplayFcnLine (hGlbTxtLine, lpMemPTD, uLineNum);