PRT_VALUE *P_FUN_TestMachine_GetPassword_IMPL(PRT_MACHINEINST *context) { PRT_MACHINEINST_PRIV *p_tmp_mach_priv = (PRT_MACHINEINST_PRIV *)context; PRT_VALUE *p_tmp_ret = NULL; PRT_FUNSTACK_INFO p_tmp_frame; //remm to pop frame PrtPopFrame(p_tmp_mach_priv, &p_tmp_frame); //remm to free the frame PrtFreeLocals(p_tmp_mach_priv, &p_tmp_frame); return PrtMkDefaultValue(P_GEND_TYPE_StringType); }
void PrtPushNewFrame( _Inout_ PRT_MACHINEINST_PRIV *context, _In_ PRT_UINT32 funIndex, _In_ PRT_VALUE *parameters ) { PRT_UINT16 length = context->funStack.length; PrtAssert(length < PRT_MAX_FUNSTACK_DEPTH, "Fun stack overflow"); context->funStack.length = length + 1; context->funStack.funs[length].funIndex = funIndex; PRT_FUNDECL *funDecl = &(context->process->program->machines[context->instanceOf].funs[funIndex]); PRT_VALUE **locals = NULL; if (funDecl->maxNumLocals == 0) { PrtAssert(parameters == NULL && funDecl->localsNmdTupType == NULL, "Incorrect maxNumLocals value"); } else { locals = PrtCalloc(funDecl->maxNumLocals, sizeof(PRT_VALUE *)); for (PRT_UINT32 i = 0; i < funDecl->maxNumLocals; i++) { locals[i] = NULL; } PRT_UINT32 count = 0; if (parameters != NULL) { PRT_UINT32 size = parameters->valueUnion.tuple->size; for (PRT_UINT32 i = 0; i < size; i++) { locals[count] = PrtTupleGet(parameters, i); count++; } PrtFreeValue(parameters); } if (funDecl->localsNmdTupType != NULL) { PRT_UINT32 size = funDecl->localsNmdTupType->typeUnion.nmTuple->arity; for (PRT_UINT32 i = 0; i < size; i++) { PRT_TYPE *indexType = funDecl->localsNmdTupType->typeUnion.nmTuple->fieldTypes[i]; locals[count] = PrtMkDefaultValue(indexType); count++; } } } context->funStack.funs[length].locals = locals; context->funStack.funs[length].freeLocals = PRT_TRUE; context->funStack.funs[length].returnTo = 0xFFFF; context->funStack.funs[length].rcase = NULL; }
void PrtPushNewEventHandlerFrame( _Inout_ PRT_MACHINEINST_PRIV *context, _In_ PRT_UINT32 funIndex, _In_ PRT_VALUE **locals ) { PRT_UINT16 length = context->funStack.length; PrtAssert(length < PRT_MAX_FUNSTACK_DEPTH, "Fun stack overflow"); context->funStack.length = length + 1; context->funStack.funs[length].funIndex = funIndex; PRT_BOOLEAN freeLocals = (locals == NULL); PRT_FUNDECL *funDecl = &(context->process->program->machines[context->instanceOf].funs[funIndex]); if (locals == NULL && funDecl->maxNumLocals != 0) { locals = PrtCalloc(funDecl->maxNumLocals, sizeof(PRT_VALUE *)); for (PRT_UINT32 i = 0; i < funDecl->maxNumLocals; i++) { locals[i] = NULL; } } PRT_UINT32 count = funDecl->numEnvVars; if (funDecl->name == NULL) { PrtAssert(0 < count, "numEnvVars must be positive for anonymous function"); PRT_UINT32 payloadIndex = count - 1; if (locals[payloadIndex] != NULL) { PrtFreeValue(locals[payloadIndex]); } locals[payloadIndex] = PrtCloneValue(context->currentPayload); } if (funDecl->localsNmdTupType != NULL) { PRT_UINT32 size = funDecl->localsNmdTupType->typeUnion.nmTuple->arity; for (PRT_UINT32 i = 0; i < size; i++) { PRT_TYPE *indexType = funDecl->localsNmdTupType->typeUnion.nmTuple->fieldTypes[i]; if (locals[count] != NULL) { PrtFreeValue(locals[count]); } locals[count] = PrtMkDefaultValue(indexType); count++; } } context->funStack.funs[length].locals = locals; context->funStack.funs[length].freeLocals = freeLocals; context->funStack.funs[length].returnTo = 0xFFFF; context->funStack.funs[length].rcase = NULL; }
PRT_VALUE *P_FUN__CREATECONTAINER_IMPL(PRT_MACHINEINST *context, PRT_UINT32 funIndex, PRT_VALUE *value) { //first step is to get the nodeId from central node. int newNodeId = PrtDistGetNextNodeId(); //send message to the node manager on the new node to create container. int newContainerId = PrtDistCreateContainer(newNodeId); PRT_VALUE* containerMachine = PrtMkDefaultValue(PrtMkPrimitiveType(PRT_KIND_MACHINE)); containerMachine->valueUnion.mid->machineId = 1; //the first machine. containerMachine->valueUnion.mid->processId.data1 = newContainerId; containerMachine->valueUnion.mid->processId.data2 = newNodeId; return containerMachine; }
PRT_MACHINEINST_PRIV * PrtMkMachinePrivate( _Inout_ PRT_PROCESS_PRIV *process, _In_ PRT_UINT32 instanceOf, _In_ PRT_VALUE *payload ) { PRT_UINT32 packSize; PRT_UINT32 nVars; PRT_UINT8 eQSize; PRT_MACHINEINST_PRIV *context; PRT_UINT32 i; PrtLockMutex(process->processLock); nVars = process->program->machines[instanceOf].nVars; eQSize = PRT_QUEUE_LEN_DEFAULT; // // Allocate memory for state machine context // context = (PRT_MACHINEINST_PRIV*)PrtMalloc(sizeof(PRT_MACHINEINST_PRIV)); // // Add it to the array of machines in the process // PRT_UINT32 numMachines = process->numMachines; PRT_UINT32 machineCount = process->machineCount; PRT_MACHINEINST **machines = process->machines; if (machineCount == 0) { machines = (PRT_MACHINEINST **)PrtCalloc(1, sizeof(PRT_MACHINEINST *)); process->machines = machines; process->machineCount = 1; } else if (machineCount == numMachines) { PRT_MACHINEINST **newMachines = (PRT_MACHINEINST **)PrtCalloc(2 * machineCount, sizeof(PRT_MACHINEINST *)); for (PRT_UINT32 i = 0; i < machineCount; i++) { newMachines[i] = machines[i]; } PrtFree(machines); machines = newMachines; process->machines = newMachines; process->machineCount = 2 * machineCount; } machines[numMachines] = (PRT_MACHINEINST *)context; process->numMachines++; // // Initialize Machine Identity // context->process = (PRT_PROCESS *)process; context->instanceOf = instanceOf; PRT_MACHINEID id; id.machineId = process->numMachines; // index begins with 1 since 0 is reserved id.processId = process->guid; context->id = PrtMkMachineValue(id); context->extContext = NULL; context->isModel = PRT_FALSE; // // Initialize the map used in PrtDist, map from sender to the last seqnumber received // PRT_TYPE *domType = PrtMkPrimitiveType(PRT_KIND_MACHINE); PRT_TYPE *codType = PrtMkPrimitiveType(PRT_KIND_INT); PRT_TYPE *recvMapType = PrtMkMapType(domType, codType); context->recvMap = PrtMkDefaultValue(recvMapType); PrtFreeType(domType); PrtFreeType(codType); PrtFreeType(recvMapType); // Initialize Machine Internal Variables // context->currentState = process->program->machines[context->instanceOf].initStateIndex; context->isRunning = PRT_FALSE; context->isHalted = PRT_FALSE; context->lastOperation = ReturnStatement; context->currentTrigger = PrtMkEventValue(PRT_SPECIAL_EVENT_NULL); context->currentPayload = PrtCloneValue(payload); // // Allocate memory for local variables and initialize them // context->varValues = NULL; if (nVars > 0) { context->varValues = PrtCalloc(nVars, sizeof(PRT_VALUE*)); for (i = 0; i < nVars; i++) { context->varValues[i] = PrtMkDefaultValue(process->program->machines[instanceOf].vars[i].type); } } context->receive = NULL; // // Initialize various stacks // context->callStack.length = 0; context->funStack.length = 0; // // Initialize event queue // context->eventQueue.eventsSize = eQSize; context->eventQueue.events = (PRT_EVENT*)PrtCalloc(eQSize, sizeof(PRT_EVENT)); context->eventQueue.headIndex = 0; context->eventQueue.tailIndex = 0; context->eventQueue.size = 0; packSize = PrtGetPackSize(context); // // Initialize Inherited Deferred Set // context->inheritedDeferredSetCompact = (PRT_UINT32*)PrtCalloc(packSize, sizeof(PRT_UINT32)); // // Initialize the current deferred set // context->currentDeferredSetCompact = (PRT_UINT32*)PrtCalloc(packSize, sizeof(PRT_UINT32)); // // Initialize actions // context->inheritedActionSetCompact = (PRT_UINT32*)PrtCalloc(packSize, sizeof(PRT_UINT32)); context->currentActionSetCompact = (PRT_UINT32*)PrtCalloc(packSize, sizeof(PRT_UINT32)); // //Initialize state machine lock // context->stateMachineLock = PrtCreateMutex(); // //Log // PrtLog(PRT_STEP_CREATE, context); // // Allocate external context Structure // process->program->machines[context->instanceOf].extCtorFun((PRT_MACHINEINST *)context, payload); PrtUnlockMutex(process->processLock); // // Run the state machine // PrtLockMutex(context->stateMachineLock); PrtRunStateMachine(context, PRT_FALSE); return context; }