-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecfns.c
More file actions
1578 lines (1351 loc) · 73.5 KB
/
execfns.c
File metadata and controls
1578 lines (1351 loc) · 73.5 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 -- Execution Functions
//***************************************************************************
/***************************************************************************
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"
//***************************************************************************
// $ExecuteFn0
//
// Execute a niladic function
//***************************************************************************
LPPL_YYSTYPE ExecuteFn0
(LPPL_YYSTYPE lpYYFcn0) // Ptr to function PL_YYSTYPE
{
LPPRIMFNS lpNameFcn;
// Split cases based upon the ptr type bits
switch (GetPtrTypeDir (lpYYFcn0->tkToken.tkData.tkVoid))
{
case PTRTYPE_STCONST:
// tkData is an LPSYMENTRY
lpNameFcn = lpYYFcn0->tkToken.tkData.tkSym->stData.stNameFcn;
if (lpYYFcn0->tkToken.tkData.tkSym->stFlags.FcnDir)
// Call the execution routine
return (*lpNameFcn) (NULL, // Ptr to left arg token (may be NULL if monadic)
&lpYYFcn0->tkToken, // Ptr to function token
NULL, // Ptr to right arg token
NULL); // Ptr to axis token (may be NULL)
break;
case PTRTYPE_HGLOBAL:
// tkData is an HGLOBAL
lpNameFcn = lpYYFcn0->tkToken.tkData.tkGlbData;
break;
defstop
break;
} // End SWITCH
// tkData is a valid HGLOBAL function array or user-defined function/operator
Assert (IsGlbTypeFcnDir_PTB (lpNameFcn)
|| IsGlbTypeDfnDir_PTB (lpNameFcn));
// Split cases based upon the array signature
switch (GetSignatureGlb_PTB (lpNameFcn))
{
case FCNARRAY_HEADER_SIGNATURE:
// Execute a function array global memory handle
return ExecFcnGlb_EM_YY (NULL, // Ptr to left arg token (may be NULL if niladic/monadic)
lpNameFcn, // Function array global memory handle
NULL, // Ptr to right arg token (may be NULL if niladic)
NULL); // Ptr to axis token (may be NULL)
case DFN_HEADER_SIGNATURE:
// Execute a user-defined function/operator global memory handle
return ExecDfnGlb_EM_YY (lpNameFcn, // User-defined function/operator global memory handle
NULL, // Ptr to left arg token (may be NULL if monadic)
lpYYFcn0, // Ptr to function strand
NULL, // Ptr to axis token (may be NULL -- used only if function strand is NULL)
NULL, // Ptr to right arg token
LINENUM_ONE); // Starting line # (see LINE_NUMS)
defstop
return NULL;
} // End SWITCH
} // End ExecuteFn0
//***************************************************************************
// $ExecFunc_EM_YY
//
// Execute a user-defined, system, or primitive function
//***************************************************************************
#ifdef DEBUG
#define APPEND_NAME L" -- ExecFunc_EM_YY"
#else
#define APPEND_NAME
#endif
LPPL_YYSTYPE ExecFunc_EM_YY
(LPTOKEN lptkLftArg, // Ptr to left arg token (may be NULL if monadic)
LPPL_YYSTYPE lpYYFcnStr, // Ptr to function strand
LPTOKEN lptkRhtArg) // Ptr to right arg token
{
LPPRIMFNS lpPrimFn; // Ptr to direct primitive or system function
LPTOKEN lptkAxis; // Ptr to axis token (may be NULL)
HGLOBAL hGlbFcn, // Function array global memory handle
hGlbLft, // Left arg global memory handle (may be NULL)
hGlbRht; // Right ...
LPPERTABDATA lpMemPTD; // Ptr to PerTabData global memory
LPHSHTABSTR lphtsPTD = NULL, // Ptr to HshTab struc about to be activated
lphtsOld; // ... old HTS
LPPL_YYSTYPE lpYYRes = NULL; // Ptr to the result
UINT uSysNSLvl; // System namespace level
// Get the left and right arg global memory handle
if (lptkLftArg NE NULL)
hGlbLft = GetGlbHandle (lptkLftArg);
else
hGlbLft = NULL;
if (lptkRhtArg NE NULL)
hGlbRht = GetGlbHandle (lptkRhtArg);
else
hGlbRht = NULL;
// Check for NoValue
if (IsTokenNoValue (lptkLftArg)
|| IsTokenNoValue (lptkRhtArg))
goto VALUE_EXIT;
// Check for axis operator
lptkAxis = CheckAxisOper (lpYYFcnStr);
// Get ptr to PerTabData global memory
lpMemPTD = GetMemPTD ();
// Split cases based upon the function token type
switch (lpYYFcnStr->tkToken.tkFlags.TknType)
{
case TKT_FCNIMMED:
// Get the address of the execution routine
lpPrimFn = PrimFnsTab[SymTrans (&lpYYFcnStr->tkToken)];
if (lpPrimFn EQ NULL)
goto SYNTAX_EXIT;
// Get the system namespace level
uSysNSLvl = lpYYFcnStr->tkToken.tkFlags.SysNSLvl;
// Check for system namespace
if (uSysNSLvl > 0)
{
// Save the old HTS
lphtsPTD =
lphtsOld = lpMemPTD->lphtsPTD;
// Peel back HshTabStrs
while (uSysNSLvl-- > 1 && lphtsPTD->lphtsPrvSrch)
lphtsPTD = lphtsPTD->lphtsPrvSrch;
// If we found a new HTS, ...
if (lphtsPTD NE lphtsOld)
// Point to it
lpMemPTD->lphtsPTD = lphtsPTD;
} // End IF
__try
{
// Execute the primitive function
lpYYRes =
(*lpPrimFn) (lptkLftArg, // Ptr to left arg token (may be NULL if monadic)
&lpYYFcnStr->tkToken, // Ptr to function token
lptkRhtArg, // Ptr to right arg token
lptkAxis); // Ptr to axis token (may be NULL)
} __except (CheckException (GetExceptionInformation (), L"ExecFunc_EM_YY #1"))
{
// Set the error message text
ErrorMessageIndirectToken (ERRMSG_LIMIT_ERROR APPEND_NAME,
&lpYYFcnStr->tkToken);
// Mark as an error
lpYYRes = NULL;
} // End __try/__except
// Get the system namespace level
uSysNSLvl = lpYYFcnStr->tkToken.tkFlags.SysNSLvl;
// Check for system namespace,
// and past HshTabStr struc
if (uSysNSLvl > 0
&& lphtsPTD NE lphtsOld)
// Restore the old HTS
lpMemPTD->lphtsPTD = lphtsOld;
break;
case TKT_FCNNAMED:
// tkData is an LPSYMENTRY
Assert (GetPtrTypeDir (lpYYFcnStr->tkToken.tkData.tkVoid) EQ PTRTYPE_STCONST);
// If the LPSYMENTRY is not immediate, it must be an HGLOBAL
if (!lpYYFcnStr->tkToken.tkData.tkSym->stFlags.Imm)
{
STFLAGS stFlags;
// Get the STE flags of the first token
stFlags = lpYYFcnStr->tkToken.tkData.tkSym->stFlags;
// If it's an internal function, execute it directly
if (stFlags.FcnDir)
{
LPPRIMFNS lpNameFcn; // Ptr to the internal routine
// Get the address of the execution routine
lpNameFcn = lpYYFcnStr->tkToken.tkData.tkSym->stData.stNameFcn;
// Get the system namespace level
uSysNSLvl = lpYYFcnStr->tkToken.tkFlags.SysNSLvl;
// Check for system namespace
if (uSysNSLvl > 0)
{
// Save the old HTS
lphtsPTD =
lphtsOld = lpMemPTD->lphtsPTD;
// Peel back HshTabStrs
while (uSysNSLvl-- > 1 && lphtsPTD->lphtsPrvSrch)
lphtsPTD = lphtsPTD->lphtsPrvSrch;
// If we found a new HTS, ...
if (lphtsPTD NE lphtsOld)
// Point to it
lpMemPTD->lphtsPTD = lphtsPTD;
} // End IF
__try
{
// If it's an internal function, ...
lpYYRes =
(*lpNameFcn) (lptkLftArg, // Ptr to left arg token (may be NULL if monadic)
&lpYYFcnStr->tkToken, // Ptr to function token
lptkRhtArg, // Ptr to right arg token
lptkAxis); // Ptr to axis token (may be NULL)
} __except (CheckException (GetExceptionInformation (), L"ExecFunc_EM_YY #2"))
{
// Set the error message text
ErrorMessageIndirectToken (ERRMSG_LIMIT_ERROR APPEND_NAME,
&lpYYFcnStr->tkToken);
// Mark as an error
lpYYRes = NULL;
} // End __try/__except
// Get the system namespace level
uSysNSLvl = lpYYFcnStr->tkToken.tkFlags.SysNSLvl;
// Check for system namespace,
// and past HshTabStr struc
if (uSysNSLvl > 0
&& lphtsPTD NE lphtsOld)
// Restore the old HTS
lpMemPTD->lphtsPTD = lphtsOld;
break;
} // End IF
// Use the HGLOBAL
hGlbFcn = lpYYFcnStr->tkToken.tkData.tkSym->stData.stGlbData;
// stData is a valid HGLOBAL function array
// or user-defined function/operator
Assert (IsGlbTypeFcnDir_PTB (hGlbFcn)
|| IsGlbTypeDfnDir_PTB (hGlbFcn));
__try
{
// If it's a user-defined function/operator, ...
if (stFlags.UsrDfn)
lpYYRes =
ExecDfnGlb_EM_YY (hGlbFcn, // User-defined function/operator global memory handle
lptkLftArg, // Ptr to left arg token (may be NULL if monadic)
lpYYFcnStr, // Ptr to function strand
lptkAxis, // Ptr to axis token (may be NULL -- used only if function strand is NULL)
lptkRhtArg, // Ptr to right arg token
LINENUM_ONE); // Starting line # (see LINE_NUMS)
else
// Execute a function array global memory handle
lpYYRes =
ExecFcnGlb_EM_YY (lptkLftArg, // Ptr to left arg token (may be NULL if niladic/monadic)
hGlbFcn, // Function array global memory handle
lptkRhtArg, // Ptr to right arg token (may be NULL if niladic)
lptkAxis); // Ptr to axis token (may be NULL)
} __except (CheckException (GetExceptionInformation (), L"ExecFunc_EM_YY #3"))
{
// Set the error message text
ErrorMessageIndirectToken (ERRMSG_LIMIT_ERROR APPEND_NAME,
&lpYYFcnStr->tkToken);
// Mark as an error
lpYYRes = NULL;
} // End __try/__except
break;
} // End IF
// Handle the immediate case
// Split cases based upon the immediate type
switch (lpYYFcnStr->tkToken.tkData.tkSym->stFlags.ImmType)
{
case IMMTYPE_PRIMFCN:
{
TOKEN tkFn = {0};
lpPrimFn = PrimFnsTab[FcnTrans (lpYYFcnStr->tkToken.tkData.tkSym->stData.stChar)];
if (lpPrimFn EQ NULL)
goto SYNTAX_EXIT;
// Fill in for PrimFn*** test
tkFn.tkFlags.TknType = TKT_FCNIMMED;
tkFn.tkFlags.ImmType = GetImmTypeFcn (lpYYFcnStr->tkToken.tkData.tkSym->stData.stChar);
////////////////////tkFn.tkFlags.NoDisplay = FALSE; // Already zero from {0}
tkFn.tkData.tkChar = lpYYFcnStr->tkToken.tkData.tkSym->stData.stChar;
tkFn.tkCharIndex = lpYYFcnStr->tkToken.tkCharIndex;
__try
{
lpYYRes =
(*lpPrimFn) (lptkLftArg, // Ptr to left arg token (may be NULL if monadic)
&tkFn, // Ptr to function token
lptkRhtArg, // Ptr to right arg token
lptkAxis); // Ptr to axis token (may be NULL)
} __except (CheckException (GetExceptionInformation (), L"ExecFunc_EM_YY #4"))
{
// Set the error message text
ErrorMessageIndirectToken (ERRMSG_LIMIT_ERROR APPEND_NAME,
&lpYYFcnStr->tkToken);
// Mark as an error
lpYYRes = NULL;
} // End __try/__except
break;
} // End IMMTYPE_PRIMFCN
defstop
break;
} // End SWITCH
break;
case TKT_FCNARRAY:
case TKT_FCNAFO:
// Get the global memory handle
hGlbFcn = GetGlbDataToken (&lpYYFcnStr->tkToken);
// tkData is a valid HGLOBAL function array
// or user-defined function/operator
Assert (IsGlbTypeFcnDir_PTB (hGlbFcn)
|| IsGlbTypeDfnDir_PTB (hGlbFcn));
__try
{
// If it's a user-defined function/operator, ...
switch (GetSignatureGlb_PTB (hGlbFcn))
{
case FCNARRAY_HEADER_SIGNATURE:
// Execute a function array global memory handle
lpYYRes =
ExecFcnGlb_EM_YY (lptkLftArg, // Ptr to left arg token (may be NULL if niladic/monadic)
hGlbFcn, // Function array global memory handle
lptkRhtArg, // Ptr to right arg token
lptkAxis); // Ptr to axis token (may be NULL)
break;
case DFN_HEADER_SIGNATURE:
// Execute a user-defined function/operator global memory handle
lpYYRes =
ExecDfnGlb_EM_YY (hGlbFcn, // User-defined function/operator global memory handle
lptkLftArg, // Ptr to left arg token (may be NULL if monadic)
lpYYFcnStr, // Ptr to function strand
lptkAxis, // Ptr to axis token (may be NULL -- used only if function strand is NULL)
lptkRhtArg, // Ptr to right arg token
LINENUM_ONE); // Starting line # (see LINE_NUMS)
break;
defstop
break;
} // End SWITCH
} __except (CheckException (GetExceptionInformation (), L"ExecFunc_EM_YY #5"))
{
// Set the error message text
ErrorMessageIndirectToken (ERRMSG_LIMIT_ERROR APPEND_NAME,
&lpYYFcnStr->tkToken);
// Mark as an error
lpYYRes = NULL;
} // End __try/__except
break;
case TKT_DELAFO:
{
HGLOBAL hGlbFcn; // Function global memory handle
LPPL_YYSTYPE lpYYFcnStrLft, // Ptr to left operand (may be NULL if function )
lpYYFcnStrRht; // ... right ... (... if function or monadic operator)
// Get the global memory handle
hGlbFcn = lpYYFcnStr->tkToken.tkData.tkGlbData;
// Setup left and right operands (if present)
GetOperands (hGlbFcn, &lpYYFcnStrLft, &lpYYFcnStrRht);
__try
{
// Call common routine
lpYYRes =
ExecDfnOprGlb_EM_YY (hGlbFcn, // User-defined function/operator global memory handle
lptkLftArg, // Ptr to left arg token (may be NULL if monadic)
lpYYFcnStrLft, // Ptr to left operand function strand (may be NULL if not an operator and no axis)
lpYYFcnStr, // 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)
lptkAxis, // Ptr to axis token (may be NULL -- used only if function strand is NULL)
lptkRhtArg, // Ptr to right arg token
LINENUM_ONE); // Starting line # (see LINE_NUMS)
} __except (CheckException (GetExceptionInformation (), L"ExecFunc_EM_YY #6"))
{
// Set the error message text
ErrorMessageIndirectToken (ERRMSG_LIMIT_ERROR APPEND_NAME,
&lpYYFcnStr->tkToken);
// Mark as an error
lpYYRes = NULL;
} // End __try/__except
// 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);
break;
} // End TKT_DELAFO
defstop
break;
} // End SWITCH
// If the result is valid, ...
if (lpYYRes NE NULL
&& !IsTokenNoValue (&lpYYRes->tkToken))
// Change the tkSynObj
lpYYRes->tkToken.tkSynObj = soA;
goto NORMAL_EXIT;
SYNTAX_EXIT:
ErrorMessageIndirectToken (ERRMSG_SYNTAX_ERROR APPEND_NAME,
&lpYYFcnStr->tkToken);
goto NORMAL_EXIT;
VALUE_EXIT:
ErrorMessageIndirectToken (ERRMSG_VALUE_ERROR APPEND_NAME,
(lptkLftArg NE NULL) ? lptkLftArg
: lptkRhtArg);
goto NORMAL_EXIT;
NORMAL_EXIT:
return lpYYRes;
} // End ExecFunc_EM_YY
#undef APPEND_NAME
//***************************************************************************
// $GetOperands
//
// Setup left & right operands if present
//***************************************************************************
void GetOperands
(HGLOBAL hGlbFcn, // Function global memory handle
LPPL_YYSTYPE *lplpYYFcnStrLft, // Ptr to ptr to left operand
LPPL_YYSTYPE *lplpYYFcnStrRht) // ... right ...
{
LPDFN_HEADER lpMemDfnHdr; // Ptr to user-defined function/operator header
// Lock the memory to get a ptr to it
lpMemDfnHdr = MyGlobalLockDfn (hGlbFcn);
// If there's a left operand, ...
if (lpMemDfnHdr->steLftOpr NE NULL)
{
// Allocate a new YYRes for the left operand
*lplpYYFcnStrLft = YYAlloc ();
// Split cases based upon the type of the left operand
switch (lpMemDfnHdr->steLftOpr->stFlags.stNameType)
{
case NAMETYPE_UNK:
(*lplpYYFcnStrLft)->tkToken.tkFlags.TknType = TKT_FILLJOT;
////////////////(*lplpYYFcnStrLft)->tkToken.tkFlags.ImmType = IMMTYPE_ERROR; // Already zero from YYAlloc
////////////////(*lplpYYFcnStrLft)->tkToken.tkFlags.NoDisplay = FALSE; // Already zero from YYAlloc
(*lplpYYFcnStrLft)->tkToken.tkData.tkChar = UTF16_JOT;
////////////////(*lplpYYFcnStrLft)->tkToken.tkCharIndex = // Ignored
break;
case NAMETYPE_VAR:
// If the var is immediate, ...
if (lpMemDfnHdr->steLftOpr->stFlags.Imm)
{
// Fill in the result token
(*lplpYYFcnStrLft)->tkToken.tkFlags.TknType = TKT_VARIMMED;
(*lplpYYFcnStrLft)->tkToken.tkFlags.ImmType = lpMemDfnHdr->steLftOpr->stFlags.ImmType;
////////////////////(*lplpYYFcnStrLft)->tkToken.tkFlags.NoDisplay = // Filled in by YYAlloc
(*lplpYYFcnStrLft)->tkToken.tkData.tkLongest = lpMemDfnHdr->steLftOpr->stData.stLongest;
////////////////////(*lplpYYFcnStrLft)->tkToken.tkCharIndex = // Ignored
} else
{
// Fill in the result token
(*lplpYYFcnStrLft)->tkToken.tkFlags.TknType = TKT_VARNAMED;
////////////////////(*lplpYYFcnStrLft)->tkToken.tkFlags.ImmType = // Filled in by YYAlloc
////////////////////(*lplpYYFcnStrLft)->tkToken.tkFlags.NoDisplay = // Filled in by YYAlloc
(*lplpYYFcnStrLft)->tkToken.tkData.tkSym = lpMemDfnHdr->steLftOpr;
////////////////////(*lplpYYFcnStrLft)->tkToken.tkCharIndex = // Ignored
} // End IF/ELSE
break;
case NAMETYPE_FN12:
// If the fcn is immediate, ...
if (lpMemDfnHdr->steLftOpr->stFlags.Imm)
{
// Fill in the result token
(*lplpYYFcnStrLft)->tkToken.tkFlags.TknType = TKT_FCNIMMED;
(*lplpYYFcnStrLft)->tkToken.tkFlags.ImmType = lpMemDfnHdr->steLftOpr->stFlags.ImmType;
////////////////////(*lplpYYFcnStrLft)->tkToken.tkFlags.NoDisplay = // Filled in by YYAlloc
(*lplpYYFcnStrLft)->tkToken.tkData.tkLongest = lpMemDfnHdr->steLftOpr->stData.stLongest;
////////////////////(*lplpYYFcnStrLft)->tkToken.tkCharIndex = // Ignored
} else
{
// Fill in the result token
(*lplpYYFcnStrLft)->tkToken.tkFlags.TknType = TKT_FCNNAMED;
////////////////////(*lplpYYFcnStrLft)->tkToken.tkFlags.ImmType = // Filled in by YYAlloc
////////////////////(*lplpYYFcnStrLft)->tkToken.tkFlags.NoDisplay = // Filled in by YYAlloc
(*lplpYYFcnStrLft)->tkToken.tkData.tkSym = lpMemDfnHdr->steLftOpr;
////////////////////(*lplpYYFcnStrLft)->tkToken.tkCharIndex = // Ignored
} // End IF/ELSE
break;
case NAMETYPE_OP1:
// If the op1 is immediate, ...
if (lpMemDfnHdr->steLftOpr->stFlags.Imm)
{
// Fill in the result token
(*lplpYYFcnStrLft)->tkToken.tkFlags.TknType = TKT_OP1IMMED;
(*lplpYYFcnStrLft)->tkToken.tkFlags.ImmType = lpMemDfnHdr->steLftOpr->stFlags.ImmType;
////////////////////(*lplpYYFcnStrLft)->tkToken.tkFlags.NoDisplay = // Filled in by YYAlloc
(*lplpYYFcnStrLft)->tkToken.tkData.tkLongest = lpMemDfnHdr->steLftOpr->stData.stLongest;
////////////////////(*lplpYYFcnStrLft)->tkToken.tkCharIndex = // Ignored
} else
{
// Fill in the result token
(*lplpYYFcnStrLft)->tkToken.tkFlags.TknType = TKT_OP1NAMED;
////////////////////(*lplpYYFcnStrLft)->tkToken.tkFlags.ImmType = // Filled in by YYAlloc
////////////////////(*lplpYYFcnStrLft)->tkToken.tkFlags.NoDisplay = // Filled in by YYAlloc
(*lplpYYFcnStrLft)->tkToken.tkData.tkSym = lpMemDfnHdr->steLftOpr;
////////////////////(*lplpYYFcnStrLft)->tkToken.tkCharIndex = // Ignored
} // End IF/ELSE
break;
case NAMETYPE_OP2:
// If the op2 is immediate, ...
if (lpMemDfnHdr->steLftOpr->stFlags.Imm)
{
// Fill in the result token
(*lplpYYFcnStrLft)->tkToken.tkFlags.TknType = TKT_OP2IMMED;
(*lplpYYFcnStrLft)->tkToken.tkFlags.ImmType = lpMemDfnHdr->steLftOpr->stFlags.ImmType;
////////////////////(*lplpYYFcnStrLft)->tkToken.tkFlags.NoDisplay = // Filled in by YYAlloc
(*lplpYYFcnStrLft)->tkToken.tkData.tkLongest = lpMemDfnHdr->steLftOpr->stData.stLongest;
////////////////////(*lplpYYFcnStrLft)->tkToken.tkCharIndex = // Ignored
} else
{
// Fill in the result token
(*lplpYYFcnStrLft)->tkToken.tkFlags.TknType = TKT_OP2NAMED;
////////////////////(*lplpYYFcnStrLft)->tkToken.tkFlags.ImmType = // Filled in by YYAlloc
////////////////////(*lplpYYFcnStrLft)->tkToken.tkFlags.NoDisplay = // Filled in by YYAlloc
(*lplpYYFcnStrLft)->tkToken.tkData.tkSym = lpMemDfnHdr->steLftOpr;
////////////////////(*lplpYYFcnStrLft)->tkToken.tkCharIndex = // Ignored
} // End IF/ELSE
break;
defstop
break;
} // End SWITCH
// Set the token count
(*lplpYYFcnStrLft)->TknCount = 1;
} else
// Mark as unallocated
*lplpYYFcnStrLft = NULL;
// If there's a right operand, ...
if (lpMemDfnHdr->steRhtOpr NE NULL)
{
// Allocate a new YYRes for it
*lplpYYFcnStrRht = YYAlloc ();
// Split cases based upon the type of the right operand
switch (lpMemDfnHdr->steRhtOpr->stFlags.stNameType)
{
case NAMETYPE_UNK:
(*lplpYYFcnStrRht)->tkToken.tkFlags.TknType = TKT_FILLJOT;
////////////////(*lplpYYFcnStrRht)->tkToken.tkFlags.ImmType = IMMTYPE_ERROR; // Already zero from YYAlloc
////////////////(*lplpYYFcnStrRht)->tkToken.tkFlags.NoDisplay = FALSE; // Already zero from YYAlloc
(*lplpYYFcnStrRht)->tkToken.tkData.tkChar = UTF16_JOT;
////////////////(*lplpYYFcnStrRht)->tkToken.tkCharIndex = // Ignored
break;
case NAMETYPE_VAR:
// If the var is immediate, ...
if (lpMemDfnHdr->steRhtOpr->stFlags.Imm)
{
// Fill in the result token
(*lplpYYFcnStrRht)->tkToken.tkFlags.TknType = TKT_VARIMMED;
(*lplpYYFcnStrRht)->tkToken.tkFlags.ImmType = lpMemDfnHdr->steRhtOpr->stFlags.ImmType;
////////////////////(*lplpYYFcnStrRht)->tkToken.tkFlags.NoDisplay = // Filled in by YYAlloc
(*lplpYYFcnStrRht)->tkToken.tkData.tkLongest = lpMemDfnHdr->steRhtOpr->stData.stLongest;
////////////////////(*lplpYYFcnStrRht)->tkToken.tkCharIndex = // Ignored
} else
{
// Fill in the result token
(*lplpYYFcnStrRht)->tkToken.tkFlags.TknType = TKT_VARNAMED;
////////////////////(*lplpYYFcnStrRht)->tkToken.tkFlags.ImmType = // Filled in by YYAlloc
////////////////////(*lplpYYFcnStrRht)->tkToken.tkFlags.NoDisplay = // Filled in by YYAlloc
(*lplpYYFcnStrRht)->tkToken.tkData.tkSym = lpMemDfnHdr->steRhtOpr;
////////////////////(*lplpYYFcnStrRht)->tkToken.tkCharIndex = // Ignored
} // End IF/ELSE
break;
case NAMETYPE_FN12:
// If the fcn is immediate, ...
if (lpMemDfnHdr->steRhtOpr->stFlags.Imm)
{
// Fill in the result token
(*lplpYYFcnStrRht)->tkToken.tkFlags.TknType = TKT_FCNIMMED;
(*lplpYYFcnStrRht)->tkToken.tkFlags.ImmType = lpMemDfnHdr->steRhtOpr->stFlags.ImmType;
////////////////////(*lplpYYFcnStrRht)->tkToken.tkFlags.NoDisplay = // Filled in by YYAlloc
(*lplpYYFcnStrRht)->tkToken.tkData.tkLongest = lpMemDfnHdr->steRhtOpr->stData.stLongest;
////////////////////(*lplpYYFcnStrRht)->tkToken.tkCharIndex = // Ignored
} else
{
// Fill in the result token
(*lplpYYFcnStrRht)->tkToken.tkFlags.TknType = TKT_FCNNAMED;
////////////////////(*lplpYYFcnStrRht)->tkToken.tkFlags.ImmType = // Filled in by YYAlloc
////////////////////(*lplpYYFcnStrRht)->tkToken.tkFlags.NoDisplay = // Filled in by YYAlloc
(*lplpYYFcnStrRht)->tkToken.tkData.tkSym = lpMemDfnHdr->steRhtOpr;
////////////////////(*lplpYYFcnStrRht)->tkToken.tkCharIndex = // Ignored
} // End IF/ELSE
break;
case NAMETYPE_OP1:
// If the op1 is immediate, ...
if (lpMemDfnHdr->steRhtOpr->stFlags.Imm)
{
// Fill in the result token
(*lplpYYFcnStrRht)->tkToken.tkFlags.TknType = TKT_OP1IMMED;
(*lplpYYFcnStrRht)->tkToken.tkFlags.ImmType = lpMemDfnHdr->steRhtOpr->stFlags.ImmType;
////////////////////(*lplpYYFcnStrRht)->tkToken.tkFlags.NoDisplay = // Filled in by YYAlloc
(*lplpYYFcnStrRht)->tkToken.tkData.tkLongest = lpMemDfnHdr->steRhtOpr->stData.stLongest;
////////////////////(*lplpYYFcnStrRht)->tkToken.tkCharIndex = // Ignored
} else
{
// Fill in the result token
(*lplpYYFcnStrRht)->tkToken.tkFlags.TknType = TKT_OP1NAMED;
////////////////////(*lplpYYFcnStrRht)->tkToken.tkFlags.ImmType = // Filled in by YYAlloc
////////////////////(*lplpYYFcnStrRht)->tkToken.tkFlags.NoDisplay = // Filled in by YYAlloc
(*lplpYYFcnStrRht)->tkToken.tkData.tkSym = lpMemDfnHdr->steRhtOpr;
////////////////////(*lplpYYFcnStrRht)->tkToken.tkCharIndex = // Ignored
} // End IF/ELSE
break;
case NAMETYPE_OP2:
// If the op2 is immediate, ...
if (lpMemDfnHdr->steRhtOpr->stFlags.Imm)
{
// Fill in the result token
(*lplpYYFcnStrRht)->tkToken.tkFlags.TknType = TKT_OP2IMMED;
(*lplpYYFcnStrRht)->tkToken.tkFlags.ImmType = lpMemDfnHdr->steRhtOpr->stFlags.ImmType;
////////////////////(*lplpYYFcnStrRht)->tkToken.tkFlags.NoDisplay = // Filled in by YYAlloc
(*lplpYYFcnStrRht)->tkToken.tkData.tkLongest = lpMemDfnHdr->steRhtOpr->stData.stLongest;
////////////////////(*lplpYYFcnStrRht)->tkToken.tkCharIndex = // Ignored
} else
{
// Fill in the result token
(*lplpYYFcnStrRht)->tkToken.tkFlags.TknType = TKT_OP2NAMED;
////////////////////(*lplpYYFcnStrRht)->tkToken.tkFlags.ImmType = // Filled in by YYAlloc
////////////////////(*lplpYYFcnStrRht)->tkToken.tkFlags.NoDisplay = // Filled in by YYAlloc
(*lplpYYFcnStrRht)->tkToken.tkData.tkSym = lpMemDfnHdr->steRhtOpr;
////////////////////(*lplpYYFcnStrRht)->tkToken.tkCharIndex = // Ignored
} // End IF/ELSE
break;
defstop
break;
} // End SWITCH
// Set the token count
(*lplpYYFcnStrRht)->TknCount = 1;
} else
// Mark as unallocated
*lplpYYFcnStrRht = NULL;
// We no longer need this ptr
MyGlobalUnlock (hGlbFcn); lpMemDfnHdr = NULL;
} // End GetOperands
//***************************************************************************
// $ExecFcnGlb_EM_YY
//
// Execute a function in global memory
//***************************************************************************
#ifdef DEBUG
#define APPEND_NAME L" -- ExecFcnGlb_EM_YY"
#else
#define APPEND_NAME
#endif
LPPL_YYSTYPE ExecFcnGlb_EM_YY
(LPTOKEN lptkLftArg, // Ptr to left arg token (may be NULL if monadic)
HGLOBAL hGlbFcn, // Handle to function strand
LPTOKEN lptkRhtArg, // Ptr to right arg token
LPTOKEN lptkAxis) // Ptr to axis token (may be NULL)
{
LPFCNARRAY_HEADER lpMemHdrFcn = NULL; // Ptr to function array header
NAME_TYPES fnNameType; // Function array NAMETYPE
UINT tknNELM; // # tokens in the function array
LPPL_YYSTYPE lpYYFcnStr, // Ptr to function strand
lpYYRes; // Ptr to the result
LPTOKEN lptkAxis2; // Ptr to secondary axis token (may be NULL)
// Lock the memory to get a ptr to it
lpMemHdrFcn = MyGlobalLockFcn (hGlbFcn);
#define lpHeader lpMemHdrFcn
// Save the NAMETYPE_xxx and # tokens
fnNameType = lpHeader->fnNameType;
tknNELM = lpHeader->tknNELM;
#undef lpHeader
// Skip over the header to the data (PL_YYSTYPEs)
lpYYFcnStr = FcnArrayBaseToData (lpMemHdrFcn);
// Check for axis operator
lptkAxis2 = CheckAxisOper (lpYYFcnStr);
// If two axis tokens, that's an error
if (lptkAxis NE NULL && lptkAxis2 NE NULL)
goto AXIS_SYNTAX_EXIT;
else
// If the secondary only, use it
if (lptkAxis2 NE NULL)
lptkAxis = lptkAxis2;
// If it's a Train, ...
if (fnNameType EQ NAMETYPE_TRN)
{
if (lptkAxis NE NULL)
lpYYRes =
PrimFnSyntaxError_EM (&lpYYFcnStr->tkToken APPEND_NAME_ARG);
else
// Execute as Train, skipping over the monadic operator
lpYYRes =
ExecTrain_EM_YY (lptkLftArg, // Ptr to left arg token
&lpYYFcnStr[1], // Ptr to function strand
lptkRhtArg, // Ptr to right arg token
tknNELM - 1); // # elements in the train
} else
// The contents of the global memory object consist of
// a series of PL_YYSTYPEs in RPN order.
lpYYRes =
ExecFuncStr_EM_YY (lptkLftArg, // Ptr to left arg token
lpYYFcnStr, // Ptr to function strand
lptkRhtArg, // Ptr to right arg token
lptkAxis); // Ptr to axis token
// We no longer need this ptr
MyGlobalUnlock (hGlbFcn); lpMemHdrFcn = NULL;
// If the result is valid, ...
if (lpYYRes NE NULL
&& !IsTokenNoValue (&lpYYRes->tkToken))
// Change the SynObj
lpYYRes->tkToken.tkSynObj = soA;
return lpYYRes;
AXIS_SYNTAX_EXIT:
ErrorMessageIndirectToken (ERRMSG_SYNTAX_ERROR APPEND_NAME,
&lpYYFcnStr->tkToken);
return NULL;
} // End ExecFcnGlb_EM_YY
#undef APPEND_NAME
//***************************************************************************
// $ExecTrain_EM_YY
//
// Execute a Train
//***************************************************************************
#ifdef DEBUG
#define APPEND_NAME L" -- ExecTrain_EM_YY"
#else
#define APPEND_NAME
#endif
LPPL_YYSTYPE ExecTrain_EM_YY
(LPTOKEN lptkLftArg, // Ptr to left arg token (may be NULL if monadic)
LPPL_YYSTYPE lpYYFcnStr, // Ptr to function strand
LPTOKEN lptkRhtArg, // Ptr to right arg token
UINT tknNELM) // # elements in the Train
{
LPPL_YYSTYPE lpYYRes = NULL, // Ptr to the result
lpYYRes1 = NULL, // Ptr to temporary result #1
lpYYRes2 = NULL; // ... 2
// Note that the rightmost function is at the start of Train (lpYYFcnStr[0])
// and the leftmost function is at the end of the Train (lpYYFcnStr[tknNELM - 1]).
Assert (tknNELM > 1);
// Split cases based upon the # elements in the Train
switch (tknNELM)
{ // Monadic Dyadic
// (g h)R (A h)R L(g h)R L(A h)R
// -------------------------------------------------
////////case 2: // R g h R A L g h R
case 2: // g h R A g L h R A
// If the lefthand token (A or g) is an array, ...
if (IsTknTypeVar (lpYYFcnStr[1].tkToken.tkFlags.TknType))
{
// Allocate a new YYRes
lpYYRes = YYAlloc ();
// Copy the PL_YYSTYPE
YYCopy (lpYYRes, &lpYYFcnStr[1]);
// Increment the RefCnt
DbgIncrRefCntTkn (&lpYYRes->tkToken);
} else
{
// Execute the righthand function (h)
// between the (optional) left arg (L) and the right arg (R)
// to yield h R or L h R
lpYYRes1 = ExecFuncStr_EM_YY (lptkLftArg, // Ptr to left arg token
&lpYYFcnStr[0], // Ptr to function strand
lptkRhtArg, // Ptr to right arg token
NULL); // Ptr to axis token
if (lpYYRes1 NE NULL)
{
// Check for NoValue
if (IsTokenNoValue (&lpYYRes1->tkToken))
{
// Free the YYRes (but not the storage)
YYFree (lpYYRes1); lpYYRes1 = NULL;
goto VALUE_EXIT;
} // End IF
#ifdef DEBUG
// Decrement the SI level of lpYYRes1
// so YYResIsEmpty won't complain
lpYYRes1->SILevel--;
#endif
// If this derived function is monadic, ...
if (lptkLftArg EQ NULL)
lptkLftArg = lptkRhtArg;
// Execute the lefthand function (g)
// on the previous result
lpYYRes = ExecFuncStr_EM_YY (NULL, // Ptr to left arg token
&lpYYFcnStr[1], // Ptr to function strand
&lpYYRes1->tkToken, // Ptr to right arg token
NULL); // Ptr to axis token
#ifdef DEBUG
// Restore the SI level of lpYYRes1
lpYYRes1->SILevel++;
#endif
} // End IF
} // End IF/ELSE
break;
// Monadic Dyadic
// (f g h)R (A g h)R L(f g h)R L(A g h)R
// ---------------------------------------------------------
case 3: // (f R) g (h R) A g h R (L f R) g (L h R) A g L h R
// If the lefthand token (A or f) is an array, ...
if (IsTknTypeVar (lpYYFcnStr[2].tkToken.tkFlags.TknType))
{
// Execute the righthand function (h)
// between the (optional) left arg (L) and the right arg (R)
// to yield h R or L h R
lpYYRes1 = ExecFuncStr_EM_YY (lptkLftArg, // Ptr to left arg token
&lpYYFcnStr[0], // Ptr to function strand
lptkRhtArg, // Ptr to right arg token
NULL); // Ptr to axis token
if (lpYYRes1 NE NULL)
{
// Check for NoValue
if (IsTokenNoValue (&lpYYRes1->tkToken))
{
// Free the YYRes (but not the storage)
YYFree (lpYYRes1); lpYYRes1 = NULL;
goto VALUE_EXIT;
} // End IF
#ifdef DEBUG
// Decrement the SI level of lpYYRes1
// so YYResIsEmpty won't complain
lpYYRes1->SILevel--;
#endif
// Execute the lefthand function (g)
// between the array (A) and the previous result
// to yield A g h R or A g L h R
lpYYRes = ExecFuncStr_EM_YY (&lpYYFcnStr[2].tkToken, // Ptr to left arg token
&lpYYFcnStr[1], // Ptr to function strand
&lpYYRes1->tkToken, // Ptr to right arg token
NULL); // Ptr to axis token
#ifdef DEBUG
// Restore the SI level of lpYYRes1
lpYYRes1->SILevel++;
#endif
} // End IF
} else
{
// Execute the righthand function (h) between
// the (optional) left (L) and right (R) args
// to yield h R or L h R
lpYYRes1 = ExecFuncStr_EM_YY (lptkLftArg, // Ptr to left arg token
&lpYYFcnStr[0], // Ptr to function strand
lptkRhtArg, // Ptr to right arg token
NULL); // Ptr to axis token
if (lpYYRes1 NE NULL)
{
// Check for NoValue
if (IsTokenNoValue (&lpYYRes1->tkToken))
{
// Free the YYRes (but not the storage)
YYFree (lpYYRes1); lpYYRes1 = NULL;
goto VALUE_EXIT;
} // End IF
#ifdef DEBUG
// Decrement the SI level of lpYYRes1
// so YYResIsEmpty won't complain
lpYYRes1->SILevel--;
#endif
// Execute the lefthand function (f) between
// the (optional) left (L) and right (R) args
// to yield f R or L f R
lpYYRes2 = ExecFuncStr_EM_YY (lptkLftArg, // Ptr to left arg token
&lpYYFcnStr[2], // Ptr to function strand
lptkRhtArg, // Ptr to right arg token
NULL); // Ptr to axis token
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
#ifdef DEBUG
// Decrement the SI level of lpYYRes2
// so YYResIsEmpty won't complain
lpYYRes2->SILevel--;
#endif
// Execute the middle function (g) between
// the two previous results
// to yield (f R) g (h R) or (L f R) g (L h R)
lpYYRes = ExecFuncStr_EM_YY (&lpYYRes2->tkToken, // Ptr to left arg token
&lpYYFcnStr[1], // Ptr to function strand
&lpYYRes1->tkToken, // Ptr to right arg token
NULL); // Ptr to axis token