This commit is contained in:
Ilusha 2024-03-07 12:27:32 +03:00
parent b906e0e66c
commit 20ac8620e6
20 changed files with 86 additions and 853 deletions

View file

@ -18,7 +18,6 @@ add_subdirectory(Math)
add_subdirectory(Allocators) add_subdirectory(Allocators)
add_subdirectory(Strings) add_subdirectory(Strings)
add_subdirectory(Language) add_subdirectory(Language)
add_subdirectory(CommandLine)
add_subdirectory(Externals) add_subdirectory(Externals)
add_subdirectory(Connection) add_subdirectory(Connection)
add_subdirectory(Graphics) add_subdirectory(Graphics)

View file

@ -1,15 +0,0 @@
project(CommandLine)
### ---------------------- Static Library --------------------- ###
file(GLOB SOURCES "./private/*.cpp")
file(GLOB HEADERS "./public/*.hpp")
add_library(${PROJECT_NAME} STATIC ${SOURCES} ${HEADERS})
target_include_directories(${PROJECT_NAME} PUBLIC ./public/)
target_link_libraries(${PROJECT_NAME} PUBLIC Language Connection)
### -------------------------- Tests -------------------------- ###
enable_testing()
file(GLOB TEST_SOURCES "./tests/*.cpp")
add_executable(${PROJECT_NAME}Tests ${TEST_SOURCES})
target_link_libraries(${PROJECT_NAME}Tests ${PROJECT_NAME} Utils)
add_test(NAME ${PROJECT_NAME}Tests COMMAND ${PROJECT_NAME}Tests)

View file

@ -1,117 +0,0 @@
#include "CmdLineInterpreter.hpp"
#define MAX_LINE_LENGTH 1024
#include <cstdio>
#include <cstring>
using namespace tp;
static bool helpFunction(CmdLineInterpreter* self, const CommandLine& args) {
self->help(args);
return true;
}
void CmdLineInterpreter::help(const CommandLine& args) const {
auto commandName = args.getString("CommandName");
auto allCommands = commandName == "_none_";
if (allCommands) {
printf("Commands:\n");
for (auto command : mCommands) {
printf(" %s\n", command->key.read());
}
return;
}
auto idx = mCommands.presents(commandName);
if (!idx) {
printf("Command '%s' not found\n", commandName.read());
return;
}
printf("Command '%s'\n", commandName.read());
auto command = &mCommands.getSlotVal(idx);
command->args->help();
}
CmdLineInterpreter::CmdLineInterpreter() {
auto helpArgs = new CommandLine{ { "CommandName", "_none_" } };
addCommand("help", helpArgs, (CommandFunction) helpFunction, this);
}
void CmdLineInterpreter::addCommand(const String& id, CommandLine* args, CommandFunction function, void* customData) {
ASSERT(!mCommands.presents(id))
mCommands.put(id, { args, function, customData });
}
void CmdLineInterpreter::run() {
char buffer[MAX_LINE_LENGTH];
printf("Command Line Interpreter (or type 'exit' to quit):\n");
while (true) {
printf("%s >> ", mName.read());
// Read input from the user
if (fgets(buffer, MAX_LINE_LENGTH, stdin) == nullptr) {
printf("Error reading input.\n");
return;
}
// Remove the trailing newline character if it exists
auto length = strlen(buffer);
if (length > 0 && buffer[length - 1] == '\n') {
buffer[length - 1] = '\0';
}
// Check if the user wants to exit
if (strcmp(buffer, "exit") == 0) {
return;
}
// Process the input here
processCommand(buffer);
}
}
bool CmdLineInterpreter::processCommand(int1* commandString) {
ualni commandLen = 0;
for (auto i = commandString; *i != 0; i++) {
if (*i == ' ') break;
commandLen++;
}
commandString[commandLen] = 0;
auto args = commandString + commandLen + 1;
auto idx = mCommands.presents(commandString);
if (!idx) {
printf("ERROR: Command '%s' is not found\n", commandString);
printf("Please execute 'help' for more information\n\n");
return true;
}
auto command = &mCommands.getSlotVal(idx);
command->args->parse(args);
if (command->args->mError) {
printf("ERROR: Command call '%s' has invalid arguments\n", commandString);
command->args->resetError();
return true;
}
if (!command->function(command->customData, *command->args)) {
printf("ERROR: Command call '%s' failed\n", commandString);
return true;
}
return true;
}
CmdLineInterpreter::~CmdLineInterpreter() {
for (auto cmd : mCommands) {
delete cmd->val.args;
}
}

