Changes On Branch list-and-dict-types

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Changes In Branch list-and-dict-types Excluding Merge-Ins

This is equivalent to a diff from 602b3659c7 to 721be90d96

2019-02-02
18:14
Expansion... sort of Leaf check-in: 721be90d96 user: dkf tags: list-and-dict-types
2019-01-02
16:22
A little bit less wrong. check-in: 75fd3b203e user: dkf tags: list-and-dict-types
2018-12-08
21:46
Add a micropass to optimize away conditional jumps that are identical to a conditional jump in a dominator. (Partial redundancy elimination appears to create these.) check-in: 344567b919 user: kbk tags: trunk
21:45
Add a micropass to optimize away conditional jumps that are identical to a conditional jump in a dominator. (Partial redundancy elimination appears to create these.) Closed-Leaf check-in: 1c9b4510d1 user: kbk tags: kbk-deadcond
17:56
merge trunk check-in: 01fb4f7ffb user: dkf tags: list-and-dict-types
2018-12-07
02:43
Fixes that make poly1305 compilable. check-in: 602b3659c7 user: kbk tags: trunk
02:23
Increase recursion limit to allow compilation of longer procedures. Correct a bug in expandInlines that left dangling references to procedure args. Correct a bug in analyzeTypes where the INT/ENTIER break was set to int32 rather than int64. Add shift operations to constfold. Improve auditing. Merge trunk. Closed-Leaf check-in: 023d0828f0 user: kbk tags: poly1305
2018-12-06
03:15
Merge kbk-pre - add the optimizations of loop inversion (enables loop-invariant code motion) and partial redundancy elimination, and fix multiple bugs exposed by these optimizations. check-in: 0e06123e97 user: kbk tags: trunk

Changes to codegen/build.tcl.

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
    #	The concatenated value as an LLVM value reference.

    method concat() {vector {name ""}} {
	my ExtractVector $vector
	my call ${tcl.concatenate} [list $len $ary] $name
    }

    # Builder:dictAppend(STRING,STRING,STRING) --
    #
    #	Append a value to a key in a dictionary. NOTE: this operation can fail
    #	(e.g., because it can be given an invalid dictionary) so it produces a
    #	STRING FAIL. Quadcode implementation ('dictAppend').
    #
    # Parameters:
    #	dict -	The dictionary as an LLVM value reference.
    #	key -	The key as an LLVM value reference.
    #	value -	The value to append as an LLVM value reference.
    #	ec -	Where to write the error code if an error happens.
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	The resulting dictionary as an LLVM value reference, or a FAIL.

    method dictAppend(STRING,STRING,STRING) {dict key value ec {name ""}} {
	my call ${tcl.dict.append} [list $dict $key $value $ec] $name
    }





    # Builder:dictExists(STRING) --
    #
    #	Find whether a key exists in a dictionary. This version uses a vector
    #	of values for the key path. Quadcode implementation ('dictExists').
    #
    # Parameters:
    #	dict -	The dictionary as an LLVM value reference.
    #	vector -
    #		The key path as an LLVM vector value reference.
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	Whether the value exists as an LLVM ZEROONE value reference.

    method dictExists(STRING) {dict vector {name ""}} {
	my ExtractVector $vector
	my call ${tcl.dict.exists} [list $dict $len $ary] $name
    }




    # Builder:dictExists(STRING,STRING) --
    #
    #	Find whether a key exists in a dictionary. This version uses a single
    #	simple key. Quadcode implementation ('dictExists').
    #
    # Parameters:
    #	dict -	The dictionary as an LLVM value reference.
    #	key -	The key as an LLVM value reference.
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	Whether the value exists as an LLVM ZEROONE value reference.

    method dictExists(STRING,STRING) {dict key {name ""}} {
	my call ${tcl.dict.exists1} [list $dict $key] $name
    }




    # Builder:dictGet(STRING) --
    #
    #	Retrieve a value from a dictionary. This version uses a vector as a
    #	key path. NOTE: this operation can fail (e.g., because it can be given
    #	an invalid dictionary) so it produces a STRING FAIL. Quadcode
    #	implementation ('dictGet').
    #
    # Parameters:
    #	dict -	The dictionary as an LLVM value reference.
    #	vector -
    #		The key path as an LLVM vector value reference.
    #	ec -	Where to write the error code if an error happens.
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	The retrieved value as an LLVM value reference, or a FAIL.

    method dictGet(STRING) {dict vector ec {name ""}} {





	my ExtractVector $vector
	my call ${tcl.dict.get} [list $dict $len $ary $ec] $name
    }

    # Builder:dictGet(STRING,STRING) --
    #
    #	Retrieve a value from a dictionary. This version uses a single simple
    #	key. NOTE: this operation can fail (e.g., because it can be given an
    #	invalid dictionary) so it produces a STRING FAIL. Quadcode
    #	implementation ('dictGet').
    #
    # Parameters:
    #	dict -	The dictionary as an LLVM value reference.
    #	key -	The key as an LLVM value reference.
    #	ec -	Where to write the error code if an error happens.
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	The retrieved value as an LLVM value reference, or a FAIL.

    method dictGet(STRING,STRING) {dict key ec {name ""}} {




	my call ${tcl.dict.get1} [list $dict $key $ec] $name
    }

    # Builder:dictGetOrNexist(STRING,STRING) --
    #
    #	Retrieve a value from a dictionary, or NEXIST if the key doesn't map
    #	to a value in the dict. This version uses a single simple key. NOTE:
    #	this operation can fail (e.g., because it can be given an invalid
    #	dictionary) so it produces a FAIL NEXIST STRING. Quadcode
    #	implementation ('dictGetOrNexist').
    #
    # Parameters:
    #	dict -	The dictionary as an LLVM value reference.
    #	key -	The key as an LLVM value reference.
    #	ec -	Where to write the error code if an error happens.
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	The retrieved value as an LLVM value reference, or a NEXIST or FAIL.

    method dictGetOrNexist(STRING,STRING) {dict key ec {name ""}} {
	my call ${tcl.dict.get1.empty} [list $dict $key $ec] $name
    }





    # Builder:dictIncr(STRING,STRING,INT) --
    #
    #	Increment the value for a key in a dictionary. NOTE: this operation
    #	can fail (e.g., because it can be given an invalid dictionary) so it
    #	produces a STRING FAIL. Quadcode implementation ('dictIncr').
    #
    # Parameters:
    #	dict -	The dictionary as an LLVM value reference.
    #	key -	The key as an LLVM value reference.
    #	value -	The amount to increment by as an LLVM value reference.
    #	ec -	Where to write the error code if an error happens.
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	The resulting dictionary as an LLVM value reference, or a FAIL.

    method dictIncr(STRING,STRING,INT) {dict key value ec {name ""}} {




	my call ${tcl.dict.incr} [list $dict $key $value $ec] $name
    }

    # Builder:dictIterStart(STRING) --
    #
    #	Start iterating over a dictionary; other opcodes are used to retrieve
    #	what the state of the iteration is. NOTE: this operation can fail
    #	(e.g., because it can be given an invalid dictionary) so it produces a
    #	DICTITER FAIL. Quadcode implementation ('dictIterStart').
    #
    # Parameters:
    #	dict -	The dictionary as an LLVM value reference.
    #	ec -	Where to write the error code if an error happens.
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	The iteration state as an LLVM DICTITER value reference, or a FAIL.

    method dictIterStart(STRING) {dict ec {name ""}} {
	my call ${tcl.dict.iterStart} [list $dict $ec] $name




    }

    # Builder:dictIterNext --
    #
    #	Get the next step when iterating over a dictionary; other opcodes are
    #	used to retrieve what the state of the iteration is. Quadcode
    #	implementation ('dictIterNext').







|

|
<
|





<




|

|
|

>
>
>
|
>
|














|



>
>
|
>
|













|


>
>
|
>
|


|
|
|












|
>
>
>
>
>




|


|
<
|











|
>
>
>
>



|


|
<
<
|









|

|
|

>
>
>
|
>
|
















|
>
>
>
>



|


|
<
|



<




|

|
|
>
>
>
>







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
    #	The concatenated value as an LLVM value reference.

    method concat() {vector {name ""}} {
	my ExtractVector $vector
	my call ${tcl.concatenate} [list $len $ary] $name
    }

    # Builder:dictAppend(DICT,STRING,STRING) --
    #
    #	Append a value to a key in a dictionary. Quadcode implementation

    #	('dictAppend').
    #
    # Parameters:
    #	dict -	The dictionary as an LLVM value reference.
    #	key -	The key as an LLVM value reference.
    #	value -	The value to append as an LLVM value reference.

    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	The resulting dictionary as an LLVM value reference.

    method dictAppend(DICT,STRING,STRING) {dict key value {name ""}} {
	my call ${tcl.dict.append} [list $dict $key $value] $name
    }
    method dictAppend(EMPTY,STRING,STRING) {dict key value {name ""}} {
	# TODO: Optimize case?
	my call ${tcl.dict.append} [list $dict $key $value] $name
    }

    # Builder:dictExists(DICT) --
    #
    #	Find whether a key exists in a dictionary. This version uses a vector
    #	of values for the key path. Quadcode implementation ('dictExists').
    #
    # Parameters:
    #	dict -	The dictionary as an LLVM value reference.
    #	vector -
    #		The key path as an LLVM vector value reference.
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	Whether the value exists as an LLVM ZEROONE value reference.

    method dictExists(DICT) {dict vector {name ""}} {
	my ExtractVector $vector
	my call ${tcl.dict.exists} [list $dict $len $ary] $name
    }
    method dictExists(EMPTY) {dict vector {name ""}} {
	Const 0 int1
    }

    # Builder:dictExists(DICT,STRING) --
    #
    #	Find whether a key exists in a dictionary. This version uses a single
    #	simple key. Quadcode implementation ('dictExists').
    #
    # Parameters:
    #	dict -	The dictionary as an LLVM value reference.
    #	key -	The key as an LLVM value reference.
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	Whether the value exists as an LLVM ZEROONE value reference.

    method dictExists(DICT,STRING) {dict key {name ""}} {
	my call ${tcl.dict.exists1} [list $dict $key] $name
    }
    method dictExists(EMPTY,STRING) {dict key {name ""}} {
	Const 0 int1
    }

    # Builder:dictGet(DICT) --
    #
    #	Retrieve a value from a dictionary. This version uses a vector as a
    #	key path. NOTE: this operation can fail (e.g., a key not present or an
    #	invalid dictionary inside a valid one) so it produces a STRING FAIL.
    #	Quadcode implementation ('dictGet').
    #
    # Parameters:
    #	dict -	The dictionary as an LLVM value reference.
    #	vector -
    #		The key path as an LLVM vector value reference.
    #	ec -	Where to write the error code if an error happens.
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	The retrieved value as an LLVM value reference, or a FAIL.

    method dictGet(DICT) {dict vector ec {name ""}} {
	my ExtractVector $vector
	my call ${tcl.dict.get} [list $dict $len $ary $ec] $name
    }
    method dictGet(EMPTY) {dict vector ec {name ""}} {
	# TODO: Optimize case?
	my ExtractVector $vector
	my call ${tcl.dict.get} [list $dict $len $ary $ec] $name
    }

    # Builder:dictGet(DICT,STRING) --
    #
    #	Retrieve a value from a dictionary. This version uses a single simple
    #	key. NOTE: this operation can fail so it produces a STRING FAIL.

    #	Quadcode implementation ('dictGet').
    #
    # Parameters:
    #	dict -	The dictionary as an LLVM value reference.
    #	key -	The key as an LLVM value reference.
    #	ec -	Where to write the error code if an error happens.
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	The retrieved value as an LLVM value reference, or a FAIL.

    method dictGet(DICT,STRING) {dict key ec {name ""}} {
	my call ${tcl.dict.get1} [list $dict $key $ec] $name
    }
    method dictGet(EMPTY,STRING) {dict key ec {name ""}} {
	# TODO: Optimize case?
	my call ${tcl.dict.get1} [list $dict $key $ec] $name
    }

    # Builder:dictGetOrNexist(EMPTY DICT,STRING) --
    #
    #	Retrieve a value from a dictionary, or NEXIST if the key doesn't map
    #	to a value in the dict. This version uses a single simple key.


    #	Quadcode implementation ('dictGetOrNexist').
    #
    # Parameters:
    #	dict -	The dictionary as an LLVM value reference.
    #	key -	The key as an LLVM value reference.
    #	ec -	Where to write the error code if an error happens.
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	The retrieved value as an LLVM value reference, or a NEXIST.

    method dictGetOrNexist(DICT,STRING) {dict key {name ""}} {
	my call ${tcl.dict.get1.empty} [list $dict $key] $name
    }
    method dictGetOrNexist(EMPTY,STRING) {dict key {name ""}} {
	# TODO: Optimize case
	my call ${tcl.dict.get1.empty} [list $dict $key] $name
    }

    # Builder:dictIncr(EMPTY DICT,STRING,INT) --
    #
    #	Increment the value for a key in a dictionary. NOTE: this operation
    #	can fail (e.g., because it can be given an invalid dictionary) so it
    #	produces a STRING FAIL. Quadcode implementation ('dictIncr').
    #
    # Parameters:
    #	dict -	The dictionary as an LLVM value reference.
    #	key -	The key as an LLVM value reference.
    #	value -	The amount to increment by as an LLVM value reference.
    #	ec -	Where to write the error code if an error happens.
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	The resulting dictionary as an LLVM value reference, or a FAIL.

    method dictIncr(DICT,STRING,INT) {dict key value ec {name ""}} {
	my call ${tcl.dict.incr} [list $dict $key $value $ec] $name
    }
    method dictIncr(EMPY,STRING,INT) {dict key value ec {name ""}} {
	# TODO: Optimize case
	my call ${tcl.dict.incr} [list $dict $key $value $ec] $name
    }

    # Builder:dictIterStart(DICT) --
    #
    #	Start iterating over a dictionary; other opcodes are used to retrieve
    #	what the state of the iteration is. Quadcode implementation

    #	('dictIterStart').
    #
    # Parameters:
    #	dict -	The dictionary as an LLVM value reference.

    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	The iteration state as an LLVM DICTITER value reference.

    method dictIterStart(DICT) {dict {name ""}} {
	my call ${tcl.dict.iterStart} [list $dict] $name
    }
    method dictIterStart(EMPTY) {dict {name ""}} {
	# TODO: Optimize case
	my call ${tcl.dict.iterStart} [list $dict] $name
    }

    # Builder:dictIterNext --
    #
    #	Get the next step when iterating over a dictionary; other opcodes are
    #	used to retrieve what the state of the iteration is. Quadcode
    #	implementation ('dictIterNext').
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
    # Results:
    #	The termination flag as an LLVM ZEROONE value reference.

    method dictIterDone {iter {name ""}} {
	my call ${tcl.dict.iterDone} [list $iter] $name
    }

    # Builder:dictLappend(STRING,STRING,STRING) --
    #
    #	List-append a value to a key in a dictionary. NOTE: this operation can
    #	fail (e.g., because it can be given an invalid dictionary) so it
    #	produces a STRING FAIL. Quadcode implementation ('dictLappend').
    #
    # Parameters:
    #	dict -	The dictionary as an LLVM value reference.
    #	key -	The key as an LLVM value reference.
    #	value -	The value to append as an LLVM value reference.
    #	ec -	Where to write the error code if an error happens.
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	The resulting dictionary as an LLVM value reference, or a FAIL.

    method dictLappend(STRING,STRING,STRING) {dict key value ec {name ""}} {




	my call ${tcl.dict.lappend} [list $dict $key $value $ec] $name
    }

    # Builder:dictSet(STRING,STRING) --
    #
    #	Set or create a value in a dictionary. This version uses a vector as a
    #	dictionary key path. NOTE: this operation can fail (e.g., because it
    #	can be given an invalid dictionary) so it produces a STRING FAIL.
    #	Quadcode implementation ('dictSet').
    #
    # Parameters:
    #	dict -	The dictionary as an LLVM value reference.
    #	value -	The value as an LLVM value reference.
    #	vector -
    #		The key path as an LLVM vector value reference.
    #	ec -	Where to write the error code if an error happens.
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	The new dictionary value.

    method dictSet(STRING,STRING) {dict value vector ec {name ""}} {





	my ExtractVector $vector
	my call ${tcl.dict.set} [list $dict $len $ary $value $ec] $name
    }

    # Builder:dictSet(STRING,STRING,STRING) --
    #
    #	Set or create a value in a dictionary. This version uses a single











    #	simple key. NOTE: this operation can fail (e.g., because it can be







    #	given an invalid dictionary) so it produces a STRING FAIL. Quadcode



    #	implementation ('dictSet').
    #
    # Parameters:
    #	dict -	The dictionary as an LLVM value reference.
    #	key -	The key as an LLVM value reference.
























    #	value -	The value as an LLVM value reference.





    #	ec -	Where to write the error code if an error happens.

















    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	The new dictionary value.

    method dictSet(STRING,STRING,STRING) {dict key value ec {name ""}} {
	my call ${tcl.dict.set1} [list $dict $key $value $ec] $name
    }

    # Builder:dictSetOrUnset(STRING,STRING,NEXIST) --
    #
    #	Remove a value in a dictionary. This version uses a single simple key.
    #	NOTE: this operation can fail (e.g., because it can be given an
    #	invalid dictionary) so it produces a STRING FAIL. Quadcode
    #	implementation ('dictSetOrUnset').
    #
    # Parameters:
    #	dict -	The dictionary as an LLVM value reference.
    #	key -	The key as an LLVM value reference.
    #	value -	The NEXIST value (actually ignored).
    #	ec -	Where to write the error code if an error happens.
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	The new dictionary value, or FAIL.

    method dictSetOrUnset(STRING,STRING,NEXIST) {dict key value ec {name ""}} {
	my call ${tcl.dict.set1.empty} [list $dict $key [my nothing STRING] $ec] $name
    }

    # Builder:dictSetOrUnset(STRING,STRING,NEXIST STRING) --
    #
    #	Set, create or remove a value in a dictionary. This version uses a
    #	single simple key, and the value can be NEXIST to remove the key.
    #	NOTE: this operation can fail (e.g., because it can be given an
    #	invalid dictionary) so it produces a STRING FAIL. Quadcode
    #	implementation ('dictSetOrUnset').
    #
    # Parameters:
    #	dict -	The dictionary as an LLVM value reference.
    #	key -	The key as an LLVM value reference.
    #	value -	The value as an LLVM value reference, or NEXIST.
    #	ec -	Where to write the error code if an error happens.
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	The new dictionary value, or FAIL.

    method dictSetOrUnset(STRING,STRING,NEXIST\040STRING) {dict key value ec {name ""}} {
	my call ${tcl.dict.set1.empty} [list $dict $key $value $ec] $name
    }

    # Builder:dictSetOrUnset(STRING,STRING,NEXIST STRING) --
    #
    #	Set or create a value in a dictionary. This version uses a single
    #	simple key.  NOTE: this operation can fail (e.g., because it can be
    #	given an invalid dictionary) so it produces a STRING FAIL. Quadcode
    #	implementation ('dictSetOrUnset').
    #
    # Parameters:
    #	dict -	The dictionary as an LLVM value reference.
    #	key -	The key as an LLVM value reference.
    #	value -	The value as an LLVM value reference.
    #	ec -	Where to write the error code if an error happens.
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	The new dictionary value, or FAIL.

    method dictSetOrUnset(STRING,STRING,STRING) {dict key value ec {name ""}} {
	my call ${tcl.dict.set1.empty} [list $dict $key [my just $value] $ec] $name
    }

    # Builder:dictSize(STRING) --
    #
    #	Get the size of a dictionary, i.e., the number of key-value pairs.
    #
    # Parameters:
    #	value -	The STRING LLVM value reference to a dict to get the size of.
    #	ecvar -	Location to write the Tcl return code into, as an LLVM int*
    #		reference.
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	An INT FAIL in an LLVM value reference.

    method dictSize(STRING) {value ecvar {name ""}} {
	my call ${tcl.dict.size} [list $value $ecvar] $name
    }




    # Builder:dictUnset(STRING) --
    #
    #	Remove a key from a dictionary. This version uses a vector as a
    #	dictionary key path. NOTE: this operation can fail (e.g., because it
    #	can be given an invalid dictionary) so it produces a STRING FAIL.
    #	Quadcode implementation ('dictUnset').
    #
    # Parameters:
    #	dict -	The dictionary as an LLVM value reference.
    #	vector -
    #		The key path as an LLVM vector value reference.
    #	ec -	Where to write the error code if an error happens.
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	The new dictionary value.

    method dictUnset(STRING) {dict vector ec {name ""}} {





	my ExtractVector $vector
	my call ${tcl.dict.unset} [list $dict $len $ary $ec] $name
    }

    # Builder:dictUnset(STRING,STRING) --
    #
    #	Remove a key from a dictionary. This version uses a single simple
    #	key. NOTE: this operation can fail (e.g., because it can be given an
    #	invalid dictionary) so it produces a STRING FAIL. Quadcode
    #	implementation ('dictUnset').
    #
    # Parameters:
    #	dict -	The dictionary as an LLVM value reference.
    #	key -	The key as an LLVM value reference.
    #	ec -	Where to write the error code if an error happens.
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	The new dictionary value.

    method dictUnset(STRING,STRING) {dict key ec {name ""}} {
	my call ${tcl.dict.unset1} [list $dict $key $ec] $name




    }

    # Builder:directAppend(STRING,STRING) --
    #
    #	Append a value to a variable, which should be referred to by a
    #	fully-qualified name. NOTE: this operation can fail because of traces
    #	so it produces a STRING FAIL. Quadcode implementation







|



|












|
>
>
>
>



|


|
|
|











|

|
>
>
>
>
>




|


>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
|
>
>
>
|




>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>






|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|

|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
|


<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|





<
<




|

|
|

>
>
|
>
|


|
|













|
>
>
>
>
>




|

|
<
<
<




|






|
|
>
>
>
>







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
    # Results:
    #	The termination flag as an LLVM ZEROONE value reference.

    method dictIterDone {iter {name ""}} {
	my call ${tcl.dict.iterDone} [list $iter] $name
    }

    # Builder:dictLappend(DICT,STRING,STRING) --
    #
    #	List-append a value to a key in a dictionary. NOTE: this operation can
    #	fail (e.g., because it can be given an invalid dictionary) so it
    #	produces a DICT FAIL. Quadcode implementation ('dictLappend').
    #
    # Parameters:
    #	dict -	The dictionary as an LLVM value reference.
    #	key -	The key as an LLVM value reference.
    #	value -	The value to append as an LLVM value reference.
    #	ec -	Where to write the error code if an error happens.
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	The resulting dictionary as an LLVM value reference, or a FAIL.

    method dictLappend(DICT,STRING,STRING) {dict key value ec {name ""}} {
	my call ${tcl.dict.lappend} [list $dict $key $value $ec] $name
    }
    method dictLappend(EMPTY,STRING,STRING) {dict key value ec {name ""}} {
	# TODO: Optimize case
	my call ${tcl.dict.lappend} [list $dict $key $value $ec] $name
    }

    # Builder:dictSet(DICT,STRING) --
    #
    #	Set or create a value in a dictionary. This version uses a vector as a
    #	dictionary key path.. NOTE: this operation can fail (e.g., because
    #	there is an invalid dictionary nested inside) so it produces a DICT
    #	FAIL. Quadcode implementation ('dictSet').
    #
    # Parameters:
    #	dict -	The dictionary as an LLVM value reference.
    #	value -	The value as an LLVM value reference.
    #	vector -
    #		The key path as an LLVM vector value reference.
    #	ec -	Where to write the error code if an error happens.
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	The new dictionary value or a FAIL.

    method dictSet(DICT,STRING) {dict value vector ec {name ""}} {
	my ExtractVector $vector
	my call ${tcl.dict.set} [list $dict $len $ary $value $ec] $name
    }
    method dictSet(EMPTY,STRING) {dict value vector ec {name ""}} {
	# TODO: Optimize case
	my ExtractVector $vector
	my call ${tcl.dict.set} [list $dict $len $ary $value $ec] $name
    }

    # Builder:dictSet(DICT,STRING,STRING) --
    #
    #	Set or create a value in a dictionary. This version uses a single
    #	simple key. Quadcode implementation ('dictSet').
    #
    # Parameters:
    #	dict -	The dictionary as an LLVM value reference.
    #	key -	The key as an LLVM value reference.
    #	value -	The value as an LLVM value reference.
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	The new dictionary value.

    method dictSet(DICT,STRING,STRING) {dict key value {name ""}} {
	my call ${tcl.dict.set1} [list $dict $key $value] $name
    }
    method dictSet(EMPTY,STRING,STRING) {dict key value {name ""}} {
	# TODO: Optimize case
	my call ${tcl.dict.set1} [list $dict $key $value] $name
    }

    # Builder:dictSetOrUnset(DICT,STRING,NEXIST) --
    #
    #	Remove a value in a dictionary. This version uses a single simple key.
    #	Quadcode implementation ('dictSetOrUnset').
    #
    # Parameters:
    #	dict -	The dictionary as an LLVM value reference.
    #	key -	The key as an LLVM value reference.
    #	value -	The NEXIST value (actually ignored).
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	The new dictionary value.

    method dictSetOrUnset(DICT,STRING,NEXIST) {dict key value {name ""}} {
	my call ${tcl.dict.set1.empty} [list $dict $key [my nothing STRING]] $name
    }
    method dictSetOrUnset(EMPTY,STRING,NEXIST) {dict key value {name ""}} {
	# TODO: Optimize case
	my call ${tcl.dict.set1.empty} [list $dict $key [my nothing STRING]] $name
    }

    # Builder:dictSetOrUnset(DICT,STRING,NEXIST STRING) --
    #
    #	Set, create or remove a value in a dictionary. This version uses a
    #	single simple key, and the value can be NEXIST to remove the key.
    #	Quadcode implementation ('dictSetOrUnset').
    #
    # Parameters:
    #	dict -	The dictionary as an LLVM value reference.
    #	key -	The key as an LLVM value reference.
    #	value -	The value as an LLVM value reference, or NEXIST.
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	The new dictionary value.

    method dictSetOrUnset(DICT,STRING,NEXIST\040STRING) {dict key value {name ""}} {
	my call ${tcl.dict.set1.empty} [list $dict $key $value] $name
    }
    method dictSetOrUnset(EMPTY,STRING,NEXIST\040STRING) {dict key value {name ""}} {
	# TODO: Optimize case
	my call ${tcl.dict.set1.empty} [list $dict $key $value] $name
    }

    # Builder:dictSetOrUnset(DICT,STRING,NEXIST STRING) --
    #
    #	Set or create a value in a dictionary. This version uses a single
    #	simple key. Quadcode implementation ('dictSetOrUnset').
    #
    # Parameters:
    #	dict -	The dictionary as an LLVM value reference.
    #	key -	The key as an LLVM value reference.
    #	value -	The value as an LLVM value reference.
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	The new dictionary value.

    method dictSetOrUnset(DICT,STRING,STRING) {dict key value {name ""}} {






















	my call ${tcl.dict.set1.empty} [list $dict $key [my just $value]] $name
    }
    method dictSetOrUnset(EMPTY,STRING,STRING) {dict key value {name ""}} {


















	# TODO: Optimize case

	my call ${tcl.dict.set1.empty} [list $dict $key [my just $value]] $name
    }























    # Builder:dictSize(DICT) --
    #
    #	Get the size of a dictionary, i.e., the number of key-value pairs.
    #
    # Parameters:
    #	value -	The STRING LLVM value reference to a dict to get the size of.


    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	An INT in an LLVM value reference.

    method dictSize(DICT) {value {name ""}} {
	my call ${tcl.dict.size} [list $value] $name
    }
    method dictSize(EMPTY) {value ecvar {name ""}} {
	my packInt32 [Const 0] $name
    }

    # Builder:dictUnset(DICT) --
    #
    #	Remove a key from a dictionary. This version uses a vector as a
    #	dictionary key path. NOTE: this operation can fail (e.g., because of
    #	an invalid dictionary inside a valid one) so it produces a DICT FAIL.
    #	Quadcode implementation ('dictUnset').
    #
    # Parameters:
    #	dict -	The dictionary as an LLVM value reference.
    #	vector -
    #		The key path as an LLVM vector value reference.
    #	ec -	Where to write the error code if an error happens.
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	The new dictionary value.

    method dictUnset(DICT) {dict vector ec {name ""}} {
	my ExtractVector $vector
	my call ${tcl.dict.unset} [list $dict $len $ary $ec] $name
    }
    method dictUnset(EMPTY) {dict vector ec {name ""}} {
	# TODO: Optimize case
	my ExtractVector $vector
	my call ${tcl.dict.unset} [list $dict $len $ary $ec] $name
    }

    # Builder:dictUnset(DICT,STRING) --
    #
    #	Remove a key from a dictionary. Quadcode implementation ('dictUnset').



    #
    # Parameters:
    #	dict -	The dictionary as an LLVM value reference.
    #	key -	The key as an LLVM value reference.
    #	ec -	Where to write the error code if an error happens. (Ignored)
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	The new dictionary value.

    method dictUnset(DICT,STRING) {dict key ec {name ""}} {
	my call ${tcl.dict.unset1} [list $dict $key] $name
    }
    method dictUnset(EMPTY,STRING) {dict key ec {name ""}} {
	# TODO: Optimize case
	my call ${tcl.dict.unset1} [list $dict $key] $name
    }

    # Builder:directAppend(STRING,STRING) --
    #
    #	Append a value to a variable, which should be referred to by a
    #	fully-qualified name. NOTE: this operation can fail because of traces
    #	so it produces a STRING FAIL. Quadcode implementation
3043
3044
3045
3046
3047
3048
3049
































3050
3051
3052
3053
3054
3055
3056
    # Results:
    #	None.

    method dropReference {value} {
	my Call tcl.dropReference $value
	return
    }

































    # Builder:dropReference(STRING) --
    #
    #	Generate code to decrement the reference count of a value and delete
    #	the value if it has ceased to be used.
    #
    # Parameters:







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







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
    # Results:
    #	None.

    method dropReference {value} {
	my Call tcl.dropReference $value
	return
    }

    # Builder:dropReference(DICT) --
    #
    #	Generate code to decrement the reference count of a value and delete
    #	the value if it has ceased to be used.
    #
    # Parameters:
    #	value -	The DICT LLVM value reference for the operand.
    #
    # Results:
    #	None.

    method dropReference(DICT) {value} {
	my Call tcl.dropReference $value
	return
    }

    # Builder:dropReference(LIST) --
    #
    #	Generate code to decrement the reference count of a value and delete
    #	the value if it has ceased to be used.
    #
    # Parameters:
    #	value -	The LIST LLVM value reference for the operand.
    #
    # Results:
    #	None.

    method dropReference(LIST) {value} {
	my Call tcl.dropReference $value
	return
    }

    # Builder:dropReference(STRING) --
    #
    #	Generate code to decrement the reference count of a value and delete
    #	the value if it has ceased to be used.
    #
    # Parameters:
4411
4412
4413
4414
4415
4416
4417
























4418
4419
4420
4421
4422
4423
4424

    method instanceOf.ZEROONE_BOOLEAN(STRING) {value {name ""}} {
	my call ${tcl.isZeroOneBoolean} [list $value [Const false bool]] $name
    }
    method instanceOf.IMPURE_ZEROONE_BOOLEAN(STRING) {value {name ""}} {
	my call ${tcl.isZeroOneBoolean} [list $value [Const false bool]] $name
    }

























    # Builder:int --
    #
    #	Generate code to create an integer "literal".
    #
    # Parameters:
    #	value -	The Tcl integer that we are converting to an LLVM INT.







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524

    method instanceOf.ZEROONE_BOOLEAN(STRING) {value {name ""}} {
	my call ${tcl.isZeroOneBoolean} [list $value [Const false bool]] $name
    }
    method instanceOf.IMPURE_ZEROONE_BOOLEAN(STRING) {value {name ""}} {
	my call ${tcl.isZeroOneBoolean} [list $value [Const false bool]] $name
    }

    # Builder:instanceOf.DICT --
    #
    #	Generate code to check if the given STRING contains something that can
    #	be parsed to get a DICT.

    method instanceOf.DICT(STRING) {value {name ""}} {
	my call ${tcl.isDict} [list $value] $name
    }
    method instanceOf.IMPURE_DICT(STRING) {value {name ""}} {
	my call ${tcl.isDict} [list $value] $name
    }

    # Builder:instanceOf.LIST --
    #
    #	Generate code to check if the given STRING contains something that
    #	can be parsed to get a LIST.

    method instanceOf.LIST(STRING) {value {name ""}} {
	my call ${tcl.isList} [list $value] $name
    }
    method instanceOf.IMPURE_LIST(STRING) {value {name ""}} {
	my call ${tcl.isList} [list $value] $name
    }

    # Builder:int --
    #
    #	Generate code to create an integer "literal".
    #
    # Parameters:
    #	value -	The Tcl integer that we are converting to an LLVM INT.
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852







































































4853
4854
4855
4856
4857
4858
4859
4860








4861














4862
4863


4864

4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996


4997

4998























4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040



5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063




5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086



5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108



