-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
135 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* MIT License | ||
# | ||
# Copyright (c) 2021 Ferhat Geçdoğan All Rights Reserved. | ||
# Distributed under the terms of the MIT License. | ||
# | ||
# */ | ||
|
||
#ifndef KALEM_HASH_CHECKER_HPP | ||
#define KALEM_HASH_CHECKER_HPP | ||
|
||
#include <iostream> | ||
#include <string> | ||
#include <cstddef> | ||
|
||
typedef struct { | ||
std::size_t old_hash, | ||
hash; | ||
|
||
std::string file; | ||
|
||
bool changed = false; | ||
} kl_hash; | ||
|
||
class KalemHashChecker { | ||
kl_hash hash; | ||
public: | ||
bool HashInit(std::string file); | ||
|
||
void HashCreate(std::string file); | ||
}; | ||
|
||
|
||
#endif //KALEM_HASH_CHECKER_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#!/bin/sh | ||
|
||
c++ -std=c++20 src/Kalem_Structure.cpp src/Kalem_Codegen.cpp src/Kalem.cpp -o kalem | ||
c++ -std=c++20 src/Kalem_Hash_Checker.cpp src/Kalem_Structure.cpp src/Kalem_Codegen.cpp src/Kalem.cpp -o kalem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* MIT License | ||
# | ||
# Copyright (c) 2021 Ferhat Geçdoğan All Rights Reserved. | ||
# Distributed under the terms of the MIT License. | ||
# | ||
# */ | ||
|
||
#include <string> | ||
#include <fstream> | ||
#include <functional> | ||
#include <sstream> | ||
|
||
#include "../include/Kalem_Hash_Checker.hpp" | ||
|
||
#include "../include/libs/FileSystemPlusPlus.hpp" | ||
|
||
bool KalemHashChecker::HashInit(std::string file) { | ||
std::string _data = fsplusplus::ReadFileWithReturn(file); | ||
|
||
hash.hash = std::hash<std::string>{}(_data); | ||
|
||
_data.erase(); | ||
|
||
if(fsplusplus::IsExistFile(fsplusplus::GetCurrentWorkingDir() | ||
+ "/" | ||
+ file | ||
+ ".__kalem_hash_cache__")) { | ||
const std::string old_hash = fsplusplus::ReadFileWithReturn(file | ||
+ ".__kalem_hash_cache__"); | ||
|
||
// TODO: Implement size_t to string converter | ||
std::stringstream temp_stream(old_hash); | ||
|
||
std::size_t temp_hash; | ||
|
||
temp_stream >> temp_hash; | ||
|
||
if(hash.hash == temp_hash) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} else { | ||
return false; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
void KalemHashChecker::HashCreate(std::string file) { | ||
std::string _data = fsplusplus::ReadFileWithReturn(file); | ||
|
||
hash.hash = std::hash<std::string>{}(_data); | ||
|
||
_data.erase(); | ||
|
||
if(fsplusplus::IsExistFile(fsplusplus::GetCurrentWorkingDir() | ||
+ "/" | ||
+ file | ||
+ ".__kalem_hash_cache__") == false) { | ||
fsplusplus::CreateFile(file + ".__kalem_hash_cache__", std::to_string(hash.hash)); | ||
} else { | ||
_data = fsplusplus::ReadFileWithReturn(file | ||
+ ".__kalem_hash_cache__"); | ||
|
||
if(std::to_string(hash.hash) != _data) { | ||
std::ofstream output_stream; | ||
output_stream.open(fsplusplus::GetCurrentWorkingDir() | ||
+ "/" | ||
+ file | ||
+ ".__kalem_hash_cache__", std::ofstream::trunc); | ||
|
||
output_stream << std::to_string(hash.hash); | ||
|
||
output_stream.close(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,5 @@ | |
@my_test void { | ||
@print "Greetings from test.kalem!\n" | ||
} | ||
|
||
|