View file

@ -1,464 +0,0 @@
#include "CommandLine.hpp"
using namespace tp;
static ModuleManifest* sModuleDependencies[] = { &gModuleTokenizer, &gModuleConnection, nullptr };
ModuleManifest tp::gModuleCommandLine = ModuleManifest("CommandLine", nullptr, nullptr, sModuleDependencies);
const char* regexSpace = "\n|\t| |\r";
const char* regexFalse = "N|n|(False)|(false)";
const char* regexTrue = "Y|y|(True)|(true)";
const char* regexInt = "((\\-)|(\\+))?[0-9]+";
const char* regexFloat = R"(((\-)|(\+))?([0-9]+)(\.)([0-9]*)?)";
const char* regexString = "'{'-'}*'";
CommandLine::Arg::Arg(const Arg& arg) {
mId = arg.mId;
switch (arg.mType) {
case CommandLine::Arg::INT:
mType = INT;
mInt = arg.mInt;
break;
case CommandLine::Arg::FLOAT:
mType = FLOAT;
mFloat = arg.mFloat;
break;
case CommandLine::Arg::BOOL:
mType = BOOL;
mBool = arg.mBool;
break;
case CommandLine::Arg::STR:
mType = STR;
new (&mStr) StringArg();
mStr = arg.mStr;
break;
case CommandLine::Arg::FILE_IN:
mType = FILE_IN;
new (&mFile) FileInputArg();
mFile = arg.mFile;
break;
default: ASSERT(false)
}
mOptional = arg.mOptional;
}
CommandLine::Arg::Arg(const String& id, Type type) {
mId = id;
switch (type) {
case CommandLine::Arg::INT:
mType = INT;
new (&mInt) IntArg();
break;
case CommandLine::Arg::FLOAT:
mType = FLOAT;
new (&mFloat) FloatArg();
break;
case CommandLine::Arg::BOOL:
mType = BOOL;
new (&mBool) BoolArg();
break;
case CommandLine::Arg::STR:
mType = STR;
new (&mStr) StringArg();
break;
case CommandLine::Arg::FILE_IN:
mType = FILE_IN;
new (&mFile) FileInputArg();
break;
default: ASSERT(false)
}
mOptional = false;
}
CommandLine::Arg::Arg(const String& id, const Range<alni>& aAcceptingRange) {
mId = id;
mType = FLOAT;
mInt = { 0, 0, aAcceptingRange };
mOptional = false;
}
CommandLine::Arg::Arg(const String& id, const Range<alnf>& aAcceptingRange) {
mId = id;
mType = FLOAT;
mFloat = { 0, 0, aAcceptingRange };
mOptional = false;
}
CommandLine::Arg::Arg(const String& id, const Range<alni>& aAcceptingRange, alni aDefault) {
mId = id;
mType = INT;
mInt = { 0, aDefault, aAcceptingRange };
}
CommandLine::Arg::Arg(const String& id, const Range<alnf>& aAcceptingRange, alnf aDefault) {
mId = id;
mType = FLOAT;
mFloat = { 0, aDefault, aAcceptingRange };
}
CommandLine::Arg::Arg(const String& id, bool aDefault) {
mId = id;
mType = BOOL;
mBool.mDefault = aDefault;
}
CommandLine::Arg::Arg(const String& id, const char* aDefault) {
mId = id;
mType = STR;
new (&mStr) StringArg();
mStr.mDefault = aDefault;
}
CommandLine::Arg::~Arg() {
switch (mType) {
case CommandLine::Arg::STR: mStr.~StringArg(); break;
case CommandLine::Arg::FILE_IN: mFile.~FileInputArg(); break;
default: break;
}
}
CommandLine::CommandLine(const InitialierList<Arg>& args) {
bool optional_start = false;
for (auto& arg : args) {
ASSERT(!mArgs.presents(arg.mId) && "Argument Redefinition")
auto copy_arg = new Arg(arg);
mArgs.put(arg.mId, copy_arg);
mArgsOrder.pushBack(mArgs.get(arg.mId));
if (arg.mOptional) {
mOptionals++;
}
if (optional_start) {
ASSERT(arg.mOptional && "Not Optional Argument After Optionals")
} else if (arg.mOptional) {
optional_start = true;
}
}
mTokenizer.build({
{ regexSpace, TokType::SPACE },
{ regexFalse, TokType::BOOL_FALSE },
{ regexTrue, TokType::BOOL_TRUE },
{ regexInt, TokType::INT },
{ regexFloat, TokType::FLOAT },
{ regexString, TokType::STR },
});
ASSERT(mTokenizer.isBuild() && "Internal Error")
mArgumentTokenizer.build({ { regexSpace, ArgTokType::SPACE }, { "{ - }*", ArgTokType::ARG } });
ASSERT(mTokenizer.isBuild() && "Internal Error")
}
CommandLine::~CommandLine() {
for (auto arg : mArgsOrder) {
delete arg.data();
}
}
bool CommandLine::parse(char argc, const char* argv[], bool logError, ualni skipArgs) {
// discard some arguments
argc -= (char) skipArgs;
argv += skipArgs;
if (argc < mArgs.size() - mOptionals) {
ErrInvalidArgCount();
if (logError) {
ErrLog();
}
return false;
}
ualni idx = 0;
for (auto arg : mArgsOrder) {
if (idx < argc) {
parseArg(*arg.data(), argv[idx]);
} else {
initDefault(*arg.data());
}
if (mError) {
if (logError) ErrLog();
return false;
}
idx++;
}
return true;
}
bool CommandLine::parse(const char* args, bool logError) {
mArgumentTokenizer.bindSource(args);
mArgumentTokenizer.reset();
ualni argc = 0;
auto tok = mArgumentTokenizer.readTok();
auto argument = mArgsOrder.first();
while (tok != ArgTokType::FAILURE && tok != ArgTokType::END) {
if (tok != ArgTokType::ARG) {
tok = mArgumentTokenizer.readTok();
continue;
}
if (!argument) {
ErrInvalidArgCount();
if (logError) ErrLog();
return false;
}
parseArg(*argument->data, mArgumentTokenizer.extractVal().read());
if (mError && logError) {
ErrLog();
return false;
}
argc++;
argument = argument->next;
tok = mArgumentTokenizer.readTok();
}
ualni idx = 0;
for (auto arg : mArgsOrder) {
if (idx >= argc) {
initDefault(*arg.data());
}
if (mError) {
if (logError) ErrLog();
return false;
}
idx++;
}
return true;
}
alni CommandLine::getInt(const String& id) const {
auto& arg = getArg(id, Arg::INT);
return arg.mInt.mVal;
}
alnf CommandLine::getFloat(const String& id) const {
auto& arg = getArg(id, Arg::FLOAT);
return arg.mFloat.mVal;
}
bool CommandLine::getBool(const String& id) const {
auto& arg = getArg(id, Arg::BOOL);
return arg.mBool.mFlag;
}
const String& CommandLine::getString(const String& id) const {
auto& arg = getArg(id, Arg::STR);
return arg.mStr.mStr;
}
const LocalConnection::Location& CommandLine::getFile(const String& id) const {
auto& arg = getArg(id, Arg::FILE_IN);
return arg.mFile.mFileLocation;
}
CommandLine::Arg& CommandLine::getArg(const String& id, Arg::Type type) {
auto idx = mArgs.presents(id);
ASSERT(idx && "Invalid Id")
auto& arg = mArgs.getSlotVal(idx);
ASSERT(arg->mType == type && "Invalid Type Requested")
return *arg;
}
const CommandLine::Arg& CommandLine::getArg(const String& id, Arg::Type type) const {
auto idx = mArgs.presents(id);
ASSERT(idx && "Invalid Id")
auto& arg = mArgs.getSlotVal(idx);
ASSERT(arg->mType == type && "Invalid Type Requested")
return *arg;
}
void CommandLine::ErrInvalidArgCount() { mError = { "Invalid Number Of Arguments Passed", nullptr }; }
void CommandLine::ErrInvalidArgSyntax(Arg* arg) { mError = { "Invalid Syntax Of Argument", arg }; }
void CommandLine::ErrInvalidArgType(Arg* arg) { mError = { "Invalid Type Of Argument", arg }; }
void CommandLine::ErrFileNotExists(Arg* arg) { mError = { "File Not Exists", arg }; }
void CommandLine::ErrFileCouldNotOpen(Arg* arg) { mError = { "Could Not Open File", arg }; }
void CommandLine::ErrValNotinRange(Arg* arg) { mError = { "Value Not In Range", arg }; }
void CommandLine::ErrLog() {
printf("\nERROR : Invalid Command Line\n");
if (mError.mArg) {
alni idx = 0;
for (auto arg : mArgsOrder) {
if (mError.mArg == arg.data()) break;
idx++;
}
printf("\nArgument: %lli\n", idx);
logArg(*mError.mArg);
}
printf("Error Description: %s. \n", mError.mDescr);
printf("\nExpected Arguments are: \n");
ualni idx = 0;
for (auto arg : mArgsOrder) {
printf(" -- %lli -- \n", idx);
logArg(*arg.data());
idx++;
}
printf("\nNote regex for types are:\n");
printf(" False - %s\n", regexFalse);
printf(" True - %s\n", regexTrue);
printf(" Int - %s\n", regexInt);
printf(" Float - %s\n", regexFloat);
printf(" String - %s\n", regexString);
printf(" File - else\n");
}
void CommandLine::logArg(const Arg& arg) {
switch (arg.mType) {
case Arg::INT:
{
printf("Type : Int\n");
printf("Range : %lli - %lli\n", arg.mInt.mAcceptingRange.mBegin, arg.mInt.mAcceptingRange.mEnd);
if (arg.mOptional) {
printf("Default : %lli\n", arg.mInt.mDefault);
}
printf("Value : %lli\n", arg.mInt.mVal);
}
break;
case Arg::FLOAT:
{
printf("Type : Float\n");
printf("Range : %f - %f\n", (halnf) arg.mFloat.mAcceptingRange.mBegin, (halnf) arg.mFloat.mAcceptingRange.mEnd);
if (arg.mOptional) {
printf("Default : %f\n", arg.mFloat.mDefault);
}
printf("Value : %f\n", arg.mFloat.mVal);
}
break;
case Arg::BOOL:
{
printf("Type : Bool\n");
if (arg.mOptional) {
printf("Default : %s\n", arg.mBool.mDefault ? "True" : "False");
}
printf("Value : %s\n", arg.mBool.mFlag ? "True" : "False");
}
break;
case Arg::STR:
{
printf("Type : String\n");
if (arg.mOptional) {
printf("Default : %s\n", arg.mStr.mDefault.read());
}
printf("Value : %s\n", arg.mStr.mStr.read());
}
break;
case Arg::FILE_IN:
{
printf("Type : File Input\n");
printf("Value Path : %s\n", arg.mFile.mFileLocation.getLocation().read());
}
break;
default: ASSERT(false)
}
}
void CommandLine::initDefault(Arg& arg) {
switch (arg.mType) {
case Arg::INT: arg.mInt.mVal = arg.mInt.mDefault; break;
case Arg::FLOAT: arg.mFloat.mVal = arg.mFloat.mDefault; break;
case Arg::BOOL: arg.mBool.mFlag = arg.mBool.mDefault; break;
case Arg::STR: arg.mStr.mStr = arg.mStr.mDefault; break;
default: break;
}
}
void CommandLine::parseArg(Arg& arg, const char* src) {
mTokenizer.reset();
mTokenizer.bindSource(src);
auto tok = mTokenizer.readTok();
if (tok < TokType::INT || tok > TokType::STR) {
ErrInvalidArgSyntax(&arg);
return;
}
auto val = mTokenizer.extractVal();
switch (arg.mType) {
case Arg::INT:
{
if (tok != TokType::INT) {
ErrInvalidArgType(&arg);
return;
}
auto converted = String::Logic::convertStringToValue(val.read(), arg.mInt.mVal);
if (converted && arg.mInt.mVal < arg.mInt.mAcceptingRange.mBegin || arg.mInt.mVal > arg.mInt.mAcceptingRange.mEnd) {
ErrValNotinRange(&arg);
return;
}
}
break;
case Arg::FLOAT:
{
if (tok != TokType::FLOAT) {
ErrInvalidArgType(&arg);
return;
}
auto converted = String::Logic::convertStringToValue(val.read(), arg.mFloat.mVal);
if (converted && arg.mFloat.mVal < arg.mFloat.mAcceptingRange.mBegin || arg.mFloat.mVal > arg.mFloat.mAcceptingRange.mEnd) {
ErrValNotinRange(&arg);
return;
}
}
break;
case Arg::STR:
{
if (tok != TokType::STR) {
ErrInvalidArgType(&arg);
return;
}
arg.mStr.mStr.resize(val.size() - 2);
memCopy(arg.mStr.mStr.write(), val.read() + 1, val.size() - 2);
}
break;
case Arg::BOOL:
{
if (tok != TokType::BOOL_FALSE && tok != TokType::BOOL_TRUE) {
ErrInvalidArgType(&arg);
return;
}
arg.mBool.mFlag = tok == TokType::BOOL_TRUE;
}
break;
case Arg::FILE_IN:
{
if (tok != TokType::STR) {
ErrInvalidArgType(&arg);
return;
}
arg.mFile.mFileLocation.setLocation(val);
if (!arg.mFile.mFileLocation.exists()) {
ErrFileNotExists(&arg);
return;
}
}
break;
default: ASSERT(false)
}
arg.mIsPassed = true;
}
void CommandLine::help() const {
printf("Arguments:\n");
for (auto arg : mArgsOrder) {
logArg(*arg.data());
}
}

