interface
| 1738 | |
| 1739 | // interface |
| 1740 | int asCModule::CompileFunction(const char* sectionName, const char* code, int lineOffset, asDWORD compileFlags, asIScriptFunction** outFunc) |
| 1741 | { |
| 1742 | // Make sure the outFunc is null if the function fails, so the |
| 1743 | // application doesn't attempt to release a non-existent function |
| 1744 | if (outFunc) |
| 1745 | *outFunc = 0; |
| 1746 | |
| 1747 | #ifdef AS_NO_COMPILER |
| 1748 | UNUSED_VAR(sectionName); |
| 1749 | UNUSED_VAR(code); |
| 1750 | UNUSED_VAR(lineOffset); |
| 1751 | UNUSED_VAR(compileFlags); |
| 1752 | return asNOT_SUPPORTED; |
| 1753 | #else |
| 1754 | // Validate arguments |
| 1755 | if (code == 0 || |
| 1756 | (compileFlags != 0 && compileFlags != asCOMP_ADD_TO_MODULE)) |
| 1757 | return asINVALID_ARG; |
| 1758 | |
| 1759 | // Only one thread may build at one time |
| 1760 | // TODO: It should be possible to have multiple threads perform compilations |
| 1761 | int r = m_engine->RequestBuild(); |
| 1762 | if (r < 0) |
| 1763 | return r; |
| 1764 | |
| 1765 | // Prepare the engine |
| 1766 | m_engine->PrepareEngine(); |
| 1767 | if (m_engine->configFailed) |
| 1768 | { |
| 1769 | m_engine->WriteMessage("", 0, 0, asMSGTYPE_ERROR, TXT_INVALID_CONFIGURATION); |
| 1770 | m_engine->BuildCompleted(); |
| 1771 | return asINVALID_CONFIGURATION; |
| 1772 | } |
| 1773 | |
| 1774 | // Compile the single function |
| 1775 | asCBuilder funcBuilder(m_engine, this); |
| 1776 | asCString str = code; |
| 1777 | asCScriptFunction* func = 0; |
| 1778 | r = funcBuilder.CompileFunction(sectionName, str.AddressOf(), lineOffset, compileFlags, &func); |
| 1779 | |
| 1780 | if (r >= 0) |
| 1781 | { |
| 1782 | // Invoke the JIT compiler if it has been set |
| 1783 | if (m_engine->jitCompiler) |
| 1784 | func->JITCompile(); |
| 1785 | } |
| 1786 | |
| 1787 | m_engine->BuildCompleted(); |
| 1788 | |
| 1789 | if( r >= 0 && outFunc && func ) |
| 1790 | { |
| 1791 | // Return the function to the caller and add an external reference |
| 1792 | *outFunc = func; |
| 1793 | func->AddRef(); |
| 1794 | } |
| 1795 | |
| 1796 | // Release our reference to the function |
| 1797 | if( func ) |
no test coverage detected