crowlogic / arb4j

arb4j is a Java API for the arbitrary precision ball arithmetic library found at http://arblib.org
Other
1 stars 0 forks source link

LiteralConstant.generate is ignoring requested type, make it do the type conversion before returning the val #407

Closed crowlogic closed 2 months ago

crowlogic commented 2 months ago

The design is such that the caller of the generate method does the conversion if it notices that the requested type is not the one that it got but casting is possible, but its better if the generate method does it since it works in more situations

  @Override
  public MethodVisitor generate(Class<?> resultType, MethodVisitor mv)
  {
    generatedType = type();
    if (π.equals(fieldName))
    {
      getStaticField(mv, π);
    }
    else if (half.equals(fieldName))
    {
      getStaticField(mv, "half");
    }
    else
    {
      // todo: https://github.com/crowlogic/arb4j/issues/222: use the primitive int ,
      // the signature of the method being invoked will also have to know this has
      // been done and change correspondingly
      expression.loadFieldOntoStack(loadThisOntoStack(mv),
                                    fieldName,
                                    generatedType.descriptorString());
    }

    if (isResult)
    {
      expression.generateSetResultInvocation(mv, generatedType);
    }

    // expression.addToTypeStack(thisType, toString() );

    return mv;
  }