public wolFloat() : base() { strtype = "float"; parents = new Dictionary <string, wolClass> { { "int", VirtualMachine.GetWolClass("int") } }; }
public wolByte() : base() { strtype = "byte"; parents = new Dictionary <string, wolClass> { { "void", VirtualMachine.GetWolClass("void") } }; }
public wolDouble() : base() { strtype = "double"; parents = new Dictionary <string, wolClass> { { "float", VirtualMachine.GetWolClass("float") } }; }
public wolShort() : base() { strtype = "short"; parents = new Dictionary <string, wolClass> { { "byte", VirtualMachine.GetWolClass("byte") } }; }
public wolArray() : base() { strtype = "Array"; parents = new Dictionary <string, wolClass> { { "Collection", VirtualMachine.GetWolClass("Collection") } }; }
public wolEnum() : base() { strtype = "Enum"; classType = wolClassType.STATIC; parents = new Dictionary <string, wolClass> { { "void", VirtualMachine.GetWolClass("void") } }; }
/// <summary> /// Constructor of Collection for overriding /// </summary> public wolCollection() : base() { classType = wolClassType.ABSTRACT; strtype = "Collection"; parents = new Dictionary <string, wolClass> { { "void", VirtualMachine.GetWolClass("void") } }; }
public wolInt() : base() { strtype = "int"; parents = new Dictionary <string, wolClass> { { "short", VirtualMachine.GetWolClass("short") } }; constructors.Add("int", wolFunction.NewDefaultConstructor(this)); }
public wolFunc() : base() { strtype = "Func"; classType = wolClassType.DEFAULT; parents = new Dictionary <string, wolClass> { { "void", VirtualMachine.GetWolClass("void") } }; constructors.Add("Func", wolFunction.NewDefaultConstructor(this)); //add empty constructor }
public wolBool() : base() { value = true; strtype = "bool"; constants = new Dictionary <string, Value> { { "false", new Value(new wolInt(0)) }, { "true", new Value(new wolInt(1)) } }; parents = new Dictionary <string, wolClass> { { "void", VirtualMachine.GetWolClass("void") } }; constructors = new Dictionary <string, wolFunction> { { "bool", wolFunction.NewDefaultConstructor(this) } }; }
public wolClass(string name, SecurityModifer securityModifer = SecurityModifer.PUBLIC, wolClassType type = wolClassType.DEFAULT, string ConstructorName = "init") { strtype = name; security = securityModifer; classType = type; switch (classType) { case wolClassType.DEFAULT: methods = new Dictionary <string, wolFunction>(); constructors = new Dictionary <string, wolFunction> { { ConstructorName, new wolFunction() } }; destructors = new List <wolFunction> { new wolFunction() }; fields = new Dictionary <string, Value>(); static_fields = new Dictionary <string, Value>(); parents = new Dictionary <string, wolClass> { { "void", VirtualMachine.GetWolClass("void") } }; break; case wolClassType.ENUM: constants = new Dictionary <string, Value>(); parents = new Dictionary <string, wolClass> { { "int", VirtualMachine.GetWolClass("int") } }; break; case wolClassType.STATIC: parents = new Dictionary <string, wolClass> { { "void", VirtualMachine.GetWolClass("void") } }; static_fields = new Dictionary <string, Value>(); methods = new Dictionary <string, wolFunction>(); break; case wolClassType.STRUCT: constants = new Dictionary <string, Value>(); parents = new Dictionary <string, wolClass> { { "void", VirtualMachine.GetWolClass("void") } }; fields = new Dictionary <string, Value>(); methods = new Dictionary <string, wolFunction>(); constructors = new Dictionary <string, wolFunction> { { ConstructorName, new wolFunction() } }; destructors = new List <wolFunction> { new wolFunction() }; break; case wolClassType.ABSTRACT: parents = new Dictionary <string, wolClass> { { "void", VirtualMachine.GetWolClass("void") } }; fields = new Dictionary <string, Value>(); static_fields = new Dictionary <string, Value>(); methods = new Dictionary <string, wolFunction>(); break; } }
public wolType(string type_name) : this() { value = VirtualMachine.GetWolClass(type_name); }
public bool CheckType(string name) => name == type.strtype ? true : false; //thanks C# for one-string functions)) public static Value GetSmallValue(string val, Value parent = null) { //Console.WriteLine("Value is " + val); Value value = VoidValue; val = val.Trim(); if (val.StartsWith("<") && val.EndsWith(">")) //example of syntax - _loads : <wolSystem:string> ; { if (parent != null) { VirtualMachine.ThrowVMException("Default value cannot have parent value", VirtualMachine.position, ExceptionType.ValueException); } val = val.Remove(0, 1).Remove(val.Length - 2); //remove '<' and '>' string[] vals = val.Split(':'); if (vals.Length == 2) { string type_word = vals[1].Trim(), val_word = vals[0].Trim(); if (type_word == "double") { wolDouble type = new wolDouble(); type.ParseDouble(val_word); value = new Value(type); } else if (type_word == "int") { wolInt type = new wolInt(); type.ParseInt(val_word); value = new Value(type); } else if (type_word == "string") { wolString type = new wolString(); type.value = Regex.Unescape(vals[0]); value = new Value(type); } else if (type_word == "long") { wolLong type = new wolLong(); type.ParseLong(val_word); value = new Value(type); } else if (type_word == "bool") { wolBool type = new wolBool(); type.ParseBool(val_word); value = new Value(type); } else if (type_word == "void") { value = VoidValue; } else if (type_word == "short") { wolShort type = new wolShort(); type.ParseShort(val_word); value = new Value(type); } else if (type_word == "float") { wolFloat type = new wolFloat(); type.ParseFloat(val_word); value = new Value(type); } else if (type_word == "byte") { wolByte type = new wolByte(); type.ParseByte(val_word); value = new Value(type); } else if (type_word == "char") { wolChar type = new wolChar(); type.ParseChar(val_word); value = new Value(type); } else { value = new Value(VirtualMachine.GetWolClass(type_word)); foreach (string f in vals[0].Split(',')) { string[] fs = f.Split('='); try { value.type.fields[fs[0].Trim()] = GetValue(fs[1]); } catch (KeyNotFoundException) { VirtualMachine.ThrowVMException($"Field by name {fs[0]} not found", VirtualMachine.position, ExceptionType.NotFoundException); } } } return(value); } else { VirtualMachine.ThrowVMException("Value and his type not found in this string", VirtualMachine.position, ExceptionType.BLDSyntaxException); return(null); } } else if (val.StartsWith("@")) //example of syntax - plus : @a, @b ; { //Console.WriteLine(val); val = val.Remove(0, 1); //skip '@' if (parent != null) { if (parent.CheckType("Type")) { return(((wolType)parent.type).value.GetStaticField(val)); } else { return(parent.GetField(val)); } } else { try { value = VirtualMachine.mainstack.values[val]; } catch (KeyNotFoundException) { VirtualMachine.ThrowVMException($"Variable by name '{val}' not found in main stack", VirtualMachine.position, ExceptionType.NotFoundException); } return(value); } } else if (val.StartsWith("&")) //example of syntax - set : &@this, <null:void> ; { val = val.Remove(0, 1); //remove '&' if (parent != null) { VirtualMachine.ThrowVMException("Link cannot haven`t ParentValue. He can have only valid address", VirtualMachine.position, ExceptionType.ValueException); return(new Value(new wolLink())); } else { return(new Value(new wolLink(val))); } } else if (val.StartsWith("#")) //example of syntax - set : &@this, #sum ; { val = val.Remove(0, 1); //remove '#' if (parent != null) { if (parent.CheckType("Type")) { return(new Value(new wolFunc(((wolType)parent.type).value.GetStaticMethod(val)))); //one string or how make code unreadable } else { if (val == "set") { return(new Value(new wolFunc(parent.setter))); } else if (val == "get") { return(new Value(new wolFunc(parent.getter))); } else { return(new Value(new wolFunc(parent.GetMethod(val)))); //return not static method of ParentValue by name } } } else { return(VirtualMachine.FindFunc(val)); //one string) } } else if (val.StartsWith("$")) //example of syntax - equals : $void, (typeof : <null:void>) ; { if (parent != null) { VirtualMachine.ThrowVMException("Class (Type) cannot have parent value", VirtualMachine.position, ExceptionType.ValueException); } return(new Value(new wolType(val.Remove(0, 1)))); //let`s write in one string!!! } else if (val.StartsWith("%")) //example of syntax - if : ( equals : $void, (typeof : <null:void>) ), %if_block1 ; { if (parent != null) { VirtualMachine.ThrowVMException("Block cannot have parent value", VirtualMachine.position, ExceptionType.ValueException); } return(VirtualMachine.FindBlock(val.Remove(0, 1))); //one string again! } else if (val.StartsWith("(")) //example of syntax - return (typeof : @this ) ; { if (parent != null) { VirtualMachine.ThrowVMException("Expression cannot have parent value", VirtualMachine.position - val.Length, ExceptionType.ValueException); } StringBuilder buffer = new StringBuilder(); char current = val[1]; //skip '(' int pos = 1; //skip '(' byte priority = 0; while (true) //add body of expression { if (current == '(') { priority++; } else if (current == ')') { if (priority == 0) { break; } else { priority--; } } try { buffer.Append(current); current = val[++pos]; } catch (IndexOutOfRangeException) { VirtualMachine.ThrowVMException($"End of string expression ('{val}') not found", VirtualMachine.position - val.Length + pos, ExceptionType.BLDSyntaxException); } } return(Script.ParseExpression(buffer.ToString())); } else { VirtualMachine.ThrowVMException($"Value {val} cannot find", VirtualMachine.position - val.Length, ExceptionType.BLDSyntaxException); return(null); } }
public static Value ParseExpression(string string_expression, Dictionary <string, Value> arguments) { //Console.WriteLine("String expression: " + string_expression); VirtualMachine.mainstack = VirtualMachine.mainstack + arguments; string[] tokens = string_expression.Split(new char[4] { ' ', '\t', '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); string keyword = tokens[0]; if (keyword.StartsWith("@") || keyword.StartsWith("#") || keyword.StartsWith("$") || keyword.StartsWith("%") || keyword.StartsWith("<") || keyword.StartsWith("&")) { wolFunc value = new wolFunc(); //create empty 'Func' instance for not throwing NullRefrenceException try { value = (wolFunc)Value.GetValue(keyword).type; } catch (InvalidCastException) { VirtualMachine.ThrowVMException($"'{keyword}' haven`t type Func", VirtualMachine.position, ExceptionType.InvalidTypeException); } string args = string_expression.Substring(string_expression.IndexOf(':') + 1).Trim(); //code after name of function (string with arguments) List <string> argums = new List <string>(); //array with arguments of expression int pos = 0; char current = args[0]; StringBuilder buffer = new StringBuilder(); while (true) { if (current == '(') { while (current != ')') { try { buffer.Append(current); current = args[++pos]; } catch (IndexOutOfRangeException) { VirtualMachine.ThrowVMException("End of expression not found", VirtualMachine.position - args.Length + pos, ExceptionType.BLDSyntaxException); } } } else if (current == '<') { while (current != '>') { try { buffer.Append(current); current = args[++pos]; } catch (IndexOutOfRangeException) { VirtualMachine.ThrowVMException("End of value not found", VirtualMachine.position - args.Length + pos, ExceptionType.BLDSyntaxException); } } } else if (current == ',') { argums.Add(buffer.ToString()); buffer.Clear(); try { current = args[++pos]; } catch (IndexOutOfRangeException) { break; } } else { try { buffer.Append(current); current = args[++pos]; } catch (IndexOutOfRangeException) { argums.Add(buffer.ToString()); break; } } } Value[] values = new Value[argums.Count]; //array with arguments who converted to Value for (int i = 0; i < argums.Count; i++) { values[i] = Value.GetValue(argums[i].TrimStart()); //convert string arguments to Value arguments } VirtualMachine.mainstack = VirtualMachine.mainstack - arguments; return(value.Call(values)); } else if (keyword.StartsWith("^")) { string[] toks = keyword.Remove(0, 1).Split('.'); string args = string_expression.Substring(string_expression.IndexOf(':') + 1).Trim(); //code after constructor (string with arguments) string[] argums = args.Split(','); //array with arguments of constructor Value[] values = new Value[argums.Length]; //array with arguments who converted to Value for (int i = 0; i < argums.Length; i++) { values[i] = Value.GetValue(argums[i].TrimStart()); //convert string arguments to Value arguments } VirtualMachine.mainstack = VirtualMachine.mainstack - arguments; return(new Value(VirtualMachine.GetWolClass(toks[0]), toks[1], values)); } else if (keyword.StartsWith("~")) { string args = string_expression.Substring(string_expression.IndexOf(':') + 1).Trim(); //code after destructor (string with arguments) string[] argums = args.Split(','); //array with arguments of destructor Value[] values = new Value[argums.Length]; //array with arguments who converted to Value for (int i = 0; i < argums.Length; i++) { values[i] = Value.GetValue(argums[i].TrimStart()); //convert string arguments to Value arguments } string[] toks = keyword.Remove(0, 1).Split(':'); VirtualMachine.GetWolClass(toks[0]).CallDestructor(int.Parse(toks[1]), values); VirtualMachine.mainstack = VirtualMachine.mainstack - arguments; return(Value.VoidValue); } else { bool haveExpression = true; //check on found expression by this name foreach (KeyValuePair <string, VMExpression> expression in VirtualMachine.expressions) { if (expression.Key == keyword) { List <string> argums = new List <string>(); if (string_expression.Contains(":")) { string args = string_expression.Substring(string_expression.IndexOf(':') + 1).Trim(); //code after name of expression (string with arguments) StringBuilder buffer = new StringBuilder(); byte expr = 0; //priority of expressions for (int i = 0; i < args.Length; i++) { char cur = args[i]; if (cur == ',' && expr == 0) { argums.Add(buffer.ToString()); buffer.Clear(); } else if (cur == ')' && expr > 0) { buffer.Append(cur); expr--; //Console.WriteLine("Priority ): " + expr); } else if (cur == '(' && expr >= 0) { buffer.Append(cur); expr++; //Console.WriteLine("Priority (: " + expr); } else { buffer.Append(cur); } } argums.Add(buffer.ToString()); //Console.WriteLine(string.Join(' ', argums) + '\t' + argums.Count); } else { haveExpression = true; return(expression.Value.ParseExpression()); } Value[] values = new Value[argums.Count]; //array with arguments who converted to Value for (int i = 0; i < argums.Count; i++) { values[i] = Value.GetValue(argums[i].TrimStart()); //convert string arguments to Value arguments } haveExpression = true; VirtualMachine.mainstack = VirtualMachine.mainstack - arguments; return(expression.Value.ParseExpression(values)); } else { haveExpression = false; } } if (!haveExpression) { VirtualMachine.ThrowVMException($"VM Expression by name {keyword} not found and will cannot parse", VirtualMachine.position, ExceptionType.NotFoundException); } VirtualMachine.mainstack = VirtualMachine.mainstack - arguments; return(null); } }