cleanup
This commit is contained in:
parent
c7a4effaab
commit
4f3d1d2f2e
|
@ -43,6 +43,7 @@ std::any EmitVisitor::visitStatement(xlangParser::StatementContext *ctx) {
|
|||
}
|
||||
if (ctx->If()) {
|
||||
int block = blockcount++;
|
||||
|
||||
output << "@if" << block << "_expr" << std::endl;
|
||||
tmpcount = 0;
|
||||
visitCondition(ctx->condition());
|
||||
|
@ -60,6 +61,7 @@ std::any EmitVisitor::visitStatement(xlangParser::StatementContext *ctx) {
|
|||
}
|
||||
if (ctx->While()) {
|
||||
int block = blockcount++;
|
||||
|
||||
output << "@while" << block << "_expr" << std::endl;
|
||||
tmpcount = 0;
|
||||
visitCondition(ctx->condition());
|
||||
|
@ -115,12 +117,6 @@ std::any EmitVisitor::visitBoolean(xlangParser::BooleanContext *ctx) {
|
|||
output << " " << tmp() << " = w xor 1, " << b << std::endl;
|
||||
return {};
|
||||
}
|
||||
OPERATOR(Less, visitExpr, expr(0), visitExpr, expr(1), "csltw");
|
||||
OPERATOR(LessEqual, visitExpr, expr(0), visitExpr, expr(1), "cslew");
|
||||
OPERATOR(Greater, visitExpr, expr(0), visitExpr, expr(1), "csgtw");
|
||||
OPERATOR(GreaterEqual, visitExpr, expr(0), visitExpr, expr(1), "csgew");
|
||||
OPERATOR(Equal, visitExpr, expr(0), visitExpr, expr(1), "ceqw");
|
||||
OPERATOR(NotEqual, visitExpr, expr(0), visitExpr, expr(1), "cnew");
|
||||
if (ctx->True()) {
|
||||
last = "1";
|
||||
return {};
|
||||
|
@ -129,6 +125,12 @@ std::any EmitVisitor::visitBoolean(xlangParser::BooleanContext *ctx) {
|
|||
last = "0";
|
||||
return {};
|
||||
}
|
||||
OPERATOR(Less, visitExpr, expr(0), visitExpr, expr(1), "csltw");
|
||||
OPERATOR(LessEqual, visitExpr, expr(0), visitExpr, expr(1), "cslew");
|
||||
OPERATOR(Greater, visitExpr, expr(0), visitExpr, expr(1), "csgtw");
|
||||
OPERATOR(GreaterEqual, visitExpr, expr(0), visitExpr, expr(1), "csgew");
|
||||
OPERATOR(Equal, visitExpr, expr(0), visitExpr, expr(1), "ceqw");
|
||||
OPERATOR(NotEqual, visitExpr, expr(0), visitExpr, expr(1), "cnew");
|
||||
visitChildren(ctx);
|
||||
return {};
|
||||
}
|
||||
|
@ -178,6 +180,7 @@ std::any EmitVisitor::visitVariable(xlangParser::VariableContext *ctx) {
|
|||
|
||||
if (ctx->LeftParen()) {
|
||||
std::vector<std::string> args;
|
||||
|
||||
if (auto arg_list = ctx->argumentList()) {
|
||||
for (auto value : arg_list->value()) {
|
||||
visitValue(value);
|
||||
|
|
|
@ -21,6 +21,7 @@ std::any TypeCheckVisitor::visitFile(xlangParser::FileContext *ctx) {
|
|||
for (auto function : ctx->function()) {
|
||||
auto token = function->Identifier()->getSymbol();
|
||||
auto name = token->getText();
|
||||
|
||||
if (function_arity.find(name) != function_arity.end()) {
|
||||
errorlistener.typeError(token->getLine(), token->getCharPositionInLine(),
|
||||
"duplicate function '" + name + "'");
|
||||
|
|
|
@ -17,9 +17,9 @@ condition : condition (And|Or|Xor) boolean
|
|||
| boolean
|
||||
;
|
||||
boolean : Not boolean
|
||||
| expr (Less|LessEqual|Greater|GreaterEqual|Equal|NotEqual) expr
|
||||
| True
|
||||
| False
|
||||
| expr (Less|LessEqual|Greater|GreaterEqual|Equal|NotEqual) expr
|
||||
| variable
|
||||
| LeftParen condition RightParen
|
||||
;
|
||||
|
|
Loading…
Reference in a new issue