From f9d62c324de2b7c2802225b511b45607111f07f3 Mon Sep 17 00:00:00 2001 From: IlushaShurupov Date: Thu, 3 Aug 2023 21:15:27 +0300 Subject: [PATCH] "Added new test 'Complex' and improved error debugging" This revision adds a complex test to the 'TestInterpreter.cpp' file to test functionalities such as classes, variable initializations, loops, conditionals and methods in the interpreter. The token parser has also been updated with a reset method in the 'parser.cpp' file for cleaning up any previous state before parsing a new script. This ensures the parser starts fresh for each new parse request. It also improves the debugging process in 'function.cpp' by printing the description of parser errors. Few completed tasks are removed from the TODO list. --- Objects/private/compiler/function.cpp | 2 +- Objects/private/parser/parser.cpp | 3 +- Objects/tests/interpreter/TestInterpreter.cpp | 50 ++++++++++++++++++- TODO | 11 ++-- 4 files changed, 55 insertions(+), 11 deletions(-) diff --git a/Objects/private/compiler/function.cpp b/Objects/private/compiler/function.cpp index 7b26b8d..c178136 100644 --- a/Objects/private/compiler/function.cpp +++ b/Objects/private/compiler/function.cpp @@ -544,7 +544,7 @@ bool obj::BCgen::Compile(obj::MethodObject* method) { if (res.err) { // TODO : print parse error auto loc = res.err->get_err_location(script.read()); - printf("Parser Error (%i,%i): \n", loc.head, loc.tail); + printf("Parser Error (%i,%i): %s\n", loc.head, loc.tail, res.err->mDescr.read()); // tp::gLogeer->write(tp::sfmt("Parser Error (%i,%i): \n", loc.head, loc.tail), true, tp::Logger::LogEntry::ERR); // tp::GLog->write(res.err->mDescr, true, tp::Logger::LogEntry::ERR); return false; diff --git a/Objects/private/parser/parser.cpp b/Objects/private/parser/parser.cpp index 255b883..7139dab 100644 --- a/Objects/private/parser/parser.cpp +++ b/Objects/private/parser/parser.cpp @@ -884,7 +884,8 @@ READ_STM: Parser::Resault Parser::parse(const tp::String& oscript) { mTok.bindSource(oscript.read()); - + mTok.reset(); + mRes.scope = new StatementScope({}, true); List stms; diff --git a/Objects/tests/interpreter/TestInterpreter.cpp b/Objects/tests/interpreter/TestInterpreter.cpp index ec2ef8d..9a0c592 100644 --- a/Objects/tests/interpreter/TestInterpreter.cpp +++ b/Objects/tests/interpreter/TestInterpreter.cpp @@ -13,8 +13,55 @@ using namespace tp; using namespace obj; -TEST_DEF_STATIC(Simple) { +auto script1 = R"( +class A { + var string = "hello"; + def log(name) { + << self.string; + << name; + } +} +def main() { + var a = new A(); + a.log(" user "); +} + +main(); + +var i = 10; + +if (i == 10) { + while (i > 0) { + << i; + i = i - 1; + } +} else { + << " no "; +} + +)"; + +auto script = R"( +var i = 10; +)"; + +TEST_DEF_STATIC(Complex) { + auto method = NDO_CAST(MethodObject, NDO->create("method")); + auto interpreter = NDO_CAST(InterpreterObject, NDO->create("interpreter")); + + interpreter->getMember("target method")->setLink(method); + + method->mScript->mReadable->val = script1; + method->compile(); + + interpreter->exec(); + + + NDO->destroy(interpreter); +} + +TEST_DEF_STATIC(Simple) { auto method = NDO_CAST(MethodObject, NDO->create("method")); auto interpreter = NDO_CAST(InterpreterObject, NDO->create("interpreter")); @@ -37,4 +84,5 @@ TEST_DEF_STATIC(Simple) { TEST_DEF(Interpreter) { testSimple(); + //testComplex(); } \ No newline at end of file diff --git a/TODO b/TODO index 47a4ae9..a57da84 100644 --- a/TODO +++ b/TODO @@ -1,20 +1,14 @@ Testing !! Objects: - Testing - Serialization - Alloc Size queries - Compile !! - parser print error write tests before refactor !! + Alloc Size queries remove obj_ref_count macro fix all clang-tidy notices - write archiver replace all strings with const string ref replace all type usages with typedefs remove tp:: rename classes - move functions around Graphics: Window event system @@ -39,6 +33,7 @@ Storage: Utils: Stack trace fixes + Save leaks and then use in debugging to break when the same call occurs? TextEditor: - Implement + Implement \ No newline at end of file