Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Tcl to C or C++

897 views
Skip to first unread message

Stefano Chiappa

unread,
Mar 23, 2005, 3:34:22 AM3/23/05
to
Hi all,
does anyone know some tool (free or not) capable to translate Tcl source
code to C or C++? Of course I believe to translate only a subset of Tcl
language (1), while statements like this:

#...some code that algorithmically generate the string a, where a is
# almost-arbitrary code
eval $a

cannot be translated at all, except with somewhat complex solutions!
Thank you

(1) I'm thinking to traslate Tcl source code written using a subset of
Tcl keywords and by following some coding rules; for example I'd avoid
this:

#...some code that calculates a and b
set $a$b 0

Stefano Chiappa

Georgios Petasis

unread,
Mar 23, 2005, 4:15:37 AM3/23/05
to
Dear Stefano,

Is there a reason for wanting this convertion?
As I have tried to do such a project in the past,
it turned out that the resulting C code was much more slower
& memory wasting than the corrsponing tcl code,
so I gave up :-) So, for such a tool
a severe investment on optimisations has to be made,
in order for the generated C code to be of use.
I remember that there was at least one such commercial compiler
in the past, but I don't know if it is still active.
See for example:

http://groups.google.com.gr/groups?q=aotto+compiler&hl=el&lr=&group=comp.lang.tcl.*&selm=pgpmoose.200101222138.11399%40non.non.net&rnum=1

I remember that I had tested the compiler and indeed it gave
some speedup over the tclc code. However, I believe the speedup
was due to the heavy optimisation that was done by the author,
and not from the fact that it was converted in C.

If you want to simply hide your code, there are other ways...

George

"Stefano Chiappa" <stef...@saparawimi.is> wrote in message
news:e-idnREztK6...@kpnqwest.it...

David N. Welton

unread,
Mar 23, 2005, 7:09:39 AM3/23/05
to
Stefano Chiappa <stef...@saparawimi.is> writes:

> does anyone know some tool (free or not) capable to translate Tcl
> source code to C or C++? Of course I believe to translate only a
> subset of Tcl language (1), while statements like this:

Hi,

Is this to speed your code up or hide it? There are better approaches
to both, depending on your needs. Perhaps you could back up and tell
us about your situation, and what problems you are experiencing...

Ciao,
--
David N. Welton
- http://www.dedasys.com/davidw/

Apache, Linux, Tcl Consulting
- http://www.dedasys.com/

David N. Welton

unread,
Mar 23, 2005, 8:20:19 AM3/23/05
to
Stefano Chiappa <stef...@saparawimi.is> writes:

> Hi, the reason for which I'd like to convert Tcl to C/C++ is
> speed. Infact the approach I'm using now is to convert some
> "utility" functions to C ones, and I get speed improvement. I have a
> C application that launches Tcl interpreters and interacts with
> them. My idea is: when the Tcl code is enough tested, I'd like to
> convert them to C, to make it run faster, or best I hope this. I'm
> thinking to something like this: I have this Tcl code:

> set a 0
> incr a

> suppose I have a tool that understand that the a variable will be
> used "like an integer" (1), this could be translated to this in C:

> int a = 0;
> a++;

> If this is possible, the code will be faster.

I don't think that's really available at this point in time for Tcl.
I think your best bet is to analyze where your code is slow, and
rewrite it in C - perhaps not line for line, but using a higher level
approach that takes into account the design and goals of your program.

Stefano Chiappa

unread,
Mar 23, 2005, 8:15:25 AM3/23/05
to David N. Welton
David N. Welton wrote:
> Stefano Chiappa <stef...@saparawimi.is> writes:
>
>
>>does anyone know some tool (free or not) capable to translate Tcl
>>source code to C or C++? Of course I believe to translate only a
>>subset of Tcl language (1), while statements like this:
>
>
> Hi,
>
> Is this to speed your code up or hide it? There are better approaches
> to both, depending on your needs. Perhaps you could back up and tell
> us about your situation, and what problems you are experiencing...
>
> Ciao,

