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

type conversion error in expr compiler #363

Closed crowlogic closed 5 months ago

crowlogic commented 5 months ago

The source of the error is indeed where the Variable.generate method is called, expecting a Real representation (resultType parameter), but an Integer gets pushed onto the stack instead. This discrepancy occurs during the bytecode generation phase, where the type of the variable z is being handled.

Here’s a breakdown of the issue based on the provided code snippets:

  1. Mismatch Between Expected and Actual Type: The Variable.generate method generates bytecode for a variable node, which is expected to result in a type compatible with the resultType parameter. In this case, the resultType is expected to be arb/Real, but the actual loaded type is arb/Integer, as indicated by the error.

  2. generateReference Method Call: Inside Variable.generate, the method generateReference is invoked, which determines the type of reference to load onto the stack based on the variable's characteristics (whether it's independent, indeterminate, or defined in the context). This method is crucial for understanding where the type mismatch originates.

    • For an independent variable, it attempts to cast the loaded input parameter to the domain type of the expression (expression.domainType), which should be Real for this case.
    • For a variable defined in the context (not independent or indeterminate), it loads the field onto the stack using the field's type. The mismatch here implies that the type of the field for variable z in the context is actually Integer, not Real.
  3. Resolution Path:

    • Review Context Variable Registration: Ensure that when variable z is registered in the context (or when its reference is resolved), it is correctly identified with the type arb/Real. This might involve checking the logic within resolveReference and how variables are added to the variables map in the Expression class.
    • Type Conversion or Checking: If variable z is somehow dynamically determined and could be either Real or Integer based on the expression's context, ensure there's a type check or conversion mechanism in place before loading its value onto the stack. This might not be directly supported by the bytecode generation logic, necessitating a higher-level check or adjustment in the expression construction logic.
    • Debug Output and Variable Identification: Use the debug output to verify the point at which z is treated as Integer. This involves tracing back from the bytecode generation (especially around calls to loadFieldOntoStack and generateReference) to where z is defined or its type is inferred.
  4. Corrective Action: Based on the resolution path, you may need to adjust how variables are typed within the expression context or ensure that z is explicitly marked or converted to Real where necessary. This could involve modifying how expressions are parsed and compiled, ensuring that type expectations align with the actual types of variables as they are registered and used within expressions.

Given the complexity of the codebase and the specificity of the error, it's crucial to trace through the logic of variable type determination, especially how z is handled from its definition to its usage in expressions, to ensure it aligns with the expected Real type at all points of execution.

crowlogic commented 5 months ago

finally farking fixed the damned son of a bitching thing