View file

@ -1,34 +0,0 @@
#pragma once
#include "CommandLine.hpp"
#include "Map.hpp"
namespace tp {
class CmdLineInterpreter {
public:
typedef bool (*CommandFunction)(void* customData, const CommandLine& args);
private:
struct Command {
CommandLine* args;
CommandFunction function;
void* customData = nullptr;
};
Map<String, Command> mCommands;
String mName = "InterpName";
public:
CmdLineInterpreter();
~CmdLineInterpreter();
void setName(const String& name) { mName = name; }
[[nodiscard]] const String& getName() const { return mName; }
void help(const CommandLine& args) const;
void addCommand(const String& id, CommandLine* args, CommandFunction function, void* customData = nullptr);
void run();
bool processCommand(int1* command);
};
}

View file

@ -1,131 +0,0 @@
#pragma once
#include "LocalConnection.hpp"
#include "Map.hpp"
#include "Tokenizer.hpp"
namespace tp {
extern ModuleManifest gModuleCommandLine;
struct CommandLine {
struct IntArg {
alni mVal = 0;
alni mDefault = 0;
Range<alni> mAcceptingRange = { -(std::numeric_limits<alni>::max() - 1), std::numeric_limits<alni>::max() };
};
struct FloatArg {
alnf mVal = 0.f;
alnf mDefault = 0.f;
Range<alnf> mAcceptingRange = { -(std::numeric_limits<alnf>::max() - 1), std::numeric_limits<alnf>::max() };
};
struct BoolArg {
bool mFlag = false;
bool mDefault = false;
};
struct StringArg {
String mStr;
String mDefault;
};
struct FileInputArg {
LocalConnection::Location mFileLocation;
};
struct Arg {
String mId;
enum Type { INT, FLOAT, BOOL, STR, FILE_IN, NONE } mType = NONE;
union {
IntArg mInt;
FloatArg mFloat;
BoolArg mBool;
StringArg mStr;
FileInputArg mFile;
};
bool mOptional = true;
bool mIsPassed = false;
Arg(const Arg& arg);
Arg(const String& id, Type type);
Arg(const String& id, const Range<alni>& aAcceptingRange);
Arg(const String& id, const Range<alnf>& aAcceptingRange);
Arg(const String& id, const Range<alni>& aAcceptingRange, alni aDefault);
Arg(const String& id, const Range<alnf>& aAcceptingRange, alnf aDefault);
Arg(const String& id, bool aDefault);
Arg(const String& id, const char* aDefault);
~Arg();
};
struct Error {
const char* mDescr = nullptr;
Arg* mArg = nullptr;
operator bool() { return mDescr != nullptr; }
} mError;
CommandLine(const InitialierList<Arg>& args);
~CommandLine();
void resetError() { mError.mDescr = nullptr; }
bool parse(char argc, const char* argv[], bool logError = true, ualni skipArgs = 1);
bool parse(const char* args, bool logError = true);
void help() const;
[[nodiscard]] alni getInt(const String& id) const;
[[nodiscard]] alnf getFloat(const String& id) const;
[[nodiscard]] bool getBool(const String& id) const;
[[nodiscard]] const String& getString(const String& id) const;
[[nodiscard]] const LocalConnection::Location& getFile(const String& id) const;
const CommandLine& operator=(const CommandLine&) = delete;
private:
enum class TokType {
SPACE,
INT,
FLOAT,
BOOL_FALSE,
BOOL_TRUE,
STR,
NONE,
FAILURE,
END,
};
typedef SimpleTokenizer<char, TokType, TokType::NONE, TokType::FAILURE, TokType::END> Tokenizer;
Tokenizer mTokenizer;
Map<String, Arg*> mArgs;
List<Arg*> mArgsOrder;
ualni mOptionals = 0;
enum class ArgTokType {
SPACE,
ARG,
NONE,
FAILURE,
END,
};
SimpleTokenizer<char, ArgTokType, ArgTokType::NONE, ArgTokType::FAILURE, ArgTokType::END> mArgumentTokenizer;
Arg& getArg(const String& id, Arg::Type type);
[[nodiscard]] const Arg& getArg(const String& id, Arg::Type type) const;
void ErrInvalidArgCount();
void ErrInvalidArgSyntax(Arg* arg);
void ErrInvalidArgType(Arg* arg);
void ErrFileNotExists(Arg* arg);
void ErrFileCouldNotOpen(Arg* arg);
void ErrValNotinRange(Arg* arg);
void ErrLog();
static void logArg(const Arg& arg);
static void initDefault(Arg& arg);
void parseArg(Arg& arg, const char* src);
};
}

