summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2006-04-17 23:24:20 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2006-04-17 23:24:20 (GMT)
commit2ba107a563754126778abfe0a89b756eea5959d7 (patch)
treef519c25e6509382533c24200cd7a8636bb326959
parentaf97cb584ec0e8c2d4fc444b1b8b9883b44fe70c (diff)
downloadtcl-2ba107a563754126778abfe0a89b756eea5959d7.zip
tcl-2ba107a563754126778abfe0a89b756eea5959d7.tar.gz
tcl-2ba107a563754126778abfe0a89b756eea5959d7.tar.bz2
Baby steps towards doing the initialization right
-rw-r--r--generic/tcl.h4
-rw-r--r--generic/tclInt.h6
-rw-r--r--generic/tclOO.c82
3 files changed, 66 insertions, 26 deletions
diff --git a/generic/tcl.h b/generic/tcl.h
index fb20564..38d0c5d 100644
--- a/generic/tcl.h
+++ b/generic/tcl.h
@@ -13,7 +13,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tcl.h,v 1.210 2005/12/27 17:39:01 kennykb Exp $
+ * RCS: @(#) $Id: tcl.h,v 1.210.2.1 2006/04/17 23:24:20 dkf Exp $
*/
#ifndef _TCL
@@ -953,6 +953,8 @@ typedef struct Tcl_CallFrame {
char *dummy8;
int dummy9;
char* dummy10;
+ void* dummy11;
+ int dummy12;
} Tcl_CallFrame;
/*
diff --git a/generic/tclInt.h b/generic/tclInt.h
index fddd582..79d2604 100644
--- a/generic/tclInt.h
+++ b/generic/tclInt.h
@@ -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: tclInt.h,v 1.267.2.1 2006/04/16 21:24:10 dkf Exp $
+ * RCS: @(#) $Id: tclInt.h,v 1.267.2.2 2006/04/17 23:24:21 dkf Exp $
*/
#ifndef _TCLINT
@@ -892,10 +892,12 @@ typedef struct CallFrame {
* recognized by the compiler. The compiler
* emits code that refers to these variables
* using an index into this array. */
+ void *methodChain; /* TODO: Docme */
+ int methodChainIdx; /* TODO: Docme */
} CallFrame;
#define FRAME_IS_PROC 0x1
-#define FRAME_IS_METHOD 0x2
+#define FRAME_IS_METHOD 0x2 /* TODO: Docme */
/*
*----------------------------------------------------------------
diff --git a/generic/tclOO.c b/generic/tclOO.c
index 14e9dc5..76ea12a 100644
--- a/generic/tclOO.c
+++ b/generic/tclOO.c
@@ -8,7 +8,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclOO.c,v 1.1.2.2 2006/04/16 21:24:10 dkf Exp $
+ * RCS: @(#) $Id: tclOO.c,v 1.1.2.3 2006/04/17 23:24:21 dkf Exp $
*/
#include <tclInt.h>
@@ -95,30 +95,56 @@ typedef struct {
* Function declarations.
*/
-static Object * AllocObject(Tcl_Interp *interp);
-static int InvokeContext(Tcl_Interp *interp, Object *oPtr,
- CallContext *contextPtr, int objc,
- Tcl_Obj *const *objv);
-static int CmpStr(const void *ptr1, const void *ptr2);
-static int ObjectCmd(Object *oPtr, Tcl_Interp *interp, int objc,
- Tcl_Obj *const *objv, int publicOnly);
+static Class * AllocClass(Tcl_Interp *interp, Object *useThisObj);
+static Object * AllocObject(Tcl_Interp *interp, const char *nameStr);
static void AddClassMethodNames(Class *clsPtr, int publicOnly,
Tcl_HashTable *namesPtr);
-static CallContext * GetCallContext(Foundation *fPtr, Object *oPtr,
- Tcl_Obj *methodNameObj);
+static void AddMethodToCallChain(Tcl_HashTable *methodTablePtr,
+ Tcl_Obj *methodObj, CallContext *contextPtr,
+ int isFilter);
static void AddSimpleChainToCallContext(Object *oPtr,
Tcl_Obj *methodNameObj, CallContext *contextPtr,
int isFilter);
static void AddSimpleClassChainToCallContext(Class *classPtr,
Tcl_Obj *methodNameObj, CallContext *contextPtr,
int isFilter);
-static void AddMethodToCallChain(Tcl_HashTable *methodTablePtr,
- Tcl_Obj *methodObj, CallContext *contextPtr,
- int isFilter);
+static int CmpStr(const void *ptr1, const void *ptr2);
+static CallContext * GetCallContext(Foundation *fPtr, Object *oPtr,
+ Tcl_Obj *methodNameObj);
+static int InvokeContext(Tcl_Interp *interp, Object *oPtr,
+ CallContext *contextPtr, int idx, int objc,
+ Tcl_Obj *const *objv);
+static int ObjectCmd(Object *oPtr, Tcl_Interp *interp, int objc,
+ Tcl_Obj *const *objv, int publicOnly);
static void ObjNameChangedTrace(ClientData clientData,
Tcl_Interp *interp, const char *oldName,
const char *newName, int flags);
+void
+Oo_Init(
+ Tcl_Interp *interp)
+{
+ Interp *iPtr = (Interp *) interp;
+ Foundation *fPtr;
+
+ fPtr = iPtr->ooFoundation = (Foundation *) ckalloc(sizeof(Foundation));
+
+ fPtr->objectCls = AllocClass(interp, AllocObject(interp, "::oo::Object"));
+ fPtr->classCls = AllocClass(interp, AllocObject(interp, "::oo::Class"));
+#error Splice together classes
+ fPtr->definerCls = AllocClass(interp,
+ AllocObject(interp, "::oo::Definer"));
+ fPtr->structCls = AllocClass(interp, AllocObject(interp, "::oo::Struct"));
+#error Allocate Definer and Struct less magically?
+
+ fPtr->helpersNs = Tcl_CreateNamespace(interp, "::oo::Helpers", NULL,
+ NULL);
+ fPtr->epoch = 0;
+ fPtr->nsCount = 0;
+ fPtr->unknownMethodNameObj = Tcl_NewStringObj("unknown", -1);
+ Tcl_IncrRefCount(fPtr->unknownMethodNameObj);
+}
+
/*
* ----------------------------------------------------------------------
*
@@ -131,7 +157,9 @@ static void ObjNameChangedTrace(ClientData clientData,
*/
static Object *
-AllocObject(Tcl_Interp *interp)
+AllocObject(
+ Tcl_Interp *interp,
+ const char *nameStr)
{
Object *oPtr;
Interp *iPtr = (Interp *) interp;
@@ -156,7 +184,7 @@ AllocObject(Tcl_Interp *interp)
* Initialize the traces.
*/
- oPtr->command = Tcl_CreateEnsemble(interp, "",
+ oPtr->command = Tcl_CreateEnsemble(interp, (nameStr ? nameStr : ""),
(Tcl_Namespace *) oPtr->nsPtr, TCL_ENSEMBLE_PREFIX);
oPtr->myCommand = Tcl_CreateEnsemble(interp, "my",
(Tcl_Namespace *) oPtr->nsPtr, TCL_ENSEMBLE_PREFIX);
@@ -197,7 +225,9 @@ ObjNameChangedTrace(
*/
static Class *
-AllocClass(Tcl_Interp *interp, Object *useThisObj)
+AllocClass(
+ Tcl_Interp *interp,
+ Object *useThisObj)
{
Class *clsPtr;
Interp *iPtr = (Interp *) interp;
@@ -205,7 +235,7 @@ AllocClass(Tcl_Interp *interp, Object *useThisObj)
clsPtr = (Class *) ckalloc(sizeof(Class));
if (useThisObj == NULL) {
- clsPtr->thisPtr = AllocObject(interp);
+ clsPtr->thisPtr = AllocObject(interp, NULL);
} else {
clsPtr->thisPtr = useThisObj;
}
@@ -244,7 +274,7 @@ NewInstance(
int objc,
Tcl_Obj *objv)
{
- Object *oPtr = AllocObject(interp);
+ Object *oPtr = AllocObject(interp, NULL);
oPtr->selfCls = clsPtr;
if (clsPtr->instancesSize == 0) {
@@ -356,6 +386,7 @@ ObjectCmd(
{
Interp *iPtr = (Interp *) interp;
CallContext *contextPtr;
+ int result;
if (objc < 2) {
Tcl_WrongNumArgs(interp, 1, objv, "method ?arg ...?");
@@ -366,7 +397,10 @@ ObjectCmd(
// TODO: Cache contexts
contextPtr = GetCallContext(iPtr->ooFoundation, oPtr, objv[1]);
- return InvokeContext(interp, oPtr, contextPtr, objc, objv);
+ Tcl_Preserve(contextPtr);
+ result = InvokeContext(interp, oPtr, contextPtr, 0, objc, objv);
+ Tcl_Release(contextPtr);
+ return result;
}
static int
@@ -374,6 +408,7 @@ InvokeContext(
Tcl_Interp *interp,
Object *oPtr,
CallContext *contextPtr,
+ int idx,
int objc,
Tcl_Obj *const *objv)
{
@@ -381,9 +416,7 @@ InvokeContext(
struct MInvoke *mInvokePtr;
CallFrame *framePtr, **framePtrPtr;
-#error This function should have much in common with TclObjInterpProc
- /*
- mInvokePtr = contextPtr->callChain[0];
+ mInvokePtr = contextPtr->callChain[idx];
result = TclProcCompileProc(interp, mInvokePtr->mPtr->procPtr,
mInvokePtr->mPtr->procPtr->bodyPtr, oPtr->nsPtr, "body of method",
TclGetString(objv[1]));
@@ -397,9 +430,12 @@ InvokeContext(
if (result != TCL_OK) {
return result;
}
- */
+ framePtr->methodChain = contextPtr;
+ framePtr->methodChainIdx = 0;
+#error This function should have much in common with TclObjInterpProc
Tcl_Panic("not yet implemented");
+
return TCL_ERROR;
}