-
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
1 parent
2b99f8c
commit 80f9e84
Showing
40 changed files
with
1,174 additions
and
647 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
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
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
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
This file was deleted.
Oops, something went wrong.
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,82 @@ | ||
#pragma once | ||
|
||
#include <cassert> | ||
#include <filesystem> | ||
#include <fstream> | ||
#include <iostream> | ||
#include <istream> | ||
#include <vector> | ||
|
||
#include "ChaiVM/interpreter/code-manager/func-struct.hpp" | ||
#include "ChaiVM/memory/allocator.hpp" | ||
#include "ChaiVM/memory/linear-allocator.hpp" | ||
#include "ChaiVM/memory/linear-buffer.hpp" | ||
|
||
namespace chai::interpreter { | ||
|
||
/** | ||
* Class to manage bytecode. Similar to ClassLoader. | ||
*/ | ||
class CodeManager final { | ||
public: | ||
enum ConstantTag : uint8_t { | ||
CNST_I64 = 1, | ||
CNST_F64, | ||
CNST_FUNC_NAME_AND_TYPE, | ||
CNST_RAW_STR, // Analogue of CONSTANT_Utf8 in jvm | ||
}; | ||
|
||
/** | ||
* Parses and loads the full file. | ||
* @param path Path to the .chai file. | ||
*/ | ||
void load(const std::filesystem::path &path); | ||
|
||
/** | ||
* Loads stream of Constant pool. | ||
* @param istream | ||
*/ | ||
void loadPool(std::istream &istream); | ||
|
||
void loadFunction(std::istream &istream); | ||
|
||
chsize_t getCnst(Immidiate id); | ||
|
||
bytecode_t getBytecode(size_t func, chsize_t pc); | ||
|
||
const Function &getFunc(Immidiate imm) const; | ||
|
||
const Function &getStartFunc() const; | ||
|
||
private: | ||
std::vector<Function> funcs_; | ||
|
||
/** | ||
* Runtime constant pool. Constants(excepting Strings) with id [imm] can be | ||
* retrieved via this vector. If [imm] is String then the string keeps in | ||
* stringPool_[constantPool_[imm]]. | ||
*/ | ||
std::vector<chsize_t> constantPool_; | ||
|
||
/** | ||
* We cannot contain strings in constantPool_ so we keep constant strings | ||
* here. | ||
*/ | ||
std::vector<std::string> stringPool_; | ||
|
||
/** | ||
* Id in appropriate collection by immidiate. | ||
* For example, func by imm is found as funcs_[dispatch_[imm]]. | ||
* @todo #1:90min We can avoid using dispatch_ anywhere via inheritance. | ||
*/ | ||
std::vector<Immidiate> dispatch_; | ||
}; | ||
|
||
class BeyondCodeBoundaries : public std::runtime_error { | ||
public: | ||
BeyondCodeBoundaries(char const *msg); | ||
BeyondCodeBoundaries(const std::string &msg); | ||
const char *what() const noexcept override; | ||
}; | ||
|
||
} // namespace chai::interpreter |
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,17 @@ | ||
#pragma once | ||
|
||
#include <vector> | ||
|
||
#include "ChaiVM/interpreter/instruction.hpp" | ||
#include "ChaiVM/types.hpp" | ||
|
||
namespace chai::interpreter { | ||
|
||
struct Function { | ||
uint8_t numRegs; | ||
uint8_t numArgs; | ||
Immidiate constFuncRef; | ||
std::vector<bytecode_t> code = {}; | ||
}; | ||
|
||
} // namespace chai::interpreter |
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,37 @@ | ||
#pragma once | ||
|
||
#include "ChaiVM/interpreter/code-manager/func-struct.hpp" | ||
#include "ChaiVM/memory/linear-allocator.hpp" | ||
#include "ChaiVM/memory/linear-buffer.hpp" | ||
|
||
namespace chai::interpreter { | ||
|
||
class Frame { | ||
|
||
public: | ||
Frame(Frame *prev, const Function &func, memory::LinearBuffer &buffer); | ||
|
||
void passArgs(); | ||
|
||
chai::chsize_t &operator[](size_t n) &; | ||
const chsize_t &operator[](size_t n) const &; | ||
|
||
/** | ||
* Get state. | ||
* @return state. | ||
*/ | ||
std::vector<chsize_t> copyState(); | ||
|
||
Frame *back(); | ||
|
||
public: | ||
Function const &func_; | ||
chsize_t pc_; | ||
|
||
private: | ||
Frame *prev_; | ||
size_t regsize_; | ||
std::vector<chsize_t, memory::LinearAllocator<chsize_t>> registers_; | ||
}; | ||
|
||
} // namespace chai::interpreter |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
80f9e84
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Puzzle
1-083ca17e
discovered ininclude/ChaiVM/interpreter/code-manager/code-manager.hpp
) and submitted as #63. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.80f9e84
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Puzzle
1-b9389013
discovered insrc/ChaiVM/interpreter/code-manager/code-manager.cpp
) and submitted as #64. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.