View file

@ -1,21 +0,0 @@
#include "Tests.hpp"
using namespace tp;
static CommandLine createCmdLine() {
CommandLine cmd({
{ "bool", CommandLine::Arg::BOOL },
{ "int", CommandLine::Arg::INT },
{ "string", CommandLine::Arg::STR },
{ "float", CommandLine::Arg::FLOAT },
});
return cmd;
}
TEST_DEF_STATIC(Simple) {
auto cmd = createCmdLine();
const char* args[] = { "false", "2", "'str'", "-0.15" };
cmd.parse(4, args, true, 0);
}
TEST_DEF(CommandLine) { testSimple(); }

View file

@ -1,33 +0,0 @@
#include "CmdLineInterpreter.hpp"
#include "Tests.hpp"
using namespace tp;
TEST_DEF_STATIC(Simple) {
struct TestStruct {
int val = 0;
static bool print(TestStruct* self, const CommandLine& args) {
printf("Test Val - %i\n", (int) args.getBool("bool"));
return false;
}
};
TestStruct self;
CmdLineInterpreter interp;
interp.addCommand("test", new CommandLine{ { "bool", CommandLine::Arg::BOOL } }, (CmdLineInterpreter::CommandFunction) TestStruct::print);
printf("test false\n", stdin);
printf("help\n", stdin);
printf("help test\n", stdin);
printf("exit\n", stdin);
interp.run();
}
TEST_DEF(Interpreter) {
// testSimple();
}

