static Symbol* task_proc(NodeFunction* pFunc, ParseInfo* pinfo, std::vector<Symbol*>* pvecSyms) { if(!pFunc || !pinfo) return 0; SymbolTable *pTable = new SymbolTable(); SymbolArray arrArgs; arrArgs.SetDontDel(1); const NodeFunction *pThreadFunc = 0; RuntimeInfo *pruninfo2 = new RuntimeInfo(); pThreadFunc = (NodeFunction*)pFunc/*->clone()->optimize()*/; if(pvecSyms) arrArgs.GetArr() = *pvecSyms; arrArgs.UpdateIndices(); pTable->InsertSymbol(T_STR"<args>", &arrArgs); Symbol* pRet = pThreadFunc->eval(*pinfo, *pruninfo2, pTable); pTable->RemoveSymbolNoDelete(T_STR"<ret>"); pTable->RemoveSymbolNoDelete(T_STR"<args>"); if(pTable) delete pTable; if(pvecSyms) delete_symbols(pvecSyms); //if(pThreadFunc) delete pThreadFunc; delete pruninfo2; return pRet; }
static inline bool is_array_of_arrays(const Symbol* pSym) { if(!pSym) return 0; if(pSym->GetType()!=SYMBOL_ARRAY) return 0; SymbolArray* pSymArr = (SymbolArray*)pSym; if(pSymArr->GetArr().size()==0) return 0; Symbol* pSymInArr = pSymArr->GetArr()[0]; return (pSymInArr->GetType()==SYMBOL_ARRAY); }
void UnitType::GetUsedArray(SymbolArray &array) { UnitString *pSymbol = NULL; array.RemoveAll(); POSITION pos = m_symbolList.GetHeadPosition(); while(pos) { pSymbol = m_symbolList.GetNext(pos); if(pSymbol->IsUsed()) { array.Add(pSymbol->GetSymbol()); } } }
BOOL CheckTextSize( SymbolArray &text, int Threshold ) { if(text.GetSize() < Threshold ) { Message(IDS_STRING_ERR_INPUT_TEXT_LENGTH, MB_ICONEXCLAMATION, Threshold); return FALSE; } return TRUE; }
/************************************************************************ 版本: 8.0 注释时间: [2009/4/21] 作者: [Zhufy] 评审人: 功能: 根据所选中的列初始化单位列表 输入: 输出: < 修改人 > < 时间 > < 版本 > < 描述 > ************************************************************************/ void PageJunOutControl::OnLvnItemchangedListShowout(NMHDR *pNMHDR, LRESULT *pResult) { LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR); POSITION pos = m_lstShowAtt.GetFirstSelectedItemPosition(); if ( pos == NULL ) { return; } int nItem = m_lstShowAtt.GetNextSelectedItem( pos ); int nKey = (int)m_lstShowAtt.GetItemData(nItem); if ( -1 == nKey ) { return; } CString strKey; strKey.Format( _T("%d") , nKey ); OutMgr &outMgr = m_outModel.SteadyOut().ComponentOutMgr().JunOutMgr(); OutAttrArray& AttArr = outMgr.GetArray(); OutDataAttr &dataAttr = AttArr.GetAt( 0 ); int i; for(i = 0; i < 30; i++) { if ( strKey != _T("0") && strKey == outMgr.m_OutPutSys.GetJunOutArray()[i].GetKey()) { dataAttr = AttArr.GetAt( i + 1 ); break; } } m_comboUnit.ResetContent(); SymbolArray array; UnitSubSystem &system = dataAttr.UnitSys(); UnitTypeID id = dataAttr.UnitType(); CString m_strCurSymbol = dataAttr.Unit(); system.FindSymbolArray( id,array ); for( i=0;i<array.GetSize();i++ ) { m_comboUnit.AddString( array.GetAt(i) ); } m_comboUnit.SelectString( -1,m_strCurSymbol ); *pResult = 0; }
BOOL DlgChangeUnit::OnInitDialog() { CDialog::OnInitDialog(); // TODO: Add extra initialization here m_list.ResetContent(); SymbolArray array; UnitSubSystem &system = m_outAttr.UnitSys(); UnitTypeID id = m_outAttr.UnitType(); CString m_strCurSymbol = m_outAttr.Unit(); system.FindSymbolArray(id,array); for(int i=0;i<array.GetSize();i++) { m_list.AddString(array.GetAt(i)); } m_list.SelectString(-1,m_strCurSymbol); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }
void compileFunction(Symbol functionDefinitionStatement) { if (functionDefinitionStatement.cache<FunctionDefinitionCache>()-> getCompilingFlag()) { // TODO: Give more details about what's being evaluated and how that came to call this spanOf(functionDefinitionStatement).end().throwError( "Function called during its own compilation"); } functionDefinitionStatement.cache<FunctionDefinitionCache>()-> setCompilingFlag(true); _epilogueStack.push(SymbolLabel()); //Symbol type = typeOf(functionDefinitionStatement); //Symbol returnType = type[1].symbol(); //_returnTypeStack.push(returnType); int stackAdjust = offsetOf(functionDefinitionStatement); if (stackAdjust != 0) addAdjustStackPointer(-stackAdjust); _stackOffset = 0; compileStatementSequence(functionDefinitionStatement[4].array()); Symbol type = typeOf(functionDefinitionStatement); Symbol returnType = type[1].symbol(); int returnTypeSize = (sizeOf(returnType) + 3) & -4; int parametersSize = 0; SymbolArray parameterTypes = type[2].array(); for (int i = 0; i < parameterTypes.count(); ++i) parametersSize += (sizeOf(parameterTypes[i]) + 3) & -4; if (_reachable && returnType.atom() != atomVoid) { // TODO: Give more details about how it got there spanOf(functionDefinitionStatement).end().throwError( "Control reaches end of non-Void function"); } addLabel(_epilogueStack.pop()); addLoadWordFromStackRelativeAddress(returnTypeSize + stackAdjust); addMoveBlock(0, stackAdjust + 4 + parametersSize, 1 + returnTypeSize/4); if (stackAdjust != 0) addAdjustStackPointer(stackAdjust); add(Symbol(atomReturn)); //_returnTypeStack.pop(); functionDefinitionStatement.cache<FunctionDefinitionCache>()->setCompilingFlag(false); functionDefinitionStatement[5].label().setTarget(_firstBasicBlock.target()); }
// execute script static inline int script_main(int argc, char** argv) { if(argc<=1) { usage(argv[0]); return -1; } bool bShowSymbols = 0; bool bInteractive = 0; unsigned int uiDebugLevel = 3; #ifndef NDEBUG uiDebugLevel = 4; #endif unsigned int iStartArg = 1; for(iStartArg=1; iStartArg<unsigned(argc); ++iStartArg) { t_string strArg = STR_TO_WSTR(argv[iStartArg]); tl::trim(strArg); // end of arguments to hermelin if(strArg[0] != T_STR'-') break; if(strArg=="-s" || strArg == "--symbols") bShowSymbols = 1; else if(strArg=="-i" || strArg == "--interactive") bInteractive = 1; else if(strArg=="-h" || strArg == "--help") { usage(argv[0]); return 0; } else if(strArg=="-d0") uiDebugLevel = 0; else if(strArg=="-d1") uiDebugLevel = 1; else if(strArg=="-d2") uiDebugLevel = 2; else if(strArg=="-d3") uiDebugLevel = 3; else if(strArg=="-d4") uiDebugLevel = 4; } const std::array<tl::Log*, 5> arrLogs{{&tl::log_crit, &tl::log_err, &tl::log_warn, &tl::log_info, &tl::log_debug}}; for(unsigned int iLog=0; iLog<arrLogs.size(); ++iLog) arrLogs[iLog]->SetEnabled(uiDebugLevel>=iLog); // debug in script.yy needs to be set yydebug = (uiDebugLevel>=4); if(bInteractive) return interactive(bShowSymbols, uiDebugLevel); if(iStartArg >= unsigned(argc)) { tl::log_err("No input file given."); return -1; } // loading of input file const char* pcFile = argv[iStartArg]; t_string strFile = STR_TO_WSTR(pcFile); t_char* pcInput = load_file(pcFile); if(!pcInput) return -2; ParseObj par; ParseInfo info; RuntimeInfo runinfo; info.bEnableDebug = (uiDebugLevel>=4); // lexing par.strCurFile = strFile; par.pLexer = new Lexer(pcInput, strFile.c_str()); delete[] pcInput; pcInput = 0; if(!par.pLexer->IsOk()) { tl::log_err("Lexer returned with errors."); return -3; } init_global_syms(info.pGlobalSyms); // parsing int iParseRet = yyparse(&par); delete par.pLexer; par.pLexer = 0; if(iParseRet != 0) { tl::log_err("Parser returned with error code ", iParseRet, "."); return -4; } // optimizing par.pRoot = par.pRoot->optimize(); // executing SymbolArray *parrMainArgs = new SymbolArray(); for(int iArg=iStartArg; iArg<argc; ++iArg) { SymbolString *pSymArg = new SymbolString(); pSymArg->SetVal(STR_TO_WSTR(argv[iArg])); parrMainArgs->GetArr().push_back(pSymArg); } //std::vector<Symbol*> vecMainArgs = { &arrMainArgs }; SymbolTable *pTableSup = new SymbolTable(); info.pmapModules->insert(ParseInfo::t_mods::value_type(strFile, par.pRoot)); runinfo.strExecFkt = T_STR"main"; //info.pvecExecArg = &vecMainArgs; runinfo.strInitScrFile = strFile; SymbolArray arrMainArgs; arrMainArgs.GetArr().push_back(parrMainArgs); pTableSup->InsertSymbol(T_STR"<args>", &arrMainArgs); par.pRoot->eval(info, runinfo, pTableSup); pTableSup->RemoveSymbolNoDelete(T_STR"<args>"); delete pTableSup; if(bShowSymbols) { tl::log_info("================================================================================"); tl::log_info("Global symbols:"); info.pGlobalSyms->print(); std::ostringstream ostrFkts; for(const NodeFunction* pFunc : info.vecFuncs) ostrFkts << pFunc->GetName() << ", "; tl::log_info("Script functions: ", ostrFkts.str()); const t_mapFkts* pExtFkts = get_ext_calls(); std::ostringstream ostrSysFkts; for(const auto& fktpair : *pExtFkts) ostrSysFkts << fktpair.first << ", "; tl::log_info("System functions: ", ostrSysFkts.str()); tl::log_info("================================================================================"); } return 0; }
void checkTypes(SymbolEntry entry, Symbol returnType) { if (entry.isArray()) { SymbolList list; SymbolArray array = entry.array(); for (int i = 0; i < array.count(); ++i) checkTypes(array[i], returnType); } if (!entry.isSymbol()) return; Symbol symbol = entry.symbol(); switch (symbol.atom()) { case atomLogicalOr: case atomLogicalAnd: assertTypeBoolean(symbol[1].symbol()); assertTypeBoolean(symbol[2].symbol()); break; case atomFunctionCall: { Symbol function = symbol[1].symbol(); SymbolArray parameterTypes = typeOf(function)[2].array(); SymbolArray argumentTypes = typeOf(symbol[2]).array(); if (parameterTypes != argumentTypes) spanOf(symbol).throwError( "function requires arguments of types " + typesToString(parameterTypes) + " but passed arguments of types " + typesToString(argumentTypes)); } break; case atomFunctionDefinitionStatement: checkTypes(symbol[3], returnType); checkTypes(symbol[4], symbol[1].symbol()); return; case atomVariableDefinitionStatement: { Symbol initializerType = typeOf(symbol[3]); Symbol variableType = typeOf(symbol[1]); if (variableType != initializerType) spanOf(symbol).throwError("variable declared as type " + typeToString(variableType) + " but initialized with expression of type " + typeToString(initializerType)); } break; case atomIfStatement: assertTypeBoolean(symbol[1].symbol()); break; case atomSwitchStatement: { Symbol type = typeOf(symbol[1]); SymbolArray cases = symbol[2].array(); for (int i = 0; i < cases.count(); ++i) { Symbol c = cases[i]; SymbolArray expressions = c[1].array(); for (int j = 0; j < expressions.count(); ++j) { Symbol expression = expressions[j]; Symbol expressionType = typeOf(expression); if (type != expressionType) spanOf(expression).throwError( "can't compare an expression of type " + typeToString(type) + " to an expression of type " + typeToString(expressionType)); } } } break; case atomReturnStatement: { Symbol expression = symbol[1].symbol(); Symbol type; if (expression.valid()) type = typeOf(expression); else type = Symbol(atomVoid); if (type != returnType) spanOf(symbol).throwError( "returning an expression of type " + typeToString(type) + " from a function with return type " + typeToString(returnType)); } break; case atomIncludeStatement: { Symbol expression = symbol[1].symbol(); Symbol type = typeOf(expression); if (type.atom() != atomString) spanOf(expression).throwError( "argument to include is of type " + typeToString(type) + ", expected String"); } break; case atomFromStatement: { Symbol expression = symbol[1].symbol(); Symbol type = typeOf(expression); if (type.atom() != atomString) spanOf(expression).throwError( "argument to from is of type " + typeToString(type) + ", expected String"); } break; case atomWhileStatement: case atomUntilStatement: case atomForStatement: assertTypeBoolean(symbol[2].symbol()); break; case atomGotoStatement: { Symbol expression = symbol[1].symbol(); Symbol type = typeOf(expression); if (type.atom() != atomLabel) if (type.atom() != atomLabel) spanOf(expression).throwError( "expression is of type " + typeToString(type) + ", Label expected"); } break; case atomEmit: // TODO: Check that type of argument is Sequence<Compiler.Instruction> break; } const SymbolTail* tail = symbol.tail(); while (tail != 0) { checkTypes(tail->head(), returnType); tail = tail->tail(); } }
// nthread(iNumThreads, strFunc, vecArgs, ...) static Symbol* fkt_nthread(const std::vector<Symbol*>& vecSyms, ParseInfo& info, RuntimeInfo &runinfo, SymbolTable* pSymTab) { if(vecSyms.size()<3) { std::ostringstream ostrErr; ostrErr << linenr(runinfo) << "nthread needs at least 3 arguments: N, func, arg." << std::endl; throw tl::Err(ostrErr.str(),0); } Symbol* _pSymN = vecSyms[0]; if(_pSymN->GetType() != SYMBOL_INT) { std::ostringstream ostrErr; ostrErr << linenr(runinfo) << "Number of threads has to be integer." << std::endl; throw tl::Err(ostrErr.str(),0); } SymbolInt *pSymN = (SymbolInt*)_pSymN; t_int iNumThreads = pSymN->GetVal(); Symbol* _pSymIdent = vecSyms[1]; if(_pSymIdent->GetType() != SYMBOL_STRING) { std::ostringstream ostrErr; ostrErr << linenr(runinfo) << "Thread proc identifier needs to be a string." << std::endl; throw tl::Err(ostrErr.str(), 0); } SymbolString *pSymIdent = (SymbolString*)_pSymIdent; const t_string& strIdent = pSymIdent->GetVal(); Symbol* _pSymArr = vecSyms[2]; if(_pSymArr->GetType() != SYMBOL_ARRAY) { std::ostringstream ostrErr; ostrErr << linenr(runinfo) << "Thread arg has to be an array." << std::endl; throw tl::Err(ostrErr.str(), 0); } SymbolArray *pSymArr = (SymbolArray*)_pSymArr; const std::vector<Symbol*>& vecArr = pSymArr->GetArr(); NodeFunction* pFunc = info.GetFunction(strIdent); if(pFunc == 0) { std::ostringstream ostrErr; ostrErr << linenr(runinfo) << "Thread proc \"" << strIdent << "\" not defined." << std::endl; throw tl::Err(ostrErr.str(), 0); } if(iNumThreads > int(vecArr.size())) { iNumThreads = vecArr.size(); tl::log_warn(linenr(runinfo), "More threads requested in nthread than necessary, ", "reducing to array size (", iNumThreads, ")."); } std::vector<SymbolArray*> vecSymArrays; vecSymArrays.resize(iNumThreads); t_int iCurTh = 0; for(Symbol* pThisSym : vecArr) { if(!vecSymArrays[iCurTh]) vecSymArrays[iCurTh] = new SymbolArray(); vecSymArrays[iCurTh]->GetArr().push_back(pThisSym->clone()); vecSymArrays[iCurTh]->UpdateLastNIndices(1); ++iCurTh; if(iCurTh == iNumThreads) iCurTh = 0; } std::vector<std::thread*> vecThreads; vecThreads.reserve(iNumThreads); for(iCurTh=0; iCurTh<iNumThreads; ++iCurTh) { std::vector<Symbol*>* vecThreadSyms = new std::vector<Symbol*>; vecThreadSyms->reserve(vecSyms.size()-3+1); vecThreadSyms->push_back(vecSymArrays[iCurTh]); for(unsigned int iSym=3; iSym<vecSyms.size(); ++iSym) vecThreadSyms->push_back(vecSyms[iSym]->clone()); std::thread *pth = new std::thread(::thread_proc, pFunc, &info, vecThreadSyms); vecThreads.push_back(pth); } /* // automatically join for(iCurTh=0; iCurTh<iNumThreads; ++iCurTh) { vecThreads[iCurTh]->join(); delete vecThreads[iCurTh]; vecThreads[iCurTh] = 0; }*/ SymbolArray* pArrThreads = new SymbolArray(); for(iCurTh=0; iCurTh<iNumThreads; ++iCurTh) { std::thread* pCurThread = vecThreads[iCurTh]; t_int iHandle = info.phandles->AddHandle(new HandleThread(pCurThread)); SymbolInt *pSymThreadHandle = new SymbolInt(iHandle); pArrThreads->GetArr().push_back(pSymThreadHandle); } pArrThreads->UpdateIndices(); return pArrThreads; }
LFSR::LFSR(const SymbolArray& Vec) : m_Coeff(0), m_State(0), m_InitialState(0) { m_Modulus=Vec.GetModulus(); m_Coeff.Copy(Vec); SetState(); }
void LoadText( const char *infile, SymbolArray &text ) { CWaitCursor WCursor; text.Read(infile); WCursor.Restore(); }