public static object Convert(Values.Value value) { if (value.Type == Values.ValueType.INT64) { return(System.Convert.ToInt64(value.Data)); } if (value.Type == Values.ValueType.INTEGER) { Values.IntegerValue intVal = (Values.IntegerValue)value; if (intVal.asBoolean) { return(value.GetAsBoolean()); } return(System.Convert.ToInt32(value.Data)); } if (value.Type == Values.ValueType.BIGINTEGER) { return(System.Numerics.BigInteger.Parse(value.Data.ToString())); } if (value.Type == Values.ValueType.COMPLEX) { return(value.Data); } if (value.Type == Values.ValueType.STRING) { return(value.Data); } if (value.Type == Values.ValueType.FLOAT) { return(System.Convert.ToDouble(value.Data)); } return(null); }
static void Main(string[] args) { Console.ForegroundColor = ConsoleColor.White; while (true) { Console.Write("> "); string expression = Console.ReadLine(); if (expression.StartsWith(">>>")) { expression += "\n"; do { expression += Console.ReadLine() + "\n"; } while (!expression.EndsWith("<<<\n")); expression = expression.Substring(3, expression.Length - 7); } if (expression == "") { break; } #if DEBUG // TODO Remove debug construct after development if (expression == "TEST") { if (LoadFile.TryLoad(@"..\..\..\..\codeExamples\load", out string content)) { Console.WriteLine(content); Code.RunConsole(content); Console.WriteLine(); } else { Console.WriteLine(content); } Code.RunConsole(LoadFile.Load(@"..\..\..\..\codeExamples\test")); continue; } Code.RunDebug(expression); #else Console.Write("= "); Values.Value result = Code.Run(expression); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(result); Console.ForegroundColor = ConsoleColor.White; #endif } }
public static object[] ListToArray(Values.Value list) { try { int count = list.GetElementCount(); object[] array = new object[count]; for (int i = 0; i < count; i++) { array[i] = list.GetElementAt(i).Value.Data; } return(array); } catch { } return(null); }