public override Boolean Execute(OALProgram OALProgram, EXEScope Scope) { //OALProgram.RequestNextStep(); OALProgram.ThreadSyncer.RequestStep(this, Scope, null); return(true); }
public virtual bool PreExecute(AnimationCommandStorage ACS, OALProgram OALProgram, EXEScope Scope) { OALProgram.AccessInstanceDatabase(); Boolean Success = this.Execute(OALProgram, Scope); ACS.AddAnimationStep(new AnimationCommand(Scope, this)); OALProgram.LeaveInstanceDatabase(); return(Success); }
public EXEThreadSynchronizator(OALProgram OALProgram) { this.Syncer = new object(); this.ThreadCount = 0; this.UntilLockResetCount = 0; this.InLockCount = 0; this.Blocked = false; this.Change = 0; this.OALProgram = OALProgram; }
public EXEScope() { this.PrimitiveVariables = new List <EXEPrimitiveVariable>(); this.ReferencingVariables = new List <EXEReferencingVariable>(); this.SetReferencingVariables = new List <EXEReferencingSetVariable>(); this.SuperScope = null; this.Commands = new List <EXECommand>(); this.OALProgram = null; }
public virtual Boolean SynchronizedExecute(OALProgram OALProgram, EXEScope Scope) { OALProgram.AccessInstanceDatabase(); Console.WriteLine(this.ToCode()); Boolean Success = this.Execute(OALProgram, Scope); Console.WriteLine("Done"); OALProgram.LeaveInstanceDatabase(); return(Success); }
public override bool Execute(OALProgram OALProgram, EXEScope Scope) { bool Result = DecoratedCommand.Execute(OALProgram, Scope); if (!Result) { return(Result); } CallTextBuffer.Append(DecoratedCommand.ToCode()); return(Result); }
public override Boolean Execute(OALProgram OALProgram, EXEScope Scope) { //Console.WriteLine("Assignment is being executed"); Boolean Result = false; String AssignedValue = this.AssignedExpression.Evaluate(Scope, OALProgram.ExecutionSpace); if (AssignedValue == null) { return(Result); } // If we are assigning to a variable if (this.AttributeName == null) { //Console.WriteLine("Assigning value: " + AssignedValue + " to variable " + this.VariableName); EXEPrimitiveVariable Variable = Scope.FindPrimitiveVariableByName(this.VariableName); // If the variable doesnt exist, we simply create it if (Variable == null) { //Console.WriteLine("Creating new var " + this.VariableName); Result = Scope.AddVariable(new EXEPrimitiveVariable(this.VariableName, AssignedValue)); } //If variable exists and its type is UNDEFINED else if (EXETypes.UnitializedName.Equals(Variable.Type)) { //Console.WriteLine("Assigning to unitialized var" + this.VariableName); Result = Variable.AssignValue(Variable.Name, AssignedValue); } // If the variable exists and is primitive else if (!EXETypes.ReferenceTypeName.Equals(Variable.Type)) { //Console.WriteLine("Assigning to initialized var" + this.VariableName); // If the types don't match, this fails and returns false AssignedValue = EXETypes.AdjustAssignedValue(Variable.Type, AssignedValue); Result = Variable.AssignValue("", AssignedValue); } // Variable exists and is not primitive. What to do, what to do? // We do nothing, we CANNOT ASSIGN TO HANDLES!!! } // We are assigning to an attribute of a variable else { EXEReferenceEvaluator RefEvaluator = new EXEReferenceEvaluator(); Result = RefEvaluator.SetAttributeValue(this.VariableName, this.AttributeName, Scope, OALProgram.ExecutionSpace, AssignedValue); //Console.WriteLine("Tried to assign " + AssignedValue + " to " + this.VariableName + "." + this.AttributeName); } //Console.WriteLine("Assignment Result: " + Result); return(Result); }
public override Boolean Execute(OALProgram OALProgram, EXEScope Scope) { //OALProgram.RequestNextStep(); OALProgram.ThreadSyncer.RequestStep(this, Scope, null); //Filip, ak mas null v executablecode tak vrat true inak toto dole EXEScopeMethod ExecutableCode = OALProgram.ExecutionSpace.getClassByName(this.CalledClass).getMethodByName(this.CalledMethod).ExecutableCode; if (ExecutableCode != null) { return(ExecutableCode.SynchronizedExecute(OALProgram, Scope)); } return(true); }
public override bool Execute(OALProgram OALProgram, EXEScope Scope) { bool Result = false; EXEReferencingVariable Variable = Scope.FindReferencingVariableByName(this.VariableName); if (Variable != null) { bool DestructionSuccess = OALProgram.ExecutionSpace.DestroyInstance(Variable.ClassName, Variable.ReferencedInstanceId); if (DestructionSuccess) { Result = Scope.UnsetReferencingVariables(Variable.ClassName, Variable.ReferencedInstanceId); } } return(Result); }
public override Boolean PreExecute(AnimationCommandStorage ACS, OALProgram OALProgram, EXEScope Scope) { this.OALProgram = OALProgram; this.OALProgram.ThreadSyncer.RegisterThread((uint)this.Threads.Count); EXEScopeParallel ParallelScope = this; Boolean Success = true; lock (this.MyThreadEndSyncer) { this.ActiveThreadCount = this.Threads.Count; } OALProgram.ThreadSyncer.UnregisterThread(); foreach (EXEScope ThreadScope in this.Threads) { new Thread(() => { Thread.CurrentThread.IsBackground = false; Boolean MySuccess = ThreadScope.PreExecute(ACS, OALProgram, ParallelScope); OALProgram.ThreadSyncer.UnregisterThread(); lock (ParallelScope.MyThreadEndSyncer) { Success &= MySuccess; ParallelScope.ActiveThreadCount--; if (ParallelScope.ActiveThreadCount == 0) { Monitor.PulseAll(this.MyThreadEndSyncer); } } }).Start(); } lock (this.MyThreadEndSyncer) { while (this.ActiveThreadCount > 0) { Monitor.Wait(this.MyThreadEndSyncer); } } OALProgram.ThreadSyncer.RegisterThread(1); return(Success); }
public EXEScope(EXEScope SuperScope, EXECommand[] Commands) { this.PrimitiveVariables = new List <EXEPrimitiveVariable>(); this.ReferencingVariables = new List <EXEReferencingVariable>(); this.SetReferencingVariables = new List <EXEReferencingSetVariable>(); this.SetSuperScope(SuperScope); this.Commands = new List <EXECommand>(); foreach (EXECommand Command in Commands) { this.AddCommand(Command); } this.OALProgram = null; }
public override Boolean PreExecute(AnimationCommandStorage ACS, OALProgram OALProgram, EXEScope Scope) { OALProgram.ThreadSyncer.RequestStep(this, Scope, ACS); //ACS.AddAnimationStep(new AnimationCommand(Scope, this)); //Filip, ak mas null v executablecode tak vrat true inak toto dole EXEScopeMethod ExecutableCode = OALProgram.ExecutionSpace.getClassByName(this.CalledClass).getMethodByName(this.CalledMethod).ExecutableCode; if (ExecutableCode != null) { return(ExecutableCode.PreExecute(ACS, OALProgram, Scope)); } return(true); }
public override Boolean PreExecute(AnimationCommandStorage ACS, OALProgram OALProgram, EXEScope Scope) { this.OALProgram = OALProgram; Boolean Success = true; foreach (EXECommand Command in this.Commands) { Success = Command.PreExecute(ACS, OALProgram, this); if (!Success) { break; } } return(Success); }
//"Scope" param is ignored here, because this class is a scope public override Boolean Execute(OALProgram OALProgram, EXEScope Scope) { this.OALProgram = OALProgram; Boolean Success = true; foreach (EXECommand Command in this.Commands) { Success = Command.SynchronizedExecute(OALProgram, this); if (!Success) { break; } } return(Success); }
// SetUloh2 public override bool Execute(OALProgram OALProgram, EXEScope Scope) { //Create an instance of given class -> will affect ExecutionSpace. //If ReferencingVariableName is provided (is not ""), create a referencing variable pointing to this instance -> will affect scope CDClass Class = OALProgram.ExecutionSpace.getClassByName(this.ClassName); if (Class == null) { return(false); } EXEReferencingVariable Variable = Scope.FindReferencingVariableByName(this.ReferencingVariableName); if (Variable != null) { if (!String.Equals(this.ClassName, Variable.ClassName)) { return(false); } } CDClassInstance Instance = Class.CreateClassInstance(); if (Instance == null) { return(false); } if (!"".Equals(this.ReferencingVariableName)) { if (Variable != null) { Variable.ReferencedInstanceId = Instance.UniqueID; } else { Variable = new EXEReferencingVariable(this.ReferencingVariableName, Class.Name, Instance.UniqueID); return(Scope.AddVariable(Variable)); } } return(true); }
// Create a relationship instance (between two variables pointing to class instances) // Based on class names get the CDRelationship from RelationshipSpace // Based on variable names get the instance ids from Scope.ReferencingVariables // Create relationship between the given instance ids (CDRelationship.CreateRelationship) and return result of it public override bool Execute(OALProgram OALProgram, EXEScope Scope) { EXEReferencingVariable Variable1 = Scope.FindReferencingVariableByName(this.Variable1Name); if (Variable1 == null) { return(false); } EXEReferencingVariable Variable2 = Scope.FindReferencingVariableByName(this.Variable2Name); if (Variable2 == null) { return(false); } CDRelationship Relationship = OALProgram.RelationshipSpace.GetRelationship(this.RelationshipName, Variable1.ClassName, Variable2.ClassName); if (Relationship == null) { return(false); } bool Success = Relationship.DestroyRelationship(Variable1.ReferencedInstanceId, Variable2.ReferencedInstanceId); return(Success); }
public abstract Boolean Execute(OALProgram OALProgram, EXEScope Scope);
public override Boolean Execute(OALProgram OALProgram, EXEScope Scope) { this.OALProgram = OALProgram; OALProgram.AccessInstanceDatabase(); EXEReferencingVariable IteratorVariable = this.FindReferencingVariableByName(this.IteratorName); EXEReferencingSetVariable IterableVariable = this.FindSetReferencingVariableByName(this.IterableName); OALProgram.LeaveInstanceDatabase(); Boolean Success = true; // We cannot iterate over not existing reference set if (Success && IterableVariable == null) { Success = false; } // If iterator already exists and its class does not match the iterable class, we cannot do this if (Success && IteratorVariable != null && !IteratorVariable.ClassName.Equals(IterableVariable.ClassName)) { Success = false; } // If iterator name is already taken for another variable, we quit again. Otherwise we create the iterator variable if (Success && IteratorVariable == null) { IteratorVariable = new EXEReferencingVariable(this.IteratorName, IterableVariable.ClassName, -1); Success = this.GetSuperScope().AddVariable(IteratorVariable); } if (Success) { foreach (EXEReferencingVariable CurrentItem in IterableVariable.GetReferencingVariables()) { //!!NON-RECURSIVE!! this.ClearVariables(); IteratorVariable.ReferencedInstanceId = CurrentItem.ReferencedInstanceId; Console.WriteLine("ForEach: " + CurrentItem.ReferencedInstanceId); foreach (EXECommand Command in this.Commands) { if (this.CurrentLoopControlCommand != LoopControlStructure.None) { break; } Success = Command.SynchronizedExecute(OALProgram, this); if (!Success) { break; } } if (!Success) { break; } if (this.CurrentLoopControlCommand == LoopControlStructure.Break) { this.CurrentLoopControlCommand = LoopControlStructure.None; break; } else if (this.CurrentLoopControlCommand == LoopControlStructure.Continue) { this.CurrentLoopControlCommand = LoopControlStructure.None; continue; } } } return(Success); }
public override Boolean SynchronizedExecute(OALProgram OALProgram, EXEScope Scope) { Boolean Success = this.Execute(OALProgram, this); return(Success); }
public override Boolean PreExecute(AnimationCommandStorage ACS, OALProgram OALProgram, EXEScope Scope) { OALProgram.ThreadSyncer.RequestStep(this, Scope, ACS); //ACS.AddAnimationStep(new AnimationCommand(Scope, this)); return(true); }
public override Boolean Execute(OALProgram OALProgram, EXEScope Scope) { this.OALProgram = OALProgram; Boolean Result = true; Boolean AScopeWasExecuted = false; if (this.Condition == null) { return(false); } OALProgram.AccessInstanceDatabase(); String ConditionResult = this.Condition.Evaluate(Scope, OALProgram.ExecutionSpace); OALProgram.LeaveInstanceDatabase(); if (ConditionResult == null) { return(false); } if (!EXETypes.BooleanTypeName.Equals(EXETypes.DetermineVariableType("", ConditionResult))) { return(false); } Boolean IfConditionResult = EXETypes.BooleanTrue.Equals(ConditionResult) ? true : false; if (IfConditionResult) { foreach (EXECommand Command in this.Commands) { Result = Command.SynchronizedExecute(OALProgram, this); if (!Result) { break; } } AScopeWasExecuted = true; } if (AScopeWasExecuted) { return(Result); } if (this.ElifScopes != null) { foreach (EXEScopeCondition CurrentElif in this.ElifScopes) { if (CurrentElif.Condition == null) { return(false); } OALProgram.AccessInstanceDatabase(); ConditionResult = CurrentElif.Condition.Evaluate(Scope, OALProgram.ExecutionSpace); OALProgram.LeaveInstanceDatabase(); if (ConditionResult == null) { return(false); } if (!EXETypes.BooleanTypeName.Equals(EXETypes.DetermineVariableType("", ConditionResult))) { return(false); } IfConditionResult = EXETypes.BooleanTrue.Equals(ConditionResult) ? true : false; if (IfConditionResult) { Result = CurrentElif.SynchronizedExecute(OALProgram, CurrentElif); AScopeWasExecuted = true; break; } } } if (AScopeWasExecuted) { return(Result); } if (this.ElseScope != null) { Result = this.ElseScope.SynchronizedExecute(OALProgram, ElseScope); } return(Result); }
public override Boolean Execute(OALProgram OALProgram, EXEScope Scope) { Boolean Success = true; this.OALProgram = OALProgram; bool ConditionTrue = true; String ConditionResult; int IterationCounter = 0; while (ConditionTrue) { OALProgram.AccessInstanceDatabase(); ConditionResult = this.Condition.Evaluate(Scope, OALProgram.ExecutionSpace); OALProgram.LeaveInstanceDatabase(); //!!NON-RECURSIVE!! this.ClearVariables(); if (ConditionResult == null) { return(false); } if (!EXETypes.BooleanTypeName.Equals(EXETypes.DetermineVariableType("", ConditionResult))) { return(false); } ConditionTrue = EXETypes.BooleanTrue.Equals(ConditionResult); if (!ConditionTrue) { break; } if (IterationCounter >= EXEExecutionGlobals.LoopIterationCap) { Success = false; break; } foreach (EXECommand Command in this.Commands) { if (this.CurrentLoopControlCommand != LoopControlStructure.None) { break; } Success = Command.SynchronizedExecute(OALProgram, this); if (!Success) { break; } } if (!Success) { break; } IterationCounter++; if (this.CurrentLoopControlCommand == LoopControlStructure.Break) { this.CurrentLoopControlCommand = LoopControlStructure.None; break; } else if (this.CurrentLoopControlCommand == LoopControlStructure.Continue) { this.CurrentLoopControlCommand = LoopControlStructure.None; continue; } } return(Success); }
// SetUloh2 public override bool Execute(OALProgram OALProgram, EXEScope Scope) { //Select instances of given class that match the criteria and assign them to variable with given name // ClassName tells us which class we are interested in // Cardinality tells us whether we want one random instance (matching the criteria) or all of them // "Many" - we create variable EXEReferencingSetVariable, "Any" - we create variable EXEReferencingVariable // Variable name tells us how to name the newly created referencing variable // Where condition tells us which instances to select from all instances of the class (just do EXEASTNode.Evaluate and return true if the result "true" and false for "false") // When making unit tests, do not use the "where" causule yet, because its evaluation is not yet implemented // If relationship selection does not exists, this is problem if (this.RelationshipSelection == null) { return(false); } CDClass Class = OALProgram.ExecutionSpace.getClassByName(this.RelationshipSelection.GetLastClassName()); if (Class == null) { return(false); } // We need to check, if the variable already exists, it must be of corresponding type if (Scope.VariableNameExists(this.VariableName)) { if ( !( (EXECommandQuerySelect.CardinalityAny.Equals(this.Cardinality) && this.RelationshipSelection.GetLastClassName() == Scope.FindReferencingVariableByName(this.VariableName).ClassName) || (EXECommandQuerySelect.CardinalityMany.Equals(this.Cardinality) && this.RelationshipSelection.GetLastClassName() == Scope.FindSetReferencingVariableByName(this.VariableName).ClassName) ) ) { return(false); } } // Evaluate relationship selection. If it fails, execution fails too List <long> SelectedIds = this.RelationshipSelection.Evaluate(OALProgram.RelationshipSpace, Scope); if (SelectedIds == null) { return(false); } // If class has no instances, command may execute successfully, but we better verify references in the WHERE condition if (SelectedIds.Count() == 0 && this.WhereCondition != null) { return(this.WhereCondition.VerifyReferences(Scope, OALProgram.ExecutionSpace)); } // Now let's evaluate the condition if (this.WhereCondition != null && SelectedIds.Any()) { String TempSelectedVarName = "selected"; EXEReferencingVariable SelectedVar = new EXEReferencingVariable(TempSelectedVarName, this.RelationshipSelection.GetLastClassName(), -1); if (!Scope.AddVariable(SelectedVar)) { return(false); } List <long> ResultIds = new List <long>(); foreach (long Id in SelectedIds) { SelectedVar.ReferencedInstanceId = Id; String ConditionResult = this.WhereCondition.Evaluate(Scope, OALProgram.ExecutionSpace); //Console.Write(Id + " : " + ConditionResult); if (!EXETypes.IsValidValue(ConditionResult, EXETypes.BooleanTypeName)) { Scope.DestroyReferencingVariable(TempSelectedVarName); return(false); } if (EXETypes.BooleanTrue.Equals(ConditionResult)) { ResultIds.Add(Id); } } SelectedIds = ResultIds; Scope.DestroyReferencingVariable(TempSelectedVarName); } // Now we have ids of selected instances. Let's assign them to a variable if (EXECommandQuerySelect.CardinalityMany.Equals(this.Cardinality)) { EXEReferencingSetVariable Variable = Scope.FindSetReferencingVariableByName(this.VariableName); if (Variable == null) { Variable = new EXEReferencingSetVariable(this.VariableName, this.RelationshipSelection.GetLastClassName()); if (!Scope.AddVariable(Variable)) { return(false); } } foreach (long Id in SelectedIds) { Variable.AddReferencingVariable(new EXEReferencingVariable("", Variable.ClassName, Id)); } } else if (EXECommandQuerySelect.CardinalityAny.Equals(this.Cardinality)) { EXEReferencingVariable Variable = Scope.FindReferencingVariableByName(this.VariableName); if (Variable == null) { long ResultId = SelectedIds.Any() ? SelectedIds[new Random().Next(SelectedIds.Count)] : -1; Variable = new EXEReferencingVariable(this.VariableName, this.RelationshipSelection.GetLastClassName(), ResultId); if (!Scope.AddVariable(Variable)) { return(false); } } } else { return(false); } return(true); }
public override bool SynchronizedExecute(OALProgram OALProgram, EXEScope Scope) { return(this.Execute(OALProgram, Scope)); }
// SetUloh2 public override bool Execute(OALProgram OALProgram, EXEScope Scope) { /* * //Select instances of given class that match the criteria and assign them to variable with given name * // ClassName tells us which class we are interested in * // Cardinality tells us whether we want one random instance (matching the criteria) or all of them * // "Many" - we create variable EXEReferencingSetVariable, "Any" - we create variable EXEReferencingVariable * // Variable name tells us how to name the newly created referencing variable * // Where condition tells us which instances to select from all instances of the class (just do EXEASTNode.Evaluate and return true if the result "true" and false for "false") * // When making unit tests, do not use the "where" causule yet, because its evaluation is not yet implemented * * CDClass Class = OALProgram.ExecutionSpace.getClassByName(this.ClassName); * if (Class == null) * { * return false; * } * * // We need to check, if the variable already exists, it must be of corresponding type * if (Scope.VariableNameExists(this.VariableName)) * { * if * ( * !( * ( * EXECommandQuerySelect.CardinalityAny.Equals(this.Cardinality) * && * this.ClassName == Scope.FindReferencingVariableByName(this.VariableName).ClassName * ) || || ( || EXECommandQuerySelect.CardinalityMany.Equals(this.Cardinality) || && || this.ClassName == Scope.FindSetReferencingVariableByName(this.VariableName).ClassName || ) || ) || ) || { || return false; || } ||} || ||// Evaluate relationship selection. If it fails, execution fails too ||List<long> SelectedIds = Class.GetAllInstanceIDs(); ||if (SelectedIds == null) ||{ || return false; ||} || ||// If class has no instances, command may execute successfully, but we better verify references in the WHERE condition ||if (SelectedIds.Count() == 0 && this.WhereCondition != null) ||{ || return this.WhereCondition.VerifyReferences(Scope, OALProgram.ExecutionSpace); ||} || ||//Console.WriteLine("Select has " + SelectedIds.Count + " potential results"); || ||// Now let's evaluate the condition ||if (this.WhereCondition != null && SelectedIds.Any()) ||{ || String TempSelectedVarName = "selected"; || || //Console.WriteLine("creating selected var"); || EXEReferencingVariable SelectedVar = new EXEReferencingVariable(TempSelectedVarName, this.ClassName, -1); || if (!Scope.AddVariable(SelectedVar)) || { || return false; || } ||// Console.WriteLine("created selected var"); || List<long> ResultIds = new List<long>(); || foreach (long Id in SelectedIds) || { || //Console.WriteLine("id check iteration start"); || SelectedVar.ReferencedInstanceId = Id; || String ConditionResult = this.WhereCondition.Evaluate(Scope, OALProgram.ExecutionSpace); || || //Console.WriteLine("cond evaluated"); || //Console.WriteLine(Id + " : " + ConditionResult == null ? "null" : ConditionResult); || || if (!EXETypes.IsValidValue(ConditionResult, EXETypes.BooleanTypeName)) || { || Scope.DestroyReferencingVariable(TempSelectedVarName); || return false; || } || || if (EXETypes.BooleanTrue.Equals(ConditionResult)) || { || ResultIds.Add(Id); || } || } || //Console.WriteLine("Select has " + SelectedIds.Count + " results"); || //foreach (long id in ResultIds) Console.WriteLine("RES: " + id); || SelectedIds = ResultIds; || Scope.DestroyReferencingVariable(TempSelectedVarName); || ||} || ||// Now we have ids of selected instances. Let's assign them to a variable ||if (EXECommandQuerySelect.CardinalityMany.Equals(this.Cardinality)) ||{ || EXEReferencingSetVariable Variable = Scope.FindSetReferencingVariableByName(this.VariableName); || if (Variable == null) || { || Variable = new EXEReferencingSetVariable(this.VariableName, this.ClassName); || if (!Scope.AddVariable(Variable)) || { || return false; || } || } || foreach (long Id in SelectedIds) || { || Variable.AddReferencingVariable(new EXEReferencingVariable("", Variable.ClassName, Id)); || } ||} ||else if (EXECommandQuerySelect.CardinalityAny.Equals(this.Cardinality)) ||{ || EXEReferencingVariable Variable = Scope.FindReferencingVariableByName(this.VariableName); || long ResultId = SelectedIds.Any() ? SelectedIds[new Random().Next(SelectedIds.Count)] : -1; || if (Variable == null) || { || //Console.WriteLine("Final 'any' id is " + ResultId); || Variable = new EXEReferencingVariable(this.VariableName, this.ClassName, ResultId); || if (!Scope.AddVariable(Variable)) || { || return false; || } || } || else || { || Variable.ReferencedInstanceId = ResultId; || } ||} ||else ||{ || return false; ||} || ||return true; */ ConsolePanel.Instance.YieldOutput(ToCodeSimple()); return(true); }