public static PyConstValue Evaluate(IPyValue v) { try { if (v is PyConstValue co) { return(co); } if (v is PyBinaryOperatorExpression bo) { var left = Evaluate(bo.Left).Value; var right = Evaluate(bo.Right).Value; switch (bo.Operator) { case "+": return(new PyConstValue(ValueHelper.Add(left, right))); case "-": return(new PyConstValue(ValueHelper.Sub(left, right))); case "*": return(new PyConstValue(ValueHelper.Mul(left, right))); case "/": return(new PyConstValue(ValueHelper.Div(left, right))); } } } catch (Exception e) { throw new NotSupportedException("unable to get static value from " + v.GetPyCode(new PyEmitStyle()), e); } throw new NotSupportedException("unable to get static value from " + v.GetPyCode(new PyEmitStyle())); }