public override object Generate(FunctionExpression expr, object[] inputs) { var node = new SSAGenerator.NodeOperator(); node.Expression = expr; node.Type = Type; var ret = new SSAGenerator.Value(); ret.Index = 0; ret.Generator = node; for (int i = 0; i < Arguments.Length; i++) { node.Inputs.Add((SSAGenerator.Value)inputs[i]); } node.Outputs.Add(ret); return(ret); }
public virtual object Generate(FunctionExpression expr, object[] inputs) { return(null); }
object EvalFunction(FunctionExpression expr, EvalOption option) { var inputs = new List <object>(); for (int i = 0; i < expr.Args.Length; i++) { var input = Eval(expr.Args[i], null); if (input is Attribute) { input = (input as Attribute).Value; } inputs.Add(input); } return(functionDefinitionCollection.Generate(expr, inputs.ToArray())); /* * var node = new NodeOperator(); * node.Expression = expr; * if (expr.Value == "sin") * { * node.Type = OperatorType.Sine; * if (expr.Args.Count() != 1) throw new ArgSizeException(expr.Args.Count(), 1, expr.Line); * } * * if (expr.Value == "cos") * { * node.Type = OperatorType.Cos; * if (expr.Args.Count() != 1) throw new ArgSizeException(expr.Args.Count(), 1, expr.Line); * } * * if (expr.Value == "rand") * { * node.Type = OperatorType.Rand; * * if (expr.Args.Count() == 0) * { * node.Type = OperatorType.Rand; * } * else if (expr.Args.Count() == 1) * { * node.Type = OperatorType.Rand_WithSeed; * } * else * { * throw new ArgSizeException(expr.Args.Count(), new[] { 0, 1 }, expr.Line); * } * } * * if(expr.Value == "step") * { * node.Type = OperatorType.Rand; * if (expr.Args.Count() != 1) throw new ArgSizeException(expr.Args.Count(), 2, expr.Line); * } * * // input * for (int i = 0; i < expr.Args.Length; i++) * { * var input = Eval(expr.Args[i], null); * if (input is Attribute) * { * input = (input as Attribute).Value; * } * * if (input is SymbolTable) * { * var retTable = new SymbolTable(); * int ind = 0; * foreach (var table in (input as SymbolTable).Tables) * { * if (!(table.Value.Value is Value)) * { * throw new InvalidOperationException(expr.Line); * } * * node.Inputs.Add(table.Value.Value as Value); * } * //return retTable; * } * else if (input is Value) * { * node.Inputs.Add(input as Value); * } * else * { * throw new Exception(); * } * } * * // output * if (expr.Args.Count() > 0) * { * var input = Eval(expr.Args[0], null); * if (input is Attribute) * { * input = (input as Attribute).Value; * } * * if (input is SymbolTable) * { * var retTable = new SymbolTable(); * int ind = 0; * foreach (var table in (input as SymbolTable).Tables) * { * var ret = new Value(); * ret.Index = ind; * ret.Generator = node; * node.Outputs.Add(ret); * retTable.Tables.Add(table.Key, new Attribute(ret)); * ind++; * } * return retTable; * } * else if (input is Value) * { * var ret = new Value(); * ret.Index = 0; * ret.Generator = node; * node.Outputs.Add(ret); * return ret; * } * else * { * throw new Exception(); * } * * } * else * { * var ret = new Value(); * ret.Index = 0; * ret.Generator = node; * node.Outputs.Add(ret); * return ret; * } */ }
object EvalFunction(FunctionExpression expr, EvalOption option) { var node = new NodeOperator(); node.Expression = expr; if (expr.Value == "sin") { node.Type = OperatorType.Sine; } if (expr.Value == "cos") { node.Type = OperatorType.Cos; } if (expr.Args.Count() != 1) { throw new ArgSizeException(expr.Args.Count(), 1, expr.Line); } var input = Eval(expr.Args[0], null); if (input is Attribute) { input = (input as Attribute).Value; } if (input is SymbolTable) { var retTable = new SymbolTable(); int ind = 0; foreach (var table in (input as SymbolTable).Tables) { var ret = new Value(); ret.Index = ind; ret.Generator = node; if (!(table.Value.Value is Value)) { throw new InvalidOperationException(expr.Line); } node.Inputs.Add(table.Value.Value as Value); node.Outputs.Add(ret); retTable.Tables.Add(table.Key, new Attribute(ret)); ind++; } return(retTable); } else if (input is Value) { var ret = new Value(); ret.Index = 0; ret.Generator = node; node.Inputs.Add(input as Value); node.Outputs.Add(ret); return(ret); } else { throw new Exception(); } }