Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove compare primitive #73

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 0 additions & 79 deletions src/code.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,15 +266,6 @@ Expr *read_code()
"Negative sign with expr that is not an numeric literal.");
}
}
case Token::Compare:
{
Expr* e1 = read_code();
Expr* e2 = read_code();
Expr* e3 = read_code();
Expr* e4 = read_code();
eat_token(Token::Close);
return new CExpr(COMPARE, e1, e2, e3, e4);
}
case Token::Eof:
{
report_error("Unexpected end of file.");
Expand Down Expand Up @@ -642,47 +633,6 @@ Expr *check_code(Expr *_e)
}
return tp1;
}
case COMPARE:
{
SymSExpr *tp0 = (SymSExpr *)check_code(e->kids[0]);
if (tp0->getclass() != SYMS_EXPR || tp0->val)
{
string errstr0 =
(string("\"compare\" is used with a first expression which ")
+ string("cannot be a lambda-bound variable.\n")
+ string("1. the expression :") + e->kids[0]->toString()
+ string("\n2. its type: ") + tp0->toString());
report_error(errstr0);
}

SymSExpr *tp1 = (SymSExpr *)check_code(e->kids[1]);

if (tp1->getclass() != SYMS_EXPR || tp1->val)
{
string errstr1 =
(string("\"compare\" is used with a second expression which ")
+ string("cannot be a lambda-bound variable.\n")
+ string("1. the expression :") + e->kids[1]->toString()
+ string("\n2. its type: ") + tp1->toString());
report_error(errstr1);
}

Expr *tp2 = check_code(e->kids[2]);
Expr *tp3 = check_code(e->kids[3]);
tp2 = tp2->followDefs();
tp3 = tp3->followDefs();
if (tp2 != tp3)
{
report_error(
string("\"compare\" used with expressions that do not ")
+ string("have equal simple datatypes\nfor their types.\n")
+ string("\n1. first expression: ") + e->kids[2]->toString()
+ string("\n2. second expression: ") + e->kids[3]->toString()
+ string("\n3. first expression's type: ") + tp2->toString()
+ string("\n4. second expression's type: ") + tp3->toString());
}
return tp2;
}
case IFEQUAL:
{
Expr *tp0 = check_code(e->kids[0]);
Expand Down Expand Up @@ -1022,35 +972,6 @@ Expr *run_code(Expr *_e)
_e = e->kids[3];
goto start_run_code;
}
case COMPARE:
{
Expr *r1 = run_code(e->kids[0]);
if (!r1) return NULL;
if (r1->getclass() != SYM_EXPR && r1->getclass() != SYMS_EXPR)
{
r1->dec();
return NULL;
}
Expr *r2 = run_code(e->kids[1]);
if (!r2) return NULL;
if (r2->getclass() != SYM_EXPR && r2->getclass() != SYMS_EXPR)
{
r2->dec();
return NULL;
}
if (r1 < r2)
{
r1->dec();
r2->dec();
_e = e->kids[2];
goto start_run_code;
}
// else
r1->dec();
r2->dec();
_e = e->kids[3];
goto start_run_code;
}
case IFEQUAL:
{
Expr *r1 = run_code(e->kids[0]);
Expand Down
5 changes: 0 additions & 5 deletions src/expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -999,11 +999,6 @@ void Expr::print(ostream &os) const
print_kids(os, e->kids);
os << ")";
break;
case COMPARE:
os << "(compare";
print_kids(os, e->kids);
os << ")";
break;
case IFEQUAL:
os << "(ifequal";
print_kids(os, e->kids);
Expand Down
1 change: 0 additions & 1 deletion src/expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ enum
FAIL,
MARKVAR,
IFMARKED,
COMPARE,
IFEQUAL
};

Expand Down
1 change: 0 additions & 1 deletion src/lexer.flex
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ comment ;[^\n]*\n
"mp_ifneg" return Token::MpIfNeg;
"mp_ifzero" return Token::MpIfZero;
"mpz_to_mpq" return Token::MpzToMpq;
"compare" return Token::Compare;
"ifequal" return Token::IfEqual;
"fail" return Token::Fail;

Expand Down
29 changes: 0 additions & 29 deletions src/sccwriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -588,34 +588,6 @@ void sccwriter::write_code(
write_dec(expr, os, ind);
}
break;
case COMPARE:
{
std::string expr1, expr2;
write_expr(((CExpr*)code)->kids[0],
os,
ind,
expr1,
opt_write_check_sym_expr);
write_expr(((CExpr*)code)->kids[1],
os,
ind,
expr2,
opt_write_check_sym_expr);
indent(os, ind);
os << "if( ((SymExpr*)" << expr1.c_str()
<< ")->followDefs() < ((SymExpr*)" << expr2.c_str()
<< ")->followDefs() ){" << std::endl;
write_code(((CExpr*)code)->kids[2], os, ind + 1, retModStr);
indent(os, ind);
os << "}else{" << std::endl;
write_code(((CExpr*)code)->kids[3], os, ind + 1, retModStr);
indent(os, ind);
os << "}" << std::endl;
// clean up memory
write_dec(expr1, os, ind);
write_dec(expr2, os, ind);
}
break;
case IFEQUAL:
{
std::string expr1, expr2;
Expand Down Expand Up @@ -963,7 +935,6 @@ void sccwriter::debug_write_code(Expr* code, std::ostream& os, int ind)
case FAIL: os << "fail"; break;
case MARKVAR: os << "markvar"; break;
case IFMARKED: os << "ifmarked"; break;
case COMPARE: os << "compare"; break;
default: os << "???"; break;
}
}
Expand Down