当前位置: 首页>>代码示例>>C++>>正文


C++ TObject::getClass方法代码示例

本文整理汇总了C++中TObject::getClass方法的典型用法代码示例。如果您正苦于以下问题:C++ TObject::getClass方法的具体用法?C++ TObject::getClass怎么用?C++ TObject::getClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TObject的用法示例。


在下文中一共展示了TObject::getClass方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: doSendMessage

void SmalltalkVM::doSendMessage(TVMExecutionContext& ec, TSymbol* selector, TObjectArray* arguments, TClass* receiverClass /*= 0*/ )
{
    hptr<TObjectArray> messageArguments = newPointer(arguments);

    if (!receiverClass) {
        TObject* receiver = messageArguments[0];
        assert(receiver != 0);
        receiverClass = isSmallInteger(receiver) ? globals.smallIntClass : receiver->getClass();
        assert(receiverClass != 0);
    }

    hptr<TMethod> receiverMethod = newPointer(lookupMethod(selector, receiverClass));

    // Checking whether we found a method
    if (receiverMethod == 0) {
        // Oops. Method was not found. In this case we should send #doesNotUnderstand: message to the receiver
        setupVarsForDoesNotUnderstand(receiverMethod, messageArguments, selector, receiverClass);
        // Continuing the execution just as if #doesNotUnderstand: was the actual selector that we wanted to call
    }

    // Save stack and opcode pointers
    ec.storePointers();

    // Create a new context for the giving method and arguments
    hptr<TContext>   newContext = newObject<TContext>();
    hptr<TObjectArray> newStack = newObject<TObjectArray>(receiverMethod->stackSize);
    hptr<TObjectArray> newTemps = newObject<TObjectArray>(receiverMethod->temporarySize);

    newContext->stack           = newStack;
    newContext->temporaries     = newTemps;
    newContext->arguments       = messageArguments;
    newContext->method          = receiverMethod;
    newContext->stackTop        = 0;
    newContext->bytePointer     = 0;

    // Suppose that current send message operation is last operation in the current context.
    // If it is true then next instruction will be either stackReturn or blockReturn.
    //
    // VM will switch to the newContext, perform it and then switch back to the current context
    // for the single one return instruction. This is pretty dumb to load the whole context
    // just to exit it immediately. Therefore, we looking one instruction ahead to see if it is
    // a return instruction. If it is, we may skip our context and set our previousContext as
    // previousContext for the newContext. In case of blockReturn it will be the previousContext
    // of the wrapping method context.

    uint8_t nextInstruction = ec.currentContext->method->byteCodes->getByte(ec.bytePointer);
    if (nextInstruction == (opcode::doSpecial * 16 + special::stackReturn)) {
        // Optimizing stack return
        newContext->previousContext = ec.currentContext->previousContext;
    } else if (nextInstruction == (opcode::doSpecial * 16 + special::blockReturn) &&
              (ec.currentContext->getClass() == globals.blockClass))
    {
        // Optimizing block return
        newContext->previousContext = ec.currentContext.cast<TBlock>()->creatingContext->previousContext;
    } else {
        newContext->previousContext = ec.currentContext;
    }
    // Replace current context with the new one. On the next iteration,
    // VM will start interpreting instructions from the new context.
    ec.currentContext = newContext;
    ec.loadPointers();

    m_messagesSent++;
}
开发者ID:0x7CFE,项目名称:llst,代码行数:64,代码来源:vm.cpp


注:本文中的TObject::getClass方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。