5109
5110
5111
5112
5113
5114
5115
	    }
	} else {
	    set len [Const 0]
	}
	my call ${tcl.list.create} [list $len [my gep $objv 0 0]] $name
    }

    # Builder:listAppend(STRING,STRING) --
    #
    #	Append an element to a list. NOTE: this operation can fail (e.g.,
    #	because it can be given an invalid list) so it produces a STRING FAIL.
    #	Quadcode implementation ('listAppend').
    #
    # Parameters:
    #	list -	List value to get append to, in an LLVM STRING reference.
    #	value -	The value to append as an LLVM STRING value reference.







































































    #	ec -	Location to write the Tcl return code into, as an LLVM int*
    #		reference.
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	The element of the list, as an LLVM STRING FAIL reference.









    method listAppend(STRING,STRING) {list value ec {name ""}} {














	my call ${tcl.list.append} [list $list $value $ec] $name
    }




    # Builder:listConcat(STRING,STRING) --
    #
    #	Append a list of elements to a list. NOTE: this operation can fail
    #	(e.g., because it can be given an invalid list) so it produces a
    #	STRING FAIL. Quadcode implementation ('listConcat').
    #
    # Parameters:
    #	list -	List value to get append to, in an LLVM STRING reference.
    #	value -	The list of values to append, as an LLVM STRING value
    #		reference.
    #	ec -	Location to write the Tcl return code into, as an LLVM int*
    #		reference.
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	The element of the list, as an LLVM STRING FAIL reference.

    method listConcat(STRING,STRING) {list value ec {name ""}} {
	my call ${tcl.list.concat} [list $list $value $ec] $name
    }

    # Builder:listIn(STRING,STRING) --
    #
    #	Determine if an element is present in a list by simple linear search.
    #	NOTE: this operation can fail (e.g., because it can be given an
    #	invalid list) so it produces an INT FAIL. Quadcode implementation
    #	('listIn').
    #
    # Parameters:
    #	value -	The value to check for, as an LLVM STRING value reference.
    #	list -	List value to search, in an LLVM STRING reference.
    #	ec -	Location to write the Tcl return code into, as an LLVM int*
    #		reference.
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	If the element is present, as an LLVM INT FAIL reference.

    method listIn(STRING,STRING) {value list ec {name ""}} {
	my call ${tcl.list.in} [list $value $list $ec] $name
    }

    # Builder:listIndex(STRING) --
    #
    #	Get an element of a list. NOTE: this operation can fail (e.g., because
    #	it can be given an invalid list) so it produces a STRING FAIL.
    #	Quadcode implementation ('listIndex').
    #
    # Parameters:
    #	value -	List value to get the length of, in an LLVM STRING reference.
    #	vector -
    #		The indices as an LLVM vector value reference.
    #	errVar -
    #		Location to write the Tcl return code into, as an LLVM int*
    #		reference.
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	The element of the list, as an LLVM STRING FAIL reference.

    method listIndex(STRING) {value vector ec {name ""}} {
	my ExtractVector $vector
	my call ${tcl.list.index} [list $value $len $ary $ec] $name
    }

    # Builder:listIndex(STRING,INT) --
    #
    #	Get an element of a list. NOTE: this operation can fail (e.g., because
    #	it can be given an invalid list) so it produces a STRING FAIL.
    #	Quadcode implementation ('listIndex').
    #
    # Parameters:
    #	value -	List value to get the length of, in an LLVM STRING reference.
    #	index -	Index value to use, in an LLVM INT reference.
    #	errVar -
    #		Location to write the Tcl return code into, as an LLVM int*
    #		reference.
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	The element of the list, as an LLVM STRING FAIL reference.

    method listIndex(STRING,INT) {value index ec {name ""}} {
	my call ${tcl.list.index1} [list $value $index $ec] $name
    }

    # Builder:listIndex(STRING,STRING) --
    #
    #	Get an element of a list. NOTE: this operation can fail (e.g., because
    #	it can be given an invalid list) so it produces a STRING FAIL.
    #	Quadcode implementation ('listIndex').
    #
    # Parameters:
    #	value -	List value to get the length of, in an LLVM STRING reference.
    #	index -	Index value to use, in an LLVM STRING reference.
    #	errVar -
    #		Location to write the Tcl return code into, as an LLVM int*
    #		reference.
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	The element of the list, as an LLVM STRING FAIL reference.

    method listIndex(STRING,STRING) {value index ec {name ""}} {
	my call ${tcl.list.indexList} [list $value $index $ec] $name
    }

    # Builder:listLength(STRING) --
    #
    #	Get the length of a list. NOTE: this operation can fail (e.g., because
    #	it can be given an invalid list) so it produces an INT FAIL. Quadcode
    #	implementation ('listLength').
    #
    # Parameters:
    #	value -	List value to get the length of, in an LLVM STRING reference.
    #	errVar -
    #		Location to write the Tcl return code into, as an LLVM int*
    #		reference.
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	The length of the list, as an LLVM INT FAIL reference.

    method listLength(STRING) {value ec {name ""}} {
	my call ${tcl.list.length} [list $value $ec] $name
    }




    # Builder:listRange(STRING,INT,INT) --























    #
    #	Get a sublist of a list. NOTE: this operation can fail (e.g., because
    #	it can be given an invalid list) so it produces a STRING FAIL.
    #	Quadcode implementation ('listRange').
    #
    # Parameters:
    #	value -	List value to get a substring of, in an LLVM STRING reference.
    #	from -	Index of first element to return, in an LLVM INT reference.
    #	to -	Index of last element to return, in an LLVM INT reference.
    #	errVar -
    #		Location to write the Tcl return code into, as an LLVM int*
    #		reference.
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	The sublist, as an LLVM STRING FAIL reference.

    method listRange(STRING,INT,INT) {value from to ec {name ""}} {
	my call ${tcl.list.range1} [list $value $from $to $ec] $name
    }

    # Builder:listRange(STRING,STRING,STRING) --
    #
    #	Get a sublist of a list. NOTE: this operation can fail (e.g., because
    #	it can be given an invalid list) so it produces a STRING FAIL.
    #	Quadcode implementation ('listRange').
    #
    # Parameters:
    #	value -	List value to get a substring of, in an LLVM STRING reference.
    #	from -	Index of first element to return, in an LLVM STRING reference.
    #	to -	Index of last element to return, in an LLVM STRING reference.
    #	errVar -
    #		Location to write the Tcl return code into, as an LLVM int*
    #		reference.
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	The sublist, as an LLVM STRING FAIL reference.

    method listRange(STRING,STRING,STRING) {value from to ec {name ""}} {



	my call ${tcl.list.range} [list $value $from $to $ec] $name
    }

    # Builder:listSet(STRING,STRING) --
    #
    #	Update an element in a sublist of a list. NOTE: this operation can
    #	fail (e.g., because it can be given an invalid list) so it produces a
    #	STRING FAIL. Quadcode implementation ('listSet').
    #
    # Parameters:
    #	list -	List value to get a substring of, in an LLVM STRING reference.
    #	elem -	The value to write into the list, in an LLVM STRING reference.
    #	vector -
    #		The indices as an LLVM vector value reference.
    #	ecvar -	Location to write the Tcl return code into, as an LLVM int*
    #		reference.
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	The updated list, as an LLVM STRING FAIL reference.

    method listSet(STRING,STRING) {list elem vector ecvar {name ""}} {




	my ExtractVector $vector
	my call ${tcl.list.set} [list $list $len $ary $elem $ecvar] $name
    }

    # Builder:listSet(STRING,INT,STRING) --
    #
    #	Update an element of a list. NOTE: this operation can fail (e.g.,
    #	because it can be given an invalid list) so it produces a STRING FAIL.
    #	Quadcode implementation ('listSet').
    #
    # Parameters:
    #	list -	List value update, in an LLVM STRING reference.
    #	idx -	The index into the list to set, in an LLVM INT reference.
    #	elem -	The value to write into the list, in an LLVM STRING reference.
    #	ecvar -	Location to write the Tcl return code into, as an LLVM int*
    #		reference.
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	The updated list, as an LLVM STRING FAIL reference.

    method listSet(STRING,INT,STRING) {list idx elem ecvar {name ""}} {



	my call ${tcl.list.set1} [list $list $idx $elem $ecvar] $name
    }

    # Builder:listSet(STRING,STRING,STRING) --
    #
    #	Update an element of a list or sublist. NOTE: this operation can fail
    #	(e.g., because it can be given an invalid list) so it produces a
    #	STRING FAIL. Quadcode implementation ('listSet').
    #
    # Parameters:
    #	list -	List value update, in an LLVM STRING reference.
    #	idx -	The index into the list to set, in an LLVM STRING reference.
    #	elem -	The value to write into the list, in an LLVM STRING reference.
    #	ecvar -	Location to write the Tcl return code into, as an LLVM int*
    #		reference.
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	The updated list, as an LLVM STRING FAIL reference.

    method listSet(STRING,STRING,STRING) {list idx elem ecvar {name ""}} {



	my call ${tcl.list.setList} [list $list $idx $elem $ecvar] $name
    }

    # Builder:lor(INT,INT) --
    #
    #	Generate code to compute the logical or of two INTs.  Quadcode
    #	implementation ('lor').







|

<
<
|




>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>








>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|

>
>
|
>
|

|
|
|


|
<
|








<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
|

<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|



|

<
<
|


|
<
<
<




|

|
|

>
>
|
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>






|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<


<
|





|

|
>
>
>



|


|
|


|









|

|
>
>
>
>




|


|



|








|

|
>
>
>



|


|
|


|








|

|
>
>
>







4937
4938
4939
4940
4941
4942
4943
4944
4945


4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066

5067
5068
5069
5070
5071
5072
5073
5074
5075




































































5076
5077
5078



















5079
5080
5081
5082
5083
5084


5085
5086
5087
5088



5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132























5133
5134

5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
	    }
	} else {
	    set len [Const 0]
	}
	my call ${tcl.list.create} [list $len [my gep $objv 0 0]] $name
    }

    # Builder:listAppend(LIST,STRING) --
    #


    #	Append an element to a list. Quadcode implementation ('listAppend').
    #
    # Parameters:
    #	list -	List value to get append to, in an LLVM STRING reference.
    #	value -	The value to append as an LLVM STRING value reference.
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	The element of the list, as an LLVM LIST reference.

    method listAppend(LIST,STRING) {list value {name ""}} {
	my call ${tcl.list.append} [list $list $value] $name
    }
    method listAppend(EMPTY,STRING) {list value {name ""}} {
	my call ${tcl.list.append} [list $list $value] $name
    }

    # Builder:listConcat(LIST,LIST) --
    #
    #	Append a list of elements to a list. Quadcode implementation
    #	('listConcat').
    #
    # Parameters:
    #	list -	List value to get append to, in an LLVM LIST reference.
    #	value -	The list of values to append, as an LLVM LIST reference.
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	The concatenated list, as an LLVM LIST reference.

    method listConcat(LIST,LIST) {list value {name ""}} {
	my call ${tcl.list.concat} [list $list $value] $name
    }
    method listConcat(LIST,EMPTY) {list value {name ""}} {
	my call ${tcl.list.concat} [list $list $value] $name
    }
    method listConcat(EMPTY,LIST) {list value {name ""}} {
	my call ${tcl.list.concat} [list $list $value] $name
    }
    method listConcat(EMPTY,EMPTY) {list value {name ""}} {
	my call ${tcl.list.concat} [list $list $value] $name
    }

    # Builder:listIn(STRING,LIST) --
    #
    #	Determine if an element is present in a list by simple linear search.
    #	Quadcode implementation ('listIn').
    #
    # Parameters:
    #	value -	The value to check for, as an LLVM STRING value reference.
    #	list -	List value to search, in an LLVM LIST value reference.
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	If the element is present, as an LLVM ZEROOONE reference.

    method listIn(STRING,LIST) {value list {name ""}} {
	my call ${tcl.list.in} [list $value $list] $name
    }
    method listIn(STRING,EMPTY) {value list {name ""}} {
	my call ${tcl.list.in} [list $value $list] $name
    }

    # Builder:listIndex(LIST) --
    #
    #	Get an element of a list. NOTE: this operation can fail (e.g., because
    #	it can be given an invalid interior list) so it produces a STRING
    #	FAIL. Quadcode implementation ('listIndex').
    #
    # Parameters:
    #	value -	List value to get the length of, in an LLVM LIST reference.
    #	vector -
    #		The indices as an LLVM vector value reference.
    #	ec -	Location to write the Tcl return code into, as an LLVM int*
    #		reference.
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	The element of the list, as an LLVM STRING FAIL reference.

    method listIndex(LIST) {value vector ec {name ""}} {
	my ExtractVector $vector
	my call ${tcl.list.index} [list $value $len $ary $ec] $name
    }
    method listIndex(EMPTY) {value vector ec {name ""}} {
	my ExtractVector $vector
	my call ${tcl.list.index} [list $value $len $ary $ec] $name
    }

    # Builder:listIndex(LIST,INT) --
    #
    #	Get an element of a list. Quadcode implementation ('listIndex').
    #
    # Parameters:
    #	value -	List value to get the length of, in an LLVM LIST reference.
    #	index -	Index value to use, in an LLVM INT reference.
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	The element of the list, as an LLVM STRING reference.

    method listIndex(LIST,INT) {value index {name ""}} {
	my call ${tcl.list.index1} [list $value $index] $name
    }
    method listIndex(LIST,INT) {value index {name ""}} {
	my call ${tcl.list.index1} [list $value $index] $name
    }

    # Builder:listIndex(LIST,STRING) --
    #
    #	Get an element of a list. NOTE: this operation can fail (e.g., because
    #	it can be given an invalid index) so it produces a STRING FAIL.
    #	Quadcode implementation ('listIndex').
    #
    # Parameters:
    #	value -	List value to index into, in an LLVM LIST reference.

    #	index -	Index value to use, in an LLVM STRING reference.
    #	ec -	Location to write the Tcl return code into, as an LLVM int*
    #		reference.
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	The element of the list, as an LLVM STRING FAIL reference.





































































    method listIndex(LIST,STRING) {value index ec {name ""}} {
	my call ${tcl.list.indexList} [list $value $index $ec] $name
    }



















    method listIndex(EMPTY,STRING) {value index ec {name ""}} {
	my call ${tcl.list.indexList} [list $value $index $ec] $name
    }

    # Builder:listLength(LIST) --
    #


    #	Get the length of a list. Quadcode implementation ('listLength').
    #
    # Parameters:
    #	value -	List value to get the length of, in an LLVM LIST reference.



    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	The length of the list, as an LLVM INT reference.

    method listLength(LIST) {value {name ""}} {
	my call ${tcl.list.length} [list $value] $name
    }
    method listLength(EMPTY) {value {name ""}} {
	my packInt32 [Const 0] $name
    }

    # Builder:listRange(LIST,INT,INT) --
    #
    #	Get a sublist of a list. Quadcode implementation ('listRange').
    #
    # Parameters:
    #	value -	List value to get a substring of, in an LLVM LIST reference.
    #	from -	Index of first element to return, in an LLVM INT reference.
    #	to -	Index of last element to return, in an LLVM INT reference.
    #	ec -	Location to write the Tcl return code into, as an LLVM int*
    #		reference. (Ignored.)
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	The sublist, as an LLVM LIST FAIL reference.

    method listRange(LIST,INT,INT) {value from to ec {name ""}} {
	my call ${tcl.list.range1} [list $value $from $to] $name
    }
    method listRange(EMPTY,INT,INT) {value from to c {name ""}} {
	my call ${tcl.list.range1} [list $value $from $to] $name
    }

    # Builder:listRange(LIST,STRING,STRING) --
    #
    #	Get a sublist of a list. NOTE: this operation can fail (e.g., because
    #	it can be given an invalid list) so it produces a STRING FAIL.
    #	Quadcode implementation ('listRange').
    #
    # Parameters:
    #	value -	List value to get a substring of, in an LLVM LIST reference.























    #	from -	Index of first element to return, in an LLVM STRING reference.
    #	to -	Index of last element to return, in an LLVM STRING reference.

    #	ec -	Location to write the Tcl return code into, as an LLVM int*
    #		reference.
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	The sublist, as an LLVM LIST FAIL reference.

    method listRange(LIST,STRING,STRING) {value from to ec {name ""}} {
	my call ${tcl.list.range} [list $value $from $to $ec] $name
    }
    method listRange(EMPTY,STRING,STRING) {value from to ec {name ""}} {
	my call ${tcl.list.range} [list $value $from $to $ec] $name
    }

    # Builder:listSet(LIST,STRING) --
    #
    #	Update an element in a sublist of a list. NOTE: this operation can
    #	fail (e.g., because it can be given an invalid index) so it produces a
    #	LIST FAIL. Quadcode implementation ('listSet').
    #
    # Parameters:
    #	list -	List value to get a substring of, in an LLVM LIST reference.
    #	elem -	The value to write into the list, in an LLVM STRING reference.
    #	vector -
    #		The indices as an LLVM vector value reference.
    #	ecvar -	Location to write the Tcl return code into, as an LLVM int*
    #		reference.
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	The updated list, as an LLVM LIST FAIL reference.

    method listSet(LIST,STRING) {list elem vector ecvar {name ""}} {
	my ExtractVector $vector
	my call ${tcl.list.set} [list $list $len $ary $elem $ecvar] $name
    }
    method listSet(EMPTY,STRING) {list elem vector ecvar {name ""}} {
	my ExtractVector $vector
	my call ${tcl.list.set} [list $list $len $ary $elem $ecvar] $name
    }

    # Builder:listSet(LIST,INT,STRING) --
    #
    #	Update an element of a list. NOTE: this operation can fail (e.g.,
    #	because it can be given an invalid index) so it produces a LIST FAIL.
    #	Quadcode implementation ('listSet').
    #
    # Parameters:
    #	list -	List value update, in an LLVM LIST reference.
    #	idx -	The index into the list to set, in an LLVM INT reference.
    #	elem -	The value to write into the list, in an LLVM STRING reference.
    #	ecvar -	Location to write the Tcl return code into, as an LLVM int*
    #		reference.
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	The updated list, as an LLVM LIST FAIL reference.

    method listSet(LIST,INT,STRING) {list idx elem ecvar {name ""}} {
	my call ${tcl.list.set1} [list $list $idx $elem $ecvar] $name
    }
    method listSet(EMPTY,INT,STRING) {list idx elem ecvar {name ""}} {
	my call ${tcl.list.set1} [list $list $idx $elem $ecvar] $name
    }

    # Builder:listSet(LIST,STRING,STRING) --
    #
    #	Update an element of a list or sublist. NOTE: this operation can fail
    #	(e.g., because it can be given an invalid index) so it produces a LIST
    #	FAIL. Quadcode implementation ('listSet').
    #
    # Parameters:
    #	list -	List value update, in an LLVM LIST reference.
    #	idx -	The index into the list to set, in an LLVM STRING reference.
    #	elem -	The value to write into the list, in an LLVM STRING reference.
    #	ecvar -	Location to write the Tcl return code into, as an LLVM int*
    #		reference.
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	The updated list, as an LLVM LIST FAIL reference.

    method listSet(LIST,STRING,STRING) {list idx elem ecvar {name ""}} {
	my call ${tcl.list.setList} [list $list $idx $elem $ecvar] $name
    }
    method listSet(EMPTY,STRING,STRING) {list idx elem ecvar {name ""}} {
	my call ${tcl.list.setList} [list $list $idx $elem $ecvar] $name
    }

    # Builder:lor(INT,INT) --
    #
    #	Generate code to compute the logical or of two INTs.  Quadcode
    #	implementation ('lor').
5545
5546
5547
5548
5549
5550
5551
























































5552
5553
5554
5555
5556
5557
5558
	if {[string match "* NEXIST" $type]} {
	    set type [string range $type 0 end-7]
	} elseif {[string match "NEXIST *" $type]} {
	    set type [string range $type 7 end]
	}
	my insert [my undef $type!] [Const true bool] 0 $name
    }

























































    # Builder:unmaybe --
    #
    #	Get the value out of a FAIL or NEXIST. NOTE: The FAIL/NEXIST must be a
    #	Just or the result will be an 'undef'; test with the 'maybe' method
    #	first!
    #







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
	if {[string match "* NEXIST" $type]} {
	    set type [string range $type 0 end-7]
	} elseif {[string match "NEXIST *" $type]} {
	    set type [string range $type 7 end]
	}
	my insert [my undef $type!] [Const true bool] 0 $name
    }

    # Builder:narrowToType.DICT(STRING) --
    #
    #	Generate code to parse the given STRING and extract a DICT. The
    #	STRING is already be known to contain a value of the right type (due
    #	to higher-level quadcode constraints). Quadcode implementation
    #	('narrowToType').
    #
    # Parameters:
    #	value -	The STRING LLVM value reference to parse.
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	A DICT LLVM value reference.

    method narrowToType.DICT(STRING) {value {name ""}} {
	return $value
    }
    method narrowToType.IMPURE_DICT(STRING) {value {name ""}} {
	return $value
    }
    method narrowToType.EMPTY_DICT(STRING) {value {name ""}} {
	return $value
    }
    method narrowToType.IMPURE_EMPTY_DICT(STRING) {value {name ""}} {
	return $value
    }

    # Builder:narrowToType.LIST(STRING) --
    #
    #	Generate code to parse the given STRING and extract a LIST. The
    #	STRING is already be known to contain a value of the right type (due
    #	to higher-level quadcode constraints). Quadcode implementation
    #	('narrowToType').
    #
    # Parameters:
    #	value -	The STRING LLVM value reference to parse.
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	A LIST LLVM value reference.

    method narrowToType.LIST(STRING) {value {name ""}} {
	return $value
    }
    method narrowToType.IMPURE_LIST(STRING) {value {name ""}} {
	return $value
    }
    method narrowToType.EMPTY_LIST(STRING) {value {name ""}} {
	return $value
    }
    method narrowToType.IMPURE_EMPTY_LIST(STRING) {value {name ""}} {
	return $value
    }

    # Builder:unmaybe --
    #
    #	Get the value out of a FAIL or NEXIST. NOTE: The FAIL/NEXIST must be a
    #	Just or the result will be an 'undef'; test with the 'maybe' method
    #	first!
    #
6097
6098
6099
6100
6101
6102
6103
































































6104
6105
6106
6107
6108
6109
6110
    #	Returns an LLVM IMPURE NUMERIC value

    method packImpure(NUMERIC) {value {name ""}} {
	set sval [my stringify(NUMERIC) $value]
	my addReference(STRING) $sval
	return [my impure NUMERIC $sval $value $name]
    }

































































    # Builder:packImpure(ZEROONE BOOLEAN) --
    #
    #	Convert a ZEROONE BOOLEAN to an IMPURE ZEROONE BOOLEAN
    #
    # Parameters:
    #	value -	LLVM Value to pack into the 'impure' structure







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
    #	Returns an LLVM IMPURE NUMERIC value

    method packImpure(NUMERIC) {value {name ""}} {
	set sval [my stringify(NUMERIC) $value]
	my addReference(STRING) $sval
	return [my impure NUMERIC $sval $value $name]
    }

    # Builder:packImpure(DICT) --
    #
    #	Convert a DICT to an IMPURE DICT
    #
    # Parameters:
    #	value -	LLVM Value to pack into the 'impure' structure
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	Returns an LLVM IMPURE DICT value

    method packImpure(DICT) {value {name ""}} {
	return $value
    }

    # Builder:packImpure(EMPTY DICT) --
    #
    #	Convert an EMPTY DICT to an IMPURE EMPTY DICT
    #
    # Parameters:
    #	value -	LLVM Value to pack into the 'impure' structure
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	Returns an LLVM IMPURE DICT value

    method packImpure(EMPTY\040DICT) {value {name ""}} {
	return $value
    }

    # Builder:packImpure(EMPTY LIST) --
    #
    #	Convert an EMPTY LIST to an IMPURE EMPTY LIST
    #
    # Parameters:
    #	value -	LLVM Value to pack into the 'impure' structure
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	Returns an LLVM IMPURE LIST value

    method packImpure(EMPTY\040LIST) {value {name ""}} {
	return $value
    }

    # Builder:packImpure(LIST) --
    #
    #	Convert a LIST to an IMPURE LIST
    #
    # Parameters:
    #	value -	LLVM Value to pack into the 'impure' structure
    #	name (optional) -
    #		A name to give to the result value.
    #
    # Results:
    #	Returns an LLVM IMPURE LIST value

    method packImpure(LIST) {value {name ""}} {
	return $value
    }

    # Builder:packImpure(ZEROONE BOOLEAN) --
    #
    #	Convert a ZEROONE BOOLEAN to an IMPURE ZEROONE BOOLEAN
    #
    # Parameters:
    #	value -	LLVM Value to pack into the 'impure' structure

Changes to codegen/compile.tcl.

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
	    ::quadcode::typeOfOperand \
	    ::quadcode::dataType::mightbea
	namespace eval tcl {
	    namespace eval mathfunc {
		proc literal {descriptor} {
		    string equal [lindex $descriptor 0] "literal"
		}



		proc refType {type} {
		    expr {
			[uplevel 1 [list my ReferenceType? $type]]
			&& "CALLFRAME" ni $type
		    }
		}
		proc failType {type} {
		    uplevel 1 [list my FailureType? $type]
		}
		proc operandType {operand} {
		    uplevel 1 [list my OperandType $operand]
		}
		proc consumed {var search} {
		    uplevel 1 [list my IsConsumed $var $search]
		}
		proc callframe {operand} {
		    uplevel 1 [list my IsCallFrame $operand]






		}
	    }
	}
    }

    # TclCompiler:ByteCode --
    #







>
>
>

















>
>
>
>
>
>







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
	    ::quadcode::typeOfOperand \
	    ::quadcode::dataType::mightbea
	namespace eval tcl {
	    namespace eval mathfunc {
		proc literal {descriptor} {
		    string equal [lindex $descriptor 0] "literal"
		}
		proc var {descriptor} {
		    string equal [lindex $descriptor 0] "var"
		}
		proc refType {type} {
		    expr {
			[uplevel 1 [list my ReferenceType? $type]]
			&& "CALLFRAME" ni $type
		    }
		}
		proc failType {type} {
		    uplevel 1 [list my FailureType? $type]
		}
		proc operandType {operand} {
		    uplevel 1 [list my OperandType $operand]
		}
		proc consumed {var search} {
		    uplevel 1 [list my IsConsumed $var $search]
		}
		proc callframe {operand} {
		    uplevel 1 [list my IsCallFrame $operand]
		}
		proc maybetype {operand type} {
		    uplevel 1 [list my MayBeType $operand $type]
		}
		proc impure {type} {
		    expr {"IMPURE" in $type}
		}
	    }
	}
    }

    # TclCompiler:ByteCode --
    #
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
    #
    # Results:
    #	None.

    method PrintTypedQuads {channel qs} {
	set idx -1
	set descriptions [lmap q $qs {



	    concat "[incr idx]:" $q ":" [linsert [lmap arg [lrange $q 1 end] {
		try {
		    if {$arg eq ""} {
			string cat VOID
		    } elseif {[string match {pc *} $arg]} {
			string cat BLOCK
		    } else {
			my ValueTypes $arg
		    }
		} on error {} {
		    string cat VOID
		}
	    }] 1 \u21d0]

	}]
	if {$channel eq ""} {
	    return [format "%s------>\n%s" $cmd [join $descriptions \n]]
	} else {
	    puts $channel [format "%s------>\n%s" $cmd [join $descriptions \n]]
	}
    }







