bool CRunSession::OnProcessMessage (const SArchonMessage &Msg) // OnProcessMessage // // Handle a message { // If we a reply, then process it if (m_iState == stateWaitingForHexarcReply) { // continue with execution CDatum dResult; CHexeProcess::ERunCodes iRun = m_Process.RunContinues(CSimpleEngine::MessageToHexeResult(Msg), &dResult); // Handle it return HandleResult(iRun, dResult); } // Otherwise we are done. return false; }
void CRunSession::OnMark (void) // OnMark // // Mark data in use { m_Process.Mark(); }
bool CRunSession::OnStartSession (const SArchonMessage &Msg, DWORD dwTicket) // OnStartSession // // Start the session { CDatum dCode = Msg.dPayload.GetElement(0); // Initialize the process m_Process.LoadLibrary(LIBRARY_CORE); // Parse into an expression (depending on the type of input) CDatum dExpression; if (dCode.GetBasicType() == CDatum::typeString) { CString sError; if (!CHexeDocument::ParseLispExpression(dCode, &dExpression, &sError)) { SendMessageReplyError(MSG_ERROR_UNABLE_TO_COMPLY, strPattern(ERR_COMPILER, sError)); return false; } } // Otherwise we don't know how to parse the input else { SendMessageReplyError(MSG_ERROR_UNABLE_TO_COMPLY, ERR_UNABLE_TO_PARSE_CODE); return false; } // Run the code CDatum dResult; CHexeProcess::ERunCodes iRun = m_Process.Run(dExpression, &dResult); // Deal with the result return HandleResult(iRun, dResult); }
CDatum CAeonView::ComputeColumns (CHexeProcess &Process, CDatum dRowData) // ComputeColumns // // Returns a new row struct containing any computed columns. { if (m_ComputedColumns.IsNil() || !m_ComputedColumns.CanInvoke()) return dRowData; // Compute columns. We should get back a struct of all new columns. TArray<CDatum> Args; Args.Insert(dRowData); CDatum dResult; CHexeProcess::ERunCodes iRun = Process.Run(m_ComputedColumns, Args, &dResult); switch (iRun) { case CHexeProcess::runOK: { // dResult is a struct containing zero or more columns CDatum dNewRowData(new CComplexStruct(dRowData)); dNewRowData.Append(dResult); return dNewRowData; } case CHexeProcess::runError: { CDatum dNewRowData(new CComplexStruct(dRowData)); dNewRowData.SetElement(FIELD_ERROR, strPattern("ERROR: %s", dResult.AsString())); return dNewRowData; } default: { CDatum dNewRowData(new CComplexStruct(dRowData)); dNewRowData.SetElement(FIELD_ERROR, ERR_COMPUTED_COLUMN); return dNewRowData; } } }
CString ExecuteLispCommand (const CString &sInput) { CString sOutput; CDatum dExpression; if (!CHexeDocument::ParseLispExpression(sInput, &dExpression, &sOutput)) return sOutput; CDatum dResult; CHexeProcess::ERunCodes iRun = g_Process.Run(dExpression, &dResult); switch (iRun) { case CHexeProcess::runOK: case CHexeProcess::runError: return dResult.AsString(); default: return CString("Unable to complete run."); } }
int main (int argc, char* argv[]) { CString sError; if (!CFoundation::Boot(0, &sError)) { printf("ERROR: %s\n", (LPSTR)sError); return 1; } CHexe::Boot(); g_Process.LoadLibrary(LIBRARY_CORE); // Commands SOptions Options; ParseCommandLine(argc, argv, &Options); // Do it return AI1(Options); }
bool CAeonView::InitAsSecondaryView (CDatum dDesc, CHexeProcess &Process, const CString &sRecoveryFilespec, bool bForceUpdate, CString *retsError) // InitAsSecondaryView // // Initializes a secondary view. { int i; ASSERT(m_Dims.GetCount() == 0); // Get the name m_sName = dDesc.GetElement(FIELD_NAME); m_bUsesListKeys = false; // Parse the x dimension CDatum dimDesc = dDesc.GetElement(FIELD_X); if (!dimDesc.IsNil()) { SDimensionDesc *pDimDesc = m_Dims.Insert(); CDatum *pKey = m_Keys.Insert(); if (!CAeonTable::ParseDimensionDescForSecondaryView(dimDesc, Process, pDimDesc, pKey, retsError)) { m_bInvalid = true; return false; } if (pDimDesc->iKeyType == keyListUTF8) m_bUsesListKeys = true; // Parse the y dimension dimDesc = dDesc.GetElement(FIELD_Y); if (!dimDesc.IsNil()) { pDimDesc = m_Dims.Insert(); pKey = m_Keys.Insert(); if (!CAeonTable::ParseDimensionDescForSecondaryView(dimDesc, Process, pDimDesc, pKey, retsError)) { m_bInvalid = true; return false; } if (pDimDesc->iKeyType == keyListUTF8) m_bUsesListKeys = true; // Parse z dimension dimDesc = dDesc.GetElement(FIELD_Z); if (!dimDesc.IsNil()) { pDimDesc = m_Dims.Insert(); pKey = m_Keys.Insert(); if (!CAeonTable::ParseDimensionDescForSecondaryView(dimDesc, Process, pDimDesc, pKey, retsError)) { m_bInvalid = true; return false; } if (pDimDesc->iKeyType == keyListUTF8) m_bUsesListKeys = true; } } } // If we don't have at least one dimension then this is an error else { *retsError = ERR_DIMENSIONS_REQUIRED; m_bInvalid = true; return false; } // Secondary views always have an extra dimension. We use the rowID as a // way to break ties in the other parts of the key (since secondary keys // need not be unique). SDimensionDesc *pDimDesc = m_Dims.Insert(); pDimDesc->iKeyType = keyInt64; pDimDesc->iSort = AscendingSort; // Parse columns CDatum dColumns = dDesc.GetElement(FIELD_COLUMNS); for (i = 0; i < dColumns.GetCount(); i++) { const CString &sCol = dColumns.GetElement(i); if (!sCol.IsEmpty()) m_Columns.Insert(sCol); } // Computed columns m_ComputedColumns = dDesc.GetElement(FIELD_COMPUTED_COLUMNS); // We need to set the global environment because it got loaded under a // different process. if (strEquals(m_ComputedColumns.GetTypename(), TYPENAME_HEXE_FUNCTION)) m_ComputedColumns.SetElement(FIELD_GLOBAL_ENV, Process.GetGlobalEnv()); // Exclude nil? m_bExcludeNil = !dDesc.GetElement(FIELD_EXCLUDE_NIL_KEYS).IsNil(); // Initialize rows if (!InitRows(sRecoveryFilespec, NULL, retsError)) { m_bInvalid = true; return false; } // Set up update. If we have stored an update sequence number then it means // that we are loading an old view that has not yet been fully updated. // // Otherwise we take the updating number passed in. m_bUpdateNeeded = (bForceUpdate ? true : !dDesc.GetElement(FIELD_UPDATE_NEEDED).IsNil()); // Done return true; }
bool CAeonView::CreateSecondaryKeys (CHexeProcess &Process, CDatum dData, SEQUENCENUMBER RowID, TArray<CRowKey> *retKeys) // CreateSecondaryKeys // // Creates a secondary key from the data and rowID. We return TRUE if all of // the key values are non-nil. FALSE if one or more values are nil. { int i; bool bAllValid = true; // Pull the dimensions from the data TArray<CDatum> KeyData; for (i = 0; i < m_Keys.GetCount(); i++) { CDatum dValue; CDatum dKeyDesc = m_Keys[i]; // If this is a function then we need to evaluate it. if (dKeyDesc.CanInvoke()) { TArray<CDatum> Args; Args.Insert(dData); CHexeProcess::ERunCodes iRun = Process.Run(dKeyDesc, Args, &dValue); switch (iRun) { case CHexeProcess::runOK: // dValue is a valid value for a key break; case CHexeProcess::runError: dValue = CDatum(strPattern("(%s)", dValue.AsString())); break; default: dValue = CDatum(STR_ERROR_KEY); } } // Otherwise this specifies a field in the data to use as a key else dValue = dData.GetElement((const CString &)dKeyDesc); // We don't support Nil keys, so we have to replace these with a // a special value. if (dValue.IsNil()) { dValue = CDatum(STR_EMPTY_KEY); // If we're not valid if we're excluding nil keys if (m_bExcludeNil) bAllValid = false; } // Add to list KeyData.Insert(dValue); } // Generate the keys. // If we use list keys then we need to create permuted keys retKeys->DeleteAll(); if (m_bUsesListKeys) CreatePermutedKeys(KeyData, 0, TArray<CDatum>(), RowID, retKeys); // Otherwise we just create the key normally else { CRowKey *pNewKey = retKeys->Insert(); CRowKey::CreateFromDatumAndRowID(m_Dims, KeyData, RowID, pNewKey); } // Done return bAllValid; }