aboutsummaryrefslogtreecommitdiff
path: root/internal/crt2/tcl.go
blob: 64f2da7a5f47ae7a4a04a04561cc9839e24b7317 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
// Copyright 2020 The Sqlite Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package crt2 // import "modernc.org/sqlite/internal/crt2"

import (
	"fmt"
	"os"
	"runtime"
	"strings"

	"modernc.org/crt/v3"
)

// const (
// 	TCL_GLOBAL_ONLY = 1
// )
//
// var (
// 	fToken           uint64
// 	nameOfExecutable string
// 	objects          = map[uintptr]objectNfo{}
// 	objectsMu        sync.Mutex
// )
//
// func nextToken() uintptr { return uintptr(atomic.AddUint64(&fToken, 1)) }
//
// type objectNfo struct {
// 	memcheckerNfo
// 	value interface{}
// }
//
// func addObject(o interface{}) uintptr {
// 	var v objectNfo
// 	v.value = o
// 	v.object = o
// 	v.pc, v.file, v.line, v.ok = runtime.Caller(1)
// 	h := nextToken()
// 	objectsMu.Lock()
// 	objects[h] = v
// 	objectsMu.Unlock()
// 	return h
// }
//
// func getObject(h uintptr) interface{} {
// 	if h <= 0 {
// 		panic(todo(""))
// 	}
//
// 	objectsMu.Lock()
// 	v, ok := objects[h]
// 	if !ok {
// 		panic(todo("", h))
// 	}
//
// 	objectsMu.Unlock()
// 	return v.value
// }
//
// func removeObject(h uintptr) {
// 	if h <= 0 {
// 		panic(todo(""))
// 	}
//
// 	objectsMu.Lock()
// 	if _, ok := objects[h]; !ok {
// 		panic(todo(""))
// 	}
//
// 	delete(objects, h)
// 	objectsMu.Unlock()
// }

func todo(s string, args ...interface{}) string { //TODO-
	switch {
	case s == "":
		s = fmt.Sprintf(strings.Repeat("%v ", len(args)), args...)
	default:
		s = fmt.Sprintf(s, args...)
	}
	pc, fn, fl, _ := runtime.Caller(1)
	f := runtime.FuncForPC(pc)
	var fns string
	if f != nil {
		fns = f.Name()
		if x := strings.LastIndex(fns, "."); x > 0 {
			fns = fns[x+1:]
		}
	}
	r := fmt.Sprintf("%s:%d:%s: TODOTODO %s", fn, fl, fns, s) //TODOOK
	fmt.Fprintf(os.Stdout, "%s\n", r)
	os.Stdout.Sync()
	return r
}

func trc(s string, args ...interface{}) string { //TODO-
	switch {
	case s == "":
		s = fmt.Sprintf(strings.Repeat("%v ", len(args)), args...)
	default:
		s = fmt.Sprintf(s, args...)
	}
	_, fn, fl, _ := runtime.Caller(1)
	r := fmt.Sprintf("\n%s:%d: TRC %s", fn, fl, s)
	fmt.Fprintf(os.Stdout, "%s\n", r)
	os.Stdout.Sync()
	return r
}

// int sched_yield(void);
func Xsched_yield(tls *crt.TLS) int32 {
	panic(todo(""))
}

// int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg);
func Xpthread_create(tls *crt.TLS, thread, attr, start_routine, arg uintptr) int32 {
	panic(todo(""))
}

// int pthread_detach(pthread_t thread);
func Xpthread_detach(tls *crt.TLS, thread crt.Size_t) int32 {
	panic(todo(""))
}

// int ferror(FILE *stream);
func Xferror(tls *crt.TLS, stream uintptr) int32 {
	panic(todo(""))
}

// // int ftruncate(int fd, off_t length);
// func Xftruncate(tls *crt.TLS, fd int32, length crt.Ssize_t) int32 {
// 	panic(todo(""))
// }

// int fstat(int fd, struct stat *statbuf);
func Xfstat(tls *crt.TLS, fd int32, statbuf uintptr) int32 {
	panic(todo(""))
}

// // int rename(const char *oldpath, const char *newpath);
// func Xrename(tls *crt.TLS, oldpath, newpath uintptr) int32 {
// 	panic(todo(""))
// }

// int pthread_mutex_lock(pthread_mutex_t *mutex);
func Xpthread_mutex_lock(tls *crt.TLS, mutex uintptr) int32 {
	panic(todo(""))
}

// int pthread_cond_signal(pthread_cond_t *cond);
func Xpthread_cond_signal(tls *crt.TLS, cond uintptr) int32 {
	panic(todo(""))
}

// int pthread_mutex_unlock(pthread_mutex_t *mutex);
func Xpthread_mutex_unlock(tls *crt.TLS, mutex uintptr) int32 {
	panic(todo(""))
}

// int pthread_mutex_init(pthread_mutex_t *restrict mutex, const pthread_mutexattr_t *restrict attr);
func Xpthread_mutex_init(tls *crt.TLS, mutex, attr uintptr) int32 {
	panic(todo(""))
}

// int pthread_cond_init(pthread_cond_t *restrict cond, const pthread_condattr_t *restrict attr);
func Xpthread_cond_init(tls *crt.TLS, cond, attr uintptr) int32 {
	panic(todo(""))
}

// int pthread_cond_wait(pthread_cond_t *restrict cond, pthread_mutex_t *restrict mutex);
func Xpthread_cond_wait(tls *crt.TLS, cond, mutex uintptr) int32 {
	panic(todo(""))
}

// int pthread_cond_destroy(pthread_cond_t *cond);
func Xpthread_cond_destroy(tls *crt.TLS, cond uintptr) int32 {
	panic(todo(""))
}

