public static void DoEval(RCRunner runner, RCClosure closure, RCReference reference) { runner.Yield(closure, Resolve(reference._static, closure, reference.Parts, null)); }
public void EvalEval(RCRunner runner, RCClosure closure, RCBlock left, RCUserOperator right) { // Invocation using the activator requires a perfect match on the argument type. EvalEval(runner, closure, left, (RCOperator)right); }
public RCBot(RCRunner runner, long id) { Id = id; RCSystem.Activator.InjectState(this); }
public void EvalFormat(RCRunner runner, RCClosure closure, object left, object right) { // eventually should support xml and json, maybe csv? string which = "default"; RCSymbol format = (RCSymbol)left; RCValue content = (RCValue)right; which = format[0].Part(0).ToString(); string result = null; if (which.Equals("default")) { result = content.Format(RCFormat.Default); } else if (which.Equals("pretty")) { result = content.Format(RCFormat.Pretty); } else if (which.Equals("defaultnot")) { result = content.Format(RCFormat.DefaultNoT); } else if (which.Equals("canonical")) { result = content.Format(RCFormat.Canonical); } else if (which.Equals("testcanonical")) { result = content.Format(RCFormat.TestCanonical); } else if (which.Equals("fragment")) { result = content.Format(RCFormat.EditorFragment); } else if (which.Equals("html")) { // content must be a cube result = content.Format(RCFormat.Html); } else if (which.Equals("csv")) { // content must be a cube result = content.Format(RCFormat.Csv); } else if (which.Equals("log")) { // content must be a cube containing expected logging fields result = content.Format(RCFormat.Log); } else if (which.Equals("json")) { result = content.Format(RCFormat.Json); } else if (which.Equals("text")) { result = DoTextFormat(right, Environment.NewLine); } else if (which.Equals("textcrlf")) { result = DoTextFormat(right, "\r\n"); } else if (which.Equals("textlf")) { result = DoTextFormat(right, "\n"); } else { throw new Exception("Unknown format:" + which); } runner.Yield(closure, new RCString(result)); }
// Construct the next closure for an operator. public static RCClosure DoNext(RCOperator op, RCRunner runner, RCClosure head, RCClosure previous, RCValue result) { if (op.Left == null) { if (previous.Index == 0) { RCValue userop; RCArray <RCBlock> useropContext; RCClosure nextParentOf = NextParentOf(op, previous, out userop, out useropContext); RCClosure next = new RCClosure(nextParentOf, head.Bot, op, previous.Left, new RCBlock(null, "1", ":", result), previous.Index + 1, userop, useropContext); return(next); } else if (previous.Index == 1 && previous.Parent != null) { return(previous.Parent.Code.Next(runner, head == null ? previous : head, previous.Parent, result)); } else { return(null); } } else { if (previous.Index == 0) { return(new RCClosure(previous.Parent, head.Bot, op, result, previous.Result, previous.Index + 1, previous.UserOp, previous.UserOpContext)); } else if (previous.Index == 1) { RCValue userop; RCArray <RCBlock> useropContext; RCClosure next = new RCClosure(NextParentOf(op, previous, out userop, out useropContext), head.Bot, op, // reset "pocket" left to null. null, // fold it into the current context for the // final eval. new RCBlock(new RCBlock(null, "0", ":", previous.Left), "1", ":", result), previous.Index + 1, userop, useropContext); return(next); } else if (previous.Index == 2 && previous.Parent != null) { return(previous.Parent.Code.Next(runner, head == null ? previous : head, previous.Parent, result)); } else if (previous.Parent != null && previous.Parent.Parent != null) { return(previous.Parent.Parent.Code.Next(runner, head == null ? previous : head, previous.Parent.Parent, result)); } else { return(null); } } }
public void Invoke(RCRunner runner, RCClosure closure, string name, object left, object right) { OverloadValue overload; Type ltype = left.GetType(); Type rtype = right.GetType(); Type ctype = right.GetType(); try { if (_dispatch.TryGetValue(new OverloadKey(name, ctype, ltype, rtype), out overload)) { RCBot bot = runner.GetBot(closure.Bot); object state = bot.GetModule(overload.Module); overload.Implementation.Invoke(state, new object[] { runner, closure, left, right }); } else if (_dispatch.TryGetValue(new OverloadKey(name, typeof(object), ltype, rtype), out overload)) { RCBot bot = runner.GetBot(closure.Bot); object state = bot.GetModule(overload.Module); overload.Implementation.Invoke(state, new object[] { runner, closure, left, right }); } else if (_dispatch.TryGetValue(new OverloadKey(name, typeof(object), typeof(object), rtype), out overload)) { RCBot bot = runner.GetBot(closure.Bot); object state = bot.GetModule(overload.Module); overload.Implementation.Invoke(state, new object[] { runner, closure, left, right }); } else if (_dispatch.TryGetValue(new OverloadKey(name, typeof(object), ltype, typeof(object)), out overload)) { RCBot bot = runner.GetBot(closure.Bot); object state = bot.GetModule(overload.Module); overload.Implementation.Invoke(state, new object[] { runner, closure, left, right }); } else if (_dispatch.TryGetValue(new OverloadKey(name, typeof(object), typeof(object), typeof(object)), out overload)) { RCBot bot = runner.GetBot(closure.Bot); object state = bot.GetModule(overload.Module); overload.Implementation.Invoke(state, new object[] { runner, closure, left, right }); } else if (_dispatch.TryGetValue(new OverloadKey(name, typeof(object), ltype, typeof(RCOperator)), out overload)) { RCBot bot = runner.GetBot(closure.Bot); object state = bot.GetModule(overload.Module); overload.Implementation.Invoke(state, new object[] { runner, closure, left, right }); } else { throw RCException.Overload(closure, name, left, right); } } catch (TargetInvocationException tiex) { Exception ex = tiex.GetBaseException(); if (ex is RCException) { throw ex; } else { // You have to pass the tiex, not ex here so that the interior stack trace will // be // preserved when/if it is rethrown. throw new RCException(closure, tiex, RCErrors.Native, ThrowMessage(name, ex)); } } }
public void EvalFiber(RCRunner runner, RCClosure closure, RCBlock right) { long fiber = DoFiber(runner, closure, right); runner.Yield(closure, new RCLong(closure.Bot, fiber)); }
public void EvalEval(RCRunner runner, RCClosure closure, RCReference right) { DoEval(runner, closure, right); }
public void EvalDone(RCRunner runner, RCClosure closure, RCLong right) { runner.Done(closure, right); }
public void EvalWatch(RCRunner runner, RCClosure closure, RCLong right) { runner.Watch(closure, right[0]); }
public virtual RCValue Finish(RCRunner runner, RCClosure closure, RCValue result) { return(RCL.Kernel.Eval.DoFinish(runner, closure, result)); }
public virtual void Eval(RCRunner runner, RCClosure closure) { runner.Yield(closure, this); }
public void EvalFormat(RCRunner runner, RCClosure closure, object right) { EvalFormat(runner, closure, new RCSymbol(new RCSymbolScalar(null, "default")), right); }
public static void DoEvalInline(RCRunner runner, RCClosure closure, RCInlineOperator op) { op._code.Eval(runner, UserOpClosure(closure, op._code, null, noClimb: false)); }
public void EvalWait(RCRunner runner, RCClosure closure, RCLong right) { runner.Wait(closure, right); }
public static void DoEvalTemplate(RCRunner runner, RCClosure closure, RCTemplate template) { throw new Exception("Not implemented"); }
public override void Eval(RCRunner runner, RCClosure closure) { RCL.Kernel.Eval.DoEval(runner, closure, this); }
public void EvalEval(RCRunner runner, RCClosure closure, RCBlock left, RCReference right) { RCClosure parent = UserOpClosure(closure, right, new RCArray <RCBlock> (left), noClimb: true); DoEval(runner, parent, right); }
public void EvalEval(RCRunner runner, RCClosure closure, RCTime right) { runner.Yield(closure, right); }
public void EvalEval(RCRunner runner, RCClosure closure, RCBlock left, RCByte right) { runner.Yield(closure, right); }
public void EvalApply(RCRunner runner, RCClosure closure, RCReference left, object right) { RCClosure parent = UserOpClosure(closure, left, null, null, (RCValue)right); DoEval(runner, parent, left); }
public override void EvalOperator(RCRunner runner, RCClosure closure) { RCL.Kernel.Eval.DoEvalUserOp(runner, closure, this); }
// Kicks off evaluation for a block. public static void DoEval(RCRunner runner, RCClosure closure, RCBlock block) { if (block.Count == 0) { DoYield(runner, closure, block); } else { RCBlock current = block.GetName(closure.Index); if (current.Evaluator.Invoke) { string op = ((RCString)current.Value)[0]; RCSystem.Activator.Invoke(runner, closure, op, closure.Result); } else if (current.Evaluator.Template) { try { RCString result = ExpandTemplate(new StringBuilder(), (RCTemplate)current, closure.Result, 0, ""); runner.Yield(closure, result); } catch (Exception ex) { RCException rcex = new RCException(closure, ex, RCErrors.Native, "An exception was thrown by the template."); runner.Finish(closure, rcex, (int)RCErrors.Native); } } else if (current.Evaluator.Pass) { DoYield(runner, closure, current.Value); } // This means that Value is an operator or a reference. else if (current.Value.ArgumentEval) { current.Value.Eval(runner, new RCClosure(closure, closure.Bot, current.Value, closure.Left, closure.Result, 0)); } else if (current.Evaluator.Return) { DoYield(runner, closure, current.Value); } else { // I need something different to happen when we are at the top level already. // Or maybe I need to inject a wrapper closure when I do Rep this way? if ((closure.Index < block.Count - 1) || (closure.Parent != null)) { DoYield(runner, closure, current.Value); } else { DoYield(runner, closure, current); } } } }
public void FiberDone(RCRunner runner, long bot, long fiber, RCValue result) { Fiber module = (Fiber)GetModule(typeof(Fiber)); module.FiberDone(runner, bot, fiber, result); }
public void EvalFail(RCRunner runner, RCClosure closure, RCString right) { runner.Finish(closure, new RCException(closure, RCErrors.Custom, right[0]), (int)RCErrors.Custom); }