Private
Public Access
recursion ***somewhat*** works
This commit is contained in:
1 parent
2cf9e1a402
commit
229ce3ca56
10 files changed
+48
-54
No files matched your search
-1
@@ -94,7 +94,6 @@
|
||||
<Compile Include="Verbs\DrawingVerbs\Shape\Triangle.cs" />
|
||||
<Compile Include="Verbs\Flow\DeclareMethod.cs" />
|
||||
<Compile Include="Verbs\Flow\IfChunk.cs" />
|
||||
<Compile Include="Verbs\Flow\IncreaseStack.cs" />
|
||||
<Compile Include="Verbs\Flow\IVerbChunk.cs" />
|
||||
<Compile Include="Verbs\Flow\MethodChunk.cs" />
|
||||
<Compile Include="Verbs\Value\ValueObjects\PointValue.cs" />
|
||||
|
||||
+6
-4
@@ -7,15 +7,17 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Advanced_Software_Engineering.Verbs.Flow {
|
||||
class DeclareMethod : IVerb, IVerbChunk {
|
||||
|
||||
MethodChunk methodChunk;
|
||||
string methodName;
|
||||
Drawer drawer;
|
||||
|
||||
|
||||
public DeclareMethod(MethodChunk methodChunk) {
|
||||
this.methodChunk = methodChunk;
|
||||
public DeclareMethod(Drawer drawer, string methodName) {
|
||||
this.drawer = drawer;
|
||||
this.methodName = methodName;
|
||||
}
|
||||
|
||||
public void AddVerb(IVerb verb) {
|
||||
MethodChunk methodChunk = drawer.Methods[methodName];
|
||||
methodChunk.AddVerb(verb);
|
||||
}
|
||||
|
||||
|
||||
-26
@@ -1,26 +0,0 @@
|
||||
using Advanced_Software_Engineering.Verbs.Value;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Advanced_Software_Engineering.Verbs.Flow {
|
||||
public class IncreaseStack : IVerb {
|
||||
|
||||
ValueStorage valueStorage;
|
||||
|
||||
public IncreaseStack(ValueStorage valueStorage) {
|
||||
valueStorage.IncreaseStack();
|
||||
this.valueStorage = valueStorage;
|
||||
}
|
||||
|
||||
public void ExecuteVerb() {
|
||||
valueStorage.IncreaseStack();
|
||||
}
|
||||
|
||||
public string GetDescription() {
|
||||
return "Increase the stack";
|
||||
}
|
||||
}
|
||||
}
|
||||
+23
-2
@@ -8,6 +8,7 @@ namespace Advanced_Software_Engineering.Verbs.Flow {
|
||||
|
||||
ValueStorage valueStorage;
|
||||
DeclareVariable[] variables;
|
||||
UpdateVariable[] updateVariables;
|
||||
bool init = false;
|
||||
IValue result;
|
||||
|
||||
@@ -26,12 +27,32 @@ namespace Advanced_Software_Engineering.Verbs.Flow {
|
||||
return variables;
|
||||
}
|
||||
|
||||
public void SetVariableValues(UpdateVariable[] updateVariables) {
|
||||
this.updateVariables = updateVariables;
|
||||
}
|
||||
|
||||
public MethodChunk DuplicateForExecution() {
|
||||
MethodChunk method = new MethodChunk(valueStorage, variables);
|
||||
method.SetVariableValues(updateVariables);
|
||||
|
||||
foreach (IVerb verb in base.GetVerbs()) method.AddVerb(verb);
|
||||
|
||||
return method;
|
||||
}
|
||||
|
||||
public new void ExecuteVerb() {
|
||||
init = false;
|
||||
result = null;
|
||||
// The stack increased artificially
|
||||
//valueStorage.IncreaseStack();
|
||||
|
||||
valueStorage.IncreaseStack();
|
||||
|
||||
//Declare everything
|
||||
foreach (DeclareVariable variable in variables) variable.ExecuteVerb();
|
||||
|
||||
//Set the values of everything
|
||||
foreach (UpdateVariable variable in updateVariables) variable.ExecuteVerb();
|
||||
|
||||
//Run code
|
||||
base.ExecuteVerb();
|
||||
if (valueStorage.CheckVariableExists("ret")) {
|
||||
result = valueStorage.GetVariable("ret");
|
||||
|
||||
@@ -21,6 +21,10 @@ namespace Advanced_Software_Engineering.Verbs.Flow {
|
||||
foreach (IVerb verb in verbs) verb.ExecuteVerb();
|
||||
}
|
||||
|
||||
public IVerb[] GetVerbs() {
|
||||
return verbs.ToArray();
|
||||
}
|
||||
|
||||
public string GetDescription() {
|
||||
string s = "VerbChunk Start";
|
||||
foreach (IVerb verb in verbs) s += "\n" + verb.GetDescription();
|
||||
|
||||
+2
-1
@@ -109,7 +109,8 @@ namespace Advanced_Software_Engineering.Verbs.Value {
|
||||
}
|
||||
|
||||
public void ExecuteVerb() {
|
||||
storage.SetVariable(name, value);
|
||||
if (value != null) storage.SetVariable(name, value.Clone());
|
||||
else storage.SetVariable(name, value);
|
||||
}
|
||||
|
||||
public string GetDescription() {
|
||||
|
||||
+1
-1
@@ -62,7 +62,7 @@ namespace Advanced_Software_Engineering.Verbs.Value {
|
||||
|
||||
public IValue GetVariable(string name) {
|
||||
for (int stack = currentStack; stack >= 0; stack--) {
|
||||
if (CheckVariableExists(name, stack)) return GetVariable(name, stack);
|
||||
if (CheckVariableExists(name, stack) && GetVariable(name, stack) != null) return GetVariable(name, stack);
|
||||
}
|
||||
throw new Exception("Cannot find variable " + name);
|
||||
}
|
||||
|
||||
+4
-1
@@ -57,7 +57,10 @@ namespace Advanced_Software_Engineering.Verbs.Value {
|
||||
private IValue Evaluate() {
|
||||
if (evaluated) return evaluatedValue;
|
||||
|
||||
string outputType = variable1.Clone().GetOriginalType();
|
||||
IValue variable1 = this.variable1.Clone();
|
||||
IValue variable2 = this.variable2.Clone();
|
||||
|
||||
string outputType = variable1.GetOriginalType();
|
||||
|
||||
switch (outputType) {
|
||||
case "bool":
|
||||
|
||||
+1
-1
@@ -46,7 +46,7 @@ namespace Advanced_Software_Engineering.Verbs.Value.ValueTypes {
|
||||
}
|
||||
|
||||
public IValue Clone() {
|
||||
return new VariableValue(storage, variableName);
|
||||
return get().Clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -113,10 +113,12 @@ namespace Advanced_Software_Engineering {
|
||||
}
|
||||
methodParameters = methodParameterList.ToArray();
|
||||
}
|
||||
|
||||
//Get method name
|
||||
string methodName = commandParameters[0];
|
||||
|
||||
MethodChunk methodChunk = new MethodChunk(rootValueStorage, methodParameters);
|
||||
DeclareMethod declareMethod = new DeclareMethod(methodChunk);
|
||||
DeclareMethod declareMethod = new DeclareMethod(drawer, methodName);
|
||||
|
||||
drawer.Methods.Add(methodName, methodChunk);
|
||||
verbChunks.Add(declareMethod);
|
||||
@@ -159,27 +161,15 @@ namespace Advanced_Software_Engineering {
|
||||
*
|
||||
*/
|
||||
|
||||
VerbChunk localChunk = new VerbChunk();
|
||||
localChunk.AddVerb(new IncreaseStack(rootValueStorage));
|
||||
|
||||
// Declare all of the variables first
|
||||
foreach (DeclareVariable variable in methodChunk.GetVariables()) localChunk.AddVerb(variable);
|
||||
|
||||
// Update the values of the variables
|
||||
List<UpdateVariable> UpdateVariableList = new List<UpdateVariable>();
|
||||
for (int variableIndex = 0; variableIndex < methodVariableNames.Length; variableIndex++) {
|
||||
UpdateVariable variableDeclaration = new UpdateVariable(rootValueStorage, methodVariableNames[variableIndex], parameters[variableIndex]);
|
||||
localChunk.AddVerb(variableDeclaration);
|
||||
UpdateVariableList.Add(new UpdateVariable(rootValueStorage, methodVariableNames[variableIndex], parameters[variableIndex]));
|
||||
}
|
||||
|
||||
// localChunk.AddVerb(methodChunk);
|
||||
|
||||
//Add chunk to chunk stack
|
||||
localChunk.AddVerb(methodChunk);
|
||||
//verbChunks.Add(localChunk);
|
||||
|
||||
//chunkDepth = verbChunks.Count - 1;
|
||||
//currentChunk = verbChunks[chunkDepth];
|
||||
tmpVerb = localChunk;
|
||||
methodChunk.SetVariableValues(UpdateVariableList.ToArray());
|
||||
tmpVerb = methodChunk.DuplicateForExecution();
|
||||
}
|
||||
|
||||
//process drawing commands and extras
|
||||
|
||||
Reference in new issue
Block a user