Index: xotcl/ChangeLog =================================================================== diff -u -r0896d4deb00780e48b5b03269bf9c4ecca948919 -r836f3964b3b9bff2d75f7f0b5dbc7939164ba24e --- xotcl/ChangeLog (.../ChangeLog) (revision 0896d4deb00780e48b5b03269bf9c4ecca948919) +++ xotcl/ChangeLog (.../ChangeLog) (revision 836f3964b3b9bff2d75f7f0b5dbc7939164ba24e) @@ -1,3 +1,13 @@ +2004-01-07 Gustaf.Neumann@wu-wien.ac.at + * code cleanup for nonpos args + * new methods for Serialzer: + - Serializer methodSerialize (to serialize methods) + - Serializer exportMethods (to export methods from the + xotcl namespace via ::Serializer all + - Serializer exportObjects (to export Objects from ::xotcl::*) + * put Serializer into a namespace (::Serializer is auto-exported) + * aolserver: support for namespaced objects in xotcl.tcl + 2004-01-06 Gustaf.Neumann@wu-wien.ac.at * made introspection options for methods with nonpos args compatible with tcl Index: xotcl/Makefile =================================================================== diff -u -r0896d4deb00780e48b5b03269bf9c4ecca948919 -r836f3964b3b9bff2d75f7f0b5dbc7939164ba24e --- xotcl/Makefile (.../Makefile) (revision 0896d4deb00780e48b5b03269bf9c4ecca948919) +++ xotcl/Makefile (.../Makefile) (revision 836f3964b3b9bff2d75f7f0b5dbc7939164ba24e) @@ -12,7 +12,7 @@ # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # -# RCS: @(#) $Id: Makefile,v 1.29 2005/01/06 03:10:04 neumann Exp $ +# RCS: @(#) $Id: Makefile,v 1.30 2005/01/07 02:40:58 neumann Exp $ #======================================================================== # Add additional lines to handle any additional AC_SUBST cases that @@ -27,7 +27,7 @@ src_test_dir = ${srcdir}/tests src_app_dir = ${srcdir}/apps src_generic_dir = ${srcdir}/generic -TCL_LIB_SPEC = -L/home/neumann/tcl8.4.7/unix -ltcl8.4 +TCL_LIB_SPEC = -L/home/neumann/import/tcl8.4.9/unix -ltcl8.4 TK_LIB_SPEC = subdirs = aol_prefix = /usr/local/aolserver @@ -143,11 +143,11 @@ SHLIB_CFLAGS = -fPIC SHLIB_LD = gcc -pipe -shared SHLIB_LD_FLAGS = -SHLIB_LD_LIBS = ${LIBS} -L/home/neumann/tcl8.4.7/unix -ltclstub8.4 +SHLIB_LD_LIBS = ${LIBS} -L/home/neumann/import/tcl8.4.9/unix -ltclstub8.4 STLIB_LD = ${AR} cr -TCL_DEFS = -DTCL_THREADS=1 -DUSE_THREAD_ALLOC=1 -D_REENTRANT=1 -D_THREAD_SAFE=1 -DHAVE_PTHREAD_ATTR_SETSTACKSIZE=1 -DHAVE_PTHREAD_ATFORK=1 -DHAVE_READDIR_R=1 -DPEEK_XCLOSEIM=1 -D_LARGEFILE64_SOURCE=1 -DTCL_WIDE_INT_TYPE=long\ long -DHAVE_STRUCT_STAT64=1 -DHAVE_TYPE_OFF64_T=1 -DHAVE_GETCWD=1 -DHAVE_OPENDIR=1 -DHAVE_STRSTR=1 -DHAVE_STRTOL=1 -DHAVE_STRTOLL=1 -DHAVE_STRTOULL=1 -DHAVE_TMPNAM=1 -DHAVE_WAITPID=1 -DHAVE_LIMITS_H=1 -DHAVE_UNISTD_H=1 -DHAVE_SYS_PARAM_H=1 -DUSE_TERMIOS=1 -DHAVE_SYS_TIME_H=1 -DTIME_WITH_SYS_TIME=1 -DHAVE_TM_ZONE=1 -DHAVE_GMTIME_R=1 -DHAVE_LOCALTIME_R=1 -DHAVE_TM_GMTOFF=1 -DHAVE_TIMEZONE_VAR=1 -DHAVE_ST_BLKSIZE=1 -DSTDC_HEADERS=1 -DHAVE_SIGNED_CHAR=1 -DHAVE_LANGINFO=1 -DHAVE_SYS_IOCTL_H=1 -TCL_BIN_DIR = /home/neumann/tcl8.4.7/unix -TCL_SRC_DIR = /home/neumann/tcl8.4.7 +TCL_DEFS = -DTCL_THREADS=1 -DUSE_THREAD_ALLOC=1 -D_REENTRANT=1 -D_THREAD_SAFE=1 -DHAVE_PTHREAD_ATTR_SETSTACKSIZE=1 -DHAVE_PTHREAD_ATFORK=1 -DHAVE_READDIR_R=1 -DHAVE_THREE_ARG_READDIR_R=1 -DPEEK_XCLOSEIM=1 -D_LARGEFILE64_SOURCE=1 -DTCL_WIDE_INT_TYPE=long\ long -DHAVE_STRUCT_STAT64=1 -DHAVE_OPEN64=1 -DHAVE_LSEEK64=1 -DHAVE_TYPE_OFF64_T=1 -DHAVE_GETCWD=1 -DHAVE_OPENDIR=1 -DHAVE_STRSTR=1 -DHAVE_STRTOL=1 -DHAVE_STRTOLL=1 -DHAVE_STRTOULL=1 -DHAVE_TMPNAM=1 -DHAVE_WAITPID=1 -DHAVE_LIMITS_H=1 -DHAVE_UNISTD_H=1 -DHAVE_SYS_PARAM_H=1 -DUSE_TERMIOS=1 -DHAVE_SYS_TIME_H=1 -DTIME_WITH_SYS_TIME=1 -DHAVE_TM_ZONE=1 -DHAVE_GMTIME_R=1 -DHAVE_LOCALTIME_R=1 -DHAVE_TM_GMTOFF=1 -DHAVE_TIMEZONE_VAR=1 -DHAVE_ST_BLKSIZE=1 -DSTDC_HEADERS=1 -DHAVE_SIGNED_CHAR=1 -DHAVE_LANGINFO=1 -DHAVE_SYS_IOCTL_H=1 +TCL_BIN_DIR = /home/neumann/tcl8.4.9/unix +TCL_SRC_DIR = /home/neumann/import/tcl8.4.9 # This is necessary for packages that use private Tcl headers #TCL_TOP_DIR_NATIVE = $(TCL_SRC_DIR) # Not used, but retained for reference of what libs Tcl required @@ -169,7 +169,7 @@ LD_LIBRARY_PATH="$(EXTRA_PATH):$(LD_LIBRARY_PATH)" \ PATH="$(EXTRA_PATH):$(PATH)" \ TCLLIBPATH="$(top_builddir) ${srcdir}" -TCLSH_PROG = /home/neumann/tcl8.4.7/unix/tclsh +TCLSH_PROG = /home/neumann/tcl8.4.9/unix/tclsh TCLSH = $(TCLSH_ENV) $(TCLSH_PROG) SHARED_BUILD = 1 @@ -617,7 +617,7 @@ @echo " setenv TCLLIBPATH \"$(TCLLIBPATH)\"" @echo " and" @if test "x$(XOTCLSH)" = "x" ; then \ - echo " /home/neumann/tcl8.4.7/unix/tclsh" ; \ + echo " /home/neumann/tcl8.4.9/unix/tclsh" ; \ echo " package require XOTcl; namespace import -force xotcl::*" ; \ echo " or" ; \ echo " put the 'package require' line into your ~/.tclshrc" ; \ Index: xotcl/apps/utils/xotclsh =================================================================== diff -u -r900ba9665a79888f0561e2c4b8574c2e4a3dad8b -r836f3964b3b9bff2d75f7f0b5dbc7939164ba24e --- xotcl/apps/utils/xotclsh (.../xotclsh) (revision 900ba9665a79888f0561e2c4b8574c2e4a3dad8b) +++ xotcl/apps/utils/xotclsh (.../xotclsh) (revision 836f3964b3b9bff2d75f7f0b5dbc7939164ba24e) @@ -1,7 +1,7 @@ -#!/home/neumann/tcl8.4.7/unix/tclsh +#!/home/neumann/tcl8.4.9/unix/tclsh if {$argc == 0} { puts "Don't use [info script] as interactive shell! Use instead:" - puts " /home/neumann/tcl8.4.7/unix/tclsh" + puts " /home/neumann/tcl8.4.9/unix/tclsh" puts " package require XOTcl; namespace import ::xotcl::*" } else { package require XOTcl Index: xotcl/apps/utils/xowish =================================================================== diff -u -r900ba9665a79888f0561e2c4b8574c2e4a3dad8b -r836f3964b3b9bff2d75f7f0b5dbc7939164ba24e --- xotcl/apps/utils/xowish (.../xowish) (revision 900ba9665a79888f0561e2c4b8574c2e4a3dad8b) +++ xotcl/apps/utils/xowish (.../xowish) (revision 836f3964b3b9bff2d75f7f0b5dbc7939164ba24e) @@ -1,5 +1,5 @@ #!@WISH_PROG@ -###!/home/neumann/tcl8.4.7/unix/tclsh +###!/home/neumann/tcl8.4.9/unix/tclsh ###package require Tk if {$argc == 0} { puts "Don't use [info script] as interactive shell! Use instead:" Index: xotcl/doc/xo-daemon.html =================================================================== diff -u -r0896d4deb00780e48b5b03269bf9c4ecca948919 -r836f3964b3b9bff2d75f7f0b5dbc7939164ba24e --- xotcl/doc/xo-daemon.html (.../xo-daemon.html) (revision 0896d4deb00780e48b5b03269bf9c4ecca948919) +++ xotcl/doc/xo-daemon.html (.../xo-daemon.html) (revision 836f3964b3b9bff2d75f7f0b5dbc7939164ba24e) @@ -76,7 +76,7 @@ Date: - [::xotcl::rcs date {$Date: 2005/01/06 03:10:05 $}] + [::xotcl::rcs date {$Date: 2005/01/07 02:40:59 $}] Index: xotcl/doc/xo-whichPkg.html =================================================================== diff -u -r0896d4deb00780e48b5b03269bf9c4ecca948919 -r836f3964b3b9bff2d75f7f0b5dbc7939164ba24e --- xotcl/doc/xo-whichPkg.html (.../xo-whichPkg.html) (revision 0896d4deb00780e48b5b03269bf9c4ecca948919) +++ xotcl/doc/xo-whichPkg.html (.../xo-whichPkg.html) (revision 836f3964b3b9bff2d75f7f0b5dbc7939164ba24e) @@ -52,7 +52,7 @@ Date: - [::xotcl::rcs date {$Date: 2005/01/06 03:10:05 $}] + [::xotcl::rcs date {$Date: 2005/01/07 02:40:59 $}] Index: xotcl/generic/aol-xotcl.tcl =================================================================== diff -u -r0896d4deb00780e48b5b03269bf9c4ecca948919 -r836f3964b3b9bff2d75f7f0b5dbc7939164ba24e --- xotcl/generic/aol-xotcl.tcl (.../aol-xotcl.tcl) (revision 0896d4deb00780e48b5b03269bf9c4ecca948919) +++ xotcl/generic/aol-xotcl.tcl (.../aol-xotcl.tcl) (revision 836f3964b3b9bff2d75f7f0b5dbc7939164ba24e) @@ -1,4 +1,4 @@ -# $Id: aol-xotcl.tcl,v 1.3 2005/01/06 03:10:05 neumann Exp $ +# $Id: aol-xotcl.tcl,v 1.4 2005/01/07 02:40:59 neumann Exp $ # # Load XOTcl library and some related packages. @@ -9,7 +9,7 @@ # package require XOTcl; namespace import ::xotcl::* -package require xotcl::serializer 0.6 +package require xotcl::serializer 0.7 # # Overload procedure defined in bin/init.tcl. @@ -37,11 +37,12 @@ } } if {[catch {::Serializer all} objects]} { - set objects "" ns_log notice "XOTcl extension not loaded; will not copy objects." + set objects "" } - #ns_ictl save [append script \n $objects \n $import] - ns_ictl save [append script \n $import \n $objects] + ns_ictl save [append script \n \ + "namespace import ::xotcl::*" \n \ + $objects \n $import] if {0} { set f [open /tmp/__aolserver-blueprint.tcl w] puts $f $script Index: xotcl/generic/xotcl.c =================================================================== diff -u -r0896d4deb00780e48b5b03269bf9c4ecca948919 -r836f3964b3b9bff2d75f7f0b5dbc7939164ba24e --- xotcl/generic/xotcl.c (.../xotcl.c) (revision 0896d4deb00780e48b5b03269bf9c4ecca948919) +++ xotcl/generic/xotcl.c (.../xotcl.c) (revision 836f3964b3b9bff2d75f7f0b5dbc7939164ba24e) @@ -1,4 +1,4 @@ -/* $Id: xotcl.c,v 1.34 2005/01/06 03:10:05 neumann Exp $ +/* $Id: xotcl.c,v 1.35 2005/01/07 02:40:59 neumann Exp $ * * XOTcl - Extended OTcl * @@ -4378,9 +4378,9 @@ static XOTclNonposArgs* NonposArgsGet(Tcl_HashTable* nonposArgsTable, char* methodName) { - Tcl_HashEntry* hPtr = nonposArgsTable ? Tcl_FindHashEntry(nonposArgsTable, - methodName) : 0; - if (hPtr) { + Tcl_HashEntry* hPtr; + if (nonposArgsTable && + ((hPtr = Tcl_FindHashEntry(nonposArgsTable, methodName)))) { return (XOTclNonposArgs*) Tcl_GetHashValue(hPtr); } return NULL; @@ -4477,7 +4477,6 @@ npaObj = Tcl_NewListObj(0, NULL); arg = ObjStr(npav[0]); if (arg[0] != '-') { - INCR_REF_COUNT(npaObj); DECR_REF_COUNT(npaObj); DECR_REF_COUNT(nonposArgsObj); return XOTclVarErrMsg(in, "non-positional args does not start with '-': ", @@ -4517,22 +4516,29 @@ Tcl_ListObjAppendElement(in, npaObj, npav[1]); } Tcl_ListObjAppendElement(in, nonposArgsObj, npaObj); + *haveNonposArgs = 1; + } + if (*haveNonposArgs) { + XOTclNonposArgs* nonposArg; + if (*nonposArgsTable == 0) { *nonposArgsTable = NonposArgsCreateTable(); } hPtr = Tcl_CreateHashEntry(*nonposArgsTable, procName, &nw); - if (nw) { - XOTclNonposArgs* nonposArg; - MEM_COUNT_ALLOC("nonposArg",nonposArg); - nonposArg = (XOTclNonposArgs*)ckalloc(sizeof(XOTclNonposArgs)); - nonposArg->nonposArgs = nonposArgsObj; - nonposArg->ordinaryArgs = ordinaryArgs; - INCR_REF_COUNT(ordinaryArgs); - Tcl_SetHashValue(hPtr, (ClientData)nonposArg); - } - *haveNonposArgs = 1; + assert(nw); + + MEM_COUNT_ALLOC("nonposArg",nonposArg); + nonposArg = (XOTclNonposArgs*)ckalloc(sizeof(XOTclNonposArgs)); + nonposArg->nonposArgs = nonposArgsObj; + nonposArg->ordinaryArgs = ordinaryArgs; + INCR_REF_COUNT(ordinaryArgs); + Tcl_SetHashValue(hPtr, (ClientData)nonposArg); + } else { + /* for strange resons, we did not find nonpos-args, although we + have definitions */ + DECR_REF_COUNT(nonposArgsObj); } } return TCL_OK; @@ -4549,9 +4555,9 @@ Tcl_HashEntry* hPtr = NULL; char *procName = ObjStr(objv[1]); - hPtr = *nonposArgsTable ? Tcl_FindHashEntry(*nonposArgsTable, procName) : 0; - if (hPtr) + if (*nonposArgsTable && (hPtr = Tcl_FindHashEntry(*nonposArgsTable, procName))) { NonposArgsDeleteHashEntry(hPtr); + } ov[0] = objv[0]; ov[1] = objv[1]; @@ -4569,9 +4575,11 @@ ov[3] = addPrefixToBody(objv[4], 0); } } else { +#if !defined(XOTCL_DISJOINT_ARGLISTS) int argsc, i; Tcl_Obj **argsv; + /* see, if we have nonposArgs in the ordinary argument list */ result = Tcl_ListObjGetElements(in, objv[2], &argsc, &argsv); if (result != TCL_OK) { return XOTclVarErrMsg(in, "cannot break args into list: ", @@ -4600,8 +4608,8 @@ if (result != TCL_OK) return result; } +#endif if (haveNonposArgs) { - /*fprintf(stderr, "haveNonposArgs = %d\n",haveNonposArgs);*/ ov[2] = XOTclGlobalObjects[XOTE_ARGS]; ov[3] = addPrefixToBody(objv[3], 1); } else { /* no nonpos arguments */ @@ -9527,9 +9535,6 @@ "instproc name ?non-positional-args? args body ?preAssertion postAssertion?"); if (objc == 5 || objc == 7) { - if (cl->nonposArgsTable == 0) { - cl->nonposArgsTable = NonposArgsCreateTable(); - } incr = 1; } Index: xotcl/library/serialize/Serializer.xotcl =================================================================== diff -u -r0896d4deb00780e48b5b03269bf9c4ecca948919 -r836f3964b3b9bff2d75f7f0b5dbc7939164ba24e --- xotcl/library/serialize/Serializer.xotcl (.../Serializer.xotcl) (revision 0896d4deb00780e48b5b03269bf9c4ecca948919) +++ xotcl/library/serialize/Serializer.xotcl (.../Serializer.xotcl) (revision 836f3964b3b9bff2d75f7f0b5dbc7939164ba24e) @@ -1,315 +1,393 @@ -# $Id: Serializer.xotcl,v 1.5 2005/01/06 03:10:05 neumann Exp $ -package require XOTcl 1.0 -package provide xotcl::serializer 0.6 +# $Id: Serializer.xotcl,v 1.6 2005/01/07 02:40:59 neumann Exp $ +package require XOTcl 1.3 -@ @File { +set ::xotcl::ns ::xotcl::serializer +namespace eval $::xotcl::ns { + + package provide xotcl::serializer 0.7 + namespace import ::xotcl::* + + @ @File { description { This package provides the class Serializer, which can be used to generate a snapshot of the current state of the workspace in the form of XOTcl source code. } authors { - Gustaf Neumann, Gustaf.Neumann@wu-wien.ac.at + Gustaf Neumann, Gustaf.Neumann@wu-wien.ac.at } - date { $Date: 2005/01/06 03:10:05 $ } -} + date { $Date: 2005/01/07 02:40:59 $ } + } -@ Serializer proc all { - ?-ignoreVarsRE RE? - "provide regular expression; matching vars are ignored" - ?-ignore obj1 obj2 ...? - "provide a list of objects to be omitted"} { - Description { - Serialize all objects and classes that are currently - defined (except the specified omissions and the current - Serializer object). -

Examples:<@br> - <@tt>Serializer all -ignoreVarsRE {::b$}<@br> - do not serialize any instance variable named b (of any object)

- <@tt>Serializer all -ignoreVarsRE {^::o1::.*text.*$|^::o2::x$}<@br> - do not serialize any variable of c1 whose name contains - the string "text" and do not serialze the variable x of o2

- <@tt>Serializer all - ignore obj1 obj2 ... <@br> - do not serizalze the specified objects + @ Serializer proc all { + ?-ignoreVarsRE RE? + "provide regular expression; matching vars are ignored" + ?-ignore obj1 obj2 ...? + "provide a list of objects to be omitted"} { + Description { + Serialize all objects and classes that are currently + defined (except the specified omissions and the current + Serializer object). +

Examples:<@br> + <@pre class='code'>Serializer all -ignoreVarsRE {::b$} + Do not serialize any instance variable named b (of any object).

+ <@pre class='code'>Serializer all -ignoreVarsRE {^::o1::.*text.*$|^::o2::x$} + Do not serialize any variable of c1 whose name contains + the string "text" and do not serialze the variable x of o2.

+ <@pre class='code'>Serializer all -ignore obj1 obj2 ... + do not serizalze the specified objects + } + return "script" } - return "script" -} - -@ Serializer proc deepSerialize { - objs "Objects to be serialized" - ?-ignoreVarsRE RE? - "provide regular expression; matching vars are ignored" - ?-ignore obj1 obj2 ...? - "provide a list of objects to be omitted" - ?-map list? "translate object names in serialized code" -} { - Description { - Serialize object with all child objects (deep operation) - except the specified omissions. For the description of - <@tt>ignore and <@tt>igonoreVarsRE see - <@tt>Serizalizer all. <@tt>map can be used - in addition to provide pairs of old-string and new-string - (like in the tcl command <@tt>string map). This option - can be used to regenerate the serialized object under a different - object or under an different name, or to translate relative - object names in the serialized code.

- - Examples: - <@tt>Serializer deepSerialize ::a::b::c -map {::a::b ::x::y}<@br> - Serialize the object <@tt>c which is a child of <@tt>a::b; - the object will be reinitialized as object <@tt>::x::y::c, - all references <@tt>::a::b will be replaced by <@tt>::x::y.

- - <@tt>Serializer deepSerialize ::a::b::c -map {::a::b [self]}<@br> - The serizalized object can be reinstantiated under some current object, - under which the script is evaluated.

- - <@tt>Serializer deepSerialize ::a::b::c -map {::a::b::c ${var}}<@br> - The serizalized object will be reinstantiated under a name specified - by the variable <@tt>var<@tt> in the recreation context. + + @ Serializer proc deepSerialize { + objs "Objects to be serialized" + ?-ignoreVarsRE RE? + "provide regular expression; matching vars are ignored" + ?-ignore obj1 obj2 ...? + "provide a list of objects to be omitted" + ?-map list? "translate object names in serialized code" + } { + Description { + Serialize object with all child objects (deep operation) + except the specified omissions. For the description of + <@tt>ignore and <@tt>igonoreVarsRE see + <@tt>Serizalizer all. <@tt>map can be used + in addition to provide pairs of old-string and new-string + (like in the tcl command <@tt>string map). This option + can be used to regenerate the serialized object under a different + object or under an different name, or to translate relative + object names in the serialized code.

+ + Examples: + <@pre class='code'>Serializer deepSerialize ::a::b::c -map {::a::b ::x::y} + Serialize the object <@tt>c which is a child of <@tt>a::b; + the object will be reinitialized as object <@tt>::x::y::c, + all references <@tt>::a::b will be replaced by <@tt>::x::y.

+ + <@pre class='code'>Serializer deepSerialize ::a::b::c -map {::a::b [self]} + The serizalized object can be reinstantiated under some current object, + under which the script is evaluated.

+ + <@pre class='code'>Serializer deepSerialize ::a::b::c -map {::a::b::c ${var}} + The serizalized object will be reinstantiated under a name specified + by the variable <@tt>var<@tt> in the recreation context. + } + return "script" } - return "script" -} - -@ Serializer instproc serialize {entity "Object or Class"} { - Description { - Serialize the specified object or class. + + @ Serializer proc methodSerialize { + object "object or class" + method "name of method" + prefix "either empty or 'inst' (latter for instprocs)" + } { + Description { + Serialize the specified method. In order to serialize + an instproc, <@tt>prefix should be 'inst'; to serialze + procs, it should be empty.

+ + Examples: + <@pre class='code'>Serializer methodSerialize Serializer deepSerialize "" + This command serializes the proc <@tt>deepSerialize + of the Class <@tt>Serializer.

+ + <@pre class='code'>Serializer methodSerialize Serializer serialize inst + This command serializes the instproc <@tt>serialize + of the Class <@tt>Serializer.

+ } + return {Script, which can be used to recreate the specified method} } - return {Object or Class with all currently defined methods, - variables, invariants, filters and mixins} -} - -######################################################################################## -Class Serializer -parameter {ignoreVarsRE map} -Serializer proc addGlobalMethods list { - foreach {o p m} $list {my set globalExportMethods($o,$p,$m) 1} -} -Serializer proc ignore args { - my set skip $args -} -Serializer instproc ignore args { - foreach i $args { my set skip($i) 1 } -} -Serializer instproc init {} { - my ignore [self] - if {[[self class] exists skip]} { - eval my ignore [[self class] set skip] + @ Serializer proc exportMethods { + list "list of methods of the form 'object proc|instproc methodname'" + } { + Description { + This method can be used to specify methods that should be + exported in every <@tt>Serializer all<@/tt>. The rationale + behind this is that the serializer does not serialize objects + from the ::xotcl:: namespace, which is used for XOTcl internals + and volatile objects. It is however often useful to define + methods on ::xotcl::Class or ::xotcl::Objects, which should + be exported.

+ Example: + <@pre class='code'> Serializer exportMethods { + ::xotcl::Object instproc __split_arguments + ::xotcl::Object instproc __make_doc + ::xotcl::Object instproc ad_proc + ::xotcl::Class instproc ad_instproc + }<@/pre> + } } -} -Serializer instproc method-serialize {o m prefix} { - my pcmd [my unescaped-method-serialize $o $m $prefix] -} -Serializer instproc unescaped-method-serialize {o m prefix} { - set arglist [list] - foreach v [$o info ${prefix}args $m] { - if {[$o info ${prefix}default $m $v x]} { - lappend arglist [list $v $x] } {lappend arglist $v} + + + @ Serializer instproc serialize {entity "Object or Class"} { + Description { + Serialize the specified object or class. + } + return {Object or Class with all currently defined methods, + variables, invariants, filters and mixins} } - lappend r ${prefix}proc $m \ - [concat [$o info ${prefix}nonposargs $m] $arglist] \ - [$o info ${prefix}body $m] - foreach p {pre post} { - if {[$o info ${prefix}$p $m]!=""} {lappend r [$o info ${prefix}$p $m]} + + ######################################################################################## + Class Serializer -parameter {ignoreVarsRE map} + namespace export Serializer + Serializer proc ignore args { + my set skip $args } - return $r -} -Serializer instproc pcmd list { - foreach a $list { - if {[regexp -- {^-[[:alpha:]]} $a]} { - set mustEscape 1 - break + Serializer instproc ignore args { + foreach i $args { my set skip($i) 1 } + } + Serializer instproc init {} { + my ignore [self] + if {[[self class] exists skip]} { + eval my ignore [[self class] set skip] } } - if {[info exists mustEscape]} { - return "\[list -$list\]" - } else { - return -$list + Serializer instproc method-serialize {o m prefix} { + my pcmd [my unescaped-method-serialize $o $m $prefix] } -} -Serializer instproc Object-serialize o { - append cmd [list [$o info class] create $o -noinit] " \\\n" - foreach i [$o info procs] { - append cmd " " [my method-serialize $o $i ""] " \\\n" + Serializer instproc unescaped-method-serialize {o m prefix} { + set arglist [list] + foreach v [$o info ${prefix}args $m] { + if {[$o info ${prefix}default $m $v x]} { + lappend arglist [list $v $x] } {lappend arglist $v} + } + lappend r ${prefix}proc $m \ + [concat [$o info ${prefix}nonposargs $m] $arglist] \ + [$o info ${prefix}body $m] + foreach p {pre post} { + if {[$o info ${prefix}$p $m]!=""} {lappend r [$o info ${prefix}$p $m]} + } + return $r } - foreach i [$o info forward] { - set fwd [concat [list forward $i] [$o info forward -definition $i]] - append cmd \t [my pcmd $fwd] " \\\n" + Serializer instproc pcmd list { + foreach a $list { + if {[regexp -- {^-[[:alpha:]]} $a]} { + set mustEscape 1 + break + } + } + if {[info exists mustEscape]} { + return "\[list -$list\]" + } else { + return -$list + } } - set vset {} - set nrVars 0 - foreach v [$o info vars] { - set setcmd [list] - if {![my exists ignoreVarsRE] || - ![regexp [my set ignoreVarsRE] ${o}::$v]} { - if {[$o array exists $v]} { - lappend setcmd array set $v [$o array get $v] - } else { - lappend setcmd set $v [$o set $v] + Serializer instproc Object-serialize o { + append cmd [list [$o info class] create $o -noinit] " \\\n" + foreach i [$o info procs] { + append cmd " " [my method-serialize $o $i ""] " \\\n" + } + foreach i [$o info forward] { + set fwd [concat [list forward $i] [$o info forward -definition $i]] + append cmd \t [my pcmd $fwd] " \\\n" + } + set vset {} + set nrVars 0 + foreach v [$o info vars] { + set setcmd [list] + if {![my exists ignoreVarsRE] || + ![regexp [my set ignoreVarsRE] ${o}::$v]} { + if {[$o array exists $v]} { + lappend setcmd array set $v [$o array get $v] + } else { + lappend setcmd set $v [$o set $v] + } + incr nrVars + append cmd \t [my pcmd $setcmd] " \\\n" } - incr nrVars - append cmd \t [my pcmd $setcmd] " \\\n" } + foreach x {mixin invar} { + set v [$o info $x] + if {[string compare "" $v]} {append cmd [my pcmd [list $x $v]] " \\\n"} + } + set v [$o info filter -guards] + if {[string compare "" $v]} {append cmd [my pcmd [list filter $v]] " \\\n"} + return $cmd } - foreach x {mixin invar} { - set v [$o info $x] - if {[string compare "" $v]} {append cmd [my pcmd [list $x $v]] " \\\n"} + Serializer instproc Class-serialize o { + set cmd [my Object-serialize $o] + set p [$o info parameter] + if {[string compare "" $p]} { + append cmd " " [my pcmd [list parameter $p]] " \\\n" + } + foreach i [$o info instprocs] { + append cmd " " [my method-serialize $o $i inst] " \\\n" + } + foreach i [$o info instforward] { + set fwd [concat [list instforward $i] [$o info instforward -definition $i]] + append cmd \t [my pcmd $fwd] " \\\n" + } + foreach x {superclass instmixin instinvar} { + set v [$o info $x] + if {[string compare "" $v] && [string compare "::xotcl::Object" $v]} { + append cmd " " [my pcmd [list $x $v]] " \\\n" + } + } + set v [$o info instfilter -guards] + if {[string compare "" $v]} {append cmd [my pcmd [list instfilter $v]] " \\\n"} + return $cmd\n } - set v [$o info filter -guards] - if {[string compare "" $v]} {append cmd [my pcmd [list filter $v]] " \\\n"} - return $cmd -} -Serializer instproc Class-serialize o { - set cmd [my Object-serialize $o] - set p [$o info parameter] - if {[string compare "" $p]} { - append cmd " " [my pcmd [list parameter $p]] " \\\n" + + Serializer instproc args {o prefix m} { + foreach v [$o info ${prefix}args $m] { + if {[$o info ${prefix}default $m $v x]} { + lappend arglist [list $v $x] } { + lappend arglist $v } + } + return $arglist } - foreach i [$o info instprocs] { - append cmd " " [my method-serialize $o $i inst] " \\\n" + Serializer instproc category c { + if {[$c istype ::Class]} {return Class} {return Object} } - foreach i [$o info instforward] { - set fwd [concat [list instforward $i] [$o info instforward -definition $i]] - append cmd \t [my pcmd $fwd] " \\\n" + Serializer instproc allChildren o { + set set $o + foreach c [$o info children] { + eval lappend set [my allChildren $c] + } + return $set } - foreach x {superclass instmixin instinvar} { - set v [$o info $x] - if {[string compare "" $v] && [string compare "::xotcl::Object" $v]} { - append cmd " " [my pcmd [list $x $v]] " \\\n" + Serializer instproc allInstances C { + set set [$C info instances] + foreach sc [$C info subclass] { + eval lappend set [my allInstances $sc] } + return $set } - set v [$o info instfilter -guards] - if {[string compare "" $v]} {append cmd [my pcmd [list instfilter $v]] " \\\n"} - return $cmd\n -} - -Serializer instproc args {o prefix m} { - foreach v [$o info ${prefix}args $m] { - if {[$o info ${prefix}default $m $v x]} { - lappend arglist [list $v $x] } { - lappend arglist $v } + + Serializer instproc topoSort {set} { + if {[my array exists s]} {my array unset s} + if {[my array exists level]} {my array unset level} + foreach c $set { + if {[string match ::xotcl::* $c] && + ![[self class] exists exportObjects($c)]} continue + if {[my exists skip($c)]} continue + my set s($c) 1 + } + set stratum 0 + while {1} { + set set [my array names s] + if {[llength $set] == 0} break + incr stratum + #puts "$stratum set=$set" + my set level($stratum) {} + foreach c $set { + if {[my [my category $c]-needsNothing $c]} { + my lappend level($stratum) $c + } + } + if {[string equal "" [my set level($stratum)]]} { + my set level($stratum) $set + my warn "Cyclic dependency in $set" + } + foreach i [my set level($stratum)] {my unset s($i)} + } } - return $arglist -} -Serializer instproc category c { - if {[$c istype ::Class]} {return Class} {return Object} -} -Serializer instproc allChildren o { - set set $o - foreach c [$o info children] { - eval lappend set [my allChildren $c] + Serializer instproc warn msg { + if {[string compare "" [info command ns_log]]} { + ns_log Notice $msg + } else { + puts stderr "!!! Warning: $msg" + } } - return $set -} -Serializer instproc allInstances C { - set set [$C info instances] - foreach sc [$C info subclass] { - eval lappend set [my allInstances $sc] + + Serializer instproc Class-needsNothing x { + if {![my Object-needsNothing $x]} {return 0} + if {[my needsOneOf [$x info superclass]]} {return 0} + if {[my needsOneOf [$x info instmixin ]]} {return 0} + return 1 } - return $set -} - -Serializer instproc topoSort {set} { - if {[my array exists s]} {my array unset s} - if {[my array exists level]} {my array unset level} - foreach c $set { - if {[regexp ^::xotcl:: $c]} continue - if {[my exists skip($c)]} continue - my set s($c) 1 + Serializer instproc Object-needsNothing x { + set p [$x info parent] + if {[string compare $p "::"] && [my needsOneOf $p]} {return 0} + if {[my needsOneOf [$x info class]]} {return 0} + if {[my needsOneOf [$x info mixin ]]} {return 0} + return 1 } - set stratum 0 - while {1} { - set set [my array names s] - if {[llength $set] == 0} break - incr stratum - #puts "$stratum set=$set" - my set level($stratum) {} - foreach c $set { - if {[my [my category $c]-needsNothing $c]} { - my lappend level($stratum) $c + Serializer instproc needsOneOf list { + foreach e $list {if {[my exists s($e)]} {return 1}} + return 0 + } + Serializer instproc serialize {objectOrClass} { + my [my category $objectOrClass]-serialize $objectOrClass + } + Serializer instproc serializeList {list} { + my topoSort $list + #foreach i [lsort [my array names level]] {puts "$i: [my set level($i)]"} + set result "" + foreach l [lsort [my array names level]] { + foreach i [my set level($l)] { + append result [string trimright [my serialize $i] "\\\n"] \n } } - if {[string equal "" [my set level($stratum)]]} { - my set level($stratum) $set - my warn "Cyclic dependency in $set" + foreach e $list { + if {[namespace exists $e]} { + set namespace($e) 1 + set namespace([namespace parent $e]) 1 + } } - foreach i [my set level($stratum)] {my unset s($i)} - } -} -Serializer instproc warn msg { - if {[string compare "" [info command ns_log]]} { - ns_log Notice $msg - } else { - puts stderr "!!! Warning: $msg" - } -} -Serializer instproc Class-needsNothing x { - if {![my Object-needsNothing $x]} {return 0} - if {[my needsOneOf [$x info superclass]]} {return 0} - if {[my needsOneOf [$x info instmixin ]]} {return 0} - return 1 -} -Serializer instproc Object-needsNothing x { - set p [$x info parent] - if {[string compare $p "::"] && [my needsOneOf $p]} {return 0} - if {[my needsOneOf [$x info class]]} {return 0} - if {[my needsOneOf [$x info mixin ]]} {return 0} - return 1 -} -Serializer instproc needsOneOf list { - foreach e $list {if {[my exists s($e)]} {return 1}} - return 0 -} -Serializer instproc serialize {objectOrClass} { - my [my category $objectOrClass]-serialize $objectOrClass -} -Serializer instproc serializeList {list} { - my topoSort $list - #foreach i [lsort [my array names level]] {puts "$i: [my set level($i)]"} - set result "" - foreach l [lsort [my array names level]] { - foreach i [my set level($l)] { - append result [string trimright [my serialize $i] "\\\n"] \n + set exports "" + set nsdefines "" + # delete ::xotcl from the namespace list, if it exists... + catch {unset namespace(::xotcl)} + foreach ns [array name namespace] { + if {![my isobject $ns]} { + append nsdefines "namespace eval $ns {}\n" + } elseif {[string compare $ns [namespace origin $ns]]} { + append nsdefines "namespace eval $ns {}\n" + } + set exp [namespace eval $ns {namespace export}] + if {[string compare "" $exp]} { + append exports "namespace eval $ns {namespace export $exp}" \n + } } + return $nsdefines$result$exports } - return $result -} -Serializer instproc deepSerialize o { - # assumes $o to be fully qualified - my serializeList [my allChildren $o] -} + Serializer instproc deepSerialize o { + # assumes $o to be fully qualified + my serializeList [my allChildren $o] + } + + Serializer proc exportMethods list { + foreach {o p m} $list {my set exportMethods($o,$p,$m) 1} + } + Serializer proc exportObjects list { + foreach o $list {my set exportObjects($o) 1} + } -Serializer proc all {args} { - set s [eval my new -childof [self] -volatile $args] - set r [$s serializeList [$s allInstances ::Object]] - my addGlobalMethods [list ::xotcl::Object proc __exitHandler] - foreach k [my array names globalExportMethods] { - foreach {o p m} [split $k ,] break - switch $p { - proc {set prefix ""} - instproc {set prefix inst} + Serializer proc all {args} { + set s [eval my new -childof [self] -volatile $args] + set r [$s serializeList [$s allInstances ::xotcl::Object]] + my exportMethods [list ::xotcl::Object proc __exitHandler] + foreach k [my array names exportMethods] { + foreach {o p m} [split $k ,] break + switch $p { + proc {set prefix ""} + instproc {set prefix inst} + } + if {[string compare "" [$o info ${prefix}procs $m]]} { + if {![info exists methods($o)]} {set methods($o) ""} + append methods($o) [$s method-serialize $o $m $prefix] " \\\n " + } } - if {[string compare "" [$o info ${prefix}procs $m]]} { - if {![info exists methods($o)]} {set methods($o) ""} - append methods($o) [$s method-serialize $o $m $prefix] " \\\n " + foreach o [array names methods] { + append r \n "$o configure \\\n " [string trimright $methods($o) "\\\n "] } + return $r } - foreach o [array names methods] { - append r \n "$o configure \\\n " [string trimright $methods($o) "\\\n "] + Serializer proc methodSerialize {object method prefix} { + set s [my new -childof [self] -volatile] + concat $object [$s unescaped-method-serialize $object $method $prefix] } - return $r -} -Serializer proc methodSerialize {object method prefix} { - set s [my new -childof [self] -volatile] - concat $object [$s unescaped-method-serialize $object $method $prefix] -} -Serializer proc deepSerialize args { - set s [my new -childof [self] -volatile] - set nr [eval $s configure $args] - foreach o [lrange $args 0 [incr nr -1]] { - append r [$s deepSerialize [$o]] + Serializer proc deepSerialize args { + set s [my new -childof [self] -volatile] + set nr [eval $s configure $args] + foreach o [lrange $args 0 [incr nr -1]] { + append r [$s deepSerialize [$o]] } - if {[$s exists map]} {return [string map [$s map] $r]} - return $r + if {[$s exists map]} {return [string map [$s map] $r]} + return $r + } } - +namespace import ${::xotcl::ns}::* +Serializer exportObjects ${::xotcl::ns}::Serializer Index: xotcl/library/serialize/pkgIndex.tcl =================================================================== diff -u -r0896d4deb00780e48b5b03269bf9c4ecca948919 -r836f3964b3b9bff2d75f7f0b5dbc7939164ba24e --- xotcl/library/serialize/pkgIndex.tcl (.../pkgIndex.tcl) (revision 0896d4deb00780e48b5b03269bf9c4ecca948919) +++ xotcl/library/serialize/pkgIndex.tcl (.../pkgIndex.tcl) (revision 836f3964b3b9bff2d75f7f0b5dbc7939164ba24e) @@ -10,4 +10,3 @@ package ifneeded xotcl::scriptCreation::recoveryPoint 0.8 [list source [file join $dir RecoveryPoint.xotcl]] package ifneeded xotcl::scriptCreation::scriptCreator 0.8 [list source [file join $dir ScriptCreator.xotcl]] -package ifneeded xotcl::serializer 0.6 [list source [file join $dir Serializer.xotcl]] Index: xotcl/xotclConfig.sh =================================================================== diff -u -r0896d4deb00780e48b5b03269bf9c4ecca948919 -r836f3964b3b9bff2d75f7f0b5dbc7939164ba24e --- xotcl/xotclConfig.sh (.../xotclConfig.sh) (revision 0896d4deb00780e48b5b03269bf9c4ecca948919) +++ xotcl/xotclConfig.sh (.../xotclConfig.sh) (revision 836f3964b3b9bff2d75f7f0b5dbc7939164ba24e) @@ -65,5 +65,5 @@ XOTCL_UNSHARED_LIB_SUFFIX=1.3.5${DBGX}.a # the shell in whose installation dirs the xotcl package is installed -XOTCL_COMPATIBLE_TCLSH=/home/neumann/tcl8.4.7/unix/tclsh +XOTCL_COMPATIBLE_TCLSH=/home/neumann/tcl8.4.9/unix/tclsh