View file

@ -1,16 +0,0 @@
#include "Tests.hpp"
int main() {
tp::ModuleManifest* deps[] = { &tp::gModuleUtils, &tp::gModuleTokenizer, nullptr };
tp::ModuleManifest testModule("CommandLineTest", nullptr, nullptr, deps);
if (!testModule.initialize()) {
return 1;
}
// testCommandLine();
testInterpreter();
testModule.deinitialize();
}

View file

@ -1,8 +0,0 @@
#pragma once
#include "Allocators.hpp"
#include "CommandLine.hpp"
#include "Testing.hpp"
void testCommandLine();
void testInterpreter();

View file

@ -0,0 +1,41 @@
#pragma once
#include "ConnectionCommon.hpp"
#include "List.hpp"
namespace tp {
class RemoteConnectionContext;
class RemoteConnection : public Connection {
public:
class Location {
ualni mId = 0;
public:
Location() = default;
};
public:
RemoteConnection(){ MODULE_SANITY_CHECK(gModuleConnection) };
virtual ~RemoteConnection() {
if (mStatus.isOpened()) RemoteConnection::disconnect();
}
public:
virtual bool connect(const Location& location, const Type& connectionInfo);
virtual bool disconnect();
public:
virtual const Location& getLocation() { return mLocation; }
public:
virtual bool readBytes(Byte* bytes, SizeBytes size);
virtual bool writeBytes(const Byte* bytes, SizeBytes size);
private:
RemoteConnectionContext* mHandle = nullptr;
Location mLocation;
};
}

