aboutsummaryrefslogtreecommitdiff
path: root/jim.h
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2023-06-28 11:18:10 +1000
committerSteve Bennett <steveb@workware.net.au>2023-07-04 10:14:40 +1000
commit6fd2ff925d636fca8aaf5f8cd3beddfe95475b82 (patch)
tree3fce94143c663ca4f0ef05cff249670f29ed1a92 /jim.h
parentc33f287435a41fa94aa494c315ecdb628322f72a (diff)
downloadjimtcl-6fd2ff925d636fca8aaf5f8cd3beddfe95475b82.zip
jimtcl-6fd2ff925d636fca8aaf5f8cd3beddfe95475b82.tar.gz
jimtcl-6fd2ff925d636fca8aaf5f8cd3beddfe95475b82.tar.bz2
core: add support for proc statics by reference
set a 5 proc b {} {&a} { incr a } b Now a is 6 because b captured a by reference instead of by value Signed-off-by: Steve Bennett <steveb@workware.net.au>
Diffstat (limited to 'jim.h')
-rw-r--r--jim.h15
1 files changed, 8 insertions, 7 deletions
diff --git a/jim.h b/jim.h
index 98d21e2..19c94bb 100644
--- a/jim.h
+++ b/jim.h
@@ -308,7 +308,7 @@ typedef struct Jim_Obj {
} ptrIntValue;
/* Variable object */
struct {
- struct Jim_Var *varPtr;
+ struct Jim_VarVal *vv;
unsigned long callFrameId; /* for caching */
int global; /* If the variable name is globally scoped with :: */
} varValue;
@@ -458,17 +458,18 @@ typedef struct Jim_EvalFrame {
Jim_Obj *scriptObj;
} Jim_EvalFrame;
-/* The var structure. It just holds the pointer of the referenced
- * object. If linkFramePtr is not NULL the variable is a link
+/* The var structure. It holds the pointer of the referenced
+ * object and a reference count. If linkFramePtr is not NULL the variable is a link
* to a variable of name stored in objPtr living in the given callframe
* (this happens when the [global] or [upvar] command is used).
- * The interp in order to always know how to free the Jim_Obj associated
- * with a given variable because in Jim objects memory management is
+ * refCount is normally 1, but may be more than 1 if this has additional references
+ * (e.g. from proc static &var)
* bound to interpreters. */
-typedef struct Jim_Var {
+typedef struct Jim_VarVal {
Jim_Obj *objPtr;
struct Jim_CallFrame *linkFramePtr;
-} Jim_Var;
+ int refCount;
+} Jim_VarVal;
/* The cmd structure. */
typedef int Jim_CmdProc(struct Jim_Interp *interp, int argc,