Skip to content

Commit

Permalink
DGen
Browse files Browse the repository at this point in the history
- When transforming a `CastedValueInstructionA` ensure that we wrap the expression being-casted in `(<expr>)` (parenthesis) because otherwise C is unhappy and in cases, like binary operator expressions, it will cause the C compiler to attempt casting the left-hand operand not the resultant of the binary operator expression
- When doing an emit for `BinaryOperatorExpression`, ignore the case whereby ether left or right-hand side operand s a pointer type and ONLY when) the operatr is `SymbolType.EQUALS`
  • Loading branch information
deavmi committed May 19, 2024
1 parent 3a10a1a commit 52ff503
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions source/tlang/compiler/codegen/emit/dgen.d
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,13 @@ public final class DCodeEmitter : CodeEmitter
* the cast out me thinks.
*
* See issue #140 (https://deavmi.assigned.network/git/tlang/tlang/issues/140#issuecomment-1892)
*
* Note, this would NOT be the case for equality
*/
Type leftHandOpType = (cast(Value)binOpInstr.lhs).getInstrType();
Type rightHandOpType = (cast(Value)binOpInstr.rhs).getInstrType();

if(typeChecker.isPointerType(leftHandOpType))
if(typeChecker.isPointerType(leftHandOpType) && binOpInstr.operator != SymbolType.EQUALS)
{
// Sanity check the other side should have been coerced to CastedValueInstruction
CastedValueInstruction cvInstr = cast(CastedValueInstruction)binOpInstr.rhs;
Expand All @@ -319,7 +321,7 @@ public final class DCodeEmitter : CodeEmitter
// Relax the CV-instr to prevent it from emitting explicit cast code
cvInstr.setRelax(true);
}
else if(typeChecker.isPointerType(rightHandOpType))
else if(typeChecker.isPointerType(rightHandOpType) && binOpInstr.operator != SymbolType.EQUALS)
{
// Sanity check the other side should have been coerced to CastedValueInstruction
CastedValueInstruction cvInstr = cast(CastedValueInstruction)binOpInstr.lhs;
Expand Down Expand Up @@ -614,7 +616,7 @@ public final class DCodeEmitter : CodeEmitter
emit ~= "("~typeTransform(castingTo)~")";

/* The expression being casted */
emit ~= transform(uncastedInstruction);
emit ~= "("~transform(uncastedInstruction)~")";
}
else
{
Expand Down

0 comments on commit 52ff503

Please sign in to comment.