public Value Evaluate(Scope scope) { Value v = Body.Evaluate(scope); scope.Add(Name, v, Mode); return v; }
public Value Evaluate(Scope scope) { foreach (var c in Cases) if (c.Item1.Evaluate(scope).IsTrue()) return c.Item2.Evaluate(scope); return Else.Evaluate(scope); }
public override Value Evaluate(Scope scope) { Value ret = new GTTree(); foreach (var v in body.Evaluate(scope).Enumerate()) { Scope s = new Scope(scope); s.Add(name, v); ret = ret.AddRange(child.Evaluate(s)); } return ret; }
public Value Evaluate(Scope scope) { Scope s; if (Parent == null) s = new Scope(scope, true); else s = new Scope(from v in Parent.Evaluate(scope).Enumerate() where v.Type == GTType.Scope select (Scope)v, true); Body.Evaluate(s); // return value is ignored return s; }
public Value Evaluate(IExpression left, IExpression right, Scope scope) { Value l = left.Evaluate(scope); Value r = right.Evaluate(scope); if (l.Count > 1 && l.Count == r.Count) { var lv = new List<Value>(l.Enumerate()); var rv = new List<Value>(r.Enumerate()); var res = new List<Value>(lv.Count); for (int i = 0; i < lv.Count(); i++) res.Add(Evaluate(lv[i], rv[i], scope)); return new GTTree(res); } if (l.Count > 1 && r.Count == 1) return new GTTree(from x in l.Enumerate() select Evaluate(x, r, scope)); if (r.Count > 1 && l.Count == 1) return new GTTree(from x in r.Enumerate() select Evaluate(l, x, scope)); if (l is IGTAdapter && r is IGTAdapter) { dynamic res = Fun.Invoke(((IGTAdapter)l).Get(), ((IGTAdapter)r).Get()); if (l.Type == GTType.Float || r.Type == GTType.Float) return new GTFloat(res); else return new GTInt(res); } throw new InvalidOperationException(String.Format("Cannot use operator {0} on types {1} and {2}", this, l.Type, r.Type)); }
public Value Evaluate(Scope scope) { return new GTFunction(Body, scope.Close(), Parameters); }
public Value Evaluate(Scope scope) { if (Condition.Evaluate(scope).IsTrue()) return Body.Evaluate(scope); else return Else.Evaluate(scope); }
public override Value Evaluate(Scope scope) { return Left.Evaluate(scope).AddRange(Right.Evaluate(scope)); }
public Value Evaluate(Scope scope) { return new GTTree(Expressions.Select(e => e.Evaluate(scope))); }
public Value Evaluate(Scope scope) { if (Scope == null) return scope.Find(Name); else { Value v = Scope.Evaluate(scope).Self(); if (v.Type == GTType.List) return new GTTree(from s in v.Enumerate() select new Usage(Name, s).Evaluate(scope)); else if (v.Type == GTType.Scope) return ((Scope)v).Find(Name); else throw new InvalidOperationException("Cannot dereference from non-scope value: " + v.ToString()); } }
public override Value Evaluate(Scope scope) { int res = Left.Evaluate(scope).CompareTo(Right.Evaluate(scope)); return new GTBool(res == -1 || res == 0); // can't be -2 }
public Value Evaluate(Scope scope) { return root.Evaluate(scope); }
public abstract Value Evaluate(Scope scope);
// AddLazy public virtual Value AddExp(IExpression exp, Scope scope) { return new GTTree(this, null, new GTLazy(exp, scope)); }
public Value Evaluate(Scope scope) { return this; }
public Value Evaluate(Scope scope) { // Evaluate the function Value v = Function.Evaluate(scope); Value ret = new GTTree(); int c = v.Count; foreach (var res in v.Enumerate()) { var r = res.Self(); if (r.Type != GTType.Function) if (c == 1) throw new InvalidOperationException("Cannot call non-function type"); else continue; GTFunction f = (GTFunction)res; // Check the parameter count if (Parameters.Count > f.Parameters.Count) if (c == 1) throw new InvalidOperationException("Too many arguments in call to function: " + Function.ToString()); else continue; // Create evaluation context Scope s = new Scope(f.Container); // Add this() for recursion s.Add("this", f); for (int i = 0; i < Parameters.Count; i++) s.Add(f.Parameters[i], Parameters[i].Evaluate(scope)); // All parameters filled if (Parameters.Count == f.Parameters.Count) { Value o; if (f.Body == null) { // Invoke the method var w = (WrapperFunc)f; o = (Value)w.Method.Invoke(null, (from par in w.Parameters select new Usage(par).Evaluate(s)).ToArray()); } else o = f.Body.Evaluate(s); ret = ret.Add(o); continue; } // No partial application in list context if (c > 1) continue; // Partial application: Create a new function var newparams = new List<string>(); for (int i = f.Parameters.Count - Parameters.Count; i < f.Parameters.Count; i++) newparams.Add(f.Parameters[i]); return new GTFunction(f.Body, s, newparams); } if (ret.Count == 1) return ret[0]; // single values -> skip the list stuff else return ret; }
internal static void AddTo(Scope scope) { foreach (var kvp in Funcs) scope.Add(kvp.Key, kvp.Value, ScopeMode.Public); }
public Value Evaluate(Scope scope) { return Body.Evaluate(scope); }
public override Value Evaluate(Scope scope) { return new GTBool(Left.Evaluate(scope).IsTrue() || Right.Evaluate(scope).IsTrue()); }
public GTFunction(IExpression body, Scope parent, IEnumerable<string> args) { this.Body = body; this.Container = parent; this.Parameters = new List<string>(args); }
public override Value Evaluate(Scope scope) { return new GTTree(body.Evaluate(scope)); }
public Scope(Scope parent, bool HasStatic = false) : this(new Scope[] { parent }, HasStatic) { }
public override Value Evaluate(Scope scope) { if (body.Evaluate(scope).IsTrue()) return child.Evaluate(scope); else return new GTTree(); }
public Value Evaluate(Scope scope) { return scope.Find(Name, Body.Evaluate(scope)); }
public override Value Evaluate(Scope scope) { return Evaluate(Left, Right, scope); }
public override Value Evaluate(Scope scope) { return new GTBool(Left.Evaluate(scope).CompareTo(Right.Evaluate(scope)) == 1); }
public GTLazy(IExpression exp, Scope scope) { this.Body = exp; this.Container = scope; }
public Scope Close() { // create a new child scope Scope s = new Scope(from p in Parents select p.Close()); // Duplicate all variables foreach (var v in Local) s.Add(v.Key, v.Value); // Apend self for static referencing s.Parents.Add(this); return s; }