diff --git a/Slang/Main.cpp b/Slang/Main.cpp index 2976c50..ff86d20 100644 --- a/Slang/Main.cpp +++ b/Slang/Main.cpp @@ -286,14 +286,17 @@ int varOperation(const vector& str, unordered_map& v boost::any ProcessLine(const vector>& words, int lineNum, unordered_map& variableValues) { + if (words[lineNum].size() == 0) + return nullType; + if (words[lineNum][0][0] == '/' && words[lineNum][0][1] == '/') - return boost::any{}; + return nullType; // If print statement (deprecated, now use CPP.System.Print() function) else if (words[lineNum][0] == "print") { cout << AnyAsString(EvalExpression(unWrapVec(vector(words[lineNum].begin() + 1, words[lineNum].end())), variableValues)) << endl; - return boost::any{}; + return nullType; } // Check if function return @@ -308,7 +311,7 @@ boost::any ProcessLine(const vector>& words, int lineNum, unorder else if (IsFunction(trim(split(words[lineNum][0], '(')[0]))) { ExecuteFunction(trim(split(words[lineNum][0], '(')[0]), VarValues(split(RMParenthesis(replace(unWrapVec(words[lineNum]), trim(split(words[lineNum][0], '(')[0]), "")), ','), variableValues)); - return boost::any{}; + return nullType; } // Iterate through all types to see if line inits or @@ -316,7 +319,7 @@ boost::any ProcessLine(const vector>& words, int lineNum, unorder else if (countInVector(types, words[lineNum][0]) > 0) { variableValues[words[lineNum][1]] = EvalExpression(unWrapVec(vector(words[lineNum].begin() + 3, words[lineNum].end())), variableValues); - return boost::any{}; + return nullType; } // Check existing variables: If matches, then it means @@ -325,7 +328,7 @@ boost::any ProcessLine(const vector>& words, int lineNum, unorder { // Evaluates what the operator (ex. '=', '+=') does to the value on the left by the value on the right varOperation(vector(words[lineNum].begin(), words[lineNum].end()), variableValues); - return boost::any{}; + return nullType; } // Gathers while loop contents @@ -361,11 +364,11 @@ boost::any ProcessLine(const vector>& words, int lineNum, unorder for (int lineNum = 0; lineNum < (int)whileContents.size(); lineNum++) { boost::any returnVal = ProcessLine(innerWords, lineNum, variableValues); - if (AnyAsString(returnVal) != "") + if (!returnVal.empty() && returnVal.empty() == false) return returnVal; } } - return boost::any{}; + return nullType; } // Gathers if statement contents @@ -403,7 +406,7 @@ boost::any ProcessLine(const vector>& words, int lineNum, unorder for (int l = 0; l < (int)ifContents.size(); l++) { boost::any returnVal = ProcessLine(innerWords, l, variableValues); - if (!returnVal.empty()) + if (!returnVal.empty() && returnVal.empty() == false) return returnVal; } } @@ -438,9 +441,9 @@ boost::any ProcessLine(const vector>& words, int lineNum, unorder { ProcessLine(innerWords, lineNum, variableValues); } - return boost::any{}; + return nullType; } - return boost::any{}; + return nullType; } //// Gathers else statement contents //if (words[lineNum][0] == "else") @@ -448,7 +451,7 @@ boost::any ProcessLine(const vector>& words, int lineNum, unorder // //} - return boost::any{}; + return nullType; } boost::any ExecuteFunction(const string& functionName, const vector& inputVarVals) @@ -457,11 +460,9 @@ boost::any ExecuteFunction(const string& functionName, const vector& vector> words = functionValues[functionName]; unordered_map variableValues; - vector args = split(functionValues[functionName][0][0], ','); + vector args = split(words[0][0], ','); for (int i = 0; i < (int)inputVarVals.size(); i++) - { - variableValues[trim(args[i])] = EvalExpression(AnyAsString(inputVarVals[i]), variableValues); - } + variableValues[args[i]] = inputVarVals[i]; //Iterate through all lines in function for (int lineNum = 0; lineNum < (int)words.size(); lineNum++) @@ -475,10 +476,10 @@ boost::any ExecuteFunction(const string& functionName, const vector& { LogCriticalError("\'" + unWrapVec(words[lineNum]) + "\'\nIn function: " + functionName + "\nLine: " + to_string(lineNum)); } - if (!returnVal.empty()) + if (!returnVal.empty() && returnVal.empty() == false) return returnVal; } - return boost::any{}; + return nullType; } int parseSlang(string script) @@ -537,8 +538,8 @@ int parseSlang(string script) globalVariableValues[words[lineNum][1]] = stof(words[lineNum][3]); else if (words[lineNum][0] == "bool") globalVariableValues[words[lineNum][1]] = stob(words[lineNum][3]); - else - LogWarning("unrecognized type \'" + words[lineNum][0] + "\' on line: " + to_string(lineNum)); + //else + // LogWarning("unrecognized type \'" + words[lineNum][0] + "\' on line: " + to_string(lineNum)); } } diff --git a/Slang/anyops.h b/Slang/anyops.h index b89dadb..b46cf31 100644 --- a/Slang/anyops.h +++ b/Slang/anyops.h @@ -75,7 +75,7 @@ string AnyAsString(const boost::any& val) catch (boost::bad_any_cast) // Does not convert, return { LogWarning("invalid conversion to type \'string\'"); - return ""; + return "ERR"; } } } @@ -196,4 +196,21 @@ int any_type(const boost::any& val) } } +// Gets if any is NullType +bool any_null(const boost::any& val) +{ + /*if (val.type() == typeid(NullType)) + return true;*/ + return false; + //try // Try converting to Null + //{ + // NullType n = any_cast(val); + // return true; + //} + //catch (boost::bad_any_cast) + //{ + // return false; + //} +} + #endif diff --git a/Slang/builtin.h b/Slang/builtin.h index d6a9794..b551da3 100644 --- a/Slang/builtin.h +++ b/Slang/builtin.h @@ -23,6 +23,12 @@ unordered_map builtinVarVals; Parser mainWindow; +class NullType { +public: + string type = "NULL"; +}; + +boost::any nullType; int LogWarning(const string& warningText) { @@ -96,8 +102,8 @@ int GetBuiltins(const string& s) builtinVarVals[words[lineNum][1]] = stof(words[lineNum][3]); else if (words[lineNum][0] == "bool") builtinVarVals[words[lineNum][1]] = stob(words[lineNum][3]); - else - LogWarning("unrecognized type \'" + words[lineNum][0] + "\' on line: " + to_string(lineNum)); + //else + // LogWarning("unrecognized type \'" + words[lineNum][0] + "\' on line: " + to_string(lineNum)); } } diff --git a/Slang/strops.cpp b/Slang/strops.cpp index 60c0d39..f85ed83 100644 --- a/Slang/strops.cpp +++ b/Slang/strops.cpp @@ -19,14 +19,10 @@ bool isNumber(const string& str) return true; } -bool stob(string str) +bool stob(const string& str) { - //transform(str.begin(), str.end(), str.begin(), ::tolower); - //istringstream is(str); - //bool b; - //is >> boolalpha >> b; - //return b; - return false; + bool b = trim(str) == "true"; + return b; } string StringRaw(const string& s) diff --git a/Slang/strops.h b/Slang/strops.h index 537e853..de67f3c 100644 --- a/Slang/strops.h +++ b/Slang/strops.h @@ -7,7 +7,7 @@ using namespace std; bool isNumber(const string& str); -bool stob(string str); +bool stob(const string& str); string StringRaw(const string& s);