This commit is contained in:
nub31
2025-05-14 21:47:04 +02:00
parent 86878e5fd2
commit b8103c11ad
3 changed files with 58 additions and 34 deletions

View File

@@ -541,6 +541,7 @@ public class Generator
_builder.AppendLine($" %{outputLabel} =w ceqw {left}, {right}"); _builder.AppendLine($" %{outputLabel} =w ceqw {left}, {right}");
return $"%{outputLabel}"; return $"%{outputLabel}";
} }
break; break;
} }
case BinaryExpressionOperator.NotEqual: case BinaryExpressionOperator.NotEqual:
@@ -569,6 +570,7 @@ public class Generator
_builder.AppendLine($" %{outputLabel} =w cnew {left}, {right}"); _builder.AppendLine($" %{outputLabel} =w cnew {left}, {right}");
return $"%{outputLabel}"; return $"%{outputLabel}";
} }
break; break;
} }
case BinaryExpressionOperator.GreaterThan: case BinaryExpressionOperator.GreaterThan:
@@ -590,6 +592,7 @@ public class Generator
_builder.AppendLine($" %{outputLabel} =w csgtw {left}, {right}"); _builder.AppendLine($" %{outputLabel} =w csgtw {left}, {right}");
return $"%{outputLabel}"; return $"%{outputLabel}";
} }
break; break;
} }
case BinaryExpressionOperator.GreaterThanOrEqual: case BinaryExpressionOperator.GreaterThanOrEqual:
@@ -611,6 +614,7 @@ public class Generator
_builder.AppendLine($" %{outputLabel} =w csgew {left}, {right}"); _builder.AppendLine($" %{outputLabel} =w csgew {left}, {right}");
return $"%{outputLabel}"; return $"%{outputLabel}";
} }
break; break;
} }
case BinaryExpressionOperator.LessThan: case BinaryExpressionOperator.LessThan:
@@ -632,6 +636,7 @@ public class Generator
_builder.AppendLine($" %{outputLabel} =w csltw {left}, {right}"); _builder.AppendLine($" %{outputLabel} =w csltw {left}, {right}");
return $"%{outputLabel}"; return $"%{outputLabel}";
} }
break; break;
} }
case BinaryExpressionOperator.LessThanOrEqual: case BinaryExpressionOperator.LessThanOrEqual:
@@ -653,6 +658,7 @@ public class Generator
_builder.AppendLine($" %{outputLabel} =w cslew {left}, {right}"); _builder.AppendLine($" %{outputLabel} =w cslew {left}, {right}");
return $"%{outputLabel}"; return $"%{outputLabel}";
} }
break; break;
} }
case BinaryExpressionOperator.Plus: case BinaryExpressionOperator.Plus:
@@ -668,6 +674,7 @@ public class Generator
_builder.AppendLine($" %{outputLabel} =w add {left}, {right}"); _builder.AppendLine($" %{outputLabel} =w add {left}, {right}");
return $"%{outputLabel}"; return $"%{outputLabel}";
} }
break; break;
} }
case BinaryExpressionOperator.Minus: case BinaryExpressionOperator.Minus:
@@ -683,6 +690,7 @@ public class Generator
_builder.AppendLine($" %{outputLabel} =w sub {left}, {right}"); _builder.AppendLine($" %{outputLabel} =w sub {left}, {right}");
return $"%{outputLabel}"; return $"%{outputLabel}";
} }
break; break;
} }
case BinaryExpressionOperator.Multiply: case BinaryExpressionOperator.Multiply:
@@ -698,6 +706,7 @@ public class Generator
_builder.AppendLine($" %{outputLabel} =w mul {left}, {right}"); _builder.AppendLine($" %{outputLabel} =w mul {left}, {right}");
return $"%{outputLabel}"; return $"%{outputLabel}";
} }
break; break;
} }
case BinaryExpressionOperator.Divide: case BinaryExpressionOperator.Divide:
@@ -713,6 +722,7 @@ public class Generator
_builder.AppendLine($" %{outputLabel} =w div {left}, {right}"); _builder.AppendLine($" %{outputLabel} =w div {left}, {right}");
return $"%{outputLabel}"; return $"%{outputLabel}";
} }
break; break;
} }
default: default:
@@ -721,7 +731,8 @@ public class Generator
} }
} }
throw new NotSupportedException($"Binary operator {binaryExpression.Operator} for types left: {binaryExpression.Left.Type}, right: {binaryExpression.Right.Type} not supported"); throw new NotSupportedException(
$"Binary operator {binaryExpression.Operator} for types left: {binaryExpression.Left.Type}, right: {binaryExpression.Right.Type} not supported");
} }
private string GenerateIdentifier(IdentifierNode identifier) private string GenerateIdentifier(IdentifierNode identifier)
@@ -750,6 +761,17 @@ public class Generator
throw new NotSupportedException($"Literal {literal.LiteralType} is not supported"); throw new NotSupportedException($"Literal {literal.LiteralType} is not supported");
} }
private string GenerateCast(string input, NubType inputType, string output, NubType outputType)
{
if (outputType is not NubPrimitiveType primitiveOutputType || inputType is not NubPrimitiveType primitiveInputType)
{
throw new NotSupportedException("Casting is only supported for primitive types");
}
// var instruction =
return ""
}
private string GenerateStructInitializer(StructInitializerNode structInitializer) private string GenerateStructInitializer(StructInitializerNode structInitializer)
{ {
var structDefinition = _definitions.OfType<StructDefinitionNode>() var structDefinition = _definitions.OfType<StructDefinitionNode>()

View File

@@ -6,7 +6,6 @@
<TargetFramework>net9.0</TargetFramework> <TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<PublishAot>true</PublishAot>
</PropertyGroup> </PropertyGroup>
</Project> </Project>

View File

@@ -81,16 +81,19 @@ public class NubPrimitiveType : NubType
{ {
return kind switch return kind switch
{ {
PrimitiveTypeKind.I64 => "i64",
PrimitiveTypeKind.I32 => "i32",
PrimitiveTypeKind.I16 => "i16",
PrimitiveTypeKind.I8 => "i8", PrimitiveTypeKind.I8 => "i8",
PrimitiveTypeKind.U64 => "u64", PrimitiveTypeKind.I16 => "i16",
PrimitiveTypeKind.U32 => "u32", PrimitiveTypeKind.I32 => "i32",
PrimitiveTypeKind.U16 => "u16", PrimitiveTypeKind.I64 => "i64",
PrimitiveTypeKind.U8 => "u8", PrimitiveTypeKind.U8 => "u8",
PrimitiveTypeKind.F64 => "f64", PrimitiveTypeKind.U16 => "u16",
PrimitiveTypeKind.U32 => "u32",
PrimitiveTypeKind.U64 => "u64",
PrimitiveTypeKind.F32 => "f32", PrimitiveTypeKind.F32 => "f32",
PrimitiveTypeKind.F64 => "f64",
PrimitiveTypeKind.Bool => "bool", PrimitiveTypeKind.Bool => "bool",
PrimitiveTypeKind.String => "string", PrimitiveTypeKind.String => "string",
PrimitiveTypeKind.Any => "any", PrimitiveTypeKind.Any => "any",