Properly move NbRuntime to its own thread
diff --git a/main.cpp b/main.cpp
index 0cb36e8..278f1d0 100644
--- a/main.cpp
+++ b/main.cpp
@@ -22,35 +22,35 @@
void testEval(QString function, QString expression, QString expected)
{
- Evaluator eval;
- Parser funcParser(function),
- exprParser(expression),
- resParser(expected);
+ Evaluator eval;
+ Parser funcParser(function),
+ exprParser(expression),
+ resParser(expected);
- Function func;
+ Function func;
- QList<AstNode> expr;
- ParseResult exprRet = exprParser.parseMany<AstNode>(&expr);
- QList<Token> res;
- ParseResult resRet = resParser.parseMany<Token>(&res);
- ParseResult funcRet;
+ QList<AstNode> expr;
+ ParseResult exprRet = exprParser.parseMany<AstNode>(&expr);
+ QList<Token> res;
+ ParseResult resRet = resParser.parseMany<Token>(&res);
+ ParseResult funcRet;
- QList<Token> result;
+ QList<Token> result;
- exprParser.skip();
- resParser.skip();
- while ((funcRet = funcParser.parseFunctionDefinition(&func)))
- {
- eval.addFunction(func);
- }
+ exprParser.skip();
+ resParser.skip();
+ while ((funcRet = funcParser.parseFunctionDefinition(&func)))
+ {
+ eval.addFunction(func);
+ }
- funcParser.skip();
+ funcParser.skip();
- if (!exprRet || !resRet || funcRet.status() == ParseResult::INCOMPLETE)
- {
+ if (!exprRet || !resRet || funcRet.status() == ParseResult::INCOMPLETE)
+ {
g_numFailed++;
qDebug() << "\n\033[31mTEST FAILS:\033[0m";
- qDebug() << "Failed to fully parse expression, function or result";
+ qDebug() << "Failed to fully parse expression, function or result";
qDebug() << "Function:";
sout(pprint(funcRet, funcParser));
@@ -60,33 +60,33 @@
qDebug() << "Result:";
sout(pprint(resRet, resParser));
- goto end;
- }
+ goto end;
+ }
- for (const AstNode &node : expr)
- {
- RuntimeResult rr = eval.evaluate(node, VarContext());
+ for (const AstNode &node : expr)
+ {
+ RuntimeResult rr = eval.evaluate(node, VarContext());
- if (!rr.success())
- {
- g_numFailed++;
- qDebug() << "\n\033[31mTEST FAILS:\033[0m";
- qDebug() << "Runtime error while evaluating" << node;
- qDebug() << rr;
+ if (!rr.success())
+ {
+ g_numFailed++;
+ qDebug() << "\n\033[31mTEST FAILS:\033[0m";
+ qDebug() << "Runtime error while evaluating" << node;
+ qDebug() << rr;
- goto end;
- }
+ goto end;
+ }
- result.append(rr.result());
- }
+ result.append(rr.result());
+ }
- if (result != res)
- {
- g_numFailed++;
- qDebug() << "\n\033[31mTEST FAILS:\033[0m";
- qDebug() << "Expected result" << res;
- qDebug() << "Got" << result;
- }
+ if (result != res)
+ {
+ g_numFailed++;
+ qDebug() << "\n\033[31mTEST FAILS:\033[0m";
+ qDebug() << "Expected result" << res;
+ qDebug() << "Got" << result;
+ }
end:
qDebug() << "\033[36mEvaluate\033[0m" << function << expression << "->" << pprint(result);
@@ -94,7 +94,7 @@
void testEval(QString function, QString expression, QList<Token> expected)
{
- testEval(function, expression, pprint(expected));
+ testEval(function, expression, pprint(expected));
}
void testEval(QString expression, QString expected)
@@ -124,13 +124,13 @@
Parser dataParser(data),
patternParser(pattern);
- QList<Token> parsedData, parsedPattern;
-
- dataParser.parseMany<Token>(&parsedData);
- patternParser.parseMany<Token>(&parsedPattern);
+ QList<Token> parsedData, parsedPattern;
+
+ dataParser.parseMany<Token>(&parsedData);
+ patternParser.parseMany<Token>(&parsedPattern);
testMatch(pattern + " = " + data, shouldBe,
- match(parsedData, parsedPattern, VarContext()));
+ match(parsedData, parsedPattern, VarContext()));
}
void testParseAst(QString string, QList<AstNode> equals = {})
@@ -138,14 +138,14 @@
Parser parser{string};
QList<AstNode> result;
- parser.parseMany<AstNode>(&result);
+ parser.parseMany<AstNode>(&result);
- if (!equals.empty() && result != equals)
- {
+ if (!equals.empty() && result != equals)
+ {
g_numFailed++;
qDebug() << "\n\033[31mTEST FAILS:\033[0m";
qDebug() << "Expected" << pprint(equals);
- }
+ }
qDebug() << "\033[36mParse\033[0m" << string << pprint(result);
}
@@ -153,7 +153,7 @@
void testParseFunc(QString string)
{
Parser parser{string};
- ParseResult ret;
+ ParseResult ret;
Function func;
@@ -200,13 +200,13 @@
Token('e', "middle"),
Token('s', "a")};
testMatch("s.a e.middle s.a = aea", true,
- match({Token('a'), Token('e'), Token('a')}, sameStartEnd, VarContext()));
+ match({Token('a'), Token('e'), Token('a')}, sameStartEnd, VarContext()));
testMatch("s.a e.middle s.a = aef Hi a", true,
- match({Token('a'), Token('e'), Token('f'), Token("Hi"), Token('a')}, sameStartEnd, VarContext()));
+ match({Token('a'), Token('e'), Token('f'), Token("Hi"), Token('a')}, sameStartEnd, VarContext()));
testMatch("s.a e.middle s.a = aef Hi c", false,
- match({Token('a'), Token('e'), Token('f'), Token("Hi"), Token('c')}, sameStartEnd, VarContext()));
+ match({Token('a'), Token('e'), Token('f'), Token("Hi"), Token('c')}, sameStartEnd, VarContext()));
LTok parenthesized = {
Token(LTok({Token('s', "a")})),
@@ -220,14 +220,14 @@
Token('y')};
testMatch("(s.a) e.Middle s.a = (y)f MiddleStuff y", true,
- match(parenTest1, parenthesized, VarContext()));
+ match(parenTest1, parenthesized, VarContext()));
// testMatch("(y)f Middle-stuff y", "(s.a) e.Middle s.a");
testMatch("(a)", "(a)");
- testMatch("hello", "s.A e.Rest");
- testMatch("123", "123");
- testMatch("(123)", "t.a");
- testMatch("(123)", "(s.a)");
+ testMatch("hello", "s.A e.Rest");
+ testMatch("123", "123");
+ testMatch("(123)", "t.a");
+ testMatch("(123)", "(s.a)");
}
void testAllParses()
@@ -244,8 +244,8 @@
testParseAst("(s.a) e.Middle s.a");
testParseAst("Hello; Goodbye");
testParseAst("Key = Value");
- testParseAst("123", {AstNode("123", 10)});
- testParseAst("12 00", {AstNode::fromInteger(12), AstNode::fromInteger(0)});
+ testParseAst("123", {AstNode("123", 10)});
+ testParseAst("12 00", {AstNode::fromInteger(12), AstNode::fromInteger(0)});
testParseAst("s.A s.B", {AstNode('s', "A"), AstNode('s', "B")});
testParseAst("a '=' b", {AstNode('a'), AstNode('='), AstNode('b')});
testParseAst("'This\\'<>#$@#^%\\n' 'another $3543543'");
@@ -259,8 +259,8 @@
void testAllEvals()
{
- testEval("First {s.A e.Rest = s.A;}", "<First hello>", "h");
- testEval("Number { = 123; }", "<Number>", QList<Token>{Token::fromInteger(123)});
+ testEval("First {s.A e.Rest = s.A;}", "<First hello>", "h");
+ testEval("Number { = 123; }", "<Number>", QList<Token>{Token::fromInteger(123)});
testEval("<Br Name '=' Jim> <Dg Name>", "Jim");
testEval("<Br A '=' hello> <Br A '=' 'good bye'> <Dg A> <Dg A>", "'good byehello'");
}
@@ -273,43 +273,43 @@
a.setApplicationName("REFAL");
a.setApplicationVersion("1.0-a1");
- QCommandLineParser cli;
- cli.setApplicationDescription("REFAL interpreter");
- cli.addHelpOption();
- cli.addVersionOption();
+ QCommandLineParser cli;
+ cli.setApplicationDescription("REFAL interpreter");
+ cli.addHelpOption();
+ cli.addVersionOption();
cli.addPositionalArgument("script", "REFAL script to run");
- QCommandLineOption testOption(QStringList{"t", "test"}, "Run test suite.");
- cli.addOption(testOption);
+ QCommandLineOption testOption(QStringList{"t", "test"}, "Run test suite.");
+ cli.addOption(testOption);
QCommandLineOption replOption(QStringList({"r", "repl"}), "Start CLI REPL");
cli.addOption(replOption);
- cli.process(a);
+ cli.process(a);
if (cli.positionalArguments().length() > 0)
{
qDebug() << "Running script" << cli.positionalArguments()[0];
}
else if (cli.isSet(testOption))
- {
- testAllMatches();
- qDebug() << "";
- testAllParses();
- qDebug() << "";
- testAllFunctionDefs();
- qDebug() << "";
- testAllEvals();
+ {
+ testAllMatches();
+ qDebug() << "";
+ testAllParses();
+ qDebug() << "";
+ testAllFunctionDefs();
+ qDebug() << "";
+ testAllEvals();
- qDebug() << "";
+ qDebug() << "";
- return testResults();
- }
+ return testResults();
+ }
else if (cli.isSet(replOption))
- {
- Repl repl;
- repl.start();
- }
+ {
+ Repl repl;
+ repl.start();
+ }
else
{
return ideMain(&a);