mirror of
https://github.com/sam-astro/Z-Sharp.git
synced 2025-12-11 16:22:12 +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;
|
||||
}
|
||||
|
||||
bool IsFunction(string funcName)
|
||||
int IsFunction(string funcName)
|
||||
{
|
||||
// Iterate through all functions
|
||||
for (int t = 0; t < (int)functions.size(); t++)
|
||||
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)
|
||||
@ -194,7 +194,8 @@ string EvalExpression(string expression, vector<string>& variables, vector<strin
|
||||
// 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 (IsFunction(split(expression, '(')[0]) && !inQuotes)
|
||||
int funcIndex = IsFunction(split(expression, '(')[0]);
|
||||
if (funcIndex != -1 && !inQuotes)
|
||||
{
|
||||
//cout << split(expression, '(')[0] << endl;
|
||||
string argContents = "";
|
||||
@ -206,7 +207,7 @@ string EvalExpression(string expression, vector<string>& variables, vector<strin
|
||||
y++;
|
||||
}
|
||||
//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;
|
||||
}
|
||||
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);
|
||||
if (IsFunction(name) && !inQuotes)
|
||||
int funcIndex = IsFunction(name);
|
||||
if (funcIndex != -1 && !inQuotes)
|
||||
{
|
||||
string argContents = "";
|
||||
i++;
|
||||
@ -256,7 +258,7 @@ string EvalExpression(string expression, vector<string>& variables, vector<strin
|
||||
|
||||
i++;
|
||||
}
|
||||
string returnVal = ExecuteFunction(name, VarValues(split(argContents, ','), variables, variableVals));
|
||||
string returnVal = ExecuteFunction(name, VarValues(split(argContents, ','), variables, variableVals), funcIndex);
|
||||
newExpression += returnVal;
|
||||
//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])
|
||||
{
|
||||
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 "";
|
||||
}
|
||||
}
|
||||
@ -575,20 +577,23 @@ string ProcessLine(vector<vector<string>> words, int lineNum, vector<string>& va
|
||||
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> functionLines;
|
||||
int functionIndex = 0;
|
||||
//Get index of function
|
||||
for (int f = 0; f < (int)functions.size(); f++)
|
||||
if (split(functions[f], ' ')[0] == functionName)
|
||||
{
|
||||
functionLines = functionValues[f];
|
||||
functionIndex = f;
|
||||
break;
|
||||
}
|
||||
if (functionIndex == -1)
|
||||
{
|
||||
for (int f = 0; f < (int)functions.size(); f++)
|
||||
if (split(functions[f], ' ')[0] == functionName)
|
||||
{
|
||||
functionLines = functionValues[f];
|
||||
functionIndex = f;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
functionLines = functionValues[functionIndex];
|
||||
|
||||
vector<string> variables;
|
||||
vector<string> variableValues;
|
||||
@ -683,7 +688,7 @@ int parseSlang(string script)
|
||||
}
|
||||
|
||||
// Executes main, which is the starting function
|
||||
ExecuteFunction("Main", vector<string> {"\"hi\"", "0"});
|
||||
ExecuteFunction("Main", vector<string> {"\"hi\"", "0"}, -1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ float EulersNumber = 2.71828183
|
||||
|
||||
float Sin(float input)
|
||||
{
|
||||
print input
|
||||
float out = CPP.Math.Sin(input)
|
||||
return out
|
||||
}
|
||||
|
||||
@ -34,7 +34,7 @@ public:
|
||||
|
||||
bool OnUserUpdate(float fElapsedTime) override
|
||||
{
|
||||
ExecuteFunction("Update", vector<string> {""});
|
||||
ExecuteFunction("Update", vector<string> {""}, -1);
|
||||
|
||||
// Called once per frame
|
||||
//for (int x = 0; x < ScreenWidth(); x++)
|
||||
|
||||
@ -4,6 +4,6 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
string ExecuteFunction(string functionName, vector<string> inputVarVals);
|
||||
string ExecuteFunction(string functionName, vector<string> inputVarVals, int functionIndex);
|
||||
|
||||
#endif
|
||||
@ -4,12 +4,14 @@ void Main(string input, int in)
|
||||
{
|
||||
print "PI is: " + PI
|
||||
int x = 1
|
||||
|
||||
print x
|
||||
float k = 0
|
||||
|
||||
print k
|
||||
while x < 5
|
||||
{
|
||||
print x
|
||||
float s = Sin(x)
|
||||
print s
|
||||
int k = Sigmoid(s)
|
||||
print k
|
||||
|
||||
@ -19,9 +21,19 @@ void Main(string input, int in)
|
||||
CPP.Graphics.Init(64, 64, 4)
|
||||
}
|
||||
|
||||
void Update(string x, string y)
|
||||
void Update(string input)
|
||||
{
|
||||
SetPixel(x, y, 255, 0, 0)
|
||||
y += 1
|
||||
// print "updating"
|
||||
int x = 0
|
||||
int y = 0
|
||||
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