mirror of
https://github.com/usatiuk/psil.git
synced 2025-10-28 10:47:49 +01:00
Fix log tags, change EXPECT_ to ASSERT_ in tests
This commit is contained in:
47
.idea/codeStyles/Project.xml
generated
47
.idea/codeStyles/Project.xml
generated
@@ -1,47 +0,0 @@
|
|||||||
<component name="ProjectCodeStyleConfiguration">
|
|
||||||
<code_scheme name="Project" version="173">
|
|
||||||
<Objective-C-extensions>
|
|
||||||
<rules>
|
|
||||||
<rule entity="NAMESPACE" visibility="ANY" specifier="ANY" prefix="" style="PASCAL_CASE" suffix="" />
|
|
||||||
<rule entity="MACRO" visibility="ANY" specifier="ANY" prefix="" style="SCREAMING_SNAKE_CASE" suffix="" />
|
|
||||||
<rule entity="CLASS" visibility="ANY" specifier="ANY" prefix="" style="PASCAL_CASE" suffix="" />
|
|
||||||
<rule entity="STRUCT" visibility="ANY" specifier="ANY" prefix="" style="PASCAL_CASE" suffix="" />
|
|
||||||
<rule entity="ENUM" visibility="ANY" specifier="ANY" prefix="" style="PASCAL_CASE" suffix="" />
|
|
||||||
<rule entity="ENUMERATOR" visibility="ANY" specifier="ANY" prefix="" style="PASCAL_CASE" suffix="" />
|
|
||||||
<rule entity="TYPEDEF" visibility="ANY" specifier="ANY" prefix="" style="PASCAL_CASE" suffix="" />
|
|
||||||
<rule entity="UNION" visibility="ANY" specifier="ANY" prefix="" style="PASCAL_CASE" suffix="" />
|
|
||||||
<rule entity="CLASS_MEMBER_FUNCTION" visibility="ANY" specifier="ANY" prefix="" style="SNAKE_CASE" suffix="" />
|
|
||||||
<rule entity="STRUCT_MEMBER_FUNCTION" visibility="ANY" specifier="ANY" prefix="" style="SNAKE_CASE" suffix="" />
|
|
||||||
<rule entity="CLASS_MEMBER_FIELD" visibility="ANY" specifier="ANY" prefix="_" style="SNAKE_CASE" suffix="" />
|
|
||||||
<rule entity="STRUCT_MEMBER_FIELD" visibility="ANY" specifier="ANY" prefix="_" style="SNAKE_CASE" suffix="" />
|
|
||||||
<rule entity="GLOBAL_FUNCTION" visibility="ANY" specifier="ANY" prefix="" style="SNAKE_CASE" suffix="" />
|
|
||||||
<rule entity="GLOBAL_VARIABLE" visibility="ANY" specifier="ANY" prefix="" style="SCREAMING_SNAKE_CASE" suffix="" />
|
|
||||||
<rule entity="PARAMETER" visibility="ANY" specifier="ANY" prefix="" style="SNAKE_CASE" suffix="" />
|
|
||||||
<rule entity="LOCAL_VARIABLE" visibility="ANY" specifier="ANY" prefix="" style="SNAKE_CASE" suffix="" />
|
|
||||||
</rules>
|
|
||||||
</Objective-C-extensions>
|
|
||||||
<Objective-C-extensions>
|
|
||||||
<rules>
|
|
||||||
<rule entity="NAMESPACE" visibility="ANY" specifier="ANY" prefix="" style="PASCAL_CASE" suffix="" />
|
|
||||||
<rule entity="MACRO" visibility="ANY" specifier="ANY" prefix="" style="SCREAMING_SNAKE_CASE" suffix="" />
|
|
||||||
<rule entity="CLASS" visibility="ANY" specifier="ANY" prefix="" style="PASCAL_CASE" suffix="" />
|
|
||||||
<rule entity="STRUCT" visibility="ANY" specifier="ANY" prefix="" style="PASCAL_CASE" suffix="" />
|
|
||||||
<rule entity="ENUM" visibility="ANY" specifier="ANY" prefix="" style="PASCAL_CASE" suffix="" />
|
|
||||||
<rule entity="ENUMERATOR" visibility="ANY" specifier="ANY" prefix="" style="PASCAL_CASE" suffix="" />
|
|
||||||
<rule entity="TYPEDEF" visibility="ANY" specifier="ANY" prefix="" style="PASCAL_CASE" suffix="" />
|
|
||||||
<rule entity="UNION" visibility="ANY" specifier="ANY" prefix="" style="PASCAL_CASE" suffix="" />
|
|
||||||
<rule entity="CLASS_MEMBER_FUNCTION" visibility="ANY" specifier="ANY" prefix="" style="SNAKE_CASE" suffix="" />
|
|
||||||
<rule entity="STRUCT_MEMBER_FUNCTION" visibility="ANY" specifier="ANY" prefix="" style="SNAKE_CASE" suffix="" />
|
|
||||||
<rule entity="CLASS_MEMBER_FIELD" visibility="ANY" specifier="ANY" prefix="_" style="SNAKE_CASE" suffix="" />
|
|
||||||
<rule entity="STRUCT_MEMBER_FIELD" visibility="ANY" specifier="ANY" prefix="_" style="SNAKE_CASE" suffix="" />
|
|
||||||
<rule entity="GLOBAL_FUNCTION" visibility="ANY" specifier="ANY" prefix="" style="SNAKE_CASE" suffix="" />
|
|
||||||
<rule entity="GLOBAL_VARIABLE" visibility="ANY" specifier="ANY" prefix="" style="SCREAMING_SNAKE_CASE" suffix="" />
|
|
||||||
<rule entity="PARAMETER" visibility="ANY" specifier="ANY" prefix="" style="SNAKE_CASE" suffix="" />
|
|
||||||
<rule entity="LOCAL_VARIABLE" visibility="ANY" specifier="ANY" prefix="" style="SNAKE_CASE" suffix="" />
|
|
||||||
</rules>
|
|
||||||
</Objective-C-extensions>
|
|
||||||
<clangFormatSettings>
|
|
||||||
<option name="ENABLED" value="true" />
|
|
||||||
</clangFormatSettings>
|
|
||||||
</code_scheme>
|
|
||||||
</component>
|
|
||||||
3
.idea/misc.xml
generated
3
.idea/misc.xml
generated
@@ -1,5 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
|
<component name="CMakePythonSetting">
|
||||||
|
<option name="pythonIntegrationState" value="YES" />
|
||||||
|
</component>
|
||||||
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
|
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
|
||||||
<component name="CidrRootsConfiguration">
|
<component name="CidrRootsConfiguration">
|
||||||
<excludeRoots>
|
<excludeRoots>
|
||||||
|
|||||||
@@ -14,14 +14,17 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
class Logger {
|
class Logger
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
Logger();
|
Logger();
|
||||||
|
|
||||||
enum LogLevel { ALWAYS = 0, ERROR = 1, INFO = 2, DEBUG = 3, TRACE = 4 };
|
enum LogLevel { ALWAYS = 0, ERROR = 1, INFO = 2, DEBUG = 3, TRACE = 4 };
|
||||||
|
|
||||||
enum LogTag { MemoryContext, VM, Compiler, LogTagMax };
|
enum LogTag { MemoryContext, VM, Compiler, LogTagMax };
|
||||||
static void log(LogTag tag, const std::string &what, int level);
|
|
||||||
static void log(LogTag tag, const std::function<void(std::ostream &)> &fn, int level);
|
static void log(LogTag tag, const std::string& what, int level);
|
||||||
|
static void log(LogTag tag, const std::function<void(std::ostream&)>& fn, int level);
|
||||||
|
|
||||||
// 0 - disabled
|
// 0 - disabled
|
||||||
// 1 - error
|
// 1 - error
|
||||||
@@ -32,25 +35,32 @@ public:
|
|||||||
static int get_level(LogTag tag);
|
static int get_level(LogTag tag);
|
||||||
static bool en_level(LogTag tag, int level);
|
static bool en_level(LogTag tag, int level);
|
||||||
|
|
||||||
static void set_out(std::ostream &out);
|
static void set_out(std::ostream& out);
|
||||||
static void set_out_err(std::ostream &out_err);
|
static void set_out_err(std::ostream& out_err);
|
||||||
|
|
||||||
static void reset();
|
static void reset();
|
||||||
|
|
||||||
static Logger &get();
|
static Logger& get();
|
||||||
|
|
||||||
static LogTag str_to_tag(const std::string &str) { return _str_to_tag.at(str); }
|
static LogTag str_to_tag(const std::string& str) { return _str_to_tag.at(str); }
|
||||||
|
static const std::string& tag_to_str(LogTag tag) { return _tag_to_str.at(tag); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::array<LogLevel, LogTag::LogTagMax> _levels{};
|
std::array<LogLevel, LogTag::LogTagMax> _levels{};
|
||||||
static inline std::unordered_map<int, std::string> _level_names{
|
static inline std::unordered_map<int, std::string> _level_names{
|
||||||
{ALWAYS, "ALWAYS"}, {ERROR, "ERROR"}, {INFO, "INFO"}, {DEBUG, "DEBUG"}, {TRACE, "TRACE"},
|
{ALWAYS, "ALWAYS"}, {ERROR, "ERROR"}, {INFO, "INFO"}, {DEBUG, "DEBUG"}, {TRACE, "TRACE"},
|
||||||
};
|
};
|
||||||
static inline std::unordered_map<std::string, LogTag> _str_to_tag{
|
static inline std::unordered_map<std::string, LogTag> _str_to_tag{
|
||||||
{"VM", VM},
|
{"VM", VM},
|
||||||
{"MemoryContext", MemoryContext},
|
{"MemoryContext", MemoryContext},
|
||||||
{"Compiler", Compiler},
|
{"Compiler", Compiler},
|
||||||
};
|
};
|
||||||
|
static inline std::unordered_map<LogTag, std::string> _tag_to_str{
|
||||||
|
{VM, "VM"},
|
||||||
|
{MemoryContext, "MemoryContext"},
|
||||||
|
{Compiler, "Compiler"},
|
||||||
|
};
|
||||||
|
|
||||||
std::chrono::time_point<std::chrono::high_resolution_clock> _start_time = std::chrono::high_resolution_clock::now();
|
std::chrono::time_point<std::chrono::high_resolution_clock> _start_time = std::chrono::high_resolution_clock::now();
|
||||||
std::reference_wrapper<std::ostream> _out = std::cout;
|
std::reference_wrapper<std::ostream> _out = std::cout;
|
||||||
std::reference_wrapper<std::ostream> _out_err = std::cerr;
|
std::reference_wrapper<std::ostream> _out_err = std::cerr;
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#include "Options.h"
|
#include "Options.h"
|
||||||
|
|
||||||
Logger &Logger::get() {
|
Logger &Logger::get() {
|
||||||
static Logger logger;
|
static Logger logger;
|
||||||
return logger;
|
return logger;
|
||||||
@@ -19,15 +20,14 @@ void Logger::log(LogTag tag, const std::string &what, int level) {
|
|||||||
auto now = std::chrono::high_resolution_clock::now();
|
auto now = std::chrono::high_resolution_clock::now();
|
||||||
std::stringstream out;
|
std::stringstream out;
|
||||||
out << std::setprecision(3) << std::fixed << "["
|
out << std::setprecision(3) << std::fixed << "["
|
||||||
<< static_cast<double>(
|
<< static_cast<double>(
|
||||||
std::chrono::duration_cast<std::chrono::milliseconds>(now - get()._start_time).count()) /
|
std::chrono::duration_cast<std::chrono::milliseconds>(now - get()._start_time).count()) /
|
||||||
1000.0
|
1000.0
|
||||||
<< "s]"
|
<< "s]"
|
||||||
<< "[" << tag << "][" << get()._level_names.at(level) << "] " << what << '\n';
|
<< "[" << tag_to_str(tag) << "][" << get()._level_names.at(level) << "] " << what << '\n';
|
||||||
|
|
||||||
if (level == 1) get()._out_err.get() << out.str();
|
if (level == 1) get()._out_err.get() << out.str();
|
||||||
else
|
else get()._out.get() << out.str();
|
||||||
get()._out.get() << out.str();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,4 +52,4 @@ bool Logger::en_level(LogTag tag, int level) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger::Logger() { _levels.fill(static_cast<LogLevel>(Options::get<size_t>("default_log_level"))); }
|
Logger::Logger() { _levels.fill(static_cast<LogLevel>(Options::get<size_t>("default_log_level"))); }
|
||||||
@@ -39,7 +39,7 @@ TEST(CompilerTest, BasicHello) {
|
|||||||
vm.run();
|
vm.run();
|
||||||
}
|
}
|
||||||
ssout.flush();
|
ssout.flush();
|
||||||
EXPECT_EQ(ssout.str(), "3\n");
|
ASSERT_EQ(ssout.str(), "3\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(CompilerTest, BasicLet) {
|
TEST(CompilerTest, BasicLet) {
|
||||||
@@ -54,7 +54,7 @@ TEST(CompilerTest, BasicLet) {
|
|||||||
vm.run();
|
vm.run();
|
||||||
}
|
}
|
||||||
ssout.flush();
|
ssout.flush();
|
||||||
EXPECT_EQ(ssout.str(), "1\n");
|
ASSERT_EQ(ssout.str(), "1\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(CompilerTest, BasicFn) {
|
TEST(CompilerTest, BasicFn) {
|
||||||
@@ -69,7 +69,7 @@ TEST(CompilerTest, BasicFn) {
|
|||||||
vm.run();
|
vm.run();
|
||||||
}
|
}
|
||||||
ssout.flush();
|
ssout.flush();
|
||||||
EXPECT_EQ(ssout.str(), "5\n");
|
ASSERT_EQ(ssout.str(), "5\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(CompilerTest, BasicFn2) {
|
TEST(CompilerTest, BasicFn2) {
|
||||||
@@ -84,7 +84,7 @@ TEST(CompilerTest, BasicFn2) {
|
|||||||
vm.run();
|
vm.run();
|
||||||
}
|
}
|
||||||
ssout.flush();
|
ssout.flush();
|
||||||
EXPECT_EQ(ssout.str(), "-1\n");
|
ASSERT_EQ(ssout.str(), "-1\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(CompilerTest, MultiLet) {
|
TEST(CompilerTest, MultiLet) {
|
||||||
@@ -95,7 +95,7 @@ TEST(CompilerTest, MultiLet) {
|
|||||||
VM vm(ssin, ssout);
|
VM vm(ssin, ssout);
|
||||||
Parser parser;
|
Parser parser;
|
||||||
parser.loadStr("(LDC (let ((plfn (lambda (a b) (- a b))) (plfn2 (lambda (a b) (- b a)))) (plfn 2 3)) EVAL "
|
parser.loadStr("(LDC (let ((plfn (lambda (a b) (- a b))) (plfn2 (lambda (a b) (- b a)))) (plfn 2 3)) EVAL "
|
||||||
"PRINT STOP)");
|
"PRINT STOP)");
|
||||||
vm.loadControl(parser.parseExpr());
|
vm.loadControl(parser.parseExpr());
|
||||||
vm.run();
|
vm.run();
|
||||||
}
|
}
|
||||||
@@ -104,12 +104,12 @@ TEST(CompilerTest, MultiLet) {
|
|||||||
VM vm(ssin, ssout);
|
VM vm(ssin, ssout);
|
||||||
Parser parser;
|
Parser parser;
|
||||||
parser.loadStr("(LDC (let ((plfn (lambda (a b) (- a b))) (plfn2 (lambda (a b) (- b a)))) (plfn2 2 3)) EVAL "
|
parser.loadStr("(LDC (let ((plfn (lambda (a b) (- a b))) (plfn2 (lambda (a b) (- b a)))) (plfn2 2 3)) EVAL "
|
||||||
"PRINT STOP)");
|
"PRINT STOP)");
|
||||||
vm.loadControl(parser.parseExpr());
|
vm.loadControl(parser.parseExpr());
|
||||||
vm.run();
|
vm.run();
|
||||||
}
|
}
|
||||||
ssout.flush();
|
ssout.flush();
|
||||||
EXPECT_EQ(ssout.str(), "-1\n1\n");
|
ASSERT_EQ(ssout.str(), "-1\n1\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -125,8 +125,9 @@ TEST(CompilerTest, BasicFnIfT) {
|
|||||||
vm.run();
|
vm.run();
|
||||||
}
|
}
|
||||||
ssout.flush();
|
ssout.flush();
|
||||||
EXPECT_EQ(ssout.str(), "1\n");
|
ASSERT_EQ(ssout.str(), "1\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(CompilerTest, BasicFnIfF) {
|
TEST(CompilerTest, BasicFnIfF) {
|
||||||
std::stringstream ssin;
|
std::stringstream ssin;
|
||||||
std::stringstream ssout;
|
std::stringstream ssout;
|
||||||
@@ -139,8 +140,9 @@ TEST(CompilerTest, BasicFnIfF) {
|
|||||||
vm.run();
|
vm.run();
|
||||||
}
|
}
|
||||||
ssout.flush();
|
ssout.flush();
|
||||||
EXPECT_EQ(ssout.str(), "2\n");
|
ASSERT_EQ(ssout.str(), "2\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(CompilerTest, RecursiveFn) {
|
TEST(CompilerTest, RecursiveFn) {
|
||||||
std::stringstream ssin;
|
std::stringstream ssin;
|
||||||
std::stringstream ssout;
|
std::stringstream ssout;
|
||||||
@@ -149,12 +151,12 @@ TEST(CompilerTest, RecursiveFn) {
|
|||||||
VM vm(ssin, ssout);
|
VM vm(ssin, ssout);
|
||||||
Parser parser;
|
Parser parser;
|
||||||
parser.loadStr("(LDC (letrec ((fib (lambda (n) (if n (if (+ n -1) (+ (fib (+ n -1)) (fib(+ n -2))) 1) 0) ))) "
|
parser.loadStr("(LDC (letrec ((fib (lambda (n) (if n (if (+ n -1) (+ (fib (+ n -1)) (fib(+ n -2))) 1) 0) ))) "
|
||||||
"(fib 10)) EVAL PRINT STOP)");
|
"(fib 10)) EVAL PRINT STOP)");
|
||||||
vm.loadControl(parser.parseExpr());
|
vm.loadControl(parser.parseExpr());
|
||||||
vm.run();
|
vm.run();
|
||||||
}
|
}
|
||||||
ssout.flush();
|
ssout.flush();
|
||||||
EXPECT_EQ(ssout.str(), "55\n");
|
ASSERT_EQ(ssout.str(), "55\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(CompilerTest, GlobalDefine) {
|
TEST(CompilerTest, GlobalDefine) {
|
||||||
@@ -169,7 +171,7 @@ TEST(CompilerTest, GlobalDefine) {
|
|||||||
vm.run();
|
vm.run();
|
||||||
}
|
}
|
||||||
ssout.flush();
|
ssout.flush();
|
||||||
EXPECT_EQ(ssout.str(), "1\n");
|
ASSERT_EQ(ssout.str(), "1\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -185,7 +187,7 @@ TEST(CompilerTest, GlobalDefineFn) {
|
|||||||
vm.run();
|
vm.run();
|
||||||
}
|
}
|
||||||
ssout.flush();
|
ssout.flush();
|
||||||
EXPECT_EQ(ssout.str(), "5\n");
|
ASSERT_EQ(ssout.str(), "5\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(CompilerTest, GlobalDefineFnQuote) {
|
TEST(CompilerTest, GlobalDefineFnQuote) {
|
||||||
@@ -200,7 +202,7 @@ TEST(CompilerTest, GlobalDefineFnQuote) {
|
|||||||
vm.run();
|
vm.run();
|
||||||
}
|
}
|
||||||
ssout.flush();
|
ssout.flush();
|
||||||
EXPECT_EQ(ssout.str(), "(1 2)\n");
|
ASSERT_EQ(ssout.str(), "(1 2)\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(CompilerTest, GlobalDefineFnCar) {
|
TEST(CompilerTest, GlobalDefineFnCar) {
|
||||||
@@ -211,12 +213,12 @@ TEST(CompilerTest, GlobalDefineFnCar) {
|
|||||||
VM vm(ssin, ssout);
|
VM vm(ssin, ssout);
|
||||||
Parser parser;
|
Parser parser;
|
||||||
parser.loadStr("(LDC (define (carr l) (car l)) EVAL LDC (carr (quote (1 2))) EVAL PRINT LDC (carr (cdr (quote "
|
parser.loadStr("(LDC (define (carr l) (car l)) EVAL LDC (carr (quote (1 2))) EVAL PRINT LDC (carr (cdr (quote "
|
||||||
"(1 2)))) EVAL PRINT STOP)");
|
"(1 2)))) EVAL PRINT STOP)");
|
||||||
vm.loadControl(parser.parseExpr());
|
vm.loadControl(parser.parseExpr());
|
||||||
vm.run();
|
vm.run();
|
||||||
}
|
}
|
||||||
ssout.flush();
|
ssout.flush();
|
||||||
EXPECT_EQ(ssout.str(), "1\n2\n");
|
ASSERT_EQ(ssout.str(), "1\n2\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(CompilerTest, GlobalDefineFnEq) {
|
TEST(CompilerTest, GlobalDefineFnEq) {
|
||||||
@@ -227,7 +229,7 @@ TEST(CompilerTest, GlobalDefineFnEq) {
|
|||||||
VM vm(ssin, ssout);
|
VM vm(ssin, ssout);
|
||||||
Parser parser;
|
Parser parser;
|
||||||
parser.loadStr("(LDC (define (eqtest l) (= l ())) EVAL LDC (eqtest (quote ())) EVAL PRINT LDC (eqtest (nil)) "
|
parser.loadStr("(LDC (define (eqtest l) (= l ())) EVAL LDC (eqtest (quote ())) EVAL PRINT LDC (eqtest (nil)) "
|
||||||
"EVAL PRINT STOP)");
|
"EVAL PRINT STOP)");
|
||||||
vm.loadControl(parser.parseExpr());
|
vm.loadControl(parser.parseExpr());
|
||||||
vm.run();
|
vm.run();
|
||||||
}
|
}
|
||||||
@@ -236,12 +238,12 @@ TEST(CompilerTest, GlobalDefineFnEq) {
|
|||||||
VM vm(ssin, ssout);
|
VM vm(ssin, ssout);
|
||||||
Parser parser;
|
Parser parser;
|
||||||
parser.loadStr("(LDC (define (eqtest l) (= l (nil))) EVAL LDC (eqtest (quote ())) EVAL PRINT LDC (eqtest "
|
parser.loadStr("(LDC (define (eqtest l) (= l (nil))) EVAL LDC (eqtest (quote ())) EVAL PRINT LDC (eqtest "
|
||||||
"(nil)) EVAL PRINT STOP)");
|
"(nil)) EVAL PRINT STOP)");
|
||||||
vm.loadControl(parser.parseExpr());
|
vm.loadControl(parser.parseExpr());
|
||||||
vm.run();
|
vm.run();
|
||||||
}
|
}
|
||||||
ssout.flush();
|
ssout.flush();
|
||||||
EXPECT_EQ(ssout.str(), "1\n1\n1\n1\n");
|
ASSERT_EQ(ssout.str(), "1\n1\n1\n1\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(CompilerTest, GlobalDefineFnMulti) {
|
TEST(CompilerTest, GlobalDefineFnMulti) {
|
||||||
@@ -252,12 +254,12 @@ TEST(CompilerTest, GlobalDefineFnMulti) {
|
|||||||
VM vm(ssin, ssout);
|
VM vm(ssin, ssout);
|
||||||
Parser parser;
|
Parser parser;
|
||||||
parser.loadStr("(LDC (define (one x y) (+ x y)) EVAL LDC (define (two x y) (one (+ x 1) y)) EVAL LDC (two 2 3) "
|
parser.loadStr("(LDC (define (one x y) (+ x y)) EVAL LDC (define (two x y) (one (+ x 1) y)) EVAL LDC (two 2 3) "
|
||||||
"EVAL PRINT STOP)");
|
"EVAL PRINT STOP)");
|
||||||
vm.loadControl(parser.parseExpr());
|
vm.loadControl(parser.parseExpr());
|
||||||
vm.run();
|
vm.run();
|
||||||
}
|
}
|
||||||
ssout.flush();
|
ssout.flush();
|
||||||
EXPECT_EQ(ssout.str(), "6\n");
|
ASSERT_EQ(ssout.str(), "6\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(CompilerTest, GlobalDefineFnMultiTwo) {
|
TEST(CompilerTest, GlobalDefineFnMultiTwo) {
|
||||||
@@ -268,12 +270,12 @@ TEST(CompilerTest, GlobalDefineFnMultiTwo) {
|
|||||||
VM vm(ssin, ssout);
|
VM vm(ssin, ssout);
|
||||||
Parser parser;
|
Parser parser;
|
||||||
parser.loadStr("(LDC (define (one x y) (- x y)) EVAL LDC (define (two x y) (one (+ x 1) y)) EVAL LDC (two 2 3) "
|
parser.loadStr("(LDC (define (one x y) (- x y)) EVAL LDC (define (two x y) (one (+ x 1) y)) EVAL LDC (two 2 3) "
|
||||||
"EVAL PRINT STOP)");
|
"EVAL PRINT STOP)");
|
||||||
vm.loadControl(parser.parseExpr());
|
vm.loadControl(parser.parseExpr());
|
||||||
vm.run();
|
vm.run();
|
||||||
}
|
}
|
||||||
ssout.flush();
|
ssout.flush();
|
||||||
EXPECT_EQ(ssout.str(), "0\n");
|
ASSERT_EQ(ssout.str(), "0\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -286,12 +288,12 @@ TEST(CompilerTest, GlobalDefineFnRec) {
|
|||||||
VM vm(ssin, ssout);
|
VM vm(ssin, ssout);
|
||||||
Parser parser;
|
Parser parser;
|
||||||
parser.loadStr("(LDC (define (fib n) (if n (if (+ n -1) (+ (fib (+ n -1)) (fib(+ n -2))) 1) 0) ) EVAL LDC (fib "
|
parser.loadStr("(LDC (define (fib n) (if n (if (+ n -1) (+ (fib (+ n -1)) (fib(+ n -2))) 1) 0) ) EVAL LDC (fib "
|
||||||
"20) EVAL PRINT STOP)");
|
"20) EVAL PRINT STOP)");
|
||||||
vm.loadControl(parser.parseExpr());
|
vm.loadControl(parser.parseExpr());
|
||||||
vm.run();
|
vm.run();
|
||||||
}
|
}
|
||||||
Options::set<bool>("command_strs", true);
|
Options::set<bool>("command_strs", true);
|
||||||
Logger::set_level(Logger::VM, Logger::DEBUG);
|
Logger::set_level(Logger::VM, Logger::DEBUG);
|
||||||
ssout.flush();
|
ssout.flush();
|
||||||
EXPECT_EQ(ssout.str(), "6765\n");
|
ASSERT_EQ(ssout.str(), "6765\n");
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,7 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
#include "MemoryContext.h"
|
#include "MemoryContext.h"
|
||||||
|
|
||||||
class Environment : public ::testing::Environment {
|
class Environment : public ::testing::Environment {
|
||||||
public:
|
public:
|
||||||
~Environment() override {}
|
~Environment() override {}
|
||||||
@@ -30,26 +31,26 @@ TEST(GCTest, GCTest) {
|
|||||||
c.append(Handle::makeNumCell(1));
|
c.append(Handle::makeNumCell(1));
|
||||||
c.append(Handle::makeNumCell(2));
|
c.append(Handle::makeNumCell(2));
|
||||||
MemoryContext::get().request_gc_and_wait();
|
MemoryContext::get().request_gc_and_wait();
|
||||||
EXPECT_EQ(c.car().val(), 1);
|
ASSERT_EQ(c.car().val(), 1);
|
||||||
EXPECT_EQ(c.cdr().car().val(), 2);
|
ASSERT_EQ(c.cdr().car().val(), 2);
|
||||||
}
|
}
|
||||||
MemoryContext::get().request_gc_and_wait();
|
MemoryContext::get().request_gc_and_wait();
|
||||||
MemoryContext::get().request_gc_and_wait();
|
MemoryContext::get().request_gc_and_wait();
|
||||||
MemoryContext::get().request_gc_and_wait();
|
MemoryContext::get().request_gc_and_wait();
|
||||||
EXPECT_EQ(MemoryContext::get().cell_count(), 0);
|
ASSERT_EQ(MemoryContext::get().cell_count(), 0);
|
||||||
{
|
{
|
||||||
Handle c = Handle::cons(nullptr, nullptr);
|
Handle c = Handle::cons(nullptr, nullptr);
|
||||||
MemoryContext::get().request_gc_and_wait();
|
MemoryContext::get().request_gc_and_wait();
|
||||||
c.push(Handle::makeNumCell(1));
|
c.push(Handle::makeNumCell(1));
|
||||||
c.push(Handle::makeNumCell(2));
|
c.push(Handle::makeNumCell(2));
|
||||||
MemoryContext::get().request_gc_and_wait();
|
MemoryContext::get().request_gc_and_wait();
|
||||||
EXPECT_EQ(c.car().val(), 2);
|
ASSERT_EQ(c.car().val(), 2);
|
||||||
EXPECT_EQ(c.cdr().car().val(), 1);
|
ASSERT_EQ(c.cdr().car().val(), 1);
|
||||||
}
|
}
|
||||||
MemoryContext::get().request_gc_and_wait();
|
MemoryContext::get().request_gc_and_wait();
|
||||||
MemoryContext::get().request_gc_and_wait();
|
MemoryContext::get().request_gc_and_wait();
|
||||||
MemoryContext::get().request_gc_and_wait();
|
MemoryContext::get().request_gc_and_wait();
|
||||||
EXPECT_EQ(MemoryContext::get().cell_count(), 0);
|
ASSERT_EQ(MemoryContext::get().cell_count(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(GCTest, GCTestAppend) {
|
TEST(GCTest, GCTestAppend) {
|
||||||
@@ -59,13 +60,14 @@ TEST(GCTest, GCTestAppend) {
|
|||||||
MemoryContext::get().request_gc();
|
MemoryContext::get().request_gc();
|
||||||
c.append(Handle::makeNumCell(1));
|
c.append(Handle::makeNumCell(1));
|
||||||
MemoryContext::get().request_gc();
|
MemoryContext::get().request_gc();
|
||||||
EXPECT_EQ(c.car().val(), 1);
|
ASSERT_EQ(c.car().val(), 1);
|
||||||
}
|
}
|
||||||
MemoryContext::get().request_gc_and_wait();
|
MemoryContext::get().request_gc_and_wait();
|
||||||
MemoryContext::get().request_gc_and_wait();
|
MemoryContext::get().request_gc_and_wait();
|
||||||
MemoryContext::get().request_gc_and_wait();
|
MemoryContext::get().request_gc_and_wait();
|
||||||
EXPECT_EQ(MemoryContext::get().cell_count(), 0);
|
ASSERT_EQ(MemoryContext::get().cell_count(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(GCTest, GCTestPop) {
|
TEST(GCTest, GCTestPop) {
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -77,13 +79,13 @@ TEST(GCTest, GCTestPop) {
|
|||||||
}
|
}
|
||||||
for (int i = test_size - 1; i >= 0; i--) {
|
for (int i = test_size - 1; i >= 0; i--) {
|
||||||
MemoryContext::get().request_gc();
|
MemoryContext::get().request_gc();
|
||||||
EXPECT_EQ(i, c.pop().val());
|
ASSERT_EQ(i, c.pop().val());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MemoryContext::get().request_gc_and_wait();
|
MemoryContext::get().request_gc_and_wait();
|
||||||
MemoryContext::get().request_gc_and_wait();
|
MemoryContext::get().request_gc_and_wait();
|
||||||
MemoryContext::get().request_gc_and_wait();
|
MemoryContext::get().request_gc_and_wait();
|
||||||
EXPECT_EQ(MemoryContext::get().cell_count(), 0);
|
ASSERT_EQ(MemoryContext::get().cell_count(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(GCTest, GCTestAppend2) {
|
TEST(GCTest, GCTestAppend2) {
|
||||||
@@ -96,12 +98,12 @@ TEST(GCTest, GCTestAppend2) {
|
|||||||
}
|
}
|
||||||
for (int i = 0; i < test_size; i++) {
|
for (int i = 0; i < test_size; i++) {
|
||||||
MemoryContext::get().request_gc();
|
MemoryContext::get().request_gc();
|
||||||
EXPECT_EQ(i, c.pop().val());
|
ASSERT_EQ(i, c.pop().val());
|
||||||
}
|
}
|
||||||
MemoryContext::get().request_gc_and_wait();
|
MemoryContext::get().request_gc_and_wait();
|
||||||
MemoryContext::get().request_gc_and_wait();
|
MemoryContext::get().request_gc_and_wait();
|
||||||
MemoryContext::get().request_gc_and_wait();
|
MemoryContext::get().request_gc_and_wait();
|
||||||
EXPECT_EQ(MemoryContext::get().cell_count(), 0);
|
ASSERT_EQ(MemoryContext::get().cell_count(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(GCTest, GCTestAppend3) {
|
TEST(GCTest, GCTestAppend3) {
|
||||||
@@ -114,11 +116,11 @@ TEST(GCTest, GCTestAppend3) {
|
|||||||
MemoryContext::get().request_gc();
|
MemoryContext::get().request_gc();
|
||||||
Handle n = c.cdr();
|
Handle n = c.cdr();
|
||||||
c.setcdr(nullptr);
|
c.setcdr(nullptr);
|
||||||
EXPECT_EQ(n.car().val(), 2);
|
ASSERT_EQ(n.car().val(), 2);
|
||||||
EXPECT_EQ(c.car().val(), 1);
|
ASSERT_EQ(c.car().val(), 1);
|
||||||
}
|
}
|
||||||
MemoryContext::get().request_gc_and_wait();
|
MemoryContext::get().request_gc_and_wait();
|
||||||
MemoryContext::get().request_gc_and_wait();
|
MemoryContext::get().request_gc_and_wait();
|
||||||
MemoryContext::get().request_gc_and_wait();
|
MemoryContext::get().request_gc_and_wait();
|
||||||
EXPECT_EQ(MemoryContext::get().cell_count(), 0);
|
ASSERT_EQ(MemoryContext::get().cell_count(), 0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include "Command.h"
|
#include "Command.h"
|
||||||
#include "VM.h"
|
#include "VM.h"
|
||||||
|
|
||||||
class Environment : public ::testing::Environment {
|
class Environment : public ::testing::Environment {
|
||||||
public:
|
public:
|
||||||
~Environment() override {}
|
~Environment() override {}
|
||||||
@@ -36,7 +37,7 @@ TEST(VMTest, BasicHello) {
|
|||||||
vm.run();
|
vm.run();
|
||||||
}
|
}
|
||||||
ssout.flush();
|
ssout.flush();
|
||||||
EXPECT_EQ(ssout.str(), "h");
|
ASSERT_EQ(ssout.str(), "h");
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: maybe rewrite it all...
|
//TODO: maybe rewrite it all...
|
||||||
@@ -84,7 +85,7 @@ TEST(VMTest, BasicHello) {
|
|||||||
// vm.run();
|
// vm.run();
|
||||||
// }
|
// }
|
||||||
// ssout.flush();
|
// ssout.flush();
|
||||||
// EXPECT_EQ(ssout.str(), "14");
|
// ASSERT_EQ(ssout.str(), "14");
|
||||||
//}
|
//}
|
||||||
//
|
//
|
||||||
//TEST(VMTest, SimpleFunction) {
|
//TEST(VMTest, SimpleFunction) {
|
||||||
@@ -112,7 +113,7 @@ TEST(VMTest, BasicHello) {
|
|||||||
// vm.run();
|
// vm.run();
|
||||||
// }
|
// }
|
||||||
// ssout.flush();
|
// ssout.flush();
|
||||||
// EXPECT_EQ(ssout.str(), "3");
|
// ASSERT_EQ(ssout.str(), "3");
|
||||||
//}
|
//}
|
||||||
//
|
//
|
||||||
//TEST(VMTest, RecursiveFunction) {
|
//TEST(VMTest, RecursiveFunction) {
|
||||||
@@ -257,5 +258,5 @@ TEST(VMTest, BasicHello) {
|
|||||||
//vm.run();
|
//vm.run();
|
||||||
//}
|
//}
|
||||||
//ssout.flush();
|
//ssout.flush();
|
||||||
//EXPECT_EQ(ssout.str(), "2358 55");
|
//ASSERT_EQ(ssout.str(), "2358 55");
|
||||||
//}
|
//}
|
||||||
@@ -33,7 +33,7 @@ TEST(VMWithParserTest, BasicHello) {
|
|||||||
vm.run();
|
vm.run();
|
||||||
}
|
}
|
||||||
ssout.flush();
|
ssout.flush();
|
||||||
EXPECT_EQ(ssout.str(), "h");
|
ASSERT_EQ(ssout.str(), "h");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(VMWithParserTest, BasicBranch) {
|
TEST(VMWithParserTest, BasicBranch) {
|
||||||
@@ -44,12 +44,12 @@ TEST(VMWithParserTest, BasicBranch) {
|
|||||||
VM vm(ssin, ssout);
|
VM vm(ssin, ssout);
|
||||||
Parser parser;
|
Parser parser;
|
||||||
parser.loadStr("(LDC 1 SEL (LDC 10 PUTNUM JOIN) (LDC 20 PUTNUM JOIN) LDC 0 SEL (LDC 30 PUTNUM JOIN) (LDC 40 "
|
parser.loadStr("(LDC 1 SEL (LDC 10 PUTNUM JOIN) (LDC 20 PUTNUM JOIN) LDC 0 SEL (LDC 30 PUTNUM JOIN) (LDC 40 "
|
||||||
"PUTNUM JOIN) STOP)");
|
"PUTNUM JOIN) STOP)");
|
||||||
vm.loadControl(parser.parseExpr());
|
vm.loadControl(parser.parseExpr());
|
||||||
vm.run();
|
vm.run();
|
||||||
}
|
}
|
||||||
ssout.flush();
|
ssout.flush();
|
||||||
EXPECT_EQ(ssout.str(), "1040");
|
ASSERT_EQ(ssout.str(), "1040");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(VMWithParserTest, BasicFunction) {
|
TEST(VMWithParserTest, BasicFunction) {
|
||||||
@@ -64,7 +64,7 @@ TEST(VMWithParserTest, BasicFunction) {
|
|||||||
vm.run();
|
vm.run();
|
||||||
}
|
}
|
||||||
ssout.flush();
|
ssout.flush();
|
||||||
EXPECT_EQ(ssout.str(), "3");
|
ASSERT_EQ(ssout.str(), "3");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(VMWithParserTest, RecFunction) {
|
TEST(VMWithParserTest, RecFunction) {
|
||||||
@@ -75,17 +75,17 @@ TEST(VMWithParserTest, RecFunction) {
|
|||||||
VM vm(ssin, ssout);
|
VM vm(ssin, ssout);
|
||||||
Parser parser;
|
Parser parser;
|
||||||
parser.loadStr("( DUM NIL LDF ( LD ( 1 . 1 ) SEL ( LD ( 1 . 1 ) LDC -1 ADD SEL ( NIL LD ( 1 . 1 ) LDC -1 ADD "
|
parser.loadStr("( 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 "
|
"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 "
|
"NIL LD ( 1 . 1 ) LDC -2 ADD CONS LD ( 2 . 1 ) AP ADD JOIN ) ( LDC 1 JOIN ) JOIN ) ( LDC 0 JOIN "
|
||||||
") RET ) CONS LDF ( "
|
") RET ) CONS LDF ( "
|
||||||
"NIL LDC 20 CONS LD ( 1 . 1 ) AP RET ) RAP PUTNUM STOP )");
|
"NIL LDC 20 CONS LD ( 1 . 1 ) AP RET ) RAP PUTNUM STOP )");
|
||||||
vm.loadControl(parser.parseExpr());
|
vm.loadControl(parser.parseExpr());
|
||||||
vm.run();
|
vm.run();
|
||||||
}
|
}
|
||||||
MemoryContext::get().request_gc_and_wait();
|
MemoryContext::get().request_gc_and_wait();
|
||||||
MemoryContext::get().request_gc_and_wait();
|
MemoryContext::get().request_gc_and_wait();
|
||||||
MemoryContext::get().request_gc_and_wait();
|
MemoryContext::get().request_gc_and_wait();
|
||||||
EXPECT_EQ(MemoryContext::get().cell_count(), 0);
|
ASSERT_EQ(MemoryContext::get().cell_count(), 0);
|
||||||
ssout.flush();
|
ssout.flush();
|
||||||
EXPECT_EQ(ssout.str(), "6765");
|
ASSERT_EQ(ssout.str(), "6765");
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user