>
>
>
|
|
|
|
|
|
|
|
|
|
|
|
|
>







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
    #
    # Results:
    #	None.

    method PrintTypedQuads {channel qs} {
	set idx -1
	set descriptions [lmap q $qs {
	    if {[string match @debug-* [lindex $q 0]]} {
		concat "[incr idx]:" $q
	    } else {
		concat "[incr idx]:" $q ":" [linsert [lmap arg [lrange $q 1 end] {
		    try {
			if {$arg eq ""} {
			    string cat VOID
			} elseif {[string match {pc *} $arg]} {
			    string cat BLOCK
			} else {
			    my ValueTypes $arg
			}
		    } on error {} {
			string cat VOID
		    }
		}] 1 "\u21d0"]
	    }
	}]
	if {$channel eq ""} {
	    return [format "%s------>\n%s" $cmd [join $descriptions \n]]
	} else {
	    puts $channel [format "%s------>\n%s" $cmd [join $descriptions \n]]
	}
    }
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
	# NB: block(-1) is the function entry block. It's supposed to be
	# almost entirely optimized out.
	$block(-1) build-in $b
	$b @location 0
	set errorCode [$b alloc int "tcl.errorCode"]
	set curr_block $block(-1)
	set 0 [$b int 0]


	##############################################################
	#
	# Create debug info for variables in LLVM

	dict for {name typecode} $vtypes {
	    lassign $name kind formalname origin
	    set type [nameOfType $typecode]

	    # Make the debugging information for the variable provided it is a
	    # variable as perceived from the Tcl level. "Internal" temporary
	    # variables aren't nearly so interesting.

	    if {$kind eq "var"} {
		if {[lindex $quads $origin 0] eq "param"} {
		    set idx [lsearch $bytecodeVars \
			[list "scalar arg" $formalname]]
		    if {$idx < 0} {
			return -code error \
			    "unmapped formal variable name: $formalname ($name)"
		    }







>













|







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
	# NB: block(-1) is the function entry block. It's supposed to be
	# almost entirely optimized out.
	$block(-1) build-in $b
	$b @location 0
	set errorCode [$b alloc int "tcl.errorCode"]
	set curr_block $block(-1)
	set 0 [$b int 0]
	$b store [Const 0 int] $errorCode

	##############################################################
	#
	# Create debug info for variables in LLVM

	dict for {name typecode} $vtypes {
	    lassign $name kind formalname origin
	    set type [nameOfType $typecode]

	    # Make the debugging information for the variable provided it is a
	    # variable as perceived from the Tcl level. "Internal" temporary
	    # variables aren't nearly so interesting.

	    if {var($name)} {
		if {[lindex $quads $origin 0] eq "param"} {
		    set idx [lsearch $bytecodeVars \
			[list "scalar arg" $formalname]]
		    if {$idx < 0} {
			return -code error \
			    "unmapped formal variable name: $formalname ($name)"
		    }
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
			my Warn "default injection for parameter %d of '%s'; injecting '%s'" \
			    [expr {$idx + 1}] [GetValueName [$func ref]] $defaultvalue
			set var [my LoadTypedLiteral $defaultvalue $type]
		    } else {
			set var [$func param $idx $name]
		    }
		    set variables($tgt) $var
		    if {[regexp {^IMPURE } $type]} {
			set var [$b stringifyImpure $var]
			set type STRING
		    }
		    if {refType($type)} {
			$b printref $var "param:"
			$b addReference($type) $var
			$b assume [$b shared $var]
		    }
		}
		"moveToCallFrame" {
		    set mapping [lassign $l opcode tgt src]
		    if {callframe($src)} {
			foreach {name value} $mapping {
			    set name [lindex $name 1]
			    set var [dict get $thevarmap $name]
			    if {$value ne "Nothing"} {
				set op frame.store([my ValueTypes $value])
				set value [my LoadOrLiteral $value]
				$b $op $value $theframe $var $name
			    } else {
				$b frame.unset $theframe $var $name
			    }
			}
		    }
		    my StoreResult $tgt [my LoadOrLiteral $src]
		}
		"retrieveResult" {
		    lassign $l opcode tgt src
		    if {[my ValueTypes $src] eq "CALLFRAME"} {
			set value [$b undef NOTHING]
		    } elseif {"CALLFRAME" in [my ValueTypes $src]} {
			set value [$b frame.value [my LoadOrLiteral $src]]
		    } else {
			set value [my LoadOrLiteral $src]
			my Warn "retrieveResult from non-callframe"
		    }
		    my StoreResult $tgt $value
		}
		"extractCallFrame" {
		    lassign $l opcode tgt src
		    if {callframe($src)} {
			set value [my LoadOrLiteral $src]
			if {[my ValueTypes $src] ne "CALLFRAME"} {
			    set name [my LocalVarName $tgt]
			    set value [$b frame.frame $value $name]
			}
		    } else {
			set value $theframe
		    }
		    my StoreResult $tgt $value







|
















|











|

|











|







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
			my Warn "default injection for parameter %d of '%s'; injecting '%s'" \
			    [expr {$idx + 1}] [GetValueName [$func ref]] $defaultvalue
			set var [my LoadTypedLiteral $defaultvalue $type]
		    } else {
			set var [$func param $idx $name]
		    }
		    set variables($tgt) $var
		    if {impure($type) && "LIST" ni $type && "DICT" ni $type} {
			set var [$b stringifyImpure $var]
			set type STRING
		    }
		    if {refType($type)} {
			$b printref $var "param:"
			$b addReference($type) $var
			$b assume [$b shared $var]
		    }
		}
		"moveToCallFrame" {
		    set mapping [lassign $l opcode tgt src]
		    if {callframe($src)} {
			foreach {name value} $mapping {
			    set name [lindex $name 1]
			    set var [dict get $thevarmap $name]
			    if {$value ne "Nothing"} {
				set op frame.store([my OperandType $value])
				set value [my LoadOrLiteral $value]
				$b $op $value $theframe $var $name
			    } else {
				$b frame.unset $theframe $var $name
			    }
			}
		    }
		    my StoreResult $tgt [my LoadOrLiteral $src]
		}
		"retrieveResult" {
		    lassign $l opcode tgt src
		    if {operandType($src) eq "CALLFRAME"} {
			set value [$b undef NOTHING]
		    } elseif {callframe($src)} {
			set value [$b frame.value [my LoadOrLiteral $src]]
		    } else {
			set value [my LoadOrLiteral $src]
			my Warn "retrieveResult from non-callframe"
		    }
		    my StoreResult $tgt $value
		}
		"extractCallFrame" {
		    lassign $l opcode tgt src
		    if {callframe($src)} {
			set value [my LoadOrLiteral $src]
			if {operandType($src) ne "CALLFRAME"} {
			    set name [my LocalVarName $tgt]
			    set value [$b frame.frame $value $name]
			}
		    } else {
			set value $theframe
		    }
		    my StoreResult $tgt $value
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
			my StoreResult $tgt \
			    [$b frame.load $theframe $var $vname $name]
		    }
		}
		"result" {
		    lassign $l opcode tgt src
		    set name [my LocalVarName $tgt]
		    append opcode ( [my ValueTypes $src] )
		    set src [my LoadOrLiteral $src]
		    my StoreResult $tgt [$b $opcode $src $name]
		}
		"returnOptions" {
		    lassign $l opcode tgt src ecode
		    set srcs [lassign $l opcode tgt]
		    set name [my LocalVarName $tgt]
		    append opcode ( [my ValueTypes {*}$srcs] )
		    set srcs [lmap s $srcs {my LoadOrLiteral $s}]
		    my StoreResult $tgt [$b $opcode {*}$srcs $name]
		}
		"nsupvar" - "upvar" - "variable" {
		    set srcs [lassign $l opcode tgt src]
		    set localvar [lindex $srcs 0]
		    if {[lindex $localvar 0] ne "literal"} {
			error "local variable must be literal"
		    }
		    set name [my LocalVarName $tgt]
		    set var [dict get $thevarmap [lindex $localvar 1]]
		    set op [dict get {
			nsupvar  frame.bind.nsvar
			upvar	 frame.bind.upvar
			variable frame.bind.var
		    } $opcode]
		    append op ( [my ValueTypes {*}$srcs] )
		    set srcs [lmap s $srcs {my LoadOrLiteral $s}]
		    set res [$b $op {*}$srcs $var $theframe $errorCode $name]
		    if {"FAIL" in [my ValueTypes $tgt]} {
			my SetErrorLine $errorCode \
			    [$b maybe [$b frame.value $res]]
		    }
		    my StoreResult $tgt $res
		}
		"bitor" - "bitxor" - "bitand" - "lshift" - "rshift" -
		"add" - "sub" - "mult" - "uminus" - "uplus" - "land" - "lor" -







|














|












|







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
			my StoreResult $tgt \
			    [$b frame.load $theframe $var $vname $name]
		    }
		}
		"result" {
		    lassign $l opcode tgt src
		    set name [my LocalVarName $tgt]
		    append opcode ( [my OperandType $src] )
		    set src [my LoadOrLiteral $src]
		    my StoreResult $tgt [$b $opcode $src $name]
		}
		"returnOptions" {
		    lassign $l opcode tgt src ecode
		    set srcs [lassign $l opcode tgt]
		    set name [my LocalVarName $tgt]
		    append opcode ( [my ValueTypes {*}$srcs] )
		    set srcs [lmap s $srcs {my LoadOrLiteral $s}]
		    my StoreResult $tgt [$b $opcode {*}$srcs $name]
		}
		"nsupvar" - "upvar" - "variable" {
		    set srcs [lassign $l opcode tgt src]
		    set localvar [lindex $srcs 0]
		    if {!literal($localvar)} {
			error "local variable must be literal"
		    }
		    set name [my LocalVarName $tgt]
		    set var [dict get $thevarmap [lindex $localvar 1]]
		    set op [dict get {
			nsupvar  frame.bind.nsvar
			upvar	 frame.bind.upvar
			variable frame.bind.var
		    } $opcode]
		    append op ( [my ValueTypes {*}$srcs] )
		    set srcs [lmap s $srcs {my LoadOrLiteral $s}]
		    set res [$b $op {*}$srcs $var $theframe $errorCode $name]
		    if {"FAIL" in operandType($tgt)} {
			my SetErrorLine $errorCode \
			    [$b maybe [$b frame.value $res]]
		    }
		    my StoreResult $tgt $res
		}
		"bitor" - "bitxor" - "bitand" - "lshift" - "rshift" -
		"add" - "sub" - "mult" - "uminus" - "uplus" - "land" - "lor" -
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
		}
		"originCmd" {
		    set srcs [lassign $l opcode tgt]
		    set name [my LocalVarName $tgt]
		    append opcode ( [my ValueTypes {*}$srcs] )
		    set srcs [lmap s $srcs {my LoadOrLiteral $s}]
		    set res [$b $opcode {*}$srcs $errorCode $name]
		    if {"FAIL" in [my ValueTypes $tgt]} {
			my SetErrorLine $errorCode [$b maybe $res]
		    }
		    my StoreResult $tgt $res
		}
		"list" {
		    set srcs [lassign $l opcode tgt]
		    set name [my LocalVarName $tgt]
		    set types [split [my ValueTypes {*}$srcs] ,]
		    set srcs [lmap s $srcs {my LoadOrLiteral $s}]
		    my StoreResult $tgt [$b list $objv $srcs $types $name]
		}
		"strindex" {
		    set srcs [lassign $l opcode tgt]
		    set name [my LocalVarName $tgt]
		    set srcs [my ConvertIndices 0 strlen 1]
		    set res [$b $opcode {*}$srcs $errorCode $name]
		    if {"FAIL" in [my ValueTypes $tgt]} {
			my SetErrorLine $errorCode [$b maybe $res]
		    }
		    my StoreResult $tgt $res
		}
		"strrange" - "strreplace" {
		    set srcs [lassign $l opcode tgt]
		    set name [my LocalVarName $tgt]
		    set srcs [my ConvertIndices 0 strlen 1 2]
		    set res [$b $opcode {*}$srcs $errorCode $name]
		    if {"FAIL" in [my ValueTypes $tgt]} {
			my SetErrorLine $errorCode [$b maybe $res]
		    }
		    my StoreResult $tgt $res
		}
		"directGet" - "directSet" - "directAppend" - "directLappend" -
		"directLappendList" - "directUnset" -
		"directArrayGet" - "directArraySet" - "directArrayAppend" -
		"directArrayLappend" - "directArrayLappendList" -
		"directArrayUnset" - "directIsArray" - "directMakeArray" -
		"regexp" - "listLength" -
		"listIn" - "listNotIn" - "dictIterStart" -
		"dictAppend" - "dictIncr" - "dictLappend" - "dictSize" -
		"div" - "expon" - "mod" - "verifyList" -
		"dictGetOrNexist" - "dictSetOrUnset" {
		    set srcs [lassign $l opcode tgt]
		    set name [my LocalVarName $tgt]
		    append opcode ( [my ValueTypes {*}$srcs] )
		    set srcs [lmap s $srcs {my LoadOrLiteral $s}]

		    set res [$b $opcode {*}$srcs $errorCode $name]
		    if {"FAIL" in [my ValueTypes $tgt]} {
			my SetErrorLine $errorCode [$b maybe $res]


		    }
		    my StoreResult $tgt $res
		}
		"listAppend" - "listConcat" - "listRange" {
		    set srcs [lassign $l opcode tgt]
		    set src1 [lindex $srcs 0]
		    set name [my LocalVarName $tgt]
		    append opcode ( [my ValueTypes {*}$srcs] )
		    set srcs [lmap s $srcs {my LoadOrLiteral $s}]


		    if {consumed($src1, $pc + 1)} {

			set res [$b $opcode {*}$srcs $errorCode $name]
		    } else {

			$b addReference([my ValueTypes $src1]) [lindex $srcs 0]
			set res [$b $opcode {*}$srcs $errorCode $name]
			$b dropReference([my ValueTypes $src1]) [lindex $srcs 0]
		    }
		    if {"FAIL" in [my ValueTypes $tgt]} {
			my SetErrorLine $errorCode [$b maybe $res]
		    }
		    my StoreResult $tgt $res
		}
		"returnCode" {
		    lassign $l opcode tgt src
		    set name [my LocalVarName $tgt]
		    append opcode ( [my ValueTypes $src] )
		    my StoreResult $tgt \
			[$b $opcode [my LoadOrLiteral $src] \
			     [$b load $errorCode] $name]
		}
		"initException" {
		    my IssueException $l
		}
		"setReturnCode" {
		    lassign $l opcode tgt src
		    append opcode ( [my ValueTypes $src] )
		    my StoreResult $tgt \
			[$b $opcode [my LoadOrLiteral $src] $errorCode]
		}
		"procLeave" {
		    set srcs [lassign $l opcode tgt]
		    set name [my LocalVarName $tgt]
		    append opcode ( [my ValueTypes {*}$srcs] )







|
















|









|


















>
|
<

>
>









>
>

>
|

>
|
|
|

|







|









|







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
		}
		"originCmd" {
		    set srcs [lassign $l opcode tgt]
		    set name [my LocalVarName $tgt]
		    append opcode ( [my ValueTypes {*}$srcs] )
		    set srcs [lmap s $srcs {my LoadOrLiteral $s}]
		    set res [$b $opcode {*}$srcs $errorCode $name]
		    if {"FAIL" in operandType($tgt)} {
			my SetErrorLine $errorCode [$b maybe $res]
		    }
		    my StoreResult $tgt $res
		}
		"list" {
		    set srcs [lassign $l opcode tgt]
		    set name [my LocalVarName $tgt]
		    set types [split [my ValueTypes {*}$srcs] ,]
		    set srcs [lmap s $srcs {my LoadOrLiteral $s}]
		    my StoreResult $tgt [$b list $objv $srcs $types $name]
		}
		"strindex" {
		    set srcs [lassign $l opcode tgt]
		    set name [my LocalVarName $tgt]
		    set srcs [my ConvertIndices 0 strlen 1]
		    set res [$b $opcode {*}$srcs $errorCode $name]
		    if {"FAIL" in operandType($tgt)} {
			my SetErrorLine $errorCode [$b maybe $res]
		    }
		    my StoreResult $tgt $res
		}
		"strrange" - "strreplace" {
		    set srcs [lassign $l opcode tgt]
		    set name [my LocalVarName $tgt]
		    set srcs [my ConvertIndices 0 strlen 1 2]
		    set res [$b $opcode {*}$srcs $errorCode $name]
		    if {"FAIL" in operandType($tgt)} {
			my SetErrorLine $errorCode [$b maybe $res]
		    }
		    my StoreResult $tgt $res
		}
		"directGet" - "directSet" - "directAppend" - "directLappend" -
		"directLappendList" - "directUnset" -
		"directArrayGet" - "directArraySet" - "directArrayAppend" -
		"directArrayLappend" - "directArrayLappendList" -
		"directArrayUnset" - "directIsArray" - "directMakeArray" -
		"regexp" - "listLength" -
		"listIn" - "listNotIn" - "dictIterStart" -
		"dictAppend" - "dictIncr" - "dictLappend" - "dictSize" -
		"div" - "expon" - "mod" - "verifyList" -
		"dictGetOrNexist" - "dictSetOrUnset" {
		    set srcs [lassign $l opcode tgt]
		    set name [my LocalVarName $tgt]
		    append opcode ( [my ValueTypes {*}$srcs] )
		    set srcs [lmap s $srcs {my LoadOrLiteral $s}]
		    if {"FAIL" in operandType($tgt)} {
			set res [$b $opcode {*}$srcs $errorCode $name]

			my SetErrorLine $errorCode [$b maybe $res]
		    } else {
			set res [$b $opcode {*}$srcs $name]
		    }
		    my StoreResult $tgt $res
		}
		"listAppend" - "listConcat" - "listRange" {
		    set srcs [lassign $l opcode tgt]
		    set src1 [lindex $srcs 0]
		    set name [my LocalVarName $tgt]
		    append opcode ( [my ValueTypes {*}$srcs] )
		    set srcs [lmap s $srcs {my LoadOrLiteral $s}]
		    set canFail [expr {"FAIL" in operandType($tgt)}]
		    set ec [if {$canFail} {list $errorCode}]
		    if {consumed($src1, $pc + 1)} {
			$b printref [lindex $srcs 0] "[lindex $l 0 0]:A:"
			set res [$b $opcode {*}$srcs {*}$ec $name]
		    } else {
			$b printref [lindex $srcs 0] "[lindex $l 0 0]:B:"
			$b addReference([my OperandType $src1]) [lindex $srcs 0]
			set res [$b $opcode {*}$srcs {*}$ec $name]
			$b dropReference([my OperandType $src1]) [lindex $srcs 0]
		    }
		    if {$canFail} {
			my SetErrorLine $errorCode [$b maybe $res]
		    }
		    my StoreResult $tgt $res
		}
		"returnCode" {
		    lassign $l opcode tgt src
		    set name [my LocalVarName $tgt]
		    append opcode ( [my OperandType $src] )
		    my StoreResult $tgt \
			[$b $opcode [my LoadOrLiteral $src] \
			     [$b load $errorCode] $name]
		}
		"initException" {
		    my IssueException $l
		}
		"setReturnCode" {
		    lassign $l opcode tgt src
		    append opcode ( [my OperandType $src] )
		    my StoreResult $tgt \
			[$b $opcode [my LoadOrLiteral $src] $errorCode]
		}
		"procLeave" {
		    set srcs [lassign $l opcode tgt]
		    set name [my LocalVarName $tgt]
		    append opcode ( [my ValueTypes {*}$srcs] )
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
		    set srcs [lassign $l opcode tgt srcObj]
		    set name [my LocalVarName $tgt]
		    if {[llength $srcs] == 1} {
			# Simple case
			set srcs [list $srcObj {*}$srcs]
			append opcode ( [my ValueTypes {*}$srcs] )
			set srcs [lmap s $srcs {my LoadOrLiteral $s}]
			set res [$b $opcode {*}$srcs $errorCode $name]
			my StoreResult $tgt $res
		    } else {
			# Need to construct the variadic path
			set vectortypes [lmap s $srcs {my ValueTypes $s}]
			set vector [$b buildVector $objv $vectortypes \
				  [lmap s $srcs {my LoadOrLiteral $s}]]
			append opcode ( [my ValueTypes $srcObj] )
			set srcObj [my LoadOrLiteral $srcObj]
			set res [$b $opcode $srcObj $vector $errorCode $name]
			my StoreResult $tgt $res
			$b clearVector $vector
		    }
		    if {"FAIL" in [my ValueTypes $tgt]} {
			my SetErrorLine $errorCode [$b maybe $res]
		    }
		}
		"dictSet" - "listSet" {


























		    set srcs [lassign $l opcode tgt srcObj srcValue]
		    set name [my LocalVarName $tgt]
		    if {[llength $srcs] == 1} {
			# Simple case
			set srcs [list $srcObj {*}$srcs $srcValue]
			append opcode ( [my ValueTypes {*}$srcs] )
			set srcs [lmap s $srcs {my LoadOrLiteral $s}]
			set res [$b $opcode {*}$srcs $errorCode $name]
			my StoreResult $tgt $res
		    } else {
			# Need to construct the variadic path
			set vectortypes [lmap s $srcs {my ValueTypes $s}]
			set vector [$b buildVector $objv $vectortypes \
				  [lmap s $srcs {my LoadOrLiteral $s}]]
			set srcs [list $srcObj $srcValue]
			append opcode ( [my ValueTypes {*}$srcs] )
			set srcs [lmap s $srcs {my LoadOrLiteral $s}]
			set res [$b $opcode {*}$srcs $vector $errorCode $name]
			my StoreResult $tgt $res
			$b clearVector $vector
		    }
		    if {"FAIL" in [my ValueTypes $tgt]} {
			my SetErrorLine $errorCode [$b maybe $res]
		    }
		}
		"copy" - "expand" {
		    lassign $l opcode tgt src
		    set value [my LoadOrLiteral $src]
		    set type [my OperandType $tgt]
		    set name [my LocalVarName $tgt]
		    SetValueName $value $name
		    if {refType($type)} {
			$b addReference($type) $value
			$b printref $value "copy:"
		    }
		    my StoreResult $tgt $value
		}
		"maptoint" {
		    lassign $l opcode tgt src map def
		    set map [lindex $map 1]
		    set def [lindex $def 1]
		    set name [my LocalVarName $tgt]
		    append opcode ( [my ValueTypes $src] )
		    set src [my LoadOrLiteral $src]
		    my StoreResult $tgt [$b $opcode $src $map $def $name]
		}
		"extractExists" - "extractMaybe" {
		    my IssueExtract $l
		}
		"extractFail" {
		    lassign $l opcode tgt src
		    set name [my LocalVarName $tgt]
		    append opcode ( [my ValueTypes $src] )
		    set src [my LoadOrLiteral $src]
		    my StoreResult $tgt [$b $opcode $src $name]
		}
		"purify" {
		    lassign $l opcode tgt src
		    set value [my LoadOrLiteral $src]
		    if {![regexp {^IMPURE} [my OperandType $src]]} {

			return -code error \
			    "Trying to purify something that is not impure"
		    }
		    set name [my LocalVarName $tgt]

		    set value [$b impure.value $value $name]

		    set type [my OperandType $tgt]
		    if {refType($type)} {
			$b addReference($type) $value
			$b printref $value "purify:"
		    }
		    my StoreResult $tgt $value
		}
		"free" {
		    lassign $l opcode tgt src
		    set type [my OperandType $src]
		    if {$src ni $consumed} {
			if {$type eq "VOID"} {
			    # VOID is trivial to free
			} elseif {refType($type)} {
			    $b printref $variables($src) "free:"

			    if {"ARRAY" in [my ValueTypes $src]} {
				# TRICKY POINT: need variable name to unset an array
				set name [Const [my LocalVarName $tgt] STRING]
				$b dropReference([my ValueTypes $src]) $variables($src) $name
			    } else {
				$b dropReference([my ValueTypes $src]) $variables($src)
			    }
			}
			lappend consumed $src
		    }
		}
		"exists" {
		    lassign $l opcode tgt src







|



|


|





|



|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>











|









|




















|









|






|
>




>
|
>















>
|


|

|







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
		    set srcs [lassign $l opcode tgt srcObj]
		    set name [my LocalVarName $tgt]
		    if {[llength $srcs] == 1} {
			# Simple case
			set srcs [list $srcObj {*}$srcs]
			append opcode ( [my ValueTypes {*}$srcs] )
			set srcs [lmap s $srcs {my LoadOrLiteral $s}]
			set res [$b $opcode {*}$srcs $name]
			my StoreResult $tgt $res
		    } else {
			# Need to construct the variadic path
			set vectortypes [lmap s $srcs {my OperandType $s}]
			set vector [$b buildVector $objv $vectortypes \
				  [lmap s $srcs {my LoadOrLiteral $s}]]
			append opcode ( [my OperandType $srcObj] )
			set srcObj [my LoadOrLiteral $srcObj]
			set res [$b $opcode $srcObj $vector $errorCode $name]
			my StoreResult $tgt $res
			$b clearVector $vector
		    }
		    if {"FAIL" in operandType($tgt)} {
			my SetErrorLine $errorCode [$b maybe $res]
		    }
		}
		"dictSet" {
		    set srcs [lassign $l opcode tgt srcObj srcValue]
		    set name [my LocalVarName $tgt]
		    if {[llength $srcs] == 1} {
			# Simple case
			set srcs [list $srcObj {*}$srcs $srcValue]
			append opcode ( [my ValueTypes {*}$srcs] )
			set srcs [lmap s $srcs {my LoadOrLiteral $s}]
			set res [$b $opcode {*}$srcs $name]
			my StoreResult $tgt $res
		    } else {
			# Need to construct the variadic path
			set vectortypes [lmap s $srcs {my OperandType $s}]
			set vector [$b buildVector $objv $vectortypes \
				  [lmap s $srcs {my LoadOrLiteral $s}]]
			set srcs [list $srcObj $srcValue]
			append opcode ( [my ValueTypes {*}$srcs] )
			set srcs [lmap s $srcs {my LoadOrLiteral $s}]
			set res [$b $opcode {*}$srcs $vector $errorCode $name]
			my StoreResult $tgt $res
			$b clearVector $vector
		    }
		    if {"FAIL" in operandType($tgt)} {
			my SetErrorLine $errorCode [$b maybe $res]
		    }
		}
		"listSet" {
		    set srcs [lassign $l opcode tgt srcObj srcValue]
		    set name [my LocalVarName $tgt]
		    if {[llength $srcs] == 1} {
			# Simple case
			set srcs [list $srcObj {*}$srcs $srcValue]
			append opcode ( [my ValueTypes {*}$srcs] )
			set srcs [lmap s $srcs {my LoadOrLiteral $s}]
			set res [$b $opcode {*}$srcs $errorCode $name]
			my StoreResult $tgt $res
		    } else {
			# Need to construct the variadic path
			set vectortypes [lmap s $srcs {my OperandType $s}]
			set vector [$b buildVector $objv $vectortypes \
				  [lmap s $srcs {my LoadOrLiteral $s}]]
			set srcs [list $srcObj $srcValue]
			append opcode ( [my ValueTypes {*}$srcs] )
			set srcs [lmap s $srcs {my LoadOrLiteral $s}]
			set res [$b $opcode {*}$srcs $vector $errorCode $name]
			my StoreResult $tgt $res
			$b clearVector $vector
		    }
		    if {"FAIL" in operandType($tgt)} {
			my SetErrorLine $errorCode [$b maybe $res]
		    }
		}
		"copy" - "expand" {
		    lassign $l opcode tgt src
		    set value [my LoadOrLiteral $src]
		    set type [my OperandType $tgt]
		    set name [my LocalVarName $tgt]
		    SetValueName $value $name
		    if {refType($type)} {
			$b addReference($type) $value
			$b printref $value "copy:"
		    }
		    my StoreResult $tgt $value
		}
		"maptoint" {
		    lassign $l opcode tgt src map def
		    set map [lindex $map 1]
		    set def [lindex $def 1]
		    set name [my LocalVarName $tgt]
		    append opcode ( [my OperandType $src] )
		    set src [my LoadOrLiteral $src]
		    my StoreResult $tgt [$b $opcode $src $map $def $name]
		}
		"extractExists" - "extractMaybe" {
		    my IssueExtract $l
		}
		"extractFail" {
		    lassign $l opcode tgt src
		    set name [my LocalVarName $tgt]
		    append opcode ( [my OperandType $src] )
		    set src [my LoadOrLiteral $src]
		    my StoreResult $tgt [$b $opcode $src $name]
		}
		"purify" {
		    lassign $l opcode tgt src
		    set value [my LoadOrLiteral $src]
		    set srctype [my OperandType $src]
		    if {!impure($srctype)} {
			return -code error \
			    "Trying to purify something that is not impure"
		    }
		    set name [my LocalVarName $tgt]
		    if {"LIST" ni $srctype && "DICT" ni $srctype} {
			set value [$b impure.value $value $name]
		    }
		    set type [my OperandType $tgt]
		    if {refType($type)} {
			$b addReference($type) $value
			$b printref $value "purify:"
		    }
		    my StoreResult $tgt $value
		}
		"free" {
		    lassign $l opcode tgt src
		    set type [my OperandType $src]
		    if {$src ni $consumed} {
			if {$type eq "VOID"} {
			    # VOID is trivial to free
			} elseif {refType($type)} {
			    $b printref $variables($src) "free:"
			    set vt [my OperandType $src]
			    if {"ARRAY" in $vt} {
				# TRICKY POINT: need variable name to unset an array
				set name [Const [my LocalVarName $tgt] STRING]
				$b dropReference($vt) $variables($src) $name
			    } else {
				$b dropReference($vt) $variables($src)
			    }
			}
			lappend consumed $src
		    }
		}
		"exists" {
		    lassign $l opcode tgt src
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
			$b br $block($tgt)
		    }
		}
		"jumpTrue" {
		    lassign $l opcode tgt src
		    set name [my LocalVarName $src]
		    set tgt [lindex $tgt 1]
		    set mth isTrue([my ValueTypes $src])
		    set test [$b $mth [my LoadOrLiteral $src] test_$name]
		    $b condBr $test $block($tgt) $ipath($pc)
		}
		"jumpFalse" {
		    lassign $l opcode tgt src
		    set name [my LocalVarName $src]
		    set tgt [lindex $tgt 1]
		    set mth isTrue([my ValueTypes $src])
		    set test [$b $mth [my LoadOrLiteral $src] test_$name]
		    $b condBr $test $ipath($pc) $block($tgt)
		}
		"jump" {
		    $b br $block([lindex $l 1 1])
		}
		"return" {
		    lassign $l opcode -> frame src
		    set val [my LoadOrLiteral $src]
		    if {"CALLFRAME" in [my ValueTypes $src]} {
			# The CALLFRAME does not leave
			set val [$b frame.value $val]
		    }
		    set type [nameOfType $returnType]
		    if {refType($type)} {
			$b printref $val "ret:"
			if {literal($src)} {







|







|









|







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
			$b br $block($tgt)
		    }
		}
		"jumpTrue" {
		    lassign $l opcode tgt src
		    set name [my LocalVarName $src]
		    set tgt [lindex $tgt 1]
		    set mth isTrue([my OperandType $src])
		    set test [$b $mth [my LoadOrLiteral $src] test_$name]
		    $b condBr $test $block($tgt) $ipath($pc)
		}
		"jumpFalse" {
		    lassign $l opcode tgt src
		    set name [my LocalVarName $src]
		    set tgt [lindex $tgt 1]
		    set mth isTrue([my OperandType $src])
		    set test [$b $mth [my LoadOrLiteral $src] test_$name]
		    $b condBr $test $ipath($pc) $block($tgt)
		}
		"jump" {
		    $b br $block([lindex $l 1 1])
		}
		"return" {
		    lassign $l opcode -> frame src
		    set val [my LoadOrLiteral $src]
		    if {callframe($src)} {
			# The CALLFRAME does not leave
			set val [$b frame.value $val]
		    }
		    set type [nameOfType $returnType]
		    if {refType($type)} {
			$b printref $val "ret:"
			if {literal($src)} {
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
			}
		    }
		}
		"frameArgs" {
		    lassign $l opcode tgt src
		    set name [my LocalVarName $tgt]
		    set opcode frame.args
		    append opcode ( [my ValueTypes $src] )
		    set val [my LoadOrLiteral $src]
		    set result [$b $opcode $val $theframe $name]
		    my StoreResult $tgt $result
		}
		"frameDepth" {
		    lassign $l opcode tgt
		    set name [my LocalVarName $tgt]







|







875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
			}
		    }
		}
		"frameArgs" {
		    lassign $l opcode tgt src
		    set name [my LocalVarName $tgt]
		    set opcode frame.args
		    append opcode ( [my OperandType $src] )
		    set val [my LoadOrLiteral $src]
		    set result [$b $opcode $val $theframe $name]
		    my StoreResult $tgt $result
		}
		"frameDepth" {
		    lassign $l opcode tgt
		    set name [my LocalVarName $tgt]
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
			lappend consumed $src1
		    } else {
			set result [$b unshareCopy($type) $val $name]
		    }
		    $b printref $result "cat:"
		    foreach src $srcs {
			set val [my LoadOrLiteral $src]
			$b appendString([my ValueTypes $src]) $val $result
		    }
		    my StoreResult $tgt $result
		}
		"concat" {
		    set srcs [lassign $l opcode tgt]
		    # Need to construct the variadic vector
		    set vectortypes [lmap s $srcs {my ValueTypes $s}]
		    set vector [$b buildVector $objv $vectortypes \
			    [lmap s $srcs {my LoadOrLiteral $s}]]
		    set name [my LocalVarName $tgt]
		    set result [$b concat() $vector $name]
		    my StoreResult $tgt $result
		    $b clearVector $vector
		}
		"foreachStart" {
		    set srcs [lassign $l opcode tgt assign]
		    set listtypes [lmap s $srcs {my ValueTypes $s}]
		    set lists [lmap s $srcs {my LoadOrLiteral $s}]
		    set result [$b foreachStart \
				    [lindex $assign 1] $lists \
				    $listtypes $errorCode]
		    if {"FAIL" in [my ValueTypes $tgt]} {
			my SetErrorLine $errorCode [$b maybe $result]
		    }
		    my StoreResult $tgt $result
		}
		"unshareList" {
		    lassign $l opcode tgt src
		    set name [my LocalVarName $tgt]
		    append opcode ( [my ValueTypes $src] )
		    set result [$b $opcode [my LoadOrLiteral $src] $name]
		    my StoreResult $tgt $result
		}
		"foreachIter" - "foreachAdvance" - "foreachMayStep" -
		"dictIterKey" - "dictIterValue" - "dictIterDone" -
		"dictIterNext" {
		    lassign $l opcode tgt src







|






|









|




|







|







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
			lappend consumed $src1
		    } else {
			set result [$b unshareCopy($type) $val $name]
		    }
		    $b printref $result "cat:"
		    foreach src $srcs {
			set val [my LoadOrLiteral $src]
			$b appendString([my OperandType $src]) $val $result
		    }
		    my StoreResult $tgt $result
		}
		"concat" {
		    set srcs [lassign $l opcode tgt]
		    # Need to construct the variadic vector
		    set vectortypes [lmap s $srcs {my OperandType $s}]
		    set vector [$b buildVector $objv $vectortypes \
			    [lmap s $srcs {my LoadOrLiteral $s}]]
		    set name [my LocalVarName $tgt]
		    set result [$b concat() $vector $name]
		    my StoreResult $tgt $result
		    $b clearVector $vector
		}
		"foreachStart" {
		    set srcs [lassign $l opcode tgt assign]
		    set listtypes [lmap s $srcs {my OperandType $s}]
		    set lists [lmap s $srcs {my LoadOrLiteral $s}]
		    set result [$b foreachStart \
				    [lindex $assign 1] $lists \
				    $listtypes $errorCode]
		    if {"FAIL" in operandType($tgt)} {
			my SetErrorLine $errorCode [$b maybe $result]
		    }
		    my StoreResult $tgt $result
		}
		"unshareList" {
		    lassign $l opcode tgt src
		    set name [my LocalVarName $tgt]
		    append opcode ( [my OperandType $src] )
		    set result [$b $opcode [my LoadOrLiteral $src] $name]
		    my StoreResult $tgt $result
		}
		"foreachIter" - "foreachAdvance" - "foreachMayStep" -
		"dictIterKey" - "dictIterValue" - "dictIterDone" -
		"dictIterNext" {
		    lassign $l opcode tgt src
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
	set varmeta [dict get $bytecode variables]
	set argtypes {STRING}
	set arguments [list [list literal $cmd]]
	foreach vinfo $varmeta {
	    if {"arg" in [lindex $vinfo 0]} {
		set vname [list var [lindex $vinfo 1] [llength $arguments]]
		lappend arguments $vname
		lappend argtypes [my ValueTypes $vname]
	    }
	}

	# Patch in the extra variables discovered during quadcode analysis;
	# these are never arguments as Tcl always correctly puts those in the
	# original bytecode descriptor.
	set stdnames [lmap vinfo $varmeta {lindex $vinfo 1}]







|







1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
	set varmeta [dict get $bytecode variables]
	set argtypes {STRING}
	set arguments [list [list literal $cmd]]
	foreach vinfo $varmeta {
	    if {"arg" in [lindex $vinfo 0]} {
		set vname [list var [lindex $vinfo 1] [llength $arguments]]
		lappend arguments $vname
		lappend argtypes [my OperandType $vname]
	    }
	}

	# Patch in the extra variables discovered during quadcode analysis;
	# these are never arguments as Tcl always correctly puts those in the
	# original bytecode descriptor.
	set stdnames [lmap vinfo $varmeta {lindex $vinfo 1}]
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
    }

    method IssueInvokeFunction {tgt func arguments vname} {
	upvar 1 callframe callframe thecallframe thecallframe
	set BASETYPES {ZEROONE INT DOUBLE NUMERIC STRING}

	set result [$b call $func $arguments $vname]
	if {[my ValueTypes $tgt] eq "FAIL"} {
	    $b store $result $errorCode
	    my SetErrorLine $errorCode
	} else {
	    set ts [lmap t $BASETYPES {Type $t?}]
	    if {[TypeOf $result] in $ts} {
		$b store [$b extract $result 0] $errorCode
	    } elseif {[Type [TypeOf $result]?] eq [Type [my ValueTypes $tgt]]} {
		# Managed to prove non-failure in this case...
		set result [$b ok $result]
	    }
	    if {"FAIL" in [my ValueTypes $tgt]} {
		my SetErrorLine $errorCode [$b maybe $result]
	    }
	}

	if {callframe($thecallframe)} {
	    set result [$b frame.pack $callframe $result]
	}
	my StoreResult $tgt $result
    }

    method IssueInvokeCommand {tgt resolved arguments argvals vname} {
	upvar 1 callframe callframe thecallframe thecallframe

	set types [lmap s $arguments {my ValueTypes $s}]
	if {$resolved ne ""} {
	    # FIXME: this causes wrong "wrong # args" messages
	    set argvals [lreplace $argvals 0 0 $resolved]
	}
	set vector [$b buildVector $objv $types $argvals]
	set result [$b invoke $vector \
			[expr {callframe($thecallframe)}] $callframe \







|






|



|













|







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
    }

    method IssueInvokeFunction {tgt func arguments vname} {
	upvar 1 callframe callframe thecallframe thecallframe
	set BASETYPES {ZEROONE INT DOUBLE NUMERIC STRING}

	set result [$b call $func $arguments $vname]
	if {operandType($tgt) eq "FAIL"} {
	    $b store $result $errorCode
	    my SetErrorLine $errorCode
	} else {
	    set ts [lmap t $BASETYPES {Type $t?}]
	    if {[TypeOf $result] in $ts} {
		$b store [$b extract $result 0] $errorCode
	    } elseif {[Type [TypeOf $result]?] eq [Type [my OperandType $tgt]]} {
		# Managed to prove non-failure in this case...
		set result [$b ok $result]
	    }
	    if {"FAIL" in operandType($tgt)} {
		my SetErrorLine $errorCode [$b maybe $result]
	    }
	}

	if {callframe($thecallframe)} {
	    set result [$b frame.pack $callframe $result]
	}
	my StoreResult $tgt $result
    }

    method IssueInvokeCommand {tgt resolved arguments argvals vname} {
	upvar 1 callframe callframe thecallframe thecallframe

	set types [lmap s $arguments {my OperandType $s}]
	if {$resolved ne ""} {
	    # FIXME: this causes wrong "wrong # args" messages
	    set argvals [lreplace $argvals 0 0 $resolved]
	}
	set vector [$b buildVector $objv $types $argvals]
	set result [$b invoke $vector \
			[expr {callframe($thecallframe)}] $callframe \
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
    method IssueInvokeExpanded {callframe operation} {
	set arguments [lassign $operation opcode tgt thecallframe]
	set vname [my LocalVarName $tgt]
	set expandPositions [lmap s $arguments {
	    expr {"EXPANDED" in [my OperandType $s]}
	}]
	set argvals [lmap s $arguments {my LoadOrLiteral $s}]
	set types [lmap s $arguments {my ValueTypes $s}]
	set vector [$b buildVector $objv $types $argvals]
	set flags [$b buildBitArray $bitv $expandPositions]
	set result [$b invokeExpanded $vector $flags $errorCode $vname]
	my SetErrorLine $errorCode [$b maybe $result]
	if {callframe($thecallframe)} {
	    set result [$b frame.pack $callframe $result]
	}







|







1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
    method IssueInvokeExpanded {callframe operation} {
	set arguments [lassign $operation opcode tgt thecallframe]
	set vname [my LocalVarName $tgt]
	set expandPositions [lmap s $arguments {
	    expr {"EXPANDED" in [my OperandType $s]}
	}]
	set argvals [lmap s $arguments {my LoadOrLiteral $s}]
	set types [lmap s $arguments {my OperandType $s}]
	set vector [$b buildVector $objv $types $argvals]
	set flags [$b buildBitArray $bitv $expandPositions]
	set result [$b invokeExpanded $vector $flags $errorCode $vname]
	my SetErrorLine $errorCode [$b maybe $result]
	if {callframe($thecallframe)} {
	    set result [$b frame.pack $callframe $result]
	}
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
    #
    # Results:
    #	none

    method IssueWiden {operation} {
	lassign $operation opcode tgt src
	set name [my LocalVarName $tgt]
	set srctype [my ValueTypes $src]
	set tgttype [lindex $opcode 2]
	if {$tgttype eq ""} {
	    set tgttype [my OperandType $tgt]
	}
	if {$srctype in {"VOID" "NOTHING" "NEXIST"}} {
	    switch -glob -- $tgttype {
		"FAIL *" {
		    set t [lrange $tgttype 1 end]
		    set value [$b fail $t "" $name]
		}
		"NEXIST *" {
		    set t [lrange $tgttype 1 end]
		    set value [$b nothing $t $name]
		}
		"STRING" - "EMPTY" {
		    set value [my LoadOrLiteral "literal {}"]
		}
		default {
		    # Should be unreachable in practice
		    my Warn "widened void to %s; result is undef" $tgttype
		    set value [$b undef $tgttype]
		}







|














|







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
    #
    # Results:
    #	none

    method IssueWiden {operation} {
	lassign $operation opcode tgt src
	set name [my LocalVarName $tgt]
	set srctype [my OperandType $src]
	set tgttype [lindex $opcode 2]
	if {$tgttype eq ""} {
	    set tgttype [my OperandType $tgt]
	}
	if {$srctype in {"VOID" "NOTHING" "NEXIST"}} {
	    switch -glob -- $tgttype {
		"FAIL *" {
		    set t [lrange $tgttype 1 end]
		    set value [$b fail $t "" $name]
		}
		"NEXIST *" {
		    set t [lrange $tgttype 1 end]
		    set value [$b nothing $t $name]
		}
		"STRING" - "LIST" - "DICT" - "EMPTY" {
		    set value [my LoadOrLiteral "literal {}"]
		}
		default {
		    # Should be unreachable in practice
		    my Warn "widened void to %s; result is undef" $tgttype
		    set value [$b undef $tgttype]
		}
1411
1412
1413
1414
1415
1416
1417

1418
1419
1420
1421
1422
1423
1424
	    return [$b frame.pack $frame $value $name]
	} elseif {"CALLFRAME" in $tgttype} {
	    error "callframe injection"
	}

	# Handle FAIL-extended types
	if {"FAIL" eq $srctype && "FAIL" in $tgttype} {

	    # Implementation type of pure FAIL is int32 (Tcl result code)
	    set tgttype [lrange $tgttype 1 end]
	    return [$b fail $tgttype $value]
	} elseif {"FAIL" in $srctype && "FAIL" in $tgttype} {
	    set value [$b unmaybe $value]
	    set srctype [lrange $srctype 1 end]
	    set tgttype [lrange $tgttype 1 end]







>







1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
	    return [$b frame.pack $frame $value $name]
	} elseif {"CALLFRAME" in $tgttype} {
	    error "callframe injection"
	}

	# Handle FAIL-extended types
	if {"FAIL" eq $srctype && "FAIL" in $tgttype} {
	    my Warn "widen FAIL (%s) to %s" [PrintValueToString $value] $tgttype
	    # Implementation type of pure FAIL is int32 (Tcl result code)
	    set tgttype [lrange $tgttype 1 end]
	    return [$b fail $tgttype $value]
	} elseif {"FAIL" in $srctype && "FAIL" in $tgttype} {
	    set value [$b unmaybe $value]
	    set srctype [lrange $srctype 1 end]
	    set tgttype [lrange $tgttype 1 end]
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
		set tuple [$b arraystring.from.array $value]
	    } else {
		set svalue [my WidenedValue $value $srctype STRING]
		set tuple [$b arraystring.from.scalar $svalue]
	    }
	    return $tuple
	}







	# IMPURE to IMPURE - Copy the string value, and promote the
	# inner value

	if {[lindex $tgttype 0] eq "IMPURE"
		&& [lindex $srctype 0] eq "IMPURE"} {
	    set itgttype [lrange $tgttype 1 end]
	    set isrctype [lrange $srctype 1 end]
	    set ivalue [my WidenedValue [$b impure.value $value] \
			    $isrctype $itgttype]
	    set svalue [$b impure.string $value]
	    set value [$b impure $itgttype $svalue $ivalue $name]
	} elseif {[lindex $srctype 0] eq "IMPURE" && "STRING" in $tgttype} {
	    set value [$b stringifyImpure $value $name]
	} elseif {[regexp {^IMPURE (.*)$} $tgttype -> innertype]} {
	    set widened [my WidenedValue $value $srctype $innertype]
	    set value [$b packImpure($innertype) $widened $name]
	} elseif {$tgttype eq "ZEROONE BOOLEAN"} {
	    if {$srctype in {"ZEROONE" "BOOLEAN"}} {
		# do nothing - the internal reps are the same







>
>
>
>
>
>




|
<






|







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
		set tuple [$b arraystring.from.array $value]
	    } else {
		set svalue [my WidenedValue $value $srctype STRING]
		set tuple [$b arraystring.from.scalar $svalue]
	    }
	    return $tuple
	}

	# Variations of LIST and DICT go straight to STRING

	if {"STRING" in $tgttype && ("LIST" in $srctype || "DICT" in $srctype)} {
	    return $value
	}

	# IMPURE to IMPURE - Copy the string value, and promote the
	# inner value

	if {impure($tgttype) && impure($srctype)} {

	    set itgttype [lrange $tgttype 1 end]
	    set isrctype [lrange $srctype 1 end]
	    set ivalue [my WidenedValue [$b impure.value $value] \
			    $isrctype $itgttype]
	    set svalue [$b impure.string $value]
	    set value [$b impure $itgttype $svalue $ivalue $name]
	} elseif {impure($srctype) && "STRING" in $tgttype} {
	    set value [$b stringifyImpure $value $name]
	} elseif {[regexp {^IMPURE (.*)$} $tgttype -> innertype]} {
	    set widened [my WidenedValue $value $srctype $innertype]
	    set value [$b packImpure($innertype) $widened $name]
	} elseif {$tgttype eq "ZEROONE BOOLEAN"} {
	    if {$srctype in {"ZEROONE" "BOOLEAN"}} {
		# do nothing - the internal reps are the same
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514



1515
1516
1517
1518
1519
1520
1521
	    if {$srctype eq "DOUBLE"} {
		set value [$b packNumericDouble $value $name]
	    } else {
		set value [$b packNumericInt $value $name]
	    }
	} elseif {$srctype eq "EMPTY" && $tgttype eq "STRING"} {
	    set value [Const "" STRING]
	} elseif {$srctype ne $tgttype} {
	    my Warn "unimplemented convert from '%s' to '%s'" $srctype $tgttype
	}
	if {[Type $tgttype] eq [Type [TypeOf $value]?]} {
	    set value [$b ok $value]
	} elseif {[Type $tgttype] eq [Type [TypeOf $value]!]} {
	    set value [$b just $value]



	}
	return $value
    }

    # TclCompiler:IssueDictExists --
    #
    #	Generate the code for testing whether an element of a dictionary







<
<





>
>
>







1557
1558
1559
1560
1561
1562
1563


1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
	    if {$srctype eq "DOUBLE"} {
		set value [$b packNumericDouble $value $name]
	    } else {
		set value [$b packNumericInt $value $name]
	    }
	} elseif {$srctype eq "EMPTY" && $tgttype eq "STRING"} {
	    set value [Const "" STRING]


	}
	if {[Type $tgttype] eq [Type [TypeOf $value]?]} {
	    set value [$b ok $value]
	} elseif {[Type $tgttype] eq [Type [TypeOf $value]!]} {
	    set value [$b just $value]
	} elseif {[Type $srctype] ne [Type $tgttype]} {
	    # If the types didn't end up matching, we're in deep trouble now...
	    my Warn "unimplemented convert from '%s' to '%s'" $srctype $tgttype
	}
	return $value
    }

    # TclCompiler:IssueDictExists --
    #
    #	Generate the code for testing whether an element of a dictionary
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
	    return
	} elseif {[llength $srcs] == 0 && $srcDict eq "literal \uf8ff"} {
	    my StoreResult $tgt [my LoadOrLiteral "literal 0"]
	    return
	}

	# Need to construct the variadic vector
	set types [lmap s $srcs {my ValueTypes $s}]
	set vector [$b buildVector $objv $types \
		      [lmap s $srcs {my LoadOrLiteral $s}]]
	set name [my LocalVarName $tgt]
	append opcode ( [my ValueTypes $srcDict] )
	set srcDict [my LoadOrLiteral $srcDict]
	my StoreResult $tgt [$b $opcode $srcDict $vector $name]
	$b clearVector $vector
	return
    }

    # TclCompiler:IssueExtract --







|



|







1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
	    return
	} elseif {[llength $srcs] == 0 && $srcDict eq "literal \uf8ff"} {
	    my StoreResult $tgt [my LoadOrLiteral "literal 0"]
	    return
	}

	# Need to construct the variadic vector
	set types [lmap s $srcs {my OperandType $s}]
	set vector [$b buildVector $objv $types \
		      [lmap s $srcs {my LoadOrLiteral $s}]]
	set name [my LocalVarName $tgt]
	append opcode ( [my OperandType $srcDict] )
	set srcDict [my LoadOrLiteral $srcDict]
	my StoreResult $tgt [$b $opcode $srcDict $vector $name]
	$b clearVector $vector
	return
    }

    # TclCompiler:IssueExtract --
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
    # Results:
    #	none

    method IssueException {operation} {
	upvar 1 errorCode errorCode
	set srcs [lassign $operation opcode tgt src]
	set src2 [lindex $srcs 0]
	set maintype [my ValueTypes $src]
	set name [my LocalVarName $tgt]
	append opcode ( [my ValueTypes {*}$srcs] )
	set value [my LoadOrLiteral $src]

	# Check if we can issue more efficient code by understanding the
	# literals provided (if everything is non-literal, we can't do much).
	if {[llength $srcs] == 3 && literal($src2)} {







|







1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
    # Results:
    #	none

    method IssueException {operation} {
	upvar 1 errorCode errorCode
	set srcs [lassign $operation opcode tgt src]
	set src2 [lindex $srcs 0]
	set maintype [my OperandType $src]
	set name [my LocalVarName $tgt]
	append opcode ( [my ValueTypes {*}$srcs] )
	set value [my LoadOrLiteral $src]

	# Check if we can issue more efficient code by understanding the
	# literals provided (if everything is non-literal, we can't do much).
	if {[llength $srcs] == 3 && literal($src2)} {
1819
1820
1821
1822
1823
1824
1825
1826

1827


















1828
1829
1830
1831
1832
1833
1834
    #
    # Results:
    #	A Tcl boolean value.

    method IsCallFrame {operand} {
	variable ::quadcode::dataType::CALLFRAME

	return [expr {[lindex $operand 0] in {"var" "temp"}

		      && ([typeOfOperand $vtypes $operand] & $CALLFRAME) != 0}]


















    }

    # TclCompiler:ValueTypes --
    #
    #	Convert the sequence of arguments (to an opcode) into the type
    #	signature tuple to use with the name of the method in the Build class
    #	to enable automatic type widening.







|
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







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
    #
    # Results:
    #	A Tcl boolean value.

    method IsCallFrame {operand} {
	variable ::quadcode::dataType::CALLFRAME

	return [expr {
	    !literal($operand)
	    && ([typeOfOperand $vtypes $operand] & $CALLFRAME) != 0
	}]
    }

    # TclCompiler:MayBeBasicType --
    #
    #	Get whether a particular operand may be of a particular type.
    #
    # Parameters:
    #	operand -
    #		The operand to test the type of.
    #	type -	The name of the type (see quadcode/types.tcl)
    #
    # Results:
    #	A Tcl boolean value.

    method MayBeBasicType {operand type} {
	namespace upvar ::quadcode::dataType $type typecode
	return [expr {([typeOfOperand $vtypes $operand] & $typecode) != 0}]
    }

    # TclCompiler:ValueTypes --
    #
    #	Convert the sequence of arguments (to an opcode) into the type
    #	signature tuple to use with the name of the method in the Build class
    #	to enable automatic type widening.
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914

1915
1916
1917
1918
1919
1920
1921
	if {[info exist variables($desc)]} {
	    return $variables($desc)
	}
	if {$desc eq "Nothing"} {
	    # NEXIST special case
	    return "Nothing"
	}
	lassign $desc kind value
	if {$kind ne "literal"} {
	    return -code error "unsubstitutable argument: $desc"
	}

	set type [nameOfType [typeOfLiteral $value]]
	return [my LoadTypedLiteral $value $type]
    }

    # TclCompiler:LoadTypedLiteral --
    #
    #	Generate the code to create a LLVM value reference, given the







<
|


>







1980
1981
1982
1983
1984
1985
1986

1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
	if {[info exist variables($desc)]} {
	    return $variables($desc)
	}
	if {$desc eq "Nothing"} {
	    # NEXIST special case
	    return "Nothing"
	}

	if {!literal($desc)} {
	    return -code error "unsubstitutable argument: $desc"
	}
	lassign $desc -> value
	set type [nameOfType [typeOfLiteral $value]]
	return [my LoadTypedLiteral $value $type]
    }

    # TclCompiler:LoadTypedLiteral --
    #
    #	Generate the code to create a LLVM value reference, given the
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
    #
    # Maintainer note:
    #	DO NOT do reference count management in this function! It makes things
    #	leak or triggers use-after-free crashes. Leave that to the main
    #	compiler engine (and the STRING allocator) as that gets it right.

    method LoadTypedLiteral {value type} {
	if {[lindex $type 0] eq "IMPURE"} {
	    set sval [my LoadTypedLiteral $value STRING]
	    set itype [lrange $type 1 end]



	    set tval [my LoadTypedLiteral $value $itype]
	    return [$b impure $itype $sval $tval]
	} elseif {$type eq "DOUBLE"} {
	    return [ConstReal [Type $type] $value]
	} elseif {$type in {"ZEROONE" "BOOLEAN" "ZEROONE BOOLEAN"}} {
	    return [Const [expr {$value}] bool]
	} elseif {$type in {"INT" "ENTIER"}} {
	    return [$b int [expr {entier($value)}]]
	} elseif {$type in {"STRING" "EMPTY"}} {
	    set result [Const $value STRING]
	    $b assume [$b shared $result]
	    return $result
	} else {
	    return -code error \
		"unhandled type for literal \"${value}\": \"$type\""
	}







|


>
>
>








|







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
    #
    # Maintainer note:
    #	DO NOT do reference count management in this function! It makes things
    #	leak or triggers use-after-free crashes. Leave that to the main
    #	compiler engine (and the STRING allocator) as that gets it right.

    method LoadTypedLiteral {value type} {
	if {impure($type)} {
	    set sval [my LoadTypedLiteral $value STRING]
	    set itype [lrange $type 1 end]
	    if {$itype in {LIST DICT {EMPTY LIST} {EMPTY DICT}}} {
		return $sval
	    }
	    set tval [my LoadTypedLiteral $value $itype]
	    return [$b impure $itype $sval $tval]
	} elseif {$type eq "DOUBLE"} {
	    return [ConstReal [Type $type] $value]
	} elseif {$type in {"ZEROONE" "BOOLEAN" "ZEROONE BOOLEAN"}} {
	    return [Const [expr {$value}] bool]
	} elseif {$type in {"INT" "ENTIER"}} {
	    return [$b int [expr {entier($value)}]]
	} elseif {$type in {"STRING" "LIST" "DICT" "EMPTY" "EMPTY LIST" "EMPTY DICT"}} {
	    set result [Const $value STRING]
	    $b assume [$b shared $result]
	    return $result
	} else {
	    return -code error \
		"unhandled type for literal \"${value}\": \"$type\""
	}
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
    #	None.

    method StoreResult {desc value {opcode ""}} {

	upvar 1 phiAnnotations phiAnnotations

	# Validate that the destination is indeed a variable or temporary
	if {[lindex $desc 0] ni {"var" "temp"}} {
	    return -code error "cannot store into $desc; it makes no sense"
	}

	# Validate that SSA form has been preserved
	if {[info exists variables($desc)]} {
	    return -code error "Duplicate definition of $desc"
	}

	# Type check the assignment
	set destType [nameOfType [dict get $vtypes $desc]]
	if {[Type $destType] ne [TypeOf $value]} {
	    my Warn "Attempt to store the value '%s' into a variable, '%s', of type '%s'" \
		[PrintValueToString $value] $desc $destType
	}

	if {[lindex $desc 0] eq "var"} {
	    if {[lindex $opcode 0] eq "phi"} {
		lappend phiAnnotations [lindex $desc 1] $value
	    } else {
		my AnnotateAssignment [lindex $desc 1] $value
	    }
	}








|















|







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
    #	None.

    method StoreResult {desc value {opcode ""}} {

	upvar 1 phiAnnotations phiAnnotations

	# Validate that the destination is indeed a variable or temporary
	if {literal($desc)} {
	    return -code error "cannot store into $desc; it makes no sense"
	}

	# Validate that SSA form has been preserved
	if {[info exists variables($desc)]} {
	    return -code error "Duplicate definition of $desc"
	}

	# Type check the assignment
	set destType [nameOfType [dict get $vtypes $desc]]
	if {[Type $destType] ne [TypeOf $value]} {
	    my Warn "Attempt to store the value '%s' into a variable, '%s', of type '%s'" \
		[PrintValueToString $value] $desc $destType
	}

	if {var($desc)} {
	    if {[lindex $opcode 0] eq "phi"} {
		lappend phiAnnotations [lindex $desc 1] $value
	    } else {
		my AnnotateAssignment [lindex $desc 1] $value
	    }
	}

2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
    #	Boolean, true if the type is a reference type.

    method ReferenceType? {type} {
	if {[string is entier -strict $type]} {
	    set type [nameOfType $type]
	}
	foreach piece $type {
	    if {$piece in {IMPURE DICTITER EMPTY STRING ENTIER ARRAY}} {
		return 1
	    }
	}
	return 0
    }

    # TclCompiler:FailureType? --







|







2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
    #	Boolean, true if the type is a reference type.

    method ReferenceType? {type} {
	if {[string is entier -strict $type]} {
	    set type [nameOfType $type]
	}
	foreach piece $type {
	    if {$piece in {IMPURE DICTITER EMPTY STRING ENTIER ARRAY LIST DICT}} {
		return 1
	    }
	}
	return 0
    }

    # TclCompiler:FailureType? --
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196

2197
2198
2199
2200
2201
2202
2203
    # Parameters:
    #	qcval -	The quadcode value to extract from.
    #
    # Results:
    #	The Tcl value inside the quadcode value.

    method LiteralValue {qcval} {
	lassign $qcval key value
	if {$key ne "literal"} {
	    return -code error "assumption that '$qcval' is literal not met"
	}

	return $value
    }
}

# Class TclInterproceduralCompiler --
#
#	This class compiles a single Tcl procedure within the overall







<
|


>







2265
2266
2267
2268
2269
2270
2271

2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
    # Parameters:
    #	qcval -	The quadcode value to extract from.
    #
    # Results:
    #	The Tcl value inside the quadcode value.

    method LiteralValue {qcval} {

	if {!literal($qcval)} {
	    return -code error "assumption that '$qcval' is literal not met"
	}
	lassign $qcval -> value
	return $value
    }
}

# Class TclInterproceduralCompiler --
#
#	This class compiles a single Tcl procedure within the overall

Changes to codegen/stdlib.tcl.

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
    variable tcl.resolveCmd tcl.originCmd

    # Variables holding implementations of Tcl's list operators
    variable tcl.list.create tcl.list.length tcl.list.append tcl.list.concat
    variable tcl.list.foreach.getStep tcl.list.foreach.mayStep
    variable tcl.list.foreach.nextStep tcl.list.foreach.start.step
    variable tcl.list.foreach.start.finish tcl.list.unshare
    variable tcl.list.range tcl.list.range1 tcl.list.in
    variable tcl.list.index tcl.list.index1 tcl.list.indexList
    variable tcl.list.set tcl.list.set1 tcl.list.setList tcl.list.verify

    # Variables holding implementations of Tcl's dict operators
    variable tcl.dict.get1 tcl.dict.get tcl.dict.set1 tcl.dict.set
    variable tcl.dict.exists1 tcl.dict.exists tcl.dict.unset1 tcl.dict.unset
    variable tcl.dict.iterStart tcl.dict.iterNext tcl.dict.iterDone
    variable tcl.dict.iterKey tcl.dict.iterValue tcl.dict.addIterReference
    variable tcl.dict.addIterFailReference
    variable tcl.dict.dropIterReference tcl.dict.dropIterFailReference
    variable tcl.dict.append tcl.dict.lappend tcl.dict.incr tcl.dict.size
    variable tcl.dict.get1.empty tcl.dict.set1.empty
    variable tcl.maptoint

    # Variables holding implementations of Tcl's exception-handling machinery
    variable tcl.getresult tcl.getreturnopts tcl.initExceptionOptions
    variable tcl.initExceptionSimple tcl.processReturn tcl.procedure.return
    variable tcl.setErrorLine tcl.existsOrError tcl.logCommandInfo
    variable tcl.handleExceptionResult tcl.invoke.command tcl.invoke.expanded







|











|







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
    variable tcl.resolveCmd tcl.originCmd

    # Variables holding implementations of Tcl's list operators
    variable tcl.list.create tcl.list.length tcl.list.append tcl.list.concat
    variable tcl.list.foreach.getStep tcl.list.foreach.mayStep
    variable tcl.list.foreach.nextStep tcl.list.foreach.start.step
    variable tcl.list.foreach.start.finish tcl.list.unshare
    variable tcl.list.range tcl.list.range1 tcl.list.in tcl.isList
    variable tcl.list.index tcl.list.index1 tcl.list.indexList
    variable tcl.list.set tcl.list.set1 tcl.list.setList tcl.list.verify

    # Variables holding implementations of Tcl's dict operators
    variable tcl.dict.get1 tcl.dict.get tcl.dict.set1 tcl.dict.set
    variable tcl.dict.exists1 tcl.dict.exists tcl.dict.unset1 tcl.dict.unset
    variable tcl.dict.iterStart tcl.dict.iterNext tcl.dict.iterDone
    variable tcl.dict.iterKey tcl.dict.iterValue tcl.dict.addIterReference
    variable tcl.dict.addIterFailReference
    variable tcl.dict.dropIterReference tcl.dict.dropIterFailReference
    variable tcl.dict.append tcl.dict.lappend tcl.dict.incr tcl.dict.size
    variable tcl.dict.get1.empty tcl.dict.set1.empty tcl.isDict
    variable tcl.maptoint

    # Variables holding implementations of Tcl's exception-handling machinery
    variable tcl.getresult tcl.getreturnopts tcl.initExceptionOptions
    variable tcl.initExceptionSimple tcl.processReturn tcl.procedure.return
    variable tcl.setErrorLine tcl.existsOrError tcl.logCommandInfo
    variable tcl.handleExceptionResult tcl.invoke.command tcl.invoke.expanded
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
	#
	# Increment the reference count of a Tcl_Obj reference if the
	# object is supplied

	set f [$m local "tcl.addFailReference" void<-Tcl_Obj*?]
	params value:maybeObjPtr
	build {
	    my condBr [my maybe $value] $nothing $incr
	label incr "action.required"
	    set value [my unmaybe $value "objPtr"]
	    $api Tcl_IncrRefCount $value
	    my ret
	label nothing "nothing.to.do"
	    my ret
	}

	##### tcl.dropFailReference #####
	#
	# Type signature: objPtr:Tcl_Obj*? -> void
	#
	# Decrement the reference count of a Maybe containing a Tcl_Obj
	# reference, and delete it if the reference count drops to zero.

	set f [$m local "tcl.dropFailReference" void<-Tcl_Obj*?]
	params value:maybeObjPtr
	build {
	    my condBr [my maybe $value] $nothing $decr
	label decr "action.required"
	    set value [my unmaybe $value "objPtr"]
	    $api Tcl_DecrRefCount $value
	    my ret
	label nothing "nothing.to.do"
	    my ret
	}







|
|

















|







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
	#
	# Increment the reference count of a Tcl_Obj reference if the
	# object is supplied

	set f [$m local "tcl.addFailReference" void<-Tcl_Obj*?]
	params value:maybeObjPtr
	build {
	    my condBr [my maybe $value] $incr $nothing
	label incr "action.required.afr"
	    set value [my unmaybe $value "objPtr"]
	    $api Tcl_IncrRefCount $value
	    my ret
	label nothing "nothing.to.do"
	    my ret
	}

	##### tcl.dropFailReference #####
	#
	# Type signature: objPtr:Tcl_Obj*? -> void
	#
	# Decrement the reference count of a Maybe containing a Tcl_Obj
	# reference, and delete it if the reference count drops to zero.

	set f [$m local "tcl.dropFailReference" void<-Tcl_Obj*?]
	params value:maybeObjPtr
	build {
	    my condBr [my maybe $value] $decr $nothing
	label decr "action.required"
	    set value [my unmaybe $value "objPtr"]
	    $api Tcl_DecrRefCount $value
	    my ret
	label nothing "nothing.to.do"
	    my ret
	}
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
	#
	# Decrement the reference count of a Maybe Maybe containing a Tcl_Obj
	# reference, and delete it if the reference count drops to zero.

	set f [$m local "tcl.dropFailNExistReference" void<-Tcl_Obj*!?]
	params value:maybeObjPtr
	build {
	    my condBr [my maybe $value] $nothing $decr
	label decr "action.required"
	    my Call tcl.dropNExistReference [my unmaybe $value]
	    my ret
	label nothing "nothing.to.do"
	    my ret
	}








|







294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
	#
	# Decrement the reference count of a Maybe Maybe containing a Tcl_Obj
	# reference, and delete it if the reference count drops to zero.

	set f [$m local "tcl.dropFailNExistReference" void<-Tcl_Obj*!?]
	params value:maybeObjPtr
	build {
	    my condBr [my maybe $value] $decr $nothing
	label decr "action.required"
	    my Call tcl.dropNExistReference [my unmaybe $value]
	    my ret
	label nothing "nothing.to.do"
	    my ret
	}

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
	    my ret
	label gotNull "got.null"
	    set str [$api Tcl_ObjPrintf [my constString "%d:NULL\n"] $pr]
	    $api Tcl_WriteObj $chan $str
	    $api Tcl_DecrRefCount $str
	    my ret
	}
	set f [$m local writeref? void<-int,STRING?,char*]
	params pr val prefix
	build {
	    my condBr [my maybe $val] $done $print
	label print:
	    my Call writeref $pr [my unmaybe $val] $prefix
	    my ret
	label done:

	    my ret
	}
	set f [$m local writearef void<-int,ARRAY,char*]
	params pr val prefix
	build {
	    nonnull $val
	    set chan [$api Tcl_GetStdChannel [Const [expr 1<<3]]]
	    my condBr [my nonnull $prefix] $printPrefix $printRef
	label printPrefix "print.prefix"
	    set str [$api Tcl_NewStringObj $prefix [Const -1]]







|







>


|







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
	    my ret
	label gotNull "got.null"
	    set str [$api Tcl_ObjPrintf [my constString "%d:NULL\n"] $pr]
	    $api Tcl_WriteObj $chan $str
	    $api Tcl_DecrRefCount $str
	    my ret
	}
	set f [$m local writeref? void<-int,STRING?,char* noinline]
	params pr val prefix
	build {
	    my condBr [my maybe $val] $done $print
	label print:
	    my Call writeref $pr [my unmaybe $val] $prefix
	    my ret
	label done:
	    my Call writeref $pr {} $prefix
	    my ret
	}
	set f [$m local writearef void<-int,ARRAY,char* noinline]
	params pr val prefix
	build {
	    nonnull $val
	    set chan [$api Tcl_GetStdChannel [Const [expr 1<<3]]]
	    my condBr [my nonnull $prefix] $printPrefix $printRef
	label printPrefix "print.prefix"
	    set str [$api Tcl_NewStringObj $prefix [Const -1]]
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
	    my assume [my eq $before $after]
	    my ret $result
	}

	##### Function tcl.isPureByteArray #####
	##### Closure Build:isByteArray #####
	#
	# Type signature: objPtr:STRING -> int1
	#
	# Test if a STRING is actually a true byte array, that it can be
	# processed as bytes and not as unicode characters.

	set f [$m local "tcl.isPureByteArray" int1<-STRING readonly]
	params objPtr
	build {
	    nonnull $objPtr
	    set baType [$api tclByteArrayType]
	    set typePtr [my dereference $objPtr 0 Tcl_Obj.typePtr]
	    my condBr [my eq $baType $typePtr] $puretest $notBA
	label puretest:







|




|







688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
	    my assume [my eq $before $after]
	    my ret $result
	}

	##### Function tcl.isPureByteArray #####
	##### Closure Build:isByteArray #####
	#
	# Type signature: objPtr:STRING -> bool
	#
	# Test if a STRING is actually a true byte array, that it can be
	# processed as bytes and not as unicode characters.

	set f [$m local "tcl.isPureByteArray" bool<-STRING readonly]
	params objPtr
	build {
	    nonnull $objPtr
	    set baType [$api tclByteArrayType]
	    set typePtr [my dereference $objPtr 0 Tcl_Obj.typePtr]
	    my condBr [my eq $baType $typePtr] $puretest $notBA
	label puretest:
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
	my closure isByteArray {STRING {name ""}} {
	    my call ${tcl.isPureByteArray} [list $STRING] $name
	}

	##### Function tcl.isUnicodeString #####
	##### Closure Build:isUnicodeString #####
	#
	# Type signature: objPtr:STRING -> int1
	#
	# Test if a STRING is stored internally as a sequence of Tcl_UniChar
	# (instead of as a sequence of Unicode characters encoded as UTF-8).

	set f [$m local "tcl.isUnicodeString" int1<-STRING readonly]
	params objPtr
	build {
	    nonnull $objPtr
	    set strType [$api tclStringType]
	    set type [my dereference $objPtr 0 Tcl_Obj.typePtr]
	    my ret [my eq $type $strType]
	}
	my closure isUnicodeString {STRING {name ""}} {
	    my call ${tcl.isUnicodeString} [list $STRING] $name
	}

	##### Function tcl.impl.getBoolean #####
	##### MAPPED CALL TO METHOD: Build:GetBoolean #####
	#
	# Type signature: valueObj:STRING -> int1*int1

	set f [$m local "tcl.impl.getBoolean" struct{int1,int1}<-STRING]
	params valueObj
	build {
	    nonnull $valueObj
	    set boolVar [my alloc int32 "boolPtr"]
	    set str [$api Tcl_GetString $valueObj]
	    set code [$api Tcl_GetBooleanFromObj {} $valueObj $boolVar]
	    set res [my undef struct{int1,int1}]
	    set res [my insert $res [my eq $code [Const 0]] 0]
	    set res \
		[my insert $res [my neq [my load $boolVar "bool"] [Const 0]] 1]
	    my ret $res
	}
	my closure GetBoolean {valueObj} {
	    my call ${tcl.impl.getBoolean} [list $valueObj] "result"
	}
	unset -nocomplain valueObj
	

	##### Function tcl.impl.getDouble #####
	##### MAPPED CALL TO METHOD: Build:GetDouble #####
	#
	# Type signature: valueObj:STRING -> int * int8[]
	#
	# Gets the (pseudo-)UTF-8 version of a string. Wrapper around Tcl API
	# to ensure that scope lifetime gets better understood.

	set f [$m local "tcl.impl.getDouble" struct{int1,double}<-STRING]
	my closure GetDouble {valueObj} {
	    my call ${tcl.impl.getDouble} [list $valueObj] "result"
	}
	params valueObj
	build {
	    nonnull $valueObj
	    set dblVar [my alloc double "dblPtr"]
	    set code [$api Tcl_GetDoubleFromObj {} $valueObj $dblVar]
	    set res [my undef struct{int1,double}]
	    set res [my insert $res [my eq $code [Const 0]] 0]
	    set res [my insert $res [my load $dblVar "dbl"] 1]
	    my ret $res
	}
	unset -nocomplain valueObj

	##### Function tcl.impl.getWide #####
	##### MAPPED CALL TO METHOD: Build:GetWide #####
	#
	# Type signature: valueObj:STRING -> bool * int64
	#
	# Gets an int64 from a Tcl string. Wrapper around Tcl API to ensure
	# that scope lifetime gets better understood.

	set f [$m local "tcl.impl.getWide" struct{int1,int64}<-STRING]
	my closure GetWide {valueObj {name "result"}} {
	    my call ${tcl.impl.getWide} [list $valueObj] $name
	}
	params valueObj
	build {
	    nonnull $valueObj
	    set intVar [my alloc int64 "intPtr"]







|




|














|

|






|



















|








|














|







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
	my closure isByteArray {STRING {name ""}} {
	    my call ${tcl.isPureByteArray} [list $STRING] $name
	}

	##### Function tcl.isUnicodeString #####
	##### Closure Build:isUnicodeString #####
	#
	# Type signature: objPtr:STRING -> bool
	#
	# Test if a STRING is stored internally as a sequence of Tcl_UniChar
	# (instead of as a sequence of Unicode characters encoded as UTF-8).

	set f [$m local "tcl.isUnicodeString" bool<-STRING readonly]
	params objPtr
	build {
	    nonnull $objPtr
	    set strType [$api tclStringType]
	    set type [my dereference $objPtr 0 Tcl_Obj.typePtr]
	    my ret [my eq $type $strType]
	}
	my closure isUnicodeString {STRING {name ""}} {
	    my call ${tcl.isUnicodeString} [list $STRING] $name
	}

	##### Function tcl.impl.getBoolean #####
	##### MAPPED CALL TO METHOD: Build:GetBoolean #####
	#
	# Type signature: valueObj:STRING -> bool*bool

	set f [$m local "tcl.impl.getBoolean" struct{bool,bool}<-STRING]
	params valueObj
	build {
	    nonnull $valueObj
	    set boolVar [my alloc int32 "boolPtr"]
	    set str [$api Tcl_GetString $valueObj]
	    set code [$api Tcl_GetBooleanFromObj {} $valueObj $boolVar]
	    set res [my undef struct{bool,bool}]
	    set res [my insert $res [my eq $code [Const 0]] 0]
	    set res \
		[my insert $res [my neq [my load $boolVar "bool"] [Const 0]] 1]
	    my ret $res
	}
	my closure GetBoolean {valueObj} {
	    my call ${tcl.impl.getBoolean} [list $valueObj] "result"
	}
	unset -nocomplain valueObj
	

	##### Function tcl.impl.getDouble #####
	##### MAPPED CALL TO METHOD: Build:GetDouble #####
	#
	# Type signature: valueObj:STRING -> int * int8[]
	#
	# Gets the (pseudo-)UTF-8 version of a string. Wrapper around Tcl API
	# to ensure that scope lifetime gets better understood.

	set f [$m local "tcl.impl.getDouble" struct{bool,double}<-STRING]
	my closure GetDouble {valueObj} {
	    my call ${tcl.impl.getDouble} [list $valueObj] "result"
	}
	params valueObj
	build {
	    nonnull $valueObj
	    set dblVar [my alloc double "dblPtr"]
	    set code [$api Tcl_GetDoubleFromObj {} $valueObj $dblVar]
	    set res [my undef struct{bool,double}]
	    set res [my insert $res [my eq $code [Const 0]] 0]
	    set res [my insert $res [my load $dblVar "dbl"] 1]
	    my ret $res
	}
	unset -nocomplain valueObj

	##### Function tcl.impl.getWide #####
	##### MAPPED CALL TO METHOD: Build:GetWide #####
	#
	# Type signature: valueObj:STRING -> bool * int64
	#
	# Gets an int64 from a Tcl string. Wrapper around Tcl API to ensure
	# that scope lifetime gets better understood.

	set f [$m local "tcl.impl.getWide" struct{bool,int64}<-STRING]
	my closure GetWide {valueObj {name "result"}} {
	    my call ${tcl.impl.getWide} [list $valueObj] $name
	}
	params valueObj
	build {
	    nonnull $valueObj
	    set intVar [my alloc int64 "intPtr"]
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
	    set p5 [my phi [list $p2 $p4] [list $nextOuter $fixP] "p.5"]
	    my ret [my sub $numBytes1 [my cast(int) [my diff $p5 $bytes]]]
	}

	##### Function tcl.impl.isAscii #####
	# Replacement for non-exposed UniCharIsAscii
	#
	# Type signature: ch:int16 -> int1
	#
	# Part of quadcode implementation ('strclass')
	#
	# Returns whether the character 'ch' is in the ASCII range.

	set f [$m local "tcl.impl.isAscii" bool<-int16 readnone]
	params ch
	build {
	    my ret [my and [my ge $ch [Const 0 int16]] \
			[my lt $ch [Const 0x80 int16]]]
	}

	##### Function tcl.impl.isXdigit #####
	# Replacement for non-exposed UniCharIsXdigit
	#
	# Type signature: ch:int16 -> int1
	#
	# Part of quadcode implementation ('strclass')
	#
	# Returns whether the character 'ch' is a hex digit.

	set f [$m local "tcl.impl.isXdigit" bool<-int16 readnone]
	params ch







|















|







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
	    set p5 [my phi [list $p2 $p4] [list $nextOuter $fixP] "p.5"]
	    my ret [my sub $numBytes1 [my cast(int) [my diff $p5 $bytes]]]
	}

	##### Function tcl.impl.isAscii #####
	# Replacement for non-exposed UniCharIsAscii
	#
	# Type signature: ch:int16 -> bool
	#
	# Part of quadcode implementation ('strclass')
	#
	# Returns whether the character 'ch' is in the ASCII range.

	set f [$m local "tcl.impl.isAscii" bool<-int16 readnone]
	params ch
	build {
	    my ret [my and [my ge $ch [Const 0 int16]] \
			[my lt $ch [Const 0x80 int16]]]
	}

	##### Function tcl.impl.isXdigit #####
	# Replacement for non-exposed UniCharIsXdigit
	#
	# Type signature: ch:int16 -> bool
	#
	# Part of quadcode implementation ('strclass')
	#
	# Returns whether the character 'ch' is a hex digit.

	set f [$m local "tcl.impl.isXdigit" bool<-int16 readnone]
	params ch
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
	    my ret [Const true bool]
	label not:
	    my ret [Const false bool]
	}

	##### Function tcl.strclass #####
	#
	# Type signature: objPtr:STRING * class:int32 -> ZEROONE
	#
	# Quadcode implementation ('strclass')
	#
	# Returns whether all the characters in the string 'objPtr' are in the
	# character class given by 'class' (enumeration encoded as int32).

	set f [$m local "tcl.strclass" ZEROONE<-STRING,int]
	params objPtr class
	build {
	    nonnull $objPtr
	    lassign [my GetUnicode $objPtr obj] length string
	    my condBr [my gt $length $0] $test $match
	label test:
	    set end [my getelementptr $string [list $length]]







|






|







1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
	    my ret [Const true bool]
	label not:
	    my ret [Const false bool]
	}

	##### Function tcl.strclass #####
	#
	# Type signature: objPtr:STRING * class:int32 -> bool
	#
	# Quadcode implementation ('strclass')
	#
	# Returns whether all the characters in the string 'objPtr' are in the
	# character class given by 'class' (enumeration encoded as int32).

	set f [$m local "tcl.strclass" bool<-STRING,int]
	params objPtr class
	build {
	    nonnull $objPtr
	    lassign [my GetUnicode $objPtr obj] length string
	    my condBr [my gt $length $0] $test $match
	label test:
	    set end [my getelementptr $string [list $length]]
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
	    my ret [Const false bool]
	}

	##### Function tcl.impl.getIndex #####
	##### Closure Build:GetIndex #####
	#
	# Type signature: interp:Interp* * objPtr:Tcl_Obj* * end:int
	#			-> int1 * int
	#
	# Converts an index string into an offset into something (i.e., a
	# string or list). Returns a tuple of whether the conversion succeeded
	# (a boolean) and the index.

	set f [$m local "tcl.impl.getIndex" \
		   struct{bool,int}<-Interp*,Tcl_Obj*,int readonly]







|







1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
	    my ret [Const false bool]
	}

	##### Function tcl.impl.getIndex #####
	##### Closure Build:GetIndex #####
	#
	# Type signature: interp:Interp* * objPtr:Tcl_Obj* * end:int
	#			-> bool * int
	#
	# Converts an index string into an offset into something (i.e., a
	# string or list). Returns a tuple of whether the conversion succeeded
	# (a boolean) and the index.

	set f [$m local "tcl.impl.getIndex" \
		   struct{bool,int}<-Interp*,Tcl_Obj*,int readonly]
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
	# Type signatures: obj:STRING -> {STRING,bool}
	#		   objdupe:{STRING,bool} -> void
	#
	# Helpers for the dictionary updating functions that reduce the amount
	# of explicit branch management in the code by factoring out common
	# patterns of reference handling.

	set f [$m local "obj.dedup" struct{STRING,int1}<-STRING]
	params obj
	build {
	    set duped [my shared $obj]
	    SetValueName $duped "duped"
	    set res [my insert [my undef struct{STRING,int1}] $duped 1]
	    my condBr $duped $duplicated $unshared
	label duplicated:
	    set dupe [$api Tcl_DuplicateObj $obj]
	    SetValueName $dupe "duplicateObj"
	    my ret [my insert $res $dupe 0]
	label unshared:
	    my ret [my insert $res $obj 0]
	}
	my closure Dedup {varName} {
	    upvar 1 $varName var
	    set token [my Call obj.dedup $var]
	    set var [my extract $token 0 [GetValueName $var]]
	    return $token
	}

	set f [$m local "obj.cleanup" void<-struct{STRING,int1}]
	params objdupe
	build {
	    my condBr [my extract $objdupe 1] $duplicated $unshared
	label duplicated:
	    my dropReference [my extract $objdupe 0]
	    my ret
	label unshared:







|




|















|







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
	# Type signatures: obj:STRING -> {STRING,bool}
	#		   objdupe:{STRING,bool} -> void
	#
	# Helpers for the dictionary updating functions that reduce the amount
	# of explicit branch management in the code by factoring out common
	# patterns of reference handling.

	set f [$m local "obj.dedup" struct{STRING,bool}<-STRING]
	params obj
	build {
	    set duped [my shared $obj]
	    SetValueName $duped "duped"
	    set res [my insert [my undef struct{STRING,bool}] $duped 1]
	    my condBr $duped $duplicated $unshared
	label duplicated:
	    set dupe [$api Tcl_DuplicateObj $obj]
	    SetValueName $dupe "duplicateObj"
	    my ret [my insert $res $dupe 0]
	label unshared:
	    my ret [my insert $res $obj 0]
	}
	my closure Dedup {varName} {
	    upvar 1 $varName var
	    set token [my Call obj.dedup $var]
	    set var [my extract $token 0 [GetValueName $var]]
	    return $token
	}

	set f [$m local "obj.cleanup" void<-struct{STRING,bool}]
	params objdupe
	build {
	    my condBr [my extract $objdupe 1] $duplicated $unshared
	label duplicated:
	    my dropReference [my extract $objdupe 0]
	    my ret
	label unshared:
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
	    set call [my Call $func $obj $new]
	    AddCallAttribute $call 1 nocapture
	    AddCallAttribute $call 2 nocapture
	    my ret $new
	label fail:
	    my ret [my null STRING]
	}



















	##### Function tcl.list.create #####
	#
	# Type signature: objc:int * objv:STRING* -> STRING
	#
	# Core of quadcode implementation ('list')
	#
	# Wrapper around Tcl_NewListObj that exposes it to the general
	# instruction issuing code.

	set f [$m local "tcl.list.create" STRING<-int,STRING*]
	params objc objv
	build {
	    nonnull $objv
	    set val [$api Tcl_NewListObj $objc $objv]
	    my addReference(STRING) $val
	    my ret $val
	}

	##### Function tcl.list.length #####
	#
	# Type signature: list:STRING * ecvar:int* -> INT?
	#
	# Core of quadcode implementation ('listLength')
	#
	# Wrapper around Tcl_ListObjLength that exposes it to the general
	# instruction issuing code.

	set f [$m local "tcl.list.length" INT?<-STRING,int*]
	params list ecvar
	build {
	    noalias $list $ecvar
	    nonnull $list $ecvar
	    set var [my alloc int "length"]
	    set interp [$api tclInterp]
	    set code [$api Tcl_ListObjLength $interp $list $var]
	    my condBr [my eq $code $0] $ok $fail
	label ok:
	    my ret [my ok [my packInt32 [my load $var]]]
	label fail:
	    my store $1 $ecvar
	    my ret [my fail INT]
	}

	##### Function tcl.list.verify #####
	#
	# Type signature: value:STRING * ecvar:int* -> STRING?
	#
	# Core of quadcode implementation ('verifyList')
	#
	# Wrapper around a list operation (Tcl_ListObjLength) that verifies
	# that the value it is dealing with is a list; converting it to a FAIL
	# if it is not.

	set f [$m local "tcl.list.verify" STRING?<-STRING,int*]
	params value ecvar
	build {
	    noalias $value $ecvar
	    nonnull $value $ecvar
	    set var [my alloc int "length"]
	    set interp [$api tclInterp]
	    set code [$api Tcl_ListObjLength $interp $value $var]
	    my condBr [my eq $code $0] $ok $fail
	label ok:
	    $api Tcl_IncrRefCount $value
	    my ret [my ok $value]
	label fail:
	    my store $1 $ecvar
	    my ret [my fail STRING]
	}

	##### Function tcl.list.append #####
	#
	# Type signature: list:STRING * value:STRING * ecvar:int* -> STRING?
	#
	# Core of quadcode implementation ('listAppend')
	#
	# Wrapper around Tcl_ListObjLength that exposes it to the general
	# instruction issuing code.

	set f [$m local "tcl.list.append" STRING?<-STRING,STRING,int*]
	params list value ecvar
	build {
	    noalias $ecvar
	    nonnull $list $value $ecvar
	    set interp [$api tclInterp]
	    my condBr [my shared $list] $sharedDupe $unshared
	label sharedDupe "shared.duplicate"
	    set copy [my ListDupe $interp $list "copy"]
	    my condBr [my nonnull $copy] $shared $error
	label shared:
	    $api Tcl_ListObjAppendElement {} $copy $value
	    my br $return
	label unshared:
	    set code [$api Tcl_ListObjAppendElement $interp $list $value]
	    my condBr [my eq $code $0] $return $error
	label return:
	    set list [my phi [list $copy $list] [list $shared $unshared] "list"]
	    $api TclInvalidateStringRep $list
	    my addReference(STRING) $list
	    my condBr [my shared $value] $exit $extraRef
	label extraRef "add.extra.reference.to.value"
	    my addReference(STRING) $value
	    my br $exit
	label exit:
	    my ret [my ok $list]
	label error:
	    my store $1 $ecvar
	    my ret [my fail STRING]
	}

	##### Function tcl.list.concat #####
	#
	# Type signature: list:STRING * value:STRING * ecvar:int* -> STRING?
	#
	# Core of quadcode implementation ('listConcat')
	#
	# Wrapper around Tcl_ListObjLength that exposes it to the general
	# instruction issuing code.

	set f [$m local "tcl.list.concat" STRING?<-STRING,STRING,int*]
	params list value ecvar
	build {
	    noalias $ecvar
	    nonnull $list $value $ecvar
	    set objc [my alloc int "objc"]
	    set objv [my alloc STRING* "objv"]
	    set interp [$api tclInterp]
	    set code [$api Tcl_ListObjLength $interp $list $objc]
	    my condBr [my eq $code $0] $checkValue $error
	label checkValue "check.value.for.listness"
	    set len [my load $objc "len"]
	    set code [$api Tcl_ListObjGetElements $interp $value $objc $objv]
	    my condBr [my eq $code $0] $checkDupe $error
	label checkDupe "check.whether.to.duplicate"
	    my condBr [my shared $list] $dupe $concat
	label dupe "duplicate"
	    set copy [my ListDupe {} $list "copy"]
	    my br $concat
	label concat:
	    set working [my phi [list $list $copy] [list $checkDupe $dupe] "list"]
	    set objc [my load $objc "objc"]
	    set objv [my load $objv "objv"]
	    $api Tcl_ListObjReplace {} $working $len $0 $objc $objv
	    my addReference(STRING) $working
	    my ret [my ok $working]
	label error:
	    my store $1 $ecvar
	    my ret [my fail STRING]
	}

	##### Function tcl.list.index #####
	#
	# Type signature: list:STRING * idxc:int * idxv:STRING* * ecvar:int*
	#			-> STRING?
	#
	# Core of quadcode implementation ('listIndex')
	#
	# Effectively an implementation of TclLindexFlat.

	set f [$m local "tcl.list.index" STRING?<-STRING,int,STRING*,int*]
	params list idxc idxv ecvar
	build {
	    noalias $list $idxv $ecvar
	    nonnull $list $idxv $ecvar
	    set iPtr [my alloc int "&i"]
	    set listPtr [my alloc STRING "&list"]
	    set listLenPtr [my alloc int "&listLen"]







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>










|










|






|
|

<
|

<
|
<
<
|
<
<
<




|







|


















|






|
|

<
|

|
|

<
<



|
|









|
<
<
<




|


|
<
<
<
|
|

<
|


<
|
<
<

|
<
<





|




|
<
<
<




|






|







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
	    set call [my Call $func $obj $new]
	    AddCallAttribute $call 1 nocapture
	    AddCallAttribute $call 2 nocapture
	    my ret $new
	label fail:
	    my ret [my null STRING]
	}

	##### Function tcl.isList #####
	#
	# Type signature: objPtr:STRING -> bool
	#
	# Part of quadcode implementation ('isInstance')
	#
	# Wrapper around Tcl_ListObjLength that uses it to do a list-ness
	# check.

	set f [$m local "tcl.isList" bool<-STRING]
	params objPtr
	build {
	    nonnull $objPtr
	    set var [my alloc int "length"]
	    set code [$api Tcl_ListObjLength {} $objPtr $var]
	    my ret [my eq $code $0]
	}

	##### Function tcl.list.create #####
	#
	# Type signature: objc:int * objv:STRING* -> STRING
	#
	# Core of quadcode implementation ('list')
	#
	# Wrapper around Tcl_NewListObj that exposes it to the general
	# instruction issuing code.

	set f [$m local "tcl.list.create" LIST<-int,STRING*]
	params objc objv
	build {
	    nonnull $objv
	    set val [$api Tcl_NewListObj $objc $objv]
	    my addReference(STRING) $val
	    my ret $val
	}

	##### Function tcl.list.length #####
	#
	# Type signature: list:LIST -> INT
	#
	# Core of quadcode implementation ('listLength')
	#
	# Wrapper around Tcl_ListObjLength that exposes it to the general
	# instruction issuing code.

	set f [$m local "tcl.list.length" INT<-LIST]
	params list
	build {

	    nonnull $list
	    set var [my alloc int "length"]

	    $api Tcl_ListObjLength {} $list $var


	    my ret [my packInt32 [my load $var]]



	}

	##### Function tcl.list.verify #####
	#
	# Type signature: value:STRING * ecvar:int* -> LIST?
	#
	# Core of quadcode implementation ('verifyList')
	#
	# Wrapper around a list operation (Tcl_ListObjLength) that verifies
	# that the value it is dealing with is a list; converting it to a FAIL
	# if it is not.

	set f [$m local "tcl.list.verify" LIST?<-STRING,int*]
	params value ecvar
	build {
	    noalias $value $ecvar
	    nonnull $value $ecvar
	    set var [my alloc int "length"]
	    set interp [$api tclInterp]
	    set code [$api Tcl_ListObjLength $interp $value $var]
	    my condBr [my eq $code $0] $ok $fail
	label ok:
	    $api Tcl_IncrRefCount $value
	    my ret [my ok $value]
	label fail:
	    my store $1 $ecvar
	    my ret [my fail STRING]
	}

	##### Function tcl.list.append #####
	#
	# Type signature: list:LIST * value:STRING -> LIST
	#
	# Core of quadcode implementation ('listAppend')
	#
	# Wrapper around Tcl_ListObjLength that exposes it to the general
	# instruction issuing code.

	set f [$m local "tcl.list.append" LIST<-LIST,STRING]
	params list value
	build {

	    nonnull $list $value
	    set interp [$api tclInterp]
	    my condBr [my shared $list] $shared $unshared
	label shared "shared.duplicate"
	    set copy [my ListDupe $interp $list "copy"]


	    $api Tcl_ListObjAppendElement {} $copy $value
	    my br $return
	label unshared:
	    $api Tcl_ListObjAppendElement {} $list $value
	    my br $return
	label return:
	    set list [my phi [list $copy $list] [list $shared $unshared] "list"]
	    $api TclInvalidateStringRep $list
	    my addReference(STRING) $list
	    my condBr [my shared $value] $exit $extraRef
	label extraRef "add.extra.reference.to.value"
	    my addReference(STRING) $value
	    my br $exit
	label exit:
	    my ret $list



	}

	##### Function tcl.list.concat #####
	#
	# Type signature: list:LIST * value:LIST -> LIST
	#
	# Core of quadcode implementation ('listConcat')




	set f [$m local "tcl.list.concat" LIST<-LIST,LIST]
	params list value
	build {

	    nonnull $list $value
	    set objc [my alloc int "objc"]
	    set objv [my alloc STRING* "objv"]

	    $api Tcl_ListObjLength {} $list $objc


	    set len [my load $objc "len"]
	    $api Tcl_ListObjGetElements {} $value $objc $objv


	    my condBr [my shared $list] $dupe $concat
	label dupe "duplicate"
	    set copy [my ListDupe {} $list "copy"]
	    my br $concat
	label concat:
	    set working [PHI [Type LIST] {$list $copy} {$entry $dupe} "list"]
	    set objc [my load $objc "objc"]
	    set objv [my load $objv "objv"]
	    $api Tcl_ListObjReplace {} $working $len $0 $objc $objv
	    my addReference(STRING) $working
	    my ret $working



	}

	##### Function tcl.list.index #####
	#
	# Type signature: list:LIST * idxc:int * idxv:STRING* * ecvar:int*
	#			-> STRING?
	#
	# Core of quadcode implementation ('listIndex')
	#
	# Effectively an implementation of TclLindexFlat.

	set f [$m local "tcl.list.index" STRING?<-LIST,int,STRING*,int*]
	params list idxc idxv ecvar
	build {
	    noalias $list $idxv $ecvar
	    nonnull $list $idxv $ecvar
	    set iPtr [my alloc int "&i"]
	    set listPtr [my alloc STRING "&list"]
	    set listLenPtr [my alloc int "&listLen"]
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
	label error:
	    my store $1 $ecvar
	    my ret [my fail STRING]
	}

	##### Function tcl.list.index1 #####
	#
	# Type signature: list:STRING * index:INT * ecvar:int* -> STRING?
	#
	# Core of quadcode implementation ('listIndex')
	#
	# Basic list indexing in the case where we know that the index is an
	# integer, which avoids many of the failure modes.

	set f [$m local "tcl.list.index1" STRING?<-STRING,INT,int*]
	params list index ecvar
	build {
	    noalias $list $ecvar
	    nonnull $list $ecvar
	    set objc [my alloc int "objc"]
	    set objv [my alloc STRING* "objv"]
	    set interp [$api tclInterp]
	    set idx [my getInt32 $index]
	    set code [$api Tcl_ListObjGetElements $interp $list $objc $objv]
	    my condBr [my eq $code $0] $ok $fail
	label ok:
	    my condBr [my and [my ge $idx $0] [my lt $idx [my load $objc]]] \
		$realIndex $outOfBounds
	label realIndex "real.index"
	    set objv [my load $objv "objv"]
	    set obj [my load [my getelementptr $objv [list $idx]] "objPtr"]
	    my addReference(STRING) $obj
	    my ret [my ok $obj]
	label outOfBounds "out.of.bounds"
	    set obj [$api Tcl_NewObj]
	    my addReference(STRING) $obj
	    my ret [my ok $obj]
	label fail:
	    my store $1 $ecvar
	    my ret [my fail STRING]
	}

	##### Function tcl.list.indexList #####
	#
	# Type signature: list:STRING * index:STRING * ecvar:int* -> STRING?
	#
	# Core of quadcode implementation ('listIndex')
	#
	# Effectively an implementation of TclLindexList.

	set f [$m local "tcl.list.indexList" STRING?<-STRING,STRING,int*]
	params list index ecvar
	build {
	    noalias $ecvar
	    nonnull $list $index $ecvar
	    set objc [my alloc int "objc"]
	    set objv [my alloc STRING* "objv"]
	    set interp [$api tclInterp]
	    set code [$api Tcl_ListObjGetElements $interp $list $objc $objv]
	    my condBr [my eq $code $0] $checkType $notList
	label notList:
	    # We're not a list and we know it right now
	    my store $1 $ecvar
	    my ret [my fail STRING]
	label checkType:
	    my condBr [my neq [my dereference $index 0 Tcl_Obj.typePtr] \
			[$api tclListType]] \
		$checkIndex $slowPath
	label checkIndex:
	    set len [my load $objc]
	    my condBr [my GetIndex {} $index $len idx] \
		$immediateIndex $slowPath







|






|
|

<
|


<

|
<
<






|



|
<
<
<




|





|







|
<
<
<
<
<
<







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
	label error:
	    my store $1 $ecvar
	    my ret [my fail STRING]
	}

	##### Function tcl.list.index1 #####
	#
	# Type signature: list:LIST * index:INT -> STRING
	#
	# Core of quadcode implementation ('listIndex')
	#
	# Basic list indexing in the case where we know that the index is an
	# integer, which avoids many of the failure modes.

	set f [$m local "tcl.list.index1" STRING<-LIST,INT]
	params list index
	build {

	    nonnull $list
	    set objc [my alloc int "objc"]
	    set objv [my alloc STRING* "objv"]

	    set idx [my getInt32 $index]
	    $api Tcl_ListObjGetElements {} $list $objc $objv


	    my condBr [my and [my ge $idx $0] [my lt $idx [my load $objc]]] \
		$realIndex $outOfBounds
	label realIndex "real.index"
	    set objv [my load $objv "objv"]
	    set obj [my load [my getelementptr $objv [list $idx]] "objPtr"]
	    my addReference(STRING) $obj
	    my ret $obj
	label outOfBounds "out.of.bounds"
	    set obj [$api Tcl_NewObj]
	    my addReference(STRING) $obj
	    my ret $obj



	}

	##### Function tcl.list.indexList #####
	#
	# Type signature: list:LIST * index:STRING * ecvar:int* -> STRING?
	#
	# Core of quadcode implementation ('listIndex')
	#
	# Effectively an implementation of TclLindexList.

	set f [$m local "tcl.list.indexList" STRING?<-LIST,STRING,int*]
	params list index ecvar
	build {
	    noalias $ecvar
	    nonnull $list $index $ecvar
	    set objc [my alloc int "objc"]
	    set objv [my alloc STRING* "objv"]
	    set interp [$api tclInterp]
	    $api Tcl_ListObjGetElements {} $list $objc $objv






	    my condBr [my neq [my dereference $index 0 Tcl_Obj.typePtr] \
			[$api tclListType]] \
		$checkIndex $slowPath
	label checkIndex:
	    set len [my load $objc]
	    my condBr [my GetIndex {} $index $len idx] \
		$immediateIndex $slowPath
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
		    [my gep $dupe 0 Tcl_Obj.internalRep 0] \
		    TclList*] "listRep"]
	    set result [my Call tcl.list.index \
		    $list [my dereference $listRep 0 TclList.elemCount] \
		    [my gep $listRep 0 TclList.elements] $ecvar]
	    my dropReference $dupe
	    my ret $result




	}

	##### Function tcl.list.range #####
	#
	# Type signature: list:STRING * from:STRING * to:STRING -> STRING?
	#
	# Core of quadcode implementation ('listRangeImm')
	#
	# Wrapper around Tcl_NewListObj that exposes it to the general
	# instruction issuing code.

	set f [$m local "tcl.list.range" STRING?<-STRING,STRING,STRING,int*]
	params list from to ecvar
	build {
	    noalias $ecvar
	    nonnull $list $from $to $ecvar
	    set objcVar [my alloc int]
	    set objvVar [my alloc STRING*]
	    set interp [$api tclInterp]
	    set result [$api Tcl_ListObjLength $interp $list $objcVar]
	    my condBr [my eq $result $0] $getFrom $error
	label getFrom:
	    set objc [my load $objcVar "objc"]
	    set endIndex [my sub $objc $1]
	    my condBr [my GetIndex $interp $from $endIndex from] $getTo $error
	label getTo:
	    my condBr [my GetIndex $interp $to $endIndex to] $clamp $error
	label clamp:
	    set from [my select [my lt $from ${-1}] \







>
>
>
>




|


|
<
<
<
|







|
<
<







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
		    [my gep $dupe 0 Tcl_Obj.internalRep 0] \
		    TclList*] "listRep"]
	    set result [my Call tcl.list.index \
		    $list [my dereference $listRep 0 TclList.elemCount] \
		    [my gep $listRep 0 TclList.elements] $ecvar]
	    my dropReference $dupe
	    my ret $result
	label notList:
	    # We're not a list and we know it right now
	    my store $1 $ecvar
	    my ret [my fail STRING]
	}

	##### Function tcl.list.range #####
	#
	# Type signature: list:LIST * from:STRING * to:STRING -> LIST?
	#
	# Core of quadcode implementation ('listRangeImm')




	set f [$m local "tcl.list.range" LIST?<-LIST,STRING,STRING,int*]
	params list from to ecvar
	build {
	    noalias $ecvar
	    nonnull $list $from $to $ecvar
	    set objcVar [my alloc int]
	    set objvVar [my alloc STRING*]
	    set interp [$api tclInterp]
	    $api Tcl_ListObjLength {} $list $objcVar


	    set objc [my load $objcVar "objc"]
	    set endIndex [my sub $objc $1]
	    my condBr [my GetIndex $interp $from $endIndex from] $getTo $error
	label getTo:
	    my condBr [my GetIndex $interp $to $endIndex to] $clamp $error
	label clamp:
	    set from [my select [my lt $from ${-1}] \
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
	label error:
	    my store $1 $ecvar
	    my ret [my fail STRING]
	}

	##### Function tcl.list.range1 #####
	#
	# Type signature: list:STRING * from:INT * to:INT -> STRING?
	#
	# Core of quadcode implementation ('listRangeImm')
	#
	# Wrapper around Tcl_NewListObj that exposes it to the general
	# instruction issuing code.

	set f [$m local "tcl.list.range1" STRING?<-STRING,INT,INT,int*]
	params list from to ecvar
	build {
	    noalias $ecvar
	    nonnull $list $ecvar
	    set objc [my alloc int "objc"]
	    set objv [my alloc STRING* "objv"]
	    set interp [$api tclInterp]
	    set from [my getInt32 $from "from"]
	    set to [my getInt32 $to "to"]
	    set result [$api Tcl_ListObjGetElements $interp $list $objc $objv]
	    my condBr [my eq $result $0] $clamp $error
	label clamp:
	    set objc [my load $objc]
	    set objv [my load $objv]
	    set from [my select [my lt $from ${-1}] \
		    [my add $from [my add $1 $objc]] \
		    [my min $objc $from] \
		    "from"]
	    set from [my max ${-1} $from "from"]







|


|
<
<
<
|
|

<
|





|
<
<







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
	label error:
	    my store $1 $ecvar
	    my ret [my fail STRING]
	}

	##### Function tcl.list.range1 #####
	#
	# Type signature: list:LIST * from:INT * to:INT -> LIST
	#
	# Core of quadcode implementation ('listRangeImm')




	set f [$m local "tcl.list.range1" LIST<-LIST,INT,INT]
	params list from to
	build {

	    nonnull $list
	    set objc [my alloc int "objc"]
	    set objv [my alloc STRING* "objv"]
	    set interp [$api tclInterp]
	    set from [my getInt32 $from "from"]
	    set to [my getInt32 $to "to"]
	    $api Tcl_ListObjGetElements {} $list $objc $objv


	    set objc [my load $objc]
	    set objv [my load $objv]
	    set from [my select [my lt $from ${-1}] \
		    [my add $from [my add $1 $objc]] \
		    [my min $objc $from] \
		    "from"]
	    set from [my max ${-1} $from "from"]
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
	label empty:
	    set r2 [$api Tcl_NewObj]
	    my br $ok
	label ok:
	    set sources [list $sublistInplaceDone $sublistNew $empty]
	    set result [my phi [list $list $r1 $r2] $sources "result"]
	    my addReference(STRING) $result
	    my ret [my ok $result]
	label error:
	    my store $1 $ecvar
	    my ret [my fail STRING]
	}

	##### Function tcl.list.set #####
	#
	# Type signature: list:STRING * idxc:int * idxv:STRING* * elem:STRING
	#			* ecvar:int* -> STRING?
	#
	# Core of quadcode implementation ('lset')
	#
	# Approximately equivalent to TclLsetFlat

	set f [$m local "tcl.list.set" STRING?<-STRING,int,STRING*,STRING,int*]
	params list idxc idxv elem ecvar
	build {
	    noalias $idxv $ecvar
	    nonnull $list $idxv $elem $ecvar
	    set subList [my alloc STRING]
	    set chain [my alloc STRING]
	    set elemc [my alloc int]







|
<
<
<




|
|





|







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
	label empty:
	    set r2 [$api Tcl_NewObj]
	    my br $ok
	label ok:
	    set sources [list $sublistInplaceDone $sublistNew $empty]
	    set result [my phi [list $list $r1 $r2] $sources "result"]
	    my addReference(STRING) $result
	    my ret $result



	}

	##### Function tcl.list.set #####
	#
	# Type signature: list:LIST * idxc:int * idxv:STRING* * elem:STRING
	#			* ecvar:int* -> LIST?
	#
	# Core of quadcode implementation ('lset')
	#
	# Approximately equivalent to TclLsetFlat

	set f [$m local "tcl.list.set" LIST?<-LIST,int,STRING*,STRING,int*]
	params list idxc idxv elem ecvar
	build {
	    noalias $idxv $ecvar
	    nonnull $list $idxv $elem $ecvar
	    set subList [my alloc STRING]
	    set chain [my alloc STRING]
	    set elemc [my alloc int]
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
	#			-> STRING?
	#
	# Core of quadcode implementation ('lset')
	#
	# Wrapper around TclListObjSetElement that exposes it to the general
	# instruction issuing code.

	set f [$m local "tcl.list.set1" STRING?<-STRING,INT,STRING,int*]
	params list idx elem ecvar
	build {
	    noalias $ecvar
	    nonnull $list $elem $ecvar
	    set objc [my alloc int "objc"]
	    set objv [my alloc STRING* "objv"]
	    set idx [my getInt32 $idx "index"]
	    set interp [$api tclInterp]
	    set duped [my Dedup list]
	    set code [$api Tcl_ListObjGetElements $interp $list $objc $objv]
	    my condBr [my eq $code $1] $out $rangeCheck
	label rangeCheck "range.check"
	    set objc [my load $objc]
	    my condBr [my or [my lt $idx $0] [my gt $idx $objc]] \
		$outRange $checkOperation
	label checkOperation "operation.check"
	    set rc [my refCount $list]
	    my condBr [my eq $idx $objc] $append $set
	label append:
	    $api Tcl_ListObjAppendElement {} $list $elem
	    my br $done
	label set:
	    set call [$api TclListObjSetElement {} $list $idx $elem]
	    my br $done
	label done:
	    my assume [my eq $rc [my refCount $list]]
	    $api TclInvalidateStringRep $list
	    my addReference(STRING) $list
	    my condBr [my shared $elem] $exit2 $exit3
	label exit3 "exit"
	    my addReference(STRING) $elem
	    my br $exit2
	label exit2 "exit"
	    my ret [my ok $list]
	label outRange "failure.outOfRange"

	    $api Tcl_SetObjResult $interp \
		[$api obj.constant "list index out of range"]
	    $api Tcl_SetObjErrorCode $interp \
		[$api obj.constant {TCL OPERATION LSET BADINDEX}]
	    my br $out
	label out "failure.exit"
	    my Call obj.cleanup $duped
	    my store $1 $ecvar
	    my ret [my fail STRING]
	}

	##### Function tcl.list.setList #####
	#
	# Type signature: list:STRING * idxArg:STRING * elem:STRING
	#			* ecvar:int* -> STRING?
	#
	# Core of quadcode implementation ('lset')
	#
	# Approximately equivalent to TclLsetList

	set f [$m local "tcl.list.setList" STRING?<-STRING,STRING,STRING,int*]
	params list idxArg elem ecvar
	build {
	    noalias $ecvar
	    nonnull $list $idxArg $elem $ecvar
	    set ary [my alloc STRING]
	    set argc [my alloc int]
	    set argv [my alloc STRING*]







|







<

|
<
<


|



















|
>




<
<







|
|





|







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
	#			-> STRING?
	#
	# Core of quadcode implementation ('lset')
	#
	# Wrapper around TclListObjSetElement that exposes it to the general
	# instruction issuing code.

	set f [$m local "tcl.list.set1" LIST?<-LIST,INT,STRING,int*]
	params list idx elem ecvar
	build {
	    noalias $ecvar
	    nonnull $list $elem $ecvar
	    set objc [my alloc int "objc"]
	    set objv [my alloc STRING* "objv"]
	    set idx [my getInt32 $idx "index"]

	    set duped [my Dedup list]
	    $api Tcl_ListObjGetElements {} $list $objc $objv


	    set objc [my load $objc]
	    my condBr [my or [my lt $idx $0] [my gt $idx $objc]] \
		$error $checkOperation
	label checkOperation "operation.check"
	    set rc [my refCount $list]
	    my condBr [my eq $idx $objc] $append $set
	label append:
	    $api Tcl_ListObjAppendElement {} $list $elem
	    my br $done
	label set:
	    set call [$api TclListObjSetElement {} $list $idx $elem]
	    my br $done
	label done:
	    my assume [my eq $rc [my refCount $list]]
	    $api TclInvalidateStringRep $list
	    my addReference(STRING) $list
	    my condBr [my shared $elem] $exit2 $exit3
	label exit3 "exit"
	    my addReference(STRING) $elem
	    my br $exit2
	label exit2 "exit"
	    my ret [my ok $list]
	label error:
	    set interp [$api tclInterp]
	    $api Tcl_SetObjResult $interp \
		[$api obj.constant "list index out of range"]
	    $api Tcl_SetObjErrorCode $interp \
		[$api obj.constant {TCL OPERATION LSET BADINDEX}]


	    my Call obj.cleanup $duped
	    my store $1 $ecvar
	    my ret [my fail STRING]
	}

	##### Function tcl.list.setList #####
	#
	# Type signature: list:LIST * idxArg:STRING * elem:STRING
	#			* ecvar:int* -> LIST?
	#
	# Core of quadcode implementation ('lset')
	#
	# Approximately equivalent to TclLsetList

	set f [$m local "tcl.list.setList" LIST?<-LIST,STRING,STRING,int*]
	params list idxArg elem ecvar
	build {
	    noalias $ecvar
	    nonnull $list $idxArg $elem $ecvar
	    set ary [my alloc STRING]
	    set argc [my alloc int]
	    set argv [my alloc STRING*]
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
		$list [my load $argc] [my load $argv] $elem $ecvar]
	    my dropReference $copy
	    my ret $code
	}

	##### Function tcl.list.in #####
	#
	# Type signature: value:STRING * list:STRING * ecVar:int* -> ZEROONE?
	#
	# Core of quadcode implementation ('listIn')
	#
	# Determines if the value is present in the list, using simple string
	# comparison.

	set f [$m local "tcl.list.in" ZEROONE?<-STRING,STRING,int*]
	params value list ecVar
	build {
	    noalias $ecVar
	    nonnull $value $list $ecVar
	    set interp [$api tclInterp]
	    lassign [my GetString $value "string"] len1 bytes1
	    set lenVar [my alloc int]
	    set objvVar [my alloc STRING*]

	    set code [$api Tcl_ListObjGetElements $interp $list $lenVar $objvVar]
	    my condBr [my eq $code $0] $realCheck $fail
	label realCheck:
	    set objc [my load $lenVar "objc"]
	    set objv [my load $objvVar "objv"]
	    my condBr [my gt $objc $0] $loop $done
	label loop:
	    set i [PHI [Type int32] {$0 $iLoop} {$realCheck $loopNext} "i"]
	    set obj [my load [my getelementptr $objv [list $i]] "obj"]
	    lassign [my GetString $obj "element"] len2 bytes2
	    my condBr [my eq $len1 $len2] $loopCompare $loopNext
	label loopCompare:
	    my condBr [my eq [my memcmp $bytes1 $bytes2 $len1] $0] \
		$done $loopNext
	label loopNext:
	    set iLoop [set i [my add $i $1 "i"]]
	    my condBr [my lt $i $objc] $loop $done
	label fail:
	    my store $1 $ecVar
	    my ret [my fail ZEROONE]
	label done:
	    set flag [my phi [list [Const false bool] [Const false bool] [Const true bool]] \
		    [list $realCheck $loopNext $loopCompare] "flag"]
	    my ret [my ok $flag]
	}

	##### Function tcl.list.unshare #####
	#
	# Type signature: list:STRING -> STRING
	#
	# Core of quadcode implementation ('unshareList')
	#
	# Approximately equivalent to TclListObjCopy

	set f [$m local "tcl.list.unshare" STRING<-STRING]
	params list







|






|
|

<
|
<
<


>
|
<
<


|

|





|


|
|
<
|
|
<
<
|




|







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
		$list [my load $argc] [my load $argv] $elem $ecvar]
	    my dropReference $copy
	    my ret $code
	}

	##### Function tcl.list.in #####
	#
	# Type signature: value:STRING * list:LIST * ecVar:int* -> bool?
	#
	# Core of quadcode implementation ('listIn')
	#
	# Determines if the value is present in the list, using simple string
	# comparison.

	set f [$m local "tcl.list.in" bool<-STRING,LIST]
	params value list
	build {

	    nonnull $value $list


	    set lenVar [my alloc int]
	    set objvVar [my alloc STRING*]
	    lassign [my GetString $value "string"] len1 bytes1
	    $api Tcl_ListObjGetElements {} $list $lenVar $objvVar


	    set objc [my load $lenVar "objc"]
	    set objv [my load $objvVar "objv"]
	    my condBr [my gt $objc $0] $loop $notFound
	label loop:
	    set i [PHI [Type int32] {$0 $iLoop} {$entry $loopNext} "i"]
	    set obj [my load [my getelementptr $objv [list $i]] "obj"]
	    lassign [my GetString $obj "element"] len2 bytes2
	    my condBr [my eq $len1 $len2] $loopCompare $loopNext
	label loopCompare:
	    my condBr [my eq [my memcmp $bytes1 $bytes2 $len1] $0] \
		$found $loopNext
	label loopNext:
	    set iLoop [set i [my add $i $1 "i"]]
	    my condBr [my lt $i $objc] $loop $notFound
	label notFound "not.found"

	    my ret [Const false bool]
	label found:


	    my ret [Const true bool]
	}

	##### Function tcl.list.unshare #####
	#
	# Type signature: list:LIST -> LIST
	#
	# Core of quadcode implementation ('unshareList')
	#
	# Approximately equivalent to TclListObjCopy

	set f [$m local "tcl.list.unshare" STRING<-STRING]
	params list
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
	    my addReference(STRING) $copy
	    my ret $copy
	}

	##### Function tcl.list.foreach.start.step #####
	#
	# Type signature:
	#	nsteps:int?,list:STRING,stride:int->nsteps:int?
	#
	# Core of quadcode implementation ('foreachStart')
	#
	# Works with one pair of list and assignment pattern, making sure
	# that the list is really a list, and updating the number of iterations
	# according to the given stride.

	set f [$m local "tcl.list.foreach.start.step" \
		   int?<-int?,STRING,int]
	params steps_init list stride
	build {
	    noalias $list
	    nonnull $list
	    set objcVar [my alloc int]
	    set interp [$api tclInterp]
	    my condBr [my maybe $steps_init] $earlierError $listLength
	label earlierError:
	    my ret $steps_init
	label listLength:
	    set code [$api Tcl_ListObjLength $interp $list $objcVar]
	    my condBr [my eq $code $0] $lengthOk $lengthBad
	label lengthOk:
	    set steps_before [my unmaybe $steps_init]
	    set objc [my load $objcVar "objc"]
	    set count [my div [my add $objc [my sub $stride [Const 1 int]]] \
			   $stride "count"]
	    set stepsOk [my ok [my max $steps_before $count "steps"]]
	    my br $done
	label lengthBad:
	    set stepsBad [my fail int]
	    my br $done
	label done:
	    set steps [my phi [list $stepsOk $stepsBad] \
			   [list $lengthOk $lengthBad]]
	    my ret $steps
	}

	##### Function: tcl.list.foreach.start.finish #####
	#
	# Type signature: steps:int?,ecvar:int*->FAIL FOREACH
	#
	# After 'tcl.list.foreach.start.step' has run for each assignment







|








|










|
<
<




|
<
<
<
<
<
<
<
<







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
	    my addReference(STRING) $copy
	    my ret $copy
	}

	##### Function tcl.list.foreach.start.step #####
	#
	# Type signature:
	#	nsteps:int? * list:LIST * stride:int -> nsteps:int?
	#
	# Core of quadcode implementation ('foreachStart')
	#
	# Works with one pair of list and assignment pattern, making sure
	# that the list is really a list, and updating the number of iterations
	# according to the given stride.

	set f [$m local "tcl.list.foreach.start.step" \
		   int?<-int?,LIST,int]
	params steps_init list stride
	build {
	    noalias $list
	    nonnull $list
	    set objcVar [my alloc int]
	    set interp [$api tclInterp]
	    my condBr [my maybe $steps_init] $earlierError $listLength
	label earlierError:
	    my ret $steps_init
	label listLength:
	    $api Tcl_ListObjLength {} $list $objcVar


	    set steps_before [my unmaybe $steps_init]
	    set objc [my load $objcVar "objc"]
	    set count [my div [my add $objc [my sub $stride [Const 1 int]]] \
			   $stride "count"]
	    my ret [my ok [my max $steps_before $count "steps"]]








	}

	##### Function: tcl.list.foreach.start.finish #####
	#
	# Type signature: steps:int?,ecvar:int*->FAIL FOREACH
	#
	# After 'tcl.list.foreach.start.step' has run for each assignment
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
	params pair
	build {
	    my ret [my packInt32 [my extract $pair FOREACH.val]]
	}

	##### Function tcl.list.foreach.mayStep #####
	#
	# Type signature: pair:FOREACH -> ZEROONE
	#
	# Core of quadcode implementation ('foreachMayStep')
	#
	# Part of how lists are iterated over. This is broken up into several
	# pieces because of the number of different things assigned to. This
	# part gets whether the end of the iterations has been reached.

	set f [$m local "tcl.list.foreach.mayStep" ZEROONE<-FOREACH readnone]
	params pair
	build {
	    set val [my extract $pair FOREACH.val]
	    set max [my extract $pair FOREACH.max]
	    my ret [my lt $val $max]
	}








|







|







2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
	params pair
	build {
	    my ret [my packInt32 [my extract $pair FOREACH.val]]
	}

	##### Function tcl.list.foreach.mayStep #####
	#
	# Type signature: pair:FOREACH -> bool
	#
	# Core of quadcode implementation ('foreachMayStep')
	#
	# Part of how lists are iterated over. This is broken up into several
	# pieces because of the number of different things assigned to. This
	# part gets whether the end of the iterations has been reached.

	set f [$m local "tcl.list.foreach.mayStep" bool<-FOREACH readnone]
	params pair
	build {
	    set val [my extract $pair FOREACH.val]
	    set max [my extract $pair FOREACH.max]
	    my ret [my lt $val $max]
	}

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
    #		Thunk class).
    #
    # Results:
    #	None.

    method DictionaryFunctions {api} {
	upvar 1 0 0 1 1


















	##### Function tcl.dict.exists1 #####
	#
	# Type signature: dict:STRING * key:STRING -> ZEROONE
	#
	# Tests if a key is in a dictionary.

	set f [$m local "tcl.dict.exists1" ZEROONE<-STRING,STRING]
	params dict key
	build {
	    nonnull $dict $key
	    set resvar [my alloc STRING "valueVar"]
	    my store [my null STRING] $resvar
	    set result [$api Tcl_DictObjGet {} $dict $key $resvar]
	    my ret [my and [my eq $result $0] \
		    [my nonnull [my load $resvar "value"]] \
		    "exists"]
	}

	##### Function tcl.dict.exists #####
	#
	# Type signature: dict:STRING * pathlen:int * pathobjs:STRING*
	#			* ecvar:int32* -> ZEROONE
	#
	# Gets a value by key from a dictionary.  Can fail if the "dict" is
	# not a valid dictionary.

	set f [$m local "tcl.dict.exists" ZEROONE<-STRING,int,STRING*]
	params dict keyc keyv
	build {
	    noalias $dict $keyv
	    nonnull $dict $keyv
	    set dummy [my alloc int "dummy"]
	    set resvar [my alloc STRING "valueVar"]
	    my condBr [my eq $keyc $0] $verify $exists







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>



|



|













|
<

<
|

|







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
    #		Thunk class).
    #
    # Results:
    #	None.

    method DictionaryFunctions {api} {
	upvar 1 0 0 1 1

	##### Function tcl.isDict #####
	#
	# Type signature: objPtr:STRING -> bool
	#
	# Part of quadcode implementation ('isInstance')
	#
	# Wrapper around Tcl_DictObjSize that uses it to do a dict-ness check.

	set f [$m local "tcl.isDict" bool<-STRING]
	params objPtr
	build {
	    nonnull $objPtr
	    set var [my alloc int "length"]
	    set code [$api Tcl_DictObjSize {} $objPtr $var]
	    my ret [my eq $code $0]
	}

	##### Function tcl.dict.exists1 #####
	#
	# Type signature: dict:DICT * key:STRING -> bool
	#
	# Tests if a key is in a dictionary.

	set f [$m local "tcl.dict.exists1" bool<-DICT,STRING]
	params dict key
	build {
	    nonnull $dict $key
	    set resvar [my alloc STRING "valueVar"]
	    my store [my null STRING] $resvar
	    set result [$api Tcl_DictObjGet {} $dict $key $resvar]
	    my ret [my and [my eq $result $0] \
		    [my nonnull [my load $resvar "value"]] \
		    "exists"]
	}

	##### Function tcl.dict.exists #####
	#
	# Type signature: dict:DICT * pathlen:int * pathobjs:STRING* -> bool

	#

	# Tests if a key is present in a dictionary. Never fails.

	set f [$m local "tcl.dict.exists" bool<-DICT,int,STRING*]
	params dict keyc keyv
	build {
	    noalias $dict $keyv
	    nonnull $dict $keyv
	    set dummy [my alloc int "dummy"]
	    set resvar [my alloc STRING "valueVar"]
	    my condBr [my eq $keyc $0] $verify $exists
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
		    "exists"]
	label notOK:
	    my ret [Const false bool]
	}

	##### Function tcl.dict.size #####
	#
	# Type signature: dict:STRING * ecvar:int32* -> INT?
	#
	# Gets the size of a dictionary. Can fail if the "dict" is not a valid
	# dictionary.

	set f [$m local "tcl.dict.size" INT?<-STRING,int*]
	params dict ecvar
	build {
	    noalias $ecvar
	    nonnull $dict $ecvar
	    set size [my alloc int "size"]
	    set interp [$api tclInterp]
	    set code [$api Tcl_DictObjSize $interp $dict $size]
	    my condBr [my eq $code $0] $ok $fail
	label ok:
	    my ret [my ok [my packInt32 [my load $size]]]
	label fail:
	    my store $1 $ecvar
	    my ret [my fail INT]
	}

	##### Function tcl.dict.get1 #####
	#
	# Type signature: dict:STRING * key:STRING * ecvar:int32* -> STRING?
	#
	# Gets a value by key from a dictionary.  Can fail if the "dict" is
	# not a valid dictionary.

	set f [$m local "tcl.dict.get1" STRING?<-STRING,STRING,int*]
	params dict key ecvar
	build {
	    noalias $ecvar
	    nonnull $dict $key $ecvar
	    set resvar [my alloc STRING "valueVar"]
	    set interp [$api tclInterp]
	    set result [$api Tcl_DictObjGet $interp $dict $key $resvar]
	    my condBr [my eq $result $0] $OK $notOK
	label OK:
	    set value [my load $resvar "value"]
	    my condBr [my nonnull $value] $return $fail
	label return:
	    my addReference(STRING) $value
	    my ret [my ok $value]
	label fail:
	    set keyval [$api Tcl_GetString $key]
	    $api Tcl_SetObjResult $interp \
		[$api Tcl_ObjPrintf [my constString \
			"key \"%s\" not known in dictionary"] \
		    $keyval]
	    $api Tcl_SetErrorCode $interp \
		[my constString TCL] [my constString LOOKUP] \
		[my constString DICT] $keyval {}
	    my br $notOK
	label notOK:
	    my store $1 $ecvar
	    my ret [my fail STRING]
	}

	##### Function tcl.dict.get #####
	#
	# Type signature: dict:STRING * pathlen:int * pathobjs:STRING*
	#			* ecvar:int32* -> STRING?
	#
	# Gets a value by key from a dictionary.  Can fail if the "dict" is
	# not a valid dictionary.

	set f [$m local "tcl.dict.get" STRING?<-STRING,int,STRING*,int*]
	params dict keyc keyv ecvar
	build {
	    noalias $dict $keyv $ecvar
	    nonnull $dict $keyv $ecvar
	    set dummy [my alloc int "dummy"]
	    set resvar [my alloc STRING "valueVar"]
	    set interp [$api tclInterp]







|

|
<

|
|

<
|

<
|
<
<
|
<
<
<




|

|
|

|






|
<
<














<
<






|


|
|

|







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
		    "exists"]
	label notOK:
	    my ret [Const false bool]
	}

	##### Function tcl.dict.size #####
	#
	# Type signature: dict:DICT -> INT
	#
	# Gets the size of a dictionary.


	set f [$m local "tcl.dict.size" INT<-DICT]
	params dict
	build {

	    nonnull $dict
	    set size [my alloc int "size"]

	    $api Tcl_DictObjSize {} $dict $size


	    my ret [my packInt32 [my load $size]]



	}

	##### Function tcl.dict.get1 #####
	#
	# Type signature: dict:DICT * key:STRING * ecvar:int32* -> STRING?
	#
	# Gets a value by key from a dictionary.  Can fail if the key is
	# absent.

	set f [$m local "tcl.dict.get1" STRING?<-DICT,STRING,int*]
	params dict key ecvar
	build {
	    noalias $ecvar
	    nonnull $dict $key $ecvar
	    set resvar [my alloc STRING "valueVar"]
	    set interp [$api tclInterp]
	    $api Tcl_DictObjGet {} $dict $key $resvar


	    set value [my load $resvar "value"]
	    my condBr [my nonnull $value] $return $fail
	label return:
	    my addReference(STRING) $value
	    my ret [my ok $value]
	label fail:
	    set keyval [$api Tcl_GetString $key]
	    $api Tcl_SetObjResult $interp \
		[$api Tcl_ObjPrintf [my constString \
			"key \"%s\" not known in dictionary"] \
		    $keyval]
	    $api Tcl_SetErrorCode $interp \
		[my constString TCL] [my constString LOOKUP] \
		[my constString DICT] $keyval {}


	    my store $1 $ecvar
	    my ret [my fail STRING]
	}

	##### Function tcl.dict.get #####
	#
	# Type signature: dict:DICT * pathlen:int * pathobjs:STRING*
	#			* ecvar:int32* -> STRING?
	#
	# Gets a value by key from a dictionary.  Can fail if a "dict" inside
	# the dict is not a valid dictionary.

	set f [$m local "tcl.dict.get" STRING?<-DICT,int,STRING*,int*]
	params dict keyc keyv ecvar
	build {
	    noalias $dict $keyv $ecvar
	    nonnull $dict $keyv $ecvar
	    set dummy [my alloc int "dummy"]
	    set resvar [my alloc STRING "valueVar"]
	    set interp [$api tclInterp]
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
	label notOK:
	    my store $1 $ecvar
	    my ret [my fail STRING]
	}

	##### Function tcl.dict.get1.empty #####
	#
	# Type signature: dict:STRING * key:STRING * ecvar:int32* -> STRING!?
	#
	# Gets a value by key from a dictionary. Can only fail if the "dict"
	# is not a valid dictionary; an absent key in the terminal dictionary
	# is reported as an NEXIST result.

	set f [$m local "tcl.dict.get1.empty" STRING!?<-STRING,STRING,int*]
	params dict key ecvar
	build {
	    noalias $ecvar
	    nonnull $dict $key $ecvar
	    set resvar [my alloc STRING "valueVar"]
	    set interp [$api tclInterp]
	    set result [$api Tcl_DictObjGet $interp $dict $key $resvar]
	    my condBr [my eq $result $0] $OK $notOK
	label OK:
	    set value [my load $resvar "value"]
	    my condBr [my nonnull $value] $return $empty
	label return:
	    my addReference(STRING) $value
	    my ret [my ok [my just $value]]
	label empty:
	    my ret [my ok [my nothing STRING]]
	label notOK:
	    my store $1 $ecvar
	    my ret [my fail STRING!]
	}

	##### Function tcl.dict.set1 #####
	#
	# Type signature: dict:STRING * key:STRING * value:STRING
	#			* ecvar:int32* -> STRING?
	#
	# Sets a key in a dictionary to map to a value.  Can fail if the
	# "dict" is not a valid dictionary.

	set f [$m local "tcl.dict.set1" STRING?<-STRING,STRING,STRING,int*]
	params dict key value ecvar
	build {
	    noalias $ecvar
	    nonnull $dict $key $value $ecvar
	    set interp [$api tclInterp]
	    set dd [my Dedup dict]
	    set result [$api Tcl_DictObjPut $interp $dict $key $value]
	    my condBr [my eq $result $0] $OK $notOK
	label OK:
	    my addReference(STRING) $dict
	    my condBr [my shared $value] $exit2 $exit3
	label exit3 "exit"
	    my addReference(STRING) $value
	    my br $exit2
	label exit2 "exit"
	    my ret [my ok $dict]
	label notOK:
	    my Call obj.cleanup $dd
	    my store $1 $ecvar
	    my ret [my fail STRING]
	}

	##### Function tcl.dict.set #####
	#
	# Type signature: dict:STRING * pathlen:int * pathobjs:STRING*
	#			* value:STRING * ecvar:int32* -> STRING?
	#
	# Sets a key (or rather a key path) in a dictionary to map to a value.
	# Can fail if the "dict" is not a valid dictionary.

	set f [$m local "tcl.dict.set" STRING?<-STRING,int,STRING*,STRING,int*]
	params dict pathlen pathobjs value ecvar
	build {
	    noalias $pathobjs $ecvar
	    nonnull $dict $pathobjs $value $ecvar
	    set interp [$api tclInterp]
	    set dd [my Dedup dict]
	    set result [$api Tcl_DictObjPutKeyList $interp $dict $pathlen $pathobjs $value]







|

|
<
|

|
|

<
|

<
|
<
<




|

|
<
<
<




|
<

|
<

|
|

<
|
<

|
<
<




|

|
<
<
<
<










|







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
	label notOK:
	    my store $1 $ecvar
	    my ret [my fail STRING]
	}

	##### Function tcl.dict.get1.empty #####
	#
	# Type signature: dict:DICT * key:STRING -> STRING!
	#
	# Gets a value by key from a dictionary. An absent key in the terminal

	# dictionary is reported as an NEXIST result.

	set f [$m local "tcl.dict.get1.empty" STRING!<-DICT,STRING]
	params dict key
	build {

	    nonnull $dict $key
	    set resvar [my alloc STRING "valueVar"]

	    $api Tcl_DictObjGet {} $dict $key $resvar


	    set value [my load $resvar "value"]
	    my condBr [my nonnull $value] $return $empty
	label return:
	    my addReference(STRING) $value
	    my ret [my just $value]
	label empty:
	    my ret [my nothing STRING]



	}

	##### Function tcl.dict.set1 #####
	#
	# Type signature: dict:DICT * key:STRING * value:STRING -> DICT

	#
	# Sets a key in a dictionary to map to a value.


	set f [$m local "tcl.dict.set1" DICT<-DICT,STRING,STRING]
	params dict key value
	build {

	    nonnull $dict $key $value

	    set dd [my Dedup dict]
	    $api Tcl_DictObjPut {} $dict $key $value


	    my addReference(STRING) $dict
	    my condBr [my shared $value] $exit2 $exit3
	label exit3 "exit"
	    my addReference(STRING) $value
	    my ret $dict
	label exit2 "exit"
	    my ret $dict




	}

	##### Function tcl.dict.set #####
	#
	# Type signature: dict:STRING * pathlen:int * pathobjs:STRING*
	#			* value:STRING * ecvar:int32* -> STRING?
	#
	# Sets a key (or rather a key path) in a dictionary to map to a value.
	# Can fail if the "dict" is not a valid dictionary.

	set f [$m local "tcl.dict.set" DICT?<-DICT,int,STRING*,STRING,int*]
	params dict pathlen pathobjs value ecvar
	build {
	    noalias $pathobjs $ecvar
	    nonnull $dict $pathobjs $value $ecvar
	    set interp [$api tclInterp]
	    set dd [my Dedup dict]
	    set result [$api Tcl_DictObjPutKeyList $interp $dict $pathlen $pathobjs $value]
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
	    my Call obj.cleanup $dd
	    my store $1 $ecvar
	    my ret [my fail STRING]
	}

	##### Function tcl.dict.unset1 #####
	#
	# Type signature: dict:STRING * key:STRING * ecvar:int32* -> STRING?
	#
	# Removes a key from a dictionary.  Can fail if the "dict" is not a
	# valid dictionary.

	set f [$m local "tcl.dict.unset1" STRING?<-STRING,STRING,int*]
	params dict key ecvar
	build {
	    noalias $ecvar
	    nonnull $dict $key $ecvar
	    set interp [$api tclInterp]
	    set dd [my Dedup dict]
	    set result [$api Tcl_DictObjRemove $interp $dict $key]
	    my condBr [my eq $result $0] $OK $notOK
	label OK:
	    my addReference(STRING) $dict
	    my ret [my ok $dict]
	label notOK:
	    my Call obj.cleanup $dd
	    my store $1 $ecvar
	    my ret [my fail STRING]
	}

	##### Function tcl.dict.unset #####
	#
	# Type signature: dict:STRING * pathlen:int * pathobjs:STRING*
	#			* ecvar:int32* -> STRING?
	#
	# Removes a key (or rather a key path) from a dictionary. Can fail if
	# the "dict" is not a valid dictionary.

	set f [$m local "tcl.dict.unset" STRING?<-STRING,int,STRING*,int*]
	params dict pathlen pathobjs ecvar
	build {
	    noalias $dict $pathobjs $ecvar
	    nonnull $dict $pathobjs $ecvar
	    set interp [$api tclInterp]
	    set dd [my Dedup dict]
	    set result [$api Tcl_DictObjRemoveKeyList $interp $dict $pathlen $pathobjs]
	    my condBr [my eq $result $0] $OK $notOK
	label OK:
	    my ret [my ok $dict]
	label notOK:
	    my Call obj.cleanup $dd
	    my store $1 $ecvar
	    my ret [my fail STRING]
	}

	##### Function tcl.dict.set1.empty #####
	#
	# Type signature: dict:STRING * key:STRING * value:STRING!
	#			* ecvar:int32* -> STRING?
	#
	# Sets a key in a dictionary to map to a value, or removes the mapping
	# if the value is NEXIST. Can fail if the "dict" is not a valid
	# dictionary.

	set f [$m local "tcl.dict.set1.empty" \
		   STRING?<-STRING,STRING,STRING!,int*]
	params dict key value ecvar
	build {
	    noalias $ecvar
	    nonnull $dict $key $ecvar
	    my condBr [my exists $value] $reallySet $reallyUnset
	label reallySet "real.set"
	    set value [my unmaybe $value]
	    my ret [my Call tcl.dict.set1 $dict $key $value $ecvar]
	label reallyUnset "real.unset"
	    my ret [my Call tcl.dict.unset1 $dict $key $ecvar]
	}

	##### Function tcl.dict.addIterReference #####
	#
	# Type signature: iter:DICTITER -> void
	#
	# Increments the reference count inside a dictionary iteration state.







|

|
<

|
|

<
|
<

|
<
<

|
<
<
<
<




|
|


|

|


















|
<


|
<

|
<
|

<
|



|

|







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
	    my Call obj.cleanup $dd
	    my store $1 $ecvar
	    my ret [my fail STRING]
	}

	##### Function tcl.dict.unset1 #####
	#
	# Type signature: dict:DICT * key:STRING -> DICT
	#
	# Removes a key from a dictionary.


	set f [$m local "tcl.dict.unset1" DICT<-DICT,STRING]
	params dict key
	build {

	    nonnull $dict $key

	    set dd [my Dedup dict]
	    $api Tcl_DictObjRemove {} $dict $key


	    my addReference(STRING) $dict
	    my ret $dict




	}

	##### Function tcl.dict.unset #####
	#
	# Type signature: dict:DICT * pathlen:int * pathobjs:STRING*
	#			* ecvar:int32* -> DICT?
	#
	# Removes a key (or rather a key path) from a dictionary. Can fail if
	# the dictionary contains a "dict" that is not a valid dictionary.

	set f [$m local "tcl.dict.unset" DICT?<-DICT,int,STRING*,int*]
	params dict pathlen pathobjs ecvar
	build {
	    noalias $dict $pathobjs $ecvar
	    nonnull $dict $pathobjs $ecvar
	    set interp [$api tclInterp]
	    set dd [my Dedup dict]
	    set result [$api Tcl_DictObjRemoveKeyList $interp $dict $pathlen $pathobjs]
	    my condBr [my eq $result $0] $OK $notOK
	label OK:
	    my ret [my ok $dict]
	label notOK:
	    my Call obj.cleanup $dd
	    my store $1 $ecvar
	    my ret [my fail STRING]
	}

	##### Function tcl.dict.set1.empty #####
	#
	# Type signature: dict:DICT * key:STRING * value:STRING! -> DICT

	#
	# Sets a key in a dictionary to map to a value, or removes the mapping
	# if the value is NEXIST.


	set f [$m local "tcl.dict.set1.empty" DICT<-DICT,STRING,STRING!]

	params dict key value
	build {

	    nonnull $dict $key
	    my condBr [my exists $value] $reallySet $reallyUnset
	label reallySet "real.set"
	    set value [my unmaybe $value]
	    my ret [my Call tcl.dict.set1 $dict $key $value]
	label reallyUnset "real.unset"
	    my ret [my Call tcl.dict.unset1 $dict $key]
	}

	##### Function tcl.dict.addIterReference #####
	#
	# Type signature: iter:DICTITER -> void
	#
	# Increments the reference count inside a dictionary iteration state.
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
	label release:
	    my Call tcl.dict.addIterReference [my unmaybe $value]
	    my ret
	}

	##### Function tcl.dict.iterStart #####
	#
	# Type signature: dict:STRING * ecvar:int* -> DICTITER?
	#
	# Starts iterating over a dictionary. The current state of the
	# iteration (assuming we don't get an error) is stored inside the
	# returned iteration state value.

	set f [$m local "tcl.dict.iterStart" DICTITER?<-STRING,int*]
	params dict ecvar
	build {
	    noalias $ecvar
	    nonnull $dict $ecvar
	    set done [my alloc int "done"]
	    set interp [$api tclInterp]
	    set iter [$api cknew DICTFOR]
	    set key [my gep $iter 0 DICTFOR.key]
	    SetValueName $key "keyPtr"
	    set value [my gep $iter 0 DICTFOR.value]
	    SetValueName $value "valuePtr"
	    set search [my gep $iter 0 DICTFOR.search]
	    set code [$api Tcl_DictObjFirst $interp $dict \
			$search $key $value $done]
	    my condBr [my eq $code $0] $ok $failed
	label ok:
	    my storeInStruct $iter DICTFOR.dict $dict
	    my storeInStruct $iter DICTFOR.ref $0
	    my storeInStruct $iter DICTFOR.done [my neq [my load $done] $0]
	    my addReference(STRING) $dict
	    my Call tcl.dict.addIterReference $iter
	    my ret [my ok $iter]
	label failed:
	    $api ckfree $iter
	    my store $1 $ecvar
	    my ret [my fail DICTITER]
	}

	##### Function tcl.dict.iterNext #####
	#
	# Type signature: iter:DICTITER -> DICTITER
	#
	# Continues iterating over a dictionary. The current state of the







