// Common entry point for executing code public TypedValue Exec(ByteCode code, ILookupValue lookup = null, TypedValue aggregate = null, AccumulatorBlock accblock = null) { Logger.WriteLine(5, "Exec {0} {1} {2} {3}", code.Length, lookup, aggregate, accblock); if (code.Length == 0) { return(VoidValue.Void); } if (lookup != null) { PushLookup(lookup); } //Current = this; TypedValue retval = null; try { retval = Run(code, aggregate, accblock); } catch (TargetInvocationException ex) { Logger.WriteLine(3, "Exception {0}", ex.ToString()); throw ex.InnerException; } if (lookup != null) { PopLookup(); } return(retval); }
// evaluate an open expression returning a typed value // rename -- do it here // aggregate -- not safe to eval, so just return typed default public TypedValue EvalOpen(ILookupValue lookup) { if (IsValue) { return(Value); } if (HasFold) { return(ReturnType.DefaultValue()); } TypedValue ret; if (IsRename || IsProject) { ret = Evaluator.Lookup(OldName, lookup); } else { Logger.Assert(IsOpen || HasWin || lookup == null, Name); Logger.Assert(Evaluator != null, "evaluator null"); ret = Evaluator.Exec(Code, lookup); } CheckReturnType(ret); return(ret); }
// evaluate a fold expression with previous value returning an updated value public TypedValue EvalIsFolded(ILookupValue lookup, TypedValue aggregate) { Logger.Assert(IsFolded, Name); var ret = Evaluator.Exec(Code, lookup, aggregate); CheckReturnType(ret); return(ret); }
// evaluate a post-fold expression that depends on accumulator values public TypedValue EvalHasFold(ILookupValue lookup, AccumulatorBlock accblock, int accbase = 0) { Logger.Assert(HasFold, Name); accblock.IndexBase = accbase; var ret = Evaluator.Exec(Code, lookup, null, accblock); CheckReturnType(ret); return(ret); }
// evaluate an open predicate expression returning true/false public BoolValue EvalPred(ILookupValue lookup) { Logger.Assert(ReturnType == DataTypes.Bool, Name); if (Code.Length == 0) { return(BoolValue.True); } return(EvalOpen(lookup) as BoolValue); }
// Convert using lookup as context. Used by Invoke. public static DataTableLocal Convert(DataTable other, ILookupValue lookup, Evaluator evaluator) { if (other is DataTableLocal) { return(other as DataTableLocal); } else { evaluator.PushLookup(lookup); var ret = Create(other.Heading, other.GetRows()); evaluator.PopLookup(); return(ret); } }
// Perform a value lookup for project public TypedValue Lookup(string name, ILookupValue lookup = null) { if (lookup != null) { _lookups.Push(lookup); } var value = TypedValue.Empty; var ok = LookupValue(name, ref value); Logger.Assert(ok, name); if (lookup != null) { _lookups.Pop(); } return(value); }
// used by Invoke public void PushLookup(ILookupValue lookup) { Logger.WriteLine(4, "Push lookup {0}", lookup); _lookups.Push(lookup); }