Re: binary tcl scripts? is it possible? is it faster ?



Walid wrote:
I want to know, if it's possible to compile a library of tcl scripts
and to load into the interpreter later ?

If you are looking to obfuscate your code from prying eyes, this feature is the bytecode compiler, in TclPro with support through 8.3, and up-to-date support in ActiveState's Tcl Dev Kit: http://www.activestate.com/Tcl

Also I want to know, (if this is possible) if TCL interpreter runs this
scripts faster as it does for text scripts ?

It actually is not faster, and can be marginally slower at startup. This is because the bytecodes are made portable (eg, if you compile on an big-endian chip, it will still load just fine on a little-endian chip, and no binary chars are used), so the loading step needs to decode them from that portable form to the native Tcl bytecode. Of course, Tcl has to do this to all procedures on first use anyway, so the difference in startup time is marginal for any reasonable complex script.

--
  Jeff Hobbs, The Tcl Guy
  http://www.ActiveState.com/, a division of Sophos
.



Relevant Pages

  • tbcload fails to compile against Tcl 8.5
    ... tbcload fails to build against Tcl 8.5 due to some some #define changes ... cmpRead.c:2584: warning: assignment makes integer from pointer without a ... {bytecode terminated prematurely} ... Are there any plans to port the public tbcload sources to Tcl 8.5? ...
    (comp.lang.tcl)
  • Re: Curious timing using Tcl_ObjSetVar2
    ... > I've re-implemented some Tcl code which used arrays to store the various ... > data elements of objects, to use 'C' structs, and have added a set of C ... the explanations below RE bytecode compiler and variable name resolution. ... the array approach does look up by element name, ...
    (comp.lang.tcl)
  • Re: Tcls bytecode compilation.
    ... The bytecode is a very simple language that can be executed very quickly. ... When a procedure is compiled, the Tcl code is converted into this very simple language and then this simpler version is executed at each call, which avoids having to parse the Tcl code every time. ... Code outside of procedures is normally not compiled, so you can see the performance advantage of bytecode compilation by running some timing tests: ...
    (comp.lang.tcl)
  • [NEWS] Re: Tcls bytecode compilation.
    ... The bytecode is a very simple language that can be executed very quickly. ... When a procedure is compiled, the Tcl code is converted into this very simple language and then this simpler version is executed at each call, which avoids having to parse the Tcl code every time. ... Code outside of procedures is normally not compiled, so you can see the performance advantage of bytecode compilation by running some timing tests: ...
    (comp.lang.tcl)
  • Re: Tcl bytecode
    ... However, their purpose is to obfuscate code, and loading them is slower than parsing genuine Tcl source files:) ... However, TDK has to make the bytecode portable, so that is part of the extra translation that doesn't make this loader faster. ... Other languages have more compile overhead, so it makes more sense there to precompile. ...
    (comp.lang.tcl)