// // int stat(const char *pathname, struct stat *statbuf);
// func Xstat(tls *crt.TLS, pathname, statbuf uintptr) int32 {
// 	panic(todo(""))
// }
//
// // int lstat(const char *pathname, struct stat *statbuf);
// func Xlstat(tls *crt.TLS, pathname, statbuf uintptr) int32 {
// 	panic(todo(""))
// }
//
// // struct dirent *readdir(DIR *dirp);
// func Xreaddir(tls *crt.TLS, dirp uintptr) uintptr {
// 	panic(todo(""))
// }

// int pthread_mutex_destroy(pthread_mutex_t *mutex);
func Xpthread_mutex_destroy(tls *crt.TLS, mutex uintptr) int32 {
	panic(todo(""))
}

// // ============================================================================
//
// // void *malloc(size_t size);
// func Xmalloc(tls *crt.TLS, size crt.Size_t) uintptr {
// 	p := crt.Xmalloc(tls, size)
// 	if p != 0 {
// 		Memcheck.add(p, size)
// 	}
// 	return p
// }
//
// // void *calloc(size_t nmemb, size_t size);
// func Xcalloc(tls *crt.TLS, n, size crt.Size_t) uintptr {
// 	p := crt.Xcalloc(tls, n, size)
// 	if p != 0 {
// 		Memcheck.add(p, n*size)
// 	}
// 	return p
// }
//
// // void *realloc(void *ptr, size_t size);
// func Xrealloc(tls *crt.TLS, ptr uintptr, size crt.Size_t) uintptr {
// 	panic(todo(""))
// }
//
// // void free(void *ptr);
// func Xfree(tls *crt.TLS, ptr uintptr) {
// 	if ptr != 0 {
// 		Memcheck.remove(ptr)
// 	}
// 	crt.Xfree(tls, ptr)
// }
//
// // void abort(void);
// func Xabort(tls *crt.TLS) {
// 	Xexit(tls, 1)
// }
//
// // void exit(int status);
// func Xexit(tls *crt.TLS, status int32) {
// 	s := Memcheck.Audit()
// 	//trc("Memcheck.Audit(): %s", s)
// 	if s != "" && status == 0 {
// 		status = 1
// 	}
// 	fmt.Fprintln(os.Stderr, s)
// 	os.Stderr.Sync()
// 	crt.Xexit(tls, status)
// }
//
// func X__builtin_exit(tls *crt.TLS, status int32) { Xexit(tls, status) }
//
// // void __assert_fail(const char * assertion, const char * file, unsigned int line, const char * function);
// func X__assert_fail(tls *crt.TLS, assertion, file uintptr, line uint32, function uintptr) {
// 	fmt.Fprintf(os.Stderr, "assertion failure: %s:%d.%s: %s\n", crt.GoString(file), line, crt.GoString(function), crt.GoString(assertion))
// 	os.Stderr.Sync()
// 	Xexit(tls, 1)
// }
//
// // void __builtin_trap (void)
// func X__builtin_trap(tls *crt.TLS) {
// 	fmt.Fprintf(os.Stderr, "%s\ntrap\n", debug.Stack())
// 	os.Stderr.Sync()
// 	Xexit(tls, 1)
// }
//
// // void __builtin_unreachable (void)
// func X__builtin_unreachable(tls *crt.TLS) {
// 	fmt.Fprintf(os.Stderr, "%s\nunrechable\n", debug.Stack())
// 	os.Stderr.Sync()
// 	Xexit(tls, 1)
// }
//
// // ============================================================================
//
// // int Tcl_UnregisterChannel(Tcl_Interp *interp, Tcl_Channel chan);
// func XTcl_UnregisterChannel(tls *crt.TLS, interp, chan1 uintptr) int32 {
// 	panic(todo(""))
// }
//
// // void Tcl_Free(char *ptr);
// func XTcl_Free(tls *crt.TLS, ptr uintptr) {
// 	panic(todo(""))
// }
//
// // char * Tcl_Alloc(unsigned int size);
// func XTcl_Alloc(tls *crt.TLS, size uint32) uintptr {
// 	panic(todo(""))
// }
//
// // Tcl_Channel Tcl_CreateChannel(const Tcl_ChannelType *typePtr, const char *chanName, ClientData instanceData, int mask);
// func XTcl_CreateChannel(tls *crt.TLS, typePtr, chanName, instanceData uintptr, mask int32) uintptr {
// 	panic(todo(""))
// }
//
// // const char * Tcl_GetChannelName(Tcl_Channel chan);
// func XTcl_GetChannelName(tls *crt.TLS, chan1 uintptr) uintptr {
// 	panic(todo(""))
// }
//
// // char * Tcl_GetStringFromObj(Tcl_Obj *objPtr, int *lengthPtr);
// func XTcl_GetStringFromObj(tls *crt.TLS, objPtr, lengthPtr uintptr) uintptr {
// 	panic(todo(""))
// }
//
// // void Tcl_RegisterChannel(Tcl_Interp *interp, Tcl_Channel chan);
// func XTcl_RegisterChannel(tls *crt.TLS, interp, chan1 uintptr) {
// 	panic(todo(""))
// }
//
// // void Tcl_SetResult(Tcl_Interp *interp, char *result, Tcl_FreeProc *freeProc);
// func XTcl_SetResult(tls *crt.TLS, interp, result, freeProc uintptr) {
// 	panic(todo(""))
// }
//
// // void TclFreeObj(Tcl_Obj *objPtr);
// func XTclFreeObj(tls *crt.TLS, objPtr uintptr) {
// 	panic(todo(""))
// }
//
// // void Tcl_AppendResult(Tcl_Interp *interp, ...);
// func XTcl_AppendResult(tls *crt.TLS, interp, va uintptr) {
// 	panic(todo(""))
// }
//
// // void Tcl_BackgroundError(Tcl_Interp *interp);
// func XTcl_BackgroundError(tls *crt.TLS, interp uintptr) { panic(todo("")) }
//
// // Tcl_CreateInterp creates a new interpreter structure and returns a token for
// // it. The token is required in calls to most other Tcl procedures, such as
// // Tcl_CreateCommand, Tcl_Eval, and Tcl_DeleteInterp. The token returned by
// // Tcl_CreateInterp may only be passed to Tcl routines called from the same
// // thread as the original Tcl_CreateInterp call. It is not safe for multiple
// // threads to pass the same token to Tcl's routines. The new interpreter is
// // initialized with the built-in Tcl commands and with standard variables like
// // tcl_platform and env. To bind in additional commands, call
// // Tcl_CreateCommand, and to create additional variables, call Tcl_SetVar.
// //
// // Tcl_Interp * Tcl_CreateInterp(void);
// func XTcl_CreateInterp(tls *crt.TLS) uintptr {
// 	ctx := tee.NewContext("", false)
// 	if err := registerBuiltinCommands(ctx); err != nil {
// 		panic(todo("", err))
// 	}
//
// 	return addObject(ctx)
// }
//
// // Tcl_CreateObjCommand defines a new command in interp and associates it with
// // procedure proc such that whenever name is invoked as a Tcl command (e.g.,
// // via a call to Tcl_EvalObjEx) the Tcl interpreter will call proc to process
// // the command.
// //
// // Tcl_CreateObjCommand deletes any existing command name already associated
// // with the interpreter (however see below for an exception where the existing
// // command is not deleted). It returns a token that may be used to refer to the
// // command in subsequent calls to Tcl_GetCommandName. If name contains any ::
// // namespace qualifiers, then the command is added to the specified namespace;
// // otherwise the command is added to the global namespace. If
// // Tcl_CreateObjCommand is called for an interpreter that is in the process of
// // being deleted, then it does not create a new command and it returns NULL.
// // proc should have arguments and result that match the type Tcl_ObjCmdProc:
// //
// //	typedef int Tcl_ObjCmdProc(
// //	        ClientData clientData,
// //	        Tcl_Interp *interp,
// //	        int objc,
// //	        Tcl_Obj *const objv[]);
// //
// // When proc is invoked, the clientData and interp parameters will be copies of
// // the clientData and interp arguments given to Tcl_CreateObjCommand.
// // Typically, clientData points to an application-specific data structure that
// // describes what to do when the command procedure is invoked. Objc and objv
// // describe the arguments to the command, objc giving the number of argument
// // values (including the command name) and objv giving the values of the
// // arguments. The objv array will contain objc values, pointing to the argument
// // values. Unlike argv[argv] used in a string-based command procedure,
// // objv[objc] will not contain NULL.
// //
// // Additionally, when proc is invoked, it must not modify the contents of the
// // objv array by assigning new pointer values to any element of the array (for
// // example, objv[2] = NULL) because this will cause memory to be lost and the
// // runtime stack to be corrupted. The const in the declaration of objv will
// // cause ANSI-compliant compilers to report any such attempted assignment as an
// // error. However, it is acceptable to modify the internal representation of
// // any individual value argument. For instance, the user may call
// // Tcl_GetIntFromObj on objv[2] to obtain the integer representation of that
// // value; that call may change the type of the value that objv[2] points at,
// // but will not change where objv[2] points.
// //
// // proc must return an integer code that is either TCL_OK, TCL_ERROR,
// // TCL_RETURN, TCL_BREAK, or TCL_CONTINUE. See the Tcl overview man page for
// // details on what these codes mean. Most normal commands will only return
// // TCL_OK or TCL_ERROR. In addition, if proc needs to return a non-empty
// // result, it can call Tcl_SetObjResult to set the interpreter's result. In the
// // case of a TCL_OK return code this gives the result of the command, and in
// // the case of TCL_ERROR this gives an error message. Before invoking a command
// // procedure, Tcl_EvalObjEx sets interpreter's result to point to a value
// // representing an empty string, so simple commands can return an empty result
// // by doing nothing at all.
// //
// // The contents of the objv array belong to Tcl and are not guaranteed to
// // persist once proc returns: proc should not modify them. Call
// // Tcl_SetObjResult if you want to return something from the objv array.
// //
// // Ordinarily, Tcl_CreateObjCommand deletes any existing command name already
// // associated with the interpreter. However, if the existing command was
// // created by a previous call to Tcl_CreateCommand, Tcl_CreateObjCommand does
// // not delete the command but instead arranges for the Tcl interpreter to call
// // the Tcl_ObjCmdProc proc in the future. The old string-based Tcl_CmdProc
// // associated with the command is retained and its address can be obtained by
// // subsequent Tcl_GetCommandInfo calls. This is done for backwards
// // compatibility.
// //
// // DeleteProc will be invoked when (if) name is deleted. This can occur through
// // a call to Tcl_DeleteCommand, Tcl_DeleteCommandFromToken, or
// // Tcl_DeleteInterp, or by replacing name in another call to
// // Tcl_CreateObjCommand. DeleteProc is invoked before the command is deleted,
// // and gives the application an opportunity to release any structures
// // associated with the command. DeleteProc should have arguments and result
// // that match the type Tcl_CmdDeleteProc:
// //
// //	typedef void Tcl_CmdDeleteProc(
// //	        ClientData clientData);
// //
// // The clientData argument will be the same as the clientData argument passed
// // to Tcl_CreateObjCommand.
// //
// // Tcl_Command Tcl_CreateObjCommand(Tcl_Interp *interp, const char *cmdName, Tcl_ObjCmdProc *proc, ClientData clientData, Tcl_CmdDeleteProc *deleteProc);
// func XTcl_CreateObjCommand(tls *crt.TLS, interp, cmdName0, proc, clientData, deleteProc uintptr) uintptr {
// 	ctx := getObject(interp).(*tee.Context)
// 	if ctx.BeingDeleted {
// 		return 0
// 	}
//
// 	cmdName := crt.GoString(cmdName0)
// 	cmd, rc := ctx.Proc(
// 		tee.NewString(cmdName), tee.NewNoValue(), tee.NewNoValue(),
// 		func(ctx *tee.Context, values ...tee.Value) tee.ReturnCode {
// 			panic(todo(""))
// 		},
// 		func(cmd *tee.Command) error {
// 			panic(todo(""))
// 		},
// 		clientData,
// 	)
// 	if rc != tee.Ok {
// 		panic(todo(""))
// 	}
//
// 	return addObject(cmd)
// }
//
// // char * Tcl_DStringAppend(Tcl_DString *dsPtr, const char *bytes, int length);
// func XTcl_DStringAppend(tls *crt.TLS, dsPtr, bytes uintptr, length int32) uintptr { panic(todo("")) }
//
// // char * Tcl_DStringAppendElement(Tcl_DString *dsPtr, const char *element);
// func XTcl_DStringAppendElement(tls *crt.TLS, dsPtr, element uintptr) uintptr { panic(todo("")) }
//
// // void Tcl_DStringFree(Tcl_DString *dsPtr);
// func XTcl_DStringFree(tls *crt.TLS, dsPtr uintptr) { panic(todo("")) }
//
// // void Tcl_DStringInit(Tcl_DString *dsPtr);
// func XTcl_DStringInit(tls *crt.TLS, dsPtr uintptr) { panic(todo("")) }
//
// // int Tcl_DeleteCommand(Tcl_Interp *interp, const char *cmdName);
// func XTcl_DeleteCommand(tls *crt.TLS, interp, cmdName uintptr) int32 { panic(todo("")) }
//
// // Tcl_Obj * Tcl_DuplicateObj(Tcl_Obj *objPtr);
// func XTcl_DuplicateObj(tls *crt.TLS, objPtr uintptr) uintptr { panic(todo("")) }
//
// // int Tcl_Eval(Tcl_Interp *interp, const char *script);
// func XTcl_Eval(tls *crt.TLS, interp, script uintptr) int32 { panic(todo("")) }
//
// // int Tcl_EvalObjEx(Tcl_Interp *interp, Tcl_Obj *objPtr, int flags);
// func XTcl_EvalObjEx(tls *crt.TLS, interp, objPtr uintptr, flags int32) int32 { panic(todo("")) }
//
// // void Tcl_FindExecutable(const char *argv0);
// func XTcl_FindExecutable(tls *crt.TLS, argv00 uintptr) {
// 	argv0 := crt.GoString(argv00)
// 	if filepath.IsAbs(argv0) {
// 		nameOfExecutable = argv0
// 		return
// 	}
//
// 	argv0, err := exec.LookPath(argv0)
// 	if err != nil {
// 		return
// 	}
//
// 	if argv0, err = filepath.Abs(argv0); err != nil {
// 		return
// 	}
//
// 	nameOfExecutable = argv0
// }
//
// // int Tcl_GetBooleanFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr, int *boolPtr);
// func XTcl_GetBooleanFromObj(tls *crt.TLS, interp, objPtr, boolPtr uintptr) int32 { panic(todo("")) }
//
// // unsigned char * Tcl_GetByteArrayFromObj(Tcl_Obj *objPtr, int *lengthPtr);
// func XTcl_GetByteArrayFromObj(tls *crt.TLS, objPtr, lengthPtr uintptr) uintptr { panic(todo("")) }
//
// // int Tcl_GetCharLength(Tcl_Obj *objPtr);
// func XTcl_GetCharLength(tls *crt.TLS, objPtr uintptr) int32 { panic(todo("")) }
//
// // int Tcl_GetDoubleFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr, double *doublePtr);
// func XTcl_GetDoubleFromObj(tls *crt.TLS, interp, objPtr, doublePtr uintptr) int32 { panic(todo("")) }
//
// // int Tcl_GetIndexFromObjStruct(Tcl_Interp *interp, Tcl_Obj *objPtr, const void *tablePtr, int offset, const char *msg, int flags, int *indexPtr);
// func XTcl_GetIndexFromObjStruct(tls *crt.TLS, interp, objPtr, tablePtr uintptr, offset int32, msg uintptr, flags int32, indexPtr uintptr) int32 {
// 	panic(todo(""))
// }
//
// // int Tcl_GetIntFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr, int *intPtr);
// func XTcl_GetIntFromObj(tls *crt.TLS, interp, objPtr, intPtr uintptr) int32 { panic(todo("")) }
//
// // Tcl_Obj * Tcl_GetObjResult(Tcl_Interp *interp);
// func XTcl_GetObjResult(tls *crt.TLS, interp uintptr) uintptr { panic(todo("")) }
//
// // char * Tcl_GetString(Tcl_Obj *objPtr);
// func XTcl_GetString(tls *crt.TLS, objPtr uintptr) uintptr { panic(todo("")) }
//
// // const char * Tcl_GetStringResult(Tcl_Interp *interp);
// func XTcl_GetStringResult(tls *crt.TLS, interp uintptr) uintptr { panic(todo("")) }
//
// // const char * Tcl_GetVar2(Tcl_Interp *interp, const char *part1, const char *part2, int flags);
// func XTcl_GetVar2(tls *crt.TLS, interp, part1, part2 uintptr, flags int32) uintptr { panic(todo("")) }
//
// // Tcl_Obj * Tcl_GetVar2Ex(Tcl_Interp *interp, const char *part1, const char *part2, int flags);
// func XTcl_GetVar2Ex(tls *crt.TLS, interp, part1, part2 uintptr, flags int32) uintptr { panic(todo("")) }
//
// // void Tcl_GetVersion(int *major, int *minor, int *patchLevel, int *type);
// func XTcl_GetVersion(tls *crt.TLS, major, minor, patchLevel, type1 uintptr) { panic(todo("")) }
//
// // int Tcl_GetWideIntFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr, Tcl_WideInt *widePtr);
// func XTcl_GetWideIntFromObj(tls *crt.TLS, interp, objPtr, widePtr uintptr) int32 { panic(todo("")) }
//
// // int Tcl_GlobalEval(Tcl_Interp *interp, const char *command);
// func XTcl_GlobalEval(tls *crt.TLS, interp, command uintptr) int32 { panic(todo("")) }
//
// //  int Tcl_ListObjAppendElement(Tcl_Interp *interp, Tcl_Obj *listPtr, Tcl_Obj *objPtr);
// func XTcl_ListObjAppendElement(tls *crt.TLS, interp, listPtr, objPtr uintptr) int32 { panic(todo("")) }
//
// // int Tcl_ListObjGetElements(Tcl_Interp *interp, Tcl_Obj *listPtr, int *objcPtr, Tcl_Obj ***objvPtr);
// func XTcl_ListObjGetElements(tls *crt.TLS, interp, listPtr, objcPtr, objvPtr uintptr) int32 {
// 	panic(todo(""))
// }
//
// // int Tcl_ListObjIndex(Tcl_Interp *interp, Tcl_Obj *listPtr, int index, Tcl_Obj **objPtrPtr);
// func XTcl_ListObjIndex(tls *crt.TLS, interp, listPtr uintptr, index int32, objPtrPtr uintptr) int32 {
// 	panic(todo(""))
// }
//
// // int Tcl_ListObjLength(Tcl_Interp *interp, Tcl_Obj *listPtr, int *lengthPtr);
// func XTcl_ListObjLength(tls *crt.TLS, interp, listPtr, lengthPtr uintptr) int32 { panic(todo("")) }
//
// // void Tcl_NRAddCallback(Tcl_Interp *interp, Tcl_NRPostProc *postProcPtr, ClientData data0, ClientData data1, ClientData data2, ClientData data3);
// func XTcl_NRAddCallback(tls *crt.TLS, interp, postProcPtr, data0, data1, data2, data3 uintptr) {
// 	panic(todo(""))
// }
//
// // int Tcl_NRCallObjProc(Tcl_Interp *interp, Tcl_ObjCmdProc *objProc, ClientData clientData, int objc, Tcl_Obj *const objv[]);
// func XTcl_NRCallObjProc(tls *crt.TLS, interp, objProc, clientData uintptr, objc int32, objv uintptr) int32 {
// 	panic(todo(""))
// }
//
// // Tcl_Command Tcl_NRCreateCommand(Tcl_Interp *interp, const char *cmdName, Tcl_ObjCmdProc *proc, Tcl_ObjCmdProc *nreProc, ClientData clientData, Tcl_CmdDeleteProc *deleteProc);
// func XTcl_NRCreateCommand(tls *crt.TLS, interp, cmdName, proc, nreProc, clientData, deleteProc uintptr) uintptr {
// 	panic(todo(""))
// }
//
// // int Tcl_NREvalObj(Tcl_Interp *interp, Tcl_Obj *objPtr, int flags);
// func XTcl_NREvalObj(tls *crt.TLS, interp, objPtr uintptr, flags int32) int32 { panic(todo("")) }
//
// // Tcl_Obj * Tcl_NewByteArrayObj(const unsigned char *bytes, int length);
// func XTcl_NewByteArrayObj(tls *crt.TLS, bytes uintptr, length int32) uintptr { panic(todo("")) }
//
// // Tcl_Obj * Tcl_NewDoubleObj(double doubleValue);
// func XTcl_NewDoubleObj(tls *crt.TLS, doubleValue float64) uintptr { panic(todo("")) }
//
// // Tcl_Obj * Tcl_NewIntObj(int intValue);
// func XTcl_NewIntObj(tls *crt.TLS, intValue int32) uintptr { panic(todo("")) }
//
// // Tcl_Obj * Tcl_NewListObj(int objc, Tcl_Obj *const objv[]);
// func XTcl_NewListObj(tls *crt.TLS, objc int32, objv uintptr) uintptr { panic(todo("")) }
//
// // Tcl_Obj * Tcl_NewObj(void);
// func XTcl_NewObj(tls *crt.TLS) uintptr { panic(todo("")) }
//
// // Tcl_Obj * Tcl_NewStringObj(const char *bytes, int length);
// func XTcl_NewStringObj(tls *crt.TLS, bytes uintptr, length int32) uintptr { panic(todo("")) }
//
// // Tcl_Obj * Tcl_NewWideIntObj(Tcl_WideInt wideValue);
// func XTcl_NewWideIntObj(tls *crt.TLS, wideValue crt.Intptr) uintptr { panic(todo("")) }
//
// // Tcl_Obj * Tcl_ObjSetVar2(Tcl_Interp *interp, Tcl_Obj *part1Ptr, Tcl_Obj *part2Ptr, Tcl_Obj *newValuePtr, int flags);
// func XTcl_ObjSetVar2(tls *crt.TLS, interp, part1, part2, newValuePtr uintptr, flags int32) uintptr {
// 	panic(todo(""))
// }
//
// // int Tcl_PkgProvideEx(Tcl_Interp *interp, const char *name, const char *version, const void *clientData);
// func XTcl_PkgProvideEx(tls *crt.TLS, interp, name0, version0, clientData uintptr) int32 {
// 	name := crt.GoString(name0)
// 	version := crt.GoString(version0)
// 	switch name {
// 	case "sqlite3":
// 		if version != sqlite3.SQLITE_VERSION {
// 			panic(todo("%q %q", name, version))
// 		}
// 	default:
// 		panic(todo("%q %q", name, version))
// 	}
//
// 	return int32(tee.Ok)
// }
//
// // void Tcl_ResetResult(Tcl_Interp *interp);
// func XTcl_ResetResult(tls *crt.TLS, interp uintptr) { panic(todo("")) }
//
// // void Tcl_SetIntObj(Tcl_Obj *objPtr, int intValue);
// func XTcl_SetIntObj(tls *crt.TLS, objPtr uintptr, intValue int32) { panic(todo("")) }
//
// // void Tcl_SetObjResult(Tcl_Interp *interp, Tcl_Obj *resultObjPtr);
// func XTcl_SetObjResult(tls *crt.TLS, interp, resultObjPtr uintptr) { panic(todo("")) }
//
// // Tcl_SetSystemEncoding sets the default encoding that should be used whenever
// // the user passes a NULL value for the encoding argument to any of the other
// // encoding functions. If name is NULL, the system encoding is reset to the
// // default system encoding, binary. If the name did not refer to any known or
// // loadable encoding, TCL_ERROR is returned and an error message is left in
// // interp. Otherwise, this procedure increments the reference count of the new
// // system encoding, decrements the reference count of the old system encoding,
// // and returns TCL_OK.
// //
// // int Tcl_SetSystemEncoding(Tcl_Interp *interp, const char *name);
// func XTcl_SetSystemEncoding(tls *crt.TLS, interp, name0 uintptr) int32 {
// 	name := crt.GoString(name0)
// 	if interp != 0 {
// 		panic(todo(""))
// 	}
//
// 	if name != "utf-8" {
// 		panic(todo(""))
// 	}
//
// 	return int32(tee.Ok)
// }
//
// // Tcl_SetVar2Ex, Tcl_SetVar, Tcl_SetVar2, and Tcl_ObjSetVar2 will create a new
// // variable or modify an existing one. These procedures set the given variable
// // to the value given by newValuePtr or newValue and return a pointer to the
// // variable's new value, which is stored in Tcl's variable structure.
// // Tcl_SetVar2Ex and Tcl_ObjSetVar2 take the new value as a Tcl_Obj and return
// // a pointer to a Tcl_Obj. Tcl_SetVar and Tcl_SetVar2 take the new value as a
// // string and return a string; they are usually less efficient than
// // Tcl_ObjSetVar2. Note that the return value may be different than the
// // newValuePtr or newValue argument, due to modifications made by write traces.
// // If an error occurs in setting the variable (e.g. an array variable is
// // referenced without giving an index into the array) NULL is returned and an
// // error message is left in interp's result if the TCL_LEAVE_ERR_MSG flag bit
// // is set.
// //
// // The name of a variable may be specified to these procedures in four ways:
// //
// // 1. If Tcl_SetVar, Tcl_GetVar, or Tcl_UnsetVar is invoked, the variable name
// // is given as a single string, varName. If varName contains an open
// // parenthesis and ends with a close parenthesis, then the value between the
// // parentheses is treated as an index (which can have any string value) and the
// // characters before the first open parenthesis are treated as the name of an
// // array variable. If varName does not have parentheses as described above,
// // then the entire string is treated as the name of a scalar variable.
// //
// // 2. If the name1 and name2 arguments are provided and name2 is non-NULL, then
// // an array element is specified and the array name and index have already been
// // separated by the caller: name1 contains the name and name2 contains the
// // index. An error is generated if name1 contains an open parenthesis and ends
// // with a close parenthesis (array element) and name2 is non-NULL.
// //
// // 3. If name2 is NULL, name1 is treated just like varName in case [1] above
// // (it can be either a scalar or an array element variable name).
// //
// // The flags argument may be used to specify any of several options to the
// // procedures. It consists of an OR-ed combination of the following bits.
// //
// //	TCL_GLOBAL_ONLY
// //
// // Under normal circumstances the procedures look up variables as follows. If a
// // procedure call is active in interp, the variable is looked up at the current
// // level of procedure call. Otherwise, the variable is looked up first in the
// // current namespace, then in the global namespace. However, if this bit is set
// // in flags then the variable is looked up only in the global namespace even if
// // there is a procedure call active. If both TCL_GLOBAL_ONLY and
// // TCL_NAMESPACE_ONLY are given, TCL_GLOBAL_ONLY is ignored.
// //
// //	TCL_NAMESPACE_ONLY
// //
// // If this bit is set in flags then the variable is looked up only in the
// // current namespace; if a procedure is active its variables are ignored, and
// // the global namespace is also ignored unless it is the current namespace.
// //
// //	TCL_LEAVE_ERR_MSG
// //
// // If an error is returned and this bit is set in flags, then an error message
// // will be left in the interpreter's result, where it can be retrieved with
// // Tcl_GetObjResult or Tcl_GetStringResult. If this flag bit is not set then no
// // error message is left and the interpreter's result will not be modified.
// //
// //	TCL_APPEND_VALUE
// // If this bit is set then newValuePtr or newValue is appended to the current
// // value instead of replacing it. If the variable is currently undefined, then
// // the bit is ignored. This bit is only used by the Tcl_Set* procedures.
// //
// //	TCL_LIST_ELEMENT
// //
// // If this bit is set, then newValue is converted to a valid Tcl list element
// // before setting (or appending to) the variable. A separator space is appended
// // before the new list element unless the list element is going to be the first
// // element in a list or sublist (i.e. the variable's current value is empty, or
// // contains the single character “{”, or ends in “ }”). When appending, the
// // original value of the variable must also be a valid list, so that the
// // operation is the appending of a new list element onto a list.
// //
// // const char * Tcl_SetVar2(Tcl_Interp *interp, const char *part1, const char *part2, const char *newValue, int flags);
// func XTcl_SetVar2(tls *crt.TLS, interp, part10, part20, newValue0 uintptr, flags int32) {
// 	ctx := getObject(interp).(*tee.Context)
// 	part1 := crt.GoString(part10)
// 	part2 := crt.GoString(part20)
// 	newValue := crt.GoString(newValue0)
// 	if part20 != 0 && (strings.Contains(part1, "(") || strings.Contains(part1, ")")) {
// 		panic(todo(""))
// 	}
//
// 	name := part1
// 	if part2 != "" {
// 		name = fmt.Sprintf("%s(%s)", part1, part2)
// 	}
// 	switch flags {
// 	case TCL_GLOBAL_ONLY:
// 		_ = ctx
// 		panic(todo("%q %q %q %q %#x(%[5]v)", part1, part2, name, newValue, flags))
// 	default:
// 		panic(todo("%q %q %q %q %#x(%[5]v)", part1, part2, name, newValue, flags))
// 	}
// }
//
// // void Tcl_SetWideIntObj(Tcl_Obj *objPtr, Tcl_WideInt wideValue);
// func XTcl_SetWideIntObj(tls *crt.TLS, objPtr uintptr, wideValue crt.Intptr) { panic(todo("")) }
//
// // char * Tcl_TranslateFileName(Tcl_Interp *interp, const char *name, Tcl_DString *bufferPtr);
// func XTcl_TranslateFileName(tls *crt.TLS, interp, name, bufferPtr uintptr) uintptr { panic(todo("")) }
//
// // int Tcl_UnsetVar2(Tcl_Interp *interp, const char *part1, const char *part2, int flags);
// func XTcl_UnsetVar2(tls *crt.TLS, interp, part1, part2 uintptr, flags int32) { panic(todo("")) }
//
// // int Tcl_VarEval(Tcl_Interp *interp, ...);
// func XTcl_VarEval(tls *crt.TLS, interp, va uintptr) int32 { panic(todo("")) }
//
// // void Tcl_WrongNumArgs(Tcl_Interp *interp, int objc, Tcl_Obj *const objv[], const char *message);
// func XTcl_WrongNumArgs(tls *crt.TLS, interp uintptr, objc int32, objv, message uintptr) {
// 	panic(todo(""))
// }
//
// // int Tcl_GetCommandInfo(Tcl_Interp *interp, const char *cmdName, Tcl_CmdInfo *infoPtr);
// func XTcl_GetCommandInfo(tls *crt.TLS, interp, cmdName, infoPtr uintptr) int32 {
// 	panic(todo(""))
// }
//
// // Tcl_Command Tcl_CreateCommand(Tcl_Interp *interp, const char *cmdName, Tcl_CmdProc *proc, ClientData clientData, Tcl_CmdDeleteProc *deleteProc);
// func XTcl_CreateCommand(tls *crt.TLS, interp, cmdName, proc, clentData, deleteProc uintptr) uintptr {
// 	panic(todo(""))
// }
//
// // int Tcl_LinkVar(Tcl_Interp *interp, const char *varName, char *addr, int type);
// func XTcl_LinkVar(tls *crt.TLS, interp, varName, addr uintptr, type1 int32) int32 {
// 	panic(todo(""))
// }
//
// // void Tcl_AppendElement(Tcl_Interp *interp, const char *element);
// func XTcl_AppendElement(tls *crt.TLS, interp, element uintptr) {
// 	panic(todo(""))
// }
//
// // int Tcl_GetInt(Tcl_Interp *interp, const char *src, int *intPtr);
// func XTcl_GetInt(tls *crt.TLS, interp, src, intPtr uintptr) int32 {
// 	panic(todo(""))
// }
//
// // int Tcl_GetDouble(Tcl_Interp *interp, const char *src, double *doublePtr);
// func XTcl_GetDouble(tls *crt.TLS, interp, src, doublePtr uintptr) int32 {
// 	panic(todo(""))
// }
//
// // Tcl_Channel Tcl_GetChannel(Tcl_Interp *interp, const char *chanName, int *modePtr);
// func XTcl_GetChannel(tls *crt.TLS, interp, chanName, modePtr uintptr) uintptr {
// 	panic(todo(""))
// }
//
// // int Tcl_Flush(Tcl_Channel chan);
// func XTcl_Flush(tls *crt.TLS, chan1 uintptr) int32 {
// 	panic(todo(""))
// }
//
// // Tcl_WideInt Tcl_Seek(Tcl_Channel chan, Tcl_WideInt offset, int mode);
// func XTcl_Seek(tls *crt.TLS, chan1 uintptr, offset crt.Intptr, mode int32) crt.Intptr {
// 	panic(todo(""))
// }
//
// // ClientData Tcl_GetChannelInstanceData(Tcl_Channel chan);
// func XTcl_GetChannelInstanceData(tls *crt.TLS, chan1 uintptr) uintptr {
// 	panic(todo(""))
// }
//
// // int Tcl_EvalEx(Tcl_Interp *interp, const char *script, int numBytes, int flags);
// func XTcl_EvalEx(tls *crt.TLS, interp, script uintptr, numBytes, flags int32) int32 {
// 	panic(todo(""))
// }
//
// // __attribute__ ((noreturn)) void Tcl_Panic(const char *format, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
// func XTcl_Panic(tls *crt.TLS, format, va uintptr) {
// 	panic(todo(""))
// }
//
// // int Tcl_GetBoolean(Tcl_Interp *interp, const char *src, int *boolPtr);
// func XTcl_GetBoolean(tls *crt.TLS, interp, src, boolPtr uintptr) int32 {
// 	panic(todo(""))
// }
//
// // char * Tcl_AttemptAlloc(unsigned int size);
// func XTcl_AttemptAlloc(tls *crt.TLS, size uint32) uintptr {
// 	panic(todo(""))
// }
//
// // char * Tcl_AttemptRealloc(char *ptr, unsigned int size);
// func XTcl_AttemptRealloc(tls *crt.TLS, ptr uintptr, size uint32) uintptr {
// 	panic(todo(""))
// }
//
// // int Tcl_UtfToLower(char *src);
// func XTcl_UtfToLower(tls *crt.TLS, src uintptr) int32 {
// 	panic(todo(""))
// }
//
// // void Tcl_AppendStringsToObj(Tcl_Obj *objPtr, ...);
// func XTcl_AppendStringsToObj(tls *crt.TLS, objPtr, va uintptr) {
// 	panic(todo(""))
// }
//
// // Tcl_HashEntry * Tcl_FirstHashEntry(Tcl_HashTable *tablePtr, Tcl_HashSearch *searchPtr);
// func XTcl_FirstHashEntry(tls *crt.TLS, tablePtr, searchPtr uintptr) uintptr {
// 	panic(todo(""))
// }
//
// // Tcl_HashEntry * Tcl_NextHashEntry(Tcl_HashSearch *searchPtr);
// func XTcl_NextHashEntry(tls *crt.TLS, searchPtr uintptr) uintptr {
// 	panic(todo(""))
// }
//
// // void Tcl_DeleteHashTable(Tcl_HashTable *tablePtr);
// func XTcl_DeleteHashTable(tls *crt.TLS, tablePtr uintptr) {
// 	panic(todo(""))
// }
//
// // void Tcl_InitHashTable(Tcl_HashTable *tablePtr, int keyType);
// func XTcl_InitHashTable(tls *crt.TLS, tablePtr uintptr, keyType int32) {
// 	panic(todo(""))
// }
//
// // int Tcl_SetCommandInfo(Tcl_Interp *interp, const char *cmdName, const Tcl_CmdInfo *infoPtr);
// func XTcl_SetCommandInfo(tls *crt.TLS, interp, cmdName, infoPtr uintptr) int32 {
// 	panic(todo(""))
// }
//
// // void Tcl_AppendObjToObj(Tcl_Obj *objPtr, Tcl_Obj *appendObjPtr);
// func XTcl_AppendObjToObj(tls *crt.TLS, objPtr, appendObjPtr uintptr) {
// 	panic(todo(""))
// }
//
// // Tcl_Obj * Tcl_ObjGetVar2(Tcl_Interp *interp, Tcl_Obj *part1Ptr, Tcl_Obj *part2Ptr, int flags);
// func XTcl_ObjGetVar2(tls *crt.TLS, interp, part1Ptr, part2Ptr uintptr, flags int32) uintptr {
// 	panic(todo(""))
// }
//
// // void Tcl_ThreadQueueEvent(Tcl_ThreadId threadId, Tcl_Event *evPtr, Tcl_QueuePosition position);
// func XTcl_ThreadQueueEvent(tls *crt.TLS, threadId, evPtr uintptr, position uint32) {
// 	panic(todo(""))
// }
//
// // void Tcl_ThreadAlert(Tcl_ThreadId threadId);
// func XTcl_ThreadAlert(tls *crt.TLS, threadId uintptr) {
// 	panic(todo(""))
// }
//
// // void Tcl_DeleteInterp(Tcl_Interp *interp);
// func XTcl_DeleteInterp(tls *crt.TLS, interp uintptr) {
// 	panic(todo(""))
// }
//
// // int Tcl_DoOneEvent(int flags);
// func XTcl_DoOneEvent(tls *crt.TLS, flags int32) int32 {
// 	panic(todo(""))
// }
//
// // void Tcl_ExitThread(int status);
// func XTcl_ExitThread(tls *crt.TLS, status int32) {
// 	panic(todo(""))
// }
//
// // Tcl_ThreadId Tcl_GetCurrentThread(void);
// func XTcl_GetCurrentThread(tls *crt.TLS) uintptr {
// 	panic(todo(""))
// }
//
// // int Tcl_CreateThread(Tcl_ThreadId *idPtr, Tcl_ThreadCreateProc *proc, ClientData clientData, int stackSize, int flags);
// func XTcl_CreateThread(tls *crt.TLS, idPtr, proc, clientData uintptr, stackSize, flags int32) int32 {
// 	panic(todo(""))
// }
//
// // void Tcl_GetTime(Tcl_Time *timeBuf);
// func XTcl_GetTime(tls *crt.TLS, timeBuf uintptr) {
// 	panic(todo(""))
// }
//
// // Tcl_Interp * Tcl_GetSlave(Tcl_Interp *interp, const char *slaveName);
// func XTcl_GetSlave(tls *crt.TLS, interp, slaveName uintptr) uintptr {
// 	panic(todo(""))
// }
//
// // ============================================================================