[r9544]: main / trunk / interpreter / execution / RexxActivation.cpp Maximize Restore History

Download this file

RexxActivation.cpp    4375 lines (3985 with data), 185.7 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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
/*----------------------------------------------------------------------------*/
/* */
/* Copyright (c) 1995, 2004 IBM Corporation. All rights reserved. */
/* Copyright (c) 2005-2009 Rexx Language Association. All rights reserved. */
/* */
/* This program and the accompanying materials are made available under */
/* the terms of the Common Public License v1.0 which accompanies this */
/* distribution. A copy is also available at the following address: */
/* http://www.oorexx.org/license.html */
/* */
/* Redistribution and use in source and binary forms, with or */
/* without modification, are permitted provided that the following */
/* conditions are met: */
/* */
/* Redistributions of source code must retain the above copyright */
/* notice, this list of conditions and the following disclaimer. */
/* Redistributions in binary form must reproduce the above copyright */
/* notice, this list of conditions and the following disclaimer in */
/* the documentation and/or other materials provided with the distribution. */
/* */
/* Neither the name of Rexx Language Association nor the names */
/* of its contributors may be used to endorse or promote products */
/* derived from this software without specific prior written permission. */
/* */
/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */
/* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */
/* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS */
/* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */
/* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
/* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */
/* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY */
/* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */
/* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
/* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
/* */
/*----------------------------------------------------------------------------*/
/******************************************************************************/
/* REXX Kernel */
/* */
/* Primitive Activation Class */
/* */
/* NOTE: activations are an execution time only object. They are never */
/* flattened or saved in the image, and hence will never be in old */
/* space. Because of this, activations "cheat" and do not use */
/* OrefSet to assign values to get better performance. Care must be */
/* used to maintain this situation. */
/* */
/******************************************************************************/
/******************************************************************************/
#include <ctype.h>
#include <string.h>
#include "RexxCore.h"
#include "StringClass.hpp"
#include "BufferClass.hpp"
#include "DirectoryClass.hpp"
#include "RexxVariableDictionary.hpp"
#include "RexxActivation.hpp"
#include "RexxActivity.hpp"
#include "MethodClass.hpp"
#include "MessageClass.hpp"
#include "RexxCode.hpp"
#include "SourceFile.hpp"
#include "RexxInstruction.hpp"
#include "CallInstruction.hpp"
#include "DoBlock.hpp"
#include "DoInstruction.hpp"
#include "ProtectedObject.hpp"
#include "ActivityManager.hpp"
#include "Interpreter.hpp"
#include "SystemInterpreter.hpp"
#include "RexxInternalApis.h"
#include "PackageManager.hpp"
#include "RexxCompoundTail.hpp"
#include "CommandHandler.hpp"
#include "ActivationFrame.hpp"
#include "StackFrameClass.hpp"
#include "InterpreterInstance.hpp"
#include "PackageClass.hpp"
/* max instructions without a yield */
#define MAX_INSTRUCTIONS 100
/* default template for a new */
/* activation. This must be changed */
/* whenever the settings definition */
/* changes */
static ActivationSettings activationSettingsTemplate;
// constants use for different activation settings
const size_t RexxActivation::trace_off = 0x00000000; /* trace nothing */
const size_t RexxActivation::trace_debug = 0x00000001; /* interactive trace mode flag */
const size_t RexxActivation::trace_all = 0x00000002; /* trace all instructions */
const size_t RexxActivation::trace_results = 0x00000004; /* trace all results */
const size_t RexxActivation::trace_intermediates = 0x00000008; /* trace all instructions */
const size_t RexxActivation::trace_commands = 0x00000010; /* trace all commands */
const size_t RexxActivation::trace_labels = 0x00000020; /* trace all labels */
const size_t RexxActivation::trace_errors = 0x00000040; /* trace all command errors */
const size_t RexxActivation::trace_failures = 0x00000080; /* trace all command failures */
const size_t RexxActivation::trace_suppress = 0x00000100; /* tracing is suppressed during skips*/
const size_t RexxActivation::trace_flags = 0x000001ff; /* all tracing flags */
// the default trace setting
const size_t RexxActivation::default_trace_flags = trace_failures;
// now the flag sets for different settings
const size_t RexxActivation::trace_all_flags = (trace_all | trace_labels | trace_commands);
const size_t RexxActivation::trace_results_flags = (trace_all | trace_labels | trace_results | trace_commands);
const size_t RexxActivation::trace_intermediates_flags = (trace_all | trace_labels | trace_results | trace_commands | trace_intermediates);
const size_t RexxActivation::single_step = 0x00000800; /* we are single stepping execution */
const size_t RexxActivation::single_step_nested = 0x00001000; /* this is a nested stepping */
const size_t RexxActivation::debug_prompt_issued = 0x00002000; /* debug prompt already issued */
const size_t RexxActivation::debug_bypass = 0x00004000; /* skip next debug pause */
const size_t RexxActivation::procedure_valid = 0x00008000; /* procedure instruction is valid */
const size_t RexxActivation::clause_boundary = 0x00010000; /* work required at clause boundary */
const size_t RexxActivation::halt_condition = 0x00020000; /* a HALT condition occurred */
const size_t RexxActivation::trace_on = 0x00040000; /* external trace condition occurred */
const size_t RexxActivation::source_traced = 0x00080000; /* source string has been traced */
const size_t RexxActivation::clause_exits = 0x00100000; /* need to call clause boundary exits*/
const size_t RexxActivation::external_yield = 0x00200000; /* activity wants us to yield */
const size_t RexxActivation::forwarded = 0x00400000; /* forward instruction active */
const size_t RexxActivation::reply_issued = 0x00800000; /* reply has already been issued */
const size_t RexxActivation::set_trace_on = 0x01000000; /* trace turned on externally */
const size_t RexxActivation::set_trace_off = 0x02000000; /* trace turned off externally */
const size_t RexxActivation::traps_copied = 0x04000000; /* copy of trap info has been made */
const size_t RexxActivation::return_status_set = 0x08000000; /* had our first host command */
const size_t RexxActivation::transfer_failed = 0x10000000; /* transfer of variable lock failure */
const size_t RexxActivation::elapsed_reset = 0x20000000; // The elapsed time stamp was reset via time('r')
const size_t RexxActivation::guarded_method = 0x40000000; // this is a guarded method
void * RexxActivation::operator new(size_t size)
/******************************************************************************/
/* Function: Create a new activation object */
/******************************************************************************/
{
/* Get new object */
return new_object(size, T_Activation);
}
/**
* Initialize an activation for direct caching in the activation
* cache. At this time, this is not an executable activation
*/
RexxActivation::RexxActivation()
{
this->setHasNoReferences(); // nothing referenced from this either
}
/**
* Initialize an activation for a method invocation.
*
* @param _activity The activity we're running under.
* @param _method The method being invoked.
* @param _code The code to execute.
*/
RexxActivation::RexxActivation(RexxActivity* _activity, RexxMethod * _method, RexxCode *_code)
{
this->clearObject(); /* start with a fresh object */
this->activity = _activity; /* save the activity pointer */
this->scope = _method->getScope(); // save the scope
this->code = _code; /* get the REXX method object */
this->executable = _method; // save this as the base executable
// save the source object reference also
this->sourceObject = _method->getSourceObject();
this->settings.intermediate_trace = false;
this->activation_context = METHODCALL; // the context is a method call
this->parent = OREF_NULL; // we don't have a parent stack frame when invoked as a method
this->execution_state = ACTIVE; /* we are now in active execution */
this->object_scope = SCOPE_RELEASED; /* scope not reserved yet */
/* create a new evaluation stack. This must be done before a */
/* local variable frame is created. */
this->setHasNoReferences(); /* during allocateStack.. */
/* a live marking can happen without */
/* a properly set up stack (::live() */
/* is called). Setting the NoRefBit */
/* when creating the stack avoids it.*/
_activity->allocateStackFrame(&this->stack, this->code->getMaxStackSize());
this->setHasReferences();
// get initial settings template
// NOTE: Anything that alters information in the settings must happen AFTER
// this point.
this->settings = activationSettingsTemplate;
// and override with the package-defined settings
this->settings.numericSettings.digits = sourceObject->getDigits();
this->settings.numericSettings.fuzz = sourceObject->getFuzz();
this->settings.numericSettings.form = sourceObject->getForm();
setTrace(sourceObject->getTraceSetting(), sourceObject->getTraceFlags());
if (_method->isGuarded()) // make sure we set the appropriate guarded state
{
setGuarded();
}
/* save the source also */
this->settings.parent_code = this->code;
/* allocate a frame for the local variables from activity stack */
settings.local_variables.init(this, code->getLocalVariableSize());
this->activity->allocateLocalVariableFrame(&settings.local_variables);
/* set the initial and initial */
/* alternate address settings */
this->settings.current_env = activity->getInstance()->getDefaultEnvironment();
this->settings.alternate_env = this->settings.current_env;
/* get initial random seed value */
this->random_seed = this->activity->getRandomSeed();
/* copy the source security manager */
this->settings.securityManager = this->code->getSecurityManager();
if (this->settings.securityManager == OREF_NULL)
{
this->settings.securityManager = activity->getInstanceSecurityManager();
}
// and the call type is METHOD
this->settings.calltype = OREF_METHODNAME;
}
/**
* Create a new Rexx activation for an internal level call.
* An internal level call is an internal call, a call trap,
* an Interpret statement, or a debug pause execution.
*
* @param _activity The current activity.
* @param _parent The parent activation.
* @param _code The code to be executed. For interpret and debug pauses, this
* is a new code object. For call activations, this is the
* parent code object.
* @param context The type of call being made.
*/
RexxActivation::RexxActivation(RexxActivity *_activity, RexxActivation *_parent, RexxCode *_code, int context)
{
this->clearObject(); /* start with a fresh object */
this->activity = _activity; /* save the activity pointer */
this->code = _code; /* get the REXX method object */
if (context == DEBUGPAUSE) /* actually a debug pause? */
{
this->debug_pause = true; /* set up for debugging intercepts */
context = INTERPRET; /* this is really an interpret */
}
this->activation_context = context; /* save the context */
this->settings.intermediate_trace = false;
// the sender is our parent activity
this->parent = _parent;
this->execution_state = ACTIVE; /* we are now in active execution */
this->object_scope = SCOPE_RELEASED; /* scope not reserved yet */
/* create a new evaluation stack. This must be done before a */
/* local variable frame is created. */
this->setHasNoReferences(); /* during allocateStack.. */
/* a live marking can happen without */
/* a properly set up stack (::live() */
/* is called). Setting the NoRefBit */
/* when creating the stack avoids it.*/
_activity->allocateStackFrame(&stack, code->getMaxStackSize());
this->setHasReferences();
/* inherit parents settings */
_parent->putSettings(this->settings);
// step the trace indentation level for this internal nesting
settings.traceindent++;
// the random seed is copied from the calling activity, this led
// to reproducable random sequences even though no specific seed was given!
// see feat. 900 for example program.
adjustRandomSeed();
if (context == INTERNALCALL) /* internal call? */
{
/* force a new copy of the traps */
/* table to be created whenever it */
/* is changed */
this->settings.flags &= ~traps_copied;
this->settings.flags &= ~reply_issued; /* this is a new activation that can use its own return */
/* invalidate the timestamp */
this->settings.timestamp.valid = false;
}
/* this is a nested call until we issue a procedure */
settings.local_variables.setNested();
// get the executable from the parent.
this->executable = _parent->getExecutable();
// for internal calls, this is the same source object as the parent
if (activation_context != INTERPRET)
{
// save the source object reference also
this->sourceObject = executable->getSourceObject();
}
else
{
// use the source object for the interpret so error tracebacks are correct.
this->sourceObject = code->getSourceObject();
}
}
/**
* Create a top-level activation of Rexx code. This will
* either a toplevel program or an external call.
*
* @param _activity The current thread we're running on.
* @param _routine The routine to invoke.
* @param _code The code object to be executed.
* @param calltype Type type of call being made (function or subroutine)
* @param env The default address environment
* @param context The type of call context.
*/
RexxActivation::RexxActivation(RexxActivity *_activity, RoutineClass *_routine, RexxCode *_code,
RexxString *calltype, RexxString *env, int context)
{
this->clearObject(); /* start with a fresh object */
this->activity = _activity; /* save the activity pointer */
this->code = _code; /* get the REXX method object */
this->executable = _routine; // save this as the base executable
// save the source object reference also
this->sourceObject = _routine->getSourceObject();
this->activation_context = context; /* save the context */
this->settings.intermediate_trace = false;
this->parent = OREF_NULL; // there's no parent for a top level call
this->execution_state = ACTIVE; /* we are now in active execution */
this->object_scope = SCOPE_RELEASED; /* scope not reserved yet */
/* create a new evaluation stack. This must be done before a */
/* local variable frame is created. */
this->setHasNoReferences(); /* during allocateStack.. */
/* a live marking can happen without */
/* a properly set up stack (::live() */
/* is called). Setting the NoRefBit */
/* when creating the stack avoids it.*/
_activity->allocateStackFrame(&stack, code->getMaxStackSize());
this->setHasReferences();
/* get initial settings template */
this->settings = activationSettingsTemplate;
// and override with the package-defined settings
this->settings.numericSettings.digits = sourceObject->getDigits();
this->settings.numericSettings.fuzz = sourceObject->getFuzz();
this->settings.numericSettings.form = sourceObject->getForm();
setTrace(sourceObject->getTraceSetting(), sourceObject->getTraceFlags());
/* save the source also */
this->settings.parent_code = this->code;
/* allocate a frame for the local variables from activity stack */
settings.local_variables.init(this, code->getLocalVariableSize());
this->activity->allocateLocalVariableFrame(&settings.local_variables);
/* set the initial and initial */
/* alternate address settings */
this->settings.current_env = activity->getInstance()->getDefaultEnvironment();
this->settings.alternate_env = this->settings.current_env;
/* get initial random seed value */
this->random_seed = this->activity->getRandomSeed();
// the random seed is copied from the calling activity, this led
// to reproducable random sequences even though no specific seed was given!
// see feat. 900 for example program.
adjustRandomSeed();
/* copy the source security manager */
this->settings.securityManager = this->code->getSecurityManager();
// but use the default if not set
if (this->settings.securityManager == OREF_NULL)
{
this->settings.securityManager = activity->getInstanceSecurityManager();
}
// if we have a default environment specified, apply the override.
if (env != OREF_NULL)
{
setDefaultAddress(env);
}
// set the call type
if (calltype != OREF_NULL)
{
this->settings.calltype = calltype;
}
}
RexxObject * RexxActivation::dispatch()
/******************************************************************************/
/* Function: Re-dispatch an activation after a REPLY */
/******************************************************************************/
{
ProtectedObject r;
/* go run this */
return this->run(receiver, settings.msgname, arglist, argcount, OREF_NULL, r);
}
RexxObject * RexxActivation::run(RexxObject *_receiver, RexxString *msgname, RexxObject **_arglist,
size_t _argcount, RexxInstruction * start, ProtectedObject &resultObj)
/******************************************************************************/
/* Function: Run a REXX method...this is it! This is the heart of the */
/* interpreter that makes the whole thing run! */
/******************************************************************************/
{
// add the frame to the execution stack
RexxActivationFrame frame(activity, this);
RexxActivity *oldActivity; /* old activity */
#ifndef FIXEDTIMERS /* currently disabled */
size_t instructionCount; /* instructions without yielding */
#endif
this->receiver = _receiver; /* save the message receiver */
// the "msgname" can also be the name of an external routine, the label
// name of an internal routine.
this->settings.msgname = msgname;
/* not a reply restart situation? */
if (this->execution_state != REPLIED)
{
/* exits possible? We don't use exits for methods in the image */
if (!this->code->isOldSpace() && this->activity->isClauseExitUsed())
{
/* check at the end of each clause */
this->settings.flags |= clause_boundary;
/* remember that we have sys exits */
this->settings.flags |= clause_exits;
}
this->arglist = _arglist; /* set the argument list */
this->argcount = _argcount;
/* first entry into here? */
if (this->isTopLevelCall())
{
/* save entry argument list for */
/* variable pool fetch private */
/* access */
settings.parent_arglist = arglist;
settings.parent_argcount = argcount;
this->code->install(this); /* do any required installations */
this->next = this->code->getFirstInstruction(); /* ask the method for the start point*/
this->current = this->next; /* set the current too (for errors) */
/* not an internal method? */
if (this->isProgramLevelCall())
{
/* run initialization exit */
activity->callInitializationExit(this);
activity->getInstance()->setupProgram(this); /* do any system specific setup */
}
else
{
/* guarded method? */
if (isGuarded())
{
/* get the object variables */
this->settings.object_variables = this->receiver->getObjectVariables(this->scope);
/* reserve the variable scope */
this->settings.object_variables->reserve(this->activity);
/* and remember for later */
this->object_scope = SCOPE_RESERVED;
}
/* initialize the this variable */
this->setLocalVariable(OREF_SELF, VARIABLE_SELF, this->receiver);
/* initialize the SUPER variable */
this->setLocalVariable(OREF_SUPER, VARIABLE_SUPER, this->receiver->superScope(this->scope));
}
}
else
{
if (start == OREF_NULL) /* no starting location given? */
{
this->next = this->code->getFirstInstruction(); /* ask the method for the start point*/
}
else
{
this->next = start; /* set that as the current */
}
this->current = this->next; /* set the current too (for errors) */
}
}
else
{ /* resuming after a reply */
/* need to reaquire the lock? */
if (this->settings.flags&transfer_failed)
{
/* re-lock the variable dictionary */
this->settings.object_variables->reserve(this->activity);
/* turn off the failure flag */
this->settings.flags &= ~transfer_failed;
}
}
/* internal call? */
if (this->isInternalCall())
{
start = this->next; /* get the starting point */
/* scan over the internal labels */
while (start != OREF_NULL && start->isType(KEYWORD_LABEL))
{
start = start->nextInstruction; /* step to the next one */
}
/* this a procedure instruction */
if (start != OREF_NULL && start->isType(KEYWORD_PROCEDURE))
{
/* flip on the procedure flag */
this->settings.flags |= procedure_valid;
}
}
this->execution_state = ACTIVE; /* we are now actively processing */
if (tracingAll() && isMethodOrRoutine())
{
traceEntry();
}
while (true) // loop until we get a terminating condition
{
try
{
RexxExpressionStack *localStack = &this->stack; /* load up the stack */
#ifndef FIXEDTIMERS /* currently disabled */
instructionCount = 0; /* no instructions yet */
#endif
RexxInstruction *nextInst = this->next; /* get the next instruction */
/* loop until we get a terminating */
while (nextInst != OREF_NULL)
{ /* condition */
#ifdef FIXEDTIMERS /* currently disabled (active on Win)*/
/* has time Slice expired? */
if (Interpreter::hasTimeSliceElapsed())
{
this->activity->relinquish(); /* yield control to the activity */
}
#else
/* need to give someone else a shot? */
if (++instructionCount > MAX_INSTRUCTIONS)
{
this->activity->relinquish(); /* yield control to the activity */
instructionCount = 0; /* reset to zero */
}
#endif
this->current = nextInst; /* set the next instruction */
this->next = nextInst->nextInstruction;/* prefetch the next clause */
nextInst->execute(this, localStack); /* execute the instruction */
localStack->clear(); /* Force the stack clear */
this->settings.timestamp.valid = false;
/* need to process inter-clause stuff*/
if (this->settings.flags&clause_boundary)
{
this->processClauseBoundary(); /* go do the clause boundary stuff */
}
nextInst = this->next; /* get the next instruction */
}
if (this->execution_state == ACTIVE) /* implicit exit? */
{
this->implicitExit(); /* treat this like an EXIT */
}
/* is this a return situation? */
if (this->execution_state == RETURNED)
{
this->termination(); /* do activation termination process */
if (this->isInterpret())
{
/* save the nested setting */
bool nested = this->parent->settings.local_variables.isNested();
/* propagate parent's settings back */
this->parent->getSettings(this->settings);
if (!nested)
{
/* if our calling variable context was not nested, we */
/* need to clear it. */
this->parent->settings.local_variables.clearNested();
}
/* merge any pending conditions */
this->parent->mergeTraps(this->condition_queue, this->handler_queue);
}
resultObj = this->result; /* save the result */
this->activity->popStackFrame(false); /* now pop the current activity */
/* now go run the uninit stuff */
memoryObject.checkUninitQueue();
}
else
{ /* execution_state is REPLIED */
resultObj = this->result; /* save the result */
/* reset the next instruction */
this->next = this->current->nextInstruction;
oldActivity = this->activity; /* save the current activity */
/* clone the current activity */
this->activity = oldActivity->spawnReply();
/* save the pointer to the start of our stack frame. We're */
/* going to need to release this after we migrate everything */
/* over. */
RexxObject **framePtr = localStack->getFrame();
/* migrate the local variables and the expression stack to the */
/* new activity. NOTE: these must be done in this order to */
/* get them allocated from the new activity in the correct */
/* order. */
localStack->migrate(this->activity);
settings.local_variables.migrate(this->activity);
/* if we have arguments, we need to migrate those also, as they are subject to overwriting once we return to the parent activation. */
if (argcount > 0)
{
RexxObject **newArguments = activity->allocateFrame(argcount);
memcpy(newArguments, arglist, sizeof(RexxObject *) * argcount);
this->arglist = newArguments; /* must be set on "this" */
settings.parent_arglist = newArguments;
}
/* return our stack frame space back to the old activity. */
oldActivity->releaseStackFrame(framePtr);
this->activity->pushStackFrame(this);/* push it on to the activity stack */
// pop the old one off of the stack frame (but without returning it to
// the activation cache)
oldActivity->popStackFrame(true); /* pop existing one off the stack */
/* is the scope reserved? */
if (this->object_scope == SCOPE_RESERVED)
{
/* transfer the reservation */
if (!this->settings.object_variables->transfer(this->activity))
{
/* remember the failure */
this->settings.flags |= transfer_failed;
}
}
this->activity->run(); /* continue running the new activity */
oldActivity->relinquish(); /* give other activity a chance to go*/
}
return resultObj; /* return the result object */
}
catch (RexxActivation *t)
{
// if we're not the target of this throw, we've already been unwound
// keep throwing this until it reaches the target activation.
if (t != this )
{
throw;
}
// unwind the activation stack back to our frame
activity->unwindToFrame(this);
this->stack.clear(); /* Force the stack clear */
/* invalidate the timestamp */
this->settings.timestamp.valid = false;
if (this->debug_pause)
{ /* in a debug pause? */
this->execution_state = RETURNED;/* cause termination */
this->next = OREF_NULL; /* turn off execution engine */
}
/* have pending conditions? */
if (this->condition_queue != OREF_NULL)
{
/* get the pending count */
this->pending_count = this->condition_queue->getSize();
}
if (this->pending_count != 0)
{ /* do we have trapped conditions? */
this->processTraps(); /* go dispatch the traps */
if (this->pending_count != 0) /* have deferred conditions? */
{
/* need to check each time around */
this->settings.flags |= clause_boundary;
}
}
}
}
}
void RexxActivation::processTraps()
/******************************************************************************/
/* Function: process pending condition traps before going on to execute a */
/* clause */
/******************************************************************************/
{
size_t i = this->pending_count; /* get the pending count */
while (i--) /* while pending conditions */
{
/* get the handler off the queue */
RexxArray *trapHandler = (RexxArray *)this->handler_queue->pullRexx();
/* condition in DELAY state? */
if ((RexxString *)this->trapState((RexxString *)trapHandler->get(3)) == OREF_DELAY)
{
/* add to the end of the queue */
this->handler_queue->addLast(trapHandler);
/* move condition object to the end */
this->condition_queue->addLast(this->condition_queue->pullRexx());
}
else
{
this->pending_count--; /* decrement the pending count */
/* get the current condition object */
RexxDirectory *conditionObj = (RexxDirectory *)this->condition_queue->pullRexx();
RexxObject *rc = conditionObj->at(OREF_RC); /* get any return code information */
if (rc != OREF_NULL) /* have something to assign to RC? */
{
/* initialize the RC variable */
this->setLocalVariable(OREF_RC, VARIABLE_RC, rc);
}
// it's possible that the condition can raise an error because of a
// missing label, so we need to catch any conditions that might be thrown
try
{
/* call the condition handler */
((RexxInstructionCallBase *)trapHandler->get(1))->trap(this, conditionObj);
}
catch (RexxActivation *t)
{
// if we're not the target of this throw, we've already been unwound
// keep throwing this until it reaches the target activation.
if (t != this )
{
throw;
}
}
}
}
}
void RexxActivation::debugSkip(
wholenumber_t skipcount, /* clauses to skip pausing */
bool notrace ) /* tracing suppression flag */
/******************************************************************************/
/* Function: Process a numeric "debug skip" TRACE instruction to suppress */
/* pauses or tracing for a given number of instructions. */
/******************************************************************************/
{
if (!this->debug_pause) /* not an allowed state? */
{
/* report the error */
reportException(Error_Invalid_trace_debug);
}
/* copy the execution count */
this->settings.trace_skip = skipcount;
/* set the skip flag */
if (notrace) /* turning suppression on? */
{
/* flip on the flag */
this->settings.flags |= trace_suppress;
}
else /* skipping pauses only */
{
this->settings.flags &= ~trace_suppress;
}
this->settings.flags |= debug_bypass;/* let debug prompt know of changes */
}
RexxString * RexxActivation::traceSetting()
/******************************************************************************/
/* Function: Generate a string form of the current trace setting */
/******************************************************************************/
{
// have the source file process this
return RexxSource::formatTraceSetting(settings.traceOption);
}
/**
* Set the trace using a dynamically evaluated string.
*
* @param setting The new trace setting.
*/
void RexxActivation::setTrace(RexxString *setting)
{
size_t newsetting; /* new trace setting */
size_t traceFlags; // the optimized trace flags
char traceOption = 0; // a potential bad character
if (!RexxSource::parseTraceSetting(setting, newsetting, traceFlags, traceOption))
{
reportException(Error_Invalid_trace_trace, new_string(&traceOption, 1));
}
/* now change the setting */
setTrace(newsetting, traceFlags);
}
/**
* Set a new trace setting for the context.
*
* @param traceOption
* The new trace setting option. This includes the
* setting option and any debug flag options, ANDed together.
*/
void RexxActivation::setTrace(size_t traceOption, size_t traceFlags)
{
/* turn off the trace suppression */
this->settings.flags &= ~trace_suppress;
this->settings.trace_skip = 0; /* and allow debug pauses */
// we might need to transfer some information from the
// current settings
if ((traceOption&RexxSource::DEBUG_TOGGLE) != 0)
{
// if nothing else was specified, this was a pure toggle
// operation, which maintains the existing settings
if (traceFlags == 0)
{
// pick up the existing flags
traceFlags = settings.flags&trace_flags;
traceOption = settings.traceOption;
}
/* switch to the opposite setting */
/* already on? */
if ((this->settings.flags&trace_debug) != 0)
{
/* switch the setting off */
traceFlags &= ~trace_debug;
traceOption &= ~RexxSource::DEBUG_ON;
// flipping out of debug mode. Reissue the debug prompt when
// turned back on again
this->settings.flags &= ~debug_prompt_issued;
}
else
{
// switch the setting on in both the flags and the setting
traceFlags |= trace_debug;
traceOption |= RexxSource::DEBUG_ON;
}
}
// are we in debug mode already? A trace setting with no "?" maintains the
// debug setting, unless it is Trace Off
else if ((settings.flags&trace_debug) != 0)
{
if (traceFlags == 0)
{
// flipping out of debug mode. Reissue the debug prompt when
// turned back on again
this->settings.flags &= ~debug_prompt_issued;
}
else
{
// add debug mode into the new settings if on
traceFlags |= trace_debug;
traceOption |= RexxSource::DEBUG_ON;
}
}
// save the option so it can be formatted back into a trace value
this->settings.traceOption = traceOption;
// clear the current trace options
clearTraceSettings();
// set the new flags
settings.flags |= traceFlags;
// if tracing intermediates, turn on the special fast check flag
if ((settings.flags&trace_intermediates) != 0)
{
/* turn on the special fast-path test */
this->settings.intermediate_trace = true;
}
if (this->debug_pause) /* issued from a debug prompt? */
{
/* let debug prompt know of changes */
this->settings.flags |= debug_bypass;
}
}
/**
* Process a trace setting and reduce it to the component
* flag settings that can be used to set defaults.
*
* @param traceSetting
* The input trace setting.
*
* @return The set of flags that will be set in the debug flags
* when trace setting change.
*/
size_t RexxActivation::processTraceSetting(size_t traceSetting)
{
size_t flags = 0;
switch (traceSetting & TRACE_DEBUG_MASK)
{
case RexxSource::DEBUG_ON: /* turn on interactive debug */
/* switch the setting on */
flags |= trace_debug;
break;
case RexxSource::DEBUG_OFF: /* turn off interactive debug */
/* switch the setting off */
flags &= ~trace_debug;
break;
// These two have no meaning in a staticically defined situation, so
// they'll need to be handled at runtime.
case RexxSource::DEBUG_TOGGLE: /* toggle interactive debug setting */
case RexxSource::DEBUG_IGNORE: /* no changes to debug setting */
break;
}
// now optimize the trace setting flags
switch (traceSetting&RexxSource::TRACE_SETTING_MASK)
{
case RexxSource::TRACE_ALL: /* TRACE ALL; */
/* trace instructions, labels and */
/* all commands */
flags |= (trace_all | trace_labels | trace_commands);
break;
case RexxSource::TRACE_COMMANDS: /* TRACE COMMANDS; */
flags |= trace_commands;
break;
case RexxSource::TRACE_LABELS: /* TRACE LABELS */
flags |= trace_labels;
break;
case RexxSource::TRACE_NORMAL: /* TRACE NORMAL */
case RexxSource::TRACE_FAILURES: /* TRACE FAILURES */
/* just trace command failures */
flags |= trace_failures;
break;
case RexxSource::TRACE_ERRORS: /* TRACE ERRORS */
/* trace command failures and error */
flags |= (trace_failures | trace_errors);
break;
case RexxSource::TRACE_RESULTS: /* TRACE RESULTS */
flags |= (trace_all | trace_labels | trace_results | trace_commands);
break;
case RexxSource::TRACE_INTERMEDIATES: /* TRACE INTERMEDIATES */
/* trace just about every things */
flags |= (trace_all | trace_labels | trace_results | trace_commands | trace_intermediates);
break;
case RexxSource::TRACE_OFF: /* TRACE OFF */
flags = trace_off; // turn of all trace options, including debug flags
break;
case RexxSource::TRACE_IGNORE: /* don't change trace setting */
break;
}
return flags;
}
void RexxActivation::live(size_t liveMark)
/******************************************************************************/
/* Function: Normal garbage collection live marking */
/******************************************************************************/
{
memory_mark(this->previous);
memory_mark(this->executable);
memory_mark(this->scope);
memory_mark(this->code);
memory_mark(this->settings.securityManager);
memory_mark(this->receiver);
memory_mark(this->activity);
memory_mark(this->parent);
memory_mark(this->dostack);
/* the stack and the local variables handle their own marking. */
this->stack.live(liveMark);
this->settings.local_variables.live(liveMark);
memory_mark(this->current);
memory_mark(this->next);
memory_mark(this->result);
memory_mark(this->trapinfo);
memory_mark(this->objnotify);
memory_mark(this->environmentList);
memory_mark(this->handler_queue);
memory_mark(this->condition_queue);
memory_mark(this->settings.traps);
memory_mark(this->settings.conditionObj);
memory_mark(this->settings.parent_code);
memory_mark(this->settings.current_env);
memory_mark(this->settings.alternate_env);
memory_mark(this->settings.msgname);
memory_mark(this->settings.object_variables);
memory_mark(this->settings.calltype);
memory_mark(this->settings.streams);
memory_mark(this->settings.halt_description);
memory_mark(this->contextObject);
/* We're hold a pointer back to our arguments directly where they */
/* are created. Since in some places, this argument list comes */
/* from the C stack, we need to handle the marker ourselves. */
size_t i;
for (i = 0; i < argcount; i++)
{
memory_mark(arglist[i]);
}
for (i = 0; i < settings.parent_argcount; i++)
{
memory_mark(settings.parent_arglist[i]);
}
}
void RexxActivation::liveGeneral(int reason)
/******************************************************************************/
/* Function: Generalized object marking */
/******************************************************************************/
{
memory_mark_general(this->previous);
memory_mark_general(this->executable);
memory_mark_general(this->code);
memory_mark_general(this->settings.securityManager);
memory_mark_general(this->receiver);
memory_mark_general(this->activity);
memory_mark_general(this->parent);
memory_mark_general(this->dostack);
/* the stack and the local variables handle their own marking. */
this->stack.liveGeneral(reason);
this->settings.local_variables.liveGeneral(reason);
memory_mark_general(this->current);
memory_mark_general(this->next);
memory_mark_general(this->result);
memory_mark_general(this->trapinfo);
memory_mark_general(this->objnotify);
memory_mark_general(this->environmentList);
memory_mark_general(this->handler_queue);
memory_mark_general(this->condition_queue);
memory_mark_general(this->settings.traps);
memory_mark_general(this->settings.conditionObj);
memory_mark_general(this->settings.parent_code);
memory_mark_general(this->settings.current_env);
memory_mark_general(this->settings.alternate_env);
memory_mark_general(this->settings.msgname);
memory_mark_general(this->settings.object_variables);
memory_mark_general(this->settings.calltype);
memory_mark_general(this->settings.streams);
memory_mark_general(this->settings.halt_description);
memory_mark_general(this->contextObject);
/* We're hold a pointer back to our arguments directly where they */
/* are created. Since in some places, this argument list comes */
/* from the C stack, we need to handle the marker ourselves. */
size_t i;
for (i = 0; i < argcount; i++)
{
memory_mark_general(arglist[i]);
}
for (i = 0; i < settings.parent_argcount; i++)
{
memory_mark_general(settings.parent_arglist[i]);
}
}
void RexxActivation::reply(
RexxObject * resultObj) /* returned REPLY result */
/******************************************************************************/
/* Function: Process a REXX REPLY instruction */
/******************************************************************************/
{
/* already had a reply issued? */
if (this->settings.flags&reply_issued)
{
/* flag this as an error */
reportException(Error_Execution_reply);
}
this->settings.flags |= reply_issued;/* turn on the replied flag */
/* change execution state to */
this->execution_state = REPLIED; /* terminate the main loop */
this->next = OREF_NULL; /* turn off execution engine */
this->result = resultObj; /* save the result value */
}
void RexxActivation::returnFrom(
RexxObject * resultObj) /* returned RETURN/EXIT result */
/******************************************************************************/
/* Function: process a REXX RETURN instruction */
/******************************************************************************/
{
/* already had a reply issued? */
if (this->settings.flags&reply_issued && resultObj != OREF_NULL)
{
/* flag this as an error */
reportException(Error_Execution_reply_return);
}
/* processing an Interpret */
if (this->isInterpret())
{
this->execution_state = RETURNED; /* this is a returned state */
this->next = OREF_NULL; /* turn off execution engine */
/* cause a return in the parent */
this->parent->returnFrom(resultObj); /* activity */
}
else
{
this->execution_state = RETURNED; /* the state is returned */
this->next = OREF_NULL; /* turn off execution engine */
this->result = resultObj; /* save the return result */
/* real program call? */
if (this->isProgramLevelCall())
{
/* run termination exit */
activity->callTerminationExit(this);
}
}
/* switch debug off to avoid debug */
/* pause after exit entered from an */
this->settings.flags &= ~trace_debug;/* interactive debug prompt */
this->settings.flags |= debug_bypass;/* let debug prompt know of changes */
}
void RexxActivation::iterate(
RexxString * name ) /* name specified on iterate */
/******************************************************************************/
/* Function: Process a REXX ITERATE instruction */
/******************************************************************************/
{
RexxDoBlock *doblock = this->topBlock(); /* get the first stack item */
while (doblock != OREF_NULL)
{ /* while still DO blocks to process */
RexxBlockInstruction *loop = doblock->getParent(); /* get the actual loop instruction */
if (name == OREF_NULL) // leaving the inner-most loop?
{
// we only recognize LOOP constructs for this.
if (loop->isLoop())
{
/* reset the indentation */
this->setIndent(doblock->getIndent());
((RexxInstructionDo *)loop)->reExecute(this, &this->stack, doblock);
return; /* we're finished */
}
}
// a named LEAVE can be either a labeled block or a loop.
else if (loop->isLabel(name))
{
if (!loop->isLoop())
{
reportException(Error_Invalid_leave_iterate_name, name);
}
/* reset the indentation */
this->setIndent(doblock->getIndent());
((RexxInstructionDo *)loop)->reExecute(this, &this->stack, doblock);
return; /* we're finished */
}
this->popBlock(); /* cause termination cleanup */
this->removeBlock(); /* remove the execution nest */
doblock = this->topBlock(); /* get the new stack top */
}
if (name != OREF_NULL) /* have a name? */
{
/* report exception with the name */
reportException(Error_Invalid_leave_iteratevar, name);
}
else
{
/* have a misplaced ITERATE */
reportException(Error_Invalid_leave_iterate);
}
}
void RexxActivation::leaveLoop(
RexxString * name ) /* name specified on leave */
/******************************************************************************/
/* Function: Process a REXX LEAVE instruction */
/******************************************************************************/
{
RexxDoBlock *doblock = this->topBlock(); /* get the first stack item */
while (doblock != OREF_NULL)
{ /* while still DO blocks to process */
RexxBlockInstruction *loop = doblock->getParent(); /* get the actual loop instruction */
if (name == OREF_NULL) // leaving the inner-most loop?
{
// we only recognize LOOP constructs for this.
if (loop->isLoop())
{
loop->terminate(this, doblock); /* terminate the loop */
return; /* we're finished */
}
}
// a named LEAVE can be either a labeled block or a loop.
else if (loop->isLabel(name))
{
loop->terminate(this, doblock); /* terminate the loop */
return; /* we're finished */
}
this->popBlock(); /* cause termination cleanup */
this->removeBlock(); /* remove the execution nest */
/* get the first stack item again */
doblock = this->topBlock(); /* get the new stack top */
}
if (name != OREF_NULL) /* have a name? */
{
/* report exception with the name */
reportException(Error_Invalid_leave_leavevar, name);
}
else
{
/* have a misplaced LEAVE */
reportException(Error_Invalid_leave_leave);
}
}
size_t RexxActivation::currentLine()
/******************************************************************************/
/* Function: Return the line number of the current instruction */
/******************************************************************************/
{
if (this->current != OREF_NULL) /* have a current line? */
{
return this->current->getLineNumber(); /* return the line number */
}
else
{
return 1; /* error on the loading */
}
}
void RexxActivation::procedureExpose(
RexxVariableBase **variables, size_t count)
/******************************************************************************/
/* Function: Expose variables for a PROCEDURE instruction */
/******************************************************************************/
{
/* procedure not allowed here? */
if (!(this->settings.flags&procedure_valid))
{
/* raise the appropriate error! */
reportException(Error_Unexpected_procedure_call);
}
/* disable further procedures */
this->settings.flags &= ~procedure_valid;
/* get a new */
activity->allocateLocalVariableFrame(&settings.local_variables);
/* make sure we clear out the dictionary, otherwise we'll see the */
/* dynamic entries from the previous level. */
settings.local_variables.procedure(this);
/* now expose each individual variable */
for (size_t i = 0; i < count; i++)
{
variables[i]->procedureExpose(this, parent, &stack);
}
}
void RexxActivation::expose(
RexxVariableBase **variables, size_t count)
/******************************************************************************/
/* Function: Expose variables for an EXPOSE instruction */
/******************************************************************************/
{
/* get the variable set for this object */
RexxVariableDictionary * object_variables = getObjectVariables();
/* now expose each individual variable */
for (size_t i = 0; i < count; i++)
{
variables[i]->expose(this, &stack, object_variables);
}
}
RexxObject *RexxActivation::forward(
RexxObject * target, /* target object */
RexxString * message, /* message to send */
RexxObject * superClass, /* class over ride */
RexxObject ** _arguments, /* message arguments */
size_t _argcount, /* count of message arguments */
bool continuing) /* return/continue flag */
/******************************************************************************/
/* Function: Process a REXX FORWARD instruction */
/******************************************************************************/
{
if (target == OREF_NULL) /* no target? */
{
target = this->receiver; /* use this */
}
if (message == OREF_NULL) /* no message override? */
{
message = this->settings.msgname; /* use same message name */
}
if (_arguments == OREF_NULL)
{ /* no arguments given? */
_arguments = this->arglist; /* use the same arguments */
_argcount = this->argcount;
}
if (continuing)
{ /* just processing the message? */
ProtectedObject r;
if (superClass == OREF_NULL) /* no override? */
{
/* issue the message and return */
target->messageSend(message, _arguments, _argcount, r);
}
else
{
/* issue the message with override */
target->messageSend(message, _arguments, _argcount, superClass, r);
}
return(RexxObject *)r;
}
else
{ /* got to shut down and issue */
this->settings.flags |= forwarded; /* we are now a phantom activation */
/* already had a reply issued? */
if (this->settings.flags&reply_issued && this->result != OREF_NULL)
{
/* flag this as an error */
reportException(Error_Execution_reply_exit);
}
this->execution_state = RETURNED; /* this is an EXIT for real */
this->next = OREF_NULL; /* turn off execution engine */
/* switch debug off to avoid debug */
/* pause after exit entered from an */
/* interactive debug prompt */
this->settings.flags &= ~trace_debug;
/* let debug prompt know of changes */
this->settings.flags |= debug_bypass;
ProtectedObject r;
if (superClass == OREF_NULL) /* no over ride? */
{
/* issue the simple message */
target->messageSend(message, _arguments, _argcount, r);
}
else
{
/* use the full override */
target->messageSend(message, _arguments, _argcount, superClass, r);
}
this->result = (RexxObject *)r; /* save the result value */
/* already had a reply issued? */
if (this->settings.flags&reply_issued && this->result != OREF_NULL)
{
/* flag this as an error */
reportException(Error_Execution_reply_exit);
}
this->termination(); /* run "program" termination method */
/* if there are stream objects */
return OREF_NULL; /* just return nothing */
}
}
void RexxActivation::exitFrom(
RexxObject * resultObj) /* EXIT result */
/******************************************************************************/
/* Function: Process a REXX exit instruction */
/******************************************************************************/
{
RexxActivation *activation; /* unwound activation */
this->execution_state = RETURNED; /* this is an EXIT for real */
this->next = OREF_NULL; /* turn off execution engine */
this->result = resultObj; /* save the result value */
/* switch debug off to avoid debug */
/* pause after exit entered from an */
this->settings.flags &= ~trace_debug;/* interactive debug prompt */
this->settings.flags |= debug_bypass;/* let debug prompt know of changes */
/* at a main program level? */
if (this->isTopLevelCall())
{
/* already had a reply issued? */
if (this->settings.flags&reply_issued && result != OREF_NULL)
{
/* flag this as an error */
reportException(Error_Execution_reply_exit);
}
/* real program call? */
if (this->isProgramLevelCall())
{
/* run termination exit */
activity->callTerminationExit(this);
}
}
else
{ /* internal routine or Interpret */
/* start terminating with this level */
activation = this;
do
{
activation->termination(); /* make sure this level cleans up */
ActivityManager::currentActivity->popStackFrame(false); /* pop this level off */
/* get the next level */
activation = ActivityManager::currentActivity->getCurrentRexxFrame();
} while (!activation->isTopLevel());
activation->exitFrom(resultObj); /* tell this level to terminate */
/* unwind and process the termination*/
throw activation; // throw this as an exception to start the unwinding
}
}
#if 0
void RexxActivation::implicitExit()
/******************************************************************************/
/* Function: Process a "fall of the end" exit condition */
/******************************************************************************/
{
/* at a main program level or completing an INTERPRET */
/* instruction? */
if (this->isTopLevelCall() || this->isInterpret())
{
/* real program call? */
if (this->isProgramLevelCall())
{
/* run termination exit */
this->activity->callTerminationExit(this);
}
this->execution_state = RETURNED;/* this is an EXIT for real */
return; /* we're finished here */
}
this->exitFrom(OREF_NULL); /* we've had a nested exit, we need to process this more fully */
}
#endif
void RexxActivation::termination()
/******************************************************************************/
/* Function: do any cleanup due to a program terminating. */
/******************************************************************************/
{
this->guardOff(); /* Remove any guards for this activatio*/
/* were there any SETLOCAL calls for */
/* this method? And are there any */
/* that didn't have a matching ENDLOC*/
if (this->environmentList != OREF_NULL && this->environmentList->getSize() != 0)
{
/* Yes, then restore the environment */
/* to the ist on added. */
SystemInterpreter::restoreEnvironment(((RexxBuffer *)this->environmentList->lastItem())->getData());
}
this->environmentList = OREF_NULL; /* Clear out the env list */
this->closeStreams(); /* close any open streams */
/* release the stack frame, which also releases the frame for the */
/* variable cache. */
this->activity->releaseStackFrame(stack.getFrame());
/* do the variable termination */
cleanupLocalVariables();
// deactivate the context object if we created one.
if (contextObject != OREF_NULL)
{
contextObject->detach();
}
}
void RexxActivation::checkTrapTable()
/******************************************************************************/
/* Function: Create/copy a trap table as needed */
/******************************************************************************/
{
/* no trap table created yet? */
if (this->settings.traps == OREF_NULL)
{
/* create the trap table */
this->settings.traps = new_directory();
}
/* have to copy the trap table for an*/
/* internal routine call? */
else if (this->isInternalCall() && !(this->settings.flags&traps_copied))
{
/* copy the table */
this->settings.traps = (RexxDirectory *)this->settings.traps->copy();
/* record that we've copied this */
this->settings.flags |= traps_copied;
}
}
void RexxActivation::trapOn(
RexxString * condition, /* condition name */
/* handler for this trap */
RexxInstructionCallBase * handler )
/******************************************************************************/
/* Function: Activate a condition trap */
/******************************************************************************/
{
this->checkTrapTable(); /* make sure we have a table */
/* add the trap to the table */
this->settings.traps->put(new_array((RexxObject *)handler, OREF_ON, condition), condition);
/* novalue condition or any? */
if (condition->strCompare(CHAR_NOVALUE) || condition->strCompare(CHAR_ANY))
{
/* tag the method dictionary */
this->settings.local_variables.setNovalueOn();
}
}
void RexxActivation::trapOff(
RexxString * condition) /* condition name */
/******************************************************************************/
/* Function: Disable a condition trap */
/******************************************************************************/
{
this->checkTrapTable(); /* make sure we have a table */
/* remove the trap */
this->settings.traps->remove(condition);
/* novalue condition? */
if (!this->isInternalCall() && condition->strCompare(CHAR_NOVALUE))
{
/* not also trapping ANY? */
if (this->settings.traps->at(OREF_ANY) == OREF_NULL)
{
/* tag the method dictionary */
this->settings.local_variables.setNovalueOff();
}
}
}
RexxActivation * RexxActivation::external()
/******************************************************************************/
/* Function: Return the top level external activation */
/******************************************************************************/
{
/* if an internal call or an */
/* interpret, we need to pass this */
/* along */
if (this->isInternalLevelCall())
{
return this->parent->external(); /* get our sender method */
}
else
{
return this; /* already at the top level */
}
}
void RexxActivation::raiseExit(
RexxString * condition, /* condition to raise */
RexxObject * rc, /* information assigned to RC */
RexxString * description, /* description of the condition */
RexxObject * additional, /* extra descriptive information */
RexxObject * resultObj, /* return result */
RexxDirectory * conditionobj ) /* propagated condition object */
/******************************************************************************/
/* Function: Raise a condition using exit semantics for the returned value. */
/******************************************************************************/
{
/* not internal routine or Interpret */
/* instruction activation? */
if (this->isTopLevelCall())
{
/* do the real condition raise */
this->raise(condition, rc, description, additional, resultObj, conditionobj);
return; /* return if processed */
}
/* reached the top level? */
if (this->parent == OREF_NULL)
{
this->exitFrom(resultObj); /* turn into an exit instruction */
}
else
{
/* real program call? */
if (this->isProgramLevelCall())
{
/* run termination exit */
activity->callTerminationExit(this);
}
ProtectedObject p(this);
this->termination(); /* remove guarded status on object */
this->activity->popStackFrame(false); /* pop ourselves off active list */
/* propogate the condition backward */
this->parent->raiseExit(condition, rc, description, additional, resultObj, conditionobj);
}
}
void RexxActivation::raise(
RexxString * condition, /* condition to raise */
RexxObject * rc, /* information assigned to RC */
RexxString * description, /* description of the condition */
RexxObject * additional, /* extra descriptive information */
RexxObject * resultObj, /* return result */
RexxDirectory * conditionobj ) /* propagated condition object */
/******************************************************************************/
/* Function: Raise a give REXX condition */
/******************************************************************************/
{
bool propagated; /* propagated syntax condition */
/* propagating an existing condition?*/
if (condition->strCompare(CHAR_PROPAGATE))
{
/* get the original condition name */
condition = (RexxString *)conditionobj->at(OREF_CONDITION);
propagated = true; /* this is propagated */
/* fill in the propagation status */
conditionobj->put(TheTrueObject, OREF_PROPAGATED);
if (resultObj == OREF_NULL) /* no result specified? */
{
resultObj = conditionobj->at(OREF_RESULT);
}
}
else
{ /* build a condition object */
conditionobj = new_directory(); /* get a new directory */
/* put in the condition name */
conditionobj->put(condition, OREF_CONDITION);
/* fill in default description */
conditionobj->put(OREF_NULLSTRING, OREF_DESCRIPTION);
/* fill in the propagation status */
conditionobj->put(TheFalseObject, OREF_PROPAGATED);
propagated = false; /* remember for later */
}
if (rc != OREF_NULL) /* have an RC value? */
{
conditionobj->put(rc, OREF_RC); /* add to the condition argument */
}
if (description != OREF_NULL) /* any description to add? */
{
conditionobj->put(description, OREF_DESCRIPTION);
}
if (additional != OREF_NULL) /* or additional information */
{
conditionobj->put(additional, OREF_ADDITIONAL);
}
if (resultObj != OREF_NULL) /* or a result object */
{
conditionobj->put(resultObj, OREF_RESULT);
}
/* fatal SYNTAX error? */
if (condition->strCompare(CHAR_SYNTAX))
{
ProtectedObject p(this);
if (propagated)
{ /* reraising a condition? */
this->termination(); /* do the termination cleanup on ourselves */
this->activity->popStackFrame(false); /* pop ourselves off active list */
/* go propagate the condition */
ActivityManager::currentActivity->reraiseException(conditionobj);
}
else
{
/* go raise the error */
ActivityManager::currentActivity->raiseException(((RexxInteger *)rc)->getValue(), description, (RexxArray *)additional, resultObj);
}
}
else
{ /* normal condition trapping */
/* get the sender object (if any) */
// find a predecessor Rexx activation
RexxActivation *_sender = this->senderActivation();
/* do we have a sender that is */
/* trapping this condition? */
/* do we have a sender? */
bool trapped = false;
if (_sender != OREF_NULL)
{
/* "tickle them" with this */
trapped = _sender->trap(condition, conditionobj);
}
/* is this an untrapped halt condition? Need to transform into a SYNTAX error */
if (!trapped && condition->strCompare(CHAR_HALT))
{
/* raise as a syntax error */
reportException(Error_Program_interrupted_condition, OREF_HALT);
}
this->returnFrom(resultObj); /* process the return part */
throw this; /* unwind and process the termination*/
}
}
RexxVariableDictionary * RexxActivation::getObjectVariables()
/******************************************************************************/
/* Function: Return the associated object variables vdict */
/******************************************************************************/
{
/* no retrieved yet? */
if (this->settings.object_variables == OREF_NULL)
{
/* get the object variables */
this->settings.object_variables = this->receiver->getObjectVariables(this->scope);
if (isGuarded()) /* guarded method? */
{
/* reserve the variable scope */
this->settings.object_variables->reserve(this->activity);
/* and remember for later */
this->object_scope = SCOPE_RESERVED;
}
}
/* return the vdict */
return this->settings.object_variables;
}
/**
* Resolve a stream name for a BIF call.
*
* @param name The name of the stream.
* @param stack The expression stack.
* @param input The input/output flag.
* @param fullName The returned full name of the stream.
* @param added A flag indicating we added this.
*
* @return The backing stream object for the name.
*/
RexxObject *RexxActivation::resolveStream(RexxString *name, bool input, RexxString **fullName, bool *added)
{
if (added != NULL)
{
*added = false; /* when caller requires stream table entry then initialize */
}
RexxDirectory *streamTable = getStreams(); /* get the current stream set */
if (fullName) /* fullName requested? */
{
*fullName = name; /* initialize to name */
}
/* if length of name is 0, then it's the same as omitted */
if (name == OREF_NULL || name->getLength() == 0) /* no name? */
{
if (input) /* input operation? */
{
/* get the default output stream */
return getLocalEnvironment(OREF_INPUT);
}
else
{
/* get the default output stream */
return getLocalEnvironment(OREF_OUTPUT);
}
}
/* standard input stream? */
else if (name->strCaselessCompare(CHAR_STDIN) || name->strCaselessCompare(CHAR_CSTDIN))
{
/* get the default output stream */
return getLocalEnvironment(OREF_INPUT);
}
/* standard output stream? */
else if (name->strCaselessCompare(CHAR_STDOUT) || name->strCaselessCompare(CHAR_CSTDOUT))
{
/* get the default output stream */
return getLocalEnvironment(OREF_OUTPUT);
}
/* standard error stream? */
else if (name->strCaselessCompare(CHAR_STDERR) || name->strCaselessCompare(CHAR_CSTDERR))
{
/* get the default output stream */
return getLocalEnvironment(OREF_ERRORNAME);
}
else
{
/* go get the qualified name */
RexxString *qualifiedName = SystemInterpreter::qualifyFileSystemName(name);
if (fullName) /* fullName requested? */
{
*fullName = qualifiedName; /* provide qualified name */
}
// protect from GC
ProtectedObject p(qualifiedName);
/* Note: stream name is pushed to the stack to be protected from GC; */
/* e.g. it is used by the caller to remove stream from stream table. */
/* The stack will be reset after the function was executed and the */
/* protection is released */
/* see if we've already opened this */
RexxObject *stream = streamTable->at(qualifiedName);
if (stream == OREF_NULL) /* not open */
{
SecurityManager *manager = getEffectiveSecurityManager();
stream = manager->checkStreamAccess(qualifiedName);
if (stream != OREF_NULL)
{
streamTable->put(stream, qualifiedName);
return stream; /* return the stream object */
}
/* get the stream class */
RexxObject *streamClass = TheEnvironment->at(OREF_STREAM);
/* create a new stream object */
stream = streamClass->sendMessage(OREF_NEW, name);
if (added) /* open the stream? begin */
{
/* add to the streams table */
streamTable->put(stream, qualifiedName);
*added = true; /* mark it as added to stream table */
}
}
return stream; /* return the stream object */
}
}
RexxDirectory *RexxActivation::getStreams()
/******************************************************************************/
/* Function: Return the associated object variables stream table */
/******************************************************************************/
{
/* not created yet? */
if (this->settings.streams == OREF_NULL)
{
/* first entry into here? */
if (this->isProgramOrMethod())
{
/* always use a new directory */
this->settings.streams = new_directory();
}
else
{
// get the caller frame. If it is not a Rexx one, then
// we use a fresh stream table
RexxActivationBase *callerFrame = getPreviousStackFrame();
if (callerFrame == OREF_NULL || !callerFrame->isRexxContext())
{
this->settings.streams = new_directory();
}
else
{
/* alway's use caller's for internal */
/* call, external call or interpret */
this->settings.streams = ((RexxActivation *)callerFrame)->getStreams();
}
}
}
return this->settings.streams; /* return the stream table */
}
void RexxActivation::signalTo(
RexxInstruction * target ) /* target instruction */
/******************************************************************************/
/* Function: Signal to a targer instruction */
/******************************************************************************/
{
/* internal routine or Interpret */
/* instruction activation? */
if (this->isInterpret())
{
this->execution_state = RETURNED; /* signal interpret termination */
this->next = OREF_NULL; /* turn off execution engine */
this->parent->signalTo(target); /* propogate the signal backward */
}
else
{
/* initialize the SIGL variable */
size_t lineNum = this->current->getLineNumber();/* get the instruction line number */
this->setLocalVariable(OREF_SIGL, VARIABLE_SIGL, new_integer(lineNum));
this->next = target; /* set the new target location */
this->dostack = OREF_NULL; /* clear the do loop stack */
this->blockNest = 0; /* no more active blocks */
this->settings.traceindent = 0; /* reset trace indentation */
}
}
void RexxActivation::toggleAddress()
/******************************************************************************/
/* Function: Toggle the address setting between the current and alternate */
/******************************************************************************/
{
RexxString *temp = this->settings.current_env; /* save the current environment */
/* make the alternate the current */
this->settings.current_env = this->settings.alternate_env;
this->settings.alternate_env = temp; /* old current is now the alternate */
}
void RexxActivation::setAddress(
RexxString * address ) /* new address environment */
/******************************************************************************/
/* Function: Set the new current address, moving the current one to the */
/* alternate address */
/******************************************************************************/
{
/* old current is now the alternate */
this->settings.alternate_env = this->settings.current_env;
this->settings.current_env = address;/* set new current environment */
}
void RexxActivation::setDefaultAddress(
RexxString * address ) /* new address environment */
/******************************************************************************/
/* Function: Set up a default address environment so that both the primary */
/* and the alternate address are the same value */
/******************************************************************************/
{
/* old current is the new one */
this->settings.alternate_env = address;
this->settings.current_env = address;/* set new current environment */
}
void RexxActivation::signalValue(
RexxString * name ) /* target label name */
/******************************************************************************/
/* Function: Signal to a computed label target */
/******************************************************************************/
{
RexxInstruction *target = OREF_NULL; /* no target yet */
RexxDirectory *labels = this->getLabels(); /* get the labels */
if (labels != OREF_NULL) /* have labels? */
{
/* look up label and go to normal */
/* signal processing */
target = (RexxInstruction *)labels->at(name);
}
if (target == OREF_NULL) /* unknown label? */
{
/* raise an error */
reportException(Error_Label_not_found_name, name);
}
this->signalTo(target); /* now switch to the label location */
}
void RexxActivation::guardOn()
/******************************************************************************/
/* Function: Turn on the activations guarded state */
/******************************************************************************/
{
/* currently in unguarded state? */
if (this->object_scope == SCOPE_RELEASED)
{
/* not retrieved yet? */
if (this->settings.object_variables == OREF_NULL)
{
/* get the object variables */
this->settings.object_variables = this->receiver->getObjectVariables(this->scope);
}
/* lock the variable dictionary */
this->settings.object_variables->reserve(this->activity);
/* set the state here also */
this->object_scope = SCOPE_RESERVED;
}
}
size_t RexxActivation::digits()
/******************************************************************************/
/* Function: Return the current digits setting */
/******************************************************************************/
{
return this->settings.numericSettings.digits;
}
size_t RexxActivation::fuzz()
/******************************************************************************/
/* Function: Return the current fuzz setting */
/******************************************************************************/
{
return this->settings.numericSettings.fuzz;
}
bool RexxActivation::form()
/******************************************************************************/
/* Function: Return the current FORM setting */
/******************************************************************************/
{
return this->settings.numericSettings.form;
}
/**
* Set the digits setting to the package-defined default
*/
void RexxActivation::setDigits()
{
setDigits(sourceObject->getDigits());
}
void RexxActivation::setDigits(size_t digitsVal)
/******************************************************************************/
/* Function: Set a new digits setting */
/******************************************************************************/
{
this->settings.numericSettings.digits = digitsVal;
}
/**
* Set the fuzz setting to the package-defined default
*/
void RexxActivation::setFuzz()
{
setFuzz(sourceObject->getFuzz());
}
void RexxActivation::setFuzz(size_t fuzzVal)
/******************************************************************************/
/* Function: Set a new FUZZ setting */
/******************************************************************************/
{
this->settings.numericSettings.fuzz = fuzzVal;
}
/**
* Set the form setting to the package-defined default
*/
void RexxActivation::setForm()
{
setForm(sourceObject->getForm());
}
void RexxActivation::setForm(bool formVal)
/******************************************************************************/
/* Function: Set the new current NUMERIC FORM setting */
/******************************************************************************/
{
this->settings.numericSettings.form = formVal;
}
/**
* Return the Rexx context this operates under. Depending on the
* context, this could be null.
*
* @return The parent Rexx context.
*/
RexxActivation *RexxActivation::getRexxContext()
{
return this; // I am my own grampa...I mean Rexx context.
}
/**
* Return the Rexx context this operates under. Depending on the
* context, this could be null.
*
* @return The parent Rexx context.
*/
RexxActivation *RexxActivation::findRexxContext()
{
return this; // I am my own grampa...I mean Rexx context.
}
/**
* Indicate whether this activation is a Rexx context or not.
*
* @return true if this is a Rexx context, false otherwise.
*/
bool RexxActivation::isRexxContext()
{
return true;
}
/**
* Get the numeric settings for the current context.
*
* @return The new numeric settings.
*/
NumericSettings *RexxActivation::getNumericSettings()
{
return &(this->settings.numericSettings);
}
/**
* Get the message receiver
*
* @return The message receiver. Returns OREF_NULL if this is not
* a message activation.
*/
RexxObject *RexxActivation::getReceiver()
{
if (this->isInterpret())
{
return parent->getReceiver();
}
return receiver;
}
RexxString * RexxActivation::trapState(
RexxString * condition) /* condition trapped */
/******************************************************************************/
/* Function: Return the current state for a trap as either ON, OFF, or DELAY */
/******************************************************************************/
{
RexxString *state = OREF_OFF; /* default to OFF state */
/* actually have any traps? */
if (this->settings.traps != OREF_NULL)
{
/* see if this trap is enabled */
RexxArray *traphandler = (RexxArray *)this->settings.traps->at(condition);
if (traphandler != OREF_NULL) /* have a trap for this? */
{
/* get the trap state */
state = (RexxString *)traphandler->get(2);
}
}
return state; /* return this state */
}
void RexxActivation::trapDelay(
RexxString * condition) /* condition trapped */
/******************************************************************************/
/* Function: Put a condition trap into the delay state. */
/******************************************************************************/
{
this->checkTrapTable(); /* make sure we've got the tables */
/* see if this one is enabled */
RexxArray *traphandler = (RexxArray *)this->settings.traps->at(condition);
if (traphandler != OREF_NULL) /* have a trap for this? */
{
traphandler->put(OREF_DELAY, 2); /* change the trap state */
}
}
void RexxActivation::trapUndelay(
RexxString * condition) /* condition trapped */
/******************************************************************************/
/* Function: Remove a trap from the DELAY state */
/******************************************************************************/
{
this->checkTrapTable(); /* make sure we've got the tables */
/* see if this one is enabled */
RexxArray *traphandler = (RexxArray *)this->settings.traps->at(condition);
if (traphandler != OREF_NULL) /* have a trap for this? */
{
traphandler->put(OREF_ON, 2); /* change the trap state */
}
}
bool RexxActivation::trap( /* trap a condition */
RexxString * condition, /* condition to process */
RexxDirectory * exception_object) /* associated condition object */
/******************************************************************************/
/* Function: Check the activation to see if this is trapping a condition. */
/* For SIGNAL traps, control goes back to the point of the trap */
/* via throw. For CALL ON traps, the condition is saved, and */
/* the method returns true to indicate the trap was handled. */
/******************************************************************************/
{
if (this->settings.flags&forwarded)
{/* in the act of forwarding? */
RexxActivationBase *activation = this->getPreviousStackFrame(); /* get the sender activation */
/* have a predecessor? */
while (activation != OREF_NULL && isOfClass(Activation, activation))
{
if (!activation->isForwarded()) /* non forwarded? */
{
/* pretend he is we */
return activation->trap(condition, exception_object);
}
activation = activation->getPreviousStackFrame(); /* step to the next one */
}
return false; /* not really here, can't handle */
}
/* do we need to notify a message */
/*obj? */
if (this->objnotify != OREF_NULL && condition->strCompare(CHAR_SYNTAX))
{
/* yes, send error message and */
/*condition object */
this->objnotify->error(exception_object);
}
bool handled = false; /* not handled yet */
RexxArray *traphandler = OREF_NULL; /* no traps to process yet */
if (this->debug_pause)
{ /* working from the debug prompt? */
/* non-terminal condition? */
if (!condition->strCompare(CHAR_SYNTAX))
{
return false; /* flag as not-handled */
}
/* go display the messages */
this->activity->displayDebug(exception_object);
throw this; /* unwind and process the trap */
}
/* no trap table yet? */
if (this->settings.traps == OREF_NULL)
{
return false; /* can't very well handle this! */
}
/* see if this one is enabled */
traphandler = (RexxArray *)this->settings.traps->at(condition);
if (traphandler == OREF_NULL)
{ /* not there? try for an ANY handler*/
/* get this from the same table */
traphandler = (RexxArray *)this->settings.traps->at(OREF_ANY);
if (traphandler != OREF_NULL)
{ /* have an any handler? */
/* get the handler info */
RexxInstructionCallBase *handler = (RexxInstructionCallBase *)traphandler->get(1);
/* condition not trappable with CALL?*/
if (handler->isType(KEYWORD_CALL) &&
(condition->strCompare(CHAR_SYNTAX) ||
condition->strCompare(CHAR_NOVALUE) ||
condition->strCompare(CHAR_LOSTDIGITS) ||
condition->strCompare(CHAR_NOMETHOD) ||
condition->strCompare(CHAR_NOSTRING)))
{
return false; /* not trapped */
}
}
}
/* if the condition is being trapped, do the CALL or SIGNAL */
if (traphandler != OREF_NULL)
{ /* have a trap for this? */
/* if this is a HALT */
if (condition->strCompare(CHAR_HALT))
{
/* call the sys exit to clear it */
this->activity->callHaltClearExit(this);
}
/* get the handler info */
RexxInstructionCallBase *handler = (RexxInstructionCallBase *)traphandler->get(1);
/* no condition queue yet? */
if (this->condition_queue == OREF_NULL)
{
/* create a pending queue */
this->condition_queue = new_queue();
/* and a handler queue */
this->handler_queue = new_queue();
}
RexxString *instruction = OREF_CALL;
if (handler->isType(KEYWORD_SIGNAL))
{
instruction = OREF_SIGNAL; /* this is trapped by a SIGNAL */
}
/* add the instruction trap info */
exception_object->put(instruction, OREF_INSTRUCTION);
/* create a new condition object and */
/* add the condition object to queue */
this->condition_queue->addLast(exception_object);
/* and the corresponding trap info */
this->handler_queue->addLast(traphandler);
this->pending_count++; /* bump pending condition count */
// clear this from the activity if we're trapping this here
activity->clearCurrentCondition();
/* is this a signal instruction */
/* no the non-returnable PROPAGATE? */
if (handler->isType(KEYWORD_SIGNAL))
{
/* not an Interpret instruction? */
if (!this->isInterpret())
{
throw this; /* unwind and process the trap */
}
else
{ /* unwind interpret activations */
/* merge the traps */
this->parent->mergeTraps(this->condition_queue, this->handler_queue);
this->parent->unwindTrap(this);/* go unwind this */
}
}
else
{
handled = true; /* tell caller we're processing later*/
/* tell clause boundary to process */
this->settings.flags |= clause_boundary;
}
}
return handled; /* let call know if we've handled */
}
/**
* Process a NOVALUE event for a variable.
*
* @param name The variable name triggering the event.
* @param variable The resolved variable object for the variable.
*
* @return A value for that variable.
*/
RexxObject *RexxActivation::handleNovalueEvent(RexxString *name, RexxObject *defaultValue, RexxVariable *variable)
{
RexxObject *value = this->novalueHandler(name);
// If the handler returns anything other than .nil, this is a
// value
if (value != TheNilObject)
{
return value;
}
// give any external novalue handler a chance at this
if (!activity->callNovalueExit(this, name, value))
{
// set this variable to the object found in the engine
variable->set(value);
return value;
}
// raise novalue?
if (novalueEnabled())
{
reportNovalue(name);
}
// the provided default value is the returned value
return defaultValue;
}
void RexxActivation::mergeTraps(
RexxQueue * source_condition_queue, /* previous condition queue */
RexxQueue * source_handler_queue ) /* current condition handlers queue */
/******************************************************************************/
/* Function: Merge a list of trapped conditions from an interpret into the */
/* parent activation's queues. */
/******************************************************************************/
{
if (source_condition_queue != OREF_NULL)
{
/* no condition queue yet? */
if (this->condition_queue == OREF_NULL)
{
/* just copy over */
this->condition_queue = source_condition_queue;
/* ...both queues */
this->handler_queue = source_handler_queue;
}
else
{
/* get the item count */
size_t items = source_condition_queue->getSize();
while (items--)
{
/* add to the end of the queue */
this->handler_queue->addLast(source_handler_queue->pullRexx());
/* move condition object to the end */
this->condition_queue->addLast(source_condition_queue->pullRexx());
}
}
/* reset the counter size */
this->pending_count = this->condition_queue->getSize();
}
}
void RexxActivation::unwindTrap(RexxActivation * child )
/******************************************************************************/
/* Function: Unwind a chain of interpret activations to process a SIGNAL ON */
/* or PROPAGATE condition trap. This ensures that the SIGNAL */
/* or PROPAGATE returns to the correct condition level */
/******************************************************************************/
{
/* still an interpret level? */
if (this->isInterpret())
{
/* merge the traps */
this->parent->mergeTraps(this->condition_queue, this->handler_queue);
this->parent->unwindTrap(child); /* unwind another level */
}
else /* reached the "parent" level */
{
/* pull back the settings */
child->putSettings(this->settings);
throw this; /* unwind and process the trap */
}
}
RexxActivation * RexxActivation::senderActivation()
/******************************************************************************/
/* Function: Retrieve the activation that activated this activation (whew) */
/******************************************************************************/
{
/* get the sender from the activity */
RexxActivationBase *_sender = this->getPreviousStackFrame();
/* spin down to non-native activation*/
while (_sender != OREF_NULL && isOfClass(NativeActivation, _sender))
{
_sender = _sender->getPreviousStackFrame();
}
return(RexxActivation *)_sender; /* return that activation */
}
void RexxActivation::interpret(RexxString * codestring)
/******************************************************************************/
/* Function: Translate and interpret a string of data as a piece of REXX */
/* code within the current program context. */
/******************************************************************************/
{
ActivityManager::currentActivity->checkStackSpace(); /* have enough stack space? */
/* translate the code */
RexxCode * newCode = this->code->interpret(codestring, this->current->getLineNumber());
/* create a new activation */
RexxActivation *newActivation = ActivityManager::newActivation(this->activity, this, newCode, INTERPRET);
this->activity->pushStackFrame(newActivation); /* push on the activity stack */
ProtectedObject r;
/* run the internal routine on the */
/* new activation */
newActivation->run(OREF_NULL, OREF_NULL, arglist, argcount, OREF_NULL, r);
}
void RexxActivation::debugInterpret( /* interpret interactive debug input */
RexxString * codestring) /* entered instruction */
/******************************************************************************/
/* Function: Interpret a string created for interactive debug */
/******************************************************************************/
{
this->debug_pause = true; /* now in debug pause */
try
{
/* translate the code */
RexxCode *newCode = this->code->interpret(codestring, this->current->getLineNumber());
/* create a new activation */
RexxActivation *newActivation = ActivityManager::newActivation(this->activity, this, newCode, DEBUGPAUSE);
this->activity->pushStackFrame(newActivation); /* push on the activity stack */
ProtectedObject r;
/* run the internal routine on the */
/* new activation */
newActivation->run(receiver, settings.msgname, arglist, argcount, OREF_NULL, r);
// turn this off when done executing
this->debug_pause = false;
}
catch (RexxActivation *t)
{
// turn this off unconditionally for any errors
// if we're not the target of this throw, we've already been unwound
// keep throwing this until it reaches the target activation.
if (t != this )
{
throw;
}
}
}
RexxObject * RexxActivation::rexxVariable( /* retrieve a program entry */
RexxString * name ) /* target program entry name */
/******************************************************************************/
/* Function: Retrieve a REXX defined "dot" environment variable */
/******************************************************************************/
{
if (name->strCompare(CHAR_METHODS)) /* is this ".methods" */
{
/* get the methods directory */
return(RexxObject *)this->settings.parent_code->getMethods();
}
else if (name->strCompare(CHAR_ROUTINES)) /* is this ".routines" */
{
/* get the methods directory */
return(RexxObject *)this->settings.parent_code->getRoutines();
}
else if (name->strCompare(CHAR_RS)) /* command return status (".rs")? */
{
if (this->settings.flags&return_status_set)
{
/* returned as an integer object */
return new_integer(this->settings.return_status);
}
else /* just return the name */
{
return name->concatToCstring(".");
}
}
else if (name->strCompare(CHAR_LINE)) /* current line (".line")? */
{
// if this is an interpret, we need to report the line number of
// the context that calls the interpret.
if (this->isInterpret())
{
return parent->rexxVariable(name);
}
else
{
return new_integer(this->current->getLineNumber());
}
}
else if (name->strCompare(CHAR_CONTEXT)) /* current execution context (".context")? */
{
// if this is an interpret, we need to report the line number of
// the context that calls the interpret.
if (this->isInterpret())
{
return parent->rexxVariable(name);
}
else
{
// retrieve the context object (potentially creating it on the first request)
return getContextObject();
}
}
return OREF_NULL; // not recognized
}
/**
* Get the context object for this activation.
*
* @return The created context object.
*/
RexxObject *RexxActivation::getContextObject()
{
// the context object is created on demand...much of the time, this
// is not needed for an actvation
if (contextObject == OREF_NULL)
{
contextObject = new RexxContext(this);
}
return contextObject;
}
/**
* Return the line context information for a context.
*
* @return The current execution line.
*/
RexxObject *RexxActivation::getContextLine()
{
// if this is an interpret, we need to report the line number of
// the context that calls the interpret.
if (this->isInterpret())
{
return parent->getContextLine();
}
else
{
return new_integer(this->current->getLineNumber());
}
}
/**
* Return the line context information for a context.
*
* @return The current execution line.
*/
size_t RexxActivation::getContextLineNumber()
{
// if this is an interpret, we need to report the line number of
// the context that calls the interpret.
if (this->isInterpret())
{
return parent->getContextLineNumber();
}
else
{
return this->current->getLineNumber();
}
}
/**
* Return the RS context information for a activation.
*
* @return The current execution line.
*/
RexxObject *RexxActivation::getContextReturnStatus()
{
if (this->settings.flags&return_status_set)
{
/* returned as an integer object */
return new_integer(this->settings.return_status);
}
else
{
return TheNilObject;
}
}
/**
* Attempt to call a function stored in the macrospace.
*
* @param target The target function name.
* @param arguments The argument pointer.
* @param argcount The count of arguments,
* @param calltype The type of call (FUNCTION or SUBROUTINE)
* @param order The macrospace order flag.
* @param result The function result.
*
* @return true if the macrospace function was located and called.
*/
bool RexxActivation::callMacroSpaceFunction(RexxString * target, RexxObject **_arguments,
size_t _argcount, RexxString * calltype, int order, ProtectedObject &_result)
{
unsigned short position; /* located macro search position */
const char *macroName = target->getStringData(); /* point to the string data */
/* did we find this one? */
if (RexxQueryMacro(macroName, &position) == 0)
{
/* but not at the right time? */
if (order == MS_PREORDER && position == RXMACRO_SEARCH_AFTER)
{
return false; /* didn't really find this */
}
/* unflatten the method now */
RoutineClass *routine = getMacroCode(target);
// not restoreable is a call failure
if (routine == OREF_NULL)
{
return false;
}
/* run as a call */
routine->call(activity, target, _arguments, _argcount, calltype, OREF_NULL, EXTERNALCALL, _result);
// merge (class) definitions from macro with current settings
getSourceObject()->mergeRequired(routine->getSourceObject());
return true; /* return success we found it flag */
}
return false; /* nope, nothing to find here */
}
/**
* Main method for performing an external routine call. This
* orchestrates the search order for locating an external routine.
*
* @param target The target function name.
* @param _argcount The count of arguments for the call.
* @param _stack The expression stack holding the arguments.
* @param calltype The type of call (FUNCTION or SUBROUTINE)
* @param resultObj The returned result.
*
* @return The function result (also returned in the resultObj protected
* object reference.
*/
RexxObject *RexxActivation::externalCall(RexxString *target, size_t _argcount, RexxExpressionStack *_stack,
RexxString *calltype, ProtectedObject &resultObj)
{
/* get the arguments array */
RexxObject **_arguments = _stack->arguments(_argcount);
// Step 1: Check the global functions directory
// this is actually considered part of the built-in functions, but these are
// written in ooRexx. The names are also case sensitive
RoutineClass *routine = (RoutineClass *)TheFunctionsDirectory->get(target);
if (routine != OREF_NULL) /* not found yet? */
{
// call and return the result
routine->call(this->activity, target, _arguments, _argcount, calltype, OREF_NULL, EXTERNALCALL, resultObj);
return(RexxObject *)resultObj;
}
// Step 2: Check for a ::ROUTINE definition in the local context
routine = this->settings.parent_code->findRoutine(target);
if (routine != OREF_NULL)
{
// call and return the result
routine->call(this->activity, target, _arguments, _argcount, calltype, OREF_NULL, EXTERNALCALL, resultObj);
return(RexxObject *)resultObj;
}
// Step 2a: See if the function call exit fields this one
if (!activity->callObjectFunctionExit(this, target, calltype, resultObj, _arguments, _argcount))
{
return(RexxObject *)resultObj;
}
// Step 2b: See if the function call exit fields this one
if (!activity->callFunctionExit(this, target, calltype, resultObj, _arguments, _argcount))
{
return(RexxObject *)resultObj;
}
// Step 3: Perform all platform-specific searches
if (SystemInterpreter::invokeExternalFunction(this, this->activity, target, _arguments, _argcount, calltype, resultObj))
{
return(RexxObject *)resultObj;
}
// Step 4: Check scripting exit, which is after most of the checks
if (!activity->callScriptingExit(this, target, calltype, resultObj, _arguments, _argcount))
{
return(RexxObject *)resultObj;
}
// if it's made it through all of these steps without finding anything, we
// finally have a routine non found situation
reportException(Error_Routine_not_found_name, target);
return OREF_NULL; // prevent compile error
}
/**
* Call an external program as a function or subroutine.
*
* @param target The target function name.
* @param parent The name of the parent program (used for resolving extensions).
* @param _arguments The arguments to the call.
* @param _argcount The count of arguments for the call.
* @param calltype The type of call (FUNCTION or SUBROUTINE)
* @param resultObj The returned result.
*
* @return True if an external program was located and called. false for
* any failures.
*/
bool RexxActivation::callExternalRexx(
RexxString * target, /* Name of external function */
RexxObject ** _arguments, /* Argument array */
size_t _argcount, /* number of arguments in the call */
RexxString * calltype, /* Type of call */
ProtectedObject &resultObj) /* Result of function call */
/******************************************************************************/
/* Function: Call a rexx protram as an external routine */
/******************************************************************************/
{
/* Get full name including path */
RexxString *filename = resolveProgramName(target);
if (filename != OREF_NULL) /* found something? */
{
this->stack.push(filename); /* protect the file name here */
// try for a saved program or translate anew.
RoutineClass *routine = RoutineClass::fromFile(filename);
this->stack.pop(); /* remove the protected name */
if (routine == OREF_NULL) /* Do we have a method??? */
{
return false; /* No, return not found */
}
else /* Try to run method */
{
ProtectedObject p(routine);
/* run as a call */
routine->call(this->activity, target, _arguments, _argcount, calltype, this->settings.current_env, EXTERNALCALL, resultObj);
/* now merge all of the public info */
this->settings.parent_code->mergeRequired(routine->getSourceObject());
return true; /* Return routine found flag */
}
}
else
{
return false; /* this wasn't found */
}
}
/**
* Retrieve a macro image file from the macro space.
*
* @param macroName The name of the macro to retrieve.
*
* @return If available, the unflattened method image.
*/
RoutineClass *RexxActivation::getMacroCode(RexxString *macroName)
{
RXSTRING macroImage;
RoutineClass * macroRoutine = OREF_NULL;
macroImage.strptr = NULL;
const char *name = macroName->getStringData();
int rc;
{
UnsafeBlock releaser;
rc = RexxResolveMacroFunction(name, &macroImage);
}
if (rc == 0)
{
macroRoutine = RoutineClass::restore(&macroImage, macroName);
// return the allocated buffer
if (macroImage.strptr != NULL)
{
SystemInterpreter::releaseResultMemory(macroImage.strptr);
}
}
return macroRoutine;
}
/**
* This is resolved in the context of the calling program.
*
* @param name The name to resolve.
*
* @return The fully resolved program name, or OREF_NULL if this can't be
* located.
*/
RexxString *RexxActivation::resolveProgramName(RexxString *name)
{
return code->resolveProgramName(activity, name);
}
/**
* Resolve a class in this activation's context.
*
* @param name The name to resolve.
*
* @return The resolved class, or OREF_NULL if not found.
*/
RexxClass *RexxActivation::findClass(RexxString *name)
{
RexxClass *classObject = getSourceObject()->findClass(name);
// we need to filter this to always return a class object
if (classObject != OREF_NULL && classObject->isInstanceOf(TheClassClass))
{
return classObject;
}
return OREF_NULL;
}
/**
* Resolve a class in this activation's context.
*
* @param name The name to resolve.
*
* @return The resolved class, or OREF_NULL if not found.
*/
RexxObject *RexxActivation::resolveDotVariable(RexxString *name)
{
// if not an interpret, then resolve directly.
if (activation_context != INTERPRET)
{
return getSourceObject()->findClass(name);
}
else
{
// otherwise, send this up the call chain and resolve in the
// original source context
return parent->resolveDotVariable(name);
}
}
/**
* Load a ::REQUIRES directive when the source file is first
* invoked.
*
* @param target The name of the ::REQUIRES
* @param instruction
* The directive instruction being processed.
*/
PackageClass *RexxActivation::loadRequires(RexxString *target, RexxInstruction *instruction)
{
// this will cause the correct location to be used for error reporting
this->current = instruction;
// the loading/merging is done by the source object
return getSourceObject()->loadRequires(activity, target);
}
/**
* Load a package defined by a ::REQUIRES name LIBRARY
* directive.
*
* @param target The name of the package.
* @param instruction
* The ::REQUIRES directive being loaded.
*/
void RexxActivation::loadLibrary(RexxString *target, RexxInstruction *instruction)
{
// this will cause the correct location to be used for error reporting
this->current = instruction;
// have the package manager resolve the package
PackageManager::getLibrary(target);
}
/**
* Process an internal function or subroutine call.
*
* @param name The name of the target label.
* @param target The target instruction where we start executing (this is the label)
* @param _argcount The count of arguments
* @param _stack The context stack holding the arguments
* @param returnObject
* A holder for the return value
*
* @return The return value object
*/
RexxObject * RexxActivation::internalCall(RexxString *name, RexxInstruction *target,
size_t _argcount, RexxExpressionStack *_stack, ProtectedObject &returnObject)
{
RexxActivation * newActivation; /* new activation for call */
size_t lineNum; /* line number of the call */
RexxObject ** _arguments = _stack->arguments(_argcount);
lineNum = this->current->getLineNumber(); /* get the current line number */
/* initialize the SIGL variable */
this->setLocalVariable(OREF_SIGL, VARIABLE_SIGL, new_integer(lineNum));
/* create a new activation */
newActivation = ActivityManager::newActivation(this->activity, this, this->settings.parent_code, INTERNALCALL);
this->activity->pushStackFrame(newActivation); /* push on the activity stack */
/* run the internal routine on the */
/* new activation */
return newActivation->run(receiver, name, _arguments, _argcount, target, returnObject);
}
/**
* Processing a call to an internal trap subroutine.
*
* @param name The label name of the internal call.
* @param target The target instruction for the call (the label)
* @param conditionObj
* The associated condition object
* @param resultObj A holder for a result object
*
* @return Any return result
*/
RexxObject * RexxActivation::internalCallTrap(RexxString *name, RexxInstruction * target,
RexxDirectory *conditionObj, ProtectedObject &resultObj)
{
this->stack.push(conditionObj); /* protect the condition object */
size_t lineNum = this->current->getLineNumber(); /* get the current line number */
/* initialize the SIGL variable */
this->setLocalVariable(OREF_SIGL, VARIABLE_SIGL, new_integer(lineNum));
/* create a new activation */
RexxActivation *newActivation = ActivityManager::newActivation(this->activity, this, this->settings.parent_code, INTERNALCALL);
/* set the new condition object */
newActivation->setConditionObj(conditionObj);
this->activity->pushStackFrame(newActivation); /* push on the activity stack */
/* run the internal routine on the */
/* new activation */
return newActivation->run(OREF_NULL, name, NULL, 0, target, resultObj);
}
void RexxActivation::guardWait()
/******************************************************************************/
/* Function: Wait for a variable in a guard expression to get updated. */
/******************************************************************************/
{
int initial_state = this->object_scope; /* save the initial state */
/* have the scope reserved? */
if (this->object_scope == SCOPE_RESERVED)
{
/* tell the receiver to release this */
this->settings.object_variables->release(this->activity);
/* and change our local state */
this->object_scope = SCOPE_RELEASED; /* do an assignment! */
}
this->activity->guardWait(); /* wait on a variable inform event */
/* did we release the scope? */
if (initial_state == SCOPE_RESERVED)
{
/* tell the receiver to reserve this */
this->settings.object_variables->reserve(this->activity);
/* and change our local state */
this->object_scope = SCOPE_RESERVED; /* do an assignment! */
}
}
/**
* Get a traceback line for the current instruction.
*
* @return The formatted string traceback.
*/
RexxString *RexxActivation::getTraceBack()
{
return formatTrace(this->current, getSourceObject());
}
RexxDateTime RexxActivation::getTime()
/******************************************************************************/
/* Function: Retrieve the current activation timestamp, retrieving a new */
/* timestamp if this is the first call for a clause */
/******************************************************************************/
{
/* not a valid time stamp? */
if (!this->settings.timestamp.valid)
{
// IMPORTANT: If a time call resets the elapsed time clock, we don't
// clear the value out. The time needs to stay valid until the clause is
// complete. The time stamp value that needs to be used for the next
// elapsed time call is the timstamp that was valid at the point of the
// last call, which is our current old invalid one. So, we need to grab
// that value and set the elapsed time start point, then clear the flag
// so that it will remain current.
if (isElapsedTimerReset())
{
this->settings.elapsed_time = settings.timestamp.getUTCBaseTime();
setElapsedTimerValid();
}
/* get a fresh time stamp */
SystemInterpreter::getCurrentTime(&this->settings.timestamp);
/* got a new one */
this->settings.timestamp.valid = true;
}
/* return the current time */
return this->settings.timestamp;
}
int64_t RexxActivation::getElapsed()
/******************************************************************************/
/* Function: Retrieve the current elapsed time counter start time, starting */
/* the counter from the current time stamp if this is the first */
/* call */
/******************************************************************************/
{
// no active elapsed time clock yet?
if (this->settings.elapsed_time == 0)
{
settings.elapsed_time = settings.timestamp.getUTCBaseTime();
}
return settings.elapsed_time;
}
void RexxActivation::resetElapsed() /* reset activation elapsed time */
/******************************************************************************/
/* Function: Retrieve the current elapsed time counter start time, starting */
/* the counter from the current time stamp if this is the first */
/* call */
/******************************************************************************/
{
// Just invalidate the flat so that we'll refresh this the next time we
// obtain a new timestamp value.
setElapsedTimerInvalid();
}
#define DEFAULT_MIN 0 /* default random minimum value */
#define DEFAULT_MAX 999 /* default random maximum value */
#define MAX_DIFFERENCE 999999999 /* max spread between min and max */
uint64_t RexxActivation::getRandomSeed(RexxInteger * seed )
{
/* currently in an internal routine */
/* or interpret instruction? */
if (this->isInternalLevelCall())
{
/* forward along */
return this->parent->getRandomSeed(seed);
}
/* have a seed supplied? */
if (seed != OREF_NULL)
{
wholenumber_t seed_value = seed->getValue(); /* get the value */
if (seed_value < 0) /* negative value? */
{
/* got an error */
reportException(Error_Incorrect_call_nonnegative, CHAR_RANDOM, IntegerThree, seed);
}
/* set the saved seed value */
this->random_seed = seed_value;
/* flip all of the bits */
this->random_seed = ~this->random_seed;
/* randomize the seed number a bit */
for (size_t i = 0; i < 13; i++)
{
/* scramble the seed a bit */
this->random_seed = RANDOMIZE(this->random_seed);
}
}
/* step the randomization */
this->random_seed = RANDOMIZE(this->random_seed);
/* set the seed at the activity level*/
this->activity->setRandomSeed(this->random_seed);
return this->random_seed; /* return the seed value */
}
RexxInteger * RexxActivation::random(
RexxInteger * randmin, /* RANDOM minimum range */
RexxInteger * randmax, /* RANDOM maximum range */
RexxInteger * randseed ) /* RANDOM seed */
/******************************************************************************/
/* Function: Process the random function, using the current activation */
/* seed value. */
/******************************************************************************/
{
size_t i; /* loop counter */
/* go get the seed value */
uint64_t seed = this->getRandomSeed(randseed);
wholenumber_t minimum = DEFAULT_MIN; /* get the default MIN value */
wholenumber_t maximum = DEFAULT_MAX; /* get the default MAX value */
/* minimum specified? */
if (randmin != OREF_NULL)
{
/* no maximum value specified */
/* and no seed specified */
if ((randmax == OREF_NULL) && (randseed == OREF_NULL))
{
maximum = randmin->getValue(); /* this is actually a max value */
}
/* minimum value specified */
/* maximum value not specified */
/* seed specified */
else if ((randmin != OREF_NULL) && (randmax == OREF_NULL) && (randseed != OREF_NULL))
{
minimum = randmin->getValue();
}
else
{
minimum = randmin->getValue(); /* give both max and min values */
maximum = randmax->getValue();
}
}
else if (randmax != OREF_NULL) /* only given a maximum? */
{
maximum = randmax->getValue(); /* use the supplied maximum */
}
if (maximum < minimum) /* range problem? */
{
/* this is an error */
reportException(Error_Incorrect_call_random, randmin, randmax);
}
/* too big of a spread ? */
if (maximum - minimum > MAX_DIFFERENCE)
{
/* this is an error */
reportException(Error_Incorrect_call_random_range, randmin, randmax);
}
/* have real work to do? */
if (minimum != maximum)
{
// this will invert the bits of the value
uint64_t work = 0; /* start with zero */
for (i = 0; i < sizeof(uint64_t) * 8; i++)
{
work <<= 1; /* shift working num left one */
/* add in next seed bit value */
work = work | (seed & 0x01LL);
seed >>= 1; /* shift off the right most seed bit */
}
/* adjust for requested range */
minimum += (wholenumber_t)(work % (uint64_t)(maximum - minimum + 1));
}
return new_integer(minimum); /* return the random number */
}
static const char * trace_prefix_table[] = { /* table of trace prefixes */
"*-*", /* TRACE_PREFIX_CLAUSE */
"+++", /* TRACE_PREFIX_ERROR */
">>>", /* TRACE_PREFIX_RESULT */
">.>", /* TRACE_PREFIX_DUMMY */
">V>", /* TRACE_PREFIX_VARIABLE */
">E>", /* TRACE_PREFIX_DOTVARIABLE */
">L>", /* TRACE_PREFIX_LITERAL */
">F>", /* TRACE_PREFIX_FUNCTION */
">P>", /* TRACE_PREFIX_PREFIX */
">O>", /* TRACE_PREFIX_OPERATOR */
">C>", /* TRACE_PREFIX_COMPOUND */
">M>", /* TRACE_PREFIX_MESSAGE */
">A>", /* TRACE_PREFIX_ARGUMENT */
">=>", /* TRACE_PREFIX_ASSIGNMENT */
">I>", /* TRACE_PREFIX_INVOCATION */
};
/* extra space required to format a */
/* result line. This overhead is */
/* 6 leading spaces for the line */
/* number, + 1 space + length of the */
/* message prefix (3) + 1 space + */
/* 2 for an indent + 2 for the */
/* quotes surrounding the value */
#define TRACE_OVERHEAD 15
/* overhead for a traced instruction */
/* (6 digit line number, blank, */
/* 3 character prefix, and a blank */
#define INSTRUCTION_OVERHEAD 11
#define LINENUMBER 6 /* size of a line number */
#define PREFIX_OFFSET (LINENUMBER + 1) /* location of the prefix field */
#define PREFIX_LENGTH 3 /* length of the prefix flag */
#define INDENT_SPACING 2 /* spaces per indentation amount */
// over head for adding quotes
#define QUOTES_OVERHEAD 2
/**
* Trace program entry for a method or routine
*/
void RexxActivation::traceEntry()
{
// since we're advertising the entry location up front, we want to disable
// the normal trace-turn on notice. We'll get one or the other, but not
// both
this->settings.flags |= source_traced;
RexxArray *info = OREF_NULL;
if (isMethod())
{
info = new_array(getMessageName(), scope->getId(), getPackage()->getName());
}
else
{
info = new_array(getExecutable()->getName(), getPackage()->getName());
}
ProtectedObject p(info);
RexxString *message = activity->buildMessage(isRoutine() ? Message_Translations_routine_invocation : Message_Translations_method_invocation, info);
p = message;
/* get a string large enough to */
size_t outlength = message->getLength() + INSTRUCTION_OVERHEAD;
RexxString *buffer = raw_string(outlength); /* get an output string */
/* insert the leading blanks */
buffer->set(0, ' ', INSTRUCTION_OVERHEAD);
/* add the trace prefix */
buffer->put(PREFIX_OFFSET, trace_prefix_table[TRACE_PREFIX_INVOCATION], PREFIX_LENGTH);
/* copy the string value */
buffer->put(INSTRUCTION_OVERHEAD, message->getStringData(), message->getLength());
/* write out the line */
activity->traceOutput(this, buffer);
}
void RexxActivation::traceValue( /* trace an intermediate value */
RexxObject * value, /* value to trace */
int prefix ) /* traced result type */
/******************************************************************************/
/* Function: Trace an intermediate value or instruction result value */
/******************************************************************************/
{
/* tracing currently suppressed or */
/* no value was received? */
if (this->settings.flags&trace_suppress || this->debug_pause || value == OREF_NULL)
{
return; /* just ignore this call */
}
if (!this->code->isTraceable()) /* if we don't have real source */
{
return; /* just ignore for this */
}
/* get the string version */
RexxString *stringvalue = value->stringValue();
/* get a string large enough to */
size_t outlength = stringvalue->getLength() + TRACE_OVERHEAD + this->settings.traceindent * INDENT_SPACING;
RexxString *buffer = raw_string(outlength); /* get an output string */
ProtectedObject p(buffer);
/* insert the leading blanks */
buffer->set(0, ' ', TRACE_OVERHEAD + this->settings.traceindent * INDENT_SPACING);
/* add the trace prefix */
buffer->put(PREFIX_OFFSET, trace_prefix_table[prefix], PREFIX_LENGTH);
/* add a quotation mark */
buffer->putChar(TRACE_OVERHEAD - 2 + this->settings.traceindent * INDENT_SPACING, '\"');
/* copy the string value */
buffer->put(TRACE_OVERHEAD - 1 + this->settings.traceindent * INDENT_SPACING, stringvalue->getStringData(), stringvalue->getLength());
buffer->putChar(outlength - 1, '\"');/* add the trailing quotation mark */
/* write out the line */
this->activity->traceOutput(this, buffer);
}
/**
* Trace an entry that's of the form 'tag => "value"'.
*
* @param prefix The trace prefix tag to use.
* @param tagPrefix Any prefix string added to the tag. Use mostly for adding
* the "." to traced environment variables.
* @param quoteTag Indicates whether the tag should be quoted or not. Operator
* names are quoted.
* @param tag The tag name.
* @param value The associated trace value.
*/
void RexxActivation::traceTaggedValue(int prefix, const char *tagPrefix, bool quoteTag,
RexxString *tag, const char *marker, RexxObject * value)
{
// the trace settings would normally require us to trace this, but there are conditions
// where we just skip doing this anyway.
if (this->settings.flags&trace_suppress || this->debug_pause || value == OREF_NULL || !code->isTraceable())
{
return;
}
// get the string value from the traced object.
RexxString *stringVal = value->stringValue();
// now calculate the length of the traced string
stringsize_t outLength = tag->getLength() + stringVal->getLength();
// these are fixed overheads
outLength += TRACE_OVERHEAD + strlen(marker);
// now the indent spacing
outLength += this->settings.traceindent * INDENT_SPACING;
// now other conditionals
outLength += quoteTag ? QUOTES_OVERHEAD : 0;
// this is usually null, but dot variables add a "." to the tag.
outLength += tagPrefix == NULL ? 0 : strlen(tagPrefix);
// now get a buffer to write this out into
RexxString *buffer = raw_string(outLength);
ProtectedObject p(buffer);
// get a cursor for filling in the formatted data
stringsize_t dataOffset = TRACE_OVERHEAD + this->settings.traceindent * INDENT_SPACING - 2;
/* insert the leading blanks */
buffer->set(0, ' ', TRACE_OVERHEAD + this->settings.traceindent * INDENT_SPACING);
/* add the trace prefix */
buffer->put(PREFIX_OFFSET, trace_prefix_table[prefix], PREFIX_LENGTH);
// if this is a quoted tag (operators do this), add quotes before coping the tag
if (quoteTag)
{
buffer->putChar(dataOffset, '\"');
dataOffset++;
}
// is the tag prefixed? Add this before the name
if (tagPrefix != NULL)
{
stringsize_t prefixLength = strlen(tagPrefix);
buffer->put(dataOffset, tagPrefix, prefixLength);
dataOffset += prefixLength;
}
// add in the tag name
buffer->put(dataOffset, tag);
dataOffset += tag->getLength();
// might need a closing quote.
if (quoteTag)
{
buffer->putChar(dataOffset, '\"');
dataOffset++;
}
// now add the data marker
buffer->put(dataOffset, marker, strlen(marker));
dataOffset += strlen(marker);
// the leading quote around the value
buffer->putChar(dataOffset, '\"');
dataOffset++;
// the traced value
buffer->put(dataOffset, stringVal);
dataOffset += stringVal->getLength();
// and finally, the trailing quote
buffer->putChar(dataOffset, '\"');
dataOffset++;
/* write out the line */
this->activity->traceOutput(this, buffer);
}
/**
* Trace an entry that's of the form 'tag => "value"'.
*
* @param prefix The trace prefix tag to use.
* @param tagPrefix Any prefix string added to the tag. Use mostly for adding
* the "." to traced environment variables.
* @param quoteTag Indicates whether the tag should be quoted or not. Operator
* names are quoted.
* @param tag The tag name.
* @param value The associated trace value.
*/
void RexxActivation::traceOperatorValue(int prefix, const char *tag, RexxObject *value)
{
// the trace settings would normally require us to trace this, but there are conditions
// where we just skip doing this anyway.
if (this->settings.flags&trace_suppress || this->debug_pause || value == OREF_NULL || !code->isTraceable())
{
return;
}
// get the string value from the traced object.
RexxString *stringVal = value->stringValue();
// now calculate the length of the traced string
stringsize_t outLength = strlen(tag) + stringVal->getLength();
// these are fixed overheads
outLength += TRACE_OVERHEAD + strlen(VALUE_MARKER);
// now the indent spacing
outLength += this->settings.traceindent * INDENT_SPACING;
// now other conditionals
outLength += QUOTES_OVERHEAD;
// now get a buffer to write this out into
RexxString *buffer = raw_string(outLength);
ProtectedObject p(buffer);
// get a cursor for filling in the formatted data
stringsize_t dataOffset = TRACE_OVERHEAD + this->settings.traceindent * INDENT_SPACING - 2;
/* insert the leading blanks */
buffer->set(0, ' ', TRACE_OVERHEAD + this->settings.traceindent * INDENT_SPACING);
/* add the trace prefix */
buffer->put(PREFIX_OFFSET, trace_prefix_table[prefix], PREFIX_LENGTH);
// operators are quoted.
buffer->putChar(dataOffset, '\"');
dataOffset++;
// add in the tag name
buffer->put(dataOffset, tag, strlen(tag));
dataOffset += strlen(tag);
// need a closing quote.
buffer->putChar(dataOffset, '\"');
dataOffset++;
// now add the data marker
buffer->put(dataOffset, VALUE_MARKER, strlen(VALUE_MARKER));
dataOffset += strlen(VALUE_MARKER);
// the leading quote around the value
buffer->putChar(dataOffset, '\"');
dataOffset++;
// the traced value
buffer->put(dataOffset, stringVal);
dataOffset += stringVal->getLength();
// and finally, the trailing quote
buffer->putChar(dataOffset, '\"');
dataOffset++;
/* write out the line */
this->activity->traceOutput(this, buffer);
}
/**
* Trace a compound variable entry that's of the form 'tag =>
* "value"'.
*
* @param prefix The trace prefix tag to use.
* @param stem The stem name of the compound.
* @param tails The array of tail elements (unresolved).
* @param tailCount The count of tail elements.
* @param value The resolved tail element
*/
void RexxActivation::traceCompoundValue(int prefix, RexxString *stemName, RexxObject **tails, size_t tailCount,
RexxCompoundTail *tail)
{
traceCompoundValue(TRACE_PREFIX_COMPOUND, stemName, tails, tailCount, VALUE_MARKER, tail->createCompoundName(stemName));
}
/**
* Trace a compound variable entry that's of the form 'tag =>
* "value"'.
*
* @param prefix The trace prefix tag to use.
* @param stem The stem name of the compound.
* @param tails The array of tail elements (unresolved).
* @param tailCount The count of tail elements.
* @param value The associated trace value.
*/
void RexxActivation::traceCompoundValue(int prefix, RexxString *stemName, RexxObject **tails, size_t tailCount, const char *marker,
RexxObject * value)
{
// the trace settings would normally require us to trace this, but there are conditions
// where we just skip doing this anyway.
if (this->settings.flags&trace_suppress || this->debug_pause || value == OREF_NULL || !code->isTraceable())
{
return;
}
// get the string value from the traced object.
RexxString *stringVal = value->stringValue();
// now calculate the length of the traced string
stringsize_t outLength = stemName->getLength() + stringVal->getLength();
// build an unresolved tail name
RexxCompoundTail tail(tails, tailCount, false);
outLength += tail.getLength();
// add in the number of added dots
outLength += tailCount - 1;
// these are fixed overheads
outLength += TRACE_OVERHEAD + strlen(marker);
// now the indent spacing
outLength += this->settings.traceindent * INDENT_SPACING;
// now get a buffer to write this out into
RexxString *buffer = raw_string(outLength);
ProtectedObject p(buffer);
// get a cursor for filling in the formatted data
stringsize_t dataOffset = TRACE_OVERHEAD + this->settings.traceindent * INDENT_SPACING - 2;
/* insert the leading blanks */
buffer->set(0, ' ', TRACE_OVERHEAD + this->settings.traceindent * INDENT_SPACING);
/* add the trace prefix */
buffer->put(PREFIX_OFFSET, trace_prefix_table[prefix], PREFIX_LENGTH);
// add in the stem name
buffer->put(dataOffset, stemName);
dataOffset += stemName->getLength();
// copy the tail portion of the compound name
buffer->put(dataOffset, tail.getTail(), tail.getLength());
dataOffset += tail.getLength();
// now add the data marker
buffer->put(dataOffset, marker, strlen(marker));
dataOffset += strlen(marker);
// the leading quote around the value
buffer->putChar(dataOffset, '\"');
dataOffset++;
// the traced value
buffer->put(dataOffset, stringVal);
dataOffset += stringVal->getLength();
// and finally, the trailing quote
buffer->putChar(dataOffset, '\"');
dataOffset++;
/* write out the line */
this->activity->traceOutput(this, buffer);
}
void RexxActivation::traceSourceString()
/******************************************************************************/
/* Function: Trace the source string at debug mode start */
/******************************************************************************/
{
/* already traced? */
if (this->settings.flags&source_traced)
{
return; /* don't do it again */
}
/* tag this as traced */
this->settings.flags |= source_traced;
/* get the string version */
RexxString *string = this->sourceString(); /* get the source string */
/* get a string large enough to */
size_t outlength = string->getLength() + INSTRUCTION_OVERHEAD + 2;
RexxString *buffer = raw_string(outlength); /* get an output string */
/* insert the leading blanks */
buffer->set(0, ' ', INSTRUCTION_OVERHEAD);
/* add the trace prefix */
buffer->put(PREFIX_OFFSET, trace_prefix_table[TRACE_PREFIX_ERROR], PREFIX_LENGTH);
/* add a quotation mark */
buffer->putChar(INSTRUCTION_OVERHEAD, '\"');
/* copy the string value */
buffer->put(INSTRUCTION_OVERHEAD + 1, string->getStringData(), string->getLength());
buffer->putChar(outlength - 1, '\"');/* add the trailing quotation mark */
/* write out the line */
this->activity->traceOutput(this, buffer);
}
RexxString *RexxActivation::formatTrace(
RexxInstruction * instruction, /* instruction to trace */
RexxSource * _source ) /* program source */
/******************************************************************************/
/* Function: Format a source line for traceback or tracing */
/******************************************************************************/
{
if (instruction == OREF_NULL) /* no current instruction? */
{
return OREF_NULL; /* nothing to trace here */
}
// get the instruction location
SourceLocation location = instruction->getLocation();
/* extract the source string */
/* (formatted for tracing) */
if (this->settings.traceindent < MAX_TRACEBACK_INDENT)
{
return _source->traceBack(this, location, this->settings.traceindent, true);
}
else
{
return _source->traceBack(this, location, MAX_TRACEBACK_INDENT, true);
}
}
/* process clause boundary stuff */
void RexxActivation::processClauseBoundary()
/******************************************************************************/
/* Function: Handle all clause boundary processing (raising of halt */
/* conditions, turning on of external traces, and calling of halt */
/* and trace clause boundary exits */
/******************************************************************************/
{
if (this->pending_count != 0) /* do we have trapped conditions? */
{
this->processTraps(); /* go dispatch the traps */
}
this->activity->callHaltTestExit(this); /* Sys exit want to raise a halt? */
/* did sysexit change trace state */
if (!this->activity->callTraceTestExit(this, this->isExternalTraceOn()))
{
/* remember new state... */
if (this->isExternalTraceOn()) /* if current setting is on */
{
this->setExternalTraceOff(); /* turn it off */
}
else /* otherwise */
{
this->setExternalTraceOn(); /* turn it on */
}
}
/* yield situation occurred? */
if (this->settings.flags&external_yield)
{
/* turn off the yield flag */
this->settings.flags &= ~external_yield;
this->activity->relinquish(); /* yield control to the activity */
}
/* halt condition occurred? */
if (this->settings.flags&halt_condition)
{
/* turn off the halt flag */
this->settings.flags &= ~halt_condition;
/* yes, raise the flag */
/* process as common condition */
if (!activity->raiseCondition(OREF_HALT, OREF_NULL, settings.halt_description, OREF_NULL, OREF_NULL))
{
/* raise as a syntax error */
reportException(Error_Program_interrupted_condition, OREF_HALT);
}
}
/* need to turn on tracing? */
if (this->settings.flags&set_trace_on)
{
/* turn off the trace flag */
this->settings.flags &= ~set_trace_on;
this->setExternalTraceOn(); /* and save the current state */
/* turn on tracing */
this->setTrace(TRACE_RESULTS | DEBUG_ON, trace_results_flags | trace_debug);
}
/* need to turn off tracing? */
if (this->settings.flags&set_trace_off)
{
/* turn off the trace flag */
this->settings.flags &= ~set_trace_off;
this->setExternalTraceOff(); /* and save the current state */
/* turn on tracing */
this->setTrace(TRACE_OFF | DEBUG_OFF, trace_off);
}
/* no clause exits and all conditions*/
/* have been processed? */
if (!(this->settings.flags&clause_exits) && this->pending_count == 0)
{
/* turn off boundary processing */
this->settings.flags &= ~clause_boundary;
}
}
/**
* Turn on external trace at program startup (e.g, because
* RXTRACE is set)
*/
void RexxActivation::enableExternalTrace()
{
this->setTrace(TRACE_RESULTS | DEBUG_ON, trace_results_flags | trace_debug);
}
/**
* Halt the activation
*
* @param description
* The description for the halt condition (if any).
*
* @return true if this halt was recognized, false if there is a
* previous halt condition still to be processed.
*/
bool RexxActivation::halt(RexxString *description )
{
// if there's no halt condition pending, set this
if ((settings.flags&halt_condition) == 0)
{
/* store the description */
this->settings.halt_description = description;
/* turn on the HALT flag */
this->settings.flags |= halt_condition;
/* turn on clause boundary checking */
this->settings.flags |= clause_boundary;
return true;
}
else
{
// we're not in a good position to process this
return false;
}
}
void RexxActivation::yield()
/******************************************************************************/
/* Function: Flip ON the externally activated TRACE bit. */
/******************************************************************************/
{
/* turn on the yield flag */
this->settings.flags |= external_yield;
/* turn on clause boundary checking */
this->settings.flags |= clause_boundary;
}
void RexxActivation::externalTraceOn()
/******************************************************************************/
/* Function: Flip ON the externally activated TRACE bit. */
/******************************************************************************/
{
this->settings.flags |= set_trace_on;/* turn on the tracing flag */
/* turn on clause boundary checking */
this->settings.flags |= clause_boundary;
/* turn on tracing */
this->setTrace(TRACE_RESULTS | DEBUG_ON, trace_results_flags | trace_debug);
}
void RexxActivation::externalTraceOff()
/******************************************************************************/
/* Function: Flip OFF the externally activated TRACE bit. */
/******************************************************************************/
{
/* turn off the tracing flag */
this->settings.flags |= set_trace_off;
/* turn on clause boundary checking */
this->settings.flags |= clause_boundary;
}
bool RexxActivation::debugPause(RexxInstruction * instr)
/******************************************************************************/
/* Function: Process an individual debug pause for an instruction */
/******************************************************************************/
{
if (this->debug_pause) /* instruction during debug pause? */
{
return false; /* just get out quick */
}
if (this->settings.flags&debug_bypass)
{
/* turn off for the next time */
this->settings.flags &= ~debug_bypass;
}
/* debug pauses suppressed? */
else if (this->settings.trace_skip > 0)
{
this->settings.trace_skip--; /* account for this one */
if (this->settings.trace_skip == 0)/* gone to zero? */
{
/* turn tracing back on again (this */
/* ensures the next pause also has */
/* the instruction traced */
this->settings.flags &= ~trace_suppress;
}
}
else
{
if (!this->code->isTraceable()) /* if we don't have real source */
{
return false; /* just ignore for this */
}
/* newly into debug mode? */
if (!(this->settings.flags&debug_prompt_issued))
{
/* write the initial prompt */
this->activity->traceOutput(this, SystemInterpreter::getMessageText(Message_Translations_debug_prompt));
/* remember we've issued this */
this->settings.flags |= debug_prompt_issued;
}
RexxInstruction *currentInst = this->next; /* save the next location target */
for (;;)
{
RexxString *response;
/* read a line from the screen */
response = this->activity->traceInput(this);
if (response->getLength() == 0) /* just a "null" line entered? */
{
break; /* just end the pausing */
}
/* a re-execute request? */
else if (response->getLength() == 1 && response->getChar(0) == '=')
{
this->next = this->current; /* reset the execution pointer */
return true; /* finished (inform block instrs) */
}
else
{
this->debugInterpret(response);/* go execute this */
if (currentInst != this->next) /* flow of control change? */
{
break; /* end of this pause */
}
/* has the use changed the trace */
/* setting on us? */
else if (this->settings.flags&debug_bypass)
{
/* turn off for the next time */
this->settings.flags &= ~debug_bypass;
break; /* we also skip repausing */
}
}
}
}
return false; /* no re-execute */
}
void RexxActivation::traceClause( /* trace a REXX instruction */
RexxInstruction * clause, /* value to trace */
int prefix ) /* prefix to use */
/******************************************************************************/
/* Function: Trace an individual line of a source file */
/******************************************************************************/
{
/* tracing currently suppressed? */
if (this->settings.flags&trace_suppress || this->debug_pause)
{
return; /* just ignore this call */
}
if (!this->code->isTraceable()) /* if we don't have real source */
{
return; /* just ignore for this */
}
/* format the line */
RexxString *line = this->formatTrace(clause, this->code->getSourceObject());
if (line != OREF_NULL) /* have a source line? */
{
/* newly into debug mode? */
if ((this->settings.flags&trace_debug && !(this->settings.flags&source_traced)))
{
this->traceSourceString(); /* trace the source string */
}
/* write out the line */
this->activity->traceOutput(this, line);
}
}
/**
* Issue a command to a named host evironment
*
* @param commandString
* The command to issue
* @param address The target address
*
* @return The return code object
*/
void RexxActivation::command(RexxString *address, RexxString *commandString)
{
bool instruction_traced; /* instruction has been traced */
ProtectedObject condition;
ProtectedObject commandResult;
/* instruction already traced? */
if (tracingAll() || tracingCommands())
{
instruction_traced = true; /* remember we traced this */
}
else
{
instruction_traced = false; /* not traced yet */
}
/* if exit declines call */
if (this->activity->callCommandExit(this, address, commandString, commandResult, condition))
{
// first check for registered command handlers
CommandHandler *handler = activity->resolveCommandHandler(address);
if (handler != OREF_NULL)
{
handler->call(activity, this, address, commandString, commandResult, condition);
}
else
{
// No handler for this environment
commandResult = new_integer(RXSUBCOM_NOTREG); // just use the not registered return code
// raise the condition when things are done
condition = activity->createConditionObject(OREF_FAILURENAME, (RexxObject *)commandResult, commandString, OREF_NULL, OREF_NULL);
}
}
RexxObject *rc = (RexxObject *)commandResult;
RexxDirectory *conditionObj = (RexxDirectory *)(RexxObject *)condition;
bool failureCondition = false; // don't have a failure condition yet
int returnStatus = RETURN_STATUS_NORMAL;
// did a handler raise a condition? We need to pull the rc value from the
// condition object
if (conditionObj != OREF_NULL)
{
RexxObject *temp = conditionObj->at(OREF_RC);
if (temp == OREF_NULL)
{
// see if we have a result and make sure the condition object
// fills this as the RC value
temp = conditionObj->at(OREF_RESULT);
if (temp != OREF_NULL)
{
conditionObj->put(temp, OREF_RC);
}
}
// replace the RC value
if (temp != OREF_NULL)
{
rc = temp;
}
RexxString *conditionName = (RexxString *)conditionObj->at(OREF_CONDITION);
// check for an error or failure condition, since these get special handling
if (conditionName->strCompare(CHAR_FAILURENAME))
{
// unconditionally update the RC value
conditionObj->put(temp, OREF_RC);
// failure conditions require special handling when raising the condition
// we'll need to reraise this as an ERROR condition if not trapped.
failureCondition = true;
// set the appropriate return status
returnStatus = RETURN_STATUS_FAILURE;
}
if (conditionName->strCompare(CHAR_ERROR))
{
// unconditionally update the RC value
conditionObj->put(temp, OREF_RC);
// set the appropriate return status
returnStatus = RETURN_STATUS_ERROR;
}
}
// a handler might not return a value, so default the return code to zero
// if nothing is received.
if (rc == OREF_NULL)
{
rc = TheFalseObject;
}
// if this was done during a debug pause, we don't update RC
// and .RS.
if (!this->debug_pause)
{
// set the RC value before anything
this->setLocalVariable(OREF_RC, VARIABLE_RC, rc);
/* tracing command errors or fails? */
if ((returnStatus == RETURN_STATUS_ERROR && tracingErrors()) ||
(returnStatus == RETURN_STATUS_FAILURE && (tracingFailures())))
{
/* trace the current instruction */
this->traceClause(this->current, TRACE_PREFIX_CLAUSE);
/* then we always trace full command */
this->traceValue(commandString, TRACE_PREFIX_RESULT);
instruction_traced = true; /* we've now traced this */
}
wholenumber_t rcValue;
/* need to trace the RC info too? */
if (instruction_traced && rc->numberValue(rcValue) && rcValue != 0)
{
/* get RC as a string */
RexxString *rc_trace = rc->stringValue();
/* tack on the return code */
rc_trace = rc_trace->concatToCstring("RC(");
/* add the closing part */
rc_trace = rc_trace->concatWithCstring(")");
/* trace the return code */
this->traceValue(rc_trace, TRACE_PREFIX_ERROR);
}
// set the return status
setReturnStatus(returnStatus);
// now handle any conditions we might need to raise
// these are also not raised if it's a debug pause.
if (conditionObj != OREF_NULL)
{
// try to raise the condition, and if it isn't handled, we might
// munge this into an ERROR condition
if (!activity->raiseCondition(conditionObj))
{
// untrapped failure condition? Turn into an ERROR condition and
// reraise
if (failureCondition)
{
// just change the condition name
conditionObj->put(OREF_ERRORNAME, OREF_CONDITION);
activity->raiseCondition(conditionObj);
}
}
}
// do debug pause if necessary. necessary is defined by: we are
// tracing ALL or COMMANDS, OR, we /* using TRACE NORMAL and a FAILURE
// return code was received OR we receive an ERROR return code and
// have TRACE ERROR in effect.
if (instruction_traced && inDebug())
{
this->debugPause(); /* do the debug pause */
}
}
}
/**
* Set the return status flag for an activation context.
*
* @param status The new status value.
*/
void RexxActivation::setReturnStatus(int status)
{
this->settings.return_status = status;
this->settings.flags |= return_status_set;
}
RexxString * RexxActivation::getProgramName()
/******************************************************************************/
/* Function: Return the name of the current program file */
/******************************************************************************/
{
return this->code->getProgramName(); /* get the name from the code */
}
RexxDirectory * RexxActivation::getLabels()
/******************************************************************************/
/* Function: Return the directory of labels for this method */
/******************************************************************************/
{
return this->code->getLabels(); /* get the labels from the code */
}
RexxString * RexxActivation::sourceString()
/******************************************************************************/
/* Function: Create the source string returned by parse source */
/******************************************************************************/
{
/* produce the system specific string*/
return SystemInterpreter::getSourceString(this->settings.calltype, this->code->getProgramName());
}
/**
* Add a local routine to the current activation's routine set.
*
* @param name The name to add this under.
* @param method The method associated with the name.
*/
void RexxActivation::addLocalRoutine(RexxString *name, RexxMethod *_method)
{
// get the directory of external functions
RexxDirectory *routines = settings.parent_code->getLocalRoutines();
// if it does not exist, it will be created
if (routines == OREF_NULL)
{
settings.parent_code->getSourceObject()->setLocalRoutines(new_directory());
routines = settings.parent_code->getLocalRoutines();
}
// if a method by that name exists, it will be OVERWRITTEN!
routines->setEntry(name, _method);
}
/**
* Retrieve the directory of public routines associated with the
* current activation.
*
* @return A directory of the public routines.
*/
RexxDirectory *RexxActivation::getPublicRoutines()
{
return code->getPublicRoutines();
}
void RexxActivation::setObjNotify(
RexxMessage * notify) /* activation to notify */
/******************************************************************************/
/* Function: Set an error notification tag on the activation. */
/******************************************************************************/
{
this->objnotify = notify;
}
void RexxActivation::pushEnvironment(
RexxObject * environment) /* new local environment buffer */
/******************************************************************************/
/* Function: Push the new environment buffer onto the EnvLIst */
/******************************************************************************/
{
/* internal call or interpret? */
if (this->isTopLevelCall())
{
/* nope, push environment here. */
/* DO we have a environment list? */
if (!this->environmentList)
{
/* nope, create one */
this->environmentList = new_list();
}
this->environmentList->addFirst(environment);
}
else /* nope, process up the chain. */
{
/* Yes, forward on the message. */
this->parent->pushEnvironment(environment);
}
}
RexxObject * RexxActivation::popEnvironment()
/******************************************************************************/
/* Function: return the top level local Environemnt */
/******************************************************************************/
{
/* internal call or interpret? */
if (this->isTopLevelCall())
{
/* nope, we puop Environemnt here */
/* DO we have a environment list? */
if (this->environmentList)
{
/* yup, return first element */
return this->environmentList->removeFirst();
}
else /* nope, return .nil */
{
return TheNilObject;
}
}
else
{ /* nope, pass on up the chain. */
/* Yes, forward on the message. */
return this->parent->popEnvironment();
}
}
void RexxActivation::closeStreams()
/******************************************************************************/
/* Function: Close any streams opened by the I/O builtin functions */
/******************************************************************************/
{
RexxString *index; /* index for stream directory */
/* exiting a bottom level? */
if (this->isProgramOrMethod())
{
RexxDirectory *streams = this->settings.streams; /* get the streams directory */
/* actually have a table? */
if (streams != OREF_NULL)
{
/* traverse this */
for (HashLink j = streams->first(); (index = (RexxString *)streams->index(j)) != OREF_NULL; j = streams->next(j))
{
/* closing each stream */
streams->at(index)->sendMessage(OREF_CLOSE);
}
}
}
}
RexxObject *RexxActivation::novalueHandler(
RexxString *name ) /* name to retrieve */
/******************************************************************************/
/* Function: process unitialized variable over rides */
/******************************************************************************/
{
/* get the handler from .local */
RexxObject *novalue_handler = getLocalEnvironment(OREF_NOVALUE);
if (novalue_handler != OREF_NULL) /* have a novalue handler? */
{
/* ask it to process this */
return novalue_handler->sendMessage(OREF_NOVALUE, name);
}
return TheNilObject; /* return the handled result */
}
/**
* Retrieve the package for the current execution context.
*
* @return The Package holding the code for the current execution
* context.
*/
PackageClass *RexxActivation::getPackage()
{
return executable->getPackage();
}
RexxObject *RexxActivation::evaluateLocalCompoundVariable(RexxString *stemName, size_t index, RexxObject **tail, size_t tailCount)
{
/* new tail for compound */
RexxCompoundTail resolved_tail(this, tail, tailCount);
RexxStem *stem_table = getLocalStem(stemName, index); /* get the stem entry from this dictionary */
RexxObject *value = stem_table->evaluateCompoundVariableValue(this, stemName, &resolved_tail);
/* need to trace? */
if (tracingIntermediates())
{
traceCompoundName(stemName, tail, tailCount, &resolved_tail);
/* trace variable value */
traceCompound(stemName, tail, tailCount, value);
}
return value;
}
RexxObject *RexxActivation::getLocalCompoundVariableValue(RexxString *stemName, size_t index, RexxObject **tail, size_t tailCount)
{
/* new tail for compound */
RexxCompoundTail resolved_tail(this, tail, tailCount);
RexxStem *stem_table = getLocalStem(stemName, index); /* get the stem entry from this dictionary */
return stem_table->getCompoundVariableValue(&resolved_tail);
}
RexxObject *RexxActivation::getLocalCompoundVariableRealValue(RexxString *localstem, size_t index, RexxObject **tail, size_t tailCount)
{
/* new tail for compound */
RexxCompoundTail resolved_tail(this, tail, tailCount);
RexxStem *stem_table = getLocalStem(localstem, index); /* get the stem entry from this dictionary */
return stem_table->getCompoundVariableRealValue(&resolved_tail);
}
RexxCompoundElement *RexxActivation::getLocalCompoundVariable(RexxString *stemName, size_t index, RexxObject **tail, size_t tailCount)
{
/* new tail for compound */
RexxCompoundTail resolved_tail(this, tail, tailCount);
RexxStem *stem_table = getLocalStem(stemName, index); /* get the stem entry from this dictionary */
return stem_table->getCompoundVariable(&resolved_tail);
}
RexxCompoundElement *RexxActivation::exposeLocalCompoundVariable(RexxString *stemName, size_t index, RexxObject **tail, size_t tailCount)
{
/* new tail for compound */
RexxCompoundTail resolved_tail(this, tail, tailCount);
RexxStem *stem_table = getLocalStem(stemName, index); /* get the stem entry from this dictionary */
return stem_table->exposeCompoundVariable(&resolved_tail);
}
bool RexxActivation::localCompoundVariableExists(RexxString *stemName, size_t index, RexxObject **tail, size_t tailCount)
{
/* new tail for compound */
RexxCompoundTail resolved_tail(this, tail, tailCount);
RexxStem *stem_table = getLocalStem(stemName, index); /* get the stem entry from this dictionary */
return stem_table->compoundVariableExists(&resolved_tail);
}
void RexxActivation::assignLocalCompoundVariable(RexxString *stemName, size_t index, RexxObject **tail, size_t tailCount, RexxObject *value)
{
/* new tail for compound */
RexxCompoundTail resolved_tail(this, tail, tailCount);
RexxStem *stem_table = getLocalStem(stemName, index); /* get the stem entry from this dictionary */
/* and set the value */
stem_table->setCompoundVariable(&resolved_tail, value);
/* trace resolved compound name */
if (tracingIntermediates())
{
traceCompoundName(stemName, tail, tailCount, &resolved_tail);
/* trace variable value */
traceCompoundAssignment(stemName, tail, tailCount, value);
}
}
void RexxActivation::setLocalCompoundVariable(RexxString *stemName, size_t index, RexxObject **tail, size_t tailCount, RexxObject *value)
{
/* new tail for compound */
RexxCompoundTail resolved_tail(this, tail, tailCount);
RexxStem *stem_table = getLocalStem(stemName, index); /* get the stem entry from this dictionary */
/* and set the value */
stem_table->setCompoundVariable(&resolved_tail, value);
}
void RexxActivation::dropLocalCompoundVariable(RexxString *stemName, size_t index, RexxObject **tail, size_t tailCount)
{
/* new tail for compound */
RexxCompoundTail resolved_tail(this, tail, tailCount);
RexxStem *stem_table = getLocalStem(stemName, index); /* get the stem entry from this dictionary */
/* and set the value */
stem_table->dropCompoundVariable(&resolved_tail);
}
/**
* Get the security manager in effect for a given context.
*
* @return The security manager defined for this activation
* context.
*/
SecurityManager *RexxActivation::getSecurityManager()
{
return this->settings.securityManager;
}
/**
* Get the security manager in used by this activation.
*
* @return Either the defined security manager or the instance-global security
* manager.
*/
SecurityManager *RexxActivation::getEffectiveSecurityManager()
{
SecurityManager *manager = this->settings.securityManager;
if (manager != OREF_NULL)
{
return manager;
}
return activity->getInstanceSecurityManager();
}
/**
* Retrieve a value from the instance local environment.
*
* @param name The name of the .local object.
*
* @return The object stored at the given name.
*/
RexxObject *RexxActivation::getLocalEnvironment(RexxString *name)
{
return activity->getLocalEnvironment(name);
}
/**
* Create a stack frame for exception tracebacks.
*
* @return A StackFrame instance for this activation.
*/
StackFrameClass *RexxActivation::createStackFrame()
{
const char *type = FRAME_METHOD;
RexxArray *arguments = OREF_NULL;
RexxObject *target = OREF_NULL;
if (isInterpret())
{
type = FRAME_INTERPRET;
}
else if (isInternalCall())
{
type = FRAME_INTERNAL_CALL;
arguments = getArguments();
}
else if (isMethod())
{
type = FRAME_METHOD;
arguments = getArguments();
target = receiver;
}
else if (isProgram())
{
type = FRAME_PROGRAM;
arguments = getArguments();
}
else if (isRoutine())
{
type = FRAME_ROUTINE;
arguments = getArguments();
}
// construct the traceback line before we allocate the stack frame object.
// calling this in the constructor argument list can cause the stack frame instance
// to be inadvertently reclaimed if a GC is triggered while evaluating the constructor
// arguments.
RexxString *traceback = getTraceBack();
return new StackFrameClass(type, getMessageName(), (BaseExecutable *)getExecutableObject(), target, arguments, traceback, getContextLineNumber());
}
/**
* Format a more informative trace line when giving
* traceback information for code when no source code is
* available.
*
* @param packageName
* The package name to use (could be "REXX" for internal code)
*
* @return A formatted descriptive string for the invocation.
*/
RexxString *RexxActivation::formatSourcelessTraceLine(RexxString *packageName)
{
// if this is a method invocation, then we can give the method name and scope.
if (isMethod())
{
RexxArray *info = new_array(getMessageName(), scope->getId(), packageName);
ProtectedObject p(info);
return activity->buildMessage(Message_Translations_sourceless_method_invocation, info);
}
else if (isRoutine())
{
RexxArray *info = new_array(getMessageName(), packageName);
ProtectedObject p(info);
return activity->buildMessage(Message_Translations_sourceless_routine_invocation, info);
}
else
{
RexxArray *info = new_array(packageName);
ProtectedObject p(info);
return activity->buildMessage(Message_Translations_sourceless_program_invocation, info);
}
}