Exemple #1
0
    GameAsset* Script::Create(StreamReader& reader, GameAsset* /*existingInstance*/)
    {
        const int length = reader.ReadInt();

        Buffer buffer;
        buffer.resize(length);

        reader.Read(&buffer[0], length);
        const int numberOfFunctions = reader.ReadInt();
        FunctionTable functionTable;
        functionTable.resize(numberOfFunctions);
        for (int i = 0; i < numberOfFunctions; i++)
        {
            Function& item = functionTable[i];
            item.Name = reader.ReadString();
            item.Position = reader.ReadInt();
            item.ArgumentStackSize = reader.ReadInt();
            item.ReturnTypes.resize(reader.ReadInt());
            for (std::vector<AnyType>::size_type i = 0; i < item.ReturnTypes.size(); i++)
                item.ReturnTypes[i] = static_cast<AnyType>(reader.ReadInt());
            item.ParameterTypes.resize(reader.ReadInt());
            for (std::vector<AnyType>::size_type i = 0; i < item.ParameterTypes.size(); i++)
                item.ParameterTypes[i] = static_cast<AnyType>(reader.ReadInt());
        }

        const int numberOfStrings = reader.ReadInt();
        StringCollection stringTable;
        stringTable.reserve(numberOfStrings);
        for (int i = 0; i < numberOfStrings; i++)
            stringTable.push_back(reader.ReadString());

        return new Script(buffer, functionTable, stringTable, MoveTag());
    }
