lab5: improve weighting during compilation, fix assembly operator translation bug

This commit is contained in:
2026-11-07 21:02:02 +02:00
parent 36b4596bd4
commit 7a90247dc0
5 changed files with 43 additions and 3 deletions
+32 -1
View File
@@ -248,6 +248,37 @@ static int get_max_index(const std::vector<int>& v)
return idx;
}
static int op_weight(enum Expression::Token::Operator o)
{
switch (o)
{
case Expression::Token::OPA:
case Expression::Token::CPA:
case Expression::Token::NOP:
pr_warn("Unweightable operator - this is probably a bug!");
return 0;
case Expression::Token::ADD:
return 1;
case Expression::Token::SUB:
return 1;
case Expression::Token::MUL:
return 2;
case Expression::Token::DIV:
return 2;
case Expression::Token::POW:
return 3;
default:
pr_warn("Impossible operator - this is a bug!");
return 0;
}
}
int op_weight(DynamicPipeline::CommandType o)
{
return op_weight((enum Expression::Token::Operator) (o + 2));
}
static int write_operation(
std::vector<Expression::Operation>& ov,
std::vector<Expression::Token>& cv,
@@ -322,7 +353,7 @@ static int write_operation(
return 1;
}
#endif
int this_op_weight = get_operator_weight(mv, location) + 1;
int this_op_weight = get_operator_weight(mv, location) + op_weight(o.v.o);
int il = l.t == Expression::Token::CV ? l.v.cv.i : left_location;
int ir = r.t == Expression::Token::CV ? r.v.cv.i : right_location;