View file

@ -0,0 +1,11 @@
#include "RemoteConnection.hpp"
#include "Testing.hpp"
using namespace tp;
TEST_DEF_STATIC(Simple) {
TEST(false);
}
TEST_DEF(RemoteConnection) { testSimple(); }

View file

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "SimpleParser.hpp" // #include "SimpleParser.hpp"
const char* gGrammar = R"( const char* gGrammar = R"(
# Grammar in the CF-RE United Format (Defined by language module) # Grammar in the CF-RE United Format (Defined by language module)

View file

@ -1,6 +1,7 @@
#include "Test.hpp" #include "Test.hpp"
/*
using namespace tp; using namespace tp;
void testAutomation() { void testAutomation() {
@ -38,3 +39,7 @@ int main() {
testModule.deinitialize(); testModule.deinitialize();
} }
*/
int main() { return 0; }

View file

@ -31,6 +31,7 @@ Parser::Result Parser::parse(const tp::String& stream) {
bind(parser); bind(parser);
std::string streamStd(stream.read()); std::string streamStd(stream.read());
streamStd += "\n"; // for windows os to make happy
ASSERT(parser.valid()); ASSERT(parser.valid());

View file

@ -41,25 +41,26 @@ if (i == 10) {
)"; )";
auto script = R"( auto script = R"(
var i = false; print false;
print i;
)"; )";
TEST_DEF_STATIC(Complex) { TEST_DEF_STATIC(Simple) {
auto method = NDO_CAST(MethodObject, NDO->create("method")); auto method = NDO_CAST(MethodObject, NDO->create("method"));
auto interpreter = NDO_CAST(InterpreterObject, NDO->create("interpreter")); auto interpreter = NDO_CAST(InterpreterObject, NDO->create("interpreter"));
interpreter->getMember<LinkObject>("target method")->setLink(method); interpreter->getMember<LinkObject>("target method")->setLink(method);
method->mScript->mReadable->val = script1; method->mScript->mReadable->val = script;
method->compile(); method->compile();
interpreter->exec(); interpreter->exec();
NDO->destroy(interpreter); NDO->destroy(interpreter);
printf("\n\nEnd\n\n");
} }
TEST_DEF_STATIC(Simple) { TEST_DEF_STATIC(SimpleSave) {
auto method = NDO_CAST(MethodObject, NDO->create("method")); auto method = NDO_CAST(MethodObject, NDO->create("method"));
auto interpreter = NDO_CAST(InterpreterObject, NDO->create("interpreter")); auto interpreter = NDO_CAST(InterpreterObject, NDO->create("interpreter"));
@ -82,7 +83,22 @@ TEST_DEF_STATIC(Simple) {
printf("\n\nEnd\n\n"); printf("\n\nEnd\n\n");
} }
TEST_DEF_STATIC(Complex) {
auto method = NDO_CAST(MethodObject, NDO->create("method"));
auto interpreter = NDO_CAST(InterpreterObject, NDO->create("interpreter"));
interpreter->getMember<LinkObject>("target method")->setLink(method);
method->mScript->mReadable->val = script1;
method->compile();
interpreter->exec();
NDO->destroy(interpreter);
}
TEST_DEF(Interpreter) { TEST_DEF(Interpreter) {
testSimple(); testSimple();
testSimpleSave();
// testComplex(); // testComplex();
} }

View file

@ -18,9 +18,9 @@ int main() {
if (module.initialize()) { if (module.initialize()) {
// testParser(); testParser();
// testCore(); testCore();
// testPrimitives(); testPrimitives();
testInterpreter(); testInterpreter();
module.deinitialize(); module.deinitialize();

View file

@ -7,7 +7,7 @@ file(GLOB HEADERS "./public/*.hpp" "./public/*/*.hpp" "./applications/*.hpp")
add_library(${PROJECT_NAME} STATIC ${SOURCES} ${HEADERS}) add_library(${PROJECT_NAME} STATIC ${SOURCES} ${HEADERS})
target_include_directories(${PROJECT_NAME} PUBLIC ./public/) target_include_directories(${PROJECT_NAME} PUBLIC ./public/)
target_link_libraries(${PROJECT_NAME} PUBLIC Math CommandLine Connection) target_link_libraries(${PROJECT_NAME} PUBLIC Math Connection)
### -------------------------- Applications -------------------------- ### ### -------------------------- Applications -------------------------- ###
add_executable(rayt ./applications/Rayt.cpp applications/SceneLoad.cpp add_executable(rayt ./applications/Rayt.cpp applications/SceneLoad.cpp

View file

@ -3,7 +3,6 @@
#include "Rayt.hpp" #include "Rayt.hpp"
#include "CommandLine.hpp"
#include "Timing.hpp" #include "Timing.hpp"
#define STB_IMAGE_WRITE_IMPLEMENTATION #define STB_IMAGE_WRITE_IMPLEMENTATION

View file

@ -1,7 +1,7 @@
#include "MathCommon.hpp" #include "MathCommon.hpp"
#include "CommandLine.hpp" #include "ConnectionCommon.hpp"
#include "Module.hpp" #include "Module.hpp"
#include "Ray.hpp" #include "Ray.hpp"
#include "RayTracer.hpp" #include "RayTracer.hpp"
@ -43,7 +43,7 @@ normal = n1 * barycentric.x + n2 * barycentric.y + n3 * barycentric.z;
using namespace tp; using namespace tp;
ModuleManifest* sDependencies[] = { &gModuleMath, &gModuleCommandLine, &gModuleConnection, nullptr }; ModuleManifest* sDependencies[] = { &gModuleMath, &gModuleConnection, nullptr };
ModuleManifest tp::gModuleRayTracer = ModuleManifest("RayTracer", nullptr, nullptr, sDependencies); ModuleManifest tp::gModuleRayTracer = ModuleManifest("RayTracer", nullptr, nullptr, sDependencies);