////////////////////////////////////////////// /*public DynLanState(String DisplayName, Guid ObjectID, DynLanContextType ContextType) * { * this.DisplayName = DisplayName ?? ""; * this.ObjectID = ObjectID; * this.ID = Guid.NewGuid(); * this.ContextType = ContextType; * this.Object = new DynLanObject(); * this.Lines = new DynLanCodeLines(); * this.CurrentLineIndex = 0; * }*/ public DynLanState(DynLanProgram Program, DynLanContextType ContextType) { this.Program = Program; //this.DisplayName = DisplayName ?? ""; //this.ObjectID = ObjectID; this.ID = Guid.NewGuid(); this.ContextType = ContextType; this.Object = new DynLanObject(); //this.Lines = new DynLanCodeLines(); this.CurrentLineIndex = 0; }
//public DynLanState PushContext(String DisplayName, Guid ObjectID, DynLanContextType ContextType) public DynLanState PushContext( DynLanProgram Program, DynLanContextType ContextType, IList <Object> Parameters) { DynLanState state = new DynLanState(Program, ContextType); // DisplayName, ObjectID, ContextType); DynLanObject obj = state.Object; this.Stack.Add(state); this.CurrentState = state; List <DynLanMethodParam> finalParameters = new List <DynLanMethodParam>(); Int32 index = -1; if (Program is DynLanMethod) { DynLanMethod method = (DynLanMethod)Program; foreach (String parameter in method.Parameters) { index++; Object parameterValue = Parameters == null ? null : index < Parameters.Count ? Parameters[index] : new Undefined(); if (obj != null) { obj[parameter] = parameterValue; finalParameters.Add(new DynLanMethodParam() { Name = parameter, Value = parameterValue }); } } } if (obj != null) { foreach (DynLanMethod DynLanMethod in Program.Methods) { if (state.Program is DynLanClass) { DynLanMethod newMethod = (DynLanMethod)DynLanMethod.Clone(); newMethod.ParentObject = obj; obj[newMethod.Name] = newMethod; } else { obj[DynLanMethod.Name] = DynLanMethod; } } foreach (DynLanClass DynLanClass in Program.Classes) { obj[DynLanClass.Name] = DynLanClass; } } RaiseProgramStart( state, finalParameters); return(state); }
public static Boolean EvaluateMethod( Object Object, Object MethodObject, IList <Object> Parameters, DynLanContext DynLanContext) { if (MethodObject is DynLanMethod) { if (Parameters == null) { Parameters = new Object[0]; } DynLanMethod method = (DynLanMethod)MethodObject; DynLanContextType contextType = DynLanContextType.METHOD; // jesli tworzenie klasy (wolanie konstruktora) if (MethodObject is DynLanClass) { contextType = DynLanContextType.CLASS; } DynLanState newContext = DynLanContext. PushContext(method, contextType, Parameters); newContext.Object.ParentObject = method.ParentObject; return(true); } else if (MethodObject is DynLanProgram) { DynLanProgram program = (DynLanProgram)MethodObject; IDictionary <String, Object> currentValues = (DynLanContext == null || DynLanContext.CurrentState == null || DynLanContext.CurrentState.Object == null ? null : DynLanContext. CurrentState. Object. DynamicValues); DynLanState newState = DynLanContext.PushContext( program, DynLanContextType.METHOD, null); if (currentValues != null) { foreach (String key in currentValues.Keys) { newState.Object.DynamicValues[key] = currentValues[key]; } } return(true); } else { ExpressionMethodResult methodResult = EvaluateInlineMethod( Object, MethodObject, Parameters, DynLanContext); if (methodResult != null && methodResult.NewContextCreated) { return(true); } else { var v = methodResult == null ? null : methodResult.Value; DynLanContext.CurrentExpressionState.PushValue(v); return(false); } } }