mirror of
https://github.com/sam-astro/Z-Sharp.git
synced 2025-12-13 09:02:10 +00:00
(slightly) working version. Includes to other files needs fixing, then it should work
This commit is contained in:
parent
b99cb9ba82
commit
41b90c3b4b
11
Slang/CMakeLists.txt
Normal file
11
Slang/CMakeLists.txt
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.10)
|
||||||
|
|
||||||
|
# set the project name
|
||||||
|
project(Slang)
|
||||||
|
|
||||||
|
# add the executable
|
||||||
|
#add_executable(Main.cpp)
|
||||||
|
|
||||||
|
target_include_directories(Slang PUBLIC
|
||||||
|
"${PROJECT_BINARY_DIR}"
|
||||||
|
)
|
||||||
@ -7,7 +7,7 @@
|
|||||||
#include <limits>
|
#include <limits>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <any>
|
#include <boost/any.hpp>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
#include "eval.h"
|
#include "eval.h"
|
||||||
@ -19,10 +19,10 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace boost;
|
using namespace boost;
|
||||||
|
|
||||||
unordered_map<string, any> globalVariableValues;
|
unordered_map<string, boost::any> globalVariableValues;
|
||||||
unordered_map<string, vector<vector<string>>> functionValues;
|
unordered_map<string, vector<vector<string>>> functionValues;
|
||||||
|
|
||||||
any GetVariableValue(const string& varName, const unordered_map<string, any>& variableVals)
|
boost::any GetVariableValue(const string& varName, const unordered_map<string, boost::any>& variableVals)
|
||||||
{
|
{
|
||||||
auto iA = variableVals.find(varName);
|
auto iA = variableVals.find(varName);
|
||||||
if (iA != variableVals.end())
|
if (iA != variableVals.end())
|
||||||
@ -43,7 +43,7 @@ any GetVariableValue(const string& varName, const unordered_map<string, any>& va
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsVar(const string& varName, const unordered_map<string, any>& variableVals)
|
bool IsVar(const string& varName, const unordered_map<string, boost::any>& variableVals)
|
||||||
{
|
{
|
||||||
if (variableVals.find(varName) != variableVals.end())
|
if (variableVals.find(varName) != variableVals.end())
|
||||||
return true;
|
return true;
|
||||||
@ -51,9 +51,9 @@ bool IsVar(const string& varName, const unordered_map<string, any>& variableVals
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<any> VarValues(const vector<string>& varNames, const unordered_map<string, any>& variableVals)
|
vector<boost::any> VarValues(const vector<string>& varNames, const unordered_map<string, boost::any>& variableVals)
|
||||||
{
|
{
|
||||||
vector<any> realValues;
|
vector<boost::any> realValues;
|
||||||
|
|
||||||
for (int varIndex = 0; varIndex < varNames.size(); varIndex++)
|
for (int varIndex = 0; varIndex < varNames.size(); varIndex++)
|
||||||
{
|
{
|
||||||
@ -85,7 +85,7 @@ bool IsFunction(const string& funcName)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
any EvalExpression(const string& ex, const unordered_map<string, any>& variableVals)
|
boost::any EvalExpression(const string& ex, const unordered_map<string, boost::any>& variableVals)
|
||||||
{
|
{
|
||||||
string expression = trim(ex);
|
string expression = trim(ex);
|
||||||
bool inQuotes = false;
|
bool inQuotes = false;
|
||||||
@ -221,10 +221,10 @@ any EvalExpression(const string& ex, const unordered_map<string, any>& variableV
|
|||||||
return evaluate(newExpression);
|
return evaluate(newExpression);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BooleanLogic(const string& valA, const string& determinant, const string& valB, const unordered_map<string, any>& variableVals)
|
bool BooleanLogic(const string& valA, const string& determinant, const string& valB, const unordered_map<string, boost::any>& variableVals)
|
||||||
{
|
{
|
||||||
any valARealValue = EvalExpression(valA, variableVals);
|
boost::any valARealValue = EvalExpression(valA, variableVals);
|
||||||
any valBRealValue = EvalExpression(valB, variableVals);
|
boost::any valBRealValue = EvalExpression(valB, variableVals);
|
||||||
|
|
||||||
if (determinant == "==")
|
if (determinant == "==")
|
||||||
return AnyAsString(valARealValue) == AnyAsString(valBRealValue);
|
return AnyAsString(valARealValue) == AnyAsString(valBRealValue);
|
||||||
@ -244,7 +244,7 @@ bool BooleanLogic(const string& valA, const string& determinant, const string& v
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int varOperation(const vector<string>& str, unordered_map<string, any>& variableValues)
|
int varOperation(const vector<string>& str, unordered_map<string, boost::any>& variableValues)
|
||||||
{
|
{
|
||||||
if (IsVar(str[0], variableValues))
|
if (IsVar(str[0], variableValues))
|
||||||
{
|
{
|
||||||
@ -284,16 +284,16 @@ int varOperation(const vector<string>& str, unordered_map<string, any>& variable
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
any ProcessLine(const vector<vector<string>>& words, int lineNum, unordered_map<string, any>& variableValues)
|
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[lineNum][0][0] == '/' && words[lineNum][0][1] == '/')
|
||||||
return any{};
|
return boost::any{};
|
||||||
|
|
||||||
// If print statement (deprecated, now use CPP.System.Print() function)
|
// If print statement (deprecated, now use CPP.System.Print() function)
|
||||||
else if (words[lineNum][0] == "print")
|
else if (words[lineNum][0] == "print")
|
||||||
{
|
{
|
||||||
cout << AnyAsString(EvalExpression(unWrapVec(vector<string>(words[lineNum].begin() + 1, words[lineNum].end())), variableValues)) << endl;
|
cout << AnyAsString(EvalExpression(unWrapVec(vector<string>(words[lineNum].begin() + 1, words[lineNum].end())), variableValues)) << endl;
|
||||||
return any{};
|
return boost::any{};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if function return
|
// Check if function return
|
||||||
@ -308,7 +308,7 @@ any ProcessLine(const vector<vector<string>>& words, int lineNum, unordered_map<
|
|||||||
else if (IsFunction(trim(split(words[lineNum][0], '(')[0])))
|
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));
|
ExecuteFunction(trim(split(words[lineNum][0], '(')[0]), VarValues(split(RMParenthesis(replace(unWrapVec(words[lineNum]), trim(split(words[lineNum][0], '(')[0]), "")), ','), variableValues));
|
||||||
return any{};
|
return boost::any{};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iterate through all types to see if line inits or
|
// Iterate through all types to see if line inits or
|
||||||
@ -316,7 +316,7 @@ any ProcessLine(const vector<vector<string>>& words, int lineNum, unordered_map<
|
|||||||
else if (countInVector(types, words[lineNum][0]) > 0)
|
else if (countInVector(types, words[lineNum][0]) > 0)
|
||||||
{
|
{
|
||||||
variableValues[words[lineNum][1]] = EvalExpression(unWrapVec(vector<string>(words[lineNum].begin() + 3, words[lineNum].end())), variableValues);
|
variableValues[words[lineNum][1]] = EvalExpression(unWrapVec(vector<string>(words[lineNum].begin() + 3, words[lineNum].end())), variableValues);
|
||||||
return any{};
|
return boost::any{};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check existing variables: If matches, then it means
|
// Check existing variables: If matches, then it means
|
||||||
@ -325,7 +325,7 @@ any ProcessLine(const vector<vector<string>>& words, int lineNum, unordered_map<
|
|||||||
{
|
{
|
||||||
// Evaluates what the operator (ex. '=', '+=') does to the value on the left by the value on the right
|
// 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[lineNum].begin(), words[lineNum].end()), variableValues);
|
||||||
return any{};
|
return boost::any{};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gathers while loop contents
|
// Gathers while loop contents
|
||||||
@ -360,12 +360,12 @@ any ProcessLine(const vector<vector<string>>& words, int lineNum, unordered_map<
|
|||||||
//Iterate through all lines in while loop
|
//Iterate through all lines in while loop
|
||||||
for (int lineNum = 0; lineNum < (int)whileContents.size(); lineNum++)
|
for (int lineNum = 0; lineNum < (int)whileContents.size(); lineNum++)
|
||||||
{
|
{
|
||||||
any returnVal = ProcessLine(innerWords, lineNum, variableValues);
|
boost::any returnVal = ProcessLine(innerWords, lineNum, variableValues);
|
||||||
if (AnyAsString(returnVal) != "")
|
if (AnyAsString(returnVal) != "")
|
||||||
return returnVal;
|
return returnVal;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return any{};
|
return boost::any{};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gathers if statement contents
|
// Gathers if statement contents
|
||||||
@ -402,7 +402,7 @@ any ProcessLine(const vector<vector<string>>& words, int lineNum, unordered_map<
|
|||||||
//Iterate through all lines in if statement
|
//Iterate through all lines in if statement
|
||||||
for (int l = 0; l < (int)ifContents.size(); l++)
|
for (int l = 0; l < (int)ifContents.size(); l++)
|
||||||
{
|
{
|
||||||
any returnVal = ProcessLine(innerWords, l, variableValues);
|
boost::any returnVal = ProcessLine(innerWords, l, variableValues);
|
||||||
if (!returnVal.empty())
|
if (!returnVal.empty())
|
||||||
return returnVal;
|
return returnVal;
|
||||||
}
|
}
|
||||||
@ -438,9 +438,9 @@ any ProcessLine(const vector<vector<string>>& words, int lineNum, unordered_map<
|
|||||||
{
|
{
|
||||||
ProcessLine(innerWords, lineNum, variableValues);
|
ProcessLine(innerWords, lineNum, variableValues);
|
||||||
}
|
}
|
||||||
return any{};
|
return boost::any{};
|
||||||
}
|
}
|
||||||
return any{};
|
return boost::any{};
|
||||||
}
|
}
|
||||||
//// Gathers else statement contents
|
//// Gathers else statement contents
|
||||||
//if (words[lineNum][0] == "else")
|
//if (words[lineNum][0] == "else")
|
||||||
@ -448,15 +448,15 @@ any ProcessLine(const vector<vector<string>>& words, int lineNum, unordered_map<
|
|||||||
//
|
//
|
||||||
//}
|
//}
|
||||||
|
|
||||||
return any{};
|
return boost::any{};
|
||||||
}
|
}
|
||||||
|
|
||||||
any ExecuteFunction(const string functionName, const vector<any> inputVarVals)
|
boost::any ExecuteFunction(const string& functionName, const vector<boost::any>& inputVarVals)
|
||||||
{
|
{
|
||||||
// Get contents of function
|
// Get contents of function
|
||||||
vector<vector<string>> words = functionValues[functionName];
|
vector<vector<string>> words = functionValues[functionName];
|
||||||
|
|
||||||
unordered_map<string, any> variableValues;
|
unordered_map<string, boost::any> variableValues;
|
||||||
vector<string> args = split(functionValues[functionName][0][0], ',');
|
vector<string> args = split(functionValues[functionName][0][0], ',');
|
||||||
for (int i = 0; i < (int)inputVarVals.size(); i++)
|
for (int i = 0; i < (int)inputVarVals.size(); i++)
|
||||||
{
|
{
|
||||||
@ -466,7 +466,7 @@ any ExecuteFunction(const string functionName, const vector<any> inputVarVals)
|
|||||||
//Iterate through all lines in function
|
//Iterate through all lines in function
|
||||||
for (int lineNum = 0; lineNum < (int)words.size(); lineNum++)
|
for (int lineNum = 0; lineNum < (int)words.size(); lineNum++)
|
||||||
{
|
{
|
||||||
any returnVal = 0;
|
boost::any returnVal = 0;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
returnVal = ProcessLine(words, lineNum, variableValues);
|
returnVal = ProcessLine(words, lineNum, variableValues);
|
||||||
@ -478,7 +478,7 @@ any ExecuteFunction(const string functionName, const vector<any> inputVarVals)
|
|||||||
if (!returnVal.empty())
|
if (!returnVal.empty())
|
||||||
return returnVal;
|
return returnVal;
|
||||||
}
|
}
|
||||||
return any{};
|
return boost::any{};
|
||||||
}
|
}
|
||||||
|
|
||||||
int parseSlang(string script)
|
int parseSlang(string script)
|
||||||
@ -543,7 +543,7 @@ int parseSlang(string script)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Executes main, which is the starting function
|
// Executes main, which is the starting function
|
||||||
ExecuteFunction("Main", vector<any> {"hi", 0});
|
ExecuteFunction("Main", vector<boost::any> {"hi", 0});
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -65,9 +65,11 @@
|
|||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
<Import Project="boost_x64_release.props" />
|
||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
<Import Project="boost_x64_release.props" />
|
||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
<PropertyGroup Label="UserMacros" />
|
<PropertyGroup Label="UserMacros" />
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
@ -89,12 +91,12 @@
|
|||||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<ConformanceMode>true</ConformanceMode>
|
<ConformanceMode>true</ConformanceMode>
|
||||||
<DebugInformationFormat>OldStyle</DebugInformationFormat>
|
<DebugInformationFormat>OldStyle</DebugInformationFormat>
|
||||||
<AdditionalIncludeDirectories>D:\Code\boost</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>D:\Code\boost\libs;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
<AdditionalLibraryDirectories>D:\Code\boost</AdditionalLibraryDirectories>
|
<AdditionalLibraryDirectories>D:\Code\boost\stage\lib</AdditionalLibraryDirectories>
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
@ -158,6 +160,9 @@
|
|||||||
<None Include="builtin.slg" />
|
<None Include="builtin.slg" />
|
||||||
<None Include="script.slg" />
|
<None Include="script.slg" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Text Include="CMakeLists.txt" />
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
<ImportGroup Label="ExtensionTargets">
|
<ImportGroup Label="ExtensionTargets">
|
||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
|
|||||||
@ -49,4 +49,7 @@
|
|||||||
<None Include="script.slg" />
|
<None Include="script.slg" />
|
||||||
<None Include="builtin.slg" />
|
<None Include="builtin.slg" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Text Include="CMakeLists.txt" />
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
@ -3,37 +3,39 @@
|
|||||||
#define ANYOPS_H
|
#define ANYOPS_H
|
||||||
|
|
||||||
#include "builtin.h"
|
#include "builtin.h"
|
||||||
#include <any>
|
#include <boost/any.hpp>
|
||||||
|
|
||||||
using namespace boost;
|
using namespace boost;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
int LogWarning(const string& warningText);
|
||||||
|
|
||||||
// Will convert type 'any' val to a bool
|
// Will convert type 'any' val to a bool
|
||||||
bool AnyAsBool(const any& val)
|
bool AnyAsBool(const boost::any& val)
|
||||||
{
|
{
|
||||||
try // Try converting to bool
|
try // Try converting to bool
|
||||||
{
|
{
|
||||||
return any_cast<bool>(val);
|
return any_cast<bool>(val);
|
||||||
}
|
}
|
||||||
catch (boost::bad_any_cast &e)
|
catch (boost::bad_any_cast)
|
||||||
{
|
{
|
||||||
try // Try converting to string
|
try // Try converting to string
|
||||||
{
|
{
|
||||||
return any_cast<string>(val) == "true";
|
return any_cast<string>(val) == "true";
|
||||||
}
|
}
|
||||||
catch (boost::bad_any_cast &e)
|
catch (boost::bad_any_cast)
|
||||||
{
|
{
|
||||||
try // Try converting to float
|
try // Try converting to float
|
||||||
{
|
{
|
||||||
return any_cast<float>(val) == 1.0f;
|
return any_cast<float>(val) == 1.0f;
|
||||||
}
|
}
|
||||||
catch (boost::bad_any_cast &e) // Try converting to int
|
catch (boost::bad_any_cast) // Try converting to int
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return any_cast<int>(val) == 1;
|
return any_cast<int>(val) == 1;
|
||||||
}
|
}
|
||||||
catch (boost::bad_any_cast &e) // Does not convert, return
|
catch (boost::bad_any_cast) // Does not convert, return
|
||||||
{
|
{
|
||||||
LogWarning("invalid conversion to type \'bool\'");
|
LogWarning("invalid conversion to type \'bool\'");
|
||||||
return false;
|
return false;
|
||||||
@ -44,25 +46,25 @@ bool AnyAsBool(const any& val)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Will convert type 'any' val to a string
|
// Will convert type 'any' val to a string
|
||||||
string AnyAsString(const any& val)
|
string AnyAsString(const boost::any& val)
|
||||||
{
|
{
|
||||||
try // Try converting to string
|
try // Try converting to string
|
||||||
{
|
{
|
||||||
return any_cast<string>(val);
|
return any_cast<string>(val);
|
||||||
}
|
}
|
||||||
catch (boost::bad_any_cast &e)
|
catch (boost::bad_any_cast)
|
||||||
{
|
{
|
||||||
try // Try converting to int
|
try // Try converting to int
|
||||||
{
|
{
|
||||||
return to_string(any_cast<int>(val));
|
return to_string(any_cast<int>(val));
|
||||||
}
|
}
|
||||||
catch (boost::bad_any_cast &e)
|
catch (boost::bad_any_cast)
|
||||||
{
|
{
|
||||||
try // Try converting to float
|
try // Try converting to float
|
||||||
{
|
{
|
||||||
return to_string(any_cast<float>(val));
|
return to_string(any_cast<float>(val));
|
||||||
}
|
}
|
||||||
catch (boost::bad_any_cast &e) // Try converting to bool
|
catch (boost::bad_any_cast) // Try converting to bool
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -70,7 +72,7 @@ string AnyAsString(const any& val)
|
|||||||
if (any_cast<bool>(val) == true) i = "true";
|
if (any_cast<bool>(val) == true) i = "true";
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
catch (boost::bad_any_cast &e) // Does not convert, return
|
catch (boost::bad_any_cast) // Does not convert, return
|
||||||
{
|
{
|
||||||
LogWarning("invalid conversion to type \'string\'");
|
LogWarning("invalid conversion to type \'string\'");
|
||||||
return "";
|
return "";
|
||||||
@ -81,25 +83,25 @@ string AnyAsString(const any& val)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Will convert type 'any' val to a float
|
// Will convert type 'any' val to a float
|
||||||
float AnyAsFloat(const any& val)
|
float AnyAsFloat(const boost::any& val)
|
||||||
{
|
{
|
||||||
try // Try converting to float
|
try // Try converting to float
|
||||||
{
|
{
|
||||||
return any_cast<float>(val);
|
return any_cast<float>(val);
|
||||||
}
|
}
|
||||||
catch (boost::bad_any_cast &e)
|
catch (boost::bad_any_cast)
|
||||||
{
|
{
|
||||||
try // Try converting to int
|
try // Try converting to int
|
||||||
{
|
{
|
||||||
return (float)any_cast<int>(val);
|
return (float)any_cast<int>(val);
|
||||||
}
|
}
|
||||||
catch (boost::bad_any_cast &e)
|
catch (boost::bad_any_cast)
|
||||||
{
|
{
|
||||||
try // Try converting to string, then converting it to float
|
try // Try converting to string, then converting it to float
|
||||||
{
|
{
|
||||||
return stof(any_cast<string>(val));
|
return stof(any_cast<string>(val));
|
||||||
}
|
}
|
||||||
catch (boost::bad_any_cast &e) // Try converting to bool
|
catch (boost::bad_any_cast) // Try converting to bool
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -107,7 +109,7 @@ float AnyAsFloat(const any& val)
|
|||||||
if (any_cast<bool>(val) == true) i = 1;
|
if (any_cast<bool>(val) == true) i = 1;
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
catch (boost::bad_any_cast &e) // Does not convert, return
|
catch (boost::bad_any_cast) // Does not convert, return
|
||||||
{
|
{
|
||||||
LogWarning("invalid conversion to type \'float\'");
|
LogWarning("invalid conversion to type \'float\'");
|
||||||
return 0;
|
return 0;
|
||||||
@ -118,25 +120,25 @@ float AnyAsFloat(const any& val)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Will convert type 'any' val to an integer
|
// Will convert type 'any' val to an integer
|
||||||
int AnyAsInt(const any& val)
|
int AnyAsInt(const boost::any& val)
|
||||||
{
|
{
|
||||||
try // Try converting to int
|
try // Try converting to int
|
||||||
{
|
{
|
||||||
return any_cast<int>(val);
|
return any_cast<int>(val);
|
||||||
}
|
}
|
||||||
catch (boost::bad_any_cast &e)
|
catch (boost::bad_any_cast)
|
||||||
{
|
{
|
||||||
try // Try converting to float
|
try // Try converting to float
|
||||||
{
|
{
|
||||||
return (int)any_cast<float>(val);
|
return (int)any_cast<float>(val);
|
||||||
}
|
}
|
||||||
catch (boost::bad_any_cast &e)
|
catch (boost::bad_any_cast)
|
||||||
{
|
{
|
||||||
try // Try converting to string, then converting it to int
|
try // Try converting to string, then converting it to int
|
||||||
{
|
{
|
||||||
return stoi(any_cast<string>(val));
|
return stoi(any_cast<string>(val));
|
||||||
}
|
}
|
||||||
catch (boost::bad_any_cast &e) // Try converting to bool
|
catch (boost::bad_any_cast) // Try converting to bool
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -144,7 +146,7 @@ int AnyAsInt(const any& val)
|
|||||||
if (any_cast<bool>(val) == true) i = 1;
|
if (any_cast<bool>(val) == true) i = 1;
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
catch (boost::bad_any_cast &e) // Does not convert, return
|
catch (boost::bad_any_cast) // Does not convert, return
|
||||||
{
|
{
|
||||||
LogWarning("invalid conversion to type \'int\'");
|
LogWarning("invalid conversion to type \'int\'");
|
||||||
return 0;
|
return 0;
|
||||||
@ -156,35 +158,35 @@ int AnyAsInt(const any& val)
|
|||||||
|
|
||||||
// Gets type of 'any' val
|
// Gets type of 'any' val
|
||||||
// 0 -> int; 1 -> float; 2 -> bool; 3 -> string;
|
// 0 -> int; 1 -> float; 2 -> bool; 3 -> string;
|
||||||
int any_type(const any& val)
|
int any_type(const boost::any& val)
|
||||||
{
|
{
|
||||||
try // Try converting to int
|
try // Try converting to int
|
||||||
{
|
{
|
||||||
int i = any_cast<int>(val);
|
int i = any_cast<int>(val);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
catch (boost::bad_any_cast &e)
|
catch (boost::bad_any_cast)
|
||||||
{
|
{
|
||||||
try // Try converting to float
|
try // Try converting to float
|
||||||
{
|
{
|
||||||
float f = any_cast<float>(val);
|
float f = any_cast<float>(val);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
catch (boost::bad_any_cast &e)
|
catch (boost::bad_any_cast)
|
||||||
{
|
{
|
||||||
try // Try converting to bool
|
try // Try converting to bool
|
||||||
{
|
{
|
||||||
bool b = any_cast<bool>(val);
|
bool b = any_cast<bool>(val);
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
catch (boost::bad_any_cast &e) // Try converting to string
|
catch (boost::bad_any_cast) // Try converting to string
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string s = any_cast<string>(val);
|
string s = any_cast<string>(val);
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
catch (boost::bad_any_cast &e) // Does not convert, return
|
catch (boost::bad_any_cast) // Does not convert, return
|
||||||
{
|
{
|
||||||
LogWarning("variable has no type");
|
LogWarning("variable has no type");
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
17
Slang/boost_x64_release.props
Normal file
17
Slang/boost_x64_release.props
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<ImportGroup Label="PropertySheets" />
|
||||||
|
<PropertyGroup Label="UserMacros" />
|
||||||
|
<PropertyGroup>
|
||||||
|
<_PropertySheetDisplayName>boost_x64_release</_PropertySheetDisplayName>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemDefinitionGroup>
|
||||||
|
<ClCompile>
|
||||||
|
<AdditionalIncludeDirectories>D:\Code\boost;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<AdditionalLibraryDirectories>D:\Code\boost\stage\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemGroup />
|
||||||
|
</Project>
|
||||||
@ -7,11 +7,11 @@
|
|||||||
#include <regex>
|
#include <regex>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <any>
|
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include "strops.h"
|
#include "strops.h"
|
||||||
#include "graphics.h"
|
#include "graphics.h"
|
||||||
#include "anyops.h"
|
#include "anyops.h"
|
||||||
|
#include <boost/any.hpp>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace boost;
|
using namespace boost;
|
||||||
@ -19,7 +19,7 @@ using namespace boost;
|
|||||||
vector<string> types = { "int", "float", "string", "bool", "void", "null" };
|
vector<string> types = { "int", "float", "string", "bool", "void", "null" };
|
||||||
|
|
||||||
unordered_map<string, vector<vector<string>>> builtinFunctionValues;
|
unordered_map<string, vector<vector<string>>> builtinFunctionValues;
|
||||||
unordered_map<string, any> builtinVarVals;
|
unordered_map<string, boost::any> builtinVarVals;
|
||||||
|
|
||||||
Parser mainWindow;
|
Parser mainWindow;
|
||||||
|
|
||||||
@ -105,7 +105,7 @@ int GetBuiltins(const string& s)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Executes
|
// Executes
|
||||||
any CPPFunction(const string& name, const vector<any>& args)
|
boost::any CPPFunction(const string& name, const vector<boost::any>& args)
|
||||||
{
|
{
|
||||||
if (name == "CPP.Math.Sin")
|
if (name == "CPP.Math.Sin")
|
||||||
return sin(AnyAsFloat(args[0]));
|
return sin(AnyAsFloat(args[0]));
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
#include <stack>
|
#include <stack>
|
||||||
#include "eval.h"
|
#include "eval.h"
|
||||||
#include "strops.h"
|
#include "strops.h"
|
||||||
#include "builtin.h"
|
// #include "builtin.h"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
float precedence(const char& op) {
|
float precedence(const char& op) {
|
||||||
@ -29,7 +29,7 @@ float applyOp(const float& a, const float& b, const char& op) {
|
|||||||
case '^': return pow(a, b);
|
case '^': return pow(a, b);
|
||||||
}
|
}
|
||||||
string s(1, op);
|
string s(1, op);
|
||||||
LogWarning("operator \'" + s + "\' does not exist");
|
//LogWarning("operator \'" + s + "\' does not exist");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
#ifndef EVAL_H
|
#ifndef EVAL_H
|
||||||
#define EVAL_H
|
#define EVAL_H
|
||||||
|
|
||||||
float evaluate(std::string tokens);
|
float evaluate(const std::string& t);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@ -11,6 +11,7 @@
|
|||||||
#include <regex>
|
#include <regex>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <boost/any.hpp>
|
||||||
#include "strops.h"
|
#include "strops.h"
|
||||||
#include "builtin.h"
|
#include "builtin.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
@ -34,7 +35,7 @@ public:
|
|||||||
|
|
||||||
bool OnUserUpdate(float fElapsedTime) override
|
bool OnUserUpdate(float fElapsedTime) override
|
||||||
{
|
{
|
||||||
ExecuteFunction("Update", vector<any> {});
|
ExecuteFunction("Update", vector<boost::any> {});
|
||||||
|
|
||||||
// Called once per frame
|
// Called once per frame
|
||||||
//for (int x = 0; x < ScreenWidth(); x++)
|
//for (int x = 0; x < ScreenWidth(); x++)
|
||||||
|
|||||||
@ -3,8 +3,7 @@
|
|||||||
#define MAIN_H
|
#define MAIN_H
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace boost;
|
|
||||||
|
|
||||||
any ExecuteFunction(const string functionName, const vector<any> inputVarVals);
|
boost::any ExecuteFunction(const string& functionName, const vector<boost::any>& inputVarVals);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -3,8 +3,9 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
#include <boost/any.hpp>
|
||||||
#include "strops.h"
|
#include "strops.h"
|
||||||
#include "builtin.h"
|
//#include "builtin.h"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
const string WHITESPACE = " \n\r\t\f\v";
|
const string WHITESPACE = " \n\r\t\f\v";
|
||||||
@ -20,11 +21,12 @@ bool isNumber(const string& str)
|
|||||||
|
|
||||||
bool stob(string str)
|
bool stob(string str)
|
||||||
{
|
{
|
||||||
transform(str.begin(), str.end(), str.begin(), ::tolower);
|
//transform(str.begin(), str.end(), str.begin(), ::tolower);
|
||||||
istringstream is(str);
|
//istringstream is(str);
|
||||||
bool b;
|
//bool b;
|
||||||
is >> boolalpha >> b;
|
//is >> boolalpha >> b;
|
||||||
return b;
|
//return b;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
string StringRaw(const string& s)
|
string StringRaw(const string& s)
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
#ifndef STROPS_H
|
#ifndef STROPS_H
|
||||||
#define STROPS_H
|
#define STROPS_H
|
||||||
|
|
||||||
|
#include <boost/any.hpp>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
bool isNumber(const string& str);
|
bool isNumber(const string& str);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user