Posted to tcl by dogeen at Tue Jun 29 18:39:44 GMT 2010view raw
- int
- Tcl_AssembleProc(
- ClientData dummy, /* Not used. */
- Tcl_Interp *interp, /* Current interpreter. */
- int objc, /* Number of arguments. */
- Tcl_Obj *const objv[]) /* Argument objects. */
- {
- Interp *iPtr = (Interp *) interp;
- ByteCode *byteCodePtr;
- unsigned char *p;
- int size;
- int numCommands, numSrcBytes, numCodeBytes, numLitObjects, numExceptRanges;
- int numAuxDataItems, numCmdLocBytes, maxExceptDepth, maxStackDepth;
- int objArrayBytes, exceptArrayBytes, auxDataArrayBytes;
- // LocMapSizes *locMapPtr = &envPtr->locMap;
- Namespace *namespacePtr;
-
- objArrayBytes = (1 * sizeof(Tcl_Obj *)); /* numLitObjects = 1 */
- exceptArrayBytes = (0 * sizeof(ExceptionRange)); /* numExceptRanges = 0 */
- auxDataArrayBytes = (0 * sizeof(AuxData)); /* numAuxDataItems = 0 */
-
- size = sizeof(ByteCode);
- size += TCL_ALIGN(3); /* align object array with numCodeBytes = 3 */
- size += TCL_ALIGN(objArrayBytes); /* align exception range array */
- size += TCL_ALIGN(exceptArrayBytes); /* align AuxData array */
- size += auxDataArrayBytes;
- size += 0; /* Since numCmdLocBytes is 0 */
-
- p = (unsigned char *) ckalloc((size_t) size);
- byteCodePtr = (ByteCode *) p;
- memset(byteCodePtr, 0, (size_t) size);
-
- byteCodePtr->interpHandle = TclHandlePreserve(iPtr->handle);
-
- if (iPtr->varFramePtr != NULL) {
- namespacePtr = iPtr->varFramePtr->nsPtr;
- } else {
- namespacePtr = iPtr->globalNsPtr;
- }
-
- byteCodePtr->compileEpoch = iPtr->compileEpoch;
- byteCodePtr->nsPtr = namespacePtr;
- byteCodePtr->nsEpoch = namespacePtr->resolverEpoch;
- byteCodePtr->refCount = 1;
- byteCodePtr->flags = TCL_BYTECODE_PRECOMPILED;
- byteCodePtr->procPtr = NULL;
- byteCodePtr->structureSize = 0; /* Not really 0 needs update */
- byteCodePtr->numCommands = 1; /* kbk says 1, disassemble says 0 */
-
- char noSourceCode[] = "# Created by bytecode assembler";
- byteCodePtr->source = "# Created by bytecode assembler";
- byteCodePtr->numSrcBytes = sizeof(noSourceCode);
- byteCodePtr->maxStackDepth = 1;
- byteCodePtr->maxExceptDepth = 0;
- byteCodePtr->numAuxDataItems = 0;
- byteCodePtr->numCodeBytes = 3; /* Even the empty proc has a push1 and a done
- instruction, which sum up to 3 bytes */
- byteCodePtr->numLitObjects = 1; /* Not sure about this, but disassembling
- shows, empty proc has 1 */
- byteCodePtr->numCmdLocBytes = 0; /* Not sure about this, but disassembling
- shows, empty proc has 0 */
- byteCodePtr->numExceptRanges = 0; /* Not sure about this, but disassembling
- shows, empty proc has 0 */
-
- /* This part is the same with InitByteCode, cmpRead.c of tbcload */
- p += sizeof(ByteCode);
- byteCodePtr->codeStart = p;
-
- p += TCL_ALIGN(byteCodePtr->numCodeBytes);
- if (byteCodePtr->numLitObjects > 0) {
- byteCodePtr->objArrayPtr = (Tcl_Obj **) p;
- }
-
- p += TCL_ALIGN(objArrayBytes);
- if (byteCodePtr->numExceptRanges > 0) {
- byteCodePtr->exceptArrayPtr = (ExceptionRange *) p;
- }
-
- p += TCL_ALIGN(exceptArrayBytes);
- if (byteCodePtr->numAuxDataItems > 0) {
- byteCodePtr->auxDataArrayPtr = (AuxData *) p;
- }
-
- p += auxDataArrayBytes;
- byteCodePtr->codeDeltaStart = p;
-
- /* Have no idea, how to deal with what's below, codeDeltaSize and such
- *
- p += locMapPtr->codeDeltaSize;
- byteCodePtr->codeLengthStart = p;
- p += locMapPtr->codeLengthSize;
- byteCodePtr->srcDeltaStart = p;
- if (locMapPtr->srcDeltaSize < 0) {
- p += byteCodePtr->numCommands;
- } else {
- p += locMapPtr->srcDeltaSize;
- }
- */
- byteCodePtr->srcLengthStart = p;
-
-
-
- char strbuf[50];
- int i = 0;
- for (;i < objc; i++) {
- sprintf(strbuf, " Argument %d, %s \n", i, TclGetString(objv[i]));
- Tcl_AppendResult(interp, strbuf,NULL);
- }
- return TCL_OK;
-
- }