Change [] operator to .at(), use cin() instead of system("pause"), use cout instead of cerr, add required .dlls

* Change [] operator to .at() for vectors for proper error handling
* Use cin() instead of system("pause") for better cross-platform compatability
* Added libfreetype-6.dll, libjpeg-9.dll, libpng16-16.dll, libtiff-5.dll, libwebp-7.dll, zlib1.dll
This commit is contained in:
sam-astro 2022-01-17 12:13:34 -05:00
parent a07f7aa61f
commit 7e784d3188
4 changed files with 174 additions and 255 deletions

View File

@ -33,12 +33,6 @@
}
"Entry"
{
"MsmKey" = "8:_30B059D12CC4427B998612ABE14AD9FE"
"OwnerKey" = "8:_UNDEFINED"
"MsmSig" = "8:_UNDEFINED"
}
"Entry"
{
"MsmKey" = "8:_38EBD2EEB8C34316A3249C9D9873B1C2"
"OwnerKey" = "8:_UNDEFINED"
"MsmSig" = "8:_UNDEFINED"
@ -57,18 +51,6 @@
}
"Entry"
{
"MsmKey" = "8:_63B7B5320B9540CBB4C2AFA5A14B2649"
"OwnerKey" = "8:_UNDEFINED"
"MsmSig" = "8:_UNDEFINED"
}
"Entry"
{
"MsmKey" = "8:_6631FA01F35946F2B90DE75D9A2924D7"
"OwnerKey" = "8:_UNDEFINED"
"MsmSig" = "8:_UNDEFINED"
}
"Entry"
{
"MsmKey" = "8:_7C9D3FE3584D494F807EBD12C93E2FC5"
"OwnerKey" = "8:_UNDEFINED"
"MsmSig" = "8:_UNDEFINED"
@ -230,26 +212,6 @@
"IsDependency" = "11:FALSE"
"IsolateTo" = "8:"
}
"{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_30B059D12CC4427B998612ABE14AD9FE"
{
"SourcePath" = "8:..\\Releases\\Slang-Win-x64\\SDL2_image.dll"
"TargetName" = "8:SDL2_image.dll"
"Tag" = "8:"
"Folder" = "8:_BCDF457FF4564F7BBFD6AEF054FE16C2"
"Condition" = "8:"
"Transitive" = "11:FALSE"
"Vital" = "11:TRUE"
"ReadOnly" = "11:FALSE"
"Hidden" = "11:FALSE"
"System" = "11:FALSE"
"Permanent" = "11:FALSE"
"SharedLegacy" = "11:FALSE"
"PackageAs" = "3:1"
"Register" = "3:1"
"Exclude" = "11:FALSE"
"IsDependency" = "11:FALSE"
"IsolateTo" = "8:"
}
"{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_38EBD2EEB8C34316A3249C9D9873B1C2"
{
"SourcePath" = "8:..\\Releases\\Slang-Win-x64\\zlib1.dll"
@ -310,46 +272,6 @@
"IsDependency" = "11:FALSE"
"IsolateTo" = "8:"
}
"{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_63B7B5320B9540CBB4C2AFA5A14B2649"
{
"SourcePath" = "8:..\\Releases\\Slang-Win-x64\\SDL2.dll"
"TargetName" = "8:SDL2.dll"
"Tag" = "8:"
"Folder" = "8:_BCDF457FF4564F7BBFD6AEF054FE16C2"
"Condition" = "8:"
"Transitive" = "11:FALSE"
"Vital" = "11:TRUE"
"ReadOnly" = "11:FALSE"
"Hidden" = "11:FALSE"
"System" = "11:FALSE"
"Permanent" = "11:FALSE"
"SharedLegacy" = "11:FALSE"
"PackageAs" = "3:1"
"Register" = "3:1"
"Exclude" = "11:FALSE"
"IsDependency" = "11:FALSE"
"IsolateTo" = "8:"
}
"{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_6631FA01F35946F2B90DE75D9A2924D7"
{
"SourcePath" = "8:..\\Releases\\Slang-Win-x64\\SDL2_ttf.dll"
"TargetName" = "8:SDL2_ttf.dll"
"Tag" = "8:"
"Folder" = "8:_BCDF457FF4564F7BBFD6AEF054FE16C2"
"Condition" = "8:"
"Transitive" = "11:FALSE"
"Vital" = "11:TRUE"
"ReadOnly" = "11:FALSE"
"Hidden" = "11:FALSE"
"System" = "11:FALSE"
"Permanent" = "11:FALSE"
"SharedLegacy" = "11:FALSE"
"PackageAs" = "3:1"
"Register" = "3:1"
"Exclude" = "11:FALSE"
"IsDependency" = "11:FALSE"
"IsolateTo" = "8:"
}
"{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_7C9D3FE3584D494F807EBD12C93E2FC5"
{
"SourcePath" = "8:installer-icon.ico"
@ -537,15 +459,15 @@
{
"Name" = "8:Microsoft Visual Studio"
"ProductName" = "8:Slang"
"ProductCode" = "8:{3F1665C5-F602-4107-B71C-6101FF2DC973}"
"PackageCode" = "8:{E26509B2-C19C-4E07-A5D1-8E05B189963C}"
"ProductCode" = "8:{A5629CD2-46CB-4945-BBA2-BAC60F2DDFC4}"
"PackageCode" = "8:{DEE267E6-C968-4059-8F0F-4560CF270A35}"
"UpgradeCode" = "8:{8ABDE53F-7FF9-455B-A777-B4C1C624FA13}"
"AspNetVersion" = "8:2.0.50727.0"
"RestartWWWService" = "11:FALSE"
"RemovePreviousVersions" = "11:TRUE"
"DetectNewerInstalledVersion" = "11:TRUE"
"InstallAllUsers" = "11:FALSE"
"ProductVersion" = "8:1.2.1"
"ProductVersion" = "8:1.2.2"
"Manufacturer" = "8:Sam-Astro"
"ARPHELPTELEPHONE" = "8:"
"ARPHELPLINK" = "8:"

View File

@ -1,4 +1,4 @@

#include <iostream>
#include <fstream>
#include <string>
@ -86,7 +86,7 @@ vector<boost::any> VarValues(const vector<string>& varNames, unordered_map<strin
for (int varIndex = 0; varIndex < varNames.size(); varIndex++)
{
string varName = trim(varNames[varIndex]);
string varName = trim(varNames.at(varIndex));
//realValues.push_back(EvalExpression(varName, variableValues));
auto iA = variableValues.find(varName);
@ -116,7 +116,7 @@ bool IsFunction(const string& funcName)
}
bool IsSLBFunction(const string& funcName)
{
if (funcName[0] == 'S' && funcName[1] == 'L' && funcName[2] == 'B' && funcName[2] == '.')
if (funcName[0] == 'S' && funcName[1] == 'L' && funcName[2] == 'B' && funcName[3] == '.')
return true;
else
return false;
@ -128,7 +128,7 @@ boost::any EvalExpression(const string& ex, unordered_map<string, boost::any>& v
bool inQuotes = false;
#if DEVELOPER_MESSAGES == true
InterpreterLog("OLDEXPRESSION: |" + expression + "|");
InterpreterLog(" old expression: |" + expression + "|");
#endif
bool isFunc = IsFunction(split(expression, '(')[0]);
@ -229,7 +229,7 @@ boost::any EvalExpression(const string& ex, unordered_map<string, boost::any>& v
}
}
#if DEVELOPER_MESSAGES == true
InterpreterLog("NEW EXPRESSION: |" + newExpression + "|");
InterpreterLog(" new expression: |" + newExpression + "|");
#endif
bool addStrings = false;
@ -290,168 +290,168 @@ bool BooleanLogic(const string& valA, const string& determinant, const string& v
int varOperation(const vector<string>& str, unordered_map<string, boost::any>& variableValues)
{
if (IsVar(str[0], variableValues))
if (IsVar(str.at(0), variableValues))
{
// Checks if type is simple, like int or string
if (any_type(variableValues[str[0]]) <= 3)
if (any_type(variableValues[str.at(0)]) <= 3)
{
if (str[1] == "=")
variableValues[str[0]] = EvalExpression(unWrapVec(vector<string>(str.begin() + 2, str.end())), variableValues);
else if (str[1] == "+=")
variableValues[str[0]] = EvalExpression(str[0] + "+(" + unWrapVec(vector<string>(str.begin() + 2, str.end())) + ")", variableValues);
else if (str[1] == "-=")
variableValues[str[0]] = AnyAsFloat(variableValues[str[0]]) - AnyAsFloat(EvalExpression(unWrapVec(vector<string>(str.begin() + 2, str.end())), variableValues));
else if (str[1] == "*=")
variableValues[str[0]] = AnyAsFloat(variableValues[str[0]]) * AnyAsFloat(EvalExpression(unWrapVec(vector<string>(str.begin() + 2, str.end())), variableValues));
else if (str[1] == "/=")
variableValues[str[0]] = AnyAsFloat(variableValues[str[0]]) / AnyAsFloat(EvalExpression(unWrapVec(vector<string>(str.begin() + 2, str.end())), variableValues));
if (str.at(1) == "=")
variableValues[str.at(0)] = EvalExpression(unWrapVec(vector<string>(str.begin() + 2, str.end())), variableValues);
else if (str.at(1) == "+=")
variableValues[str.at(0)] = EvalExpression(str.at(0) + "+(" + unWrapVec(vector<string>(str.begin() + 2, str.end())) + ")", variableValues);
else if (str.at(1) == "-=")
variableValues[str.at(0)] = AnyAsFloat(variableValues[str.at(0)]) - AnyAsFloat(EvalExpression(unWrapVec(vector<string>(str.begin() + 2, str.end())), variableValues));
else if (str.at(1) == "*=")
variableValues[str.at(0)] = AnyAsFloat(variableValues[str.at(0)]) * AnyAsFloat(EvalExpression(unWrapVec(vector<string>(str.begin() + 2, str.end())), variableValues));
else if (str.at(1) == "/=")
variableValues[str.at(0)] = AnyAsFloat(variableValues[str.at(0)]) / AnyAsFloat(EvalExpression(unWrapVec(vector<string>(str.begin() + 2, str.end())), variableValues));
else
LogWarning("unrecognized operator \'" + str[1] + "\'");
LogWarning("unrecognized operator \'" + str.at(1) + "\'");
}
// Else it is a Vec2. No other complex class can be operated on it's base form (ex. you can't do: Sprite += Sprite)
else if (any_type(variableValues[str[0]]) == 5)
else if (any_type(variableValues[str.at(0)]) == 5)
{
boost::any otherExpression = EvalExpression(unWrapVec(vector<string>(str.begin() + 2, str.end())), variableValues);
if (str[1] == "=")
variableValues[str[0]] = otherExpression;
else if (str[1] == "+=")
variableValues[str[0]] = AnyAsVec2(variableValues[str[0]]) + AnyAsVec2(otherExpression);
else if (str[1] == "-=")
variableValues[str[0]] = AnyAsVec2(variableValues[str[0]]) - AnyAsVec2(otherExpression);
else if (str[1] == "*=")
variableValues[str[0]] = AnyAsVec2(variableValues[str[0]]) * AnyAsFloat(otherExpression);
else if (str[1] == "/=")
variableValues[str[0]] = AnyAsVec2(variableValues[str[0]]) / AnyAsFloat(otherExpression);
if (str.at(1) == "=")
variableValues[str.at(0)] = otherExpression;
else if (str.at(1) == "+=")
variableValues[str.at(0)] = AnyAsVec2(variableValues[str.at(0)]) + AnyAsVec2(otherExpression);
else if (str.at(1) == "-=")
variableValues[str.at(0)] = AnyAsVec2(variableValues[str.at(0)]) - AnyAsVec2(otherExpression);
else if (str.at(1) == "*=")
variableValues[str.at(0)] = AnyAsVec2(variableValues[str.at(0)]) * AnyAsFloat(otherExpression);
else if (str.at(1) == "/=")
variableValues[str.at(0)] = AnyAsVec2(variableValues[str.at(0)]) / AnyAsFloat(otherExpression);
else
LogWarning("unrecognized operator \'" + str[1] + "\'");
LogWarning("unrecognized operator \'" + str.at(1) + "\'");
}
return 0;
}
else if (IsVar(str[0], globalVariableValues))
else if (IsVar(str.at(0), globalVariableValues))
{
// Checks if type is simple, like int or string
if (any_type(globalVariableValues[str[0]]) <= 3)
if (any_type(globalVariableValues[str.at(0)]) <= 3)
{
if (str[1] == "=")
globalVariableValues[str[0]] = EvalExpression(unWrapVec(vector<string>(str.begin() + 2, str.end())), variableValues);
else if (str[1] == "+=")
globalVariableValues[str[0]] = EvalExpression(str[0] + "+(" + unWrapVec(vector<string>(str.begin() + 2, str.end())) + ")", variableValues);
else if (str[1] == "-=")
globalVariableValues[str[0]] = AnyAsFloat(globalVariableValues[str[0]]) - AnyAsFloat(EvalExpression(unWrapVec(vector<string>(str.begin() + 2, str.end())), variableValues));
else if (str[1] == "*=")
globalVariableValues[str[0]] = AnyAsFloat(globalVariableValues[str[0]]) * AnyAsFloat(EvalExpression(unWrapVec(vector<string>(str.begin() + 2, str.end())), variableValues));
else if (str[1] == "/=")
globalVariableValues[str[0]] = AnyAsFloat(globalVariableValues[str[0]]) / AnyAsFloat(EvalExpression(unWrapVec(vector<string>(str.begin() + 2, str.end())), variableValues));
if (str.at(1) == "=")
globalVariableValues[str.at(0)] = EvalExpression(unWrapVec(vector<string>(str.begin() + 2, str.end())), variableValues);
else if (str.at(1) == "+=")
globalVariableValues[str.at(0)] = EvalExpression(str.at(0) + "+(" + unWrapVec(vector<string>(str.begin() + 2, str.end())) + ")", variableValues);
else if (str.at(1) == "-=")
globalVariableValues[str.at(0)] = AnyAsFloat(globalVariableValues[str.at(0)]) - AnyAsFloat(EvalExpression(unWrapVec(vector<string>(str.begin() + 2, str.end())), variableValues));
else if (str.at(1) == "*=")
globalVariableValues[str.at(0)] = AnyAsFloat(globalVariableValues[str.at(0)]) * AnyAsFloat(EvalExpression(unWrapVec(vector<string>(str.begin() + 2, str.end())), variableValues));
else if (str.at(1) == "/=")
globalVariableValues[str.at(0)] = AnyAsFloat(globalVariableValues[str.at(0)]) / AnyAsFloat(EvalExpression(unWrapVec(vector<string>(str.begin() + 2, str.end())), variableValues));
else
LogWarning("unrecognized operator \'" + str[1] + "\'");
LogWarning("unrecognized operator \'" + str.at(1) + "\'");
}
// Else it is a Vec2. No other complex class can be operated on it's base form (ex. you can't do: Sprite += Sprite)
else if (any_type(globalVariableValues[str[0]]) == 5)
else if (any_type(globalVariableValues[str.at(0)]) == 5)
{
boost::any otherExpression = EvalExpression(unWrapVec(vector<string>(str.begin() + 2, str.end())), variableValues);
if (str[1] == "=")
globalVariableValues[str[0]] = otherExpression;
else if (str[1] == "+=")
globalVariableValues[str[0]] = AnyAsVec2(globalVariableValues[str[0]]) + AnyAsVec2(otherExpression);
else if (str[1] == "-=")
globalVariableValues[str[0]] = AnyAsVec2(globalVariableValues[str[0]]) - AnyAsVec2(otherExpression);
else if (str[1] == "*=")
globalVariableValues[str[0]] = AnyAsVec2(globalVariableValues[str[0]]) * AnyAsFloat(otherExpression);
else if (str[1] == "/=")
globalVariableValues[str[0]] = AnyAsVec2(globalVariableValues[str[0]]) / AnyAsFloat(otherExpression);
if (str.at(1) == "=")
globalVariableValues[str.at(0)] = otherExpression;
else if (str.at(1) == "+=")
globalVariableValues[str.at(0)] = AnyAsVec2(globalVariableValues[str.at(0)]) + AnyAsVec2(otherExpression);
else if (str.at(1) == "-=")
globalVariableValues[str.at(0)] = AnyAsVec2(globalVariableValues[str.at(0)]) - AnyAsVec2(otherExpression);
else if (str.at(1) == "*=")
globalVariableValues[str.at(0)] = AnyAsVec2(globalVariableValues[str.at(0)]) * AnyAsFloat(otherExpression);
else if (str.at(1) == "/=")
globalVariableValues[str.at(0)] = AnyAsVec2(globalVariableValues[str.at(0)]) / AnyAsFloat(otherExpression);
else
LogWarning("unrecognized operator \'" + str[1] + "\'");
LogWarning("unrecognized operator \'" + str.at(1) + "\'");
}
return 0;
}
LogWarning("uninitialized variable or typo in \'" + str[0] + "\'");
LogWarning("uninitialized variable or typo in \'" + str.at(0) + "\'");
return 1;
}
boost::any ProcessLine(const vector<vector<string>>& words, int lineNum, unordered_map<string, boost::any>& variableValues)
{
if (words[lineNum][0][0] == '/' && words[lineNum][0][1] == '/')
if (words.at(lineNum).at(0)[0] == '/' && words.at(lineNum).at(0)[1] == '/')
return nullType;
// If print statement (deprecated, now use SLB.System.Print() function)
else if (words[lineNum][0] == "print")
else if (words.at(lineNum).at(0) == "print")
{
cout << StringRaw(AnyAsString(EvalExpression(unWrapVec(vector<string>(words[lineNum].begin() + 1, words[lineNum].end())), variableValues))) << endl;
cout << StringRaw(AnyAsString(EvalExpression(unWrapVec(vector<string>(words.at(lineNum).begin() + 1, words.at(lineNum).end())), variableValues))) << endl;
return nullType;
}
// Check if function return
else if (words[lineNum][0] == "return")
return EvalExpression(unWrapVec(vector<string>(words[lineNum].begin() + 1, words[lineNum].end())), variableValues);
else if (words.at(lineNum).at(0) == "return")
return EvalExpression(unWrapVec(vector<string>(words.at(lineNum).begin() + 1, words.at(lineNum).end())), variableValues);
// Check if it is SLB Builtin function
else if (words[lineNum][0][0] == 'S' && words[lineNum][0][1] == 'L' && words[lineNum][0][2] == 'B' && words[lineNum][0][3] == '.')
return EvalExpression(unWrapVec(words[lineNum]), variableValues);
else if (words.at(lineNum).at(0)[0] == 'S' && words.at(lineNum).at(0)[1] == 'L' && words.at(lineNum).at(0)[2] == 'B' && words.at(lineNum).at(0)[3] == '.')
return EvalExpression(unWrapVec(words.at(lineNum)), variableValues);
// Check if it is function
else if (IsFunction(trim(split(words[lineNum][0], '(')[0])))
else if (IsFunction(trim(split(words.at(lineNum).at(0), '(')[0])))
{
if (count(words[lineNum][0], '(') > 0 && count(words[lineNum][0], ')') > 0)
ExecuteFunction(trim(split(words[lineNum][0], '(')[0]), vector<boost::any>());
if (count(words.at(lineNum).at(0), '(') > 0 && count(words.at(lineNum).at(0), ')') > 0)
ExecuteFunction(trim(split(words.at(lineNum).at(0), '(')[0]), vector<boost::any>());
else
ExecuteFunction(trim(split(words[lineNum][0], '(')[0]), VarValues(split(RMParenthesis("(" + split(unWrapVec(rangeInVec(words[lineNum], 0, (int)words[lineNum].size() - 1)), '(')[1]), ','), variableValues));
ExecuteFunction(trim(split(words.at(lineNum).at(0), '(')[0]), VarValues(split(RMParenthesis("(" + split(unWrapVec(rangeInVec(words.at(lineNum), 0, (int)words.at(lineNum).size() - 1)), '(')[1]), ','), variableValues));
return nullType;
}
// Check if global variable declaration
else if (trim(words[lineNum][0]) == "global")
else if (trim(words.at(lineNum).at(0)) == "global")
{
globalVariableValues[words[lineNum][2]] = EvalExpression(unWrapVec(slice(words[lineNum], 4, -1)), variableValues);
globalVariableValues[words.at(lineNum).at(2)] = EvalExpression(unWrapVec(slice(words.at(lineNum), 4, -1)), variableValues);
return nullType;
}
// Iterate through all types to see if line inits or
// re-inits a variable then store it with it's value
else if (countInVector(types, trim(words[lineNum][0])) > 0)
else if (countInVector(types, trim(words.at(lineNum).at(0))) > 0)
{
variableValues[words[lineNum][1]] = EvalExpression(unWrapVec(slice(words[lineNum], 3, -1)), variableValues);
variableValues[words.at(lineNum).at(1)] = EvalExpression(unWrapVec(slice(words.at(lineNum), 3, -1)), variableValues);
return nullType;
}
// Check existing variables: If matches, then it means
// the variables value is getting changed with an operator
else if (count(words[lineNum][0], '.') == 0 && (IsVar(words[lineNum][0], variableValues) || IsVar(words[lineNum][0], globalVariableValues)))
else if (count(words.at(lineNum).at(0), '.') == 0 && (IsVar(words.at(lineNum).at(0), variableValues) || IsVar(words.at(lineNum).at(0), globalVariableValues)))
{
// Evaluates what the operator (ex. '=', '+=') does to the value on the left by the value on the right
varOperation(vector<string>(words[lineNum].begin(), words[lineNum].end()), variableValues);
varOperation(vector<string>(words.at(lineNum).begin(), words.at(lineNum).end()), variableValues);
return nullType;
}
// Check existing variables: To see if class sub component matches
else if (count(words[lineNum][0], '.') > 0 && IsVar(split(words[lineNum][0], '.')[0], variableValues) || IsVar(split(words[lineNum][0], '.')[0], globalVariableValues))
else if (count(words.at(lineNum).at(0), '.') > 0 && IsVar(split(words.at(lineNum).at(0), '.')[0], variableValues) || IsVar(split(words.at(lineNum).at(0), '.')[0], globalVariableValues))
{
if (IsVar(split(words[lineNum][0], '.')[0], variableValues))
variableValues[split(words[lineNum][0], '.')[0]] = EditClassSubComponent(variableValues[split(words[lineNum][0], '.')[0]], words[lineNum][1], EvalExpression(unWrapVec(vector<string>(words[lineNum].begin() + 2, words[lineNum].end())), variableValues), split(words[lineNum][0], '.')[1]);
else if (IsVar(split(words[lineNum][0], '.')[0], globalVariableValues))
globalVariableValues[split(words[lineNum][0], '.')[0]] = EditClassSubComponent(globalVariableValues[split(words[lineNum][0], '.')[0]], words[lineNum][1], EvalExpression(unWrapVec(vector<string>(words[lineNum].begin() + 2, words[lineNum].end())), variableValues), split(words[lineNum][0], '.')[1]);
if (IsVar(split(words.at(lineNum).at(0), '.')[0], variableValues))
variableValues[split(words.at(lineNum).at(0), '.')[0]] = EditClassSubComponent(variableValues[split(words.at(lineNum).at(0), '.')[0]], words.at(lineNum).at(1), EvalExpression(unWrapVec(vector<string>(words.at(lineNum).begin() + 2, words.at(lineNum).end())), variableValues), split(words.at(lineNum).at(0), '.')[1]);
else if (IsVar(split(words.at(lineNum).at(0), '.')[0], globalVariableValues))
globalVariableValues[split(words.at(lineNum).at(0), '.')[0]] = EditClassSubComponent(globalVariableValues[split(words.at(lineNum).at(0), '.')[0]], words.at(lineNum).at(1), EvalExpression(unWrapVec(vector<string>(words.at(lineNum).begin() + 2, words.at(lineNum).end())), variableValues), split(words.at(lineNum).at(0), '.')[1]);
return nullType;
}
// Gathers while loop contents
else if (words[lineNum][0] == "while")
else if (words.at(lineNum).at(0) == "while")
{
vector<vector<string>> whileContents;
vector<string> whileParameters;
for (int w = 1; w < (int)words[lineNum].size(); w++)
whileParameters.push_back(words[lineNum][w]);
for (int w = 1; w < (int)words.at(lineNum).size(); w++)
whileParameters.push_back(words.at(lineNum)[w]);
int numOfBrackets = 1;
for (int p = lineNum + 2; p < (int)words.size(); p++)
{
numOfBrackets += countInVector(words[p], "{") - countInVector(words[p], "}");
numOfBrackets += countInVector(words.at(p), "{") - countInVector(words.at(p), "}");
if (numOfBrackets == 0)
break;
whileContents.push_back(words[p]);
whileContents.push_back(words.at(p));
}
whileContents = removeTabsWdArry(whileContents, 1);
while (BooleanLogic(whileParameters[0], whileParameters[1], whileParameters[2], variableValues))
while (BooleanLogic(whileParameters.at(0), whileParameters.at(1), whileParameters.at(2), variableValues))
{
//Iterate through all lines in while loop
for (int lineNum = 0; lineNum < (int)whileContents.size(); lineNum++)
@ -465,27 +465,27 @@ boost::any ProcessLine(const vector<vector<string>>& words, int lineNum, unorder
}
// Gathers if statement contents
else if (words[lineNum][0] == "if")
else if (words.at(lineNum).at(0) == "if")
{
vector<vector<string>> ifContents;
vector<string> ifParameters;
for (int w = 1; w < (int)words[lineNum].size(); w++)
ifParameters.push_back(words[lineNum][w]);
for (int w = 1; w < (int)words.at(lineNum).size(); w++)
ifParameters.push_back(words.at(lineNum).at(w));
int numOfBrackets = 1;
lineNum += 2;
while (lineNum < (int)words.size())
{
numOfBrackets += countInVector(words[lineNum], "{") - countInVector(words[lineNum], "}");
numOfBrackets += countInVector(words.at(lineNum), "{") - countInVector(words.at(lineNum), "}");
if (numOfBrackets == 0)
break;
ifContents.push_back(words[lineNum]);
ifContents.push_back(words.at(lineNum));
lineNum++;
}
ifContents = removeTabsWdArry(ifContents, 1);
if (BooleanLogic(ifParameters[0], ifParameters[1], ifParameters[2], variableValues))
if (BooleanLogic(ifParameters.at(0), ifParameters.at(1), ifParameters.at(2), variableValues))
{
//Iterate through all lines in if statement
for (int l = 0; l < (int)ifContents.size(); l++)
@ -546,7 +546,7 @@ boost::any ExecuteFunction(const string& functionName, const vector<boost::any>&
unordered_map<string, boost::any> variableValues = {};
std::vector<std::string> funcArgs = words[0]; // This causes problem in linux
std::vector<std::string> funcArgs = words.at(0);
for (int i = 0; i < (int)inputVarVals.size(); i++)
{
@ -570,7 +570,7 @@ boost::any ExecuteFunction(const string& functionName, const vector<boost::any>&
}
catch (const std::exception&)
{
LogCriticalError("\'" + unWrapVec(words[lineNum]) + "\'\n In function: " + functionName + "\n Line: " + to_string(lineNum));
LogCriticalError("\'" + unWrapVec(words.at(lineNum)) + "\'\n In function: " + functionName + "\n Line: " + to_string(lineNum));
}
}
return nullType;
@ -586,7 +586,7 @@ int parseSlang(string script)
vector<string> lines = split(script, '\n');
vector<vector<string>> words;
for (int i = 0; i < (int)lines.size(); i++)
words.push_back(split(lines[i], ' '));
words.push_back(split(lines.at(i), ' '));
#if DEVELOPER_MESSAGES
InterpreterLog("Gather variables & functions...");
@ -596,20 +596,20 @@ int parseSlang(string script)
for (int lineNum = 0; lineNum < (int)words.size(); lineNum++)
{
//Checks if it is function
if (words[lineNum][0] == "func")
if (words.at(lineNum).at(0) == "func")
{
vector<vector<string>> functionContents;
string functName = split(words[lineNum][1], '(')[0];
string functName = split(words.at(lineNum).at(1), '(')[0];
#if DEVELOPER_MESSAGES == true
InterpreterLog("Load script function " + functName + "...");
#endif
string args = "";
if (indexInStr(unWrapVec(words[lineNum]), ')') - indexInStr(unWrapVec(words[lineNum]), '(') > 1)
for (int w = 1; w < (int)words[lineNum].size(); w++) // Get all words from the instantiation line: these are the args
if (indexInStr(unWrapVec(words.at(lineNum)), ')') - indexInStr(unWrapVec(words.at(lineNum)), '(') > 1)
for (int w = 1; w < (int)words.at(lineNum).size(); w++) // Get all words from the instantiation line: these are the args
{
args += replace(replace(words[lineNum][w], "(", " "), ")", "");
args += replace(replace(words.at(lineNum).at(w), "(", " "), ")", "");
}
args = trim(replace(args, functName + " ", ""));
@ -618,42 +618,41 @@ int parseSlang(string script)
int numOfBrackets = 1;
for (int p = lineNum + 2; p < (int)words.size(); p++)
{
numOfBrackets += countInVector(words[p], "{") - countInVector(words[p], "}");
numOfBrackets += countInVector(words.at(p), "{") - countInVector(words.at(p), "}");
if (numOfBrackets == 0)
break;
functionContents.push_back(removeTabs(words[p], 1));
functionContents.push_back(removeTabs(words.at(p), 1));
}
functionValues[functName] = functionContents;
//cout << functName << " is \n" << Vec2Str(functionContents) << endl << endl;
}
else
{
if (words[lineNum][0] == "string"){
globalVariableValues[words[lineNum][1]] = StringRaw(words[lineNum][3]);
if (words.at(lineNum).at(0) == "string"){
globalVariableValues[words.at(lineNum).at(1)] = StringRaw(words.at(lineNum).at(3));
#if DEVELOPER_MESSAGES == true
InterpreterLog("Load script variable " + words[lineNum][1] + "...");
InterpreterLog("Load script variable " + words.at(lineNum).at(1) + "...");
#endif
}
else if (words[lineNum][0] == "int"){
globalVariableValues[words[lineNum][1]] = stoi(words[lineNum][3]);
else if (words.at(lineNum).at(0) == "int"){
globalVariableValues[words.at(lineNum).at(1)] = stoi(words.at(lineNum).at(3));
#if DEVELOPER_MESSAGES == true
InterpreterLog("Load script variable " + words[lineNum][1] + "...");
InterpreterLog("Load script variable " + words.at(lineNum).at(1) + "...");
#endif
}
else if (words[lineNum][0] == "float"){
globalVariableValues[words[lineNum][1]] = stof(words[lineNum][3]);
else if (words.at(lineNum).at(0) == "float"){
globalVariableValues[words.at(lineNum).at(1)] = stof(words.at(lineNum).at(3));
#if DEVELOPER_MESSAGES == true
InterpreterLog("Load script variable " + words[lineNum][1] + "...");
InterpreterLog("Load script variable " + words.at(lineNum).at(1) + "...");
#endif
}
else if (words[lineNum][0] == "bool"){
globalVariableValues[words[lineNum][1]] = stob(words[lineNum][3]);
else if (words.at(lineNum).at(0) == "bool"){
globalVariableValues[words.at(lineNum).at(1)] = stob(words.at(lineNum).at(3));
#if DEVELOPER_MESSAGES == true
InterpreterLog("Load script variable " + words[lineNum][1] + "...");
InterpreterLog("Load script variable " + words.at(lineNum).at(1) + "...");
#endif
}
//else
// LogWarning("unrecognized type \'" + words[lineNum][0] + "\' on line: " + to_string(lineNum));
/*else
LogWarning("unrecognized type \'" + words.at(lineNum).at(0) + "\' on line: " + to_string(lineNum));*/
}
}
@ -724,7 +723,8 @@ int main(int argc, char* argv[])
else
{
LogWarning("No script provided! Please drag and drop .SLG file over interpreter executable file, or provide it's path as a command-line argument.");
//system("pause");
cout << "Press Enter to Continue";
cin.ignore();
exit(1);
}

View File

@ -47,12 +47,16 @@ float lerp(float a, float b, float f)
int LogWarning(const string& warningText)
{
cerr << "\x1B[33mWARNING: " << warningText << "\033[0m\t\t" << endl;
cout << "\x1B[33mWARNING: " << warningText << "\033[0m\t\t" << endl;
return 1;
}
int InterpreterLog(const string& logText)
{
int Hour = 0;
int Min = 0;
int Sec = 0;
time_t timer = time(0);
tm bt{};
@ -60,25 +64,24 @@ int InterpreterLog(const string& logText)
//localtime_r(&timer, &bt);
#elif defined(_MSC_VER)
localtime_s(&bt, &timer);
Hour = bt.tm_hour;
Min = bt.tm_min;
Sec = bt.tm_sec;
#else
static mutex mtx;
std::lock_guard<std::mutex> lock(mtx);
bt = *localtime(&timer);
#endif
//int Hour = bt.tm_hour;
//int Min = bt.tm_min;
//int Sec = bt.tm_sec;
int Hour = 0;
int Min = 0;
int Sec = 0;
cout << "\x1B[34m[" + to_string(Hour) + ":" + to_string(Min) + ":" + to_string(Sec) + "] \x1B[33mSlang: \x1B[32m" << logText << "\033[0m\t\t" << endl;
return 1;
}
int LogCriticalError(const string& errorText)
{
int Hour = 0;
int Min = 0;
int Sec = 0;
time_t timer = time(0);
tm bt{};
@ -86,19 +89,15 @@ int LogCriticalError(const string& errorText)
//localtime_r(&timer, &bt);
#elif defined(_MSC_VER)
localtime_s(&bt, &timer);
Hour = bt.tm_hour;
Min = bt.tm_min;
Sec = bt.tm_sec;
#else
static mutex mtx;
std::lock_guard<std::mutex> lock(mtx);
bt = *localtime(&timer);
#endif
//int Hour = bt.tm_hour;
//int Min = bt.tm_min;
//int Sec = bt.tm_sec;
int Hour = 0;
int Min = 0;
int Sec = 0;
cerr << "\x1B[34m[" + to_string(Hour) + ":" + to_string(Min) + ":" + to_string(Sec) + "] \x1B[33mSlang: \x1B[31mERROR: " << errorText << "\033[0m\t\t" << endl;
exit(EXIT_FAILURE);
return 2;
@ -179,7 +178,7 @@ int GetBuiltins(std::string s)
vector<vector<string>> words;
for (int i = 0; i < (int)lines.size(); i++)
{
words.push_back(split(lines[i], ' '));
words.push_back(split(lines.at(i), ' '));
}
// Go through entire script and iterate through all types to see if line is a
@ -187,20 +186,20 @@ int GetBuiltins(std::string s)
for (int lineNum = 0; lineNum < (int)words.size(); lineNum++)
{
//Checks if it is function
if (words[lineNum][0] == "func")
if (words.at(lineNum).at(0) == "func")
{
vector<vector<string>> functionContents;
string functName = split(words[lineNum][1], '(')[0];
string functName = split(words.at(lineNum).at(1), '(')[0];
#if DEVELOPER_MESSAGES == true
InterpreterLog("Load builtin function " + functName + "...");
#endif
string args = "";
for (int w = 1; w < (int)words[lineNum].size(); w++) // Get all words from the instantiation line: these are the args
for (int w = 1; w < (int)words.at(lineNum).size(); w++) // Get all words from the instantiation line: these are the args
{
args += replace(replace(words[lineNum][w], "(", " "), ")", "");
args += replace(replace(words.at(lineNum).at(w), "(", " "), ")", "");
}
args = replace(args, functName + " ", "");
@ -209,42 +208,42 @@ int GetBuiltins(std::string s)
int numOfBrackets = 1;
for (int p = lineNum + 2; p < (int)words.size(); p++)
{
numOfBrackets += countInVector(words[p], "{") - countInVector(words[p], "}");
numOfBrackets += countInVector(words.at(p), "{") - countInVector(words.at(p), "}");
if (numOfBrackets == 0)
break;
functionContents.push_back(removeTabs(words[p], 1));
functionContents.push_back(removeTabs(words.at(p), 1));
}
builtinFunctionValues[functName] = functionContents;
//cout << functName << " is \n" << Vec2Str(functionContents) << endl << endl;
}
else
{
if (words[lineNum][0] == "string")
if (words.at(lineNum).at(0) == "string")
{
builtinVarVals[words[lineNum][1]] = StringRaw(words[lineNum][3]);
builtinVarVals[words.at(lineNum).at(1)] = StringRaw(words.at(lineNum).at(3));
#if DEVELOPER_MESSAGES == true
InterpreterLog("Load builtin variable " + words[lineNum][1] + "...");
InterpreterLog("Load builtin variable " + words.at(lineNum).at(1) + "...");
#endif
}
else if (words[lineNum][0] == "int")
else if (words.at(lineNum).at(0) == "int")
{
builtinVarVals[words[lineNum][1]] = stoi(words[lineNum][3]);
builtinVarVals[words.at(lineNum).at(1)] = stoi(words.at(lineNum).at(3));
#if DEVELOPER_MESSAGES == true
InterpreterLog("Load builtin variable " + words[lineNum][1] + "...");
InterpreterLog("Load builtin variable " + words.at(lineNum).at(1) + "...");
#endif
}
else if (words[lineNum][0] == "float")
else if (words.at(lineNum).at(0) == "float")
{
builtinVarVals[words[lineNum][1]] = stof(words[lineNum][3]);
builtinVarVals[words.at(lineNum).at(1)] = stof(words.at(lineNum).at(3));
#if DEVELOPER_MESSAGES == true
InterpreterLog("Load builtin variable " + words[lineNum][1] + "...");
InterpreterLog("Load builtin variable " + words.at(lineNum).at(1) + "...");
#endif
}
else if (words[lineNum][0] == "bool")
else if (words.at(lineNum).at(0) == "bool")
{
builtinVarVals[words[lineNum][1]] = stob(words[lineNum][3]);
builtinVarVals[words.at(lineNum).at(1)] = stob(words.at(lineNum).at(3));
#if DEVELOPER_MESSAGES == true
InterpreterLog("Load builtin variable " + words[lineNum][1] + "...");
InterpreterLog("Load builtin variable " + words.at(lineNum).at(1) + "...");
#endif
}
//else
@ -259,55 +258,55 @@ int GetBuiltins(std::string s)
boost::any SLBFunction(const string& name, const vector<boost::any>& args)
{
if (name == "SLB.Math.Sin")
return sin(AnyAsFloat(args[0]));
return sin(AnyAsFloat(args.at(0)));
else if (name == "SLB.Math.Cos")
return cos(AnyAsFloat(args[0]));
return cos(AnyAsFloat(args.at(0)));
else if (name == "SLB.Math.Tan")
return tan(AnyAsFloat(args[0]));
return tan(AnyAsFloat(args.at(0)));
else if (name == "SLB.Math.Round")
return AnyAsInt(args[0]);
return AnyAsInt(args.at(0));
else if (name == "SLB.Math.Lerp")
return lerp(AnyAsFloat(args[0]), AnyAsFloat(args[1]), AnyAsFloat(args[2]));
return lerp(AnyAsFloat(args.at(0)), AnyAsFloat(args.at(1)), AnyAsFloat(args.at(2)));
else if (name == "SLB.Math.Abs")
return abs(AnyAsFloat(args[0]));
return abs(AnyAsFloat(args.at(0)));
else if (name == "SLB.Graphics.Init")
{
#if DEVELOPER_MESSAGES == true
InterpreterLog("Init graphics");
#endif
initGraphics(StringRaw(AnyAsString(args[0])), AnyAsInt(args[1]), AnyAsInt(args[2]));
initGraphics(StringRaw(AnyAsString(args.at(0))), AnyAsInt(args.at(1)), AnyAsInt(args.at(2)));
}
else if (name == "SLB.Graphics.Sprite")
{
Sprite s(StringRaw(AnyAsString(args[0])), any_cast<Vec2>(args[1]), any_cast<Vec2>(args[2]), AnyAsFloat(args[3]));
Sprite s(StringRaw(AnyAsString(args.at(0))), any_cast<Vec2>(args.at(1)), any_cast<Vec2>(args.at(2)), AnyAsFloat(args.at(3)));
return s;
}
else if (name == "SLB.Graphics.Draw")
any_cast<Sprite>(args[0]).Draw();
any_cast<Sprite>(args.at(0)).Draw();
else if (name == "SLB.Graphics.Load")
any_cast<Sprite>(args[0]).Load();
any_cast<Sprite>(args.at(0)).Load();
else if (name == "SLB.Graphics.Text")
{
Text t(StringRaw(AnyAsString(args[0])), StringRaw(AnyAsString(args[1])), any_cast<Vec2>(args[2]), AnyAsFloat(args[3]), AnyAsFloat(args[4]), (Uint8)AnyAsFloat(args[5]), (Uint8)AnyAsFloat(args[6]), (Uint8)AnyAsFloat(args[7]));
Text t(StringRaw(AnyAsString(args.at(0))), StringRaw(AnyAsString(args.at(1))), any_cast<Vec2>(args.at(2)), AnyAsFloat(args.at(3)), AnyAsFloat(args.at(4)), (Uint8)AnyAsFloat(args.at(5)), (Uint8)AnyAsFloat(args.at(6)), (Uint8)AnyAsFloat(args.at(7)));
return t;
}
else if (name == "SLB.Graphics.DrawText")
any_cast<Text>(args[0]).Draw();
any_cast<Text>(args.at(0)).Draw();
else if (name == "SLB.Graphics.LoadText")
any_cast<Text>(args[0]).Load();
any_cast<Text>(args.at(0)).Load();
else if (name == "SLB.Physics.AxisAlignedCollision")
{
return AxisAlignedCollision(any_cast<Sprite>(args[0]), any_cast<Sprite>(args[1]));
return AxisAlignedCollision(any_cast<Sprite>(args.at(0)), any_cast<Sprite>(args.at(1)));
}
else if (name == "SLB.Input.GetKey")
return KEYS[StringRaw(any_cast<string>(args[0]))] == 1;
return KEYS[StringRaw(any_cast<string>(args.at(0)))] == 1;
else if (name == "SLB.System.Print")
cout << StringRaw(AnyAsString(args[0]));
cout << StringRaw(AnyAsString(args.at(0)));
else if (name == "SLB.System.PrintLine")
cout << StringRaw(AnyAsString(args[0])) << endl;
cout << StringRaw(AnyAsString(args.at(0))) << endl;
else if (name == "SLB.System.Vec2")
{
Vec2 v(AnyAsFloat(args[0]), AnyAsFloat(args[1]));
Vec2 v(AnyAsFloat(args.at(0)), AnyAsFloat(args.at(1)));
return v;
}
else

View File

@ -113,9 +113,11 @@ SDL_Renderer* gRenderer = NULL;
SDL_Surface* gScreenSurface = NULL;
bool running = true;
bool buttons[4] = {};
float dt = 0.0f;
float clamp(float v, float min, float max);
SDL_Surface* loadSurface(std::string path)
{
//The final optimized image
@ -529,14 +531,10 @@ public:
int Load()
{
cout << "Load" << endl;
SDL_Color color = { r, g, b };
SDL_Surface* surface = TTF_RenderText_Solid(font, content.c_str(), color);
//if(texture != NULL)
// SDL_DestroyTexture(texture);
cout << "Loaded" << endl;
texture = SDL_CreateTextureFromSurface(gRenderer, surface);
TTF_SizeText(font, content.c_str(), &rect.w, &rect.h);
@ -1014,7 +1012,7 @@ int updateLoop()
// Calculate frame time
auto stopTime = std::chrono::high_resolution_clock::now();
dt = std::chrono::duration<float, std::chrono::milliseconds::period>(stopTime - startTime).count() / 1000.0f;
dt = clamp(dt, 0, 1000);
}
return 0;
}