Skip to content

Aps2scala integer equality == #137

Description

@amir734jj

This APS code:

  function hf(x : Integer; y : Integer) : Boolean begin
    q : Integer := x / y;
    result := q * y == x;
  end;

Gets dumped as:

val v_hf = f_hf _;
def f_hf(v_x : T_Integer, v_y : T_Integer):T_Boolean = {

  var v_q : T_Integer = new M__basic_4[ T_Integer](t_Integer).v__op_w(v_x,v_y);
  return new M__basic_8[ T_Integer](t_Integer).v__op_00(new M__basic_4[ T_Integer](t_Integer).v__op_r(v_q,v_y),v_x);
  throw Evaluation.UndefinedAttributeException("local hf");
}

But getting these type errors because of ==

type mismatch;
 found   : M_INTEGER
 required: C_PHYLUM[basic_implicit.T_Integer]
    (which expands to)  C_PHYLUM[Int]
    return new M__basic_8[ T_Integer](t_Integer).v__op_00(new M__basic_4[ T_Integer](t_Integer).v__op_r(v_q,v_y),v_x);

Because t_Integer is actually val t_Integer = new M_INTEGER("Integer"); and M_INTEGER is not a C_PHYLUM[*]

The work arround is to replace == with <= and >=

function hf(x : Integer; y : Integer) : Boolean begin
  q : Integer := x / y;
  result := q * y <= x and q * y >= x;
end;

Which gets generated as:

val v_hf = f_hf _;
def f_hf(v_x : T_Integer, v_y : T_Integer):T_Boolean = {

  var v_q : T_Integer = new M__basic_4[ T_Integer](t_Integer).v__op_w(v_x,v_y);
  return v_and(new M__basic_3[ T_Integer](t_Integer).v__op_z0(new M__basic_4[ T_Integer](t_Integer).v__op_r(v_q,v_y),v_x),new M__basic_3[ T_Integer](t_Integer).v__op_10(new M__basic_4[ T_Integer](t_Integer).v__op_r(v_q,v_y),v_x));
  throw Evaluation.UndefinedAttributeException("local hf");
}

And compiles successfully

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions