From 577581f2ce3e4c7c709abb07c378c1bc7a2d1379 Mon Sep 17 00:00:00 2001 From: Thomas Lindner Date: Thu, 5 Jan 2023 19:37:22 +0100 Subject: [PATCH] cleanup --- bootstrap/emit.cc | 8 +++----- bootstrap/xlang.g4 | 1 - 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/bootstrap/emit.cc b/bootstrap/emit.cc index 9ca43dc..8f50004 100644 --- a/bootstrap/emit.cc +++ b/bootstrap/emit.cc @@ -3,8 +3,6 @@ namespace xlang { -class EmitFunctionVisitor : public xlangBaseVisitor {}; - EmitVisitor::EmitVisitor(std::string_view outputfile) : output{outputfile} {} std::any EmitVisitor::visitFile(xlangParser::FileContext *ctx) { @@ -33,7 +31,7 @@ std::any EmitVisitor::visitFunction(xlangParser::FunctionContext *ctx) { std::any EmitVisitor::visitStatement(xlangParser::StatementContext *ctx) { if (auto identifier = ctx->Identifier()) { tmpcount = 0; - visitChildren(ctx); + visitExpr(ctx->expr()); output << " %_" << identifier->getSymbol()->getText() << " = w copy %t" << tmpcount - 1 << std::endl; return {}; @@ -70,14 +68,14 @@ std::any EmitVisitor::visitStatement(xlangParser::StatementContext *ctx) { } if (ctx->Return()) { tmpcount = 0; - visitChildren(ctx); + visitExpr(ctx->expr()); output << " ret %t" << tmpcount - 1 << std::endl; output << "@dead" << blockcount++ << std::endl; return {}; } if (ctx->Print()) { tmpcount = 0; - visitChildren(ctx); + visitExpr(ctx->expr()); output << " call $printf(l $printformat, ..., w %t" << tmpcount - 1 << ")" << std::endl; return {}; diff --git a/bootstrap/xlang.g4 b/bootstrap/xlang.g4 index b16bbbb..ef4a5a3 100644 --- a/bootstrap/xlang.g4 +++ b/bootstrap/xlang.g4 @@ -9,7 +9,6 @@ statement : Identifier Assign expr Semicolon | While expr block | Return expr Semicolon | Print expr Semicolon - | expr Semicolon ; expr : sum ((Less|LessEqual|Greater|GreaterEqual|Equal|NotEqual) sum) | sum