"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
parent 55571ca3dd
commit f9d62c324d
4 changed files with 55 additions and 11 deletions

View file

@ -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;

View file

@ -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<Statement*> stms;

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