public override RuntimeValueNode Evaluate() { var symbolNode = Operator.Left.Root as SymbolNode; Type symbol; RuntimeScope assignmentScope = RuntimeScope; if (symbolNode == null && Operator.Left.Root is OperatorAccess) { var opAccess = Operator.Left.Root as OperatorAccess; symbol = opAccess.ReturnSymbol; var symbolValue = new RuntimeOperatorAccess( opAccess, RuntimeScope ).Evaluate(); assignmentScope = symbolValue.RuntimeScope; } else { symbol = symbolNode.Symbol; } var r = new RuntimeExpression( Operator.Right, RuntimeScope ).Evaluate(); assignmentScope.SetValue(symbol.Name, r); return(r); }
public RuntimeTypeValueNode(Type type) : base(null, type, RuntimeScope.Resolve(type.Scope)) { foreach (var m in RuntimeScope.Scope.AllMembers) { if (!(m.Value is FunctionType)) { continue; } RuntimeScope.SetValue( m.Key, new RuntimeFunctionValueNode( m.Value as FunctionType, RuntimeScope ) ); } }
public RuntimeFunction( FunctionType function, RuntimeScope scope, RuntimeValueNode[] arguments ) : base(function.DefiningToken, scope) { Function = function; Arguments = arguments; RuntimeScope = scope; var argsBegin = 0; // If functions expect a this arg, this means that the first argument given contains the reference to the // object it has been called on. Because methods do not explicitly list the this arg in the // list of parameters, it does not appear in the arguments list either and the number of arguments // and number of parameters are therefore off by one, which needs to be corrected. if (Function.ExpectsThisArg) { argsBegin = 1; foreach (var(key, _) in Arguments[0].RuntimeScope.Scope.AllMembers) { var value = Arguments[0].RuntimeScope.GetValue(key); RuntimeScope.Parent.SetValue(key, value); } } for (var i = 0; i < Function.Parameters.Length; ++i) { var param = Function.Parameters[i]; var arg = arguments[i + argsBegin]; if (param is FunctionType.InitializerParameterType) { RuntimeScope.Parent.SetValue(param.Name, arg); } scope.SetValue(param.Name, arg); } }
public RuntimeClassInstanceValueNode(Node node, ComplexType type, RuntimeScope scope) : base(node, type, scope) { Value = this; RuntimeScope.SetValue("this", this); foreach (var m in RuntimeScope.Scope.AllMembers) { if (!(m.Value is FunctionType)) { continue; } RuntimeScope.SetValue( m.Key, new RuntimeFunctionValueNode( m.Value as FunctionType, RuntimeScope ) ); } }