Skip to content

Commit

Permalink
Use pointers instead of references to track SExpr memory location
Browse files Browse the repository at this point in the history
  • Loading branch information
john-z-yang committed Nov 20, 2023
1 parent a832110 commit 67b05f4
Show file tree
Hide file tree
Showing 49 changed files with 465 additions and 452 deletions.
6 changes: 3 additions & 3 deletions src/code/Code.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ InstrPtr Code::pushCode(const uint8_t code, const unsigned int lineNum) {
return byteCodes.size() - 1;
}

uint8_t Code::pushConst(const SExpr &sExpr) {
uint8_t Code::pushConst(const SExpr *sExpr) {
consts.push_back(sExpr);
return consts.size() - 1;
}
Expand Down Expand Up @@ -89,9 +89,9 @@ std::ostream &code::operator<<(std::ostream &o, const Code &code) {

switch (byte) {
case OpCode::MAKE_CLOSURE: {
const auto &fn = cast<Prototype>(code.consts[READ_BYTE()].get());
const auto fn = cast<Prototype>(code.consts[READ_BYTE()]);
o << "MAKE_CLOSURE" << fn;
for (unsigned int i{0}; i < fn.numUpvals; i++) {
for (unsigned int i{0}; i < fn->numUpvals; i++) {
const auto isLocal = unsigned(READ_BYTE());
const auto idx = unsigned(READ_BYTE());
o << std::endl
Expand Down
4 changes: 2 additions & 2 deletions src/code/Code.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ class Code {

public:
std::vector<uint8_t> byteCodes;
std::vector<std::reference_wrapper<const sexpr::SExpr>> consts;
std::vector<const sexpr::SExpr *> consts;

std::vector<unsigned int> lineNums;

InstrPtr pushCode(const uint8_t code);
InstrPtr pushCode(const uint8_t code, const unsigned int lineNum);
uint8_t pushConst(const sexpr::SExpr &sExpr);
uint8_t pushConst(const sexpr::SExpr *sExpr);

void patchJump(const InstrPtr idx);
};
Expand Down
Loading

0 comments on commit 67b05f4

Please sign in to comment.