|
|
|
@ -40,14 +40,13 @@ int main()
|
|
|
|
|
Var::pushScope();
|
|
|
|
|
|
|
|
|
|
std::string line;
|
|
|
|
|
while (std::cin.good()) {
|
|
|
|
|
for (unsigned lineno = 1; std::cin.good(); ++lineno) {
|
|
|
|
|
std::getline(std::cin, line);
|
|
|
|
|
parseString(line);
|
|
|
|
|
//std::cout << std::endl;
|
|
|
|
|
if (!parseString(line))
|
|
|
|
|
std::cerr << " at line " << lineno << std::endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
llvmState.output();
|
|
|
|
|
|
|
|
|
|
std::cout << std::endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -56,11 +55,9 @@ bool parseString(std::string_view sv)
|
|
|
|
|
do {
|
|
|
|
|
const auto [nsv, tok] = nextToken(sv);
|
|
|
|
|
|
|
|
|
|
//printToken(tok);
|
|
|
|
|
|
|
|
|
|
if (tok == Token::none && !nsv.empty()) {
|
|
|
|
|
std::cerr << "unknown " << nsv << std::endl;
|
|
|
|
|
break;
|
|
|
|
|
std::cerr << "error: unknown term: " << nsv << std::endl;
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
std::unique_ptr<BaseAST> expr;
|
|
|
|
|
|
|
|
|
@ -76,6 +73,8 @@ bool parseString(std::string_view sv)
|
|
|
|
|
{
|
|
|
|
|
auto& thunk = scope.back();
|
|
|
|
|
auto gen = thunk.codegen(llvmState);
|
|
|
|
|
if (!gen)
|
|
|
|
|
return false;
|
|
|
|
|
Var::popScope();
|
|
|
|
|
Var::addLocal(thunk.name, Var {gen, true});
|
|
|
|
|
expr.reset(new PushAST {thunk.name});
|
|
|
|
@ -83,7 +82,8 @@ bool parseString(std::string_view sv)
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case Token::Quote:
|
|
|
|
|
break;
|
|
|
|
|
std::cerr << "error: quoting is not supported!" << std::endl;
|
|
|
|
|
return false;
|
|
|
|
|
case Token::PopVar:
|
|
|
|
|
expr.reset(new PopAST {name});
|
|
|
|
|
break;
|
|
|
|
@ -100,9 +100,14 @@ bool parseString(std::string_view sv)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (expr && !scope.empty()) {
|
|
|
|
|
expr->codegen(llvmState);
|
|
|
|
|
//scope.back().body.emplace_back().swap(expr);
|
|
|
|
|
if (expr) {
|
|
|
|
|
if (!scope.empty()) {
|
|
|
|
|
if (!expr->codegen(llvmState))
|
|
|
|
|
return false;
|
|
|
|
|
} else if (tok != Token::ThunkClose) {
|
|
|
|
|
std::cerr << "error: non-thunk at top level!" << std::endl;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|