Diff

Differences From Artifact [16583ee9af]:

To Artifact [8ce88b67f0]:


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
..
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
...
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

		if {$output == ""} {
			set type "memory"
		} else {
			if {$pkgName == ""} {
				set type "exe"
			} else {
				set type "dll"
			}
		}

		array set $handle [list tcc $tcc_handle code "" type $type filename $output package $pkgName]

		proc $handle {cmd args} [string map [list @@HANDLE@@ $handle] {
			set handle {@@HANDLE@@}
................................................................................
		set state(code) "#include <tcl.h>\n\n$state(code)"

		# Append additional generated code to support the output type
		switch -- $state(type) {
			"memory" {
				# No additional code needed
			}
			"exe" {
				if {[info exists state(procs)] && [llength $state(procs)] > 0} {
					append state(code) "int _initProcs(Tcl_Interp *interp) \{\n"
					
					foreach {procname cname} $state(procs) {
						append state(code) "  Tcl_CreateObjCommand(interp, \"$procname\", $cname, NULL, NULL);"
					}

					append state(code) "\}"
				}
			}
			"dll" {
				set packageName [lindex $state(package) 0]
				set packageVersion [lindex $state(package) 1]
				if {$packageVersion == ""} {
					set packageVersion "0"
				}

				append state(code) "int [string totitle $packageName]_Init(Tcl_Interp *interp) \{\n"
................................................................................
				append state(code) "Tcl_PkgProvide(interp, \"$packageName\", \"$packageVersion\");\n"
				append state(code) "  return(TCL_OK);\n"
				append state(code) "\}"
			}
		}

		# Generate output code








		tcc4tcl $dir $state(type) tcc

		switch -- $state(type) {
			"memory" {
				tcc compile $state(code)

				foreach {procname cname} $state(procs) {
					tcc command $procname $cname
				}
			}

			"dll" - "exe" {
				switch -glob -- $::tcl_platform(os)-$::tcl_platform(machine) {
					"Linux-x86_64" {
						tcc add_library_path "/lib64"
						tcc add_library_path "/usr/lib64"
						tcc add_library_path "/lib"
						tcc add_library_path "/usr/lib"
					}







|







 







|










|







 







>
>
>
>
>
>
>
>
|










|







23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
..
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
...
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

		if {$output == ""} {
			set type "memory"
		} else {
			if {$pkgName == ""} {
				set type "exe"
			} else {
				set type "package"
			}
		}

		array set $handle [list tcc $tcc_handle code "" type $type filename $output package $pkgName]

		proc $handle {cmd args} [string map [list @@HANDLE@@ $handle] {
			set handle {@@HANDLE@@}
................................................................................
		set state(code) "#include <tcl.h>\n\n$state(code)"

		# Append additional generated code to support the output type
		switch -- $state(type) {
			"memory" {
				# No additional code needed
			}
			"exe" - "dll" {
				if {[info exists state(procs)] && [llength $state(procs)] > 0} {
					append state(code) "int _initProcs(Tcl_Interp *interp) \{\n"
					
					foreach {procname cname} $state(procs) {
						append state(code) "  Tcl_CreateObjCommand(interp, \"$procname\", $cname, NULL, NULL);"
					}

					append state(code) "\}"
				}
			}
			"package" {
				set packageName [lindex $state(package) 0]
				set packageVersion [lindex $state(package) 1]
				if {$packageVersion == ""} {
					set packageVersion "0"
				}

				append state(code) "int [string totitle $packageName]_Init(Tcl_Interp *interp) \{\n"
................................................................................
				append state(code) "Tcl_PkgProvide(interp, \"$packageName\", \"$packageVersion\");\n"
				append state(code) "  return(TCL_OK);\n"
				append state(code) "\}"
			}
		}

		# Generate output code
		switch -- $state(type) {
			"package" {
				set tcc_type "dll"
			}
			default {
				set tcc_type $state(type)
			}
		}
		tcc4tcl $dir $tcc_type tcc

		switch -- $state(type) {
			"memory" {
				tcc compile $state(code)

				foreach {procname cname} $state(procs) {
					tcc command $procname $cname
				}
			}

			"package" - "dll" - "exe" {
				switch -glob -- $::tcl_platform(os)-$::tcl_platform(machine) {
					"Linux-x86_64" {
						tcc add_library_path "/lib64"
						tcc add_library_path "/usr/lib64"
						tcc add_library_path "/lib"
						tcc add_library_path "/usr/lib"
					}