Skip to content

Commit

Permalink
(#187) FloatingPointConstant: a new type, more architecturally correct
Browse files Browse the repository at this point in the history
  • Loading branch information
ForNeVeR committed Aug 17, 2022
1 parent 24a492c commit 8f22da7
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Cesium.CodeGen/Ir/Expressions/ConstantExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private static IConstant GetConstant(Ast.ConstantExpression expression)
CTokenType.IntLiteral => new IntegerConstant(constant.Text),
CTokenType.CharLiteral => new CharConstant(constant.Text),
CTokenType.StringLiteral => new StringConstant(constant),
CTokenType.FloatLiteral => new DoubleConstant(constant.Text),
CTokenType.FloatLiteral => new FloatingPointConstant(constant.Text),
_ => throw new WipException(228, $"Constant of kind {constant.Kind} is not supported.")
};
}
Expand Down
27 changes: 0 additions & 27 deletions Cesium.CodeGen/Ir/Expressions/Constants/FloatConstant.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@

namespace Cesium.CodeGen.Ir.Expressions.Constants;

internal class DoubleConstant : IConstant
internal class FloatingPointConstant : IConstant
{
private readonly double _value;

public DoubleConstant(string value)
public FloatingPointConstant(string value)
{
if (!double.TryParse(value, NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat, out _value))
throw new CompilationException($"Cannot parse a double literal: {value}.");
}

public void EmitTo(IDeclarationScope scope)
{
// TODO[#248]: This should support `float` as well.
scope.Method.Body.Instructions.Add(Instruction.Create(OpCodes.Ldc_R8, _value));
}

Expand Down

0 comments on commit 8f22da7

Please sign in to comment.