/** Copy constructor */
FunctionTable::FunctionTable(const FunctionTable& x) {
    
    for (std::multimap<std::string, Function *>::const_iterator it=x.begin(); it!=x.end(); ++it)
    {
        insert(std::pair<std::string, Function *>( it->first, ( it->second->clone() )));
    }
    parentTable = x.parentTable;
}
Exemple #3
0
/** Copy constructor */
FunctionTable::FunctionTable(const FunctionTable& x) {
    
    for (std::multimap<std::string, Function *>::const_iterator i=x.begin(); i!=x.end(); i++)
    {
        insert(std::pair<std::string, Function *>( (*i).first, ( (*i).second->clone() )));
    }
    parentTable = x.parentTable;
}
Exemple #4
0
//
// ObjectData::Function::Iterate
//
void Function::Iterate(IterFunc iterFunc, std::ostream *out)
{
   FunctionIter iter;

   for(iter = Table.begin(); iter != Table.end(); ++iter)
   {
      if (iter->second.context)
         iter->second.varCount = iter->second.context->getLimit(STORE_REGISTER);

      iterFunc(out, iter->second);
   }
}
void initDir() {
  FunctionEntry<pFun> funs[] = {
    "end",dirEND,
    "code",dirCODE,
    "module",dirMODULE,
    "endmodule",dirENDMODULE,
    "page",dirPAGE,
    "defpage",dirDEFPAGE,
    "##",dirMAPALIGN,
    "mapalign",dirMAPALIGN,
    "map",dirMAP,
    "endmap",dirENDMAP,
    "align",dirALIGN,
    "phase",dirPHASE,
    "dephase",dirDEPHASE,
    "incbin",/*dirINCBIN,*/ dirINCBINDOT,
    "output",dirOUTPUT,
    "update",dirUPDATE,
    "incdir",dirINCDIR,
    "assert",dirASSERT,
    "org",dirORG,
    "size",dirSIZE,
    "error",dirERROR,

    "z80",dirZ80,
#ifdef METARM
    "thumb",dirTHUMB,
    "arm",dirARM,
#endif

    "incbin.",dirINCBINDOT,
  };
  dirfuntab.init(funs, sizeof funs/sizeof funs[0]);
}
Exemple #6
0
//
// ObjectData::Function::GenerateSymbols
//
void Function::GenerateSymbols()
{
   ObjectExpression::Pointer obj;
   FunctionIter iter;
   bigsint number = 0;

   // If not set yet, generate varCount.
   for(iter = Table.begin(); iter != Table.end(); ++iter)
   {
      if(iter->second.context)
         iter->second.varCount = iter->second.context->getLimit(STORE_REGISTER);
   }

   for(iter = Table.begin(); iter != Table.end(); ++iter)
   {
      iter->second.number = ++number;

      obj = ObjectExpression::CreateValueUNS(iter->second.number, SourcePosition::none());

      ObjectExpression::add_symbol(iter->second.name, obj);
   }
}
Exemple #7
0
void BuiltinFunctions::declare(FunctionTable& ft)
{
    ft.add(print_);
    ft.add(getInt32_);
    ft.add(operatorMinusInt32_);
    ft.add(operatorMinusInt32Int32_);
    ft.add(operatorPlusInt32Int32_);
    ft.add(operatorMultInt32Int32_);
    ft.add(operatorDivInt32Int32_);
    ft.add(operatorModInt32Int32_);
}
Exemple #8
0
void Compile(const char* databasePathName, const char* cpuArchName, const char* imageFormatName, const char* outputPath)
{
	CPsfVm virtualMachine;
	auto subSystem = std::make_shared<Iop::CPsfSubSystem>(false);
	virtualMachine.SetSubSystem(subSystem);

	Jitter::CCodeGen* codeGen = nullptr;
	Jitter::CObjectFile::CPU_ARCH cpuArch = Jitter::CObjectFile::CPU_ARCH_X86;
	if(!strcmp(cpuArchName, "x86"))
	{
		codeGen = new Jitter::CCodeGen_x86_32();
		cpuArch = Jitter::CObjectFile::CPU_ARCH_X86;
	}
	else if(!strcmp(cpuArchName, "arm"))
	{
		codeGen = new Jitter::CCodeGen_Arm();
		cpuArch = Jitter::CObjectFile::CPU_ARCH_ARM;
	}
	else
	{
		throw std::runtime_error("Invalid cpu target.");
	}

	std::unique_ptr<Jitter::CObjectFile> objectFile;
	if(!strcmp(imageFormatName, "coff"))
	{
		objectFile = std::make_unique<Jitter::CCoffObjectFile>(cpuArch);
	}
	else if(!strcmp(imageFormatName, "macho"))
	{
		objectFile = std::make_unique<Jitter::CMachoObjectFile>(cpuArch);
	}
	else
	{
		throw std::runtime_error("Invalid executable image type (must be coff or macho).");
	}

	codeGen->RegisterExternalSymbols(objectFile.get());
	objectFile->AddExternalSymbol("_MemoryUtils_GetByteProxy", &MemoryUtils_GetByteProxy);
	objectFile->AddExternalSymbol("_MemoryUtils_GetHalfProxy", &MemoryUtils_GetHalfProxy);
	objectFile->AddExternalSymbol("_MemoryUtils_GetWordProxy", &MemoryUtils_GetWordProxy);
	objectFile->AddExternalSymbol("_MemoryUtils_SetByteProxy", &MemoryUtils_SetByteProxy);
	objectFile->AddExternalSymbol("_MemoryUtils_SetHalfProxy", &MemoryUtils_SetHalfProxy);
	objectFile->AddExternalSymbol("_MemoryUtils_SetWordProxy", &MemoryUtils_SetWordProxy);
	objectFile->AddExternalSymbol("_LWL_Proxy", &LWL_Proxy);
	objectFile->AddExternalSymbol("_LWR_Proxy", &LWR_Proxy);
	objectFile->AddExternalSymbol("_SWL_Proxy", &SWL_Proxy);
	objectFile->AddExternalSymbol("_SWR_Proxy", &SWR_Proxy);

	filesystem::path databasePath(databasePathName);
	auto blocks = GetBlocksFromCache(databasePath);

	//Initialize Jitter Service
	auto jitter = new CMipsJitter(codeGen);
	for(unsigned int i = 0; i < 4; i++)
	{
		jitter->SetVariableAsConstant(
			offsetof(CMIPS, m_State.nGPR[CMIPS::R0].nV[i]),
			0
			);
	}

	printf("Got %d blocks to compile.\r\n", blocks.size());

	FunctionTable functionTable;
	functionTable.reserve(blocks.size());

	for(const auto& blockCachePair : blocks)
	{
		const auto& blockKey = blockCachePair.first;

		auto functionName = "aotblock_" + std::to_string(blockKey.crc) + "_" + std::to_string(blockKey.begin) + "_" + std::to_string(blockKey.end);

		unsigned int functionSymbolIndex = CompileFunction(virtualMachine, jitter, blockCachePair.second, *objectFile, functionName, blockKey.begin, blockKey.end);

		FUNCTION_TABLE_ITEM tableItem = { blockKey, functionSymbolIndex };
		functionTable.push_back(tableItem);
	}

	std::sort(functionTable.begin(), functionTable.end(), 
		[] (const FUNCTION_TABLE_ITEM& item1, const FUNCTION_TABLE_ITEM& item2)
		{
			return item1.key < item2.key;
		}
	);

	{
		Framework::CMemStream blockTableStream;
		Jitter::CObjectFile::INTERNAL_SYMBOL blockTableSymbol;
		blockTableSymbol.name		= "__aot_firstBlock";
		blockTableSymbol.location	= Jitter::CObjectFile::INTERNAL_SYMBOL_LOCATION_DATA;

		for(const auto& functionTableItem : functionTable)
		{
			blockTableStream.Write32(functionTableItem.key.crc);
			blockTableStream.Write32(functionTableItem.key.begin);
			blockTableStream.Write32(functionTableItem.key.end);
			
			{
				Jitter::CObjectFile::SYMBOL_REFERENCE ref;
				ref.offset		= static_cast<uint32>(blockTableStream.Tell());
				ref.type		= Jitter::CObjectFile::SYMBOL_TYPE_INTERNAL;
				ref.symbolIndex	= functionTableItem.symbolIndex;
				blockTableSymbol.symbolReferences.push_back(ref);
			}

			blockTableStream.Write32(0);
		}

		blockTableSymbol.data = std::vector<uint8>(blockTableStream.GetBuffer(), blockTableStream.GetBuffer() + blockTableStream.GetLength());
		objectFile->AddInternalSymbol(blockTableSymbol);
	}

	{
		Jitter::CObjectFile::INTERNAL_SYMBOL blockCountSymbol;
		blockCountSymbol.name		= "__aot_blockCount";
		blockCountSymbol.location	= Jitter::CObjectFile::INTERNAL_SYMBOL_LOCATION_DATA;
		blockCountSymbol.data		= std::vector<uint8>(4);
		*reinterpret_cast<uint32*>(blockCountSymbol.data.data()) = functionTable.size();
		objectFile->AddInternalSymbol(blockCountSymbol);
	}

	objectFile->Write(Framework::CStdStream(outputPath, "wb"));
}
void initpreprocessor() {
    FunctionEntry<pFun> group1if[] = {
        "ifdef",preIFDEF,
        "ifndef",preIFNDEF,
        "else",preELSE,
        "endif",preENDIF,

        "elseifdef",preELSEIFDEF,
        "elseifndef",preELSEIFNDEF,
    };

    FunctionEntry<pFun> group2if[] = {
        "if",preIF,
        "ifidn",preIFIDN,
        "ifidni",preIFIDNI,
        "ifdif",preIFDIF,
        "ifdifi",preIFDIFI,
        "ifb",preIFB,
        "ifid",preIFID,
        "ifstr",preIFSTR,
        "ifnum",preIFNUM,
        "ifnb",preIFNB,
        "ifnid",preIFNID,
        "ifnstr",preIFNSTR,
        "ifnnum",preIFNNUM,
        "ifexists",preIFEXISTS,
        "ifnexists",preIFNEXISTS,
        "ifin",preIFIN,
        "ifini",preIFINI,

        "elseif",preELSEIF,
        "elseifidn",preELSEIFIDN,
        "elseifidni",preELSEIFIDNI,
        "elseifdif",preELSEIFDIF,
        "elseifdifi",preELSEIFDIFI,
        "elseifb",preELSEIFB,
        "elseifid",preELSEIFID,
        "elseifstr",preELSEIFSTR,
        "elseifnum",preELSEIFNUM,
        "elseifnb",preELSEIFNB,
        "elseifnid",preELSEIFNID,
        "elseifnstr",preELSEIFNSTR,
        "elseifnnum",preELSEIFNNUM,
        "elseifexists",preELSEIFEXISTS,
        "elseifnexists",preELSEIFNEXISTS,
        "elseifin",preELSEIFIN,
        "elseifini",preELSEIFINI,
    };

    FunctionEntry<pFun> group1[] = {
        "define",preDEFINE,
        "idefine",preIDEFINE,
        "xdefine",preXDEFINE,
        "xidefine",preXIDEFINE,
        "undef",preUNDEF,
        "assign",preASSIGN,

        "tostr",preTOSTR,
        "strlen",preSTRLEN,
        "substr",preSUBSTR,
    };

    FunctionEntry<pFun> group2[] = {
        "include",preINCLUDE,

        "macro",preMACRODOT,
        "imacro",preIMACRODOT,
        "rotate",preROTATE,
        "while",preWHILEDOT,
        "repeat",preREPEATDOT,
        "break",preBREAK,
        "continue",preCONTINUE,
        "exitmacro",preEXITMACRO,
        "xexitmacro",preXEXITMACRO,
        "struct",preSTRUCT,

        "macro.",preMACRODOT,
        "imacro.",preIMACRODOT,
        "while.",preWHILEDOT,
        "repeat.",preREPEATDOT,

        "endmacro",preENDMACRO,
        "endwhile",preENDWHILE,
        "endrepeat",preENDREPEAT,
        "endstruct",preENDSTRUCT,

        "endm",preENDMACRO,
        "ends",preENDSTRUCT,
    };

    group1iftab.init(group1if, sizeof group1if/sizeof group1if[0]);
    group2iftab.init(group2if, sizeof group2if/sizeof group2if[0]);
    group1tab.init(group1if, sizeof group1if/sizeof group1if[0]);
    group1tab.init(group1, sizeof group1/sizeof group1[0]);
    group2tab.init(group2if, sizeof group2if/sizeof group2if[0]);
    group2tab.init(group2, sizeof group2/sizeof group2[0]);

    macronl.push_back("macro");
    macronl.push_back("imacro");
    macronl.push_back("macro.");
    macronl.push_back("imacro.");
    macroel.push_back("endmacro");
    macroel.push_back("endm");
    whilenl.push_back("while");
    whilenl.push_back("while.");
    whileel.push_back("endwhile");
    repeatnl.push_back("repeat");
    repeatnl.push_back("repeat.");
    repeatel.push_back("endrepeat");
    structureel.push_back("endstruct");
    structureel.push_back("ends");
}
Exemple #10
0
ModalDamping::ModalDamping(const Model& model, const FunctionTable& function_table, int original_id) :
    AnalysisParameter(model, MODAL_DAMPING, original_id), function_table(Value::FUNCTION_TABLE,
            Reference<Value>::NO_ID, function_table.getId()) {
}
Exemple #11
0
void searchClassEntry(){
    int id;
    string classname;
    cout<<"******************************************************"<<endl;
    outputInfo();
    cout<<"请输入你要跑的示例类名"<<endl;
    cout<<"******************************************************"<<endl;
    cin>>id;
    
    
    switch (id) {
        case 0:
            {
                cout<<"谢谢使用再会!";
                exit(0);
            }
        case 1:
            {
                NumConv *numConv = new NumConv();
                numConv->cinPrint();
            }
            break;
        case 2:
            {
                HelloStrings *hello = new HelloStrings();
                hello->helloStringOutput();
                
            }
            break;
        case 3:
            {
                FillString *fill = new FillString();
                fill->fillOperation();
            }
            break;
        case 4:
            {
                getWords *getW = new getWords();
                getW->readCpp();
            }
        case 5:
            {
                Return *ret = new Return();
                ret->operatorCfunc();
            }
            break;
        case 6:
            {
                Charlist *char1 = new Charlist();
                char1->outPut();
            }
            break;
        case 7:
            {
                Specify *specify = new Specify();
                specify->weiOutput();
            }
            break;
        case 8:
            {
                PassByValue *pass = new PassByValue();
                pass->show();
            }
            break;
        case 9:
            {
                PassAddress *pass = new PassAddress();
                pass->showPointer();
            }
            break;
        case 10:
            {
                voidPointer *voidP = new voidPointer();
                voidP->opeatorPointer();
            }
            break;
        case 11:
            {
                Mathops *mathops = new Mathops();
                mathops->show();
            }
            break;
        case 12:
            {
                printBinary *p = new printBinary();
                p->printB(11);
            }
            break;
        case 13:
            {
                CommaOperator *com = new CommaOperator();
                com->show();
            }
            break;
        case 14:
            {
                staticCast *sc = new staticCast();
                sc->show();
            }
            break;
        case 15:
            {
                ConstCast *con = new ConstCast();
//                con->show();
                con->show2();
            }
            break;
        case 16:
            {
                Enum *enum1 = new Enum();
                enum1->show();
                enum1->show2();
                enum1->showArray11();
            }
            break;
        case 17:
            {
                FloatingAsBinary *fa = new FloatingAsBinary();
                fa->show();
            }
            break;
        case 18:
            {
                StringOperation *so = new StringOperation();
                so->operatorString("heeel");
            }
            break;
        case 19:
            {
                PointerLeader *pL = new PointerLeader();
                pL->show();
            }
            break;
        case 20:
            {
                FuncPointer *fP = new FuncPointer();
                fP->func();
            }
            break;
        case 21:
            {
                FunctionTable *fT = new FunctionTable();
                fT->show();
            }
            break;
        case 22:
            {
                StructCpp sc;
                cout<<"sc.d =="<<sc.d<<endl;
            }
            break;
        case 23:
            {
                TemplateTest<int,int> *temp = new TemplateTest<int,int>();
                
                int arr1[] = {1,2,3,4,5,5,6,7,8,9,10};
                
//
                int target = 8;
//
                std::cout<<(temp->binSearch(arr1, 0, 11, target))<<endl;
//
                temp->selectionSort(arr1, target);
                
            }
            break;
        case 24:
            {
//                bingTest *bt = new bingTest();
//                bind(bingTest::operator11,bt,"hello",12)();
            }
            break;
        default:
            {
                cout<<"输入错误请重新输入!";
                searchClassEntry();
            }
            break;
    }
    
}
/** Find function (also processes arguments) */
const Function& FunctionTable::findFunction(const std::string& name, const std::vector<Argument>& args, bool once) const
{
    
    std::pair<std::multimap<std::string, Function *>::const_iterator,
              std::multimap<std::string, Function *>::const_iterator> retVal;
    
    size_t hits = count(name);
    if (hits == 0)
    {
        
        if (parentTable != NULL) 
        {
            // \TODO: We shouldn't allow const casts!!!
            FunctionTable* pt = const_cast<FunctionTable*>(parentTable);
            return pt->findFunction(name, args, once);
        }
        else
        {
            throw RbException("No function named '"+ name + "'");
        }
        
    }
    retVal = equal_range(name);
    if (hits == 1)
    {
        if (retVal.first->second->checkArguments(args,NULL,once) == false)
        {
            std::ostringstream msg;

            msg << "Argument or label mismatch for function call '" << name << "' with arguments (";

            // print the passed arguments
            for (std::vector<Argument>::const_iterator it = args.begin(); it != args.end(); it++) 
            {
                // add a comma before the every argument except the first
                if (it != args.begin()) 
                {
                    msg << ",";
                }
                
                // create the default type of the passed-in argument
                std::string type = "NULL";
                // get the type if the variable wasn't NULL
                if (it->getVariable() != NULL)
                {
                    type = it->getVariable()->getRevObject().getType();
                }
                msg << " " << type;
                
                // create the default DAG type of the passed-in argument
                std::string dagtype = "";
                // get the type if the variable wasn't NULL
                if (it->getVariable() != NULL && it->getVariable()->getRevObject().getDagNode() != NULL )
                {
                    if ( it->getVariable()->getRevObject().getDagNode()->getDagNodeType() == RevBayesCore::DagNode::DETERMINISTIC )
                    {
                        dagtype = "<deterministic>";
                    }
                    else if ( it->getVariable()->getRevObject().getDagNode()->getDagNodeType() == RevBayesCore::DagNode::STOCHASTIC )
                    {
                        dagtype = "<stochastic>";
                    }
                    else if ( it->getVariable()->getRevObject().getDagNode()->getDagNodeType() == RevBayesCore::DagNode::CONSTANT )
                    {
                        dagtype = "<constant>";
                    }
                    else
                    {
                        dagtype = "<?>";
                    }
                }
                msg << dagtype;
                
                if ( it->getLabel() != "" )
                {
                    msg << " '" << it->getLabel() << "'";
                }
            }
            msg << " )." << std::endl;
            msg << "Correct usage is:" << std::endl;
            retVal.first->second->printValue( msg );
            msg << std::endl;
            throw RbException( msg );
        }
        return *retVal.first->second;
    }
    else 
    {
        std::vector<double>* matchScore = new std::vector<double>();
        std::vector<double> bestScore;
        Function* bestMatch = NULL;

        bool ambiguous = false;
        std::multimap<std::string, Function *>::const_iterator it;
        for (it=retVal.first; it!=retVal.second; it++) 
        {
            matchScore->clear();
            if ( (*it).second->checkArguments(args, matchScore, once) == true )
            {
                if ( bestMatch == NULL ) 
                {
                    bestScore = *matchScore;
                    bestMatch = it->second;
                    ambiguous = false;
                }
                else 
                {
                    size_t j;
                    for (j=0; j<matchScore->size() && j<bestScore.size(); j++) 
                    {
                        if ((*matchScore)[j] < bestScore[j]) 
                        {
                            bestScore = *matchScore;
                            bestMatch = it->second;
                            ambiguous = false;
                            break;
                        }
                        else if ((*matchScore)[j] > bestScore[j])
                            break;
                    }
                    if (j==matchScore->size() || j==bestScore.size()) 
                    {
                        ambiguous = true;   // Continue checking, there might be better matches ahead
                    }
                }
            }
        }
        
        // free the memory
        delete matchScore;
        
        /* Delete all processed arguments except those of the best matching function, if it is ambiguous */
        for ( it = retVal.first; it != retVal.second; it++ ) 
        {
            if ( !( (*it).second == bestMatch && ambiguous == false ) )
                (*it).second->clear();
        }
        if ( bestMatch == NULL || ambiguous == true ) 
        {
            std::ostringstream msg;
            if ( bestMatch == NULL )
                msg << "No overloaded function '" << name << "' matches for arguments (";
            else
                msg << "Ambiguous call to function '" << name << "' with arguments (";
            // print the passed arguments
            for (std::vector<Argument>::const_iterator j = args.begin(); j != args.end(); j++) 
            {
                if (j != args.begin()) 
                {
                    msg << ",";
                }
                const RevPtr<const RevVariable>& theVar = j->getVariable();
                msg << " " << theVar->getRevObject().getTypeSpec().getType();
                
            }
            msg << " )" << std::endl;
            
            msg << "Potentially matching functions are:" << std::endl;
            for ( it = retVal.first; it != retVal.second; it++ ) 
            {
                (*it).second->printValue( msg );
                msg << std::endl;
            }
            throw RbException( msg );
        }
        else 
        {
            return *bestMatch;
        }
    }
    
}
Exemple #13
0
/** Find function (also processes arguments) */
Function& FunctionTable::findFunction(const std::string& name, const std::vector<Argument>& args) {
    
    std::pair<std::multimap<std::string, Function *>::iterator,
              std::multimap<std::string, Function *>::iterator> retVal;
    
    size_t hits = count(name);
    if (hits == 0)
    {
        
        if (parentTable != NULL) 
        {
            // \TODO: We shouldn't allow const casts!!!
            FunctionTable* pt = const_cast<FunctionTable*>(parentTable);
            return pt->findFunction(name, args);
        }
        else
        {
            throw RbException("No function named '"+ name + "'");
        }
        
    }
    retVal = equal_range(name);
    if (hits == 1) {
        if (retVal.first->second->checkArguments(args,NULL) == false) 
        {
            
            std::ostringstream msg;
            msg << "Argument mismatch for call to function '" << name << "'(";
            // print the passed arguments
            for (std::vector<Argument>::const_iterator it = args.begin(); it != args.end(); it++) 
            {
                if (it != args.begin()) 
                {
                    msg << ",";
                }
                std::string type = "NULL";
                if (it->getVariable() != NULL) type = it->getVariable()->getRevObject().getType();
                msg << " " << type << " \"" << it->getLabel() << "\"";
            }
            msg << " ). Correct usage is:" << std::endl;
            retVal.first->second->printValue( msg );
            msg << std::endl;
            throw RbException( msg );
        }
        return *retVal.first->second;
    }
    else 
    {
        std::vector<unsigned int>* matchScore = new std::vector<unsigned int>();
        std::vector<unsigned int> bestScore;
        Function* bestMatch = NULL;

        bool ambiguous = false;
        std::multimap<std::string, Function *>::iterator it;
        for (it=retVal.first; it!=retVal.second; it++) 
        {
            matchScore->clear();
            if ( (*it).second->checkArguments(args, matchScore) == true ) 
            {
                if ( bestMatch == NULL ) 
                {
                    bestScore = *matchScore;
                    bestMatch = it->second;
                    ambiguous = false;
                }
                else 
                {
                    size_t j;
                    for (j=0; j<matchScore->size() && j<bestScore.size(); j++) 
                    {
                        if ((*matchScore)[j] < bestScore[j]) 
                        {
                            bestScore = *matchScore;
                            bestMatch = it->second;
                            ambiguous = false;
                            break;
                        }
                        else if ((*matchScore)[j] > bestScore[j])
                            break;
                    }
                    if (j==matchScore->size() || j==bestScore.size()) 
                    {
                        ambiguous = true;   // Continue checking, there might be better matches ahead
                    }
                }
            }
        }
        
        // free the memory
        delete matchScore;
        
        /* Delete all processed arguments except those of the best matching function, if it is ambiguous */
        for ( it = retVal.first; it != retVal.second; it++ ) 
        {
            if ( !( (*it).second == bestMatch && ambiguous == false ) )
                (*it).second->clear();
        }
        if ( bestMatch == NULL || ambiguous == true ) 
        {
            std::ostringstream msg;
            if ( bestMatch == NULL )
                msg << "No overloaded function '" << name << "' matches for arguments (";
            else
                msg << "Ambiguous call to function '" << name << "' with arguments (";
            // print the passed arguments
            for (std::vector<Argument>::const_iterator j = args.begin(); j != args.end(); j++) 
            {
                if (j != args.begin()) 
                {
                    msg << ",";
                }
//                msg << " " << it->getVariable().getDagNode()->getValue().getTypeSpec();
                const RevPtr<const Variable>& theVar = j->getVariable();
                msg << " " << theVar->getRevObject().getTypeSpec().getType();
                
            }
            msg << " )" << std::endl;
            
            msg << "Potentially matching functions are:" << std::endl;
            for ( it = retVal.first; it != retVal.second; it++ ) 
            {
                (*it).second->printValue( msg );
                msg << std::endl;
            }
            throw RbException( msg );
        }
        else 
        {
            return *bestMatch;
        }
    }
    
}