public override Constant Call(Constant other, Constant _this, Scope scope) { if (other is ArgumentList) { var argumentList = (ArgumentList)other; var arguments = new Constant[argumentList.Arguments.Count]; for (var i = 0; i < argumentList.Arguments.Count; i++) { var value = argumentList.Arguments[i].Execute(scope); arguments[i] = value; } var functionScope = new Scope(Scope, this, ScopeType.Function); // TODO: THIS IS A MEGA-HACK, REMOVE AS SOON AS POSSIBLE!!! foreach (var key in scope.Variables) { if (key.StartsWith("__") && key.EndsWith("__")) { functionScope.SetVariable(key, scope.GetVariable(key)); } } return(Function(_this, arguments, functionScope)); } return(base.Call(other, _this, scope)); }
public override Constant Call(Constant other, Constant _this, Scope scope) { if (other is ArgumentList) { var argumentList = (ArgumentList)other; var functionScope = new Scope(Scope, this, ScopeType.Function); functionScope.SetVariable("this", _this); for (var i = 0; i < argumentList.Arguments.Count && i < Parameters.Parameters.Count; i++) { var value = argumentList.Arguments[i].Execute(scope); Parameters.Parameters[i].Assignment(value, functionScope); } var result = Body.Execute(functionScope).Constant; if (Type != null && Type.Length > 0) { if (!Tool.CheckType(result, Type)) { throw new TypeError($"Function cannot return value of type '{result.GetType()}', must return '{Type}'"); } } return(result); } return(base.Call(other, _this, scope)); }
public override Constant Assignment(Constant other, Scope scope) { scope.SetVariable(Name, other); // For performance, so not everything is output as a string return(Static.Undefined); //return other; }