"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:
parent
3f4f2caf1f
commit
f579a969ce
4 changed files with 55 additions and 11 deletions
|
|
@ -544,7 +544,7 @@ bool obj::BCgen::Compile(obj::MethodObject* method) {
|
||||||
if (res.err) {
|
if (res.err) {
|
||||||
// TODO : print parse error
|
// TODO : print parse error
|
||||||
auto loc = res.err->get_err_location(script.read());
|
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::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);
|
// tp::GLog->write(res.err->mDescr, true, tp::Logger::LogEntry::ERR);
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -884,6 +884,7 @@ READ_STM:
|
||||||
|
|
||||||
Parser::Resault Parser::parse(const tp::String& oscript) {
|
Parser::Resault Parser::parse(const tp::String& oscript) {
|
||||||
mTok.bindSource(oscript.read());
|
mTok.bindSource(oscript.read());
|
||||||
|
mTok.reset();
|
||||||
|
|
||||||
mRes.scope = new StatementScope({}, true);
|
mRes.scope = new StatementScope({}, true);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,55 @@
|
||||||
using namespace tp;
|
using namespace tp;
|
||||||
using namespace obj;
|
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 method = NDO_CAST(MethodObject, NDO->create("method"));
|
||||||
auto interpreter = NDO_CAST(InterpreterObject, NDO->create("interpreter"));
|
auto interpreter = NDO_CAST(InterpreterObject, NDO->create("interpreter"));
|
||||||
|
|
||||||
|
|
@ -37,4 +84,5 @@ TEST_DEF_STATIC(Simple) {
|
||||||
|
|
||||||
TEST_DEF(Interpreter) {
|
TEST_DEF(Interpreter) {
|
||||||
testSimple();
|
testSimple();
|
||||||
|
//testComplex();
|
||||||
}
|
}
|
||||||
9
TODO
9
TODO
|
|
@ -1,20 +1,14 @@
|
||||||
Testing !!
|
Testing !!
|
||||||
|
|
||||||
Objects:
|
Objects:
|
||||||
Testing
|
|
||||||
Serialization
|
|
||||||
Alloc Size queries
|
|
||||||
Compile !!
|
|
||||||
parser print error
|
|
||||||
write tests before refactor !!
|
write tests before refactor !!
|
||||||
|
Alloc Size queries
|
||||||
remove obj_ref_count macro
|
remove obj_ref_count macro
|
||||||
fix all clang-tidy notices
|
fix all clang-tidy notices
|
||||||
write archiver
|
|
||||||
replace all strings with const string ref
|
replace all strings with const string ref
|
||||||
replace all type usages with typedefs
|
replace all type usages with typedefs
|
||||||
remove tp::
|
remove tp::
|
||||||
rename classes
|
rename classes
|
||||||
move functions around
|
|
||||||
|
|
||||||
Graphics:
|
Graphics:
|
||||||
Window event system
|
Window event system
|
||||||
|
|
@ -39,6 +33,7 @@ Storage:
|
||||||
|
|
||||||
Utils:
|
Utils:
|
||||||
Stack trace fixes
|
Stack trace fixes
|
||||||
|
Save leaks and then use in debugging to break when the same call occurs?
|
||||||
|
|
||||||
TextEditor:
|
TextEditor:
|
||||||
Implement
|
Implement
|
||||||
Loading…
Add table
Add a link
Reference in a new issue