...
This commit is contained in:
@@ -2,15 +2,15 @@
|
||||
|
||||
namespace Compiler;
|
||||
|
||||
public sealed class Generator(TypedAst ast)
|
||||
public sealed class Generator(List<TypedNodeDefinitionFunc> functions)
|
||||
{
|
||||
public static string Emit(TypedAst ast)
|
||||
public static string Emit(List<TypedNodeDefinitionFunc> functions)
|
||||
{
|
||||
return new Generator(ast).Emit();
|
||||
return new Generator(functions).Emit();
|
||||
}
|
||||
|
||||
private IndentedTextWriter writer = new();
|
||||
private Dictionary<NubTypeStruct, string> structTypeNames = new();
|
||||
private readonly IndentedTextWriter writer = new();
|
||||
private readonly Dictionary<NubTypeStruct, string> structTypeNames = new();
|
||||
|
||||
private string Emit()
|
||||
{
|
||||
@@ -28,31 +28,31 @@ public sealed class Generator(TypedAst ast)
|
||||
|
||||
""");
|
||||
|
||||
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("};");
|
||||
}
|
||||
// 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("};");
|
||||
// }
|
||||
|
||||
writer.WriteLine();
|
||||
|
||||
foreach (var node in ast.Functions)
|
||||
foreach (var node in functions)
|
||||
{
|
||||
var parameters = node.Parameters.Select(x => CType(x.Type, x.Name.Ident));
|
||||
writer.WriteLine($"{CType(node.ReturnType, node.Name.Ident)}({string.Join(", ", parameters)});");
|
||||
@@ -60,7 +60,7 @@ public sealed class Generator(TypedAst ast)
|
||||
|
||||
writer.WriteLine();
|
||||
|
||||
foreach (var node in ast.Functions)
|
||||
foreach (var node in functions)
|
||||
{
|
||||
var parameters = node.Parameters.Select(x => CType(x.Type, x.Name.Ident));
|
||||
writer.WriteLine($"{CType(node.ReturnType, node.Name.Ident)}({string.Join(", ", parameters)})");
|
||||
|
||||
Reference in New Issue
Block a user