|


<
|

|
|

<
|








|
<
<
<





|
<
<
<
<







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
	label release:
	    my Call tcl.dict.addIterReference [my unmaybe $value]
	    my ret
	}

	##### Function tcl.dict.iterStart #####
	#
	# Type signature: dict:DICT -> DICTITER
	#
	# Starts iterating over a dictionary. The current state of the

	# iteration is stored inside the returned iteration state value.

	set f [$m local "tcl.dict.iterStart" DICTITER<-DICT]
	params dict
	build {

	    nonnull $dict
	    set done [my alloc int "done"]
	    set interp [$api tclInterp]
	    set iter [$api cknew DICTFOR]
	    set key [my gep $iter 0 DICTFOR.key]
	    SetValueName $key "keyPtr"
	    set value [my gep $iter 0 DICTFOR.value]
	    SetValueName $value "valuePtr"
	    set search [my gep $iter 0 DICTFOR.search]
	    $api Tcl_DictObjFirst $interp $dict $search $key $value $done



	    my storeInStruct $iter DICTFOR.dict $dict
	    my storeInStruct $iter DICTFOR.ref $0
	    my storeInStruct $iter DICTFOR.done [my neq [my load $done] $0]
	    my addReference(STRING) $dict
	    my Call tcl.dict.addIterReference $iter
	    my ret $iter




	}

	##### Function tcl.dict.iterNext #####
	#
	# Type signature: iter:DICTITER -> DICTITER
	#
	# Continues iterating over a dictionary. The current state of the
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
	    set obj [my phi [list $obj $new] [list $real $alloc] "obj"]
	    my addReference(STRING) $obj
	    my ret $obj
	}

	##### Function tcl.dict.iterDone #####
	#
	# Type signature: iter:DICTITER -> ZEROONE
	#
	# Gets whether this iteration of the dictionary has finished.

	set f [$m local "tcl.dict.iterDone" ZEROONE<-DICTITER]
	params iter
	build {
	    nonnull $iter
	    my ret [my dereference $iter 0 DICTFOR.done]
	}

	##### Function tcl.dict.append #####
	#
	# Type signature: dict:STRING * key:STRING * value:STRING
	#			* ecvar:int32* -> STRING?
	#
	# Appends to value in a dictionary indicated by a key.  Can fail if the
	# "dict" is not a valid dictionary.

	set f [$m local "tcl.dict.append" STRING?<-STRING,STRING,STRING,int*]
	params dict key value ecvar
	build {
	    noalias $ecvar
	    nonnull $dict $key $value $ecvar
	    set valuePtr [my alloc STRING "valuePtr"]
	    set interp [$api tclInterp]
	    set dd [my Dedup dict]
	    set result [$api Tcl_DictObjGet $interp $dict $key $valuePtr]
	    my condBr [my eq $result $0] $OK $notOK
	label OK:
	    set dictVal [my load $valuePtr "value.in.dict"]
	    my condBr [my nonnull $dictVal] $append $set
	label set:
	    $api Tcl_DictObjPut {} $dict $key $value
	    my br $done
	label append:
	    my condBr [my shared $dictVal] $dupePut $directUpdate
	label directUpdate:
	    $api Tcl_AppendObjToObj $dictVal $value
	    $api TclInvalidateStringRep $dict
	    my br $done
	label dupePut:
	    set dictVal2 [$api Tcl_DuplicateObj $dictVal]
	    $api Tcl_AppendObjToObj $dictVal2 $value
	    set c [$api Tcl_DictObjPut {} $dict $key $dictVal2]
	    AddCallAttribute $c 3 nocapture
	    my br $done
	label done:
	    my addReference(STRING) $dict
	    my ret [my ok $dict]
	label notOK:
	    my Call obj.cleanup $dd
	    my store $1 $ecvar
	    my ret [my fail STRING]
	}

	##### Function tcl.dict.incr #####
	#
	# Type signature: dict:STRING * key:STRING * value:INT
	#			* ecvar:int32* -> STRING?
	#
	# Adds an integer to an integer in a dictionary indicated by a key.
	# Can fail if the "dict" is not a valid dictionary or the value
	# pointed to is not a valid integer.

	set f [$m local "tcl.dict.incr" STRING?<-STRING,STRING,INT,int*]
	params dict key value ecvar
	build {
	    noalias $ecvar
	    nonnull $dict $key $ecvar
	    set valuePtr [my alloc STRING "valuePtr"]
	    set intVar [my alloc int64 "intPtr"]
	    set interp [$api tclInterp]
	    set dd [my Dedup dict]
	    set result [$api Tcl_DictObjGet $interp $dict $key $valuePtr]
	    my condBr [my eq $result $0] $OK $notOK
	label OK:
	    set dictVal [my load $valuePtr "value.in.dict"]
	    my condBr [my nonnull $dictVal] $add $set
	label set:
	    set strVal [my stringify(INT) $value "value"]
	    my br $done
	label add:
	    # TODO: Revisit once we support bignums







|



|








|
<

|
<

|
|

<
|



|
<
<



















|
<
<
<
<




|
|


<
|

|








|
<
<







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
	    set obj [my phi [list $obj $new] [list $real $alloc] "obj"]
	    my addReference(STRING) $obj
	    my ret $obj
	}

	##### Function tcl.dict.iterDone #####
	#
	# Type signature: iter:DICTITER -> bool
	#
	# Gets whether this iteration of the dictionary has finished.

	set f [$m local "tcl.dict.iterDone" bool<-DICTITER]
	params iter
	build {
	    nonnull $iter
	    my ret [my dereference $iter 0 DICTFOR.done]
	}

	##### Function tcl.dict.append #####
	#
	# Type signature: dict:DICT * key:STRING * value:STRING -> DICT

	#
	# Appends to value in a dictionary indicated by a key.


	set f [$m local "tcl.dict.append" DICT<-DICT,STRING,STRING]
	params dict key value
	build {

	    nonnull $dict $key $value
	    set valuePtr [my alloc STRING "valuePtr"]
	    set interp [$api tclInterp]
	    set dd [my Dedup dict]
	    $api Tcl_DictObjGet {} $dict $key $valuePtr


	    set dictVal [my load $valuePtr "value.in.dict"]
	    my condBr [my nonnull $dictVal] $append $set
	label set:
	    $api Tcl_DictObjPut {} $dict $key $value
	    my br $done
	label append:
	    my condBr [my shared $dictVal] $dupePut $directUpdate
	label directUpdate:
	    $api Tcl_AppendObjToObj $dictVal $value
	    $api TclInvalidateStringRep $dict
	    my br $done
	label dupePut:
	    set dictVal2 [$api Tcl_DuplicateObj $dictVal]
	    $api Tcl_AppendObjToObj $dictVal2 $value
	    set c [$api Tcl_DictObjPut {} $dict $key $dictVal2]
	    AddCallAttribute $c 3 nocapture
	    my br $done
	label done:
	    my addReference(STRING) $dict
	    my ret $dict




	}

	##### Function tcl.dict.incr #####
	#
	# Type signature: dict:DICT * key:STRING * value:INT
	#			* ecvar:int32* -> DICT?
	#
	# Adds an integer to an integer in a dictionary indicated by a key.

	# Can fail if the value pointed to is not a valid integer.

	set f [$m local "tcl.dict.incr" DICT?<-DICT,STRING,INT,int*]
	params dict key value ecvar
	build {
	    noalias $ecvar
	    nonnull $dict $key $ecvar
	    set valuePtr [my alloc STRING "valuePtr"]
	    set intVar [my alloc int64 "intPtr"]
	    set interp [$api tclInterp]
	    set dd [my Dedup dict]
	    $api Tcl_DictObjGet {} $dict $key $valuePtr


	    set dictVal [my load $valuePtr "value.in.dict"]
	    my condBr [my nonnull $dictVal] $add $set
	label set:
	    set strVal [my stringify(INT) $value "value"]
	    my br $done
	label add:
	    # TODO: Revisit once we support bignums
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
	    my Call obj.cleanup $dd
	    my store $1 $ecvar
	    my ret [my fail STRING]
	}

	##### Function tcl.dict.lappend #####
	#
	# Type signature: dict:STRING * key:STRING * value:STRING
	#			* ecvar:int32* -> STRING?
	#
	# Appends to list in a dictionary indicated by a key.  Can fail if the
	# "dict" is not a valid dictionary or the value pointed to is not a
	# valid list.

	set f [$m local "tcl.dict.lappend" STRING?<-STRING,STRING,STRING,int*]
	params dict key value ecvar
	build {
	    noalias $ecvar
	    nonnull $dict $key $value $ecvar
	    set valuePtr [my alloc STRING "valuePtr"]
	    set interp [$api tclInterp]
	    set dd [my Dedup dict]
	    set result [$api Tcl_DictObjGet $interp $dict $key $valuePtr]
	    my condBr [my eq $result $0] $OK $notOK
	label OK:
	    set dictVal [my load $valuePtr "value.in.dict"]
	    my condBr [my nonnull $dictVal] $append $set
	label set:
	    my store $value $valuePtr
	    set newlist [$api Tcl_NewListObj $1 $valuePtr]
	    $api Tcl_DictObjPut {} $dict $key $newlist
	    my br $done







|
|


|
<

|







|
<
<







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
	    my Call obj.cleanup $dd
	    my store $1 $ecvar
	    my ret [my fail STRING]
	}

	##### Function tcl.dict.lappend #####
	#
	# Type signature: dict:DICT * key:STRING * value:STRING
	#			* ecvar:int32* -> DICT?
	#
	# Appends to list in a dictionary indicated by a key.  Can fail if the
	# value pointed to is not a valid list.


	set f [$m local "tcl.dict.lappend" DICT?<-DICT,STRING,STRING,int*]
	params dict key value ecvar
	build {
	    noalias $ecvar
	    nonnull $dict $key $value $ecvar
	    set valuePtr [my alloc STRING "valuePtr"]
	    set interp [$api tclInterp]
	    set dd [my Dedup dict]
	    $api Tcl_DictObjGet {} $dict $key $valuePtr


	    set dictVal [my load $valuePtr "value.in.dict"]
	    my condBr [my nonnull $dictVal] $append $set
	label set:
	    my store $value $valuePtr
	    set newlist [$api Tcl_NewListObj $1 $valuePtr]
	    $api Tcl_DictObjPut {} $dict $key $newlist
	    my br $done
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
    #	None.

    method StringComparisonFunctions {api} {
	upvar 1 sizeof sizeof 0 0 1 1

	##### Function tcl.streq #####
	#
	# Type signature: value1Ptr:STRING * value2Ptr:STRING -> ZEROONE
	#
	# Quadcode implementation ('streq')
	#
	# Returns whether the two string arguments are equal.

	set f [$m local "tcl.streq" ZEROONE<-STRING,STRING]
	params v1:value1Ptr v2:value2Ptr
	build {
	    nonnull $v1 $v2
	    my condBr [my eq $v1 $v2] $identical $nexttest
	label nexttest:
	    my condBr [my and [my isByteArray $v1] [my isByteArray $v2]] \
		$cmpBA $nexttest2







|





|







3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
    #	None.

    method StringComparisonFunctions {api} {
	upvar 1 sizeof sizeof 0 0 1 1

	##### Function tcl.streq #####
	#
	# Type signature: value1Ptr:STRING * value2Ptr:STRING -> bool
	#
	# Quadcode implementation ('streq')
	#
	# Returns whether the two string arguments are equal.

	set f [$m local "tcl.streq" bool<-STRING,STRING]
	params v1:value1Ptr v2:value2Ptr
	build {
	    nonnull $v1 $v2
	    my condBr [my eq $v1 $v2] $identical $nexttest
	label nexttest:
	    my condBr [my and [my isByteArray $v1] [my isByteArray $v2]] \
		$cmpBA $nexttest2
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
	    set diff [my phi [list $diffBA $diffUni $diffUtf] $sources]
	    my ret [my select [my eq $match $0] $diff $match]
	}

	##### Function tcl.strmatch #####
	#
	# Type signature: nocase:INT * pattern:STRING * string:STRING
	#			-> ZEROONE
	#
	# Quadcode implementation ('strmatch')
	#
	# Returns whether the glob pattern in 'pattern' matches 'string'. If
	# 'nocase' is non-zero, performs the match case-insensitively.

	set f [$m local "tcl.strmatch" ZEROONE<-INT,STRING,STRING]
	params nocaseInt:nocase patternObj:pattern stringObj:string
	build {
	    nonnull $patternObj $stringObj
	    set nocase [my getInt32 $nocaseInt]
	    my condBr [my isUnicodeString $patternObj] $test2 $ordinary
	label test2:
	    my condBr [my isUnicodeString $stringObj] $unicode $ordinary







|






|







3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
	    set diff [my phi [list $diffBA $diffUni $diffUtf] $sources]
	    my ret [my select [my eq $match $0] $diff $match]
	}

	##### Function tcl.strmatch #####
	#
	# Type signature: nocase:INT * pattern:STRING * string:STRING
	#			-> bool
	#
	# Quadcode implementation ('strmatch')
	#
	# Returns whether the glob pattern in 'pattern' matches 'string'. If
	# 'nocase' is non-zero, performs the match case-insensitively.

	set f [$m local "tcl.strmatch" bool<-INT,STRING,STRING]
	params nocaseInt:nocase patternObj:pattern stringObj:string
	build {
	    nonnull $patternObj $stringObj
	    set nocase [my getInt32 $nocaseInt]
	    my condBr [my isUnicodeString $patternObj] $test2 $ordinary
	label test2:
	    my condBr [my isUnicodeString $stringObj] $unicode $ordinary
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
		    $nocase]
	    my ret [my neq $match $0]
	}

	##### Function tcl.regexp #####
	#
	# Type signature: flags:INT * regexp:STRING * string:STRING
	#			* errVar:int* -> ZEROONE?
	#
	# Quadcode implementation ('regexp')
	#
	# Returns whether the regular expression in 'regexp' matches 'string'
	# as a WRAPPED BOOLEAN. The 'flags' control things like whether we are
	# matching case-insensitively. If the code fails (generally because of
	# a bad regular expression) then the result is a Nothing. The variable
	# pointed to by 'errVar' is set to the relevant Tcl result code.

	set f [$m local "tcl.regexp" ZEROONE?<-INT,STRING,STRING,int*]
	params flags patternObj:regexp stringObj:string errVar:errorCode
	build {
	    noalias $errVar
	    nonnull $patternObj $stringObj $errVar
	    set interp [$api tclInterp]
	    set RE [$api Tcl_GetRegExpFromObj $interp $patternObj \
		    [my getInt32 $flags]]
	    my condBr [my nonnull $RE] $exec $err
	label exec "re.exec"
	    set match [$api Tcl_RegExpExecObj $interp $RE $stringObj $0 $0 $0]
	    my condBr [my ge $match $0] $done $err
	label done "re.done"
	    my store $0 $errVar
	    my ret [my ok [my gt $match $0]]
	label err "re.error"
	    my store $1 $errVar
	    my ret [my fail ZEROONE]
	}

    }

    # Builder:@apiFunctions --
    #
    #	Generate the quadcode operator implementations that require access to







|









|
















|







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
		    $nocase]
	    my ret [my neq $match $0]
	}

	##### Function tcl.regexp #####
	#
	# Type signature: flags:INT * regexp:STRING * string:STRING
	#			* errVar:int* -> bool?
	#
	# Quadcode implementation ('regexp')
	#
	# Returns whether the regular expression in 'regexp' matches 'string'
	# as a WRAPPED BOOLEAN. The 'flags' control things like whether we are
	# matching case-insensitively. If the code fails (generally because of
	# a bad regular expression) then the result is a Nothing. The variable
	# pointed to by 'errVar' is set to the relevant Tcl result code.

	set f [$m local "tcl.regexp" bool?<-INT,STRING,STRING,int*]
	params flags patternObj:regexp stringObj:string errVar:errorCode
	build {
	    noalias $errVar
	    nonnull $patternObj $stringObj $errVar
	    set interp [$api tclInterp]
	    set RE [$api Tcl_GetRegExpFromObj $interp $patternObj \
		    [my getInt32 $flags]]
	    my condBr [my nonnull $RE] $exec $err
	label exec "re.exec"
	    set match [$api Tcl_RegExpExecObj $interp $RE $stringObj $0 $0 $0]
	    my condBr [my ge $match $0] $done $err
	label done "re.done"
	    my store $0 $errVar
	    my ret [my ok [my gt $match $0]]
	label err "re.error"
	    my store $1 $errVar
	    my ret [my fail bool]
	}

    }

    # Builder:@apiFunctions --
    #
    #	Generate the quadcode operator implementations that require access to
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
	# Type signature: returnCode:INT -> STRING
	#
	# Quadcode implementation ('returnOptions')
	#
	# Returns the return options dictionary. Note that this requires the
	# current Tcl result code in order to work correctly.

	set f [$module local "tcl.getreturnopts" STRING<-INT]
	params value:returnCode
	build {
	    set code [my int.32 $value "code"]
	    set opts [$api Tcl_GetReturnOptions [$api tclInterp] $code]
	    SetValueName $opts "optionsObj"
	    my addReference(STRING) $opts
	    my ret $opts
	}

	##### Function tcl.initExceptionOptions #####
	#
	# Type signature: objPtr:STRING * dictPtr:STRING -> int
	#
	# Initialises the return options from what we know about an exception.

	set f [$module local "tcl.initExceptionOptions" int<-STRING,STRING]
	params result:objPtr opts:dictPtr
	build {
	    nonnull $result $opts
	    set interp [$api tclInterp]
	    set code [$api Tcl_SetReturnOptions $interp $opts]
	    my switch $code $other 0 $ok 1 $error
	label ok:







|











|



|







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
	# Type signature: returnCode:INT -> STRING
	#
	# Quadcode implementation ('returnOptions')
	#
	# Returns the return options dictionary. Note that this requires the
	# current Tcl result code in order to work correctly.

	set f [$module local "tcl.getreturnopts" DICT<-INT]
	params value:returnCode
	build {
	    set code [my int.32 $value "code"]
	    set opts [$api Tcl_GetReturnOptions [$api tclInterp] $code]
	    SetValueName $opts "optionsObj"
	    my addReference(STRING) $opts
	    my ret $opts
	}

	##### Function tcl.initExceptionOptions #####
	#
	# Type signature: objPtr:STRING * dictPtr:DICT -> int
	#
	# Initialises the return options from what we know about an exception.

	set f [$module local "tcl.initExceptionOptions" int<-STRING,DICT]
	params result:objPtr opts:dictPtr
	build {
	    nonnull $result $opts
	    set interp [$api tclInterp]
	    set code [$api Tcl_SetReturnOptions $interp $opts]
	    my switch $code $other 0 $ok 1 $error
	label ok:
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
	    my store [my or [my load $field] [Const 0x800]] $field
	    my ret
	}

	##### Function tcl.processReturn #####
	#
	# Type signature: result:STRING * code:int * level:int
	#			* returnOpts:STRING -> int
	#
	# Initialises the return options from what we know about an exception.
	# Analogous to TclProcessReturn, which isn't exposed.
	#
	# Note that returnOpts may be NULL; that's equivalent to an empty
	# options dictionary, but is special-cased so it is handled more
	# efficiently by the optimizer.

	set f [$module local "tcl.processReturn" int<-STRING,int,int,STRING]
	params result code level returnOpts
	build {
	    nonnull $result
	    set valuePtr [my alloc STRING "valuePtr"]
	    set infoLen [my alloc int "infoLen"]
	    set objcPtr [my alloc int]
	    set objvPtr [my alloc STRING*]







|








|







3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
	    my store [my or [my load $field] [Const 0x800]] $field
	    my ret
	}

	##### Function tcl.processReturn #####
	#
	# Type signature: result:STRING * code:int * level:int
	#			* returnOpts:DICT -> int
	#
	# Initialises the return options from what we know about an exception.
	# Analogous to TclProcessReturn, which isn't exposed.
	#
	# Note that returnOpts may be NULL; that's equivalent to an empty
	# options dictionary, but is special-cased so it is handled more
	# efficiently by the optimizer.

	set f [$module local "tcl.processReturn" int<-STRING,int,int,DICT]
	params result code level returnOpts
	build {
	    nonnull $result
	    set valuePtr [my alloc STRING "valuePtr"]
	    set infoLen [my alloc int "infoLen"]
	    set objcPtr [my alloc int]
	    set objvPtr [my alloc STRING*]
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
	    my br $done
	label done:
	    my ret
	}

	##### Function tcl.booleanTest #####
	#
	# Type signature: objPtr:Tcl_Obj* -> ZEROONE
	#
	# Part of quadcode implementation ('isBoolean')
	#
	# Returns whether the string 'objPtr' is a Boolean bareword

	set f [$m local "tcl.booleanTest" ZEROONE<-Tcl_Obj*]
	params objPtr
	build {
	    nonnull $objPtr
	    set NULL [my null Interp*]
	    set code [my setFromAny [$api tclBooleanType] $NULL $objPtr]
	    my ret [my eq $code $0]
	}







|





|







4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
	    my br $done
	label done:
	    my ret
	}

	##### Function tcl.booleanTest #####
	#
	# Type signature: objPtr:Tcl_Obj* -> bool
	#
	# Part of quadcode implementation ('isBoolean')
	#
	# Returns whether the string 'objPtr' is a Boolean bareword

	set f [$m local "tcl.booleanTest" bool<-Tcl_Obj*]
	params objPtr
	build {
	    nonnull $objPtr
	    set NULL [my null Interp*]
	    set code [my setFromAny [$api tclBooleanType] $NULL $objPtr]
	    my ret [my eq $code $0]
	}
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
	label fail:
	    my store $code $ecvar
	    my ret [my fail STRING $code]
	}

	##### Function tcl.existsOrError #####
	#
	# Type signature: exists:int1 * message:STRING * ecvar:int* -> int1
	#
	# Conditionally generates an error about a non-existing variable.
	# Generated like this to avoid introducing extra basic blocks at the
	# pre-optimized LLVM level.

	set f [$module local "tcl.existsOrError" int1<-int1,STRING,STRING,int*]
	params exists message exception ecvar
	build {
	    noalias $message $ecvar
	    nonnull $message $exception $ecvar
	    my condBr $exists $doError $done
	label doError:
	    my initException $exception $message $ecvar
	    my br $done
	label done:
	    my ret $exists
	}

	##### Function tcl.not.string #####
	#
	# Type signature: value:STRING * ecvar:int* -> ZEROONE?
	#
	# Quadcode implementation ('not').
	#
	# Logical negation of 'value'.

	set f [$m local "tcl.not.string" ZEROONE?<-STRING,int*]
	params value ecvar
	build {
	    noalias $ecvar
	    nonnull $value $ecvar
	    set bvar [my alloc int]
	    set interp [$api tclInterp]
	    set code [$api Tcl_GetBooleanFromObj $interp $value $bvar]
	    my condBr [my eq $code [Const 0]] $ok $fail
	label fail:
	    my store [Const 1] $ecvar
	    my ret [my fail ZEROONE]
	label ok:
	    my ret [my ok [my neq [my load $bvar "bool"] [Const 1]]]
	}

	my VariableHelperFunctions $api
	my @variableFunctions $api
	my @numericConverterFunctions $api







