...
This commit is contained in:
@@ -2,11 +2,11 @@
|
||||
|
||||
namespace Compiler;
|
||||
|
||||
public sealed class Generator(List<TypedNodeDefinitionFunc> functions)
|
||||
public sealed class Generator(List<TypedNodeDefinitionFunc> functions, ModuleGraph moduleGraph)
|
||||
{
|
||||
public static string Emit(List<TypedNodeDefinitionFunc> functions)
|
||||
public static string Emit(List<TypedNodeDefinitionFunc> functions, ModuleGraph moduleGraph)
|
||||
{
|
||||
return new Generator(functions).Emit();
|
||||
return new Generator(functions, moduleGraph).Emit();
|
||||
}
|
||||
|
||||
private readonly IndentedTextWriter writer = new();
|
||||
@@ -28,27 +28,26 @@ public sealed class Generator(List<TypedNodeDefinitionFunc> functions)
|
||||
|
||||
""");
|
||||
|
||||
// for (var i = 0; i < ast.StructTypes.Count; i++)
|
||||
// {
|
||||
// var structType = ast.StructTypes[i];
|
||||
// structTypeNames[structType] = $"s{i}";
|
||||
// }
|
||||
//
|
||||
// foreach (var structType in ast.StructTypes)
|
||||
// {
|
||||
// var name = structTypeNames[structType];
|
||||
// writer.WriteLine($"struct {name}");
|
||||
// writer.WriteLine("{");
|
||||
// using (writer.Indent())
|
||||
// {
|
||||
// foreach (var field in structType.Fields)
|
||||
// {
|
||||
// writer.WriteLine($"{CType(field.Type, field.Name)};");
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// writer.WriteLine("};");
|
||||
// }
|
||||
foreach (var (i, structType) in moduleGraph.GetStructTypes().Index())
|
||||
structTypeNames[structType] = $"s{i}";
|
||||
|
||||
foreach (var typeName in structTypeNames)
|
||||
writer.WriteLine($"struct {typeName.Value};");
|
||||
|
||||
writer.WriteLine();
|
||||
|
||||
foreach (var typeName in structTypeNames)
|
||||
{
|
||||
writer.WriteLine($"struct {typeName.Value}");
|
||||
writer.WriteLine("{");
|
||||
using (writer.Indent())
|
||||
{
|
||||
foreach (var field in typeName.Key.Fields)
|
||||
writer.WriteLine($"{CType(field.Type, field.Name)};");
|
||||
}
|
||||
|
||||
writer.WriteLine("};");
|
||||
}
|
||||
|
||||
writer.WriteLine();
|
||||
|
||||
@@ -199,7 +198,8 @@ public sealed class Generator(List<TypedNodeDefinitionFunc> functions)
|
||||
TypedNodeExpressionStringLiteral expression => $"(struct string){{ \"{expression.Value.Value}\", {expression.Value.Value.Length} }}",
|
||||
TypedNodeExpressionStructLiteral expression => EmitExpressionStructLiteral(expression),
|
||||
TypedNodeExpressionMemberAccess expression => EmitExpressionMemberAccess(expression),
|
||||
TypedNodeExpressionIdent expression => expression.Value.Ident,
|
||||
TypedNodeExpressionLocalIdent expression => expression.Value.Ident,
|
||||
TypedNodeExpressionModuleIdent expression => expression.Value.Ident,
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(node), node, null)
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user