Skip to content

Commit

Permalink
Merge pull request #24 from SujalChoudhari/dev
Browse files Browse the repository at this point in the history
Project cleanup
  • Loading branch information
SujalChoudhari authored Oct 4, 2023
2 parents 1aafe81 + 5831dc8 commit 0040a30
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 69 deletions.
6 changes: 0 additions & 6 deletions Application/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ namespace Coda {

std::string subCommand = argParser.getSubCommand();

#if _DEBUG
return repl();

#else

if (subCommand == "repl") {
return repl();
}
Expand Down Expand Up @@ -83,7 +78,6 @@ namespace Coda {
}
return EXIT_SUCCESS;
}
#endif
}


Expand Down
2 changes: 1 addition & 1 deletion Application/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Coda {
dddddddd \n\
CCCCCCCCCCCCC d::::::d \n\
CCC::::::::::::C d::::::d \n\
CC:::::::::::::::C d::::::d \033[0mv0.3\033[1;96m \n\
CC:::::::::::::::C d::::::d \033[0mv1.0.1\033[1;96m \n\
C:::::CCCCCCCC::::C d:::::d \n\
C:::::C CCCCCC ooooooooooo ddddddddd:::::d aaaaaaaaaaaaa \n\
C:::::C oo:::::::::::oo dd::::::::::::::d a::::::::::::a \n\
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0.1] - 04-10-2023
- Code cleaning
- Removed `Linux` support.

## [1.0] - 02-10-2023

### Added
Expand Down
37 changes: 1 addition & 36 deletions Frontend/Importer/Importer.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
#include "Importer.h"
#include <algorithm>

#if _WIN32
#include <Windows.h>
#else
#include <unistd.h>
#include <linux/limits.h>
#endif


#include "../../Error/Error.h"

Expand Down Expand Up @@ -90,9 +85,6 @@ namespace Coda {
Error::Importer::raise("Imported file not found: " + importString);
}


#if _WIN32 // Check if the platform is Windows

std::string Importer::getExecutablePath() {
wchar_t buffer[MAX_PATH];
GetModuleFileNameW(NULL, buffer, MAX_PATH);
Expand All @@ -108,37 +100,10 @@ namespace Coda {
return narrowExecutablePath;
}

#else // Assuming Unix-like system (Linux, macOS, etc.)
std::string Importer::getExecutablePath() {
char buffer[PATH_MAX];
ssize_t len = readlink("/proc/self/exe", buffer, sizeof(buffer) - 1);
if (len != -1) {
buffer[len] = '\0';
std::string executablePath(buffer);
size_t lastSlashIndex = executablePath.rfind("/");
if (lastSlashIndex != std::string::npos) {
executablePath = executablePath.substr(0, lastSlashIndex + 1);
}
return executablePath;
}
else {
throw "failed to get path of executable file"
return "";
}
}
#endif

#if _WIN32
bool Importer::fileExists(const std::string& filePath) {
std::wstring wideFilePath(filePath.begin(), filePath.end());
DWORD fileAttributes = GetFileAttributes(wideFilePath.c_str());
return (fileAttributes != INVALID_FILE_ATTRIBUTES && !(fileAttributes & FILE_ATTRIBUTE_DIRECTORY));
}
#else
bool fileExists(const std::string& filePath) {
std::wstring wideFilePath(filePath.begin(), filePath.end());
return access(wideFilePath, F_OK) == 0;
}
#endif
}
}
32 changes: 6 additions & 26 deletions Runtime/Interpreter/EvaluateObjectType.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#include "Interpreter.h"
#ifdef _WIN32
#include <Windows.h>
#else
#include <dlcfn.h>
#endif // _WIN32



namespace Coda {
Expand Down Expand Up @@ -65,7 +62,7 @@ namespace Coda {
IF_ERROR_RETURN_VALUE_PTR;
Value args = Value();
ValuePtr name = interpret(*callExpression.left.get(), env);

Position pos = callExpression.left->endPosition;
pos.scope = name->value;
Interpreter::callStack.push(pos);
Expand Down Expand Up @@ -137,14 +134,9 @@ namespace Coda {

typedef void (*FunctionType) (IValuePtr, IValuePtr, IEnvironment*);

#ifdef _WIN32
dllFilename += ".dll";
std::wstring s(dllFilename.begin(), dllFilename.end());
HMODULE lib = LoadLibrary(s.c_str());
#else
dllFilename += ".so";
void* lib = dlopen(dllFilename, RTLD_LAZY);
#endif


if (!lib) {
Expand All @@ -153,19 +145,12 @@ namespace Coda {
}

FunctionType myFunction;
#ifdef _WIN32
myFunction = (FunctionType)GetProcAddress(lib, functionName.c_str());
#else
myFunction = (FunctionType)dlsym(lib, functionName.c_str());
#endif


if (!myFunction) {
Error::Runtime::raise("Cannot find function " + functionName + " at, ", Interpreter::callStack, callExpression.startPosition, callExpression.endPosition);
#ifdef _WIN32
FreeLibrary(lib);
#else
dlclose(lib);
#endif
return nullptr;
}

Expand All @@ -178,14 +163,9 @@ namespace Coda {
Error::Runtime::raise("Error in running '" + functionName + "': " + s);
}

// Unload the library
#ifdef _WIN32
FreeLibrary(lib);
#else
dlclose(lib);
#endif
return std::dynamic_pointer_cast<Value>(result);
}
}


ValuePtr Interpreter::evaluateMemberExpression(const Frontend::Node& astNode, Environment& env)
Expand Down Expand Up @@ -237,5 +217,5 @@ namespace Coda {
IF_ERROR_RETURN_VALUE_PTR;
return env.addFunction(astNode.value, astNode, env);
}
} // namespace Runtime
} // namespace Coda
} // namespace Runtime
} // namespace Coda

0 comments on commit 0040a30

Please sign in to comment.