|





|














|





|










|







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
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
	label fail:
	    my store $code $ecvar
	    my ret [my fail STRING $code]
	}

	##### Function tcl.existsOrError #####
	#
	# Type signature: exists:bool * message:STRING * ecvar:int* -> bool
	#
	# Conditionally generates an error about a non-existing variable.
	# Generated like this to avoid introducing extra basic blocks at the
	# pre-optimized LLVM level.

	set f [$module local "tcl.existsOrError" bool<-bool,STRING,STRING,int*]
	params exists message exception ecvar
	build {
	    noalias $message $ecvar
	    nonnull $message $exception $ecvar
	    my condBr $exists $doError $done
	label doError:
	    my initException $exception $message $ecvar
	    my br $done
	label done:
	    my ret $exists
	}

	##### Function tcl.not.string #####
	#
	# Type signature: value:STRING * ecvar:int* -> bool?
	#
	# Quadcode implementation ('not').
	#
	# Logical negation of 'value'.

	set f [$m local "tcl.not.string" bool?<-STRING,int*]
	params value ecvar
	build {
	    noalias $ecvar
	    nonnull $value $ecvar
	    set bvar [my alloc int]
	    set interp [$api tclInterp]
	    set code [$api Tcl_GetBooleanFromObj $interp $value $bvar]
	    my condBr [my eq $code [Const 0]] $ok $fail
	label fail:
	    my store [Const 1] $ecvar
	    my ret [my fail bool]
	label ok:
	    my ret [my ok [my neq [my load $bvar "bool"] [Const 1]]]
	}

	my VariableHelperFunctions $api
	my @variableFunctions $api
	my @numericConverterFunctions $api

