Changes to codegen.tcl.
Changes to codegen/build.tcl.
︙ | | |
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
|
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
# A boolean (int1) LLVM value reference.
method in32range {int {name ""}} {
my and [my ge $int [Const -0x80000000 int64]] \
[my le $int [Const 0x7fffffff int64]] $name
}
# Builder:fieldtostruct --
#
# Given a pointer to a field in a structure and a specification of which
# type and field it is, return a pointer to the overall structure
# containing that field. Note that this does not require dereferencing
# the field pointer.
#
# Parameters:
# fieldPtr -
# The pointer LLVM value reference to the field.
# type - The LLVM type of the structure.
# fieldname -
# The name of the field within the structure.
# name (optional) -
# A name to give to the result value.
#
# Results:
# A pointer LLVM value reference to the structure.
method fieldtostruct {fieldPtr type fieldname {name ""}} {
set off [my neg [my offsetof $type $fieldname]]
set ptr [my cast(ptr) $fieldPtr char]
return [my cast(ptr) [my getelementptr $ptr $off] $type $name]
}
# Builder:frame.pack --
#
# Combine a callframe with another value.
#
# Parameters:
# callframe -
# The CALLFRAME LLVM value reference.
# value - The INT LLVM value reference for the non-callframe value.
# name (optional) -
# A name to give to the result value.
#
# Results:
# A CALLFRAME-value tuple LLVM value reference.
method frame.pack {callframe value {name ""}} {
set type [Type struct{CALLFRAME,[TypeOf $value]}]
my insert [my insert [my undef $type] $callframe 0] $value 1 $name
}
# Builder:frame.frame --
#
# Extract the callframe from a tupled value.
#
# Parameters:
# callframetuple -
# The CALLFRAME-tuple LLVM value reference.
# name (optional) -
# A name to give to the result value.
#
# Results:
# A CALLFRAME LLVM value reference.
method frame.frame {callframetuple {name ""}} {
my extract $callframetuple 0 $name
}
# Builder:frame.value --
#
# Extract the non-callframe value from a tuple.
#
# Parameters:
# callframetuple -
# The CALLFRAME-tuple LLVM value reference.
# name (optional) -
# A name to give to the result value.
#
# Results:
# An LLVM value reference.
method frame.value {callframetuple {name ""}} {
my extract $callframetuple 1 $name
}
# Builder:frame.create --
#
# Create and initialise a callframe.
#
# Parameters:
# varlist -
# The Tcl list of information about the callframe's variables
# extracted from the bytecode.
# argc - The int LLVM value reference for the number of arguments.
# argv - The STRING* LLVM value reference (or equivalent type) for the
# array of arguments, allocated on the function stack.
# proc - The LLVM value reference to the procedure's metadata.
# localcache -
# The LLVM value reference to the procedure's local variable
# metadata.
#
# Results:
# A Tcl list of the LLVM CALLFRAME value reference and the mapping
# dictionary from string variable names to the corresponding LLVM Var*
# value references.
method frame.create {varlist argc argv proc localcache} {
# Construct the call frame itself
set callframe [my alloc CallFrame "callframe"]
set length [Const [llength $varlist]]
set locals [my arrayAlloc Var $length]
my Call tcl.callframe.init $callframe $length \
$argc [my cast(ptr) $argv STRING] $proc $localcache $locals
# Initialise the information about the local variables
set idx -1
set varmap {}
foreach varinfo $varlist {
lassign $varinfo flags var
set flagbits 0
set FLAGS {
scalar 0x0 array 0x1 link 0x2
arg 0x100 temp 0x200 args 0x400
resolved 0x8000
}
foreach bit $flags {
incr flagbits [dict get $FLAGS $bit]
}
set v [my Call tcl.callframe.makevar $callframe \
[Const [incr idx] int] [Const $flagbits int]]
dict set varmap $var $v
}
return [list $callframe $varmap]
}
# Builder:frame.release --
#
# Delete the contents of a call frame.
#
# Parameters:
# callframe -
# The CALLFRAME LLVM value reference.
# synthetics -
# A Tcl list of booleans saying which values in the callframe's
# argv array need to have their reference counts decremented
# because they are synthetic.
#
# Results:
# None.
method frame.release {callframe synthetics} {
set idx -1
foreach drop $synthetics {
incr idx
if {$drop} {
if {![info exist argv]} {
set argv [my dereference $callframe 0 CallFrame.argv]
if {![info exist objv]} {
set objv [my dereference $callframe 0 CallFrame.objv]
}
set obj [my dereference $argv 0 $idx]
set obj [my dereference $objv $idx]
my dropReference(STRING) $obj
}
}
my Call tcl.callframe.clear $callframe
return
}
# Builder:frame.store(STRING) --
#
# Transfer a value into a call frame variable.
#
# Parameters:
# value - The LLVM value reference to go into the call frame's var.
# callframe -
# The CALLFRAME LLVM value reference.
# var - The Var* LLVM reference for the variable to write to.
# varName -
# The Tcl string of the name of the variable.
#
# Results:
# None.
method frame.store(STRING) {value callframe var varName} {
my frame.store(NEXIST\040STRING) [my just $value] \
$callframe $var $varName
}
# Builder:frame.store(NEXIST STRING) --
#
# Transfer a value into a call frame variable. A non-existing value will
# convert into an unsetting of the variable.
#
# Parameters:
# value - The LLVM value reference to go into the call frame's var.
# callframe -
# The CALLFRAME LLVM value reference.
# var - The Var* LLVM reference for the variable to write to.
# varName -
# The Tcl string of the name of the variable.
#
# Results:
# None.
method frame.store(NEXIST\040STRING) {value callframe var varName} {
my Call tcl.callframe.store $var [Const $varName STRING] $value
return
}
# Builder:frame.store(NEXIST) --
#
# Unset a variable in a call frame.
#
# Parameters:
# value - The non-existing value to put in the variable.
# callframe -
# The CALLFRAME LLVM value reference.
# var - The Var* LLVM reference for the variable to unset.
# varName -
# The Tcl string of the name of the variable.
#
# Results:
# None.
method frame.store(NEXIST) {value callframe var varName} {
my frame.unset $callframe $var $varName
}
# Builder:frame.unset --
#
# Unset a variable in a call frame.
#
# Parameters:
# callframe -
# The CALLFRAME LLVM value reference.
# var - The Var* LLVM reference for the variable to unset.
# varName -
# The Tcl string of the name of the variable.
#
# Results:
# None.
method frame.unset {callframe var varName} {
my frame.store(NEXIST\040STRING) [my nothing STRING] \
$callframe $var $varName
}
# Builder:frame.load --
#
# Read a value from a variable in a call frame. Only variables in the
# call frame may be read or writen with this method call.
#
# Parameters:
# callframe -
# The CALLFRAME LLVM value reference.
# var - The Var* LLVM reference for the variable to read.
# varName -
# The Tcl string of the name of the variable.
# name (optional) -
# The LLVM name of the result value.
#
# Results:
# An LLVM STRING? value reference.
method frame.load {callframe var varName {name ""}} {
my call ${tcl.callframe.load} [list $var [Const $varName STRING]] \
$name
}
# Builder:frame.bind.nsvar(STRING,STRING,STRING) --
#
# Link a variable in the local call frame to a variable looked up in a
# given named namespace.
#
# Parameters:
# localName -
# An LLVM STRING reference to the local variable name.
# nsName -
# An LLVM STRING reference to the namespace name.
# otherName -
# An LLVM STRING reference to the name of the variable in the
# namespace to link to.
# localVar -
# An LLVM Var* reference to the local variable.
# callframe -
# The CALLFRAME LLVM value reference.
# ec - An int* LLVM reference for where to write error codes into.
# name (optional) -
# The LLVM name of the result value.
#
# Results:
# An LLVM bool? value reference.
method frame.bind.nsvar(STRING,STRING,STRING) {
localName nsName otherName localVar callframe ec {name ""}} {
set otherVar [my call ${tcl.callframe.lookup.varns} [list \
$callframe $nsName $otherName] "otherVar"]
set val [my Call tcl.callframe.bindvar $callframe \
$otherVar $localVar $localName $ec]
return [my frame.pack $callframe $val $name]
}
# Builder:frame.bind.var(STRING,STRING) --
#
# Link a variable in the local call frame to a variable looked up with
# general respect to the call frame's context.
#
# Parameters:
# localName -
# An LLVM STRING reference to the local variable name.
# otherName -
# An LLVM STRING reference to the name of the variable to link
# to.
# localVar -
# An LLVM Var* reference to the local variable.
# callframe -
# The CALLFRAME LLVM value reference.
# ec - An int* LLVM reference for where to write error codes into.
# name (optional) -
# The LLVM name of the result value.
#
# Results:
# An LLVM bool? value reference.
method frame.bind.var(STRING,STRING) {
localName otherName localVar callframe ec {name ""}} {
set otherVar [my call ${tcl.callframe.lookup.var} [list \
$callframe $otherName] "otherVar"]
set val [my call ${tcl.callframe.bindvar} [list \
$callframe $otherVar $localVar $localName $ec] $name]
return [my frame.pack $callframe $val $name]
}
# Builder:frame.bind.nsvar(STRING,STRING,STRING) --
#
# Link a variable in the local call frame to a variable looked up in an
# indicated call frame.
#
# Parameters:
# localName -
# An LLVM STRING reference to the local variable name.
# level - An LLVM STRING reference to the level descriptor.
# otherName -
# An LLVM STRING reference to the name of the variable in the
# namespace to link to.
# localVar -
# An LLVM Var* reference to the local variable.
# callframe -
# The CALLFRAME LLVM value reference.
# ec - An int* LLVM reference for where to write error codes into.
# name (optional) -
# The LLVM name of the result value.
#
# Results:
# An LLVM bool? value reference.
method frame.bind.upvar(STRING,STRING,STRING) {
localName level otherName localVar callframe ec {name ""}} {
set otherVar [my call ${tcl.callframe.lookup.upvar} [list \
$callframe $level $otherName] "otherVar"]
set val [my call ${tcl.callframe.bindvar} [list \
$callframe $otherVar $localVar $localName $ec] $name]
return [my frame.pack $callframe $val $name]
}
# Builder:add(INT,INT) --
#
# Generate code to add two INTs. Quadcode implementation ('add').
#
# Parameters:
# left - The INT LLVM value reference for the left operand.
|
︙ | | |
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
|
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
|
-
+
-
+
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
# Parameters:
# value - The STRING/etc. LLVM value reference for the operand.
#
# Results:
# None.
method addReference(NEXIST\040STRING) {value} {
my Call tcl.addMaybeReference $value
my Call tcl.addNExistReference $value
return
}
# Builder:addReference(FAIL STRING) --
#
# Generate code to increment the reference count of a value.
#
# Parameters:
# value - The STRING/etc. LLVM value reference for the operand.
#
# Results:
# None.
method addReference(FAIL\040STRING) {value} {
my Call tcl.addMaybeReference $value
my Call tcl.addFailReference $value
return
}
# Builder:addReference(NEXIST EMPTY) --
#
# Generate code to increment the reference count of a value.
#
# Parameters:
# value - The STRING/etc. LLVM value reference for the operand.
#
# Results:
# None.
method addReference(NEXIST\040EMPTY) {value} {
my Call tcl.addMaybeReference $value
my Call tcl.addNExistReference $value
return
}
# Builder:addReference(FAIL EMPTY) --
#
# Generate code to increment the reference count of a value.
#
# Parameters:
# value - The STRING/etc. LLVM value reference for the operand.
#
# Results:
# None.
method addReference(FAIL\040EMPTY) {value} {
my Call tcl.addMaybeReference $value
my Call tcl.addFailReference $value
return
}
# Builder:addReference(DICTITER) --
#
# Generate code to increment the reference count of a DICTITER value.
#
# Parameters:
# value - The DICTITER LLVM value reference for the operand.
#
# Results:
# None.
method addReference(DICTITER) {value} {
my call ${tcl.dict.addIterReference} [list $value] ""
return
}
# Builder:addReference(FAIL DICTITER) --
#
# Generate code to increment the reference count of a FAIL DICTITER value.
#
# Parameters:
# value - The DICTITER LLVM value reference for the operand.
#
# Results:
# None.
method addReference(FAIL\040DICTITER) {value} {
my Call tcl.dict.addIterFailReference $value
}
# Builder:appendString --
#
# Append a string value to a working buffer. The working buffer is
# assumed to be an UNSHARED Tcl_Obj reference; caller must ensure this,
# and the quadcode stream does not provide this guarantee. See also the
# unshare(STRING) and unshareCopy(STRING) methods.
|
︙ | | |
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
|
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
|
-
+
-
+
-
+
-
-
+
+
|
method cast(INT?) {value {name ""}} {
if {[TypeOf $value] eq [Type int32]} {
set packer packInt32
} else {
set packer packInt64
}
my just [my $packer $value] $name
my ok [my $packer $value] $name
}
# Builder:cast(NUMERIC?) --
#
# Generate code to cast an INT, DOUBLE, INT? or DOUBLE? to a NUMERIC?.
#
# Parameters:
# value - The LLVM value reference. Must be of type INT, DOUBLE, INT? or
# DOUBLE? for this code to work.
# name (optional) -
# A name to give to the result value.
#
# Results:
# A NUMERIC FAIL LLVM value reference.
method cast(NUMERIC?) {value {name ""}} {
set t [TypeOf $value]
if {$t eq [Type DOUBLE]} {
return [my just [my packNumericDouble $value]]
return [my ok [my packNumericDouble $value]]
} elseif {$t eq [Type INT]} {
return [my just [my packNumericInt $value]]
return [my ok [my packNumericInt $value]]
} elseif {$t eq [Type DOUBLE?]} {
set packer packNumericDouble
} else {
set packer packNumericInt
}
my select [my maybe $value] [my nothing NUMERIC] \
[my just [my $packer [my unmaybe $value]]] $name
my select [my maybe $value] [my fail NUMERIC] \
[my ok [my $packer [my unmaybe $value]]] $name
}
# Builder:cast(bool) --
#
# Generate code to cast an INT to an int1.
#
# Parameters:
|
︙ | | |
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
|
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
#
# 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
# ('directAppend').
#
# Parameters:
# varname -
# The variable name 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 new contents of the variable.
method directAppend(STRING,STRING) {varname value ec {name ""}} {
my call ${tcl.direct.append} [list $varname $value $ec] $name
}
# Builder:directExists(STRING) --
#
# Test if a variable exists; the variable should be referred to by a
# fully-qualified name. Quadcode implementation ('directExists').
#
# Parameters:
# varname -
# The variable name as an LLVM value reference.
# name (optional) -
# A name to give to the result value.
#
# Results:
# A ZEROONE that indicates whether the variable is set.
method directExists(STRING) {varname {name ""}} {
my call ${tcl.direct.exists} [list $varname] $name
}
# Builder:directGet(STRING) --
#
# Read the value of 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 ('directGet').
#
# Parameters:
# varname -
# The variable name 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 contents of the variable.
method directGet(STRING) {varname ec {name ""}} {
my call ${tcl.direct.get} [list $varname $ec] $name
}
# Builder:directLappend(STRING,STRING) --
#
# Append a value to a list in 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
# ('directLappend').
#
# Parameters:
# varname -
# The variable name 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 new contents of the variable.
method directLappend(STRING,STRING) {varname value ec {name ""}} {
my call ${tcl.direct.lappend} [list $varname $value $ec] $name
}
# Builder:directSet(STRING,STRING) --
#
# Set the value of 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 ('directSet').
#
# Parameters:
# varname -
# The variable name 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 new contents of the variable.
method directSet(STRING,STRING) {varname value ec {name ""}} {
my call ${tcl.direct.set} [list $varname $value $ec] $name
}
# Builder:directUnset(STRING,INT) --
#
# Unset a variable, which should be referred to by a fully-qualified
# name. NOTE: this operation can fail because of traces so it produces a
# ZEROONE FAIL (with meaningless value when not failing). Quadcode
# implementation ('directUnset').
#
# Parameters:
# varname -
# The variable name as an LLVM value reference.
# flag - Whether failures are allowed, 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:
# Whether the unset was successful.
method directUnset(STRING,INT) {varname flag ec {name ""}} {
my call ${tcl.direct.unset} [list $varname $flag $ec] $name
}
# Builder:div(INT,INT) --
#
# Generate code to divide two INTs. Quadcode implementation ('div').
#
# Parameters:
# left - The INT LLVM value reference for the left operand.
|
︙ | | |
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
|
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
|
-
+
-
-
+
+
-
+
-
+
-
+
|
# None.
method dropReference(STRING) {value} {
my Call tcl.dropReference $value
return
}
# Builder:dropReference(STRING FAIL) --
# Builder:dropReference(FAIL EMPTY) --
#
# Generate code to decrement the reference count of a value and delete
# the value if it has ceased to be used.
#
# Parameters:
# value - The STRING FAIL LLVM value reference for the operand.
#
# Results:
# None.
method dropReference(STRING\040FAIL) {value} {
my Call tcl.dropMaybeReference $value
method dropReference(FAIL\040EMPTY) {value} {
my Call tcl.dropFailReference $value
return
}
# Builder:dropReference(FAIL STRING) --
#
# Generate code to decrement the reference count of a value and delete
# the value if it has ceased to be used.
#
# Parameters:
# value - The STRING FAIL LLVM value reference for the operand.
#
# Results:
# None.
method dropReference(FAIL\040STRING) {value} {
my Call tcl.dropMaybeReference $value
my Call tcl.dropFailReference $value
return
}
# Builder:dropReference(NEXIST STRING) --
#
# Generate code to decrement the reference count of a value and delete
# the value if it has ceased to be used.
#
# Parameters:
# value - The NEXIST STRING LLVM value reference for the operand.
#
# Results:
# None.
method dropReference(NEXIST\040STRING) {value} {
my Call tcl.dropMaybeReference $value
my Call tcl.dropNExistReference $value
return
}
# Builder:dropReference(NEXIST EMPTY) --
#
# Generate code to decrement the reference count of a value and delete
# the value if it has ceased to be used.
#
# Parameters:
# value - The NEXIST EMPTY LLVM value reference for the operand.
#
# Results:
# None.
method dropReference(NEXIST\040EMPTY) {value} {
my Call tcl.dropMaybeReference $value
my Call tcl.dropNExistReference $value
return
}
# Builder:dropReference(DICTITER) --
#
# Generate code to decrement the reference count of a value and delete
# the value if it has ceased to be used.
|
︙ | | |
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
|
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
#
# Results:
# A NUMERIC? LLVM value reference.
method expon(NUMERIC,NUMERIC) {left right ec {name ""}} {
my call ${tcl.pow.numeric} [list $left $right $ec] $name
}
# Builder:fail --
#
# Create a Nothing FAIL of the given type.
#
# Parameters:
# type - The type of the FAIL.
# code (optional) -
# The error code in the failure (LLVM int32 reference), or the
# empty string to use the default.
# name (optional) -
# A name to give to the result value.
#
# Results:
# An LLVM FAIL value reference containing nothing.
method fail {type {code ""} {name ""}} {
if {[string match "* FAIL" $type]} {
set type [string range $type 0 end-5]
} elseif {[string match "FAIL *" $type]} {
set type [string range $type 5 end]
}
if {$code eq ""} {
set code [Const 1]
}
my insert [my undef $type?] $code 0 $name
}
# Builder:ge --
#
# Generate code to compare two integers of the same bit width *or* two
# pointers to see if the first is greater or equal to the second.
#
# Parameters:
|
︙ | | |
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
|
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
|
-
+
|
set stringed [my stringify($type) $value]
set code [my Call tcl.initExceptionOptions $stringed $dict]
# FIXME?
# my dropReference $stringed
}
my store $code $errVar
my select [my eq $code [Const 0]] \
[my just $value] [my nothing $type] $name
[my ok $value] [my fail $type $code] $name
}
# Builder:initException(STRING,INT,INT) --
#
# Generate/set up an exception, returning a FAIL derived from the
# 'value' argument. Quadcode implementation ('initException').
#
|
︙ | | |
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
|
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
|
-
+
-
+
|
# name (optional) -
# A name to give to the result value.
#
# Results:
# An LLVM value reference.
method initException(STRING,INT,INT) {dict code level value type errVar {name ""}} {
if {$type eq "STRING"} {
if {$type in {STRING EMPTY}} {
set newcode [my Call tcl.processReturn \
$value [my getInt32 $code] [my getInt32 $level] $dict]
} else {
set stringed [my stringify($type) $value]
set newcode [my Call tcl.processReturn \
$stringed [my getInt32 $code] [my getInt32 $level] $dict]
# FIXME?
my dropReference $stringed
}
SetValueName $newcode "code"
my store $newcode $errVar
my select [my eq $newcode [Const 0]] \
[my just $value] [my nothing $type] $name
[my ok $value] [my fail $type $newcode] $name
}
# Builder:instanceOf.DOUBLE(STRING) --
#
# Generate code to check if the given STRING contains something that can
# be parsed to get a DOUBLE. Quadcode implementation ('instanceOf').
#
|
︙ | | |
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
|
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
|
-
+
-
+
-
+
-
+
|
method lt(STRING,STRING) {left right {name ""}} {
my lt [my Call tcl.cmp.strstr $left $right] [Const 0] $name
}
# Builder:just --
#
# Package a value as a Just FAIL.
# Package a value as a Just NEXIST.
#
# Parameters:
# value - The value to put inside the FAIL.
# value - The value to put inside the NEXIST.
# name (optional) -
# A name to give to the result value.
#
# Results:
# An LLVM FAIL value reference containing the other value.
# An LLVM NEXIST value reference containing the other value.
method just {value {name ""}} {
my insert [my insert [my undef [TypeOf $value]?] \
my insert [my insert [my undef [TypeOf $value]!] \
[Const false bool] 0] $value 1 $name
}
# Builder:narrowToType.DOUBLE(STRING) --
#
# Generate code to parse the given STRING and extract a DOUBLE. The
# STRING is already be known to contain a value of the right type (due
|
︙ | | |
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
|
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
|
-
+
|
my addReference(STRING) $value
return [my impure DOUBLE $value $nval $name]
}
# Builder:narrowToType.IMPURE_BOOLEAN(IMPURE ZEROONE BOOLEAN) --
#
# Generate code to extract IMPURE BOOLEAN from IMPURE ZEROONE BOOLEAN.
# The extracton does nothing except bump the reference count, the two
# The extraction does nothing except bump the reference count, the two
# types have the same internal representation
#
# Parameters:
# value - The STRING LLVM value reference to parse.
# name (optional) -
# A name to give to the result value.
#
|
︙ | | |
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
|
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
|
-
+
-
+
-
+
-
-
-
-
+
+
+
+
-
+
-
-
+
+
+
|
set nval [my call ${tcl.extractNumeric} [list $value]]
my addReference(STRING) $value
return [my impure NUMERIC $value $nval $name]
}
# Builder:nothing --
#
# Create a Nothing FAIL of the given type.
# Create a Nothing NEXIST of the given type.
#
# Parameters:
# type - The type of the FAIL.
# type - The type of the NEXIST.
# name (optional) -
# A name to give to the result value.
#
# Results:
# An LLVM FAIL value reference containing nothing.
# An LLVM NEXIST value reference containing nothing.
method nothing {type {name ""}} {
if {[string match "* FAIL" $type]} {
set type [string range $type 0 end-5]
} elseif {[string match "FAIL *" $type]} {
set type [string range $type 5 end]
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
my insert [my undef $type!] [Const true bool] 0 $name
}
# Builder:unmaybe --
#
# Get the value out of a FAIL. NOTE: The FAIL must be a Just or the
# result will be an 'undef'; test with the 'maybe' method first!
# 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!
#
# Parameters:
# value - The FAIL to get the value from.
# name (optional) -
# A name to give to the result value.
#
# Results:
|
︙ | | |
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
|
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
|
-
+
-
+
-
+
+
+
+
+
+
|
set mapping [my @jumptable.constant $mapping]
set notThere [Const $notThere int]
my call ${tcl.maptoint} [list $value $mapping $notThere] $name
}
# Builder:maybe --
#
# Test if the FAIL value is a Nothing.
# Test if the FAIL or NEXIST value is a Nothing.
#
# Parameters:
# type - The FAIL to examine.
# type - The FAIL or NEXIST to examine.
# name (optional) -
# A name to give to the result value.
#
# Results:
# An LLVM int1 value reference that is true when the FAIL is a Nothing
# and false when the FAIL is a Just.
method maybe {value {name ""}} {
my extract $value 0 $name
set flag [my extract $value 0 $name]
if {[TypeOf $flag] eq [Type bool]} {
my neq [Const false bool] $flag
} else {
my neq [Const 0] $flag
}
}
# Builder:max --
#
# Determines the maximum of two LLVM int[x] values.
#
# Parameters:
|
︙ | | |
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
|
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
#
# Results:
# A ZEROONE LLVM value reference.
method not(ZEROONE) {value errVar {name ""}} {
my not $value $name
}
# Builder:ok --
#
# Package a value as a Just FAIL.
#
# Parameters:
# value - The value to put inside the FAIL.
# name (optional) -
# A name to give to the result value.
#
# Results:
# An LLVM FAIL value reference containing the other value.
method ok {value {name ""}} {
my insert [my insert [my undef [TypeOf $value]?] \
[Const 0] 0] $value 1 $name
}
# Builder:packImpure(DOUBLE) --
#
# Convert a DOUBLE to an IMPURE DOUBLE
#
# Parameters:
# value - LLVM Value to pack into the 'impure' structure
|
︙ | | |
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
|
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
# Returns an LLVM IMPURE NUMERIC value
method {packImpure(ZEROONE BOOLEAN)} {value {name ""}} {
set sval [my stringify(NUMERIC) $value]
my addReference(STRING) $sval
return [my impure ZEROONE $sval $value $name]
}
# Builder:proc.return --
#
# Convert a return code in the way the end of a procedure does.
#
# 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 NUMERIC value
method proc.return {value procName} {
set name [Const $procName STRING]
return [my call ${tcl.procedure.return} [list $value $name] "code"]
}
# Builder:regexp(INT,STRING,STRING) --
#
# Match a string against a regular expression. NOTE: this operation can
# fail (e.g., because it can be given an invalid regexp) so it produces
# an INT FAIL. Quadcode implementation ('regexp').
#
|
︙ | | |
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
|
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
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
#
# Results:
# An INT LLVM value reference.
method rshift(INT,INT) {left right {name ""}} {
my call ${tcl.shr} [list $left $right] $name
}
# Builder:logCommandInfo --
#
# Generate code to log information about a command in the exception
# trace.
#
# Parameters:
# errorCode -
# The int32 LLVM value reference for the Tcl error code.
# command -
# The Tcl string containing the text of the command script
# (i.e., sourced before substitutions are performed).
#
# Results:
# None.
method logCommandInfo {errorCode command} {
set limit 150
set overflow [expr {[string length $command] > $limit}]
set length [Const [expr {$overflow ? $limit : [string length $command]}]]
set cmd [my constString $command]
set ellipsis [my constString [if {$overflow} {string cat "..."}]]
my Call tcl.logCommandInfo $errorCode $length $cmd $ellipsis
return
}
# Builder:setErrorLine --
#
# Generate code to log information about a command in the exception
# trace if that command happens to have generated an error.
#
# Parameters:
# test - The bool LLVM value reference that says whether the command
# this is talking about generated a non-TCL_OK result.
# errorCode -
# The int32 LLVM value reference for the Tcl error code.
# line - The int32 LLVM value reference for the source line number for
# the (start of) the command.
# command -
# The Tcl string containing the text of the command script
# (i.e., sourced before substitutions are performed).
#
# Results:
# None.
method setErrorLine {test errorCode line command} {
set limit 150
set overflow [expr {[string length $command] > $limit}]
set length [Const [expr {$overflow ? $limit : [string length $command]}]]
set cmd [my constString $command]
set ellipsis [my constString [if {$overflow} {string cat "..."}]]
my Call tcl.setErrorLine $test $errorCode $line $length $cmd $ellipsis
return
}
method storeInStruct {structPointer fieldOffset value} {
set field [my gep $structPointer 0 $fieldOffset]
set fieldName [regsub {.*\.} $fieldOffset ""]
SetValueName $field [GetValueName $structPointer].$fieldName
my store $value $field
}
|
︙ | | |
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
|
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
|
-
+
|
# A name to give to the result value.
#
# Results:
# A STRING FAIL LLVM value reference (never a nothing). This will have a
# non-zero reference count.
method strindex(STRING,INT) {str idx ecvar {name ""}} {
my just [my Call tcl.stridx $str $idx] $name
my ok [my Call tcl.stridx $str $idx] $name
}
# Builder:strindex(STRING,STRING) --
#
# Generate a STRING (of length 1) that describes the character in the
# input STRING located at the index given by the input STRING, or the
# empty STRING if that index does not indicate a character in the
|
︙ | | |
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
|
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
|
-
+
|
# A name to give to the result value.
#
# Results:
# A STRING FAIL LLVM value reference (never a nothing). This will have a
# non-zero reference count.
method strrange(STRING,INT,INT) {str from to ecvar {name ""}} {
my just [my Call tcl.strrange $str $from $to] $name
my ok [my Call tcl.strrange $str $from $to] $name
}
# Builder:strrange(STRING,STRING,STRING) --
#
# Generate a STRING that describes the substring of the input STRING
# located from the index given by the input STRING 'from' to the index
# given by the input STRING 'to', or the empty STRING if those indices
|
︙ | | |
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
|
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
|
-
+
|
# A name to give to the result value.
#
# Results:
# A STRING FAIL LLVM value reference (never a nothing). This will have a
# non-zero reference count.
method strreplace(STRING,INT,INT,STRING) {str from to substr ecvar {name ""}} {
my just [my Call tcl.strreplace $str $from $to $substr] $name
my ok [my Call tcl.strreplace $str $from $to $substr] $name
}
# Builder:strreplace(STRING,STRING,STRING,STRING) --
#
# Generate a STRING that is the input STRING 'str' with the substring
# from the index given by the input STRING 'from' to the index given by
# the input STRING 'to' replaced with the input STRING 'substr'. This is
|
︙ | | |
Changes to codegen/compile.tcl.
︙ | | |
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
-
+
|
#
# Public properties:
# none
oo::class create TclCompiler {
superclass llvmEntity
variable bytecode cmd func quads paramTypes returnType vtypes variables
variable m b pc errorCode
variable m b pc errorCode currentline currentscript
variable bytecodeVars namespace
constructor {} {
next
namespace import \
::quadcode::nameOfType \
::quadcode::typeOfLiteral \
|
︙ | | |
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
|
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
|
-
+
|
set returntype [Type $rtype]
##############################################################
#
# Construct the function signature type and the function object.
#
set ft [llvmtcl FunctionType $returntype $argl 0]
set ft [FunctionType $returntype $argl 0]
dict set bytecode signature [list $rtype $argn]
set realname [my GenerateFunctionName $cmd typecodes $paramTypes]
# Check if the function already exists; that indicates serious
# problems in the caller.
if {[$m function.defined $realname]} {
return -code error "duplicate $cmd"
}
|
︙ | | |
314
315
316
317
318
319
320
321
322
323
324
325
326
327
|
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
|
+
|
set pc -1
set ERROR_TEMPLATE "\n (compiling \"%s\" @ pc %d: %s)"
set phiAnnotations {}
set theframe {}
set thevarmap {}
set syntheticargs {}
set currentline 0
set currentscript {}
foreach l $quads {
incr pc
if {[info exists block($pc)]} {
$block($pc) build-in $b
set curr_block $block($pc)
set consumed {}
}
|
︙ | | |
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
|
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
|
-
-
+
+
+
+
+
+
|
lassign [my IssueEntry $l] \
theframe thevarmap syntheticargs
}
"confluence" - "unset" {
# Do nothing; required for SSA computations only
}
"@debug-line" {
lassign $l opcode - src
set currentline [lindex $src 1]
lassign $l opcode - srcfrom
set currentline [lindex $srcfrom 1]
}
"@debug-script" {
lassign $l opcode - srcscript
set currentscript [lindex $srcscript 1]
}
"@debug-value" {
# Debugging directive mapping value in quadcode to Tcl
# source variable; except we don't do that any more.
# Instead, a general "assign to something that looks like
# a variable" is good enough anyway, and that is handled
# in TclCompiler:StoreResult.
|
︙ | | |
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
|
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
|
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
+
+
+
+
+
-
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
-
+
+
+
+
+
|
[$b frame.load $theframe $var $vname $name]
}
}
"returnOptions" - "result" {
set srcs [lassign $l opcode tgt]
set name [my LocalVarName $tgt]
set srctype [my ValueTypes [lindex $srcs 0]]
if {"CALLFRAME" in $srctype} {
if {"CALLFRAME" in $srctype || $srctype eq "NEXIST"} {
set srcs [lrange $srcs 1 end]
}
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" -
"isBoolean" - "eq" - "neq" - "lt" - "gt" - "le" - "ge" -
"streq" - "bitnot" - "strcase" - "strclass" - "strcmp" -
"strfind" - "strlen" - "strmap" - "strmatch" - "strrfind" -
"strtrim" - "resolveCmd" {
"strtrim" - "resolveCmd" - "directExists" {
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]
}
"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}]
my StoreResult $tgt [$b $opcode {*}$srcs $errorCode $name]
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 $srcs $types $name]
}
"strindex" {
set srcs [lassign $l opcode tgt]
set name [my LocalVarName $tgt]
set srcs [my ConvertIndices 0 strlen 1]
my StoreResult $tgt [$b $opcode {*}$srcs $errorCode $name]
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]
my StoreResult $tgt [$b $opcode {*}$srcs $errorCode $name]
}
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" -
"directUnset" -
"regexp" - "listAppend" - "listConcat" - "listLength" -
"listRange" - "listIn" - "listNotIn" - "dictIterStart" -
"dictAppend" - "dictIncr" - "dictLappend" - "dictSize" -
"div" - "expon" - "mod" - "not" {
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 $errorCode $name]
set res [$b $opcode {*}$srcs $errorCode $name]
if {"FAIL" in [my ValueTypes $tgt]} {
my SetErrorLine $errorCode [$b maybe $res]
}
my StoreResult $tgt $res
}
"returnCode" {
lassign $l opcode tgt
set name [my LocalVarName $tgt]
my StoreResult $tgt [$b packInt32 [$b load $errorCode] $name]
}
"initException" {
|
︙ | | |
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
|
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
|
-
+
+
-
+
+
+
+
+
-
+
+
-
+
+
+
+
+
|
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}]
my StoreResult $tgt [$b $opcode {*}$srcs $errorCode $name]
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 $vectortypes \
[lmap s $srcs {my LoadOrLiteral $s}]]
append opcode ( [my ValueTypes $srcObj] )
set srcObj [my LoadOrLiteral $srcObj]
my StoreResult $tgt [$b $opcode $srcObj $vector $errorCode $name]
set res [$b $opcode $srcObj $vector $errorCode $name]
my StoreResult $tgt $res
$b clearVector $srcs $vector $vectortypes
}
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}]
my StoreResult $tgt [$b $opcode {*}$srcs $errorCode $name]
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 $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}]
my StoreResult $tgt [$b $opcode {*}$srcs $vector $errorCode $name]
set res [$b $opcode {*}$srcs $vector $errorCode $name]
my StoreResult $tgt $res
$b clearVector $srcs $vector $vectortypes
}
if {"FAIL" in [my ValueTypes $tgt]} {
my SetErrorLine $errorCode [$b maybe $res]
}
}
"copy" {
lassign $l opcode tgt src
set value [my LoadOrLiteral $src]
set type [my OperandType $tgt]
set name [my LocalVarName $tgt]
SetValueName $value $name
|
︙ | | |
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
|
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
|
+
+
+
+
|
lappend consumed $src
}
}
"exists" {
lassign $l opcode tgt src
set type [my OperandType $src]
if {$type eq "NEXIST"} {
my Warn "in exists with NEXIST type"
set value [Const false bool]
} elseif {!failType($type)} {
my Warn "in exists with definitely existing type"
set value [Const true bool]
} else {
set value [$b exists [my LoadOrLiteral $src]]
}
my StoreResult $tgt $value
}
"jumpMaybe" {
lassign $l opcode tgt src
set tgt [lindex $tgt 1]
if {failType(operandType($src))} {
set test [my Unlikely maybe [my LoadOrLiteral $src]]
$b condBr $test $block($tgt) $ipath($pc)
} else {
# Non-FAIL types never take the branch
my Warn "in jumpMaybe with non-fail type"
$b br $ipath($pc)
}
}
"jumpMaybeNot" {
lassign $l opcode tgt src
set tgt [lindex $tgt 1]
if {failType(operandType($src))} {
set test [my Unlikely maybe [my LoadOrLiteral $src]]
$b condBr $test $ipath($pc) $block($tgt)
} else {
# Non-FAIL types always take the branch
my Warn "in jumpMaybeNot with non-fail type"
$b br $block($tgt)
}
}
"jumpTrue" {
lassign $l opcode tgt src
set name [my LocalVarName $src]
set tgt [lindex $tgt 1]
|
︙ | | |
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
|
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
|
+
+
+
-
+
-
|
if {$theframe ne "" && ![IsNull $theframe]} {
$b frame.release $theframe $syntheticargs
}
$b ret $val
}
"returnException" {
lassign $l opcode -> frame code
set code [my LoadOrLiteral $code]
if {$theframe ne "" && ![IsNull $theframe]} {
$b frame.release $theframe $syntheticargs
}
set code [$b proc.return $code [namespace tail $cmd]]
# A VOID, a FAIL, a NEXIST, are all things that are not
# strings.
# TODO: Reconsider how to process return codes for these
if {![mightbea $returnType $STRING]} {
$b ret [Const true bool]
} else {
set type [nameOfType $returnType]
$b ret [$b fail [nameOfType $returnType] $code]
$b ret [$b nothing $type]
}
}
"phi" {
set values {}
set sources {}
foreach {var origin} [lassign $l opcode tgt] {
set spc [lindex $origin end]
|
︙ | | |
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
|
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
|
+
+
+
+
+
|
}
"foreachStart" {
set srcs [lassign $l opcode tgt assign]
set listtypes [lmap s $srcs {my ValueTypes $s}]
set lists [$b buildVector $listtypes \
[lmap s $srcs {my LoadOrLiteral $s}]]
set result [$b foreachStart [lindex $assign 1] $lists $errorCode]
if {"FAIL" in [my ValueTypes $tgt]} {
my SetErrorLine $errorCode [$b maybe $result]
}
my StoreResult $tgt $result
}
"unshareList" -
"foreachIter" - "foreachAdvance" - "foreachMayStep" -
"dictIterKey" - "dictIterValue" - "dictIterDone" -
"dictIterNext" {
lassign $l opcode tgt src
set name [my LocalVarName $tgt]
set result [$b $opcode [my LoadOrLiteral $src] $name]
my StoreResult $tgt $result
}
"widenTo" {
lassign $l opcode tgt src
my IssueWiden $l
}
"initIfNotExists" {
my IssueValueInit $l
}
"throwIfNotExists" {
set test [my IssueThrowIfNEXIST $l]
my SetErrorLine $errorCode $test
$b condBr $test $block($tgt) $ipath($pc)
}
"throwNotExists" {
lassign $l opcode tgt varname
set name [my LiteralValue $varname]
set msg "can't read \"$name\": no such variable"
set exn [list TCL LOOKUP VARNAME $name]
set msg [Const $msg STRING]
set exn [Const $exn STRING]
$b initException $exn $msg $errorCode
my SetErrorLine $errorCode
$b br $block([lindex $tgt 1])
}
"instanceOf" - "narrowToType" {
lassign $l opcode tgt src
lassign $opcode opcode - type
set name [my LocalVarName $tgt]
set type2 [my OperandType $src]
|
︙ | | |
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
|
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
|
+
+
|
$b br $ipath($pc)
} else {
append opcode . $type ( [my OperandType $src] )
set msg [Const $msg STRING]
set exn [Const $exn STRING]
set jmp [my Unlikely $opcode [my LoadOrLiteral $src] \
$msg $exn $errorCode "parse.failed"]
my SetErrorLine $errorCode $jmp
$b condBr $jmp $block($tgt) $ipath($pc)
}
}
"throwArithDomainError" {
lassign $l opcode tgt src opname
set msg [format \
"can't use non-numeric string as operand of \"%s\"" \
[my LiteralValue $opname]]
set exn "ARITH DOMAIN {non-numeric string}"
set msg [Const $msg STRING]
set exn [Const $exn STRING]
$b initException $exn $msg $errorCode
my SetErrorLine $errorCode
$b br $block([lindex $tgt 1])
}
"checkFunctionParam" - "narrowToParamType" -
"narrowToNotParamType" {
# These are supposed to never reach here; assert it
return -code error \
|
︙ | | |
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
|
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
|
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
|
}
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]
# FIXME: Assumes that called commands produce either TCL_OK or
# TCL_ERROR. That Ain't Necessarily So...
set ts [lmap t $BASETYPES {Type $t?}]
if {[TypeOf $result] in $ts} {
if {[my ValueTypes $tgt] eq "FAIL"} {
# FIXME: Assumes that called commands produce either TCL_OK or
# TCL_ERROR. That Ain't Necessarily So...
$b store [Const 1] $errorCode
my SetErrorLine $errorCode
} else {
set ts [lmap t $BASETYPES {Type $t?}]
if {[TypeOf $result] in $ts} {
set ec [$b cast(uint) [$b maybe $result]]
$b store $ec $errorCode
} elseif {[Type [TypeOf $result]?] eq [Type [my ValueTypes $tgt]]} {
# Managed to prove non-failure in this case...
set result [$b just $result]
$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
}
|
︙ | | |
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
|
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
|
+
+
+
|
# TODO: Pass in the resolution context (namespace ref).
# TODO: Make the invoke do something sensible with that namespace
# reference (if provided).
set result [$b invoke $vector $errorCode $vname]
# Result type is now FAIL STRING, always.
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
$b clearVector $arguments $vector $types
}
|
︙ | | |
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
|
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
|
-
+
+
+
+
+
|
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 *" - "NEXIST *" {
"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 {
|
︙ | | |
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
|
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
|
-
+
-
+
|
# Handle FAIL-extended types
if {"FAIL" in $srctype && "FAIL" in $tgttype} {
set value [$b unmaybe $value]
set srctype [lrange $srctype 1 end]
set tgttype [lrange $tgttype 1 end]
set value [my WidenedComplexValue $value $srctype $tgttype]
return [$b just $value $name]
return [$b ok $value $name]
} elseif {"FAIL" in $tgttype} {
set tgttype [lrange $tgttype 1 end]
set value [my WidenedComplexValue $value $srctype $tgttype]
return [$b just $value $name]
return [$b ok $value $name]
}
# Handle NEXIST-extended types
if {"NEXIST" in $srctype && "NEXIST" in $tgttype} {
set value [$b unmaybe $value]
set srctype [lrange $srctype 1 end]
set tgttype [lrange $tgttype 1 end]
|
︙ | | |
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
|
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
|
+
+
|
}
} elseif {$srctype eq "EMPTY" && $tgttype eq "STRING"} {
set value [Const "" STRING]
} elseif {$srctype ne $tgttype} {
my Warn "unimplemented convert from '$srctype' to '$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 --
#
|
︙ | | |
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
|
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
|
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
if {$dlen == 1 && [dict exists $s2lit -errorcode]
&& $maintype eq "STRING"
&& literal([lindex $srcs 1]) && literal([lindex $srcs 2])
&& [lindex $srcs 1 1] == 1 && [lindex $srcs 2 1] == 0} {
# Really a throw
set exn [Const [dict get $s2lit -errorcode] STRING]
$b initException $exn $value $errorCode
my SetErrorLine $errorCode
my StoreResult $tgt [$b nothing $maintype]
my StoreResult $tgt [$b fail $maintype [$b load $errorCode]]
return
}
if {$dlen == 0} {
# Blank options; substitute a NULL
set vals [linsert [lmap s [lrange $srcs 1 end] {
my LoadOrLiteral $s
}] 0 [$b null STRING]]
}
} elseif {[llength $srcs] == 1 && literal($src2)} {
my Warn "need to analyse options: %s" [lindex $src2 1]
}
# No special instruction sequence; pass it all through to the
# lower-level code issuers.
if {![info exist vals]} {
set vals [lmap s $srcs {my LoadOrLiteral $s}]
}
my StoreResult $tgt [$b $opcode {*}$vals $value $maintype \
$errorCode $name]
if {[llength $vals] == 1} {
$b logCommandInfo [$b load $errorCode] $currentscript
} else {
my SetErrorLine $errorCode
}
return
}
# TclCompiler:SetErrorLine --
#
# Generate code to set the errorLine and errorInfo for an exception. The
# error information is only set if the errorCode is TCL_ERROR and the
# test passes.
#
# Expects to only ever be called in a context where it is possible to
# determine what the current source line and command script text are.
#
# Parameters:
# errorCode -
# The LLVM int32* (i.e., pointer to variable) that the error
# code will be loaded from.
# test (optional) -
# The LLVM bool that will govern whether to issue the exception
# processing. If omitted, will be taken as being the true
# constant.
#
# Results:
# none
method SetErrorLine {errorCode {test ""}} {
if {$test eq ""} {
set test [Const true bool]
}
set line $currentline
if {[dict exists $bytecode initiallinenumber]} {
set line [expr {
$line - [dict get $bytecode initiallinenumber]
}]
}
# The line number for the errorLine field needs to begin at 1
incr line
$b setErrorLine $test [$b load $errorCode] [Const $line int] \
$currentscript
return
}
# TclCompiler:Unlikely --
#
# Issue a (boolean-returning) instruction and mark it as being expected
# to produce a false.
|
︙ | | |
Changes to codegen/mathlib.tcl.
Changes to codegen/stdlib.tcl.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
-
+
-
+
+
|
# stdlib.tcl --
#
# Implementations of the majority of quadcodes in LLVM IR. The
# implementations are generated as mandatory-inline functions that are
# added onto the Builder class, so that it can issue them by just
# generating a call to the implementation function. This allows us to
# inject extra basic blocks without disturbing the analysis from the
# reasoning engine.
#
# See build.tcl for where these functions are called from.
#
# Copyright (c) 2015-2016 by Donal K. Fellows
# Copyright (c) 2015-2017 by Donal K. Fellows
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
#------------------------------------------------------------------------------
oo::define Builder {
# Variables holding implementations of Tcl's string operators
variable tcl.stringify.double tcl.stringify.int tcl.stringify.numeric
variable tcl.addReference tcl.dropReference
variable tcl.addMaybeReference tcl.dropMaybeReference
variable tcl.addFailReference tcl.dropFailReference
variable tcl.addNExistReference tcl.dropNExistReference
variable tcl.unshare tcl.unshare.copy
variable tcl.strlen tcl.append.string tcl.streq tcl.strcmp tcl.strmatch
variable tcl.stridx tcl.stridx.idx
variable tcl.strrange tcl.strrange.idx tcl.strreplace tcl.strreplace.idx
variable tcl.strfind.fwd tcl.strfind.rev
variable tcl.strmap tcl.strtrim tcl.strcase tcl.strclass
variable tcl.regexp tcl.concatenate tcl.booleanTest tcl.not.string
|
︙ | | |
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
|
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
|
+
-
-
+
+
-
-
-
-
+
-
+
-
-
|
variable tcl.list.set tcl.list.set1 tcl.list.setList
# 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.maptoint
# Variables holding implementations of Tcl's exception-handling machinery
variable tcl.getresult tcl.getreturnopts tcl.initExceptionOptions
variable tcl.initExceptionSimple tcl.processReturn
variable tcl.existsOrError tcl.invoke.command
variable tcl.initExceptionSimple tcl.processReturn tcl.procedure.return
variable tcl.setErrorLine tcl.existsOrError tcl.invoke.command
# Variables holding implementations of Tcl's callframe handling
variable tcl.callframe.init tcl.callframe.makevar tcl.callframe.clear
variable tcl.callframe.store tcl.callframe.load
variable tcl.logCommandInfo
# Helper functions
variable tcl.impl.trimleft tcl.impl.trimright
variable tcl.impl.trimleft tcl.impl.trimright obj.cleanup
variable tcl.impl.getIndex tcl.impl.listDupe
variable var.hash.getValue
variable tcl.read.var.ptr tcl.write.var.ptr tcl.unset.var.ptr
# Reference to the module object
variable m
# Builder:ReferenceFunctions --
#
# Generate the functions that implement Tcl_Obj reference management.
|
︙ | | |
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
|
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
|
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
+
-
+
-
+
|
params value:objPtr
build {
nonnull $value
$api Tcl_DecrRefCount $value
my ret
}
##### tcl.addMaybeReference #####
##### tcl.addFailReference #####
#
# Type signature: objPtr:Tcl_Obj*? -> void
#
# 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
}
##### tcl.addNExistReference #####
#
# Type signature: objPtr:Tcl_Obj*! -> void
#
# Increment the reference count of a Tcl_Obj reference if the
# object is supplied
set f [$m local "tcl.addMaybeReference" void<-Tcl_Obj*?]
set f [$m local "tcl.addNExistReference" 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.dropMaybeReference #####
##### tcl.dropNExistReference #####
#
# Type signature: objPtr:Tcl_Obj*? -> void
# 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.dropMaybeReference" void<-Tcl_Obj*?]
set f [$m local "tcl.dropNExistReference" 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
|
︙ | | |
413
414
415
416
417
418
419
420
421
422
423
424
425
426
|
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
|
+
+
|
set length [my castInt2Int $length $size_t]
}
my call $memcmp [list $bytes1 $bytes2 $length] $name
}
my StringInspectionFunctions $api
my StringWritingFunctions $api
my ListFunctions $api
my DictionaryFunctions $api
my StringComparisonFunctions $api
return
}
# Builder:StringInspectionFunctions --
#
|
︙ | | |
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
|
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
|
-
+
-
-
+
+
-
+
|
my ret $res
}
unset -nocomplain valueObj
##### Function tcl.impl.getWide #####
##### MAPPED CALL TO METHOD: Build:GetWide #####
#
# Type signature: valueObj:STRING -> int * int64
# 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} {
my call ${tcl.impl.getWide} [list $valueObj] "result"
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"]
set code [$api Tcl_GetWideIntFromObj {} $valueObj $intVar]
set res [my undef struct{int1,int64}]
set res [my undef struct{bool,int64}]
set res [my insert $res [my eq $code [Const 0]] 0]
set res [my insert $res [my load $intVar "int"] 1 "result"]
my ret $res
}
unset -nocomplain valueObj
##### Function tcl.impl.getString #####
|
︙ | | |
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
|
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
|
-
+
-
+
|
set unicodeResult [$api Tcl_NewStringObj $buf $len]
my br $done
label done:
set result [my phi \
[list $emptyResult $byteResult $asciiResult $unicodeResult] \
[list $empty $baIdx $byteIndex $strIdx] "result"]
my addReference(STRING) $result
my ret [my just $result]
my ret [my ok $result]
label failed:
my store $1 $ecvar
my ret [my nothing STRING]
my ret [my fail STRING]
}
##### Function tcl.strrange #####
#
# Type signature: objPtr:STRING * fromInt:INT * toInt:INT -> STRING
#
# Quadcode implementation ('strrange')
|
︙ | | |
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
|
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
|
-
+
-
+
|
label realSubstring:
set value2 [$api Tcl_GetRange $str $from $to]
my br $finish
label finish:
set result [my phi [list $value1 $value2] \
[list $empty $realSubstring] "result"]
my addReference(STRING) $result
my ret [my just $result]
my ret [my ok $result]
label failed:
my store $1 $ecvar
my ret [my nothing STRING]
my ret [my fail STRING]
}
##### Function tcl.strreplace #####
#
# Type signature: objPtr:STRING * fromInt:INT * toInt:INT
# * substringPtr:STRING -> STRING
#
|
︙ | | |
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
|
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
|
-
+
-
+
|
label getTo:
my condBr [my GetIndex $interp $toIdx $end to] \
$rangeCheck $failed
label rangeCheck:
set from [my packInt32 $from]
set to [my packInt32 $to]
set replaced [my Call tcl.strreplace $str $from $to $substr]
my ret [my just $replaced]
my ret [my ok $replaced]
label failed:
my store $1 $ecvar
my ret [my nothing STRING]
my ret [my fail STRING]
}
##### Function tcl.strmap #####
#
# Type signature: sourceObj:STRING * targetObj:STIRNG *
# stringObj:STRING -> STRING
#
|
︙ | | |
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
|
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
label releaseIntRep "release.internal.representation"
$api TclFreeIntRep $string
my br $done
label done:
my addReference(STRING) $string
my ret $string
}
##### Function tcl.maptoint #####
#
# Type signature: value:STRING * mapping:STRING * notThere:int -> INT
#
# Quadcode implementation ('maptoint')
#
# Returns the INT looked up in 'mapping' that corresponds to 'value'.
# If the value is absent, returns the 'notThere' value.
set f [$m local "tcl.maptoint" INT<-STRING,HashTable*,int]
params value mapping notThere
build {
nonnull $value $mapping
set offset [$api TclFindHashEntry $mapping $value]
SetValueName $offset "offsetPtr"
my condBr [my nonnull $offset] $present $absent
label present:
set offset [$api Tcl_GetHashValue $offset int]
SetValueName $offset "offset"
my ret [my packInt32 $offset]
label absent:
my ret [my packInt32 $notThere]
}
##### Function tcl.concatenate #####
#
# Type signature: len:int * ary:STRING* -> STRING
#
# Quadcode implementation ('concat')
#
# Returns the application of Tcl_ConcatObj() to the given values, so
# much so that it is just a very thin wrapper around that function.
set f [$m local "tcl.concatenate" STRING<-int,STRING*]
params len ary
build {
nonnull $ary
set result [$api Tcl_ConcatObj $len $ary]
my addReference(STRING) $result
my ret $result
}
}
# Builder:ListFunctions --
#
# Generate the functions that implement the list-handling operators.
# Only called from StringFunctions method.
#
# Parameters:
# api - The handle of the Tcl API object (currently an instance of the
# Thunk class).
#
# Results:
# None.
method ListFunctions {api} {
upvar 1 0 0 1 1 -1 -1
##### Function tcl.impl.listDupe #####
##### Closure Build:ListDupe #####
#
# Type signature: interp:Interp* * obj:STRING -> STRING
#
# Replacement for non-exposed TclListObjCopy().
|
︙ | | |
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
|
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
|
-
+
|
set var [my alloc int "length"]
set code [$api Tcl_ListObjLength $interp $list $var]
my condBr [my eq $code $0] $ok $fail
label ok:
my ret [my cast(INT?) [my load $var]]
label fail:
my store $1 $ecvar
my ret [my nothing INT]
my ret [my fail INT]
}
##### Function tcl.list.append #####
#
# Type signature: list:STRING * value:STRING * ecvar:int* -> STRING?
#
# Core of quadcode implementation ('listAppend')
|
︙ | | |
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
|
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
|
-
+
-
+
|
$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 just $list]
my ret [my ok $list]
label error:
my store $1 $ecvar
my ret [my nothing STRING]
my ret [my fail STRING]
}
##### Function tcl.list.concat #####
#
# Type signature: list:STRING * value:STRING * ecvar:int* -> STRING?
#
# Core of quadcode implementation ('listConcat')
|
︙ | | |
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
|
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
|
-
+
-
+
|
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 just $working]
my ret [my ok $working]
label error:
my store $1 $ecvar
my ret [my nothing STRING]
my ret [my fail STRING]
}
##### Function tcl.list.index #####
#
# Type signature: list:STRING * idxc:int * idxv:STRING* * ecvar:int*
# -> STRING?
#
|
︙ | | |
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
|
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
|
-
+
-
+
-
+
|
my condBr [my lt $i $idxc] $loopIndexValidityCheck $loopEmpty
label loopEmpty:
my store [set list [$api Tcl_NewObj]] $listPtr
my addReference(STRING) $list
my br $loopNext
label loopIndexValidityCheck:
my condBr [my GetIndex $interp \
[my load [my getelementptr $idxv [list $i]]] [Const -1]] \
[my load [my getelementptr $idxv [list $i]]] ${-1}] \
$loopIndexOutOfRange $loopIndexBad
label loopIndexBad:
my dropReference $sublistCopy
my br $error
label loopNext:
my dropReference $sublistCopy
my store [my add [my load $iPtr "i"] $1] $iPtr
my br $loopTest
label done:
set list [my load $listPtr "list"]
my ret [my just $list]
my ret [my ok $list]
label error:
my store $1 $ecvar
my ret [my nothing STRING]
my ret [my fail STRING]
}
##### Function tcl.list.index1 #####
#
# Type signature: list:STRING * index:INT * ecvar:int* -> STRING?
#
# Core of quadcode implementation ('listIndex')
|
︙ | | |
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
|
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
|
-
+
-
+
-
+
|
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 just $obj]
my ret [my ok $obj]
label outOfBounds "out.of.bounds"
set obj [$api Tcl_NewObj]
my addReference(STRING) $obj
my ret [my just $obj]
my ret [my ok $obj]
label fail:
my store $1 $ecvar
my ret [my nothing STRING]
my ret [my fail STRING]
}
##### Function tcl.list.indexList #####
#
# Type signature: list:STRING * index:STRING * ecvar:int* -> STRING?
#
# Core of quadcode implementation ('listIndex')
|
︙ | | |
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
|
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
|
-
+
-
+
-
+
|
set objc [my alloc int "objc"]
set objv [my alloc STRING* "objv"]
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 nothing STRING]
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
label immediateIndex:
my condBr [my and [my ge $idx $0] [my lt $idx $len]] \
$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 just $obj]
my ret [my ok $obj]
label outOfBounds "out.of.bounds"
set obj [$api Tcl_NewObj]
my addReference(STRING) $obj
my ret [my just $obj]
my ret [my ok $obj]
label slowPath:
set dupe [my ListDupe $interp $index "copy"]
my condBr [my nonnull $dupe] $okIndex $notList
label okIndex:
set listRep [my load [my cast(ptr) \
[my gep $dupe 0 Tcl_Obj.internalRep 0] \
TclList*] "listRep"]
|
︙ | | |
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
|
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
|
-
+
-
+
|
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 just $result]
my ret [my ok $result]
label error:
my store $1 $ecvar
my ret [my nothing STRING]
my ret [my fail STRING]
}
##### Function tcl.list.range1 #####
#
# Type signature: list:STRING * from:INT * to:INT -> STRING?
#
# Core of quadcode implementation ('listRangeImm')
|
︙ | | |
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
|
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
|
-
+
-
+
-
+
|
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 just $result]
my ret [my ok $result]
label error:
my store $1 $ecvar
my ret [my nothing STRING]
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 interp [$api tclInterp]
my condBr [my eq $idxc $0] $doNothing $sharedCheck
label doNothing:
my addReference(STRING) $list
my ret [my just $list]
my ret [my ok $list]
label sharedCheck:
my condBr [my shared $list] $duplicate $prepareToLoop
label duplicate:
set dupe [$api Tcl_DuplicateObj $list]
my br $prepareToLoop
label prepareToLoop:
set sources [list $sharedCheck $duplicate]
|
︙ | | |
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
|
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
|
-
+
|
my condBr [my neq $retValue $list] \
$loopFailDropOverall $loopFailExit
label loopFailDropOverall:
my dropReference $retValue
my br $loopFailExit
label loopFailExit:
my store $1 $ecvar
my ret [my nothing STRING]
my ret [my fail STRING]
label loopEnd:
set sublist [my load $subList]
set obj [my load $chain]
my condBr [my nonnull $obj] $loopEndDrop $terminalSet
label loopEndDrop:
set ptr2 \
[my cast(ptr) [my gep $obj 0 Tcl_Obj.internalRep 1] STRING]
|
︙ | | |
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
|
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
|
-
+
|
$api TclInvalidateStringRep $sublist
my addReference(STRING) $retValue
my condBr [my shared $elem] $exit2 $exit3
label exit3 "exit"
my addReference(STRING) $elem
my br $exit2
label exit2 "exit"
my ret [my just $retValue]
my ret [my ok $retValue]
}
##### Function tcl.list.set1 #####
#
# Type signature: list:STRING * index:INT * elem:STRING * ecvar:int*
# -> STRING?
#
|
︙ | | |
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
|
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
|
-
+
-
+
|
$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 just $list]
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 nothing STRING]
my ret [my fail STRING]
}
##### Function tcl.list.setList #####
#
# Type signature: list:STRING * idxArg:STRING * elem:STRING
# * ecvar:int* -> STRING?
#
|
︙ | | |
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
|
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
|
-
+
-
+
|
my condBr [my eq [my memcmp $bytes1 $bytes2 $len1] $0] \
$done $loopNext
label loopNext:
ReplaceAllUsesWith $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 nothing ZEROONE]
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 just $flag]
my ret [my ok $flag]
}
##### Function tcl.list.unshare #####
#
# Type signature: list:STRING -> STRING
#
# Core of quadcode implementation ('unshareList')
|
︙ | | |
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
|
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
|
-
+
-
+
|
ReplaceAllUsesWith $maxLoop [my max $iterTmp $max "max"]
ReplaceAllUsesWith $iLoop [my add $i $1 "i"]
my br $loopStart
label ok:
set pair [my undef FOREACH]
set pair [my insert $pair $0 FOREACH.val]
set pair [my insert $pair $max FOREACH.max]
my ret [my just $pair]
my ret [my ok $pair]
label fail:
my store $1 $ecVar
my ret [my nothing FOREACH]
my ret [my fail FOREACH]
}
##### Function tcl.list.foreach.getStep #####
#
# Type signature: pair:FOREACH -> INT
#
# Core of quadcode implementation ('foreachIter')
|
︙ | | |
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
|
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
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
set f [$m local "tcl.list.foreach.nextStep" FOREACH<-FOREACH readnone]
params pair
build {
set val [my extract $pair FOREACH.val]
my ret [my insert $pair [my add $val $1] FOREACH.val]
}
}
# Builder:DictionaryFunctions --
#
# Generate the functions that implement the dict-handling operators.
# Only called from StringFunctions method.
#
# Parameters:
# api - The handle of the Tcl API object (currently an instance of the
# 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.
|
︙ | | |
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
|
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
|
-
+
|
set size [my alloc int "size"]
set code [$api Tcl_DictObjSize $interp $dict $size]
my condBr [my eq $code $0] $ok $fail
label ok:
my ret [my cast(INT?) [my load $size]]
label fail:
my store $1 $ecvar
my ret [my nothing INT]
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
|
︙ | | |
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
|
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
|
-
+
-
+
|
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 just $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 null char*]
my br $notOK
label notOK:
my store $1 $ecvar
my ret [my nothing STRING]
my ret [my fail STRING]
}
##### Function tcl.dict.get #####
#
# Type signature: dict:STRING * pathlen:int * pathobjs:STRING*
# * ecvar:int32* -> STRING?
#
|
︙ | | |
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
|
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
|
-
+
-
+
|
my condBr [my eq $result $0] $OK $fail
label OK:
set value [my load $resvar "value"]
my condBr [my nonnull $value] $return $fail
label return:
set value [my phi [list $dict $value] [list $verify $OK] "value"]
my addReference(STRING) $value
my ret [my just $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 null char*]
my br $notOK
label notOK:
my store $1 $ecvar
my ret [my nothing STRING]
my ret [my fail STRING]
}
##### Function tcl.dict.set1 #####
#
# Type signature: dict:STRING * key:STRING * value:STRING
# * ecvar:int32* -> STRING?
#
|
︙ | | |
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
|
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
|
-
+
-
+
|
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 just $dict]
my ret [my ok $dict]
label notOK:
my Call obj.cleanup $dd
my store $1 $ecvar
my ret [my nothing STRING]
my ret [my fail STRING]
}
##### Function tcl.dict.set #####
#
# Type signature: dict:STRING * pathlen:int * pathobjs:STRING*
# * value:STRING * ecvar:int32* -> STRING?
#
|
︙ | | |
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
|
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
|
-
+
-
+
-
+
-
+
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
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 just $dict]
my ret [my ok $dict]
label notOK:
my Call obj.cleanup $dd
my store $1 $ecvar
my ret [my nothing STRING]
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 just $dict]
my ret [my ok $dict]
label notOK:
my Call obj.cleanup $dd
my store $1 $ecvar
my ret [my nothing STRING]
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 just $dict]
my ret [my ok $dict]
label notOK:
my Call obj.cleanup $dd
my store $1 $ecvar
my ret [my nothing STRING]
my ret [my fail STRING]
}
##### Function tcl.dict.addIterReference #####
#
# Type signature: iter:DICTITER -> void
#
# Increments the reference count inside a dictionary iteration state.
set f [$m local "tcl.dict.addIterReference" void<-DICTITER]
params iter
build {
nonnull $iter
set ref [my gep $iter 0 DICTFOR.ref]
set rc [my load $ref]
my store [my add $rc $1] $ref
my ret
}
##### Function tcl.dict.addIterFailReference #####
#
# Type signature: value:DICTITER? -> void
#
# Increments the reference count inside a dictionary iteration
# state, allowing for failure
set f [$m local "tcl.dict.addIterFailReference" void<-DICTITER?]
params value
build {
my condBr [my maybe $value] $nothing $release
label nothing:
my ret
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
|
︙ | | |
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
|
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
|
-
+
-
+
|
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 just $iter]
my ret [my ok $iter]
label failed:
$api ckfree $iter
my store $1 $ecvar
my ret [my nothing DICTITER]
my ret [my fail DICTITER]
}
##### Function tcl.dict.iterNext #####
#
# Type signature: iter:DICTITER -> DICTITER
#
# Continues iterating over a dictionary. The current state of the
|
︙ | | |
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
|
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
|
-
+
-
+
|
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 just $dict]
my ret [my ok $dict]
label notOK:
my Call obj.cleanup $dd
my store $1 $ecvar
my ret [my nothing STRING]
my ret [my fail STRING]
}
##### Function tcl.dict.incr #####
#
# Type signature: dict:STRING * key:STRING * value:INT
# * ecvar:int32* -> STRING?
#
|
︙ | | |
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
|
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
|
-
+
-
+
|
my br $done
label done:
set resultValue [my phi [list $strVal $addVal] \
[list $set $doAdd] "value"]
# No failure mode at this point: we know we've got a dictionary.
set c [$api Tcl_DictObjPut {} $dict $key $resultValue]
my addReference(STRING) $dict
my ret [my just $dict]
my ret [my ok $dict]
label notOK:
my Call obj.cleanup $dd
my store $1 $ecvar
my ret [my nothing STRING]
my ret [my fail STRING]
}
##### Function tcl.dict.lappend #####
#
# Type signature: dict:STRING * key:STRING * value:STRING
# * ecvar:int32* -> STRING?
#
|
︙ | | |
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
|
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
|
-
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
my condBr [my eq $result $0] $dupeUpdateOK $dupeNotOK
label dupeUpdateOK:
set c [$api Tcl_DictObjPut {} $dict $key $dictVal]
AddCallAttribute $c 3 nocapture
my br $done
label done:
my addReference(STRING) $dict
my ret [my just $dict]
my ret [my ok $dict]
label dupeNotOK:
my dropReference $dictVal
my br $notOK
label notOK:
my Call obj.cleanup $dd
my store $1 $ecvar
my ret [my nothing STRING]
my ret [my fail STRING]
}
##### Function tcl.maptoint #####
#
# Type signature: value:STRING * mapping:STRING * notThere:int -> INT
#
# Quadcode implementation ('maptoint')
#
# Returns the INT looked up in 'mapping' that corresponds to 'value'.
# If the value is absent, returns the 'notThere' value.
set f [$m local "tcl.maptoint" INT<-STRING,HashTable*,int]
params value mapping notThere
build {
nonnull $value $mapping
set offset [$api TclFindHashEntry $mapping $value]
SetValueName $offset "offsetPtr"
my condBr [my nonnull $offset] $present $absent
label present:
set offset [$api Tcl_GetHashValue $offset int]
SetValueName $offset "offset"
my ret [my packInt32 $offset]
label absent:
my ret [my packInt32 $notThere]
}
##### Function tcl.concatenate #####
#
# Type signature: len:int * ary:STRING* -> STRING
#
# Quadcode implementation ('concat')
#
# Returns the application of Tcl_ConcatObj() to the given values, so
# much so that it is just a very thin wrapper around that function.
set f [$m local "tcl.concatenate" STRING<-int,STRING*]
params len ary
build {
nonnull $ary
set result [$api Tcl_ConcatObj $len $ary]
my addReference(STRING) $result
my ret $result
}
}
# Builder:StringComparisonFunctions --
#
# Generate the functions that implement the string comparators. Only
# called from StringFunctions method.
|
︙ | | |
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
|
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
|
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
[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 just [my gt $match $0]]
my ret [my ok [my gt $match $0]]
label err "re.error"
my store $1 $errVar
my ret [my nothing ZEROONE]
}
}
# Builder:CallFrameFunctions --
#
# Generate the functions that implement the callframe handling.
#
# Parameters:
# api - The handle of the Tcl API object (currently an instance of the
# Thunk class).
#
# Results:
# None.
method CallFrameFunctions {api} {
set 0 [Const 0]
set 1 [Const 1]
set f [$m local "tcl.callframe.init" \
void<-CALLFRAME,int,int,STRING*,Proc*,LocalCache*,Var*]
params frame length objc objv proc localCache locals
build {
set interp [$api tclInterp]
set rcPtr [my gep $proc 0 Proc.refCount]
my store [my add [my load $rcPtr] $1] $rcPtr
set nsPtr [my dereference [my dereference $proc 0 Proc.cmdPtr] \
0 Command.nsPtr]
$api Tcl_PushCallFrame $interp $frame $nsPtr $1
set varTable [my null VarHashTable*]
set cllen1 [my mult $length [my cast(int) [my sizeof Var]]]
my storeInStruct $frame CallFrame.objc $objc
my storeInStruct $frame CallFrame.objv $objv
my storeInStruct $frame CallFrame.procPtr $proc
my storeInStruct $frame CallFrame.varTablePtr $varTable
my storeInStruct $frame CallFrame.numCompiledLocals $length
my storeInStruct $frame CallFrame.compiledLocals $locals
my storeInStruct $frame CallFrame.localCachePtr $localCache
set rcPtr [my gep $localCache 0 LocalCache.refCount]
my store [my add [my load $rcPtr] $1] $rcPtr
my bzero $locals $cllen1
my ret
my ret [my fail ZEROONE]
}
set f [$m local "tcl.callframe.makevar" Var*<-CALLFRAME,int,int]
params frame index flags
build {
set lvt [my dereference $frame 0 CallFrame.compiledLocals]
set local [my getelementptr $lvt $index]
my storeInStruct $local Var.flags $flags
my storeInStruct $local Var.value [my null Tcl_Obj*]
my ret $local
}
set f [$m local "tcl.callframe.clear" void<-CALLFRAME]
params frame
build {
set interp [$api tclInterp]
$api Tcl_PopCallFrame $interp
set proc [my dereference $frame 0 CallFrame.procPtr]
set rcPtr [my gep $proc 0 Proc.refCount]
my store [my sub [my load $rcPtr] $1] $rcPtr
# TODO: ought to theoretically delete the Proc when it has a
# refcount of 0.
my ret
}
set f [$m local "tcl.callframe.store" void<-Var*,STRING,STRING?]
params var varName value
build {
set interp [$api tclInterp]
set nv [my null Var*]
set ns [my null STRING]
my condBr [my maybe $value] $doUnset $doSet
label doSet:
set value [my unmaybe $value]
my Call tcl.write.var.ptr $interp $var $nv $varName $ns $value $0
my ret
label doUnset:
my Call tcl.unset.var.ptr $interp $var $nv $varName $ns $0
my ret
}
set f [$m local "tcl.callframe.load" STRING?<-Var*,STRING]
params var varName
build {
set interp [$api tclInterp]
set nv [my null Var*]
set ns [my null STRING]
set value [my Call tcl.read.var.ptr $interp $var $nv $varName $ns $0]
my condBr [my nonnull $value] \
$gotValue $noValue
label gotValue:
my addReference(STRING) $value
my ret [my just $value]
label noValue:
my ret [my nothing STRING]
}
}
# Builder:@apiFunctions --
#
# Generate the quadcode operator implementations that require access to
# the Tcl API to work.
#
# Parameters:
# api - The handle of the Tcl API object (currently an instance of the
# Thunk class).
#
# Results:
# None.
method @apiFunctions {module api} {
##### Function tcl.print.string #####
##### Closure Build:printf #####
##### Closure Build:fprintf #####
#
# Print a formatted string.
#
# Parameters:
# channel (fprintf only) -
# Either "stdout" or "stderr" to select which channel to
# print to.
# str - The Tcl string holding the format string.
# args - The arguments to use in the format. These must be all
# LLVM values of the correct type.
# Results:
# The reference count, as a LLVM value.
set f [$module local tcl.print.string void<-int,Tcl_Obj*]
my closure printf {str args} {
my Call tcl.print.string [Const [expr 1<<2]] \
[$api Tcl_ObjPrintf [my constString $str] {*}$args]
}
my closure fprintf {channel str args} {
set id [dict get {stdout 2 stderr 3} $channel]
my Call tcl.print.string [Const [expr {1<<$id}]] \
[$api Tcl_ObjPrintf [my constString $str] {*}$args]
}
params chanID str
build {
set chan [$api Tcl_GetStdChannel $chanID]
$api Tcl_WriteObj $chan $str
$api Tcl_DecrRefCount $str
my ret
}
my StringifyFunctions $api
my ReferenceFunctions $api
my StringFunctions $api
# Builder:MathException --
#
# Generate one of the standard math exceptions that are produced
|
︙ | | |
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
|
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
label addFlag "error.addFlag"
set field [my gep $interp 0 Interp.flags]
my store [my or [my load $field] [Const 0x800]] $field
my br $done
label done:
my ret $code
}
##### Function tcl.procedure.return #####
#
# Type signature: code:INT * procName:STRING -> int32
#
# Handles the transforms on a result when a procedure returns. See
# InterpProcNR2 in tclProc.c for what is going on; this is the part
# commencing at the 'process' label.
set f [$m local "tcl.procedure.return" int32<-INT,STRING]
params code procName
build {
set interp [$api tclInterp]
set code [my getInt32 $code]
my condBr [my eq $code [Const 2]] $handleReturn $test2
label test2:
my condBr [my eq $code [Const 3]] $handleBreak $test3
label test3:
my condBr [my eq $code [Const 4]] $handleContinue $test4
label test4:
my condBr [my eq $code [Const 1]] $handleError $done
label handleError "handle.error"
set limitVar [my alloc int]
set name [$api Tcl_GetStringFromObj $procName $limitVar]
SetValueName $name "name"
set limit [Const 60]
set nameLen [my load $limitVar "name.len"]
set overflow [my gt $nameLen $limit]
$api Tcl_AppendObjToErrorInfo $interp [$api Tcl_ObjPrintf \
[my constString "\n (procedure \"%.*s%s\" line %d)"] \
[my select $overflow $limit $nameLen] $name \
[my select $overflow [my constString "..."] \
[my constString ""]] \
[my dereference $interp 0 Interp.errorLine]]
my br $done
label handleReturn "handle.return"
my ret [$api TclUpdateReturnInfo $interp]
label handleBreak "handle.leaked.break"
$api Tcl_SetObjResult $interp [$api Tcl_ObjPrintf \
[my constString "invoked \"%s\" outside of a loop"] \
[my constString "break"]]
$api Tcl_SetObjErrorCode $interp \
[$api obj.constant {TCL RESULT UNEXPECTED}]
my ret [Const 1]
label handleContinue "handle.leaked.continue"
$api Tcl_SetObjResult $interp [$api Tcl_ObjPrintf \
[my constString "invoked \"%s\" outside of a loop"] \
[my constString "continue"]]
$api Tcl_SetObjErrorCode $interp \
[$api obj.constant {TCL RESULT UNEXPECTED}]
my ret [Const 1]
label done:
my ret $code
}
##### Function tcl.logCommandInfo #####
#
# Type signature: code:int * length:int * command:char*
# * ellipsis:char* -> void
#
# Builds the current entry in the errorInfo trace if the code is
# TCL_ERROR. Note that most of the arguments to this function are
# expected to be values that our caller will compute at compile time.
set f [$m local "tcl.logCommandInfo" void<-int,int,char*,char*]
params code length command ellipsis
build {
nonnull $command $ellipsis
set ERR_ALREADY_LOGGED [Const 4]
set interp [$api tclInterp]
set flagVar [my gep $interp 0 Interp.flags]
set flags [my load $flagVar "flags"]
my condBr [my eq $code [Const 1]] $checkForLog $done
label checkForLog "check.for.log.error"
my condBr [my eq [my and $flags $ERR_ALREADY_LOGGED] [Const 0]] \
$logError $done
label logError "log.error"
set initText [my select [my nonnull \
[my dereference $interp 0 Interp.errorInfo]] \
[my constString "invoked from within"] \
[my constString "while executing"]]
$api Tcl_AppendObjToErrorInfo $interp [
$api Tcl_ObjPrintf [my constString "\n %s\n\"%.*s%s\""] \
$initText $length $command $ellipsis]
# TODO: update the errorStack as well...
# $api Tcl_LogCommandInfo $interp {} {} [Const 0]
my br $done
label done:
my store [my and $flags [my not $ERR_ALREADY_LOGGED]] $flagVar
my ret
}
##### Function tcl.setErrorLine #####
#
# Type signature: test:bool * code:int * line:int * length:int
# * command:char* * ellipsis:char* -> void
#
# Sets the current errorLine if the test is true and builds the
# current entry in the errorInfo trace if necessary. Note that most of
# the arguments to this function are expected to be values that our
# caller will compute at compile time.
set f [$m local "tcl.setErrorLine" void<-bool,int,int,int,char*,char*]
params test code line length command ellipsis
build {
nonnull $command $ellipsis
my condBr $test $setLine $done
label setLine "set.error.line"
set interp [$api tclInterp]
my store $line [my gep $interp 0 Interp.errorLine]
my Call tcl.logCommandInfo $code $length $command $ellipsis
my br $done
label done:
my ret
}
##### Function tcl.booleanTest #####
#
# Type signature: objPtr:Tcl_Obj* -> ZEROONE
#
# Part of quadcode implementation ('isBoolean')
#
|
︙ | | |
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
|
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
|
-
+
-
+
|
nonnull $objv $ecvar
set interp [$api tclInterp]
set code [$api Tcl_EvalObjv $interp $objc $objv $0]
my condBr [my eq $code $0] $ok $fail
label ok:
set result [$api Tcl_GetObjResult $interp]
my addReference(STRING) $result
my ret [my just $result]
my ret [my ok $result]
label fail:
my store $code $ecvar
my ret [my nothing STRING]
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.
|
︙ | | |
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
|
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
|
-
-
+
+
-
+
|
noalias $ecvar
nonnull $value $ecvar
set interp [$api tclInterp]
set bvar [my alloc int]
set code [$api Tcl_GetBooleanFromObj $interp $value $bvar]
my condBr [my eq $code [Const 0]] $ok $fail
label fail:
my store $code $ecvar
my ret [my nothing ZEROONE]
my store [Const 1] $ecvar
my ret [my fail ZEROONE]
label ok:
my ret [my just [my neq [my load $bvar "bool"] [Const 1]]]
my ret [my ok [my neq [my load $bvar "bool"] [Const 1]]]
}
my @variableFunctions $api
my @numericConverterFunctions $api
##### Function: tcl.resolveCmd #####
#
|
︙ | | |
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
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
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
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
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
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
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
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
|
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
|
-
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
label notAliased:
my br $done
label done:
set finalCmdPtr [my phi [list $origCmdPtr $cmdPtr] \
[list $aliased $notAliased]]
$api Tcl_GetCommandFullName $interp $finalCmdPtr $result
my addReference(STRING) $result
my ret [my just $result]
my ret [my ok $result]
label notResolved:
my dropReference(STRING) $result
$api Tcl_SetObjResult $interp \
[$api Tcl_ObjPrintf \
[my constString "invalid command name \"%s\""] \
[$api Tcl_GetString $cmdName]]
$api Tcl_SetErrorCode $interp \
[my constString TCL] [my constString LOOKUP] \
[my constString COMMAND] [$api Tcl_GetString $cmdName] \
[my null char*]
my store $1 $ecvar
my ret [my nothing STRING]
my ret [my fail STRING]
}
my CallFrameFunctions $api
}
# Builder:@variableFunctions --
#
# Generate the quadcode operator implementations that access Tcl
# variables.
#
# Parameters:
# api - The handle of the Tcl API object (currently an instance of the
# Thunk class).
#
# Results:
# None.
method @variableFunctions {api} {
set 0 [Const 0]
set 1 [Const 1]
set ARRAY [Const 0x1]
set LINK [Const 0x2]
set ARRAY_OR_LINK [Const 0x3]
set NSGLBL [Const [expr {0x1 | 0x2}]]
set APPEND_VALUE [Const 0x04]
set IN_HASHTABLE [Const 0x04]
set LIST_ELEMENT [Const 0x08]
set DEAD_HASH [Const 0x8]
set TRACED_READS [Const 0x10]
set TRACED_WRITES [Const 0x20]
set TRACED_UNSETS [Const 0x40]
set NAMESPACE_VAR [Const 0x80]
set LEAVE_ERR_MSG [Const 0x200]
set TRACED_ARRAY [Const 0x800]
set TRACED_ALL [Const 0x870]
set ARRAY_ELEMENT [Const 0x1000]
set TRACE_ACTIVE [Const 0x2000]
set SEARCH_ACTIVE [Const 0x4000]
set ALL_HASH [Const 0x108c]
##### Function tcl.getornull #####
#
# Convenience helper, that converts a NULL Tcl_Obj* to a NULL char*,
# and otherwise returns the string content of the Tcl_Obj*.
set f [$m local tcl.getornull char*<-Tcl_Obj*]
params objPtr
build {
my condBr [my nonnull $objPtr] $realObj $nullObj
label nullObj:
my ret [my null char*]
label realObj:
my ret [$api Tcl_GetString $objPtr]
}
##### Function var.value #####
#
# Get the value stored in a Tcl variable
set f [$m local var.value Tcl_Obj*<-Var* readonly]
params varPtr
build {
nonnull $varPtr
my ret [my dereference $varPtr 0 Var.value]
}
##### Function var.defined #####
#
# Test if the Tcl variable has a value.
set f [$m local var.defined int1<-Var* readonly]
params varPtr
build {
nonnull $varPtr
my ret [my nonnull [my Call var.value $varPtr]]
}
##### Function var.value.set #####
#
# Set the value stored in a Tcl variable
set f [$m local var.value.set void<-Var*,Tcl_Obj*]
params varPtr valuePtr
build {
nonnull $varPtr
set ptr [my gep $varPtr 0 Var.value]
my store $valuePtr $ptr
my ret
}
##### Function var.value.set.undefined #####
#
# Mark a variable as being undefined.
set f [$m local var.value.set.undefined void<-Var*]
params varPtr
build {
nonnull $varPtr
set ref [my gep $varPtr 0 Var.flags]
my store [my and [my load $ref] [my not $ARRAY_OR_LINK]] $ref
my store [my null Tcl_Obj*] [my gep $varPtr 0 Var.value]
my ret
}
##### Function var.table #####
#
# Get the variable lined to from a Tcl variable
set f [$m local var.table VarHashTable*<-Var* readonly]
params varPtr
build {
nonnull $varPtr
set value [my dereference $varPtr 0 Var.value]
my ret [my cast(ptr) $value VarHashTable "table"]
}
##### Function var.link #####
#
# Get the variable lined to from a Tcl variable
set f [$m local var.link Var*<-Var* readonly]
params varPtr
build {
nonnull $varPtr
set value [my dereference $varPtr 0 Var.value]
my ret [my cast(ptr) $value Var "link"]
}
##### Function var.flag #####
#
# Test if any of the given flag bits are set on a Tcl variable
set f [$m local var.flag int1<-Var*,int readonly]
params varPtr flag
build {
nonnull $varPtr
set flags [my dereference $varPtr 0 Var.flags]
my ret [my neq [my and $flags $flag] $0]
}
##### Function var.flag.set #####
#
# Set the given flag bits on a Tcl variable
set f [$m local var.flag.set void<-Var*,int]
params varPtr flag
build {
nonnull $varPtr
set ref [my gep $varPtr 0 Var.flags]
my store [my or [my load $ref] $flag] $ref
my ret
}
##### Function var.flag.clear #####
#
# Clear the given flag bits on a Tcl variable
set f [$m local var.flag.clear void<-Var*,int]
params varPtr flag
build {
nonnull $varPtr
set ref [my gep $varPtr 0 Var.flags]
my store [my and [my load $ref] [my not $flag]] $ref
my ret
}
##### Function var.isScalar #####
#
# Test if a Tcl variable is a scalar (not array or link)
set f [$m local var.isScalar int1<-Var*]
params varPtr
build {
nonnull $varPtr
my ret [my not [my Call var.flag $varPtr $ARRAY_OR_LINK]]
}
##### Function var.isArray #####
#
# Test if a Tcl variable is an array
set f [$m local var.isArray int1<-Var*]
params varPtr
build {
nonnull $varPtr
my ret [my Call var.flag $varPtr $ARRAY]
}
##### Function var.isLink #####
#
# Test if a Tcl variable is a link to another variable
set f [$m local var.isLink int1<-Var*]
params varPtr
build {
nonnull $varPtr
my ret [my Call var.flag $varPtr $LINK]
}
##### Function var.isArrayElement #####
#
# Test if a Tcl variable is an array element
set f [$m local var.isArrayElement int1<-Var*]
params varPtr
build {
nonnull $varPtr
my ret [my Call var.flag $varPtr $ARRAY_ELEMENT]
}
##### Function var.hasSearch #####
#
# Test if a Tcl variable has an array search running over it
set f [$m local var.hasSearch int1<-Var*]
params varPtr
build {
nonnull $varPtr
my ret [my Call var.flag $varPtr $SEARCH_ACTIVE]
}
##### Function var.isTraced #####
#
# Test if a Tcl variable is traced at all
set f [$m local var.isTraced int1<-Var*]
params varPtr
build {
nonnull $varPtr
my ret [my Call var.flag $varPtr $TRACED_ALL]
}
##### Function var.isTraced.read #####
#
# Test if a Tcl variable has read traces
set f [$m local var.isTraced.read int1<-Var*]
params varPtr
build {
nonnull $varPtr
my ret [my Call var.flag $varPtr $TRACED_READS]
}
##### Function var.isTraced.write #####
#
# Test if a Tcl variable has write traces
set f [$m local var.isTraced.write int1<-Var*]
params varPtr
build {
nonnull $varPtr
my ret [my Call var.flag $varPtr $TRACED_WRITES]
}
##### Function var.isTraced.unset #####
#
# Test if a Tcl variable has unset traces
set f [$m local var.isTraced.unset int1<-Var*]
params varPtr
build {
nonnull $varPtr
my ret [my Call var.flag $varPtr $TRACED_UNSETS]
}
##### Function var.isTraced.array #####
#
# Test if a Tcl array has whole-array-level traces
set f [$m local var.isTraced.array int1<-Var*]
params varPtr
build {
nonnull $varPtr
my ret [my Call var.flag $varPtr $TRACED_ARRAY]
}
##### Function var.isInHash #####
#
# Test if a Tcl variable is stored in a hash table
set f [$m local var.isInHash int1<-Var*]
params varPtr
build {
nonnull $varPtr
my ret [my Call var.flag $varPtr $IN_HASHTABLE]
}
##### Function var.hash.refCount #####
#
# Get a pointer to the reference count for a variable in a hash table.
# MUST ONLY BE CALLED IF THE VARIABLE IS IN A HASH.
set f [$m local var.hash.refCount int*<-Var* readonly]
params varPtr
build {
nonnull $varPtr
set varPtr [my cast(ptr) $varPtr VarInHash "varPtr"]
my ret [my gep $varPtr 0 VarInHash.refCount]
}
##### Function var.hash.invalidateEntry #####
#
# Mark a variable in a hash table as being invalid. MUST ONLY BE
# CALLED IF THE VARIABLE IS IN A HASH.
set f [$m local var.hash.invalidateEntry void<-Var*]
params varPtr
build {
nonnull $varPtr
my Call var.flag.set $varPtr $DEAD_HASH
my ret
}
##### Function var.hash.clearNamespaceVar #####
#
# Mark a variable in a namespace as no longer being so. MUST ONLY BE
# CALLED IF THE VARIABLE IS IN A HASH.
set f [$m local var.clearNamespaceVar void<-Var*]
params varPtr
build {
my condBr [my Call var.flag $varPtr $NAMESPACE_VAR] \
$2 $done
label 2:
my Call var.flag.clear $varPtr $NAMESPACE_VAR
my condBr [my Call var.isInHash $varPtr] \
$3 $done
label 3:
set ref [my call ${var.hash.refCount} $varPtr]
my store [my sub [my load $ref] $1] $ref
my br $done
label done:
my ret
}
##### Function var.hash.getKey #####
#
# Get a pointer to the key of an element of a hash table. MUST ONLY BE
# CALLED IF THE VARIABLE IS IN A HASH.
set f [$m local var.hash.getKey Tcl_Obj*<-Var* readonly]
params varPtr
build {
nonnull $varPtr
set var [my cast(ptr) $varPtr VarInHash "varPtr"]
set entry [my gep $var 0 VarInHash.entry]
set key [my dereference $entry 0 HashEntry.key]
my ret [my cast(ptr) $key Tcl_Obj "objPtr"]
}
##### Function var.hash.getValue #####
#
# Get a pointer to the variable in a hash table from its hash entry.
# MUST ONLY BE CALLED IF THE VARIABLE IS IN A HASH.
set f [$m local var.hash.getValue Var*<-HashEntry* readonly]
params hPtr
build {
nonnull $hPtr
set ptr [my cast(ptr) $hPtr char "ptr"]
set offset [my neg [my offsetof VarInHash entry]]
set ptr [my getelementptr $ptr [list $offset] "ptr"]
my ret [my cast(ptr) $ptr Var "var"]
}
##### Function var.hash.delete #####
#
# Delete a hash table that is inside a variable (i.e., where that
# variable is an array). MUST ONLY BE CALLED IF THE VARIABLE IS AN
# ARRAY AND IF THE CONTENTS HAVE BEEN DELETED.
set f [$m local var.hash.delete void<-Var*]
params varPtr
build {
nonnull $varPtr
set tablePtr [my Call var.table $varPtr]
set table [my gep $tablePtr 0 VarHashTable.table]
$api Tcl_DeleteHashTable $table
$api ckfree $tablePtr
my ret
}
##### Function var.hash.firstVar #####
#
# Get a pointer to the first variable in a hash table. MUST ONLY BE
# CALLED IF THE VARIABLE IS IN A HASH.
set f [$m local var.hash.firstVar Var*<-VarHashTable*,HashSearch*]
params tablePtr searchPtr
build {
nonnull $tablePtr $searchPtr
set table [my gep $tablePtr 0 VarHashTable.table]
set hPtr [$api Tcl_FirstHashEntry $table $searchPtr]
SetValueName $hPtr "hPtr"
my condBr [my nonnull $hPtr] $yes $no
label yes:
my ret [my Call var.hash.getValue $hPtr]
label no:
my ret [my null Var*]
}
##### Function var.hash.nextVar #####
#
# Get a pointer to the next variable in a hash table. MUST ONLY BE
# CALLED IF THE VARIABLE IS IN A HASH.
set f [$m local var.hash.nextVar Var*<-HashSearch*]
params searchPtr
build {
nonnull $searchPtr
set hPtr [$api Tcl_NextHashEntry $searchPtr]
SetValueName $hPtr "hPtr"
my condBr [my nonnull $hPtr] $yes $no
label yes:
my ret [my Call var.hash.getValue $hPtr]
label no:
my ret [my null Var*]
}
##### Function var.isDeadHash #####
#
# Test if a Tcl variable is a dead member of a hash table
set f [$m local var.isDeadHash int1<-Var* readonly]
params varPtr
build {
nonnull $varPtr
my ret [my Call var.flag $varPtr $DEAD_HASH]
}
##### Function var.readerr #####
#
# Support function for tcl.read.var.ptr
set f [$m local var.readerr char*<-Var*,Var* readonly]
params varPtr arrayPtr
build {
nonnull $varPtr
my condBr [my and \
[my not [my Call var.defined $varPtr]] \
[my nonnull $arrayPtr]] \
$testDefinedArray $testArray
label testDefinedArray:
my condBr [my Call var.defined $arrayPtr] \
$noSuchElement $testArray
label testArray:
my condBr [my Call var.flag $varPtr $1] \
$isArray $noSuchVar
label noSuchElement:
my ret [my constString "no such element in array" "noSuchElement"]
label isArray:
my ret [my constString "variable is array" "isArray"]
label noSuchVar:
my ret [my constString "no such variable" "noSuchVar"]
}
##### Function tcl.read.var.ptr #####
#
# Replica of TclPtrGetVar, except without index parameter.
set f [$m local tcl.read.var.ptr \
Tcl_Obj*<-Interp*,Var*,Var*,Tcl_Obj*,Tcl_Obj*,int]
params interp varPtr arrayPtr part1Ptr part2Ptr flags
build {
nonnull $interp $varPtr $part1Ptr
my condBr [my expect [my Call var.isTraced.read $varPtr] false] \
$callTraces $test2
label test2:
my condBr [my nonnull $arrayPtr] $test3 $testDirect
label test3:
my condBr [my expect [my Call var.isTraced.read $arrayPtr] false] \
$callTraces $testDirect
label callTraces:
set code [$api TclCallVarTraces $interp $arrayPtr $varPtr \
[$api Tcl_GetString $part1Ptr] \
[my Call tcl.getornull $part2Ptr] \
[my or [my and $flags $NSGLBL] $TRACED_READS] \
[my and $flags $LEAVE_ERR_MSG]]
my condBr [my expect [my eq $code $0] true] \
$testDirect $errorReturn
label testDirect:
my condBr [my and \
[my expect [my Call var.isScalar $varPtr] true] \
[my expect [my Call var.defined $varPtr] true]] \
$direct $readFail
label direct:
my ret [my Call var.value $varPtr]
label readFail:
my condBr [my eq [my and $flags $LEAVE_ERR_MSG] $0] \
$errorReturn $generateError
label generateError "generate.error"
set msg [my Call var.readerr $varPtr $arrayPtr]
SetValueName $msg "msg"
$api TclVarErrMsg $interp [$api Tcl_GetString $part1Ptr] \
[my Call tcl.getornull $part2Ptr] \
[my constString "read"] $msg
my br $errorReturn
label errorReturn:
$api Tcl_SetObjErrorCode $interp \
[$api obj.constant {TCL READ VARNAME}]
my condBr [my Call var.defined $varPtr] \
$cleanupErrorReturn $doneError
label cleanupErrorReturn:
$api TclCleanupVar $varPtr $arrayPtr
my br $doneError
label doneError:
my ret [my null Tcl_Obj*]
}
##### Function set.by.append.element #####
#
# Helper for tcl.write.var.ptr
set f [$m local set.by.append.element \
int1<-Interp*,Var*,Tcl_Obj*,Tcl_Obj*]
params interp var oldValue newValue
build {
my condBr [my nonnull $oldValue] \
$update $initial
label initial:
set vp1 [$api Tcl_NewObj]
SetValueName $vp1 "oldValue"
my Call var.value.set $var $vp1
$api Tcl_IncrRefCount $vp1
my br $append
label update:
my condBr [my shared $oldValue] \
$unshare $append
label unshare:
set vp2 [$api Tcl_DuplicateObj $oldValue]
SetValueName $vp2 "oldValue"
my Call var.value.set $var $vp2
$api Tcl_DecrRefCount $oldValue
$api Tcl_IncrRefCount $vp2
my br $append
label append:
set origins [list $initial $unshare $update]
set vp [my phi [list $vp1 $vp2 $oldValue] $origins "oldValue"]
set result [$api Tcl_ListObjAppendElement $interp $vp $newValue]
my ret [my eq $result $0]
}
##### Function set.copy.continuations #####
#
# Helper for tcl.write.var.ptr; TclContinuationsCopy by another name
set f [$m local set.copy.continuations void<-Tcl_Obj*,Tcl_Obj*]
params to from
build {
# FIXME: Cannot make this work from here! Requires access to
# internal variables of tclObj.c.
my ret
}
##### Function set.by.append.string #####
#
# Helper for tcl.write.var.ptr
set f [$m local set.by.append.string void<-Var*,Tcl_Obj*,Tcl_Obj*]
params var oldValue newValue
build {
# We append newValuePtr's bytes but don't change its ref count.
my condBr [my nonnull $oldValue] \
$update $initial
label initial:
my Call var.value.set $var $newValue
$api Tcl_IncrRefCount $newValue
my br $done
label update:
my condBr [my shared $oldValue] \
$unshare $append
label unshare:
set vp1 [$api Tcl_DuplicateObj $oldValue]
SetValueName $vp1 "oldValue"
my Call var.value.set $var $vp1
my Call set.copy.continuations $vp1 $oldValue
$api Tcl_DecrRefCount $oldValue
$api Tcl_IncrRefCount $vp1
my br $append
label append:
set origins [list $unshare $update]
set vp [my phi [list $vp1 $oldValue] $origins "oldValue"]
$api Tcl_AppendObjToObj $vp $newValue
my condBr [my eq [my refCount $newValue] $0] \
$dropRef $done
label dropRef "dropReference"
$api Tcl_DecrRefCount $newValue
my br $done
label done:
my ret
}
##### Function set.direct #####
#
# Helper for tcl.write.var.ptr
set f [$m local set.direct void<-Var*,Tcl_Obj*,Tcl_Obj*]
params var oldValue newValue
build {
my condBr [my eq $newValue $oldValue] \
$done $replace
label replace:
# In this case we are replacing the value, so we don't need to do
# more than swap the objects.
my Call var.value.set $var $newValue
$api Tcl_IncrRefCount $newValue
my condBr [my nonnull $oldValue] \
$dropRef $done
label dropRef "dropReference"
$api Tcl_DecrRefCount $oldValue
my br $done
label done:
my ret
}
##### Function tcl.write.var.ptr #####
#
# Replica of TclPtrSetVar, except without index parameter.
set f [$m local tcl.write.var.ptr \
Tcl_Obj*<-Interp*,Var*,Var*,Tcl_Obj*,Tcl_Obj*,Tcl_Obj*,int]
params interp varPtr arrayPtr part1Ptr part2Ptr newValuePtr flags
build {
nonnull $interp $varPtr $part1Ptr $newValuePtr
set nullResultPtr [my null Tcl_Obj*]
set cleanupOnEarlyError \
[my eq [my refCount $newValuePtr] $0 "cleanupOnEarlyError"]
# If the variable is in a hashtable and its hPtr field is NULL,
# then we may have an upvar to an array element where the array
# was deleted or an upvar to a namespace variable whose namespace
# was deleted. Generate an error (allowing the variable to be
# reset would screw up our storage allocation and is meaningless
# anyway).
my condBr [my expect [my Call var.isDeadHash $varPtr] false] \
$deadHash $test2
# It's an error to try to set an array variable itself.
label test2:
my condBr [my expect [my Call var.isArray $varPtr] false] \
$setArray $test3
# Invoke any read traces that have been set for the variable if it
# is requested. This was done for INST_LAPPEND_* but that was
# inconsistent with the non-bc instruction, and would cause
# failures trying to lappend to any non-existing ::env var, which
# is inconsistent with documented behavior. [Bug #3057639].
label test3:
my condBr [my eq [my and $flags $TRACED_READS] $0] \
$doWrite $test4
label test4:
my condBr [my expect [my Call var.isTraced.read $varPtr] false] \
$callReadTraces $test5
label test5:
my condBr [my nonnull $arrayPtr] $test6 $doWrite
label test6:
my condBr [my expect [my Call var.isTraced.read $arrayPtr] false] \
$callReadTraces $doWrite
label callReadTraces:
set code [$api TclCallVarTraces $interp $arrayPtr $varPtr \
[$api Tcl_GetString $part1Ptr] \
[my Call tcl.getornull $part2Ptr] \
$TRACED_READS [my and $flags $LEAVE_ERR_MSG]]
my condBr [my expect [my eq $code $0] true] $doWrite $earlyError
# Set the variable's new value. If appending, append the new value
# to the variable, either as a list element or as a string. Also,
# if appending, then if the variable's old value is unshared we
# can modify it directly, otherwise we must create a new copy to
# modify: this is "copy on write".
label doWrite:
set oldValuePtr [my Call var.value $varPtr]
SetValueName $oldValuePtr "oldValuePtr"
my condBr [my and [my neq [my and $flags $LIST_ELEMENT] $0] \
[my eq [my and $flags $APPEND_VALUE] $0]] \
$clearValue $checkAppend
label clearValue:
my Call var.value.set $varPtr [my null Tcl_Obj*]
my br $checkAppend
label checkAppend:
my condBr [my neq [my and $flags [Const [expr {0x4|0x8}]]] $0] \
$setByAppend $setDirect
label setByAppend "set.by.append"
my condBr [my neq [my and $flags $LIST_ELEMENT] $0] \
$setByAppendElement $setByAppendString
label setByAppendElement "set.by.append.element"
my condBr [my Call set.by.append.element $interp $varPtr \
$oldValuePtr $newValuePtr] \
$testWriteTraces $earlyError
label setByAppendString "set.by.append.string"
my Call set.by.append.string $varPtr $oldValuePtr $newValuePtr
my br $testWriteTraces
label setDirect "set.direct"
my Call set.direct $varPtr $oldValuePtr $newValuePtr
my br $testWriteTraces
# Invoke any write traces for the variable.
label testWriteTraces:
my condBr [my Call var.isTraced.write $varPtr] \
$callWriteTraces $test7
label test7:
my condBr [my nonnull $arrayPtr] \
$test8 $testFastReturn
label test8:
my condBr [my Call var.isTraced.write $arrayPtr] \
$callWriteTraces $testFastReturn
label callWriteTraces:
set code [$api TclCallVarTraces $interp $arrayPtr $varPtr \
[$api Tcl_GetString $part1Ptr] \
[my Call tcl.getornull $part2Ptr] \
[my or [my and $flags $NSGLBL] $TRACED_WRITES] \
[my and $flags $LEAVE_ERR_MSG]]
my condBr [my expect [my eq $code $0] true] \
$testFastReturn $cleanup
# Return the variable's value unless the variable was changed in
# some gross way by a trace (e.g. it was unset and then recreated
# as an array).
label testFastReturn:
my condBr [my expect [my Call var.isScalar $varPtr] true] \
$test9 $slowReturn
label test9:
my condBr [my expect [my Call var.defined $varPtr] true] \
$fastReturn $slowReturn
label fastReturn:
my ret [my Call var.value $varPtr]
# A trace changed the value in some gross way. Return an empty
# string object.
label slowReturn:
set resultPtr [my dereference $interp 0 Interp.emptyObjPtr]
my br $cleanup
# Report problems when a variable is in the process of being
# deleted or when it is really an array.
label deadHash:
my condBr [my eq [my and $flags $LEAVE_ERR_MSG] $0] \
$earlyError $test10
label test10:
my condBr [my Call var.isArrayElement $varPtr] \
$deadHashElem $deadHashVar
label deadHashElem "deadHash.danglingElement"
set msg1 [my constString "upvar refers to element in deleted array" "danglingElement"]
$api Tcl_SetObjErrorCode $interp \
[$api obj.constant {TCL LOOKUP ELEMENT}]
my br $reportError
label deadHashVar "deadHash.danglingVariable"
set msg2 [my constString "upvar refers to variable in deleted namespace" "danglingVar"]
$api Tcl_SetObjErrorCode $interp \
[$api obj.constant {TCL LOOKUP VARNAME}]
my br $reportError
label setArray:
my condBr [my eq [my and $flags $LEAVE_ERR_MSG] $0] \
$earlyError $setArrayError
label setArrayError "setArray.error"
set msg3 [my constString "variable is array" "isArray"]
$api Tcl_SetObjErrorCode $interp \
[$api obj.constant {TCL WRITE ARRAY}]
my br $reportError
label reportError:
set origins [list $deadHashElem $deadHashVar $setArrayError]
set msg [my phi [list $msg1 $msg2 $msg3] $origins "msg"]
$api TclVarErrMsg $interp [$api Tcl_GetString $part1Ptr] \
[my Call tcl.getornull $part2Ptr] \
[my constString "set"] $msg
my br $earlyError
# Standard route for reporting problems prior to the set actually
# happening.
label earlyError:
my condBr $cleanupOnEarlyError \
$earlyErrorDropRef $earlyErrorDone
label earlyErrorDropRef "earlyError.dropReference"
$api Tcl_DecrRefCount $newValuePtr
my br $earlyErrorDone
label earlyErrorDone "earlyError.done"
my br $cleanup
# If the variable doesn't exist anymore and no-one's using it,
# then free up the relevant structures and hash table entries.
label cleanup:
set values [list $nullResultPtr $resultPtr $nullResultPtr]
set origins [list $callWriteTraces $slowReturn $earlyErrorDone]
set resultPtr [my phi $values $origins "resultPtr"]
my condBr [my nonnull $resultPtr] \
$cleanupErrorCode $test11
label cleanupErrorCode "cleanup.errorCode"
$api Tcl_SetObjErrorCode $interp \
[$api obj.constant {TCL WRITE VARNAME}]
my br $test11
label test11:
my condBr [my Call var.defined $varPtr] \
$cleanupDone $cleanupVar
label cleanupVar "cleanup.var"
$api TclCleanupVar $varPtr $arrayPtr
my br $cleanupDone
label cleanupDone "cleanup.done"
my ret $resultPtr
}
##### Function var.deleteSearches #####
#
# Replica of DeleteSearches.
set f [$m local var.deleteSearches void<-Interp*,Var*]
params interp varPtr
build {
nonnull $interp
my condBr [my nonnull $varPtr] $testBit $done
label testBit
my condBr [my Call var.hasSearch $varPtr] $deleteSearches $done
label deleteSearches "delete.searches"
set tablePtr [my gep $interp 0 Interp.varSearches]
set sPtr [$api TclFindHashEntry $tablePtr $varPtr]
SetValueName $sPtr "sPtr"
set store [my alloc ArraySearch*]
set value [$api Tcl_GetHashValue $sPtr ArraySearch*]
SetValueName $value "searchPtr"
my store $value $store
my br $loopTest
label loopTest "loop.test"
set search [my load $store "searchPtr"]
my condBr [my nonnull $search] $loopBody $loopDone
label loopBody "loop.body"
my store [my dereference $search 0 ArraySearch.nextPtr] $store
$api Tcl_DecrRefCount [my dereference $search 0 ArraySearch.name]
$api ckfree $search
my br $loopTest
label loopDone "loop.done"
my Call var.flag.clear $varPtr $SEARCH_ACTIVE
$api Tcl_DeleteHashEntry $sPtr
my br $done
label done:
my ret
}
##### Function var.eventuallyFreeTrace #####
#
# Wrapper round Tcl_EventuallyFree to coerce types right.
set f [$m local var.eventuallyFreeTrace void<-VarTrace*]
params trace
build {
nonnull $trace
set TCL_DYNAMIC [my castInt2Ptr [Const 3] func{void<-void*}*]
$api Tcl_EventuallyFree [my cast(ptr) $trace char] $TCL_DYNAMIC
my ret
}
##### Function tcl.unset.var.array #####
#
# Replica of DeleteArray, except without index parameter.
set f [$m local tcl.unset.var.array void<-Interp*,Tcl_Obj*,Var*,int]
params interp part1Ptr varPtr flags
build {
nonnull $interp $part1Ptr $varPtr
my Call var.deleteSearches $interp $varPtr
set search [my alloc HashSearch "search"]
set elPtr [my alloc Var* "elPtr"]
my store [my Call var.hash.firstVar \
[my Call var.table $varPtr] $search] $elPtr
my br $loopTest
label loopTest "loop.test"
set element [my load $elPtr "element"]
my condBr [my nonnull $element] $loopBody $loopDone
label loopBody "loop.body"
my condBr [my and [my Call var.isScalar $element] \
[my Call var.defined $element]] \
$clearContents $considerTraces
label clearContents "clear.element.contents"
$api Tcl_DecrRefCount [my Call var.value $element]
my Call var.value.set $element [my null Tcl_Obj*]
my br $considerTraces
# Lie about the validity of the hashtable entry. In this way the
# variables will be deleted by VarHashDeleteTable.
label considerTraces "consider.element.traces"
my Call var.hash.invalidateEntry $element
my condBr [my Call var.isTraced $element] \
$handleTraces $clearElement
label handleTraces "handle.element.traces"
my condBr [my Call var.isTraced.unset $element] \
$callTraces $squelchTraces
label callTraces "call.element.traces"
set elName [my Call var.hash.getKey $element]
my Call var.flag.clear $element $TRACE_ACTIVE
# NB: We know that elName is nonnull here
$api TclCallVarTraces $interp [my null Var*] $element \
[$api Tcl_GetString $part1Ptr] \
[$api Tcl_GetString $elName] \
$flags $0
my br $squelchTraces
label squelchTraces "squelch.element.traces"
set varTraces [my gep $interp 0 Interp.varTraces]
set tPtr [$api TclFindHashEntry $varTraces $element]
SetValueName $tPtr "tPtr"
set tracePtr [my alloc VarTrace* "tracePtr"]
set value [$api Tcl_GetHashValue $tPtr VarTrace*]
SetValueName $value "tracePtr"
my store $value $tracePtr
my br $squelchTracesTest
label squelchTracesTest "squelch.element.traces.test"
set trace [my load $tracePtr "trace"]
my condBr [my nonnull $trace] $squelchTracesBody $clearActives
label squelchTracesBody "squelch.element.traces.body"
my store [my dereference $trace 0 VarTrace.nextPtr] $tracePtr
my store [my null VarTrace*] [my gep $trace 0 VarTrace.nextPtr]
my Call var.eventuallyFreeTrace $trace
my br $squelchTracesTest
label clearActives "clear.element.traces.active"
$api Tcl_DeleteHashEntry $tPtr
my Call var.flag.clear $element $TRACED_ALL
set activePtr [my alloc ActiveVarTrace* "activePtr"]
my store [my dereference $interp 0 Interp.activeVarTracePtr] \
$activePtr
my br $clearActivesTest
label clearActivesTest "clear.element.traces.active.test"
set active [my load $activePtr "active"]
my condBr [my nonnull $active] $clearActivesBody $clearElement
label clearActivesBody "clear.element.traces.active.body"
set tracedVar [my dereference $active 0 ActiveVarTrace.varPtr]
my condBr [my eq $tracedVar $element] \
$clearActivesClear $clearActivesNext
label clearActivesClear "clear.element.traces.active.next"
my store [my null VarTrace*] \
[my gep $active 0 ActiveVarTrace.nextTracePtr]
my br $clearActivesNext
label clearActivesNext "clear.element.traces.active.next"
my store [my dereference $active 0 ActiveVarTrace.nextPtr] \
$activePtr
my br $clearActivesTest
label clearElement "clear.element"
my Call var.value.set.undefined $element
# Even though array elements are not supposed to be namespace
# variables, some combinations of [upvar] and [variable] may
# create such beasts - see [Bug 604239]. This is necessary to
# avoid leaking the corresponding Var struct, and is otherwise
# harmless.
my Call var.clearNamespaceVar $element
my br $loopNext
label loopNext "loop.next"
my store [my Call var.hash.nextVar $search] $elPtr
my br $loopTest
label loopDone "loop.done"
my Call var.hash.delete $varPtr
my ret
}
##### Function var.dispose.activetraces #####
#
# Helper for tcl.unset.var.struct to make that code simpler.
set f [$m local var.dispose.activetraces \
void<-Interp*,Var*,VarTrace*]
params interp varPtr tracePtr
build {
set store [my alloc VarTrace* "store"]
my store $tracePtr $store
my br $traceTest
label traceTest:
set trace [my load $store "trace"]
my condBr [my nonnull $trace] $traceBody $unlinkActive
label traceBody:
my store [my dereference $trace 0 VarTrace.nextPtr] $store
my store [my null VarTrace*] [my gep $trace 0 VarTrace.nextPtr]
my Call var.eventuallyFreeTrace $trace
my br $traceTest
label unlinkActive:
set store [my alloc ActiveVarTrace* "store"]
my store [my dereference $interp 0 Interp.activeVarTracePtr] \
$store
my br $activeTest
label activeTest:
set active [my load $store "activeTrace"]
my condBr [my nonnull $active] $activeBody $done
label activeBody:
set activeVar [my dereference $active 0 ActiveVarTrace.varPtr]
my condBr [my eq $activeVar $varPtr] $activeBody2 $activeNext
label activeBody2:
my store [my null VarTrace*] \
[my gep $active 0 ActiveVarTrace.nextTracePtr]
my br $activeNext
label activeNext:
my store [my dereference $active 0 ActiveVarTrace.nextPtr] \
$store
my br $activeTest
label done:
my ret
}
##### Function tcl.unset.var.struct #####
#
# Replica of UnsetVarStruct, except without index parameter.
set f [$m local tcl.unset.var.struct \
void<-Var*,Var*,Interp*,Tcl_Obj*,Tcl_Obj*,int]
params varPtr arrayPtr interp part1Ptr part2Ptr flags
build {
nonnull $varPtr $interp $part1Ptr
set dummyVar [my alloc Var "dummyVar"]
my br $ct1
label ct1 "computing.traced"
set t [my Call var.isTraced $varPtr]
my condBr $t $ct4 $ct2
label ct2 "check.array.for.traced"
my condBr [my nonnull $arrayPtr] \
$ct3 $ct4
label ct3 "check.array.for.traced"
set t2 [my Call var.isTraced.unset $arrayPtr]
my br $ct4
label ct4 "computed.traced"
set sources [list $ct1 $ct2 $ct3]
set traced [my phi [list $t $t $t2] $sources "traced"]
my Call var.deleteSearches $interp $arrayPtr
my Call var.deleteSearches $interp $varPtr
# The code below is tricky, because of the possibility that a
# trace function might try to access a variable being deleted. To
# handle this situation gracefully, do things in three steps:
# 1. Copy the contents of the variable to a dummy variable
# structure, and mark the original Var structure as undefined.
# 2. Invoke traces and clean up the variable, using the dummy
# copy.
# 3. If at the end of this the original variable is still
# undefined and has no outstanding references, then delete it
# (but it could have gotten recreated by a trace).
set dummy [my load $varPtr]
set dummy [my insert $dummy [my and [my not $ALL_HASH] \
[my extract $dummy Var.flags]] Var.flags]
my store $dummy $dummyVar
my Call var.value.set.undefined $varPtr
# Call trace functions for the variable being deleted. Then delete
# its traces. Be sure to abort any other traces for the variable
# that are still pending. Special tricks:
# 1. We need to increment varPtr's refCount around this:
# TclCallVarTraces will use dummyVar so it won't increment
# varPtr's refCount itself.
# 2. Turn off the VAR_TRACE_ACTIVE flag in dummyVar: we want to
# call unset traces even if other traces are pending.
my condBr $traced $processTraces $clearValues
label processTraces "process.traces"
set varTraces [my gep $interp 0 Interp.varTraces]
set traceActive [my alloc VarTrace*]
my store [my null VarTrace*] $traceActive
my condBr [my Call var.isTraced $dummyVar] \
$removeUnsetTraces $callUnsetTraces
# Transfer any existing traces on var, IF there are unset traces.
# Otherwise just delete them.
label removeUnsetTraces "remove.original.traces"
set tPtr [$api TclFindHashEntry $varTraces $varPtr]
SetValueName $tPtr "tPtr"
set tracePtr [$api Tcl_GetHashValue $tPtr VarTrace*]
SetValueName $tracePtr "tracePtr"
my store $tracePtr $traceActive
my Call var.flag.clear $varPtr $TRACED_ALL
$api Tcl_DeleteHashEntry $tPtr
my condBr [my Call var.isTraced.unset $dummyVar] \
$recreateUnsetTraces $callUnsetTracesCheck
label recreateUnsetTraces "recreate.unset.traces"
set tPtr [$api TclCreateHashEntry $varTraces $dummyVar]
SetValueName $tPtr "tPtr"
$api Tcl_SetHashValue $tPtr $tracePtr
my br $callUnsetTracesCheck
label callUnsetTracesCheck "call.unset.traces.check"
my condBr [my Call var.isTraced.unset $dummyVar] \
$callUnsetTraces $callUnsetTracesCheck2
label callUnsetTracesCheck2 "call.unset.traces.check"
my condBr [my nonnull $arrayPtr] \
$callUnsetTracesCheck3 $disposeActiveTraces
label callUnsetTracesCheck3 "call.unset.traces.check"
my condBr [my Call var.isTraced.unset $arrayPtr] \
$callUnsetTraces $disposeActiveTraces
label callUnsetTraces "call.unset.traces"
my Call var.flag.clear $dummyVar $TRACE_ACTIVE
$api TclCallVarTraces $interp $arrayPtr $dummyVar \
[$api Tcl_GetString $part1Ptr] \
[my Call tcl.getornull $part2Ptr] \
[my or [my and $flags $NSGLBL] $TRACED_UNSETS] $0
# The traces that we just called may have triggered a change in
# the set of traces. If so, reload the traces to manipulate.
my store [my null VarTrace*] $traceActive
my condBr [my Call var.isTraced $dummyVar] \
$refetchActive $disposeActiveTraces
label refetchActive "refetch.active.trace"
set tPtr [$api TclFindHashEntry $varTraces $dummyVar]
SetValueName $tPtr "tPtr"
my condBr [my nonnull $tPtr] \
$refetchActive2 $disposeActiveTraces
label refetchActive2 "refetch.active.trace"
set tracePtr [$api Tcl_GetHashValue $tPtr VarTrace*]
SetValueName $tracePtr "tracePtr"
my store $tracePtr $traceActive
$api Tcl_DeleteHashEntry $tPtr
my br $disposeActiveTraces
label disposeActiveTraces "dispose.active.traces"
set tracePtr [my load $traceActive "tracePtr"]
my condBr [my nonnull $tracePtr] $disposeClear $clearValues
label disposeClear "dispose.active.traces.clear"
my Call var.dispose.activetraces $interp $varPtr $tracePtr
my Call var.flag.clear $dummyVar $TRACED_ALL
my br $clearValues
label clearValues "clear.values"
my condBr [my and \
[my Call var.isScalar $dummyVar] \
[my Call var.defined $dummyVar]] \
$clearScalar $clearArrayTest
label clearScalar "clear.scalar"
$api Tcl_DecrRefCount [my Call var.value $dummyVar]
my br $clearNsVar
label clearArrayTest "clear.array.test"
my condBr [my Call var.isArray $dummyVar] \
$clearArray $clearLinkTest
label clearArray "clear.array"
# If the variable is an array, delete all of its elements. This
# must be done after calling and deleting the traces on the array,
# above (that's the way traces are defined). If the array name is
# not present and is required for a trace on some element, it will
# be computed at DeleteArray.
my Call tcl.unset.var.array $interp $part1Ptr $dummyVar \
[my or [my and $flags $NSGLBL] $TRACED_UNSETS]
my br $clearNsVar
label clearLinkTest "clear.link.test"
my condBr [my Call var.isLink $dummyVar] \
$clearLink $clearNsVar
label clearLink "clear.link"
# For global/upvar variables referenced in procedures, decrement
# the reference count on the variable referred to, and free the
# referenced variable if it's no longer needed.
set linked [my Call var.link $dummyVar]
SetValueName $linked "linkedVarPtr"
my condBr [my Call var.isInHash $linked] \
$cleanLinked $clearNsVar
label cleanLinked "clean.linked.variable"
set rcref [my Call var.hash.refCount $linked]
my store [my sub [my load $rcref] $1] $rcref
$api TclCleanupVar $linked [my null Var*]
my br $clearNsVar
# If the variable was a namespace variable, decrement its
# reference count.
label clearNsVar "clear.namespace.var"
my Call var.clearNamespaceVar $varPtr
my ret
}
##### Function tcl.unset.var.ptr #####
#
# Replica of TclPtrUnsetVar, except without index parameter.
set f [$m local tcl.unset.var.ptr \
int<-Interp*,Var*,Var*,Tcl_Obj*,Tcl_Obj*,int]
params interp varPtr arrayPtr part1Ptr part2Ptr flags
build {
set result [my select [my Call var.defined $varPtr] $0 $1 "result"]
# Keep the variable alive until we're done with it. We used to
# increase/decrease the refCount for each operation, making it
# hard to find [Bug 735335] - caused by unsetting the variable
# whose value was the variable's name.
my condBr [my Call var.isInHash $varPtr] \
$addRef $uvs
label addRef "add.reference"
set rcref [my Call var.hash.refCount $varPtr]
my store [my add [my load $rcref] $1] $rcref
my br $uvs
label uvs "unset.var.struct"
my Call tcl.unset.var.struct $varPtr $arrayPtr $interp \
$part1Ptr $part2Ptr $flags
# It's an error to unset an undefined variable.
my condBr [my eq $result $0] \
$finalCleanup $handleError
label handleError "handle.error"
my condBr [my eq [my and $flags $LEAVE_ERR_MSG] $0] \
$finalCleanup $generateError
label generateError "generate.error"
set noSuchElement [my constString "no such element in array" "noSuchElement"]
set noSuchVar [my constString "no such variable" "noSuchVar"]
set msg [my select [my nonnull $arrayPtr] \
$noSuchElement $noSuchVar]
$api TclVarErrMsg $interp [$api Tcl_GetString $part1Ptr] \
[my Call tcl.getornull $part2Ptr] \
[my constString "unset"] $msg
$api Tcl_SetObjErrorCode $interp \
[$api obj.constant {TCL UNSET VARNAME}]
my br $finalCleanup
# Finally, if the variable is truly not in use then free up its
# Var structure and remove it from its hash table, if any. The ref
# count of its value object, if any, was decremented above.
label finalCleanup "final.cleanup"
my condBr [my Call var.isInHash $varPtr] \
$doCleanup $done
label doCleanup "cleanup"
set rcref [my Call var.hash.refCount $varPtr]
my store [my sub [my load $rcref] $1] $rcref
$api TclCleanupVar $varPtr $arrayPtr
my br $done
label done:
my ret $result
}
##### Function tcl.read.global.ns #####
#
# Type signature: ns:NAMESPACE * varname:STRING * ecvar:int*
# -> STRING?
#
# Reads from a global (or other namespace) variable.
set f [$m local tcl.read.global.ns STRING?<-Namespace*,STRING,int*]
params ns varname ecvar
build {
nonnull $ns $varname $ecvar
set interp [$api tclInterp]
set arrayPtr [my alloc Var*]
# save NS
set frameNsPtr [my gep \
[my dereference $interp 0 Interp.varFramePtr] \
0 CallFrame.nsPtr]
set savedNs [my load $frameNsPtr "savedNs"]
my store $ns $frameNsPtr
set var [$api TclObjLookupVar $interp $varname \
[my null char*] [Const [expr {2+0x200+0x40000}]] \
[my constString "access"] $1 $1 $arrayPtr]
# restore NS
my store $savedNs $frameNsPtr
my condBr [my expect [my nonnull $var] true] \
$gotVar $fail
label gotVar:
set result [my Call tcl.read.var.ptr $interp \
$var [my null Var*] $varname [my null Tcl_Obj*] \
$LEAVE_ERR_MSG]
my condBr [my expect [my nonnull $result] true] \
$gotValue $fail
label gotValue:
my addReference(STRING) $result
my ret [my just $result]
label fail:
my store $1 $ecvar
my ret [my nothing STRING]
}
##### Function tcl.read.global #####
#
# Type signature: ns:STRING * varname:STRING * ecvar:int* -> STRING?
#
# Reads from a global (or other namespace) variable.
set f [$m local tcl.read.global STRING?<-STRING,STRING,int*]
params nsname varname ecvar
build {
nonnull $nsname $varname $ecvar
set interp [$api tclInterp]
set nsptr [my alloc Namespace*]
set code [$api TclGetNamespaceFromObj $interp $nsname $nsptr]
my condBr [my expect [my eq $code $0] true] $gotNS $fail
label gotNS:
set ns [my load $nsptr]
my ret [my Call tcl.read.global.ns $ns $varname $ecvar]
label fail:
my store $1 $ecvar
my ret [my nothing STRING]
}
##### Function tcl.namespace.global #####
#
# Type signature: void -> NAMESPACE
#
# Gets the handle to the global namespace.
set f [$m local tcl.namespace.global Namespace*<-]
params
build {
set interp [$api tclInterp]
my ret [my dereference $interp 0 Interp.globalNsPtr]
}
##### Function tcl.namespace.current #####
#
# Type signature: void -> NAMESPACE
#
# Gets the handle to the current namespace.
set f [$m local tcl.namespace.current Namespace*<-]
params
build {
set interp [$api tclInterp]
set frame [my dereference $interp 0 Interp.varFramePtr]
my ret [my dereference $frame 0 CallFrame.nsPtr]
}
}
export @apiFunctions
}
# Local Variables:
# mode: tcl
# fill-column: 78
# auto-fill-function: nil
# buffer-file-coding-system: utf-8-unix
# End:
|
Changes to codegen/struct.tcl.
Changes to codegen/tclapi.tcl.
Changes to codegen/thunk.tcl.
Changes to codegen/tycon.tcl.
Added codegen/varframe.tcl.