-
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.
* #82: Fixed strings, added loading of klasses * #82: make format * #94: corresponding cpp files * #94: Added commentary * #94: make format * #94: Removed Data, added `isObject` field * #94: getStringByStringPoolPos * #97: Added instructions to yaml * #97: make format * #97: Implemented AllocRef, LdraRef, StarRef * #97: Added tests * #97: Added test for GetField * #97: make format * #97: Edited todo * #97: Returned cmakelist back * #97: Added todo
- Loading branch information
1 parent
858ac6a
commit 7e6e7a8
Showing
12 changed files
with
417 additions
and
73 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#pragma once | ||
|
||
#include "ChaiVM/interpreter/code-manager/klass.hpp" | ||
#include "ChaiVM/memory/linear-allocator.hpp" | ||
#include "ChaiVM/memory/linear-buffer.hpp" | ||
#include <cassert> | ||
|
||
namespace chai::interpreter { | ||
|
||
// @todo #97:90min Add allocator here. | ||
struct ObjectHeader { | ||
chsize_t size_; | ||
Immidiate klassId_; | ||
}; | ||
|
||
/** | ||
* Facade to manage object. | ||
* Note, it does not own header and fields. | ||
* @todo #97:30min Consider refactoring object to just cast it from raw pointer. | ||
* It can be faster. | ||
*/ | ||
class Object { | ||
|
||
public: | ||
explicit Object(ObjectHeader *header, chsize_t *fields); | ||
/** | ||
* Ctor. | ||
* Create object from ref to object. | ||
* @param ref Ref to object (usually contains in register). | ||
*/ | ||
explicit Object(chsize_t ref); | ||
|
||
chsize_t getField(Immidiate offset) const; | ||
|
||
void setField(Immidiate offset, chsize_t value) const; | ||
|
||
private: | ||
ObjectHeader *header_; | ||
chsize_t *fields_; | ||
}; | ||
|
||
} // 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 |
---|---|---|
@@ -1,7 +1,12 @@ | ||
#include "ChaiVM/interpreter/code-manager/klass.hpp" | ||
#include "ChaiVM/interpreter/objects.hpp" | ||
|
||
namespace chai::interpreter { | ||
|
||
chsize_t Klass::size() { return fields_.size(); } | ||
chsize_t Klass::nFields() const { return fields_.size(); } | ||
|
||
chsize_t Klass::instanceSize() const { | ||
return nFields() * sizeof(chsize_t) + sizeof(ObjectHeader); | ||
} | ||
|
||
} // 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,25 @@ | ||
#include <cassert> | ||
|
||
#include "ChaiVM/interpreter/frame.hpp" | ||
#include "ChaiVM/interpreter/objects.hpp" | ||
|
||
namespace chai::interpreter { | ||
|
||
Object::Object(ObjectHeader *header, chsize_t *fields) | ||
: header_(header), fields_(fields) {} | ||
|
||
Object::Object(chsize_t ref) | ||
: header_(std::bit_cast<ObjectHeader *>(ref)), | ||
fields_(std::bit_cast<chsize_t *>(header_ + 1)) {} | ||
|
||
chsize_t Object::getField(Immidiate offset) const { | ||
assert(offset % 8 == 0); | ||
return fields_[offset / 8]; | ||
} | ||
|
||
void Object::setField(Immidiate offset, chsize_t value) const { | ||
assert(offset % 8 == 0); | ||
fields_[offset / 8] = value; | ||
} | ||
|
||
} // 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
Oops, something went wrong.
7e6e7a8
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
97-491954b0
discovered ininclude/ChaiVM/interpreter/executor.hpp
) and submitted as #100. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.7e6e7a8
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
97-0dcc99de
discovered ininclude/ChaiVM/interpreter/objects.hpp
) and submitted as #101. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.7e6e7a8
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
97-fe6e6775
discovered ininclude/ChaiVM/interpreter/objects.hpp
) and submitted as #102. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.