Changes to codegen/struct.tcl.

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
	    }
	    {NOTHING STRING} {
		append body2 { [my undef STRING]}
	    }
	    {{EXPANDED STRING} STRING} {
		append body2 { $} [lindex $f 0]
	    }












	    {{EXPANDED INT} INT} {
		append body2 { $} [lindex $f 0]
	    }
	    {{EXPANDED DOUBLE} DOUBLE} {
		append body2 { $} [lindex $f 0]
	    }
	    {{EXPANDED NUMERIC} NUMERIC} {
		append body2 { $} [lindex $f 0]
	    }
	    {{EXPANDED {NUMERIC BOOLEAN}} {NUMERIC BOOLEAN}} {
		append body2 { $} [lindex $f 0]
	    }














































































	}

	foreach type {
	    BOOLEAN
	    ZEROONE {ZEROONE BOOLEAN}
	    INT {INT BOOLEAN}
	    DOUBLE







>
>
>
>
>
>
>
>
>
>
>
>












>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







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
	    }
	    {NOTHING STRING} {
		append body2 { [my undef STRING]}
	    }
	    {{EXPANDED STRING} STRING} {
		append body2 { $} [lindex $f 0]
	    }
	    {{EXPANDED LIST} LIST} {
		append body2 { $} [lindex $f 0]
	    }
	    {{EXPANDED LIST} STRING} {
		append body2 { $} [lindex $f 0]
	    }
	    {{EXPANDED DICT} DICT} {
		append body2 { $} [lindex $f 0]
	    }
	    {{EXPANDED DICT} STRING} {
		append body2 { $} [lindex $f 0]
	    }
	    {{EXPANDED INT} INT} {
		append body2 { $} [lindex $f 0]
	    }
	    {{EXPANDED DOUBLE} DOUBLE} {
		append body2 { $} [lindex $f 0]
	    }
	    {{EXPANDED NUMERIC} NUMERIC} {
		append body2 { $} [lindex $f 0]
	    }
	    {{EXPANDED {NUMERIC BOOLEAN}} {NUMERIC BOOLEAN}} {
		append body2 { $} [lindex $f 0]
	    }
	    {{IMPURE DICT} STRING} {
		append body2 { $} [lindex $f 0]
	    }
	    {{IMPURE EMPTY DICT} STRING} {
		append body2 { $} [lindex $f 0]
	    }
	    {{IMPURE EMPTY DICT} DICT} {
		append body2 { $} [lindex $f 0]
	    }
	    {{EMPTY DICT} DICT} {
		append body2 { $} [lindex $f 0]
	    }
	    {DICT STRING} {
		append body2 { $} [lindex $f 0]
	    }
	    {{EMPTY DICT} STRING} {
		append body2 { $} [lindex $f 0]
	    }
	    {{IMPURE LIST} STRING} {
		append body2 { $} [lindex $f 0]
	    }
	    {{IMPURE EMPTY LIST} STRING} {
		append body2 { $} [lindex $f 0]
	    }
	    {{EMPTY LIST} STRING} {
		append body2 { $} [lindex $f 0]
	    }
	    {EMPTY {EMPTY LIST}} {
		append body2 { $} [lindex $f 0]
	    }
	    {EMPTY {EMPTY DICT}} {
		append body2 { $} [lindex $f 0]
	    }
	    {LIST STRING} {
		append body2 { $} [lindex $f 0]
	    }
	    {{IMPURE EMPTY LIST} LIST} {
		append body2 { $} [lindex $f 0]
	    }
	    {{EMPTY LIST} LIST} {
		append body2 { $} [lindex $f 0]
	    }
	    {DICT LIST} {
		append body2 { $} [lindex $f 0]
	    }
	    {{EMPTY DICT} {EMPTY LIST}} {
		append body2 { $} [lindex $f 0]
	    }
	    {{IMPURE DICT} {IMPURE LIST}} {
		append body2 { $} [lindex $f 0]
	    }
	    {{IMPURE EMPTY DICT} {IMPURE EMPTY LIST}} {
		append body2 { $} [lindex $f 0]
	    }
	    {{NEXIST DICT} {NEXIST STRING}} {
		append body2 { $} [lindex $f 0]
	    }
	    {{NEXIST LIST} {NEXIST STRING}} {
		append body2 { $} [lindex $f 0]
	    }
	    {{NEXIST EMPTY DICT} {NEXIST STRING}} {
		append body2 { $} [lindex $f 0]
	    }
	    {{NEXIST EMPTY LIST} {NEXIST STRING}} {
		append body2 { $} [lindex $f 0]
	    }
	    {{FAIL DICT} {FAIL STRING}} {
		append body2 { $} [lindex $f 0]
	    }
	    {{FAIL LIST} {FAIL STRING}} {
		append body2 { $} [lindex $f 0]
	    }
	    {{FAIL EMPTY DICT} {FAIL STRING}} {
		append body2 { $} [lindex $f 0]
	    }
	    {{FAIL EMPTY LIST} {FAIL STRING}} {
		append body2 { $} [lindex $f 0]
	    }
	}

	foreach type {
	    BOOLEAN
	    ZEROONE {ZEROONE BOOLEAN}
	    INT {INT BOOLEAN}
	    DOUBLE
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
    #	FOLLOWS STANDARD TclOO PROTOCOL
    #
    # Side effects:
    # 	May create a method. May perform a tailcall (beware if attempting to
    # 	wrap with a filter!)

    method unknown {methodName args} {


	if {[regexp {^addReference\(FAIL[ _]IMPURE (.*)\)$} \
		 $methodName -> utype]} {

	    oo::objdefine [self] method $methodName {value} \
		[string map [list @utype $utype] {
		    set sval [my impure.string [my unmaybe $value]]
		    my impure.maybeAddReference [my maybe $value] $sval
		}]
	    tailcall my $methodName {*}$args


	} elseif {[regexp {^dropReference\(FAIL[ _]IMPURE[ _](.*)\)$} \
		       $methodName -> utype]} {

	    oo::objdefine [self] method $methodName {value} \
		[string map [list @utype $utype] {
		    my select [my maybe $value] \
			[Const false bool] \
			[my addReference(STRING) \
			     [my impure.string [my unmaybe $value]]]
		}]
	    tailcall my $methodName {*}$args


	} elseif {[regexp {^addReference\(IMPURE[ _](.*)\)$} \
		       $methodName -> utype]} {

	    oo::objdefine [self] method $methodName {value} \
		[string map [list @utype $utype] {
		    my addReference(STRING) [my impure.string $value]
		}]
	    tailcall my $methodName {*}$args


	} elseif {[regexp {^dropReference\(IMPURE[ _](.*)\)$} $methodName \
		       -> utype]} {

	    oo::objdefine [self] method $methodName {value} \
		[string map [list @utype $utype] {
		    my dropReference(STRING) [my impure.string $value]
		    # How to determine whether the underlying type is
		    # itself a reference type? (Maybe never?)
		    #my {dropReference(@utype)} [my impure.value $value]
		}]
	    tailcall my $methodName {*}$args



	} elseif {[my MakeTypecastWrapper $methodName]} {
	    set v [my $methodName {*}$args]
	    return $v
	}
	next $methodName {*}$args
    }
    unexport unknown

    # Builder:MakeTypecastWrapper --
    #







>
>
|
|
>
|
|
|
|
|
|
>
>
|
|
>
|
|
|
|
|
|
|
|
>
>
|
|
>
|
|
|
|
|
|
>
|
|
>
|
|
|
|
|
|
|
|
>
>
>
|
|
<







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
    #	FOLLOWS STANDARD TclOO PROTOCOL
    #
    # Side effects:
    # 	May create a method. May perform a tailcall (beware if attempting to
    # 	wrap with a filter!)

    method unknown {methodName args} {
	set BASIC_REFTYPES {STRING LIST {EMPTY LIST} DICT {EMPTY DICT}}
	switch -regexp -matchvar match -- $methodName {
	    {^addReference\(FAIL[ _]IMPURE (.*)\)$} {
		lassign $match -> utype
		if {$utype ni $BASIC_REFTYPES} {
		    oo::objdefine [self] method $methodName {value} \
			[string map [list @utype $utype] {
			    set sval [my impure.string [my unmaybe $value]]
			    my impure.maybeAddReference [my maybe $value] $sval
			}]
		    tailcall my $methodName {*}$args
		}
	    }
	    {^dropReference\(FAIL[ _]IMPURE[ _](.*)\)$} {
		lassign $match -> utype
		if {$utype ni $BASIC_REFTYPES} {
		    oo::objdefine [self] method $methodName {value} \
			[string map [list @utype $utype] {
			    my select [my maybe $value] \
				[Const false bool] \
				[my addReference(STRING) \
				     [my impure.string [my unmaybe $value]]]
			}]
		    tailcall my $methodName {*}$args
		}
	    }
	    {^addReference\(IMPURE[ _](.*)\)$} {
		lassign $match -> utype
		if {$utype ni $BASIC_REFTYPES} {
		    oo::objdefine [self] method $methodName {value} \
			[string map [list @utype $utype] {
			    my addReference(STRING) [my impure.string $value]
			}]
		    tailcall my $methodName {*}$args
		}
	    }
	    {^dropReference\(IMPURE[ _](.*)\)$} {
		lassign $match -> utype
		if {$utype ni $BASIC_REFTYPES} {
		    oo::objdefine [self] method $methodName {value} \
			[string map [list @utype $utype] {
			    my dropReference(STRING) [my impure.string $value]
			    # How to determine whether the underlying type is
			    # itself a reference type? (Maybe never?)
			    #my {dropReference(@utype)} [my impure.value $value]
			}]
		    tailcall my $methodName {*}$args
		}
	    }
	}
	if {[my MakeTypecastWrapper $methodName]} {
	    tailcall my $methodName {*}$args

	}
	next $methodName {*}$args
    }
    unexport unknown

    # Builder:MakeTypecastWrapper --
    #

Changes to codegen/thunk.tcl.

470
471
472
473
474
475
476



477

478
479

480
481
482
483
484
485
486
	    $b condBr [$b maybe $result] $isFail $next
	    $isFail build $b {
		$b ret [$b extract $result 0]
	    }
	    $next build-in $b
	    set result [$b unmaybe $result]
	}



	if {[regexp "^IMPURE (.*)" $resultType]} {

	    set result [$b impure.string $result]
	    SetValueName $result @result

	    set resultType STRING
	}
	upvar 0 thunk.result.$resultType thunkResultMapper
	if {![info exist thunkResultMapper]} {
	    error "unhandled result type: $resultType"
	}
	$b call $thunkResultMapper [list $interp $result]







