public int Compare(object x, object y) { if (x == null || y == null) { return(1); } if (ReferenceEquals(x, y)) { return(0); } TinyValue obj1 = (TinyValue)x; TinyValue obj2 = (TinyValue)y; if (obj1.value is float && obj2.value is float) { if (obj1.Equals(obj2)) { return(0); } return(this.asFloat().CompareTo(obj2.asFloat())); } else if (obj1.isString() && obj2.isString()) { return(obj1.asString().CompareTo(obj2.asString())); } throw new InvalidOperationException("Could not compare expression: '" + obj1 + "' against '" + obj2 + "'"); }
public TinyValue invoke(List <TinyUnityParser.ExpressionContext> args, Dictionary <string, TinyFunction> functions, Scope scope) { if (args == null) { return(invokeEmpty(functions, scope)); } if (args.Count() != this.parameters.Count()) { throw new ArgumentException("Attempted to call function with invalid arguments"); } Scope functionScope = new Scope(null); EvalVisitor evisitor = new EvalVisitor(scope, functions); for (int i = 0; i < this.parameters.Count(); i++) { TinyValue val = evisitor.Visit(args[i]); functionScope.assignParam(this.parameters[i].GetText(), val); } EvalVisitor evisitorNext = new EvalVisitor(functionScope, functions); //Do stuff TinyValue ret = TinyValue.NULL; try { evisitorNext.Visit(this.functionBlock); } catch (ReturnValue returnValue) { ret = returnValue.val; } return(ret); }
public void reAssign(string var, TinyValue val) { if (variables.ContainsKey(var)) { variables[var] = val; } else if (parent != null) { parent.reAssign(var, val); } }
public void assign(string var, TinyValue val) { if (resolve(var) != null) { reAssign(var, val); } else { variables.Add(var, val); } }
public override bool Equals(object comparitor) { if (this == NULL || comparitor == NULL) { throw new InvalidOperationException("Attempted to compare void expressions: '" + this + "' and '" + comparitor + "'"); } if (this == comparitor) { return(true); } if (comparitor == null || this.GetType() != comparitor.GetType()) { return(false); } TinyValue cmp = (TinyValue)comparitor; return(this.value.Equals(cmp.value)); }
public TinyValue invokeEmpty(Dictionary <string, TinyFunction> functions, Scope scope) { Scope functionScope = new Scope(null); EvalVisitor evisitorNext = new EvalVisitor(functionScope, functions); //Do stuff TinyValue ret = TinyValue.NULL; try { evisitorNext.Visit(this.functionBlock); } catch (ReturnValue returnValue) { ret = returnValue.val; } return(ret); }
public void assignParam(string var, TinyValue val) { variables.Add(var, val); }