"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.
This commit is contained in:
IlushaShurupov 2023-08-03 21:15:27 +03:00 committed by Ilya Shurupov
parent 3f4f2caf1f
commit f579a969ce
4 changed files with 55 additions and 11 deletions

View file

@ -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<LinkObject>("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();
}