Changeset 14983
- Timestamp:
- 03/04/13 20:13:19 (12 years ago)
- Location:
- trunk/FACT++/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/InterpreterV8.cc
r14741 r14983 23 23 #include "dim.h" 24 24 #include "tools.h" 25 #include "Readline.h" 25 26 #include "externals/izstream.h" 27 28 #include "WindowLog.h" 26 29 27 30 using namespace std; … … 1719 1722 // Print (filename):(line number): (message). 1720 1723 const String::AsciiValue filename(message->GetScriptResourceName()); 1721 1722 out << *filename; 1723 if (message->GetLineNumber()>0) 1724 out << ": l." << message->GetLineNumber(); 1725 if (*exception) 1726 out << ": "; 1724 if (filename.length()>0) 1725 { 1726 out << *filename; 1727 if (message->GetLineNumber()>0) 1728 out << ": l." << message->GetLineNumber(); 1729 if (*exception) 1730 out << ": "; 1731 } 1727 1732 } 1728 1733 … … 1843 1848 1844 1849 return !ExecuteCode(buffer, name, main).IsEmpty(); 1850 } 1851 1852 bool InterpreterV8::ExecuteConsole() 1853 { 1854 JsSetState(3); 1855 1856 WindowLog lout; 1857 lout << "\n " << kUnderline << " JavaScript interpreter " << kReset << " (enter '.q' to quit)\n" << endl; 1858 1859 Readline::StaticPushHistory("java.his"); 1860 1861 string command; 1862 1863 while (1) 1864 { 1865 const string buffer = Tools::Trim(Readline::StaticPrompt(command.empty() ? "JS> " : " \\> ")); 1866 if (buffer==".q") 1867 break; 1868 1869 // buffer empty, do nothing 1870 if (buffer.empty()) 1871 continue; 1872 1873 // Compose command 1874 if (!command.empty()) 1875 command += ' '; 1876 command += buffer; 1877 1878 // If line ends with a backslash, allow addition of next line 1879 if (command.back()=='\\') 1880 { 1881 command[command.length()-1] = ' '; 1882 command = Tools::Trim(command); 1883 continue; 1884 } 1885 1886 // Catch exceptions during code compilation 1887 TryCatch exception; 1888 1889 // Execute code which was entered 1890 bool rc = ExecuteCode(command, "", false).IsEmpty(); 1891 if (exception.HasCaught()) 1892 { 1893 HandleException(exception, "compile"); 1894 rc = true; 1895 } 1896 1897 // In case of an exception add an empty line to the output 1898 if (rc) 1899 lout << endl; 1900 1901 // command has been executed, collect new command 1902 command = ""; 1903 } 1904 1905 lout << endl; 1906 1907 Readline::StaticPopHistory("java.his"); 1908 1909 return true; 1845 1910 } 1846 1911 … … 2072 2137 Locker::StartPreemption(10); 2073 2138 2074 rc &= ExecuteFile(filename, true);2139 rc &= filename.empty() ? ExecuteConsole() : ExecuteFile(filename, true); 2075 2140 2076 2141 Locker::StopPreemption(); -
trunk/FACT++/src/InterpreterV8.h
r14741 r14983 57 57 bool HandleException(v8::TryCatch &try_catch, const char *where); 58 58 bool ExecuteFile(const std::string &name, bool main=false); 59 bool ExecuteConsole(); 59 60 v8::Handle<v8::Value> ExecuteCode(const std::string &code, const std::string &file="internal", bool main=false); 60 61 v8::Handle<v8::Value> ExecuteInternal(const std::string &code);
Note:
See TracChangeset
for help on using the changeset viewer.