/// <summary> /// Converts an Element Array instance (with count and index members) to /// a fixed-size list of Functions by evaluating each index. /// </summary> /// <returns>The evaluated array, or an empty array if there was an error</returns> private static IFunction[] EvaluateArray(IFunction function, CompilationContext context) { if (function == null) { throw new ArgumentNullException(nameof(function)); } if (function.Inputs?.Length != 0) { context.LogError($"{function} needs to be an array, but it has inputs"); return(Array.Empty <IFunction>()); } var countExpr = function.Call("count", context).AsExpression(context); if (countExpr != null) { countExpr = ConstantFolding.Optimize(countExpr); } var count = (countExpr as Constant)?.Value; if (!count.HasValue) { context.LogError($"{function}'s count is not constant"); return(Array.Empty <IFunction>()); } var index = function.Call("index", context); return(Enumerable.Range(0, (int)count.Value) .Select(i => index.Call(new[] { new Constant(i) }, context)) .ToArray()); }
static double Integral(IFunction y, double min, double max) { double sum = 0; for (double x = min; x < max; x += 1e-6) { sum = sum + (y.Call(x) + y.Call(x + 1e-6)) * 1e-6 / 2; } return(sum); }
/// <summary> /// Calculates the serialized size of the given Function or Type /// </summary> /// <param name="value">The value or type in question</param> /// <param name="info">Where to log error messages</param> /// <returns>The size of the structure in singles, or null if there was a problem</returns> public static int?GetSize(this IFunction value, CompilationContext info) { if (value == Error.Instance) { return(null); } if (value is SerializableType) { return(0); } if (value.IsLeaf() || value.AsExpression(info) != null) { return(1); } if (value.Inputs?.Length != 0) { info.LogError($"Cannot serialize {value} because it has inputs"); return(null); } if (value.Outputs == null) { info.LogError($"Cannot serialize {value} because it is not introspectable"); return(null); } return(value.Outputs.Select(o => GetSize(value.Call(o.Name, info), info)) // NB: An ordinary 'Sum' will treat null as 0 .Aggregate((int?)0, (a, b) => (a == null || b == null) ? null : a + b)); }
public BaseValue Call(IFunction function, IExecutionContext context) { if (function == null) { throw new ArgumentNullException(nameof(function)); } if (function.Arguments.Count != context.Count) { throw new ArgumentOutOfRangeException(nameof(context)); } // convert arguments var actualArguments = new BaseValue[context.Count]; for (var i = 0; i < context.Count; ++i) { actualArguments[i] = ConvertTo(context[i], function.Arguments[i]); } // call the function return(function.Call(new ExecutionContext( actualArguments, this, context.Entity, context.Line, context.Column))); }
public FlattenedFunction(IFunction surrogate, string output, CompilationContext info) { this.surrogate = surrogate; surrogateName = output; var value = surrogate.Call(surrogate.Inputs.Select(p => p.Type).ToArray(), info).Call(output, info); Inputs = surrogate.Inputs.Concat(value.Inputs).ToArray(); }
IEnumerable <(string, IFunction)> Recurse(string path, IFunction func) { if (func.IsNamespace()) { return(func.Outputs.SelectMany(o => Recurse($"{path}.{o.Name}", func.Call(o.Name, context)))); } return(filter?.Invoke(func) == false?Array.Empty <(string, IFunction)>() : new[] { (path, func) });
public DeserializedStructure(IFunction structure, Func <Expression> data, CompilationContext context) { if (structure.Inputs.Length > 0) { context.LogError("ELE0001", $"Cannot deserialize {structure} because it has inputs"); } Outputs = structure.Outputs; _outputValues = Outputs.Select(o => structure.Call(o.Name, context).Deserialize(data, context)).ToArray(); }
public void OnGUI(string name, IFunction value, CompilerInfo info, Action <string, IFunction> drawOther) { EditorGUILayout.LabelField(name); EditorGUI.indentLevel++; foreach (var o in value.Outputs) { drawOther(o.Name, value.Call(o.Name, info)); } EditorGUI.indentLevel--; }
/// <summary> /// Evaluate a function with the given serialized arguments, returning the outputs as an IFunction. /// </summary> public static IFunction Evaluate(this IFunction function, float[] argumentsSerialized, CompilationContext context) { var inputs = function.Inputs; var idx = 0; Expression NextValue() => new Constant(argumentsSerialized[idx++]); var arguments = inputs.Select(i => i.Type.Deserialize(NextValue, context)).ToArray(); return(function.Call(arguments, context)); }
public IFunction CallInternal(IFunction[] arguments, string output, CompilationContext context) { if (this.CheckArguments(arguments, output, context) != null) { return(Error.Instance); } var value = surrogate.Call(arguments.Take(surrogate.Inputs.Length).ToArray(), context) .Call(surrogateName, context); return(value.Call(arguments.Skip(surrogate.Inputs.Length).ToArray(), context)); }
public IFunction CallInternal(IFunction[] arguments, string output, CompilationContext context) { if (this.CheckArguments(arguments, output, context) != null) { return(Error.Instance); } if (!_cache.TryGetValue(output, out var found)) { _cache.Add(output, found = _surrogate.Call(_args, output, context, _callSite)); } return(found); }
public static IFunction AsMethod(this IFunction classInstance, IFunction memberFunction, CallSite?callSite, CompilationContext context) { if (classInstance == null) { throw new ArgumentNullException(nameof(classInstance)); } if (memberFunction == null) { throw new ArgumentNullException(nameof(memberFunction)); } if (!(context.Debug) && memberFunction.Outputs?.Length == 1) { return(memberFunction.Call(new [] { classInstance }, memberFunction.Outputs[0].Name, context, callSite)); } return(new Method(memberFunction, classInstance, callSite).ResolveReturns(context, callSite)); }
public void FangXing() { try { Connection connection = (Connection)this.ReturnLogin().NewConnection(); if (connection.Logon(0, true)) { SAPFunctionsClass class3 = new SAPFunctionsClass { Connection = connection }; IFunction function = (IFunction)class3.Add("ZLE_RFC_ZMMWTD"); IParameter parameter = (IParameter)function.get_Exports("I_VSTEL"); parameter.Value = "3000"; IParameter parameter2 = (IParameter)function.get_Exports("I_ZMENID"); parameter2.Value = "CQ02"; IParameter parameter3 = (IParameter)function.get_Exports("I_ZCARNO"); parameter3.Value = this.I_ZCARNO; IParameter parameter4 = (IParameter)function.get_Exports("I_EBELN"); parameter4.Value = this.I_EBELN; function.Call(); Tables tables = (Tables)function.Tables; Table table = (Table)tables.get_Item("Return"); int rowCount = table.RowCount; DataTable table2 = new DataTable(); for (int i = 1; i <= rowCount; i++) { DataRow row = table2.NewRow(); if (i == 1) { table2.Columns.Add("type"); table2.Columns.Add("message"); } row["type"] = table.get_Cell(i, "type").ToString(); row["message"] = table.get_Cell(i, "message").ToString(); table2.Rows.Add(row); } this.Table2 = table2; } } catch (Exception ex) { return; } }
public double Call(double x) { var v = _function.Call(x); _elementsBuffer.AddFirst(v); if (_elementsBuffer.Count > _averagedElementCount) { _elementsBuffer.RemoveLast(); } var sum = 0.0; foreach (var ev in _elementsBuffer) { sum += ev; } return(sum / _elementsBuffer.Count); }
public override object GetDefaultValue(Type hint) { object value; if (hint == null || hint == typeof(String)) { value = m_Object.ToString(); } else { string converterName; if (hint == typeof(bool)) { converterName = "booleanValue"; } else if (CliHelper.IsNumberType(hint)) { converterName = "doubleValue"; } else { throw Context.ReportRuntimeErrorById("msg.default.value"); } object converterObject = Get(converterName, this); if (converterObject is IFunction) { IFunction f = (IFunction)converterObject; value = f.Call(Context.CurrentContext, f.ParentScope, this, ScriptRuntime.EmptyArgs); } else { if (CliHelper.IsNumberType(hint) && m_Object is bool) { bool b = (bool)m_Object; value = b ? 1.0 : 0.0; } else { value = m_Object.ToString(); } } } return(value); }
public void SaveData() { try { Connection connection = (Connection)this.ReturnLogin().NewConnection(); if (connection.Logon(0, true)) { SAPFunctionsClass class3 = new SAPFunctionsClass { Connection = connection }; IFunction function = (IFunction)class3.Add("ZLE_RFC_WTD"); IParameter parameter = (IParameter)function.get_Exports("I_WTD_ID"); parameter.Value = this.I_WTD_ID; IParameter parameter2 = (IParameter)function.get_Exports("I_DATUM"); parameter2.Value = CommonalityEntity.GetServersTime().ToString(); IParameter parameter3 = (IParameter)function.get_Exports("I_CRFLG"); parameter3.Value = this.I_CRFLG; function.Call(); Tables tables = (Tables)function.Tables; Table table = (Table)tables.get_Item("Return"); int rowCount = table.RowCount; DataTable table2 = new DataTable(); for (int i = 1; i <= rowCount; i++) { DataRow row = table2.NewRow(); if (i == 1) { table2.Columns.Add("type"); table2.Columns.Add("message"); } row["type"] = table.get_Cell(i, "type").ToString(); row["message"] = table.get_Cell(i, "message").ToString(); table2.Rows.Add(row); } this.Table2 = table2; } } catch (Exception ex) { return; } }
/// <summary> /// Creates a constructor Function based on the given type /// </summary> public Constructor(IFunction type, CompilationContext info) { if (type.Inputs?.Length != 0) { throw new Exception($"Can't make a constructor for {type} because it has inputs"); } if (type.Outputs == null) { throw new Exception($"Can't make a constructor for {type} because it's not introspectable"); } Type = type; Name = ((INamedItem)type).Name; Inputs = Type.Outputs.Select(o => new PortInfo { Name = o.Name, Type = (IType)Type.Call(o.Name, info) }) .ToArray(); Outputs = Type.Outputs; }
public IFunction CallInternal(IFunction[] arguments, string output, CompilationContext context) { var completeArgs = new[] { _classInstance }.Concat(arguments).ToArray(); if (this.CheckArguments(arguments, output, context) != null) { return(Error.Instance); } if (!_cache.TryGetValue(output, out var found)) { found = _surrogate.Call(completeArgs, output, context, _callSite); if (Inputs.Length == 0) { _cache.Add(output, found); } } return(found); }
/// <summary> /// Calls a function with arguments, but without specifying an output /// </summary> /// <returns>If the function has only one output it returns it, otherwise it returns a structure /// with all the function's outputs.</returns> public static IFunction Call(this IFunction function, IFunction[] arguments, CompilationContext context, CallSite?callSite = null) { if (function == null) { throw new ArgumentNullException(nameof(function)); } if (!(context.Debug && !(function is IType)) && function.Outputs?.Length == 1 && function.Outputs[0].Name == "return") { return(function.Call(arguments, function.Outputs[0].Name, context, callSite)); } if (function.CheckArguments(arguments, null, context) != null) { return(Error.Instance); } return(new CalledFunction(function, arguments, callSite).ResolveReturns(context, callSite)); }
private double[] CalculateFunctionValues(IFunction function, out double minValue, out double maxValue) { var values = new List <double>(); minValue = double.MaxValue; maxValue = double.MinValue; for (double x = 0; x <= Range; x += InvertedResolution) { var value = function.Call(x); values.Add(value); if (value < minValue) { minValue = value; } if (value > maxValue) { maxValue = value; } } return(values.ToArray()); }
protected object EvaluateFunCallExpr(AstFunCallExpr expr) { if (HadErrorOrReturn()) { return(null); } object calleeObj = EvaluateExpr(expr.m_callee); IFunction callee = calleeObj as IFunction; if (callee != null) { if (expr.m_args.Count != callee.ArgCount()) { // TODO: print function name in the error m_runtimeError = true; Lox.Error(expr.m_startLine, "Function expected " + callee.ArgCount() + " arguments, but was passed " + expr.m_args.Count); return(null); } List <object> args = new List <object>(); foreach (AstExpr argExpr in expr.m_args) { args.Add(EvaluateExpr(argExpr)); } return(callee.Call(this, args)); } else { // TODO: Distinguish between someUnknownFunction() and (3 + 1)() ? // It would be nice to be able to print the name of the function in the former case m_runtimeError = true; Lox.Error(expr.m_startLine, "Invalid function call"); return(null); } }
/// <summary> /// See the other overload of Serialize, but this time it takes a Queue rather than making a new array. /// </summary> /// <param name="value"></param> /// <param name="dataOut">The queue to append new values to</param> /// <param name="context"></param> public static void Serialize(this IFunction value, Queue <Expression> dataOut, CompilationContext context) { var expr = value.AsExpression(context); if (expr != null) { dataOut.Enqueue(expr); return; } if (value.IsLeaf()) { dataOut.Enqueue(Constant.Zero); return; } if (value is SerializableType) { return; } if (value.Inputs?.Length != 0) { context.LogError($"Cannot serialize {value} because it has inputs"); return; } if (value.Outputs == null) { context.LogError($"{value} doesn't have known outputs"); return; } // TODO: Arrays here? foreach (var output in value.Outputs) { Serialize(value.Call(output.Name, context), dataOut, context); } }
public void OnGUI(string name, IFunction value, CompilerInfo info, Action <string, IFunction> drawOther) { var at = value.Call(Array.Empty <IFunction>(), "at", info).Compile <Path>(); CreateLineMaterial(); CreateTarget(); var savedC = Graphics.activeColorBuffer; var savedD = Graphics.activeDepthBuffer; Graphics.SetRenderTarget(texture, 0, CubemapFace.Unknown, 0); lineMaterial.SetPass(0); GL.Clear(true, true, Color.clear); GL.PushMatrix(); GL.LoadOrtho(); GL.Begin(GL.LINE_STRIP); GL.Color(Color.white); System.Threading.Tasks.Parallel.For(0, Points.Length, i => { at(i / (float)Points.Length, out var x, out var y, out var z); Points[i] = new Vector3(x + 0.5f, y + 0.5f, z); });
public void OnGUI(string name, IFunction value, CompilerInfo info, Action <string, IFunction> drawOther) { EditorGUILayout.LabelField(name, $"x: {ToNumber(value.Call("x", info))}, y: {ToNumber(value.Call("y", info))}, z: {ToNumber(value.Call("z", info))}"); }
/// <summary> /// Calls a function with no arguments /// </summary> public static IFunction Call(this IFunction function, string output, CompilationContext context, CallSite?callSite = null) => function.Call(Array.Empty <IFunction>(), output, context, callSite);
public IFunction CallInternal(IFunction[] arguments, string output, CompilationContext context) => _elements.All(isExpression) && output == "return" ? _function.Call(_elements, context) : _function.Call(_elements.Select(e => e.Call(arguments, output, context)).ToArray(), context);
public bool?SatisfiedBy(IFunction value, CompilationContext info) { var inputs = Inputs.Select(p => p.Type).ToArray(); // TODO: A better way of doing this! var outPorts = Outputs; // We are a function type if (inputs.Length > 0) { var called = this.Call(inputs, info); value = value.Call(inputs, info); // Calling this type returned another type if (called is IType type) { return(type.SatisfiedBy(value, info)); } // Calling the type returned something that isn't introspectable if (called.Outputs == null) { // TODO: Check this. What about Abort? info.LogError(14, $"Output of {value} is not introspectable"); return(false); } // Turns a structural thing into a bare list // Was required in past due to ambiguity between structural thing and multiple returns outPorts = called.Outputs.Select(o => new PortInfo { Name = o.Name, Type = (IType)called.Call(o.Name, info) }) .ToArray(); } // Now we check type satisfaction for each output port bool?success = true; foreach (var o in outPorts) { var val = value.Call(o.Name, info); if (val is CompilationError) { success = null; } else { var thisSuccess = o.Type.SatisfiedBy(val, info); if (thisSuccess == false) { info.LogError(14, $"Output {o} not satisfied by {val}"); success = false; } else { success &= thisSuccess; } } } return(success); }
private void toolStripButton1_Click(object sender, EventArgs e) { SAPLogonControlClass login = new SAPLogonControlClass(); login.ApplicationServer = sapconfig.ApplicationServer; login.Client = sapconfig.Client; login.Language = sapconfig.Language; login.User = sapconfig.User; login.Password = sapconfig.Password; login.SystemNumber = sapconfig.SystemNumber; Connection conn = (Connection)login.NewConnection(); ds = new DataSet(); table = new DataTable(); table.Columns.Add("ID", typeof(string)); table.Columns.Add("VBELN", typeof(string)); table.Columns.Add("POSNR", typeof(string)); table.Columns.Add("KWMENG", typeof(string)); table.Columns.Add("Sapqty", typeof(string)); table.Columns.Add("WERKS", typeof(string)); table.Columns.Add("VRKME", typeof(string)); table.Columns.Add("LGORT", typeof(string)); table.Columns.Add("VSTEL", typeof(string)); table.Columns.Add("AUFNR", typeof(string)); table.Columns.Add("VGPOS", typeof(string)); table.Columns.Add("MATNR", typeof(string)); table.Columns.Add("ARKTX", typeof(string)); table.Columns.Add("OutBQty", typeof(string)); table.Columns.Add("CHARG", typeof(string)); ReqTab = new DataTable(); ReqTab.Columns.Add("ID", typeof(string)); ReqTab.Columns.Add("ZRQWK", typeof(string)); ReqTab.Columns.Add("ZREQNO", typeof(string)); ReqTab.Columns.Add("ZREQPS", typeof(string)); ReqTab.Columns.Add("ATINN", typeof(string)); ReqTab.Columns.Add("ATZHL", typeof(string)); ReqTab.Columns.Add("ATWRT", typeof(string)); if (conn.Logon(0, true)) { SAPFunctionsClass func = new SAPFunctionsClass(); func.Connection = conn; IFunction ifunc = (IFunction)func.Add("ZAST_GET_SO"); IParameter gclient = (IParameter)ifunc.get_Exports("WK_VBELN"); gclient.Value = TBVbeln.Text; ifunc.Call(); Tables tables = (Tables)ifunc.Tables; Table vbap = (Table)tables.get_Item("RT_VBAP"); Table rels = (Table)tables.get_Item("RT_CUSTOMER_RQ"); Table RET = (Table)tables.get_Item("RETURN"); for (int i = 1; i <= RET.RowCount; i++) { if (((string)RET.get_Cell(i, "TYPE") == "E") || ((string)RET.get_Cell(i, "TYPE") == "A")) { MessageBox.Show((string)RET.get_Cell(i, "MESSAGE")); return; } } for (int i = 1; i <= vbap.RowCount; i++) { DataRow dr = table.NewRow(); dr["ID"] = i.ToString(); dr["VBELN"] = vbap.get_Cell(i, "VBELN"); dr["POSNR"] = vbap.get_Cell(i, "POSNR"); dr["KWMENG"] = vbap.get_Cell(i, "KWMENG"); dr["Sapqty"] = vbap.get_Cell(i, "KWMENG"); dr["WERKS"] = vbap.get_Cell(i, "WERKS"); dr["VRKME"] = vbap.get_Cell(i, "VRKME"); dr["LGORT"] = vbap.get_Cell(i, "LGORT"); dr["VSTEL"] = vbap.get_Cell(i, "VSTEL"); dr["AUFNR"] = vbap.get_Cell(i, "AUFNR"); dr["VGPOS"] = vbap.get_Cell(i, "VGPOS"); dr["MATNR"] = vbap.get_Cell(i, "MATNR"); dr["ARKTX"] = vbap.get_Cell(i, "ARKTX"); dr["CHARG"] = vbap.get_Cell(i, "CHARG"); dr["OutBQty"] = vbap.get_Cell(i, "KWMENG"); table.Rows.Add(dr); } for (int i = 1; i <= rels.RowCount; i++) { DataRow dr = ReqTab.NewRow(); dr["ID"] = i.ToString(); dr["ZRQWK"] = rels.get_Cell(i, "ZRQWK"); dr["ZREQNO"] = rels.get_Cell(i, "ZREQNO"); dr["ZREQPS"] = rels.get_Cell(i, "ZREQPS"); dr["ATINN"] = rels.get_Cell(i, "ATINN"); dr["ATZHL"] = rels.get_Cell(i, "ATZHL"); dr["ATWRT"] = rels.get_Cell(i, "ATWRT"); ReqTab.Rows.Add(dr); } ds.Tables.Add(table.Copy()); ds.Tables.Add(ReqTab.Copy()); conn.Logoff(); this.Content.DataSource = ds.Tables[0]; gridControl1.DataSource = ds.Tables[1].DefaultView; } }
public IFunction CallInternal(IFunction[] arguments, string output, CompilationContext context) => _returnValue.Call(arguments, output, context);
public ReturnWrapper(IFunction surrogate, CompilationContext info, CallSite?callSite) { _callSite = callSite; _surrogate = surrogate; _returnValue = surrogate.Call(Array.Empty <IFunction>(), surrogate.Outputs[0].Name, info); }