Hi, the reason for which I'd like to convert Tcl to C/C++ is speed.

Infact the approach I'm using now is to convert some "utility" functions
to C ones, and I get speed improvement. I have a C application that
launches Tcl interpreters and interacts with them. My idea is: when the
Tcl code is enough tested, I'd like to convert them to C, to make it run
faster, or best I hope this.
I'm thinking to something like this: I have this Tcl code:

set a 0
incr a

suppose I have a tool that understand that the a variable will be used
"like an integer" (1), this could be translated to this in C:

int a = 0;
a++;

If this is possible, the code will be faster.

(1) I suppose some tool capable to "study" the usage of the a var,
checking the expression where it is used, and even that it is used in an
"integer" way even in subprocedures that uses it through upvar.

Stefano

Arjen Markus

unread,
Mar 23, 2005, 8:42:48 AM3/23/05
to
Stefano Chiappa wrote:
>
>
>
> Hi, the reason for which I'd like to convert Tcl to C/C++ is speed.
> Infact the approach I'm using now is to convert some "utility" functions
> to C ones, and I get speed improvement. I have a C application that
> launches Tcl interpreters and interacts with them. My idea is: when the
> Tcl code is enough tested, I'd like to convert them to C, to make it run
> faster, or best I hope this.
> I'm thinking to something like this: I have this Tcl code:
>
> set a 0
> incr a
>
> suppose I have a tool that understand that the a variable will be used
> "like an integer" (1), this could be translated to this in C:
>
> int a = 0;
> a++;
>
> If this is possible, the code will be faster.
>
> (1) I suppose some tool capable to "study" the usage of the a var,
> checking the expression where it is used, and even that it is used in an
> "integer" way even in subprocedures that uses it through upvar.
>
> Stefano

Be careful here:

The time needed to run a program one time is a very poor, even though
very popular, metric to define the performance. It is at least as
important to take the programmer's time into account, the cost of
maintenance and so on.

If you have a particularly time-consuming function in your program,
consider using Critcl or other approaches to replace that function
by a C (or Fortran or ...) extension.

The most robust way to determine this is: profile your application.
You should check out Tcllib for its profiling capabilities (I have
no experience there, so I can not advise you in more detail).

Regards,

Arjen

miguel sofer

unread,
Mar 23, 2005, 8:55:53 AM3/23/05
to

The trouble is that tcl is too dynamic for that. What if (somewhere far
from that code, maybe even in some package you are loading), there is
something like

rename incr incr.ORIG
proc incr {x {i 1}} {
upvar 1 x x
if {[catch {incr.ORIG x $i}]} {
set x [expr {$x + $i}]
}
return $x
}

because someone wanted an incr that works also on doubles (or complex
numbers, or whatever)? Or you are debugging your code, and want to put a
trace on incr, or on a? Or a is traced in order to diplay in some widget?

The logic to produce dual codes (C for speed, Tcl for fallback when
needed) and switch between the two is probably overwhelming.

What you can do now is write the critical parts directly in C as a
compiled extension, or (if you know that there is a C compiler in the
target environment), code that using http://mini.net/tcl/critcl.

Miguel

tadhan...@gmail.com

unread,
Jul 5, 2018, 12:42:19 PM7/5/18
to
> Hi David,

I'm looking for a best to hide or encrypt Tcl code, because there are algorithm in my which tcl file which needs to be encrypted.

Is there a way around to do this task?

Thank you,
Miraj Tadhani

Gerald Lester

unread,
Jul 5, 2018, 1:42:07 PM7/5/18
to
See, and follow the links from: http://wiki.tcl.tk/3960


--
+----------------------------------------------------------------------+
| Gerald W. Lester, President, KNG Consulting LLC |
| Email: Gerald...@kng-consulting.net |
+----------------------------------------------------------------------+
0 new messages