remove read only stuff
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
using System.Collections.Immutable;
|
using NubLang.CLI;
|
||||||
using NubLang.CLI;
|
|
||||||
using NubLang.Code;
|
using NubLang.Code;
|
||||||
using NubLang.Diagnostics;
|
using NubLang.Diagnostics;
|
||||||
using NubLang.Generation.QBE;
|
using NubLang.Generation.QBE;
|
||||||
@@ -100,7 +99,7 @@ if (diagnostics.Any(diagnostic => diagnostic.Severity == DiagnosticSeverity.Erro
|
|||||||
|
|
||||||
Directory.CreateDirectory(".build");
|
Directory.CreateDirectory(".build");
|
||||||
|
|
||||||
var generator = new QBEGenerator(definitions, referencedStructTypes.ToImmutableHashSet(), referencedInterfaceTypes.ToImmutableHashSet());
|
var generator = new QBEGenerator(definitions, referencedStructTypes, referencedInterfaceTypes);
|
||||||
var ssa = generator.Emit();
|
var ssa = generator.Emit();
|
||||||
var ssaFilePath = Path.Combine(".build", "out.ssa");
|
var ssaFilePath = Path.Combine(".build", "out.ssa");
|
||||||
File.WriteAllText(ssaFilePath, ssa);
|
File.WriteAllText(ssaFilePath, ssa);
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using System.Collections.Immutable;
|
using System.Diagnostics;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using NubLang.Tokenization;
|
using NubLang.Tokenization;
|
||||||
@@ -10,9 +9,9 @@ namespace NubLang.Generation.QBE;
|
|||||||
public class QBEGenerator
|
public class QBEGenerator
|
||||||
{
|
{
|
||||||
private readonly QBEWriter _writer;
|
private readonly QBEWriter _writer;
|
||||||
private readonly IReadOnlyList<DefinitionNode> _definitions;
|
private readonly List<DefinitionNode> _definitions;
|
||||||
private readonly ImmutableHashSet<StructTypeNode> _structTypes;
|
private readonly HashSet<StructTypeNode> _structTypes;
|
||||||
private readonly ImmutableHashSet<InterfaceTypeNode> _interfaceTypes;
|
private readonly HashSet<InterfaceTypeNode> _interfaceTypes;
|
||||||
|
|
||||||
private readonly List<CStringLiteral> _cStringLiterals = [];
|
private readonly List<CStringLiteral> _cStringLiterals = [];
|
||||||
private readonly List<StringLiteral> _stringLiterals = [];
|
private readonly List<StringLiteral> _stringLiterals = [];
|
||||||
@@ -24,7 +23,7 @@ public class QBEGenerator
|
|||||||
private int _stringLiteralIndex;
|
private int _stringLiteralIndex;
|
||||||
private bool _codeIsReachable = true;
|
private bool _codeIsReachable = true;
|
||||||
|
|
||||||
public QBEGenerator(IReadOnlyList<DefinitionNode> definitions, ImmutableHashSet<StructTypeNode> structTypes, ImmutableHashSet<InterfaceTypeNode> interfaceTypes)
|
public QBEGenerator(List<DefinitionNode> definitions, HashSet<StructTypeNode> structTypes, HashSet<InterfaceTypeNode> interfaceTypes)
|
||||||
{
|
{
|
||||||
_definitions = definitions;
|
_definitions = definitions;
|
||||||
_structTypes = structTypes;
|
_structTypes = structTypes;
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ public class Module
|
|||||||
private readonly List<ModuleInterfaceType> _interfaces = [];
|
private readonly List<ModuleInterfaceType> _interfaces = [];
|
||||||
private readonly List<ModuleFuncType> _functions = [];
|
private readonly List<ModuleFuncType> _functions = [];
|
||||||
|
|
||||||
public void RegisterStruct(bool exported, string name, IReadOnlyList<ModuleStructTypeField> fields)
|
public void RegisterStruct(bool exported, string name, List<ModuleStructTypeField> fields)
|
||||||
{
|
{
|
||||||
_structs.Add(new ModuleStructType(exported, name, fields));
|
_structs.Add(new ModuleStructType(exported, name, fields));
|
||||||
}
|
}
|
||||||
@@ -23,17 +23,17 @@ public class Module
|
|||||||
_functions.Add(new ModuleFuncType(exported, name, externSymbol, type));
|
_functions.Add(new ModuleFuncType(exported, name, externSymbol, type));
|
||||||
}
|
}
|
||||||
|
|
||||||
public IReadOnlyList<ModuleStructType> StructTypes(bool includePrivate)
|
public List<ModuleStructType> StructTypes(bool includePrivate)
|
||||||
{
|
{
|
||||||
return _structs.Where(x => x.Exported || includePrivate).ToList();
|
return _structs.Where(x => x.Exported || includePrivate).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IReadOnlyList<ModuleInterfaceType> InterfaceTypes(bool includePrivate)
|
public List<ModuleInterfaceType> InterfaceTypes(bool includePrivate)
|
||||||
{
|
{
|
||||||
return _interfaces.Where(x => x.Exported || includePrivate).ToList();
|
return _interfaces.Where(x => x.Exported || includePrivate).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IReadOnlyList<ModuleFuncType> Functions(bool includePrivate)
|
public List<ModuleFuncType> Functions(bool includePrivate)
|
||||||
{
|
{
|
||||||
return _functions.Where(x => x.Exported || includePrivate).ToList();
|
return _functions.Where(x => x.Exported || includePrivate).ToList();
|
||||||
}
|
}
|
||||||
@@ -41,7 +41,7 @@ public class Module
|
|||||||
|
|
||||||
public record ModuleStructTypeField(string Name, TypeSyntax Type, bool HasDefaultValue);
|
public record ModuleStructTypeField(string Name, TypeSyntax Type, bool HasDefaultValue);
|
||||||
|
|
||||||
public record ModuleStructType(bool Exported, string Name, IReadOnlyList<ModuleStructTypeField> Fields);
|
public record ModuleStructType(bool Exported, string Name, List<ModuleStructTypeField> Fields);
|
||||||
|
|
||||||
public record ModuleInterfaceType(bool Exported, string Name);
|
public record ModuleInterfaceType(bool Exported, string Name);
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ public class ModuleRepository
|
|||||||
{
|
{
|
||||||
private readonly Dictionary<string, Module> _modules = new();
|
private readonly Dictionary<string, Module> _modules = new();
|
||||||
|
|
||||||
public ModuleRepository(IReadOnlyList<SyntaxTree> syntaxTrees)
|
public ModuleRepository(List<SyntaxTree> syntaxTrees)
|
||||||
{
|
{
|
||||||
foreach (var syntaxTree in syntaxTrees)
|
foreach (var syntaxTree in syntaxTrees)
|
||||||
{
|
{
|
||||||
@@ -48,7 +48,7 @@ public class ModuleRepository
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IReadOnlyDictionary<string, Module> Modules()
|
public Dictionary<string, Module> Modules()
|
||||||
{
|
{
|
||||||
return _modules;
|
return _modules;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,19 +8,19 @@ namespace NubLang.Parsing;
|
|||||||
public sealed class Parser
|
public sealed class Parser
|
||||||
{
|
{
|
||||||
private readonly List<Diagnostic> _diagnostics = [];
|
private readonly List<Diagnostic> _diagnostics = [];
|
||||||
private IReadOnlyList<Token> _tokens = [];
|
private List<Token> _tokens = [];
|
||||||
private int _tokenIndex;
|
private int _tokenIndex;
|
||||||
private string _moduleName = string.Empty;
|
private string _moduleName = string.Empty;
|
||||||
|
|
||||||
private Token? CurrentToken => _tokenIndex < _tokens.Count ? _tokens[_tokenIndex] : null;
|
private Token? CurrentToken => _tokenIndex < _tokens.Count ? _tokens[_tokenIndex] : null;
|
||||||
private bool HasToken => CurrentToken != null;
|
private bool HasToken => CurrentToken != null;
|
||||||
|
|
||||||
public IReadOnlyList<Diagnostic> GetDiagnostics()
|
public List<Diagnostic> GetDiagnostics()
|
||||||
{
|
{
|
||||||
return _diagnostics;
|
return _diagnostics;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SyntaxTree Parse(IReadOnlyList<Token> tokens)
|
public SyntaxTree Parse(List<Token> tokens)
|
||||||
{
|
{
|
||||||
_diagnostics.Clear();
|
_diagnostics.Clear();
|
||||||
_tokens = tokens;
|
_tokens = tokens;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ public abstract record DefinitionSyntax(IEnumerable<Token> Tokens, string Name,
|
|||||||
|
|
||||||
public record FuncParameterSyntax(IEnumerable<Token> Tokens, string Name, TypeSyntax Type) : SyntaxNode(Tokens);
|
public record FuncParameterSyntax(IEnumerable<Token> Tokens, string Name, TypeSyntax Type) : SyntaxNode(Tokens);
|
||||||
|
|
||||||
public record FuncSignatureSyntax(IEnumerable<Token> Tokens, IReadOnlyList<FuncParameterSyntax> Parameters, TypeSyntax ReturnType) : SyntaxNode(Tokens);
|
public record FuncSignatureSyntax(IEnumerable<Token> Tokens, List<FuncParameterSyntax> Parameters, TypeSyntax ReturnType) : SyntaxNode(Tokens);
|
||||||
|
|
||||||
public record FuncSyntax(IEnumerable<Token> Tokens, string Name, bool Exported, string? ExternSymbol, FuncSignatureSyntax Signature, BlockSyntax? Body) : DefinitionSyntax(Tokens, Name, Exported);
|
public record FuncSyntax(IEnumerable<Token> Tokens, string Name, bool Exported, string? ExternSymbol, FuncSignatureSyntax Signature, BlockSyntax? Body) : DefinitionSyntax(Tokens, Name, Exported);
|
||||||
|
|
||||||
@@ -14,8 +14,8 @@ public record StructFieldSyntax(IEnumerable<Token> Tokens, string Name, TypeSynt
|
|||||||
|
|
||||||
public record StructFuncSyntax(IEnumerable<Token> Tokens, string Name, FuncSignatureSyntax Signature, BlockSyntax Body) : SyntaxNode(Tokens);
|
public record StructFuncSyntax(IEnumerable<Token> Tokens, string Name, FuncSignatureSyntax Signature, BlockSyntax Body) : SyntaxNode(Tokens);
|
||||||
|
|
||||||
public record StructSyntax(IEnumerable<Token> Tokens, string Name, bool Exported, IReadOnlyList<StructFieldSyntax> Fields, IReadOnlyList<StructFuncSyntax> Functions, IReadOnlyList<TypeSyntax> InterfaceImplementations) : DefinitionSyntax(Tokens, Name, Exported);
|
public record StructSyntax(IEnumerable<Token> Tokens, string Name, bool Exported, List<StructFieldSyntax> Fields, List<StructFuncSyntax> Functions, List<TypeSyntax> InterfaceImplementations) : DefinitionSyntax(Tokens, Name, Exported);
|
||||||
|
|
||||||
public record InterfaceFuncSyntax(IEnumerable<Token> Tokens, string Name, FuncSignatureSyntax Signature) : SyntaxNode(Tokens);
|
public record InterfaceFuncSyntax(IEnumerable<Token> Tokens, string Name, FuncSignatureSyntax Signature) : SyntaxNode(Tokens);
|
||||||
|
|
||||||
public record InterfaceSyntax(IEnumerable<Token> Tokens, string Name, bool Exported, IReadOnlyList<InterfaceFuncSyntax> Functions) : DefinitionSyntax(Tokens, Name, Exported);
|
public record InterfaceSyntax(IEnumerable<Token> Tokens, string Name, bool Exported, List<InterfaceFuncSyntax> Functions) : DefinitionSyntax(Tokens, Name, Exported);
|
||||||
@@ -36,9 +36,9 @@ public record BinaryExpressionSyntax(IEnumerable<Token> Tokens, ExpressionSyntax
|
|||||||
|
|
||||||
public record UnaryExpressionSyntax(IEnumerable<Token> Tokens, UnaryOperatorSyntax Operator, ExpressionSyntax Operand) : ExpressionSyntax(Tokens);
|
public record UnaryExpressionSyntax(IEnumerable<Token> Tokens, UnaryOperatorSyntax Operator, ExpressionSyntax Operand) : ExpressionSyntax(Tokens);
|
||||||
|
|
||||||
public record FuncCallSyntax(IEnumerable<Token> Tokens, ExpressionSyntax Expression, IReadOnlyList<ExpressionSyntax> Parameters) : ExpressionSyntax(Tokens);
|
public record FuncCallSyntax(IEnumerable<Token> Tokens, ExpressionSyntax Expression, List<ExpressionSyntax> Parameters) : ExpressionSyntax(Tokens);
|
||||||
|
|
||||||
public record DotFuncCallSyntax(IEnumerable<Token> Tokens, string Name, ExpressionSyntax ThisParameter, IReadOnlyList<ExpressionSyntax> Parameters) : ExpressionSyntax(Tokens);
|
public record DotFuncCallSyntax(IEnumerable<Token> Tokens, string Name, ExpressionSyntax ThisParameter, List<ExpressionSyntax> Parameters) : ExpressionSyntax(Tokens);
|
||||||
|
|
||||||
public record LocalIdentifierSyntax(IEnumerable<Token> Tokens, string Name) : ExpressionSyntax(Tokens);
|
public record LocalIdentifierSyntax(IEnumerable<Token> Tokens, string Name) : ExpressionSyntax(Tokens);
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ namespace NubLang.Parsing.Syntax;
|
|||||||
|
|
||||||
public abstract record SyntaxNode(IEnumerable<Token> Tokens);
|
public abstract record SyntaxNode(IEnumerable<Token> Tokens);
|
||||||
|
|
||||||
public record SyntaxTreeMetadata(string ModuleName, IReadOnlyList<string> Imports);
|
public record SyntaxTreeMetadata(string ModuleName, List<string> Imports);
|
||||||
|
|
||||||
public record SyntaxTree(IReadOnlyList<DefinitionSyntax> Definitions, SyntaxTreeMetadata Metadata);
|
public record SyntaxTree(List<DefinitionSyntax> Definitions, SyntaxTreeMetadata Metadata);
|
||||||
|
|
||||||
public record BlockSyntax(IEnumerable<Token> Tokens, IReadOnlyList<StatementSyntax> Statements) : SyntaxNode(Tokens);
|
public record BlockSyntax(IEnumerable<Token> Tokens, List<StatementSyntax> Statements) : SyntaxNode(Tokens);
|
||||||
@@ -4,7 +4,7 @@ namespace NubLang.Parsing.Syntax;
|
|||||||
|
|
||||||
public abstract record TypeSyntax(IEnumerable<Token> Tokens) : SyntaxNode(Tokens);
|
public abstract record TypeSyntax(IEnumerable<Token> Tokens) : SyntaxNode(Tokens);
|
||||||
|
|
||||||
public record FuncTypeSyntax(IEnumerable<Token> Tokens, IReadOnlyList<TypeSyntax> Parameters, TypeSyntax ReturnType) : TypeSyntax(Tokens);
|
public record FuncTypeSyntax(IEnumerable<Token> Tokens, List<TypeSyntax> Parameters, TypeSyntax ReturnType) : TypeSyntax(Tokens);
|
||||||
|
|
||||||
public record PointerTypeSyntax(IEnumerable<Token> Tokens, TypeSyntax BaseType) : TypeSyntax(Tokens);
|
public record PointerTypeSyntax(IEnumerable<Token> Tokens, TypeSyntax BaseType) : TypeSyntax(Tokens);
|
||||||
|
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ public sealed class Tokenizer
|
|||||||
_sourceFile = sourceFile;
|
_sourceFile = sourceFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IReadOnlyList<Diagnostic> GetDiagnostics() => _diagnostics;
|
public List<Diagnostic> GetDiagnostics() => _diagnostics;
|
||||||
|
|
||||||
public IEnumerable<Token> Tokenize()
|
public IEnumerable<Token> Tokenize()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ public abstract record DefinitionNode(string Module, string Name) : Node;
|
|||||||
|
|
||||||
public record FuncParameterNode(string Name, TypeNode Type) : Node;
|
public record FuncParameterNode(string Name, TypeNode Type) : Node;
|
||||||
|
|
||||||
public record FuncSignatureNode(IReadOnlyList<FuncParameterNode> Parameters, TypeNode ReturnType) : Node;
|
public record FuncSignatureNode(List<FuncParameterNode> Parameters, TypeNode ReturnType) : Node;
|
||||||
|
|
||||||
public record FuncNode(string Module, string Name, string? ExternSymbol, FuncSignatureNode Signature, BlockNode? Body) : DefinitionNode(Module, Name);
|
public record FuncNode(string Module, string Name, string? ExternSymbol, FuncSignatureNode Signature, BlockNode? Body) : DefinitionNode(Module, Name);
|
||||||
|
|
||||||
@@ -12,8 +12,8 @@ public record StructFieldNode(string Name, TypeNode Type, Optional<ExpressionNod
|
|||||||
|
|
||||||
public record StructFuncNode(string Name, FuncSignatureNode Signature, BlockNode Body) : Node;
|
public record StructFuncNode(string Name, FuncSignatureNode Signature, BlockNode Body) : Node;
|
||||||
|
|
||||||
public record StructNode(string Module, string Name, IReadOnlyList<StructFieldNode> Fields, IReadOnlyList<StructFuncNode> Functions, IReadOnlyList<InterfaceTypeNode> InterfaceImplementations) : DefinitionNode(Module, Name);
|
public record StructNode(string Module, string Name, List<StructFieldNode> Fields, List<StructFuncNode> Functions, List<InterfaceTypeNode> InterfaceImplementations) : DefinitionNode(Module, Name);
|
||||||
|
|
||||||
public record InterfaceFuncNode(string Name, FuncSignatureNode Signature) : Node;
|
public record InterfaceFuncNode(string Name, FuncSignatureNode Signature) : Node;
|
||||||
|
|
||||||
public record InterfaceNode(string Module, string Name, IReadOnlyList<InterfaceFuncNode> Functions) : DefinitionNode(Module, Name);
|
public record InterfaceNode(string Module, string Name, List<InterfaceFuncNode> Functions) : DefinitionNode(Module, Name);
|
||||||
@@ -39,11 +39,11 @@ public record BinaryExpressionNode(TypeNode Type, ExpressionNode Left, BinaryOpe
|
|||||||
|
|
||||||
public record UnaryExpressionNode(TypeNode Type, UnaryOperator Operator, ExpressionNode Operand) : RValueExpressionNode(Type);
|
public record UnaryExpressionNode(TypeNode Type, UnaryOperator Operator, ExpressionNode Operand) : RValueExpressionNode(Type);
|
||||||
|
|
||||||
public record FuncCallNode(TypeNode Type, ExpressionNode Expression, IReadOnlyList<ExpressionNode> Parameters) : RValueExpressionNode(Type);
|
public record FuncCallNode(TypeNode Type, ExpressionNode Expression, List<ExpressionNode> Parameters) : RValueExpressionNode(Type);
|
||||||
|
|
||||||
public record StructFuncCallNode(TypeNode Type, string Name, StructTypeNode StructType, ExpressionNode StructExpression, IReadOnlyList<ExpressionNode> Parameters) : RValueExpressionNode(Type);
|
public record StructFuncCallNode(TypeNode Type, string Name, StructTypeNode StructType, ExpressionNode StructExpression, List<ExpressionNode> Parameters) : RValueExpressionNode(Type);
|
||||||
|
|
||||||
public record InterfaceFuncCallNode(TypeNode Type, string Name, InterfaceTypeNode InterfaceType, ExpressionNode InterfaceExpression, IReadOnlyList<ExpressionNode> Parameters) : RValueExpressionNode(Type);
|
public record InterfaceFuncCallNode(TypeNode Type, string Name, InterfaceTypeNode InterfaceType, ExpressionNode InterfaceExpression, List<ExpressionNode> Parameters) : RValueExpressionNode(Type);
|
||||||
|
|
||||||
public record VariableIdentifierNode(TypeNode Type, string Name) : LValueExpressionNode(Type);
|
public record VariableIdentifierNode(TypeNode Type, string Name) : LValueExpressionNode(Type);
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,6 @@
|
|||||||
|
|
||||||
public abstract record Node;
|
public abstract record Node;
|
||||||
|
|
||||||
public record BlockNode(IReadOnlyList<StatementNode> Statements) : Node;
|
public record BlockNode(List<StatementNode> Statements) : Node;
|
||||||
|
|
||||||
public record TypedSyntaxTree(IReadOnlyList<DefinitionNode> Definitions);
|
public record TypedSyntaxTree(List<DefinitionNode> Definitions);
|
||||||
@@ -30,10 +30,10 @@ public sealed class TypeChecker
|
|||||||
.ToDictionary();
|
.ToDictionary();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IReadOnlyList<DefinitionNode> Definitions => _definitions;
|
public List<DefinitionNode> Definitions => _definitions;
|
||||||
public IReadOnlyList<Diagnostic> Diagnostics => _diagnostics;
|
public List<Diagnostic> Diagnostics => _diagnostics;
|
||||||
public IReadOnlyList<StructTypeNode> ReferencedStructTypes => _referencedStructTypes;
|
public List<StructTypeNode> ReferencedStructTypes => _referencedStructTypes;
|
||||||
public IReadOnlyList<InterfaceTypeNode> ReferencedInterfaceTypes => _referencedInterfaceTypes;
|
public List<InterfaceTypeNode> ReferencedInterfaceTypes => _referencedInterfaceTypes;
|
||||||
|
|
||||||
public void Check()
|
public void Check()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -10,5 +10,6 @@ export struct Test1
|
|||||||
|
|
||||||
extern "main" func main(args: []cstring): i64
|
extern "main" func main(args: []cstring): i64
|
||||||
{
|
{
|
||||||
|
puts("test")
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user