public object LoadFromStream(PushbackTextReader rdr, bool addPrint) { object ret = null; object eofVal = new object(); object form; while ((form = LispReader.read(rdr, false, eofVal, false)) != eofVal) { try { //LambdaExpression ast = Compiler.GenerateLambda(form, addPrint); //ret = ast.Compile().DynamicInvoke(); ret = Compiler.eval(form); RT.print(ret, Console.Out); } catch (Exception ex) { if (addPrint) { Exception root = ex; while (root.InnerException != null) { root = root.InnerException; } Console.WriteLine("Error evaluating {0}: {1}", form, root.Message); Console.WriteLine(root.StackTrace); } } } return(ret); }
internal object ParseFile() { IPersistentVector pv = PersistentVector.EMPTY; StringReader sr = new StringReader(_text); PushbackTextReader pr = new PushbackTextReader(sr); pv = pv.cons(Compiler.DO); object eofVal = new object(); object form; while ((form = LispReader.read(pr, false, eofVal, false)) != eofVal) { pv = pv.cons(form); } return(pv.seq()); }
internal object ParseInteractiveStatement(out ScriptCodeParseResult result) { result = ScriptCodeParseResult.Complete; object s = null; try { s = LispReader.read(new PushbackTextReader(new StringReader(_text)), false, _eof, false); } catch (Exception) { result = ScriptCodeParseResult.Invalid; s = null; } if (s == _eof) { result = ScriptCodeParseResult.IncompleteToken; s = null; } return(s); }
public static void Main(string[] args) { // listens for standard input // checks validity // sends code to unity for evaluation cliThread = new Thread((object socket) => { var s = (UdpClient)socket; var sb = new StringBuilder(""); while (running) { var cliIn = ReadLine() + "\n"; sb.Append(cliIn); try { // attempt read just to throw exception on invalid form LispReader.read(new PushbackTextReader(new StringReader(sb.ToString())), true, null, true); UdpSend(s, sb); sb.Length = 0; // sb.Clear(); // no StringBuilder.Clear() in .NET 3.5 } catch (EndOfStreamException) { // keep looping in EOF // hang on to string builder to build up balanced form continue; } catch (Exception e) { // clear string builder on all other errors sb.Length = 0; // sb.Clear(); // no StringBuilder.Clear() in .NET 3.5 Console.WriteLine(e); } } }); // listening for responses from unity // writes to standard out socketThread = new Thread((object sock) => { var socket = (UdpClient)sock; IPEndPoint ip = new IPEndPoint(0, 0); while (running) { try { // incoming bytes include namespace qualified prompt var bytes = socket.Receive(ref ip); var instr = Encoding.UTF8.GetString(bytes); Console.Write(instr); } catch (SocketException) { // keep looping on recieve timeout continue; } } }); Console.CancelKeyPress += (sender, e) => { // graceful exit Console.WriteLine("\n"); running = false; }; if (Environment.GetEnvironmentVariable("CLOJURE_LOAD_PATH") == null) { Environment.SetEnvironmentVariable("CLOJURE_LOAD_PATH", Path.Combine("..", "Source")); } var unitySocket = new UdpClient(); unitySocket.Connect("localhost", 11211); unitySocket.Client.ReceiveTimeout = 500; socketThread.Start(unitySocket); cliThread.Start(unitySocket); UdpSend(unitySocket, @"(binding [*warn-on-reflection* false] (do (println ""; Arcadia REPL"") (println (str ""; Clojure "" (clojure-version))) (println (str ""; Unity "" (UnityEditorInternal.InternalEditorUtility/GetFullUnityVersion))) (println (str ""; Mono "" (.Invoke (.GetMethod Mono.Runtime ""GetDisplayName"" (enum-or System.Reflection.BindingFlags/NonPublic System.Reflection.BindingFlags/Static)) nil nil)))))" ); // force clojure load on main thread RT.nextID(); }