>
>
>
|
>
|
|
>







470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
	    $b condBr [$b maybe $result] $isFail $next
	    $isFail build $b {
		$b ret [$b extract $result 0]
	    }
	    $next build-in $b
	    set result [$b unmaybe $result]
	}
	set resultType [string map {
	    {EMPTY STRING} STRING
	} [string map {DICT STRING LIST STRING} $resultType]]
	if {[regexp "^IMPURE (.*)" $resultType -> payload]} {
	    if {$payload ne "STRING"} {
		set result [$b impure.string $result]
		SetValueName $result @result
	    }
	    set resultType STRING
	}
	upvar 0 thunk.result.$resultType thunkResultMapper
	if {![info exist thunkResultMapper]} {
	    error "unhandled result type: $resultType"
	}
	$b call $thunkResultMapper [list $interp $result]

Changes to codegen/tycon.tcl.

69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
		    return [ConstInt [Type bool] 1 0]
		}
		if {[string is false -strict $value]} {
		    return [ConstInt [Type bool] 0 0]
		}
		error "invalid boolean value \"$value\""
	    }
	    "^STRING$" - "^EMPTY$" {
		variable thunkBuilder
		set theObj [$thunkBuilder obj.constant $value]
		return $theObj
	    }
	    {^LLVMTypeRef_\d+$} {
		switch [GetTypeKind $type] {
		    LLVMIntegerTypeKind {







|







69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
		    return [ConstInt [Type bool] 1 0]
		}
		if {[string is false -strict $value]} {
		    return [ConstInt [Type bool] 0 0]
		}
		error "invalid boolean value \"$value\""
	    }
	    "^STRING$" - "^(?:EMPTY )?(?:LIST|DICT)$" - "^EMPTY$" {
		variable thunkBuilder
		set theObj [$thunkBuilder obj.constant $value]
		return $theObj
	    }
	    {^LLVMTypeRef_\d+$} {
		switch [GetTypeKind $type] {
		    LLVMIntegerTypeKind {
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
	    ^long$ {
		# Machine word
		return [IntType [expr {$::tcl_platform(wordSize) * 8}]]
	    }
	    {^int(\d+)$} {
		return [IntType [lindex $m 1]]
	    }
	    ^STRING$ - ^EMPTY$ {
		return [Type named{Tcl_Obj}*]
	    }
	    ^ZEROONE$ - ^BOOLEAN$ - "^ZEROONE BOOLEAN$" {
		return [Type bool]
	    }
	    ^INT$ - ^ENTIER$ - "^INT BOOLEAN$" {
		return [Type named{INT,kind:int1,i32:int,i64:int64}]







|







166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
	    ^long$ {
		# Machine word
		return [IntType [expr {$::tcl_platform(wordSize) * 8}]]
	    }
	    {^int(\d+)$} {
		return [IntType [lindex $m 1]]
	    }
	    ^STRING$ - {^(EMPTY )?(LIST|DICT)$} - ^EMPTY$ {
		return [Type named{Tcl_Obj}*]
	    }
	    ^ZEROONE$ - ^BOOLEAN$ - "^ZEROONE BOOLEAN$" {
		return [Type bool]
	    }
	    ^INT$ - ^ENTIER$ - "^INT BOOLEAN$" {
		return [Type named{INT,kind:int1,i32:int,i64:int64}]
232
233
234
235
236
237
238



239
240
241
242
243
244
245
		return [Type "FAIL NEXIST [lindex $m 1]"]
	    }
	    {^(.*) FAIL$} - {^FAIL (.*)} - {^(.*)\?$} {
		return [Type struct{int,[Type [lindex $m 1]]}]
	    }
	    {^NEXIST (.*)$} - {^(.*)\!$} {
		return [Type struct{bool,[Type [lindex $m 1]]}]



	    }
	    {^IMPURE (.*)$} - {^<(.*)>$} {
		return [Type struct{STRING,[Type [lindex $m 1]]}]
	    }
	    {\*$} {
		return [PointerType [Type [string range $t 0 end-1]] 0]
	    }







>
>
>







232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
		return [Type "FAIL NEXIST [lindex $m 1]"]
	    }
	    {^(.*) FAIL$} - {^FAIL (.*)} - {^(.*)\?$} {
		return [Type struct{int,[Type [lindex $m 1]]}]
	    }
	    {^NEXIST (.*)$} - {^(.*)\!$} {
		return [Type struct{bool,[Type [lindex $m 1]]}]
	    }
	    {^IMPURE (?:EMPTY )?(LIST|DICT)$} {
		return [Type [lindex $m 1]]
	    }
	    {^IMPURE (.*)$} - {^<(.*)>$} {
		return [Type struct{STRING,[Type [lindex $m 1]]}]
	    }
	    {\*$} {
		return [PointerType [Type [string range $t 0 end-1]] 0]
	    }

Changes to demos/perftest/tester.tcl.

2231
2232
2233
2234
2235
2236
2237














2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
set msg "Cryptographic Forum Research Group"
set tag [fromHex {a8:06:1d:c1:30:51:36:c6:c2:2b:8b:af:0c:01:27:a9}]

# A simple helper that is not compiled, but rather just shortens code below

proc cleanopt {script} {
    variable cleanopt














    set code [uplevel 1 [list catch $script cleanopt(msg) cleanopt(opt)]]
    set msg $cleanopt(msg)
    set opt $cleanopt(opt)
    if {[dict exists $opt -during]} {
	dict set opt -during [lsort -stride 2 -dictionary -index 0 \
				  [dict remove [dict get $opt -during] \
				       -during -errorinfo -errorstack]]
    }
    list $code $msg [lsort -stride 2 -dictionary -index 0 \
			 [dict remove $opt -errorinfo -errorstack]]
}

#########################################################################
#
# List of demonstration scripts. Each of these will be executed before and
# after having the compilation engine applied; the output values from before
# and after will be compared, and if they match, the performance ratio will be







>
>
>
>
>
>
>
>
>
>
>
>
>
>





|
<


|







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
set msg "Cryptographic Forum Research Group"
set tag [fromHex {a8:06:1d:c1:30:51:36:c6:c2:2b:8b:af:0c:01:27:a9}]

# A simple helper that is not compiled, but rather just shortens code below

proc cleanopt {script} {
    variable cleanopt
    set badopts {-errorinfo -errorstack}
    set code [uplevel 1 [list catch $script cleanopt(msg) cleanopt(opt)]]
    set msg $cleanopt(msg)
    set opt $cleanopt(opt)
    if {[dict exists $opt -during]} {
	dict set opt -during [lsort -stride 2 -dictionary -index 0 \
		[dict remove [dict get $opt -during] -during {*}$badopts]]
    }
    list $code $msg [lsort -stride 2 -dictionary -index 0 \
	    [dict remove $opt {*}$badopts]]
}
proc cleaneropt {script} {
    variable cleanopt
    set badopts {-errorinfo -errorstack -errorline -errorcode}
    set code [uplevel 1 [list catch $script cleanopt(msg) cleanopt(opt)]]
    set msg $cleanopt(msg)
    set opt $cleanopt(opt)
    if {[dict exists $opt -during]} {
	dict set opt -during [lsort -stride 2 -dictionary -index 0 \
		[dict remove [dict get $opt -during] -during {*}$badopts]]

    }
    list $code $msg [lsort -stride 2 -dictionary -index 0 \
	    [dict remove $opt {*}$badopts]]
}

#########################################################################
#
# List of demonstration scripts. Each of these will be executed before and
# after having the compilation engine applied; the output values from before
# and after will be compared, and if they match, the performance ratio will be
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
    {expandtest::test1}
    {expandtest::test2}
    {expandtest::test3}
    # {expandtest::test5}   Needs support for loop exception ranges
    {expandtest::test6 {a b c d e} {2 2} x}
    {expandtest::test7}
    {expandtest::test8}
    {cleanopt {expandtest::test9}}
    {cleanopt {expandtest::test10}}
    {cleanopt {expandtest::test11}}
    {cleanopt {expandtest::test12}}

    {bug-0616bcf08e::msrange 0 10}
    {bug-0616bcf08e::msrange2 0 10}
    {singleton::lforeach}
    {singleton::llindex}
    {singleton::srange}
    {qsort {3 6 8 7 0 1 4 2 9 5}}







|
|
|
|







2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
    {expandtest::test1}
    {expandtest::test2}
    {expandtest::test3}
    # {expandtest::test5}   Needs support for loop exception ranges
    {expandtest::test6 {a b c d e} {2 2} x}
    {expandtest::test7}
    {expandtest::test8}
    {cleaneropt {expandtest::test9}}
    {cleaneropt {expandtest::test10}}
    {cleaneropt {expandtest::test11}}
    {cleaneropt {expandtest::test12}}

    {bug-0616bcf08e::msrange 0 10}
    {bug-0616bcf08e::msrange2 0 10}
    {singleton::lforeach}
    {singleton::llindex}
    {singleton::srange}
    {qsort {3 6 8 7 0 1 4 2 9 5}}

Changes to quadcode/translate.tcl.

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
		set value [list temp [incr depth -1]]
		set r [list temp $depth]
		my generate-arith-domain-check $pc [lindex $insn 0] $value
		my quads purify {temp opd0} $value
		set op [lindex $insn 0]
		my quads $op $r {temp opd0}
	    }
	    listNotIn {
		set v1 [list temp [incr depth -1]]
		set v0 [list temp [incr depth -1]]
		set r $v0


		my error-quads $pc listIn $r $v0 $v1

		my quads not $r $r

	    }
	    div - expon - mod {
		set v1 [list temp [incr depth -1]]
		set v0 [list temp [incr depth -1]]
		set r $v0
		my generate-arith-domain-check $pc [lindex $insn 0] $v0 $v1
		my quads purify {temp opd0} $v0
		my quads purify {temp opd1} $v1
		my error-quads $pc [lindex $insn 0] $r {temp opd0} {temp opd1}
	    }
	    listIn - strindex {
		set v1 [list temp [incr depth -1]]
		set v0 [list temp [incr depth -1]]
		set r $v0
		my error-quads $pc [lindex $insn 0] $r $v0 $v1
	    }
	    regexp {
		set flag [list literal [lindex $insn 1]]
		set v1 [list temp [incr depth -1]]
		set v0 [list temp [incr depth -1]]
		set r $v0
		my error-quads $pc regexp $r $flag $v0 $v1
	    }
	    lsetFlat {
		set old [list temp [incr depth -1]]
		set elem [list temp [incr depth -1]]
		set indices {}
		for {set i 0} {$i < [lindex $insn 1]-2} {incr i} {
		    lappend indices [list temp [incr depth -1]]
		}


		set new [list temp $depth]
		my error-quads $pc listSet $new $old $elem {*}[lreverse $indices]
	    }
	    lsetList {
		set old [list temp [incr depth -1]]
		set elem [list temp [incr depth -1]]
		set idx [list temp [incr depth -1]]
		set new [list temp $depth]


		my error-quads $pc listSet $new $old $elem $idx
	    }
	    strmatch {
		set flag [list literal [lindex $insn 1]]
		set v1 [list temp [incr depth -1]]
		set v0 [list temp [incr depth -1]]
		set r $v0
		my quads [lindex $insn 0] $r $flag $v0 $v1







|



>
>
|
>
|
>










|



















>
>

|






>
>
|







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
		set value [list temp [incr depth -1]]
		set r [list temp $depth]
		my generate-arith-domain-check $pc [lindex $insn 0] $value
		my quads purify {temp opd0} $value
		set op [lindex $insn 0]
		my quads $op $r {temp opd0}
	    }
	    listIn - listNotIn {
		set v1 [list temp [incr depth -1]]
		set v0 [list temp [incr depth -1]]
		set r $v0
		my generate-list-domain-check $pc [lindex $insn 0] $v0
		my quads purify {temp opd0} $v0
		my error-quads $pc listIn $r {temp opd0} $v1
		if {[lindex $insn 0] eq "listNotIn"} {
		    my quads not $r $r
		}
	    }
	    div - expon - mod {
		set v1 [list temp [incr depth -1]]
		set v0 [list temp [incr depth -1]]
		set r $v0
		my generate-arith-domain-check $pc [lindex $insn 0] $v0 $v1
		my quads purify {temp opd0} $v0
		my quads purify {temp opd1} $v1
		my error-quads $pc [lindex $insn 0] $r {temp opd0} {temp opd1}
	    }
	    strindex {
		set v1 [list temp [incr depth -1]]
		set v0 [list temp [incr depth -1]]
		set r $v0
		my error-quads $pc [lindex $insn 0] $r $v0 $v1
	    }
	    regexp {
		set flag [list literal [lindex $insn 1]]
		set v1 [list temp [incr depth -1]]
		set v0 [list temp [incr depth -1]]
		set r $v0
		my error-quads $pc regexp $r $flag $v0 $v1
	    }
	    lsetFlat {
		set old [list temp [incr depth -1]]
		set elem [list temp [incr depth -1]]
		set indices {}
		for {set i 0} {$i < [lindex $insn 1]-2} {incr i} {
		    lappend indices [list temp [incr depth -1]]
		}
		my generate-list-domain-check $pc [lindex $insn 0] $old
		my quads purify {temp opd0} $old
		set new [list temp $depth]
		my error-quads $pc listSet $new {temp opd0} $elem {*}[lreverse $indices]
	    }
	    lsetList {
		set old [list temp [incr depth -1]]
		set elem [list temp [incr depth -1]]
		set idx [list temp [incr depth -1]]
		set new [list temp $depth]
		my generate-list-domain-check $pc [lindex $insn 0] $old
		my quads purify {temp opd0} $old
		my error-quads $pc listSet $new {temp opd0} $elem $idx
	    }
	    strmatch {
		set flag [list literal [lindex $insn 1]]
		set v1 [list temp [incr depth -1]]
		set v0 [list temp [incr depth -1]]
		set r $v0
		my quads [lindex $insn 0] $r $flag $v0 $v1
407
408
409
410
411
412
413




414
415
416
417
418
419
420
		dict with aux {}
		set n [expr {$depth - [llength $assign] - 1}]
		set lists {}
		foreach group $assign {
		    lappend lists [list temp [incr n]]
		}
		set res [list temp $depth]




		my error-quads $pc foreachStart $res [list literal $assign] {*}$lists
		foreach list $lists {
		    my quads unshareList $list $list
		}
		my generate-jump [expr {$pc + 5 - $jumpOffset}]
	    }
	    foreach_step {







>
>
>
>







415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
		dict with aux {}
		set n [expr {$depth - [llength $assign] - 1}]
		set lists {}
		foreach group $assign {
		    lappend lists [list temp [incr n]]
		}
		set res [list temp $depth]
		foreach list $lists {
		    my generate-list-domain-check $pc [lindex $insn 0] $list
		    my quads purify $list $list
		}
		my error-quads $pc foreachStart $res [list literal $assign] {*}$lists
		foreach list $lists {
		    my quads unshareList $list $list
		}
		my generate-jump [expr {$pc + 5 - $jumpOffset}]
	    }
	    foreach_step {
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
		set var [my index-to-var [lindex $insn 1]]
		set dict [list temp [incr depth -1]]
		set value [list temp $depth]
		set key [list temp [incr depth]]
		set done [list temp [incr depth]]
		my generate-scalar-check $pc $var {TCL WRITE VARNAME} \
		    "can't set \"%s\": variable is array"


		my error-quads $pc dictIterStart $var $dict
		my quads dictIterKey $key $var
		my quads dictIterValue $value $var
		my quads dictIterDone $done $var
	    }
	    dictNext {
		set var [my index-to-var [lindex $insn 1]]
		set value [list temp $depth]
		set key [list temp [incr depth]]
		set done [list temp [incr depth]]
		my generate-scalar-check $pc $var {TCL WRITE VARNAME} \
		    "can't set \"%s\": variable is array"
		my quads dictIterNext $var $var
		my quads dictIterKey $key $var
		my quads dictIterValue $value $var
		my quads dictIterDone $done $var
	    }
	    dictUpdateStart {
		set var [my index-to-var [lindex $insn 1]]
		my generate-scalar-check $pc $var {TCL READ VARNAME} \
		    "can't read \"%s\": variable is array"



		set auxNum [string range [lindex $insn 2] 1 end]
		set aux [lindex [dict get $bytecode auxiliary] $auxNum]
		set mid [list temp opnd0]
		set val [list temp [incr depth -1]]
		set idx 0
		foreach v [dict get $aux variables] {
		    set r [my index-to-var $v]
		    my generate-scalar-check $pc $r {TCL WRITE VARNAME} \
			"can't set \"%s\": variable is array"
		    my error-quads $pc listIndex $mid $val [list literal $idx]
		    my error-quads $pc dictGetOrNexist $r $var $mid
		    incr idx
		}
	    }
	    dictUpdateEnd {
		set var [my index-to-var [lindex $insn 1]]
		set auxNum [string range [lindex $insn 2] 1 end]
		set aux [lindex [dict get $bytecode auxiliary] $auxNum]
		set key [list temp opnd1]
		set isary [list temp opnd2]
		set mid [list temp opnd3]
		set updating [list temp opnd4]
		set val [list temp [incr depth -1]]
		set idx 0
		my generate-scalar-check $pc $var {TCL WRITE VARNAME} \
		    "can't write \"%s\": variable is array"

		my quads copy $updating $var
		foreach v [dict get $aux variables] {
		    set r [my index-to-var $v]
		    my error-quads $pc listIndex $key $val [list literal $idx]
		    incr idx
		    # Convert an ARRAY into a NEXIST here; ARRAY is unreadable
		    # so treat as NEXIST...
		    my quads arrayExists $isary $r
		    set n [llength $quads]
		    my quads jumpFalse [list pc [expr {$n + 3}]] $isary
		    my quads copy $mid Nothing
		    my quads jump [list pc [expr {$n + 4}]]
		    my quads extractScalar $mid $r
		    # Write the value to the right key of the dict
		    my error-quads $pc dictSetOrUnset $updating $updating $key $mid
		}
		my quads copy $var $updating
	    }
	    unsetScalar {
		# TODO - This doesn't complain on unsetting a nonexistent
		#        variable, it ignores '-nocomplain'
		set var [my index-to-var [lindex $insn 2]]







>
>
|




















>
>
>


|







|















>
|













|







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
		set var [my index-to-var [lindex $insn 1]]
		set dict [list temp [incr depth -1]]
		set value [list temp $depth]
		set key [list temp [incr depth]]
		set done [list temp [incr depth]]
		my generate-scalar-check $pc $var {TCL WRITE VARNAME} \
		    "can't set \"%s\": variable is array"
		my generate-dict-domain-check $pc [lindex $insn 0] $dict
		my quads purify {temp opd0} $dict
		my quads dictIterStart $var {temp opd0}
		my quads dictIterKey $key $var
		my quads dictIterValue $value $var
		my quads dictIterDone $done $var
	    }
	    dictNext {
		set var [my index-to-var [lindex $insn 1]]
		set value [list temp $depth]
		set key [list temp [incr depth]]
		set done [list temp [incr depth]]
		my generate-scalar-check $pc $var {TCL WRITE VARNAME} \
		    "can't set \"%s\": variable is array"
		my quads dictIterNext $var $var
		my quads dictIterKey $key $var
		my quads dictIterValue $value $var
		my quads dictIterDone $done $var
	    }
	    dictUpdateStart {
		set var [my index-to-var [lindex $insn 1]]
		my generate-scalar-check $pc $var {TCL READ VARNAME} \
		    "can't read \"%s\": variable is array"
		my generate-dict-domain-check $pc [lindex $insn 0] $var
		my quads purify {temp opd0} $var
		set var {temp opd0}
		set auxNum [string range [lindex $insn 2] 1 end]
		set aux [lindex [dict get $bytecode auxiliary] $auxNum]
		set mid [list temp opnd1]
		set val [list temp [incr depth -1]]
		set idx 0
		foreach v [dict get $aux variables] {
		    set r [my index-to-var $v]
		    my generate-scalar-check $pc $r {TCL WRITE VARNAME} \
			"can't set \"%s\": variable is array"
		    my error-quads $pc listIndex $mid $val [list literal $idx]
		    my quads dictGetOrNexist $r $var $mid
		    incr idx
		}
	    }
	    dictUpdateEnd {
		set var [my index-to-var [lindex $insn 1]]
		set auxNum [string range [lindex $insn 2] 1 end]
		set aux [lindex [dict get $bytecode auxiliary] $auxNum]
		set key [list temp opnd1]
		set isary [list temp opnd2]
		set mid [list temp opnd3]
		set updating [list temp opnd4]
		set val [list temp [incr depth -1]]
		set idx 0
		my generate-scalar-check $pc $var {TCL WRITE VARNAME} \
		    "can't write \"%s\": variable is array"
		my generate-dict-domain-check $pc [lindex $insn 0] $var
		my quads purify $updating $var
		foreach v [dict get $aux variables] {
		    set r [my index-to-var $v]
		    my error-quads $pc listIndex $key $val [list literal $idx]
		    incr idx
		    # Convert an ARRAY into a NEXIST here; ARRAY is unreadable
		    # so treat as NEXIST...
		    my quads arrayExists $isary $r
		    set n [llength $quads]
		    my quads jumpFalse [list pc [expr {$n + 3}]] $isary
		    my quads copy $mid Nothing
		    my quads jump [list pc [expr {$n + 4}]]
		    my quads extractScalar $mid $r
		    # Write the value to the right key of the dict
		    my quads dictSetOrUnset $updating $updating $key $mid
		}
		my quads copy $var $updating
	    }
	    unsetScalar {
		# TODO - This doesn't complain on unsetting a nonexistent
		#        variable, it ignores '-nocomplain'
		set var [my index-to-var [lindex $insn 2]]
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
		my quads arrayUnset $ary $ary $idx
	    }
	    dictDone {
		# Do nothing; general free will clean up.
	    }
	    verifyDict {
		set r [list temp [incr depth -1]]
		my error-quads $pc dictSize $r $r
		# The result will be discarded
	    }
	    incrScalar1Imm {
		set result [list temp $depth]
		set var [my index-to-var [lindex $insn 1]]
		set delta [lindex $insn 2]
		my generate-scalar-check $pc $var {TCL WRITE VARNAME} \
		    "can't set \"%s\": variable is array"







|
<







577
578
579
580
581
582
583
584

585
586
587
588
589
590
591
		my quads arrayUnset $ary $ary $idx
	    }
	    dictDone {
		# Do nothing; general free will clean up.
	    }
	    verifyDict {
		set r [list temp [incr depth -1]]
		my generate-dict-domain-check $pc [lindex $insn 0] $r

	    }
	    incrScalar1Imm {
		set result [list temp $depth]
		set var [my index-to-var [lindex $insn 1]]
		set delta [lindex $insn 2]
		my generate-scalar-check $pc $var {TCL WRITE VARNAME} \
		    "can't set \"%s\": variable is array"
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
		# TODO: Typecheck: need list in $var
		my error-quads $pc directLappend $var $var $value
	    }
	    lappendListStk {
		set listvalue [list temp [incr depth -1]]
		set var [list temp [incr depth -1]]
		# TODO: This assumes we're dealing with qualified names!
		# TODO: Typecheck: need lists in $var and $listvalue


		my error-quads $pc directLappendList $var $var $listvalue
	    }
	    lappendArrayStk {
		set value [list temp [incr depth -1]]
		set elem [list temp [incr depth -1]]
		set var [list temp [incr depth -1]]
		# TODO: This assumes we're dealing with qualified names!
		# TODO: Typecheck: need list in $var
		my error-quads $pc directArrayLappend $var $var $elem $value
	    }
	    lappendListArrayStk {
		set listvalue [list temp [incr depth -1]]
		set elem [list temp [incr depth -1]]
		set var [list temp [incr depth -1]]
		# TODO: This assumes we're dealing with qualified names!
		# TODO: Typecheck: need lists in $var and $listvalue


		my error-quads $pc \
		    directArrayLappendList $var $var $elem $listvalue
	    }
	    existStk {
		set var [list temp [incr depth -1]]
		# TODO: This assumes we're dealing with qualified names!
		my quads directExists $var $var
	    }
	    existArrayStk {







|
>
>
|















>
>

|







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
		# TODO: Typecheck: need list in $var
		my error-quads $pc directLappend $var $var $value
	    }
	    lappendListStk {
		set listvalue [list temp [incr depth -1]]
		set var [list temp [incr depth -1]]
		# TODO: This assumes we're dealing with qualified names!
		# TODO: Typecheck: need list in $var
		my generate-list-domain-check $pc [lindex $insn 0] $listvalue
		my quads purify {temp opd1} $listvalue
		my error-quads $pc directLappendList $var $var {temp opd1}
	    }
	    lappendArrayStk {
		set value [list temp [incr depth -1]]
		set elem [list temp [incr depth -1]]
		set var [list temp [incr depth -1]]
		# TODO: This assumes we're dealing with qualified names!
		# TODO: Typecheck: need list in $var
		my error-quads $pc directArrayLappend $var $var $elem $value
	    }
	    lappendListArrayStk {
		set listvalue [list temp [incr depth -1]]
		set elem [list temp [incr depth -1]]
		set var [list temp [incr depth -1]]
		# TODO: This assumes we're dealing with qualified names!
		# TODO: Typecheck: need lists in $var and $listvalue
		my generate-list-domain-check $pc [lindex $insn 0] $listvalue
		my quads purify {temp opd2} $listvalue
		my error-quads $pc \
		    directArrayLappendList $var $var $elem {temp opd2}
	    }
	    existStk {
		set var [list temp [incr depth -1]]
		# TODO: This assumes we're dealing with qualified names!
		my quads directExists $var $var
	    }
	    existArrayStk {
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
		set q {}
		for {set i 0} {$i < $idxNum} {incr i} {
		    # NOTE: Reversed
		    lappend q [list temp [incr depth -1]]
		}
		set val [list temp [incr depth -1]]
		set r [list temp $depth]


		my error-quads $pc dictGet $r $val {*}[lreverse $q]
	    }
	    dictExists {
		set idxNum [lindex $insn 1]
		set q {}
		for {set i 0} {$i < $idxNum} {incr i} {
		    # NOTE: Reversed
		    lappend q [list temp [incr depth -1]]
		}
		set val [list temp [incr depth -1]]
		set r [list temp $depth]


		my quads dictExists $r $val {*}[lreverse $q]
	    }
	    dictSet {
		set idxNum [expr [lindex $insn 1]]
		set var [my index-to-var [lindex $insn 2]]
		set val [list temp [incr depth -1]]

		set q {}
		for {set i 0} {$i < $idxNum} {incr i} {
		    # NOTE: Reversed
		    lappend q [list temp [incr depth -1]]
		}
		set r [list temp $depth]
		my generate-scalar-check $pc $var {TCL READ VARNAME} \
		    "can't read \"%s\": variable is array"
		my quads initIfNotExists $var $var {literal {}}





		my error-quads $pc dictSet $r $var $val {*}[lreverse $q]

		my quads copy $var $r
	    }
	    dictUnset {
		set idxNum [expr [lindex $insn 1]]
		set var [my index-to-var [lindex $insn 2]]
		set q {}
		for {set i 0} {$i < $idxNum} {incr i} {
		    # NOTE: Reversed
		    lappend q [list temp [incr depth -1]]
		}
		set r [list temp $depth]
		my generate-scalar-check $pc $var {TCL READ VARNAME} \
		    "can't read \"%s\": variable is array"
		my quads initIfNotExists $var $var {literal {}}





		my error-quads $pc dictUnset $r $var {*}[lreverse $q]

		my quads copy $var $r
	    }
	    dictAppend - dictLappend {
		set var [my index-to-var [lindex $insn 1]]
		set val [list temp [incr depth -1]]
		set key [list temp [incr depth -1]]
		set res [list temp $depth]
		my generate-scalar-check $pc $var {TCL READ VARNAME} \
		    "can't read \"%s\": variable is array"
		my quads initIfNotExists $var $var {literal {}}






		my error-quads $pc [lindex $insn 0] $res $var $key $val

		my quads copy $var $res
	    }
	    dictIncrImm {
		set delta [list literal [lindex $insn 1]]
		set var [my index-to-var [lindex $insn 2]]
		set key [list temp [incr depth -1]]
		set res [list temp $depth]
		my generate-scalar-check $pc $var {TCL READ VARNAME} \
		    "can't read \"%s\": variable is array"
		my quads initIfNotExists $var $var {literal {}}


		my error-quads $pc dictIncr $res $var $key $delta
		my quads copy $var $res
	    }
	    list {
		set acount [lindex $insn 1]
		set depth [expr {$depth - $acount}]
		set result [list temp $depth]
		set qd {}
		for {set i 0} {$i < $acount} {incr i} {
		    lappend qd [list temp [expr {$depth + $i}]]
		}
		my quads list $result {*}$qd
	    }
	    listIndexImm {
		set idx [list literal [string range [lindex $insn 1] 1 end]]
		set val [list temp [incr depth -1]]


		my error-quads $pc listIndex $val $val $idx
	    }
	    listIndex {
		set idx [list temp [incr depth -1]]
		set val [list temp [incr depth -1]]


		my error-quads $pc listIndex $val $val $idx
	    }
	    lindexMulti {
		set n [lindex $insn 1]
		set val [list temp [incr depth -$n]]
		for {set i 1} {$i < $n} {incr i} {


		    my error-quads $pc listIndex $val $val [list temp [incr depth]]
		}
		# Should we do this as a single operation? c.f. TclLindexFlat
	    }
	    listRangeImm {
		set from [list literal [string range [lindex $insn 1] 1 end]]
		set to [list literal [string range [lindex $insn 2] 1 end]]
		set val [list temp [incr depth -1]]


		my error-quads $pc listRange $val $val $from $to
	    }
	    listLength {
		set value [list temp [incr depth -1]]
		set r [list temp $depth]


		my error-quads $pc [lindex $insn 0] $r $value
	    }
	    invokeReplace {
		set acount [lindex $insn 1]
		set rcount [lindex $insn 2]
		set depth [expr {$depth - $acount - 1}]
		set result [list temp $depth]
		# FIXME - Simply do the replacement in place for







>
>
|










>
>
|





>





<



>
>
>
>
>
|
>
|













>
>
>
>
>
|
>










>
>
>
>
>
>
|
>










>
>
|















>
>
|




>
>
|





>
>








>
>
|




>
>
|







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
		set q {}
		for {set i 0} {$i < $idxNum} {incr i} {
		    # NOTE: Reversed
		    lappend q [list temp [incr depth -1]]
		}
		set val [list temp [incr depth -1]]
		set r [list temp $depth]
		my generate-dict-domain-check $pc [lindex $insn 0] $val
		my quads purify {temp opd0} $val
		my error-quads $pc dictGet $r {temp opd0} {*}[lreverse $q]
	    }
	    dictExists {
		set idxNum [lindex $insn 1]
		set q {}
		for {set i 0} {$i < $idxNum} {incr i} {
		    # NOTE: Reversed
		    lappend q [list temp [incr depth -1]]
		}
		set val [list temp [incr depth -1]]
		set r [list temp $depth]
		my generate-dict-domain-check $pc [lindex $insn 0] $val
		my quads purify {temp opd0} $val
		my quads dictExists $r {temp opd0} {*}[lreverse $q]
	    }
	    dictSet {
		set idxNum [expr [lindex $insn 1]]
		set var [my index-to-var [lindex $insn 2]]
		set val [list temp [incr depth -1]]
		set vartmp {temp opd0}
		set q {}
		for {set i 0} {$i < $idxNum} {incr i} {
		    # NOTE: Reversed
		    lappend q [list temp [incr depth -1]]
		}

		my generate-scalar-check $pc $var {TCL READ VARNAME} \
		    "can't read \"%s\": variable is array"
		my quads initIfNotExists $var $var {literal {}}
		my generate-dict-domain-check $pc [lindex $insn 0] $var
		my quads purify $vartmp $var
		if {[llength $q] == 1} {
		    my quads dictSet $vartmp $vartmp $val {*}$q
		} else {
		    my error-quads $pc dictSet $vartmp $vartmp $val {*}[lreverse $q]
		}
		my quads copy $var $vartmp
	    }
	    dictUnset {
		set idxNum [expr [lindex $insn 1]]
		set var [my index-to-var [lindex $insn 2]]
		set q {}
		for {set i 0} {$i < $idxNum} {incr i} {
		    # NOTE: Reversed
		    lappend q [list temp [incr depth -1]]
		}
		set r [list temp $depth]
		my generate-scalar-check $pc $var {TCL READ VARNAME} \
		    "can't read \"%s\": variable is array"
		my quads initIfNotExists $var $var {literal {}}
		my generate-dict-domain-check $pc [lindex $insn 0] $var
		my quads purify {temp opd0} $var
		if {[llength $q] == 1} {
		    my quads dictUnset $r {temp opd0} {*}$q
		} else {
		    my error-quads $pc dictUnset $r {temp opd0} {*}[lreverse $q]
		}
		my quads copy $var $r
	    }
	    dictAppend - dictLappend {
		set var [my index-to-var [lindex $insn 1]]
		set val [list temp [incr depth -1]]
		set key [list temp [incr depth -1]]
		set res [list temp $depth]
		my generate-scalar-check $pc $var {TCL READ VARNAME} \
		    "can't read \"%s\": variable is array"
		my quads initIfNotExists $var $var {literal {}}
		my generate-dict-domain-check $pc [lindex $insn 0] $var
		my quads purify {temp opd0} $var
		if {[lindex $insn 0] eq "dictAppend"} {
		    my quads [lindex $insn 0] $res {temp opd0} $key $val
		} else {
		    # dictLappend can fail if value in dict is non-list
		    my error-quads $pc [lindex $insn 0] $res {temp opd0} $key $val
		}
		my quads copy $var $res
	    }
	    dictIncrImm {
		set delta [list literal [lindex $insn 1]]
		set var [my index-to-var [lindex $insn 2]]
		set key [list temp [incr depth -1]]
		set res [list temp $depth]
		my generate-scalar-check $pc $var {TCL READ VARNAME} \
		    "can't read \"%s\": variable is array"
		my quads initIfNotExists $var $var {literal {}}
		my generate-dict-domain-check $pc [lindex $insn 0] $var
		my quads purify {temp opd0} $var
		my error-quads $pc dictIncr $res {temp opd0} $key $delta
		my quads copy $var $res
	    }
	    list {
		set acount [lindex $insn 1]
		set depth [expr {$depth - $acount}]
		set result [list temp $depth]
		set qd {}
		for {set i 0} {$i < $acount} {incr i} {
		    lappend qd [list temp [expr {$depth + $i}]]
		}
		my quads list $result {*}$qd
	    }
	    listIndexImm {
		set idx [list literal [string range [lindex $insn 1] 1 end]]
		set val [list temp [incr depth -1]]
		my generate-list-domain-check $pc [lindex $insn 0] $val
		my quads purify {temp opd0} $val
		my error-quads $pc listIndex $val {temp opd0} $idx
	    }
	    listIndex {
		set idx [list temp [incr depth -1]]
		set val [list temp [incr depth -1]]
		my generate-list-domain-check $pc [lindex $insn 0] $val
		my quads purify {temp opd0} $val
		my error-quads $pc listIndex $val {temp opd0} $idx
	    }
	    lindexMulti {
		set n [lindex $insn 1]
		set val [list temp [incr depth -$n]]
		for {set i 1} {$i < $n} {incr i} {
		    my generate-list-domain-check $pc [lindex $insn 0] $val
		    my quads purify $val $val
		    my error-quads $pc listIndex $val $val [list temp [incr depth]]
		}
		# Should we do this as a single operation? c.f. TclLindexFlat
	    }
	    listRangeImm {
		set from [list literal [string range [lindex $insn 1] 1 end]]
		set to [list literal [string range [lindex $insn 2] 1 end]]
		set val [list temp [incr depth -1]]
		my generate-list-domain-check $pc [lindex $insn 0] $val
		my quads purify {temp opd0} $val
		my error-quads $pc listRange $val {temp opd0} $from $to
	    }
	    listLength {
		set value [list temp [incr depth -1]]
		set r [list temp $depth]
		my generate-list-domain-check $pc [lindex $insn 0] $value
		my quads purify {temp opd0} $value
		my error-quads $pc [lindex $insn 0] $r {temp opd0}
	    }
	    invokeReplace {
		set acount [lindex $insn 1]
		set rcount [lindex $insn 2]
		set depth [expr {$depth - $acount - 1}]
		set result [list temp $depth]
		# FIXME - Simply do the replacement in place for
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
	    lappendScalar1 - lappendScalar4 {
		set val [list temp [incr depth -1]]
		set var [my index-to-var [lindex $insn 1]]
		set res [list temp $depth]
		my generate-scalar-check $pc $var {TCL WRITE VARNAME} \
		    "can't set \"%s\": variable is array"
		my quads initIfNotExists $var $var {literal {}}

		# TODO: Typecheck: need list in $var
		my error-quads $pc listAppend $res $var $val
		my quads copy $var $res
	    }
	    lappendList {
		set listval [list temp [incr depth -1]]
		set var [my index-to-var [lindex $insn 1]]
		set res [list temp $depth]
		my generate-scalar-check $pc $var {TCL WRITE VARNAME} \
		    "can't set \"%s\": variable is array"
		my quads initIfNotExists $var $var {literal {}}



		# TODO: Typecheck: need lists in $var and $listval
		my error-quads $pc listConcat $res $var $listval
		my quads copy $var $res
	    }
	    lappendArray1 - lappendArray4 {
		set val [list temp [incr depth -1]]
		set idx [list temp [incr depth -1]]
		set ary [my index-to-var [lindex $insn 1]]
		set res [list temp $depth]
		set inval {temp opd0}
		my generate-array-check $pc $ary $idx {TCL LOOKUP VARNAME} \
		    "can't set \"%s(%s)\": variable isn't array"
		my quads initArrayIfNotExists $var $var
		my quads arrayGet $inval $ary $idx
		my quads initIfNotExists $inval $inval {literal {}}


		my error-quads $pc listAppend $inval $inval $val
		my quads arraySet $ary $ary $idx $inval
		my quads copy $res $inval
	    }
	    lappendListArray {
		set listval [list temp [incr depth -1]]
		set idx [list temp [incr depth -1]]
		set ary [my index-to-var [lindex $insn 1]]
		set res [list temp $depth]
		set inval {temp opd0}
		my generate-array-check $pc $ary $idx {TCL LOOKUP VARNAME} \
		    "can't set \"%s(%s)\": variable isn't array"
		my quads initArrayIfNotExists $ary $ary
		my quads arrayGet $inval $ary $idx
		my quads initIfNotExists $inval $inval {literal {}}



		# TODO: Typecheck: need lists in $inval and $listval
		my error-quads $pc listConcat $inval $inval $listval
		my quads arraySet $ary $ary $idx $inval
		my quads copy $res $inval
	    }
	    listConcat {
		set list2 [list temp [incr depth -1]]
		set list1 [list temp [incr depth -1]]
		set res [list temp $depth]

		# TODO: Typecheck: need lists in $list1 and $list2


		my error-quads $pc listConcat $res $list1 $list2
	    }
	    arrayExistsImm {
		set ary [my index-to-var [lindex $insn 1]]
		set res [list temp $depth]
		my quads arrayExists $res $ary
	    }
	    arrayMakeImm {







>
|
|









>
>
>
|
|













>
>
|














>
>
>
|
|







>
|
>
>
|







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
	    lappendScalar1 - lappendScalar4 {
		set val [list temp [incr depth -1]]
		set var [my index-to-var [lindex $insn 1]]
		set res [list temp $depth]
		my generate-scalar-check $pc $var {TCL WRITE VARNAME} \
		    "can't set \"%s\": variable is array"
		my quads initIfNotExists $var $var {literal {}}
		my generate-list-domain-check $pc [lindex $insn 0] $var
		my quads purify $var $var
		my quads listAppend $res $var $val
		my quads copy $var $res
	    }
	    lappendList {
		set listval [list temp [incr depth -1]]
		set var [my index-to-var [lindex $insn 1]]
		set res [list temp $depth]
		my generate-scalar-check $pc $var {TCL WRITE VARNAME} \
		    "can't set \"%s\": variable is array"
		my quads initIfNotExists $var $var {literal {}}
		my generate-list-domain-check $pc [lindex $insn 0] $var
		my quads purify $var $var
		my generate-list-domain-check $pc [lindex $insn 0] $listval
		my quads purify $listval $listval
		my quads listConcat $res $var $listval
		my quads copy $var $res
	    }
	    lappendArray1 - lappendArray4 {
		set val [list temp [incr depth -1]]
		set idx [list temp [incr depth -1]]
		set ary [my index-to-var [lindex $insn 1]]
		set res [list temp $depth]
		set inval {temp opd0}
		my generate-array-check $pc $ary $idx {TCL LOOKUP VARNAME} \
		    "can't set \"%s(%s)\": variable isn't array"
		my quads initArrayIfNotExists $var $var
		my quads arrayGet $inval $ary $idx
		my quads initIfNotExists $inval $inval {literal {}}
		my generate-list-domain-check $pc [lindex $insn 0] $inval
		my quads purify $inval $inval
		my quads listAppend $inval $inval $val
		my quads arraySet $ary $ary $idx $inval
		my quads copy $res $inval
	    }
	    lappendListArray {
		set listval [list temp [incr depth -1]]
		set idx [list temp [incr depth -1]]
		set ary [my index-to-var [lindex $insn 1]]
		set res [list temp $depth]
		set inval {temp opd0}
		my generate-array-check $pc $ary $idx {TCL LOOKUP VARNAME} \
		    "can't set \"%s(%s)\": variable isn't array"
		my quads initArrayIfNotExists $ary $ary
		my quads arrayGet $inval $ary $idx
		my quads initIfNotExists $inval $inval {literal {}}
		my generate-list-domain-check $pc [lindex $insn 0] $inval
		my quads purify $inval $inval
		my generate-list-domain-check $pc [lindex $insn 0] $listval
		my quads purify $listval $listval
		my quads listConcat $inval $inval $listval
		my quads arraySet $ary $ary $idx $inval
		my quads copy $res $inval
	    }
	    listConcat {
		set list2 [list temp [incr depth -1]]
		set list1 [list temp [incr depth -1]]
		set res [list temp $depth]
		my generate-list-domain-check $pc [lindex $insn 0] $list1
		my quads purify {temp opd0} $list1
		my generate-list-domain-check $pc [lindex $insn 0] $list2
		my quads purify {temp opd1} $list2
		my error-quads $pc listConcat $res {temp opd0} {temp opd1}
	    }
	    arrayExistsImm {
		set ary [my index-to-var [lindex $insn 1]]
		set res [list temp $depth]
		my quads arrayExists $res $ary
	    }
	    arrayMakeImm {
1637
1638
1639
1640
1641
1642
1643


























































1644
1645
1646
1647
1648
1649
1650
    my quads extractFail {temp @exception} {temp @exception}
    # 4
    my generate-jump $fail
    # 5

    # The narrowing pass will insert any necessary 'extract...' instructions
}



























































# generate-arith-domain-check --
#
#	Generates a check to make sure that a value is NUMERIC or INT
#	for the instructions that require such a value.  Do not call from
#	anywhere but bytecode-to-quads!
#







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







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
    my quads extractFail {temp @exception} {temp @exception}
    # 4
    my generate-jump $fail
    # 5

    # The narrowing pass will insert any necessary 'extract...' instructions
}

# generate-list-domain-check / generate-dict-domain-check --
#
#	Generates a check to make sure that a value is LIST or DICT
#	for the instructions that require such a value.  Do not call from
#	anywhere but bytecode-to-quads!
#
# Parameters:
#	q - The quadruple that will consume the value
#
# Results:
#	None.
#
# Side effects:
#	Emits a the appropriate sequence of 'instanceOf', 'jumpTrue',
#	'initException', 'jump'.

oo::define quadcode::transformer method generate-list-domain-check {pc inst val} {
    set ok [list pc [expr {[llength $quads] + 5}]]
    ;				# Quadcode address to jump to on success
    set fail [my exception-target $pc catch]
    ;				# Bytecode address to jump to on failure

    namespace upvar ::quadcode::dataType LIST typecode IMPURE impure
    set impureTC [::quadcode::dataType::typeUnion $typecode $impure]
    set opc [list instanceOf $impureTC {IMPURE LIST}]

    my quads $opc {temp @ok} $val
    my quads jumpTrue $ok {temp @ok}
    set msg [format {can't use non-list string as operand of "%s"} $inst]
    set msgLit [list literal $msg]
    set opts {literal {-errorcode {ARITH DOMAIN {non-numeric string}}}}
    my quads initException {temp @exception} \
	$msgLit $opts {literal 1} {literal 0}
    my quads extractFail {temp @exception} {temp @exception}
    my generate-jump $fail
}

oo::define quadcode::transformer method generate-dict-domain-check {pc inst val} {
    set ok [list pc [expr {[llength $quads] + 5}]]
    ;				# Quadcode address to jump to on success
    set fail [my exception-target $pc catch]
    ;				# Bytecode address to jump to on failure

    namespace upvar ::quadcode::dataType DICT typecode IMPURE impure
    set impureTC [::quadcode::dataType::typeUnion $typecode $impure]
    set opc [list instanceOf $impureTC {IMPURE DICT}]

    my quads $opc {temp @ok} $val
    my quads jumpTrue $ok {temp @ok}
    set msg [format {can't use non-list string as operand of "%s"} $inst]
    set msgLit [list literal $msg]
    set opts {literal {-errorcode {ARITH DOMAIN {non-numeric string}}}}
    my quads initException {temp @exception} \
	$msgLit $opts {literal 1} {literal 0}
    my quads extractFail {temp @exception} {temp @exception}
    my generate-jump $fail
}

# generate-arith-domain-check --
#
#	Generates a check to make sure that a value is NUMERIC or INT
#	for the instructions that require such a value.  Do not call from
#	anywhere but bytecode-to-quads!
#

Changes to quadcode/types.tcl.

15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

namespace eval quadcode::dataType {

    namespace export mightbea isa allbut typeIntersect typeUnion

    # IMPURE - Any value that has a known internal representation may
    #          have the IMPURE indicator to show that it has a string
    #          representation that must e preserved.

    variable IMPURE		[expr 0x4000000]

    # BOTTOM - means an inconsistency. We have contradictory information
    #          about a given value. Should not happen.

    variable BOTTOM		0







|







15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

namespace eval quadcode::dataType {

    namespace export mightbea isa allbut typeIntersect typeUnion

    # IMPURE - Any value that has a known internal representation may
    #          have the IMPURE indicator to show that it has a string
    #          representation that must be preserved.

    variable IMPURE		[expr 0x4000000]

    # BOTTOM - means an inconsistency. We have contradictory information
    #          about a given value. Should not happen.

    variable BOTTOM		0
120
121
122
123
124
125
126




















127
128
129
130
131
132
133

    variable NUMERIC		[expr {$DOUBLE | $ENTIER}]

    # NUMERIC_OR_BOOLEAN - the value is a number, or some spelling of
    #                      'true' or 'false'

    variable NUMERIC_OR_BOOLEAN	[expr {$NUMERIC | $BOOLEAN}]





















    # FOREACH - the value represents the iterator of a [foreach] or [lmap].
    #           There are no constants of this type, and it is therefore
    #           always pure.

    variable FOREACH		[expr 0x10000]








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







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

    variable NUMERIC		[expr {$DOUBLE | $ENTIER}]

    # NUMERIC_OR_BOOLEAN - the value is a number, or some spelling of
    #                      'true' or 'false'

    variable NUMERIC_OR_BOOLEAN	[expr {$NUMERIC | $BOOLEAN}]

    # NONEMPTYDICT - the value is a non-empty dictionary of some sort. The
    #		types of the keys and the values are just STRING.

    variable NONEMPTYDICT	[expr 0x200]

    # NONDICTLIST - the value is a list of some sort that isn't a dictionary
    #		but isn't empty. The type of the elements is just STRING.

    variable NONDICTLIST	[expr 0x100]

    # LIST - the value is a list of some sort. The type of the elements is
    #		just STRING. Note that a DICT is also a LIST.

    variable LIST		[expr {$NONDICTLIST | $NONEMPTYDICT | $EMPTY}]

    # DICT - the value is a dict of some sort. The type of the keys and values
    #		are just STRING. Note that a DICT is also a LIST.

    variable DICT		[expr {$NONEMPTYDICT | $EMPTY}]

    # FOREACH - the value represents the iterator of a [foreach] or [lmap].
    #           There are no constants of this type, and it is therefore
    #           always pure.

    variable FOREACH		[expr 0x10000]

343
344
345
346
347
348
349


350
351
352
353
354
355
356
	FAIL			FAIL
	ARRAY			ARRAY
	DICTITER		DICTITER
	FOREACH			FOREACH
	EXPANDED		EXPANDED
	OTHERSTRING		STRING
	IMPURE			IMPURE


	EMPTY			EMPTY
    } {
	namespace upvar dataType $name t
	if {$type & $t} {
	    namespace upvar dataType $wname w
	    lappend result $wname
	    set type [expr {$type & ~$w}]







>
>







363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
	FAIL			FAIL
	ARRAY			ARRAY
	DICTITER		DICTITER
	FOREACH			FOREACH
	EXPANDED		EXPANDED
	OTHERSTRING		STRING
	IMPURE			IMPURE
	NONDICTLIST		LIST
	NONEMPTYDICT		DICT
	EMPTY			EMPTY
    } {
	namespace upvar dataType $name t
	if {$type & $t} {
	    namespace upvar dataType $wname w
	    lappend result $wname
	    set type [expr {$type & ~$w}]
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
oo::define quadcode::transformer method typeOfResult {q} {
    namespace upvar ::quadcode::dataType {*}{
	DOUBLE DOUBLE INT INT STRING STRING FAIL FAIL EMPTY EMPTY
	ZEROONE ZEROONE
	BOOL_INT BOOL BOOLWORD BOOLWORD
	ENTIER ENTIER NUMERIC NUMERIC IMPURE IMPURE
	VOID VOID CALLFRAME CALLFRAME DICTITER DICTITER FOREACH FOREACH
	ARRAY ARRAY NEXIST NEXIST EXPANDED EXPANDED
    }

    switch -exact -- [lindex $q 0 0] {
	debug-value {
	    return [typeOfOperand $types [lindex $q 3]]
	}
	widenTo {







|







517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
oo::define quadcode::transformer method typeOfResult {q} {
    namespace upvar ::quadcode::dataType {*}{
	DOUBLE DOUBLE INT INT STRING STRING FAIL FAIL EMPTY EMPTY
	ZEROONE ZEROONE
	BOOL_INT BOOL BOOLWORD BOOLWORD
	ENTIER ENTIER NUMERIC NUMERIC IMPURE IMPURE
	VOID VOID CALLFRAME CALLFRAME DICTITER DICTITER FOREACH FOREACH
	ARRAY ARRAY NEXIST NEXIST EXPANDED EXPANDED LIST LIST DICT DICT
    }

    switch -exact -- [lindex $q 0 0] {
	debug-value {
	    return [typeOfOperand $types [lindex $q 3]]
	}
	widenTo {
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
	eq -
	ge -
	gt -
	instanceOf -
	isBoolean -
	land -
	le -

	lor -
	lt -
	neq -
	strclass -
	streq -
	strmatch -
	strneq {
	    return $ZEROONE
	}
	not {
	    set t [typeOfOperand $types [lindex $q 2]]
	    if {istype($t,$NUMERIC|$BOOLWORD)} {
		return $ZEROONE
	    } else {
		puts "which might FAIL"
		return [expr {$ZEROONE | $FAIL}]
	    }
	}
	regexp - listIn {
	    return [expr {$ZEROONE | $FAIL}]
	}
	listLength - dictSize {
	    return [expr {$INT | $FAIL}]
	}
	phi {
	    set r 0
	    foreach {from operand} [lrange $q 2 end] {
		set r [expr {$r | [typeOfOperand $types $operand]}]
	    }
	    return $r







>


















|



|







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
	eq -
	ge -
	gt -
	instanceOf -
	isBoolean -
	land -
	le -
	listIn -
	lor -
	lt -
	neq -
	strclass -
	streq -
	strmatch -
	strneq {
	    return $ZEROONE
	}
	not {
	    set t [typeOfOperand $types [lindex $q 2]]
	    if {istype($t,$NUMERIC|$BOOLWORD)} {
		return $ZEROONE
	    } else {
		puts "which might FAIL"
		return [expr {$ZEROONE | $FAIL}]
	    }
	}
	regexp {
	    return [expr {$ZEROONE | $FAIL}]
	}
	listLength - dictSize {
	    return $INT
	}
	phi {
	    set r 0
	    foreach {from operand} [lrange $q 2 end] {
		set r [expr {$r | [typeOfOperand $types $operand]}]
	    }
	    return $r
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
	    # Simple numbers are simple words when not IMPURE
	    if {istype($t1,$NUMERIC) && !($t1 & $IMPURE)} {
		return $t1
	    }
	    return [expr {$EXPANDED | $t1}]
	}
	verifyList {
	    return [expr {$FAIL | [typeOfOperand $types [lindex $q 2]]}]
	}
	invoke {
	    # We know the result type of a handful of the things
	    # that might be invoked
	    if {[lindex $q 3 0] eq "literal"} {
		set rtype [my typeOfInvoke [lindex $q 3 1] [lrange $q 4 end]]
	    } else {







|







701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
	    # Simple numbers are simple words when not IMPURE
	    if {istype($t1,$NUMERIC) && !($t1 & $IMPURE)} {
		return $t1
	    }
	    return [expr {$EXPANDED | $t1}]
	}
	verifyList {
	    return [expr {$FAIL | $LIST}]
	}
	invoke {
	    # We know the result type of a handful of the things
	    # that might be invoked
	    if {[lindex $q 3 0] eq "literal"} {
		set rtype [my typeOfInvoke [lindex $q 3 1] [lrange $q 4 end]]
	    } else {
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
	    # Pull from the callframe of the earlier 'invoke'
	    return [expr {[typeOfOperand $types [lindex $q 2]] & ~$CALLFRAME}]
	}
	extractCallFrame {
	    # Trim the non-callframe part
	    return $CALLFRAME
	}
	list - unshareList -


	result - returnOptions -


	dictIterKey - dictIterValue -
	concat - strcat - strmap - strtrim - strcase {
	    return $STRING
	}
	foreachAdvance {
	    return $FOREACH
	}
	foreachStart {
	    return [expr {$FOREACH | $FAIL}]
	}




























	strindex - strrange - strreplace -



	listAppend - listConcat - listIndex - listSet -









	dictSet - dictSetOrUnset - dictGet - listRange - dictUnset -






	dictAppend - dictIncr - dictLappend {
	    return [expr {$STRING | $FAIL}]
	}
	dictGetOrNexist {
	    return [expr {$STRING | $FAIL | $NEXIST}]
	}
	arrayGet {
	    return [expr {$STRING | $NEXIST}]
	}
	arraySet - arrayUnset - initArray {
	    return $ARRAY
	}
	dictIterStart {
	    return [expr {$DICTITER | $FAIL}]
	}
	dictIterNext {
	    return $DICTITER
	}
	initIfNotExists {
	    set vartype [typeOfOperand $types [lindex $q 2]]
	    set deftype [typeOfOperand $types [lindex $q 3]]
	    return [expr {$deftype | ($vartype & ~$NEXIST)}]
	}







|
>
>
|
>
>
|









>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
|
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
|
|


|







|
<
<
<







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
	    # Pull from the callframe of the earlier 'invoke'
	    return [expr {[typeOfOperand $types [lindex $q 2]] & ~$CALLFRAME}]
	}
	extractCallFrame {
	    # Trim the non-callframe part
	    return $CALLFRAME
	}
	list - unshareList {
	    return $LIST
	}
	returnOptions {
	    return $DICT
	}
	result - dictIterKey - dictIterValue -
	concat - strcat - strmap - strtrim - strcase {
	    return $STRING
	}
	foreachAdvance {
	    return $FOREACH
	}
	foreachStart {
	    return [expr {$FOREACH | $FAIL}]
	}
	listAppend - listConcat {
	    return $LIST
	}
	listIndex {
	    if {[llength $q] == 4} {
		set t2 [typeOfOperand $types [lindex $q 3]]
		# TODO: have end-relative indices be their own type
		if {istype($t2, $INT) || istype($t2, $ZEROONE)} {
		    return $STRING
		}
	    } elseif {[llength $q] == 3} {
		return [typeOfOperand $types [lindex $q 2]]
	    }
	    return [expr {$STRING | $FAIL}]
	}
	listRange {
	    set t1 [typeOfOperand $types [lindex $q 3]]
	    set t2 [typeOfOperand $types [lindex $q 4]]
	    # TODO: have end-relative indices be their own type
	    if {(istype($t1, $INT) || istype($t1, $ZEROONE)) &&
		    (istype($t2, $INT) || istype($t2, $ZEROONE))} {
		return $LIST
	    }
	    return [expr {$LIST | $FAIL}]
	}
	listSet {
	    return [expr {$LIST | $FAIL}]
	}
	strindex - strrange - strreplace - dictGet {
	    # TODO: have end-relative indices be their own type and be non-failing
	    return [expr {$STRING | $FAIL}]
	}
	dictSetOrUnset - dictAppend {
	    return $DICT
	}
	dictUnset {
	    if {[llength $q] == 4} {
		return $DICT
	    } else {
		return [expr {$DICT | $FAIL}]
	    }
	}
	dictSet {
	    if {[llength $q] == 5} {
		return $DICT
	    } else {
		return [expr {$DICT | $FAIL}]
	    }
	}
	dictIncr - dictLappend {
	    return [expr {$DICT | $FAIL}]
	}
	dictGetOrNexist {
	    return [expr {$STRING | $NEXIST}]
	}
	arrayGet {
	    return [expr {$STRING | $NEXIST}]
	}
	arraySet - arrayUnset - initArray {
	    return $ARRAY
	}
	dictIterStart - dictIterNext {



	    return $DICTITER
	}
	initIfNotExists {
	    set vartype [typeOfOperand $types [lindex $q 2]]
	    set deftype [typeOfOperand $types [lindex $q 3]]
	    return [expr {$deftype | ($vartype & ~$NEXIST)}]
	}
896
897
898
899
900
901
902

















903
904
905
906
907
908
909
	if {$y eq $x} {
	    return $dataType::DOUBLE
	} else {
	    return [dataType::typeUnion $dataType::DOUBLE $dataType::IMPURE]
	}
    } elseif {[string is boolean -strict $x]} {
	return [dataType::typeUnion $dataType::BOOLEAN $dataType::IMPURE]

















    } else {
	return $dataType::IMPUREOTHERSTRING
    }
}

# builtinCommandType -
#







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







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
	if {$y eq $x} {
	    return $dataType::DOUBLE
	} else {
	    return [dataType::typeUnion $dataType::DOUBLE $dataType::IMPURE]
	}
    } elseif {[string is boolean -strict $x]} {
	return [dataType::typeUnion $dataType::BOOLEAN $dataType::IMPURE]
    } elseif {[string is list $x] && ($x eq [list {*}$x])} {
	# Purity is determined by seeing if the string value could be made by
	# [list]; if not, we've got a value with extra whitespace we should
	# preserve.

	# We claim that lists of length one are simple STRINGs; that's usually
	# a more honest choice.
	if {[llength $x] <= 1} {
	    return $dataType::IMPUREOTHERSTRING
	}
	# Odd-length LISTs cannot be DICTs, and we prefer to not call them
	# DICTs if they have non-unique keys.
	if {([llength $x] & 1) == 0 && [dict create {*}$x] eq $x} {
	    return $dataType::NONEMPTYDICT
	} else {
	    return $dataType::NONDICTLIST
	}
    } else {
	return $dataType::IMPUREOTHERSTRING
    }
}

# builtinCommandType -
#