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