Skip to content

Commit

Permalink
#111 add gc test and fix python usage in cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
c71n93 committed Aug 24, 2024
1 parent 8635cdd commit a9a1f64
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ if (CHAI_BENCH)
add_subdirectory(bench)
endif ()

find_package(Python COMPONENTS Interpreter REQUIRED)
# @todo #15:90min Generate autogen/operations.hpp into build directory.
set(OPERATIONS_DIR ${CMAKE_SOURCE_DIR}/include/ChaiVM/interpreter/autogen/operations.hpp)
add_custom_target(gen_operations_header
COMMENT "Generating ${OPERATIONS_DIR}"
OUTPUT ${OPERATIONS_DIR}
COMMAND python3 ${CMAKE_SOURCE_DIR}/tools/opcode2operation-generator.py ${OPERATIONS_DIR} ${CMAKE_SOURCE_DIR}/tools/resources/instructions.yml
COMMAND ${Python_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tools/opcode2operation-generator.py ${OPERATIONS_DIR} ${CMAKE_SOURCE_DIR}/tools/resources/instructions.yml
)

add_library(chai_include INTERFACE)
Expand Down
29 changes: 28 additions & 1 deletion test/ChaiVM/interpreter/garbage-collector-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,31 @@ TEST_F(GarbageCollectorTest, ArrayAllocation) {
update();
exec_.run();
EXPECT_EQ(exec_.acc(), threshold);
}
}

TEST_F(GarbageCollectorTest, ArrayWithObjectsAllocation) {
auto bar_klass = chaiFile_.registerKlass("Bar");
chaiFile_.addField(bar_klass, "bar.num1", 0U, FieldTag::I64);
chaiFile_.addField(bar_klass, "bar.num2", 0U, FieldTag::I64);
chaiFile_.addField(bar_klass, "bar.num3", 0U, FieldTag::I64);
chaiFile_.addField(bar_klass, "bar.num4", 0U, FieldTag::I64);
constexpr int64_t threshold = 30;
Immidiate one_imm = chaiFile_.addConst(std::make_unique<ConstI64>(1));
Immidiate threshold_imm = chaiFile_.addConst(std::make_unique<ConstI64>(threshold));

load<Ldia>(one_imm);
load<Star>(R1);
load<Ldia>(threshold_imm);
load<Star>(R10);
load<NewRefArray>();
load<Star>(R11);
load<AllocRef>(bar_klass);
load<Ldra>(R2);
load<Add>(R1);
load<Star>(R2);
load<If_icmplt>(R10, static_cast<Immidiate>(-4));
load<Ret>();
update();
exec_.run();
EXPECT_EQ(exec_.acc(), threshold);
}
2 changes: 1 addition & 1 deletion tools/opcode2operation-generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

def main() -> int:
if len(sys.argv) != 3:
raise RuntimeError('Should be 2 args, received ' + str(len(sys.argv)))
raise RuntimeError('Should be 3 args, received ' + str(len(sys.argv)))
with open(sys.argv[2]) as file:
full = yaml.safe_load(file)
instructions = full["instructions"]
Expand Down

0 comments on commit a9a1f64

Please sign in to comment.