mirror of
https://github.com/sam-astro/Z-Sharp.git
synced 2025-12-13 09:02:10 +00:00
Performance fix
This commit is contained in:
parent
9874d03b3f
commit
2880d7e007
@ -176,14 +176,14 @@ vector<string> VarValues(vector<string> varNames, vector<string>& variables, vec
|
|||||||
return realValues;
|
return realValues;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsFunction(string funcName)
|
int IsFunction(string funcName)
|
||||||
{
|
{
|
||||||
// Iterate through all functions
|
// Iterate through all functions
|
||||||
for (int t = 0; t < (int)functions.size(); t++)
|
for (int t = 0; t < (int)functions.size(); t++)
|
||||||
if (trim(funcName) == split(functions[t], ' ')[0])
|
if (trim(funcName) == split(functions[t], ' ')[0])
|
||||||
return true;
|
return t;
|
||||||
|
|
||||||
return false;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
string EvalExpression(string expression, vector<string>& variables, vector<string>& variableVals)
|
string EvalExpression(string expression, vector<string>& variables, vector<string>& variableVals)
|
||||||
@ -194,7 +194,8 @@ string EvalExpression(string expression, vector<string>& variables, vector<strin
|
|||||||
// If no operations are applied, then return self
|
// If no operations are applied, then return self
|
||||||
if ((count(expression, '+') == 0 && count(expression, '-') == 0 && count(expression, '*') == 0 && count(expression, '/') == 0 && count(expression, '(') == 0 && count(expression, '^') == 0) || split(expression, '.')[0] == "CPP")
|
if ((count(expression, '+') == 0 && count(expression, '-') == 0 && count(expression, '*') == 0 && count(expression, '/') == 0 && count(expression, '(') == 0 && count(expression, '^') == 0) || split(expression, '.')[0] == "CPP")
|
||||||
{
|
{
|
||||||
if (IsFunction(split(expression, '(')[0]) && !inQuotes)
|
int funcIndex = IsFunction(split(expression, '(')[0]);
|
||||||
|
if (funcIndex != -1 && !inQuotes)
|
||||||
{
|
{
|
||||||
//cout << split(expression, '(')[0] << endl;
|
//cout << split(expression, '(')[0] << endl;
|
||||||
string argContents = "";
|
string argContents = "";
|
||||||
@ -206,7 +207,7 @@ string EvalExpression(string expression, vector<string>& variables, vector<strin
|
|||||||
y++;
|
y++;
|
||||||
}
|
}
|
||||||
//cout << split(expression, '(')[0] << " " << argContents << endl;
|
//cout << split(expression, '(')[0] << " " << argContents << endl;
|
||||||
string returnVal = ExecuteFunction(split(expression, '(')[0], VarValues(split(argContents, ','), variables, variableVals));
|
string returnVal = ExecuteFunction(split(expression, '(')[0], VarValues(split(argContents, ','), variables, variableVals), funcIndex);
|
||||||
return returnVal;
|
return returnVal;
|
||||||
}
|
}
|
||||||
else if (split(expression, '.')[0] == "CPP" && !inQuotes)
|
else if (split(expression, '.')[0] == "CPP" && !inQuotes)
|
||||||
@ -246,7 +247,8 @@ string EvalExpression(string expression, vector<string>& variables, vector<strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
//string varVal = GetVariableValue(name, variables, variableVals);
|
//string varVal = GetVariableValue(name, variables, variableVals);
|
||||||
if (IsFunction(name) && !inQuotes)
|
int funcIndex = IsFunction(name);
|
||||||
|
if (funcIndex != -1 && !inQuotes)
|
||||||
{
|
{
|
||||||
string argContents = "";
|
string argContents = "";
|
||||||
i++;
|
i++;
|
||||||
@ -256,7 +258,7 @@ string EvalExpression(string expression, vector<string>& variables, vector<strin
|
|||||||
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
string returnVal = ExecuteFunction(name, VarValues(split(argContents, ','), variables, variableVals));
|
string returnVal = ExecuteFunction(name, VarValues(split(argContents, ','), variables, variableVals), funcIndex);
|
||||||
newExpression += returnVal;
|
newExpression += returnVal;
|
||||||
//cout << newExpression << endl;
|
//cout << newExpression << endl;
|
||||||
}
|
}
|
||||||
@ -414,7 +416,7 @@ string ProcessLine(vector<vector<string>> words, int lineNum, vector<string>& va
|
|||||||
{
|
{
|
||||||
if (split(words[lineNum][0], '(')[0] == split(functions[t], ' ')[0])
|
if (split(words[lineNum][0], '(')[0] == split(functions[t], ' ')[0])
|
||||||
{
|
{
|
||||||
ExecuteFunction(split(functions[t], ' ')[0], VarValues(split(RMParenthesis(replace(unWrapVec(words[lineNum]), split(functions[t], ' ')[0], "")), ','), variables, variableValues));
|
ExecuteFunction(split(functions[t], ' ')[0], VarValues(split(RMParenthesis(replace(unWrapVec(words[lineNum]), split(functions[t], ' ')[0], "")), ','), variables, variableValues), t);
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -575,20 +577,23 @@ string ProcessLine(vector<vector<string>> words, int lineNum, vector<string>& va
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
string ExecuteFunction(string functionName, vector<string> inputVarVals)
|
string ExecuteFunction(string functionName, vector<string> inputVarVals, int functionIndex)
|
||||||
{
|
{
|
||||||
//vector<string> inputVarVals = split(replace(inVals, " ", ""), ',');
|
//vector<string> inputVarVals = split(replace(inVals, " ", ""), ',');
|
||||||
|
|
||||||
vector<string> functionLines;
|
vector<string> functionLines;
|
||||||
int functionIndex = 0;
|
|
||||||
//Get index of function
|
//Get index of function
|
||||||
for (int f = 0; f < (int)functions.size(); f++)
|
if (functionIndex == -1)
|
||||||
if (split(functions[f], ' ')[0] == functionName)
|
{
|
||||||
{
|
for (int f = 0; f < (int)functions.size(); f++)
|
||||||
functionLines = functionValues[f];
|
if (split(functions[f], ' ')[0] == functionName)
|
||||||
functionIndex = f;
|
{
|
||||||
break;
|
functionLines = functionValues[f];
|
||||||
}
|
functionIndex = f;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
functionLines = functionValues[functionIndex];
|
||||||
|
|
||||||
vector<string> variables;
|
vector<string> variables;
|
||||||
vector<string> variableValues;
|
vector<string> variableValues;
|
||||||
@ -683,7 +688,7 @@ int parseSlang(string script)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Executes main, which is the starting function
|
// Executes main, which is the starting function
|
||||||
ExecuteFunction("Main", vector<string> {"\"hi\"", "0"});
|
ExecuteFunction("Main", vector<string> {"\"hi\"", "0"}, -1);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,7 @@ float EulersNumber = 2.71828183
|
|||||||
|
|
||||||
float Sin(float input)
|
float Sin(float input)
|
||||||
{
|
{
|
||||||
|
print input
|
||||||
float out = CPP.Math.Sin(input)
|
float out = CPP.Math.Sin(input)
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|||||||
@ -34,7 +34,7 @@ public:
|
|||||||
|
|
||||||
bool OnUserUpdate(float fElapsedTime) override
|
bool OnUserUpdate(float fElapsedTime) override
|
||||||
{
|
{
|
||||||
ExecuteFunction("Update", vector<string> {""});
|
ExecuteFunction("Update", vector<string> {""}, -1);
|
||||||
|
|
||||||
// Called once per frame
|
// Called once per frame
|
||||||
//for (int x = 0; x < ScreenWidth(); x++)
|
//for (int x = 0; x < ScreenWidth(); x++)
|
||||||
|
|||||||
@ -4,6 +4,6 @@
|
|||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
string ExecuteFunction(string functionName, vector<string> inputVarVals);
|
string ExecuteFunction(string functionName, vector<string> inputVarVals, int functionIndex);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@ -4,12 +4,14 @@ void Main(string input, int in)
|
|||||||
{
|
{
|
||||||
print "PI is: " + PI
|
print "PI is: " + PI
|
||||||
int x = 1
|
int x = 1
|
||||||
|
print x
|
||||||
float k = 0
|
float k = 0
|
||||||
|
print k
|
||||||
while x < 5
|
while x < 5
|
||||||
{
|
{
|
||||||
|
print x
|
||||||
float s = Sin(x)
|
float s = Sin(x)
|
||||||
|
print s
|
||||||
int k = Sigmoid(s)
|
int k = Sigmoid(s)
|
||||||
print k
|
print k
|
||||||
|
|
||||||
@ -19,9 +21,19 @@ void Main(string input, int in)
|
|||||||
CPP.Graphics.Init(64, 64, 4)
|
CPP.Graphics.Init(64, 64, 4)
|
||||||
}
|
}
|
||||||
|
|
||||||
void Update(string x, string y)
|
void Update(string input)
|
||||||
{
|
{
|
||||||
SetPixel(x, y, 255, 0, 0)
|
int x = 0
|
||||||
y += 1
|
int y = 0
|
||||||
// print "updating"
|
while x < 64
|
||||||
|
{
|
||||||
|
while y < 64
|
||||||
|
{
|
||||||
|
SetPixel(x, y, 255, 0, 0)
|
||||||
|
y += 1
|
||||||
|
}
|
||||||
|
y = 0
|
||||||
|
x += 1
|
||||||
|
}
|
||||||
|
print "updating"
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user