simple gc

This commit is contained in:
2023-12-23 19:42:21 +01:00
parent a9050fc9b9
commit 0ccb7e9b56
8 changed files with 145 additions and 22 deletions

View File

@@ -91,7 +91,6 @@ TEST(VMTest, SimpleFunction) {
}
ssout.flush();
EXPECT_EQ(ssout.str(), "3");
}
TEST(VMTest, RecursiveFunction) {
@@ -171,7 +170,7 @@ TEST(VMTest, RecursiveFunction) {
vm.push(fibcallfn, vm.makeCell<ConsCell>(vm.makeCell<IntCell>(1), vm.makeCell<IntCell>(1)));
vm.push(fibcallfn, vm.makeCell<CommandCell>(CommandCell::CommandNum::LD));
vm.push(fibcallfn, vm.makeCell<CommandCell>(CommandCell::CommandNum::CONS));
vm.push(fibcallfn, vm.makeCell<IntCell>(20));
vm.push(fibcallfn, vm.makeCell<IntCell>(10));
vm.push(fibcallfn, vm.makeCell<CommandCell>(CommandCell::CommandNum::LDC));
vm.push(fibcallfn, vm.makeCell<CommandCell>(CommandCell::CommandNum::NIL));
@@ -236,6 +235,5 @@ TEST(VMTest, RecursiveFunction) {
vm.run();
}
ssout.flush();
EXPECT_EQ(ssout.str(), "2358 6765");
EXPECT_EQ(ssout.str(), "2358 55");
}

View File

@@ -1,7 +1,7 @@
#include <gtest/gtest.h>
#include "VM.h"
#include "Parser.h"
#include "VM.h"
TEST(VMWithParserTest, BasicHello) {
std::stringstream ssin;
@@ -50,9 +50,9 @@ TEST(VMWithParserTest, RecFunction) {
VM vm(ssin, ssout);
Parser parser(vm);
parser.loadSecd(
"( DUM NIL LDF ( LD ( 1 . 1 ) SEL ( LD ( 1 . 1 ) LDC -1 ADD SEL ( NIL LD ( 1 . 1 ) LDC -1 ADD CONS LD ( 2 . 1 ) AP NIL LD ( 1 . 1 ) LDC -2 ADD CONS LD ( 2 . 1 ) AP ADD JOIN ) ( LDC 1 JOIN ) JOIN ) ( LDC 0 JOIN ) RET ) CONS LDF ( NIL LDC 20 CONS LD ( 1 . 1 ) AP RET ) RAP PUTNUM STOP )");
"( DUM NIL LDF ( LD ( 1 . 1 ) SEL ( LD ( 1 . 1 ) LDC -1 ADD SEL ( NIL LD ( 1 . 1 ) LDC -1 ADD CONS LD ( 2 . 1 ) AP NIL LD ( 1 . 1 ) LDC -2 ADD CONS LD ( 2 . 1 ) AP ADD JOIN ) ( LDC 1 JOIN ) JOIN ) ( LDC 0 JOIN ) RET ) CONS LDF ( NIL LDC 10 CONS LD ( 1 . 1 ) AP RET ) RAP PUTNUM STOP )");
vm.run();
}
ssout.flush();
EXPECT_EQ(ssout.str(), "6765");
EXPECT_EQ(ssout.str(), "55");
}