├── .editorconfig ├── .gitattributes ├── .gitignore ├── .gitmodules ├── API ├── API.csproj ├── AdamantCompiler.cs ├── AssemblyBuilder.cs ├── ILAssembler.cs └── README.md ├── AST ├── AST.csproj ├── AbstractSyntaxTree.children.cs ├── AbstractSyntaxTree.tree ├── AbstractSyntaxTree.tree.cs ├── IAbstractSyntax.cs ├── IExpression.cs └── Walkers │ └── AbstractSyntaxWalker.cs ├── Adamant.Tools.Compiler.Bootstrap.sln ├── Adamant.Tools.Compiler.Bootstrap.sln.DotSettings ├── CST ├── AccessModifier.cs ├── CST.csproj ├── ExpressionSemanticsExtensions.cs ├── IArgumentSyntax.cs ├── IBlockExpressionSyntax.cs ├── IBodyStatementSyntax.cs ├── IBorrowExpressionSyntax.cs ├── IClassDeclarationSyntax.cs ├── IDeclarationSyntax.cs ├── IEntityDeclarationSyntax.cs ├── IExpressionSyntax.cs ├── IHasContainingLexicalScope.cs ├── IImplicitImmutabilityConversionExpressionSyntax.cs ├── IImplicitNoneConversionExpressionSyntax.cs ├── IImplicitNumericConversionExpressionSyntax.cs ├── IImplicitOptionalConversionExpressionSyntax.cs ├── IInvocableDeclarationSyntax.cs ├── IMoveExpressionSyntax.cs ├── INameExpressionSyntax.cs ├── INonMemberDeclarationSyntax.cs ├── INonMemberEntityDeclarationSyntax.cs ├── IShareExpressionSyntax.cs ├── ISyntax.cs ├── ITypeNameSyntax.cs ├── ITypeSyntax.cs ├── IUnqualifiedInvocationExpressionSyntax.cs ├── PackageSyntax.cs ├── README.md ├── SyntaxTree.children.cs ├── SyntaxTree.tree ├── SyntaxTree.tree.cs └── Walkers │ └── SyntaxWalker.cs ├── CodeGen ├── AssemblyInfo.cs ├── ChildrenCodeTemplate.cs ├── ChildrenCodeTemplate.custom.cs ├── ChildrenCodeTemplate.tt ├── CodeBuilder.cs ├── CodeGen.csproj ├── Config │ ├── Grammar.cs │ ├── GrammarProperty.cs │ ├── GrammarRule.cs │ ├── GrammarSymbol.cs │ └── GrammarType.cs ├── NamespaceComparer.cs ├── Parser.cs ├── Program.cs ├── TreeCodeTemplate.cs ├── TreeCodeTemplate.custom.cs └── TreeCodeTemplate.tt ├── Core ├── CodeBuilder.cs ├── CodeFile.cs ├── CodePath.cs ├── CodeReference.cs ├── CodeText.cs ├── Core.csproj ├── Diagnostic.cs ├── DiagnosticLevel.cs ├── DiagnosticPhase.cs ├── Diagnostics.cs ├── ExpressionSemantics.cs ├── FatalCompilationErrorException.cs ├── ICodeFileSource.cs ├── Operators │ ├── AccessOperator.cs │ ├── AccessOperatorExtensions.cs │ ├── AssignmentOperator.cs │ ├── AssignmentOperatorExtensions.cs │ ├── BinaryOperator.cs │ ├── BinaryOperatorExtensions.cs │ ├── UnaryOperator.cs │ ├── UnaryOperatorExtensions.cs │ └── UnaryOperatorFixity.cs ├── ParseContext.cs ├── Promises │ ├── AcyclicPromise.cs │ ├── DerivedPromise.cs │ ├── IPromise.cs │ ├── Promise.cs │ ├── PromiseExtensions.cs │ └── PromiseState.cs ├── README.md ├── TextLines.cs ├── TextPosition.cs └── TextSpan.cs ├── Emit.C ├── CCodeBuilder.cs ├── CLangCompiler.cs ├── Code.cs ├── CodeEmitter.cs ├── ConsoleCompilerOutput.cs ├── ControlFlowEmitter.cs ├── DeclarationEmitter.cs ├── Emit.C.csproj ├── ICompilerOutput.cs ├── IConverter.cs ├── IEmitter.cs ├── InternalsVisibleTo.cs ├── NameMangler.cs ├── PackageEmitter.cs ├── ParameterConverter.cs ├── Properties │ ├── Resources.Designer.cs │ └── Resources.resx ├── RuntimeLibrary.c ├── RuntimeLibrary.h └── TypeConverter.cs ├── Emit ├── Emit.csproj └── Emitter.cs ├── Framework ├── BitArrayExtensions.cs ├── CollectionDebugView.cs ├── DictionaryDebugView.cs ├── DictionaryExtensions.cs ├── EnumerableExtensions.cs ├── FixedDictionary.cs ├── FixedList.cs ├── FixedSet.cs ├── Framework.csproj ├── Generator.cs ├── QueueExtensions.cs ├── Requires.cs ├── Self.cs ├── SetExtensions.cs ├── StackExtensions.cs ├── StringExtensions.cs ├── TypeExtensions.cs ├── TypeSet.cs ├── UnreachableCodeException.cs └── Void.cs ├── IntermediateLanguage ├── CFG │ ├── Block.cs │ ├── ControlFlowGraph.cs │ ├── Instructions │ │ ├── AssignmentInstruction.cs │ │ ├── BooleanLogicInstruction.cs │ │ ├── BooleanLogicOperator.cs │ │ ├── CallInstruction.cs │ │ ├── CallVirtualInstruction.cs │ │ ├── CompareInstruction.cs │ │ ├── CompareInstructionOperator.cs │ │ ├── ConvertInstruction.cs │ │ ├── FieldAccessInstruction.cs │ │ ├── Instruction.cs │ │ ├── InstructionWithResult.cs │ │ ├── LoadBoolInstruction.cs │ │ ├── LoadIntegerInstruction.cs │ │ ├── LoadNoneInstruction.cs │ │ ├── LoadStringInstruction.cs │ │ ├── NegateInstruction.cs │ │ ├── NewObjectInstruction.cs │ │ ├── NumericInstruction.cs │ │ ├── NumericInstructionOperator.cs │ │ └── SomeInstruction.cs │ ├── Operands │ │ ├── Operand.cs │ │ └── VariableReference.cs │ ├── Places │ │ ├── FieldPlace.cs │ │ ├── Place.cs │ │ └── VariablePlace.cs │ ├── Scope.cs │ ├── StringConstant.cs │ ├── TerminatorInstructions │ │ ├── GotoInstruction.cs │ │ ├── IfInstruction.cs │ │ ├── ReturnValueInstruction.cs │ │ ├── ReturnVoidInstruction.cs │ │ └── TerminatorInstruction.cs │ ├── Variable.cs │ └── VariableDeclaration.cs ├── ClassIL.cs ├── ConstructorIL.cs ├── DeclarationIL.cs ├── FieldIL.cs ├── FieldInitializationIL.cs ├── FieldParameterIL.cs ├── FunctionIL.cs ├── IInvocableDeclarationIL.cs ├── IntermediateLanguage.csproj ├── MethodDeclarationIL.cs ├── NamedParameterIL.cs ├── PackageIL.cs ├── ParameterIL.cs ├── README.md └── SelfParameterIL.cs ├── LICENSE ├── LexicalScopes ├── LexicalScope.cs ├── LexicalScopes.csproj ├── NestedScope.cs └── PackagesScope.cs ├── Lexing ├── ITokenIterator.cs ├── LexError.cs ├── Lexer.cs ├── Lexing.csproj ├── TokenIterator.cs └── TokenIteratorExtensions.cs ├── Names ├── Name.cs ├── Names.csproj ├── NamespaceName.cs ├── SpecialTypeName.cs └── TypeName.cs ├── Parsing ├── CompilationUnitParser.cs ├── ModifierParser.cs ├── NotImplemented │ └── SyntaxNotImplementedChecker.cs ├── PackageParser.cs ├── ParseAs.cs ├── ParseError.cs ├── ParseFailedException.cs ├── Parser.Annotations.cs ├── Parser.Declarations.cs ├── Parser.Expressions.cs ├── Parser.Lists.cs ├── Parser.Names.cs ├── Parser.Parameters.cs ├── Parser.Statements.cs ├── Parser.Types.cs ├── Parser.UsingDirectives.cs ├── Parser.cs ├── Parsing.csproj ├── RecursiveDescentParser.cs ├── TokenIteratorExtensions.cs └── Tree │ ├── AbstractMethodDeclarationSyntax.cs │ ├── ArgumentSyntax.cs │ ├── AssignmentExpressionSyntax.cs │ ├── AssociatedFunctionDeclarationSyntax.cs │ ├── BinaryOperatorExpressionSyntax.cs │ ├── BlockExpressionSyntax.cs │ ├── BodySyntax.cs │ ├── BoolLiteralExpressionSyntax.cs │ ├── BorrowExpressionSyntax.cs │ ├── BreakExpressionSyntax.cs │ ├── CanReachAnnotationSyntax.cs │ ├── CapabilityTypeSyntax.cs │ ├── ClassDeclarationSyntax.cs │ ├── CompilationUnitSyntax.cs │ ├── ConcreteMethodDeclarationSyntax.cs │ ├── ConstructorDeclarationSyntax.cs │ ├── DeclarationSyntax.cs │ ├── ExpressionStatementSyntax.cs │ ├── ExpressionSyntax.cs │ ├── FieldDeclarationSyntax.cs │ ├── FieldParameterSyntax.cs │ ├── ForeachExpressionSyntax.cs │ ├── FunctionDeclarationSyntax.cs │ ├── IfExpressionSyntax.cs │ ├── IntegerLiteralExpressionSyntax.cs │ ├── InvocableDeclarationSyntax.cs │ ├── InvocationExpressionSyntax.cs │ ├── LiteralExpressionSyntax.cs │ ├── LoopExpressionSyntax.cs │ ├── MemberDeclarationSyntax.cs │ ├── MethodDeclarationSyntax.cs │ ├── MoveExpressionSyntax.cs │ ├── NameExpressionSyntax.cs │ ├── NameSyntax.cs │ ├── NamedParameterNameSyntax.cs │ ├── NamedParameterSyntax.cs │ ├── NamespaceDeclarationSyntax.cs │ ├── NewObjectExpressionSyntax.cs │ ├── NextExpressionSyntax.cs │ ├── NoneLiteralExpressionSyntax.cs │ ├── OptionalTypeSyntax.cs │ ├── ParameterSyntax.cs │ ├── QualifiedInvocationExpressionSyntax.cs │ ├── QualifiedNameExpressionSyntax.cs │ ├── ReachabilityAnnotationsSyntax.cs │ ├── ReachableFromAnnotationSyntax.cs │ ├── ResultStatementSyntax.cs │ ├── ReturnExpressionSyntax.cs │ ├── SelfExpressionSyntax.cs │ ├── SelfParameterNameSyntax.cs │ ├── SelfParameterSyntax.cs │ ├── StatementSyntax.cs │ ├── StringLiteralExpressionSyntax.cs │ ├── Syntax.cs │ ├── TypeNameSyntax.cs │ ├── TypeSyntax.cs │ ├── UnaryOperatorExpressionSyntax.cs │ ├── UnqualifiedInvocationExpressionSyntax.cs │ ├── UnsafeExpressionSyntax.cs │ ├── UsingDirectiveSyntax.cs │ ├── VariableDeclarationStatementSyntax.cs │ └── WhileExpressionSyntax.cs ├── Primitives ├── Intrinsic.cs ├── Primitive.cs └── Primitives.csproj ├── README.md ├── Semantics.Reachability.Graph ├── Access.cs ├── AssemblyInfo.cs ├── CallerVariable.cs ├── HeapPlace.cs ├── IReference.cs ├── IReferenceGraph.cs ├── MemoryPlace.cs ├── Object.cs ├── Ownership.cs ├── Phase.cs ├── README.md ├── ReachabilityGraph.cs ├── ReachabilityGraphGraphvizExtensions.cs ├── Reference.cs ├── ReferenceCapabilityExtensions.cs ├── ReferenceGraph.cs ├── Semantics.Reachability.Graph.csproj ├── StackPlace.cs ├── TempValue.cs └── Variable.cs ├── Semantics ├── AST │ ├── ASTBuilder.cs │ └── Tree │ │ ├── AbstractMethodDeclaration.cs │ │ ├── AbstractSyntax.cs │ │ ├── AssignmentExpression.cs │ │ ├── AssociatedFunctionDeclaration.cs │ │ ├── BinaryOperatorExpression.cs │ │ ├── BlockExpression.cs │ │ ├── Body.cs │ │ ├── BoolLiteralExpression.cs │ │ ├── BorrowExpression.cs │ │ ├── BreakExpression.cs │ │ ├── CanReachAnnotation.cs │ │ ├── ClassDeclaration.cs │ │ ├── ConcreteMethodDeclaration.cs │ │ ├── ConstructorDeclaration.cs │ │ ├── Declaration.cs │ │ ├── Expression.cs │ │ ├── ExpressionStatement.cs │ │ ├── FieldAccessExpression.cs │ │ ├── FieldDeclaration.cs │ │ ├── FieldParameter.cs │ │ ├── ForeachExpression.cs │ │ ├── FunctionDeclaration.cs │ │ ├── FunctionInvocationExpression.cs │ │ ├── IfExpression.cs │ │ ├── ImplicitConversionExpression.cs │ │ ├── ImplicitImmutabilityConversion.cs │ │ ├── ImplicitNoneConversionExpression.cs │ │ ├── ImplicitNumericConversionExpression.cs │ │ ├── ImplicitOptionalConversionExpression.cs │ │ ├── IntegerLiteralExpression.cs │ │ ├── InvocableDeclaration.cs │ │ ├── LiteralExpression.cs │ │ ├── LoopExpression.cs │ │ ├── MethodInvocationExpression.cs │ │ ├── MoveExpression.cs │ │ ├── NameExpression.cs │ │ ├── NamedParameter.cs │ │ ├── NamedParameterName.cs │ │ ├── NewObjectExpression.cs │ │ ├── NextExpression.cs │ │ ├── NoneLiteralExpression.cs │ │ ├── Package.cs │ │ ├── Parameter.cs │ │ ├── ReachabilityAnnotations.cs │ │ ├── ReachableFromAnnotation.cs │ │ ├── ResultStatement.cs │ │ ├── ReturnExpression.cs │ │ ├── SelfExpression.cs │ │ ├── SelfParameter.cs │ │ ├── SelfParameterName.cs │ │ ├── ShareExpression.cs │ │ ├── Statement.cs │ │ ├── StringLiteralExpression.cs │ │ ├── UnaryOperatorExpression.cs │ │ ├── UnsafeExpression.cs │ │ ├── VariableDeclarationStatement.cs │ │ └── WhileExpression.cs ├── Basic │ ├── BasicAnalyzer.cs │ ├── BasicBodyAnalyzer.cs │ ├── ImplicitOperations │ │ ├── ImplicitBorrowExpressionSyntax.cs │ │ ├── ImplicitConversionExpression.cs │ │ ├── ImplicitExpressionSyntax.cs │ │ ├── ImplicitImmutabilityConversionExpression.cs │ │ ├── ImplicitMoveSyntax.cs │ │ ├── ImplicitNoneConversionExpression.cs │ │ ├── ImplicitNumericConversionExpression.cs │ │ ├── ImplicitOptionalConversionExpression.cs │ │ └── ImplicitShareExpressionSyntax.cs │ └── InferredSyntax │ │ └── FunctionInvocationExpressionSyntax.cs ├── DataFlow │ ├── BackwardDataFlowAnalyzer.cs │ ├── DataFlowAnalysis.cs │ ├── ForwardDataFlowAnalyzer.cs │ ├── IBackwardDataFlowAnalysis.cs │ ├── IBackwardDataFlowAnalyzer.cs │ ├── IForwardDataFlowAnalysis.cs │ ├── IForwardDataFlowAnalyzer.cs │ └── VariableFlags.cs ├── DeclarationNumbers │ └── DeclarationNumberAssigner.cs ├── Errors │ ├── BorrowError.cs │ ├── NameBindingError.cs │ ├── SemanticError.cs │ └── TypeError.cs ├── ILGen │ ├── BlockBuilder.cs │ ├── ControlFlowGraphBuilder.cs │ ├── ControlFlowGraphFabrication.cs │ ├── DeclarationBuilder.cs │ └── IlFactory.cs ├── LexicalScopes │ ├── LexicalScopesBuilder.cs │ ├── LexicalScopesBuilderWalker.cs │ ├── Namespace.cs │ └── NonMemberSymbol.cs ├── Liveness │ ├── LivenessAnalysis.cs │ ├── LivenessAnalyzer.cs │ └── OldLivenessAnalyzer.cs ├── README.md ├── Reachability │ ├── Argument.cs │ ├── ReachabilityAnalyzer.cs │ └── VariableScope.cs ├── SemanticAnalyzer.cs ├── Semantics.csproj ├── Symbols │ ├── Entities │ │ └── EntitySymbolBuilder.cs │ └── Namespaces │ │ └── NamespaceSymbolBuilder.cs ├── Types │ └── TypeResolver.cs ├── Validation │ ├── ExpressionSemanticsValidator.cs │ ├── SymbolValidator.cs │ ├── TypeFulfillmentValidator.cs │ └── TypeKnownValidator.cs └── Variables │ ├── BindingMutability │ ├── BindingMutabilityAnalysis.cs │ └── BindingMutabilityAnalyzer.cs │ ├── DefiniteAssignment │ ├── DefiniteAssignmentAnalysis.cs │ └── DefiniteAssignmentAnalyzer.cs │ ├── Moves │ ├── UseOfMovedValueAnalysis.cs │ └── UseOfMovedValueAnalyzer.cs │ └── Shadowing │ ├── BindingScope.cs │ ├── EmptyBindingScope.cs │ ├── ShadowChecker.cs │ ├── VariableBinding.cs │ └── VariableBindingScope.cs ├── Symbols ├── BindingSymbol.cs ├── ConstructorSymbol.cs ├── FieldSymbol.cs ├── FunctionOrMethodSymbol.cs ├── FunctionSymbol.cs ├── InternalsVisibleTo.cs ├── InvocableSymbol.cs ├── MethodSymbol.cs ├── NamedBindingSymbol.cs ├── NamespaceOrPackageSymbol.cs ├── NamespaceSymbol.cs ├── ObjectTypeSymbol.cs ├── PackageSymbol.cs ├── PrimitiveTypeSymbol.cs ├── README.md ├── Reachability │ ├── ParameterReference.cs │ ├── ReachabilityAnnotation.cs │ ├── ReachabilityChain.cs │ ├── ReachableReferences.cs │ ├── Reference.cs │ ├── ReturnReference.cs │ └── SelfParameterReference.cs ├── SelfParameterSymbol.cs ├── Symbol.cs ├── Symbols.csproj ├── Trees │ ├── FixedSymbolTree.cs │ ├── ISymbolTree.cs │ ├── PrimitiveSymbolTree.cs │ ├── SymbolForest.cs │ └── SymbolTreeBuilder.cs ├── TypeSymbol.cs └── VariableSymbol.cs ├── Tests.Asserts ├── DiagnosticAsserts.cs ├── GlobalSuppressions.cs ├── README.md ├── Tests.Asserts.csproj └── TypeAsserts.cs ├── Tests.Conformance ├── ConformanceTests.cs ├── GlobalSuppressions.cs ├── Helpers │ ├── CompilerOutputAdapter.cs │ ├── RuntimeLibraryFixture.cs │ └── TestCase.cs └── Tests.Conformance.csproj ├── Tests.Unit.CodeGen ├── GlobalSuppressions.cs ├── ParserTests.cs └── Tests.Unit.CodeGen.csproj ├── Tests.Unit.Core ├── Tests.Unit.Core.csproj └── TextLinesTests.cs ├── Tests.Unit.Emit.C ├── GlobalSuppressions.cs ├── NameManglerTests.cs ├── ResourcesTests.cs └── Tests.Unit.Emit.C.csproj ├── Tests.Unit.Framework ├── EnumerableExtensionTests.cs ├── FixedListTests.cs ├── FixedSetTests.cs ├── GlobalSuppressions.cs ├── Tests.Unit.Framework.csproj └── YieldTests.cs ├── Tests.Unit.Lexing ├── Fakes │ └── FakeParseContext.cs ├── GlobalSuppressions.cs ├── Helpers │ ├── Arbitrary.cs │ ├── AssertExtensions.cs │ ├── DebugFormatExtensions.cs │ ├── LexResult.cs │ └── PsuedoToken.cs ├── LexerTests.cs └── Tests.Unit.Lexing.csproj ├── Tests.Unit.Names ├── GlobalSuppressions.cs ├── NamespaceNameTests.cs └── Tests.Unit.Names.csproj ├── Tests.Unit.Semantics.Reachability.Graph ├── CallerVariableTests.cs ├── GlobalSuppressions.cs ├── MoqExtensions.cs ├── ReachabilityGraphTests.cs ├── Tests.Unit.Semantics.Reachability.Graph.csproj └── VariableTests.cs ├── Tests.Unit.Symbols ├── ConstructorTests.cs ├── FunctionSymbolTests.cs ├── GlobalSuppressions.cs ├── MethodSymbolTests.cs ├── NamespaceSymbolTests.cs ├── PackageSymbolTests.cs ├── SymbolTests.cs ├── Tests.Unit.Symbols.csproj ├── TypeSymbolTests.cs └── VariableSymbolTests.cs ├── Tests.Unit.Types ├── AnyTypeTests.cs ├── BoolConstantTypeTests.cs ├── BoolTypeTests.cs ├── DataTypeExtensionsTests.cs ├── DataTypeTests.cs ├── GlobalSuppressions.cs ├── IntegerConstantTypeTests.cs ├── NeverTypeTests.cs ├── ObjectTypeTests.cs ├── OptionalTypeTests.cs ├── ReferenceCapabilityTests.cs ├── SizedIntegerTypeTests.cs ├── Tests.Unit.Types.csproj ├── UnknownTypeTests.cs ├── UnsizedIntegerTypeTests.cs └── VoidTypeTests.cs ├── Tests.Unit ├── CSharpNameResolutionTests.cs ├── DotNetFrameworkTests.cs ├── Fakes │ ├── FakeCodeFile.cs │ └── FakeCodeReference.cs ├── Helpers │ ├── GeneratorExtensions.cs │ └── SolutionDirectory.cs ├── README.md ├── SymbolTestFixture.cs └── Tests.Unit.csproj ├── Tokens ├── BareIdentifierToken.cs ├── EscapedIdentifierToken.cs ├── FalseKeywordToken.cs ├── IAccessModifierToken.cs ├── IAccessOperatorToken.cs ├── IAssignmentToken.cs ├── IBareIdentifierToken.cs ├── IBinaryOperatorToken.cs ├── IBindingToken.cs ├── IBooleanLiteralToken.cs ├── ICapabilityToken.cs ├── IEscapedIdentifierToken.cs ├── IEssentialToken.cs ├── IIdentifierOrUnderscoreToken.cs ├── IIntegerLiteralToken.cs ├── IKeywordToken.cs ├── ILiteralToken.cs ├── IMemberNameToken.cs ├── IModiferToken.cs ├── IOperatorToken.cs ├── IPrimitiveTypeToken.cs ├── IPunctuationToken.cs ├── IStringLiteralToken.cs ├── IToken.cs ├── ITriviaToken.cs ├── ITypeKindKeywordToken.cs ├── IdentifierToken.cs ├── IntegerLiteralToken.cs ├── KeywordTokens.cs ├── KeywordTokens.tt ├── OperatorPrecedence.cs ├── README.md ├── StringLiteralToken.cs ├── Token.cs ├── TokenTypes.Keywords.cs ├── TokenTypes.ReservedWord.cs ├── Tokens.cs ├── Tokens.csproj ├── Tokens.tt └── TrueKeywordToken.cs ├── Types ├── AnyType.cs ├── BoolConstantType.cs ├── BoolType.cs ├── DataType.cs ├── DataTypeExtensions.cs ├── EmptyType.cs ├── FixedSizeIntegerType.cs ├── IntegerConstantType.cs ├── IntegerType.cs ├── InternalsVisibleTo.cs ├── Metatype.cs ├── NeverType.cs ├── NumericType.cs ├── ObjectType.cs ├── OptionalType.cs ├── PointerSizedIntegerType.cs ├── README.md ├── ReferenceCapability.cs ├── ReferenceCapabilityExtensions.cs ├── ReferenceType.cs ├── ReferenceTypeExtensions.cs ├── SimpleType.cs ├── StringConstantType.cs ├── TypeSemantics.cs ├── Types.csproj ├── UnknownType.cs ├── ValueType.cs └── VoidType.cs ├── adamantc ├── Program.cs ├── Properties │ └── PublishProfiles │ │ └── Win-x64.pubxml └── adamantc.csproj ├── docs ├── CoreFeatures.md └── Implemented.md ├── forge ├── Build │ ├── Project.cs │ ├── ProjectReference.cs │ └── ProjectSet.cs ├── CommandOptionExtensions.cs ├── Config │ ├── ProjectConfig.cs │ ├── ProjectConfigSet.cs │ ├── ProjectDependencyConfig.cs │ └── ProjectTemplate.cs ├── Program.cs └── forge.csproj └── runtime ├── .gitignore ├── forge-project.vson └── src ├── Optional.ad └── String.ad /.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | 3 | # top-most EditorConfig file 4 | root = true 5 | 6 | [*] 7 | indent_style = space 8 | indent_size = 4 9 | charset = utf-8 10 | trim_trailing_whitespace = true 11 | insert_final_newline = true 12 | 13 | [*.{c,h,rsrc,ail}] 14 | end_of_line = lf 15 | 16 | [*.{xml,csproj}] 17 | indent_size = 2 18 | 19 | [*.{bat,cs,sln,csproj}] 20 | end_of_line = crlf 21 | 22 | # .NET formatting settings: 23 | [*.cs] 24 | dotnet_sort_system_directives_first = true 25 | 26 | # CA1062: Validate arguments of public methods 27 | dotnet_diagnostic.CA1062.severity = silent 28 | 29 | # CA1715: Identifiers should have correct prefix 30 | dotnet_diagnostic.CA1715.severity = silent 31 | 32 | # CA1710: Identifiers should have correct suffix 33 | dotnet_diagnostic.CA1710.severity = silent 34 | 35 | # CA1032: Implement standard exception constructors 36 | dotnet_diagnostic.CA1032.severity = silent 37 | 38 | # CA1303: Do not pass literals as localized parameters 39 | dotnet_diagnostic.CA1303.severity = silent 40 | 41 | # CA1716: Identifiers should not match keywords 42 | dotnet_diagnostic.CA1716.severity = silent 43 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | 3 | *.vson text eol=lf encoding=UTF-8 4 | *.json text eol=lf encoding=UTF-8 5 | *.ad text encoding=UTF-8 6 | *.md text 7 | *.bat text eol=crlf 8 | *.c text eol=lf 9 | *.h text eol=lf 10 | *.rsrc text eol=lf 11 | *.sh text eol=lf 12 | *.yml text eol=lf 13 | 14 | *.cs text eol=crlf 15 | *.sln text eol=crlf 16 | *.csproj text eol=crlf 17 | 18 | # These files must be UTF-8 w/ BOM to work, so treat them as binary 19 | RuntimeLibrary.c binary 20 | RuntimeLibrary.h binary 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # VS Files 2 | .vs/ 3 | bin/ 4 | obj/ 5 | *.user 6 | launchSettings.json 7 | 8 | # VS Code Files 9 | .vscode/ 10 | 11 | # OSX Files 12 | .DS_Store 13 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "stdlib"] 2 | path = stdlib 3 | url = https://github.com/adamant/adamant.stdlib.git 4 | [submodule "tests"] 5 | path = tests 6 | url = https://github.com/adamant/adamant.language.tests.git 7 | [submodule "katas"] 8 | path = katas 9 | url = https://github.com/adamant/adamant.katas.git 10 | -------------------------------------------------------------------------------- /API/README.md: -------------------------------------------------------------------------------- 1 | # Adamant.Tools.Compiler 2 | 3 | The API project contains classes in the `Adamant.Tools.Compiler` namespace that form an API to using the compiler. 4 | -------------------------------------------------------------------------------- /AST/IAbstractSyntax.cs: -------------------------------------------------------------------------------- 1 | namespace Adamant.Tools.Compiler.Bootstrap.AST 2 | { 3 | public partial interface IAbstractSyntax 4 | { 5 | string ToString(); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /AST/IExpression.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Tokens; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.AST 4 | { 5 | public partial interface IExpression 6 | { 7 | string ToGroupedString(OperatorPrecedence surroundingPrecedence); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /CST/AccessModifier.cs: -------------------------------------------------------------------------------- 1 | namespace Adamant.Tools.Compiler.Bootstrap.CST 2 | { 3 | public enum AccessModifier 4 | { 5 | Private = 1, 6 | Public, 7 | Published, 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /CST/IArgumentSyntax.cs: -------------------------------------------------------------------------------- 1 | namespace Adamant.Tools.Compiler.Bootstrap.CST 2 | { 3 | /// 4 | /// This is needed because it is not possible to put ref IExpressionSyntax 5 | /// directly into a list. 6 | /// 7 | /// TODO remove type once expression is immutable 8 | /// 9 | public partial interface IArgumentSyntax 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /CST/IBlockExpressionSyntax.cs: -------------------------------------------------------------------------------- 1 | namespace Adamant.Tools.Compiler.Bootstrap.CST 2 | { 3 | /// 4 | /// A block expression. Not to be used to represent function 5 | /// or type bodies. 6 | /// 7 | public partial interface IBlockExpressionSyntax 8 | { 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /CST/IBodyStatementSyntax.cs: -------------------------------------------------------------------------------- 1 | namespace Adamant.Tools.Compiler.Bootstrap.CST 2 | { 3 | /// 4 | /// A statement that can appear directly in a method body. (i.e. not a result statement) 5 | /// 6 | public partial interface IBodyStatementSyntax 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /CST/IBorrowExpressionSyntax.cs: -------------------------------------------------------------------------------- 1 | namespace Adamant.Tools.Compiler.Bootstrap.CST 2 | { 3 | /// 4 | /// i.e. `mut exp`. A borrow expression causes a borrow from a variable. That 5 | /// is, the result is a borrow of the value referenced. Note that borrow expressions 6 | /// don't apply to value types since they are passed by move, copy, or reference. 7 | /// 8 | public partial interface IBorrowExpressionSyntax 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /CST/IClassDeclarationSyntax.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Symbols.Trees; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.CST 4 | { 5 | public partial interface IClassDeclarationSyntax 6 | { 7 | void CreateDefaultConstructor(SymbolTreeBuilder symbolTree); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /CST/IDeclarationSyntax.cs: -------------------------------------------------------------------------------- 1 | namespace Adamant.Tools.Compiler.Bootstrap.CST 2 | { 3 | public partial interface IDeclarationSyntax 4 | { 5 | /// 6 | /// The span of whatever would count as the "name" of this declaration 7 | /// for things like operator overloads, constructors and destructors, 8 | /// this won't be just an identifier. For example, it could be: 9 | /// * "operator +" 10 | /// * "new foo" 11 | /// * "delete" 12 | /// 13 | //TextSpan NameSpan { get; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /CST/IEntityDeclarationSyntax.cs: -------------------------------------------------------------------------------- 1 | namespace Adamant.Tools.Compiler.Bootstrap.CST 2 | { 3 | /// 4 | /// All non-namespace declarations since a namespace doesn't really create 5 | /// a thing, it just defines a group of names. 6 | /// 7 | public partial interface IEntityDeclarationSyntax 8 | { 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /CST/IExpressionSyntax.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics.CodeAnalysis; 2 | using Adamant.Tools.Compiler.Bootstrap.Core; 3 | using Adamant.Tools.Compiler.Bootstrap.Tokens; 4 | using Adamant.Tools.Compiler.Bootstrap.Types; 5 | 6 | namespace Adamant.Tools.Compiler.Bootstrap.CST 7 | { 8 | public partial interface IExpressionSyntax 9 | { 10 | [DisallowNull] DataType? DataType { get; set; } 11 | [DisallowNull] ExpressionSemantics? Semantics { get; set; } 12 | string ToGroupedString(OperatorPrecedence surroundingPrecedence); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /CST/IHasContainingLexicalScope.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.LexicalScopes; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.CST 4 | { 5 | public interface IHasContainingLexicalScope 6 | { 7 | LexicalScope ContainingLexicalScope { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /CST/IImplicitImmutabilityConversionExpressionSyntax.cs: -------------------------------------------------------------------------------- 1 | namespace Adamant.Tools.Compiler.Bootstrap.CST 2 | { 3 | /// 4 | /// Cast away mutability 5 | /// 6 | public partial interface IImplicitImmutabilityConversionExpressionSyntax 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /CST/IImplicitNoneConversionExpressionSyntax.cs: -------------------------------------------------------------------------------- 1 | namespace Adamant.Tools.Compiler.Bootstrap.CST 2 | { 3 | /// 4 | /// Convert `none` to a specific optional type 5 | /// 6 | // TODO is this needed? shouldn't `none` have the type `never?` which would have an implicit conversion? 7 | public partial interface IImplicitNoneConversionExpressionSyntax 8 | { 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /CST/IImplicitNumericConversionExpressionSyntax.cs: -------------------------------------------------------------------------------- 1 | namespace Adamant.Tools.Compiler.Bootstrap.CST 2 | { 3 | /// 4 | /// Implicit conversion between simple numeric types 5 | /// 6 | public partial interface IImplicitNumericConversionExpressionSyntax 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /CST/IImplicitOptionalConversionExpressionSyntax.cs: -------------------------------------------------------------------------------- 1 | namespace Adamant.Tools.Compiler.Bootstrap.CST 2 | { 3 | /// 4 | /// Convert a type to option of that type (i.e. "Some(value)") 5 | /// 6 | public partial interface IImplicitOptionalConversionExpressionSyntax 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /CST/IInvocableDeclarationSyntax.cs: -------------------------------------------------------------------------------- 1 | namespace Adamant.Tools.Compiler.Bootstrap.CST 2 | { 3 | /// 4 | /// Base type for any declaration that declares a callable thing 5 | /// 6 | public partial interface IInvocableDeclarationSyntax 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /CST/IMoveExpressionSyntax.cs: -------------------------------------------------------------------------------- 1 | namespace Adamant.Tools.Compiler.Bootstrap.CST 2 | { 3 | /// 4 | /// i.e. `move name`. A move takes ownership of something from a variable 5 | /// 6 | public partial interface IMoveExpressionSyntax 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /CST/INameExpressionSyntax.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Adamant.Tools.Compiler.Bootstrap.Core.Promises; 3 | using Adamant.Tools.Compiler.Bootstrap.Symbols; 4 | 5 | namespace Adamant.Tools.Compiler.Bootstrap.CST 6 | { 7 | /// 8 | /// An expression that is a single unqualified name 9 | /// 10 | public partial interface INameExpressionSyntax 11 | { 12 | IEnumerable> LookupInContainingScope(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /CST/INonMemberDeclarationSyntax.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Symbols; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.CST 4 | { 5 | /// 6 | /// Things that can be declared outside of a class 7 | /// 8 | public partial interface INonMemberDeclarationSyntax 9 | { 10 | NamespaceOrPackageSymbol ContainingNamespaceSymbol { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /CST/INonMemberEntityDeclarationSyntax.cs: -------------------------------------------------------------------------------- 1 | namespace Adamant.Tools.Compiler.Bootstrap.CST 2 | { 3 | /// 4 | /// Basically, non-member, non-namespace declarations 5 | /// 6 | public partial interface INonMemberEntityDeclarationSyntax 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /CST/IShareExpressionSyntax.cs: -------------------------------------------------------------------------------- 1 | namespace Adamant.Tools.Compiler.Bootstrap.CST 2 | { 3 | /// 4 | /// A bare variable of a reference type is generally a share of that reference. 5 | /// Share expressions are inserted into the AST where needed to reflect this. 6 | /// 7 | public partial interface IShareExpressionSyntax 8 | { 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /CST/ISyntax.cs: -------------------------------------------------------------------------------- 1 | namespace Adamant.Tools.Compiler.Bootstrap.CST 2 | { 3 | public partial interface ISyntax 4 | { 5 | string ToString(); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /CST/ITypeNameSyntax.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Adamant.Tools.Compiler.Bootstrap.Core.Promises; 3 | using Adamant.Tools.Compiler.Bootstrap.Symbols; 4 | 5 | namespace Adamant.Tools.Compiler.Bootstrap.CST 6 | { 7 | public partial interface ITypeNameSyntax 8 | { 9 | IEnumerable> LookupInContainingScope(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /CST/ITypeSyntax.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics.CodeAnalysis; 2 | using Adamant.Tools.Compiler.Bootstrap.Types; 3 | 4 | namespace Adamant.Tools.Compiler.Bootstrap.CST 5 | { 6 | public partial interface ITypeSyntax 7 | { 8 | [DisallowNull] DataType? NamedType { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /CST/IUnqualifiedInvocationExpressionSyntax.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Adamant.Tools.Compiler.Bootstrap.Core.Promises; 3 | using Adamant.Tools.Compiler.Bootstrap.Symbols; 4 | 5 | namespace Adamant.Tools.Compiler.Bootstrap.CST 6 | { 7 | public partial interface IUnqualifiedInvocationExpressionSyntax 8 | { 9 | IEnumerable> LookupInContainingScope(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /CodeGen/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.CompilerServices; 2 | 3 | [assembly: InternalsVisibleTo("Adamant.Tools.Compiler.Bootstrap.Tests.Unit.CodeGen")] 4 | -------------------------------------------------------------------------------- /CodeGen/ChildrenCodeTemplate.custom.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using Adamant.Tools.Compiler.Bootstrap.CodeGen.Config; 3 | 4 | namespace Adamant.Tools.Compiler.Bootstrap.CodeGen 5 | { 6 | public partial class ChildrenCodeTemplate 7 | { 8 | private readonly Grammar grammar; 9 | 10 | public ChildrenCodeTemplate(Grammar grammar) 11 | { 12 | this.grammar = grammar; 13 | } 14 | 15 | private string TypeName(GrammarSymbol symbol) 16 | { 17 | if (symbol.IsQuoted) 18 | return symbol.Text; 19 | 20 | // If it is a nonterminal, then transform the name 21 | if (grammar.Rules.Any(r => r.Nonterminal == symbol)) 22 | return $"{grammar.Prefix}{symbol.Text}{grammar.Suffix}"; 23 | 24 | return symbol.Text; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /CodeGen/CodeBuilder.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.CodeGen.Config; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.CodeGen 4 | { 5 | public static class CodeBuilder 6 | { 7 | public static string GenerateTree(Grammar grammar) 8 | { 9 | var template = new TreeCodeTemplate(grammar); 10 | return template.TransformText(); 11 | } 12 | 13 | public static string GenerateChildren(Grammar grammar) 14 | { 15 | var template = new ChildrenCodeTemplate(grammar); 16 | return template.TransformText(); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /CodeGen/Config/GrammarProperty.cs: -------------------------------------------------------------------------------- 1 | namespace Adamant.Tools.Compiler.Bootstrap.CodeGen.Config 2 | { 3 | public class GrammarProperty 4 | { 5 | public string Name { get; } 6 | public GrammarType Type { get; } 7 | 8 | public GrammarProperty(string name, GrammarType type) 9 | { 10 | Name = name; 11 | Type = type; 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /CodeGen/Config/GrammarRule.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Adamant.Tools.Compiler.Bootstrap.Framework; 3 | 4 | namespace Adamant.Tools.Compiler.Bootstrap.CodeGen.Config 5 | { 6 | public class GrammarRule 7 | { 8 | public GrammarSymbol Nonterminal { get; } 9 | public FixedList Parents { get; } 10 | 11 | public FixedList Properties { get; } 12 | 13 | public GrammarRule( 14 | GrammarSymbol nonterminal, 15 | IEnumerable parents, 16 | IEnumerable properties) 17 | { 18 | Nonterminal = nonterminal; 19 | Parents = parents.ToFixedList(); 20 | Properties = properties.ToFixedList(); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /CodeGen/TreeCodeTemplate.tt: -------------------------------------------------------------------------------- 1 | <#@ template language="C#" #> 2 | <#@ assembly name="System.Core" #> 3 | <#@ import namespace="System.Linq" #> 4 | <#@ import namespace="System.Text" #> 5 | <#@ import namespace="System.Collections.Generic" #> 6 | <# foreach(var usingNamespace in OrderedNamespaces()) { #> 7 | using <#=usingNamespace #>; 8 | <# } #> 9 | 10 | namespace <#=grammar.Namespace #> 11 | { 12 | <# foreach(var rule in grammar.Rules) {#> 13 | <#=ClosedType(rule) #> public partial interface <#= TypeName(rule.Nonterminal) #><#= BaseTypes(rule) #> 14 | { 15 | <# foreach(var property in rule.Properties.Where(p => NeedsDeclared(rule, p))) { #> 16 | <#=IsNewDefinition(rule, property) ? "new " : "" #><#=TypeName(property.Type) #> <#=property.Name #> { get; } 17 | <# } #> 18 | } 19 | 20 | <# } #> 21 | } 22 | -------------------------------------------------------------------------------- /Core/CodeReference.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Framework; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.Core 4 | { 5 | /// Some kind of reference to where the source code came from. For example, 6 | /// this might be a path on disk or a network URL or a git hash or what 7 | /// template file the code was generated from. 8 | public abstract class CodeReference 9 | { 10 | public FixedList Namespace { get; } 11 | 12 | protected CodeReference(FixedList @namespace) 13 | { 14 | Namespace = @namespace; 15 | } 16 | 17 | public abstract override string ToString(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Core/DiagnosticLevel.cs: -------------------------------------------------------------------------------- 1 | namespace Adamant.Tools.Compiler.Bootstrap.Core 2 | { 3 | public enum DiagnosticLevel 4 | { 5 | Info = 1, 6 | Warning, 7 | /// 8 | /// An error which will occur at runtime but doesn't prevent compilation (i.e. pre-condition not met) 9 | /// 10 | RuntimeError, 11 | /// 12 | /// A compilation error that doesn't prevent further compilation. For example, using `!=` for 13 | /// not equal. 14 | /// 15 | CompilationError, 16 | /// 17 | /// An error which prevents further compilation steps 18 | /// 19 | FatalCompilationError, 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Core/DiagnosticPhase.cs: -------------------------------------------------------------------------------- 1 | namespace Adamant.Tools.Compiler.Bootstrap.Core 2 | { 3 | public enum DiagnosticPhase 4 | { 5 | Lexing = 1, 6 | Parsing, 7 | Analysis, 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Core/FatalCompilationErrorException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Adamant.Tools.Compiler.Bootstrap.Framework; 3 | 4 | namespace Adamant.Tools.Compiler.Bootstrap.Core 5 | { 6 | public class FatalCompilationErrorException : Exception 7 | { 8 | public FixedList Diagnostics { get; } 9 | 10 | public FatalCompilationErrorException(FixedList diagnostics) 11 | { 12 | Diagnostics = diagnostics; 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Core/ICodeFileSource.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.Core 4 | { 5 | /// 6 | /// A source for 7 | /// 8 | public interface ICodeFileSource 9 | { 10 | CodeFile Load(); 11 | Task LoadAsync(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Core/Operators/AccessOperator.cs: -------------------------------------------------------------------------------- 1 | namespace Adamant.Tools.Compiler.Bootstrap.Core.Operators 2 | { 3 | public enum AccessOperator 4 | { 5 | Standard, 6 | Conditional, 7 | } 8 | } -------------------------------------------------------------------------------- /Core/Operators/AccessOperatorExtensions.cs: -------------------------------------------------------------------------------- 1 | using ExhaustiveMatching; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.Core.Operators 4 | { 5 | public static class AccessOperatorExtensions 6 | { 7 | public static string ToSymbolString(this AccessOperator @operator) 8 | { 9 | return @operator switch 10 | { 11 | AccessOperator.Standard => ".", 12 | AccessOperator.Conditional => "?.", 13 | _ => throw ExhaustiveMatch.Failed(@operator) 14 | }; 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Core/Operators/AssignmentOperator.cs: -------------------------------------------------------------------------------- 1 | namespace Adamant.Tools.Compiler.Bootstrap.Core.Operators 2 | { 3 | public enum AssignmentOperator 4 | { 5 | Simple, 6 | Plus, 7 | Minus, 8 | Asterisk, 9 | Slash 10 | } 11 | } -------------------------------------------------------------------------------- /Core/Operators/AssignmentOperatorExtensions.cs: -------------------------------------------------------------------------------- 1 | using ExhaustiveMatching; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.Core.Operators 4 | { 5 | public static class AssignmentOperatorExtensions 6 | { 7 | public static string ToSymbolString(this AssignmentOperator @operator) 8 | { 9 | return @operator switch 10 | { 11 | AssignmentOperator.Simple => "=", 12 | AssignmentOperator.Plus => "+=", 13 | AssignmentOperator.Minus => "-=", 14 | AssignmentOperator.Asterisk => "*=", 15 | AssignmentOperator.Slash => "/=", 16 | _ => throw ExhaustiveMatch.Failed(@operator) 17 | }; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Core/Operators/BinaryOperator.cs: -------------------------------------------------------------------------------- 1 | namespace Adamant.Tools.Compiler.Bootstrap.Core.Operators 2 | { 3 | public enum BinaryOperator 4 | { 5 | Plus, 6 | Minus, 7 | Asterisk, 8 | Slash, 9 | EqualsEquals, 10 | NotEqual, 11 | LessThan, 12 | LessThanOrEqual, 13 | GreaterThan, 14 | GreaterThanOrEqual, 15 | And, 16 | Or, 17 | DotDot, 18 | LessThanDotDot, 19 | DotDotLessThan, 20 | LessThanDotDotLessThan, 21 | } 22 | } -------------------------------------------------------------------------------- /Core/Operators/UnaryOperator.cs: -------------------------------------------------------------------------------- 1 | namespace Adamant.Tools.Compiler.Bootstrap.Core.Operators 2 | { 3 | public enum UnaryOperator 4 | { 5 | Not, 6 | Minus, 7 | Plus, 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Core/Operators/UnaryOperatorExtensions.cs: -------------------------------------------------------------------------------- 1 | using ExhaustiveMatching; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.Core.Operators 4 | { 5 | public static class UnaryOperatorExtensions 6 | { 7 | public static string ToSymbolString(this UnaryOperator @operator) 8 | { 9 | switch (@operator) 10 | { 11 | default: 12 | throw ExhaustiveMatch.Failed(@operator); 13 | case UnaryOperator.Not: 14 | return "not "; 15 | case UnaryOperator.Minus: 16 | return "-"; 17 | case UnaryOperator.Plus: 18 | return "+"; 19 | } 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Core/Operators/UnaryOperatorFixity.cs: -------------------------------------------------------------------------------- 1 | namespace Adamant.Tools.Compiler.Bootstrap.Core.Operators 2 | { 3 | public enum UnaryOperatorFixity 4 | { 5 | Prefix, 6 | Postfix 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Core/ParseContext.cs: -------------------------------------------------------------------------------- 1 | namespace Adamant.Tools.Compiler.Bootstrap.Core 2 | { 3 | public class ParseContext 4 | { 5 | public CodeFile File { get; } 6 | public Diagnostics Diagnostics { get; } 7 | 8 | public ParseContext(CodeFile file, Diagnostics diagnostics) 9 | { 10 | File = file; 11 | Diagnostics = diagnostics; 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Core/Promises/DerivedPromise.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.Core.Promises 4 | { 5 | /// 6 | /// A promise derived from another promise by transforming the value 7 | /// 8 | internal class DerivedPromise : IPromise 9 | { 10 | private readonly IPromise promise; 11 | private readonly Func selector; 12 | 13 | public DerivedPromise(IPromise promise, Func selector) 14 | { 15 | this.promise = promise; 16 | this.selector = selector; 17 | } 18 | 19 | public bool IsFulfilled => promise.IsFulfilled; 20 | 21 | public S Result => selector(promise.Result); 22 | 23 | public IPromise? As() 24 | { 25 | if (this is IPromise convertedPromise) return convertedPromise; 26 | if (IsFulfilled && Result is TSub convertedValue) 27 | return new Promise(convertedValue); 28 | return null; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Core/Promises/IPromise.cs: -------------------------------------------------------------------------------- 1 | namespace Adamant.Tools.Compiler.Bootstrap.Core.Promises 2 | { 3 | public interface IPromise 4 | { 5 | bool IsFulfilled { get; } 6 | T Result { get; } 7 | /// 8 | /// Convert this promise to another kind of promise if possible. 9 | /// 10 | /// 11 | /// This can't be an extension method because it would have to have two 12 | /// type parameters. 13 | /// 14 | IPromise? As(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Core/Promises/PromiseExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.Core.Promises 4 | { 5 | public static class PromiseExtensions 6 | { 7 | public static IPromise Select(this IPromise promise, Func selector) 8 | { 9 | return new DerivedPromise(promise, selector); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Core/Promises/PromiseState.cs: -------------------------------------------------------------------------------- 1 | namespace Adamant.Tools.Compiler.Bootstrap.Core.Promises 2 | { 3 | public enum PromiseState 4 | { 5 | Pending = 0, 6 | InProgress, 7 | Fulfilled 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Core/README.md: -------------------------------------------------------------------------------- 1 | # Adamant.Tools.Compiler.Bootstrap.Core 2 | 3 | ## Naming Notes 4 | 5 | * Use `Code` instead of `Source`: The word "source" is often ambiguous. When combined with other words it is unclear whether it means the source code or simply the source of some data. Additionally, dictionaries do not give "source code" as one of the definitions of "source". The phrase "source code" is a little long, however, the word "code" does have a definition as computer code or source code. 6 | -------------------------------------------------------------------------------- /Emit.C/ConsoleCompilerOutput.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.Emit.C 4 | { 5 | public class ConsoleCompilerOutput : ICompilerOutput 6 | { 7 | #region Singleton 8 | public static readonly ConsoleCompilerOutput Instance = new ConsoleCompilerOutput(); 9 | 10 | private ConsoleCompilerOutput() { } 11 | #endregion 12 | 13 | public void WriteLine(string message) 14 | { 15 | Console.WriteLine(message); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Emit.C/ICompilerOutput.cs: -------------------------------------------------------------------------------- 1 | namespace Adamant.Tools.Compiler.Bootstrap.Emit.C 2 | { 3 | public interface ICompilerOutput 4 | { 5 | void WriteLine(string message); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Emit.C/IConverter.cs: -------------------------------------------------------------------------------- 1 | namespace Adamant.Tools.Compiler.Bootstrap.Emit.C 2 | { 3 | public interface IConverter 4 | { 5 | string Convert(T value); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Emit.C/IEmitter.cs: -------------------------------------------------------------------------------- 1 | namespace Adamant.Tools.Compiler.Bootstrap.Emit.C 2 | { 3 | public interface IEmitter 4 | { 5 | void Emit(T value, Code code); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Emit.C/InternalsVisibleTo.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.CompilerServices; 2 | 3 | [assembly: InternalsVisibleTo("Adamant.Tools.Compiler.Bootstrap.Tests.Unit.Emit.C")] 4 | -------------------------------------------------------------------------------- /Emit/Emitter.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.IntermediateLanguage; 2 | using Adamant.Tools.Compiler.Bootstrap.Semantics; 3 | 4 | namespace Adamant.Tools.Compiler.Bootstrap.Emit 5 | { 6 | public abstract class Emitter 7 | { 8 | public abstract void Emit(PackageIL package); 9 | public abstract string GetEmittedCode(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Framework/CollectionDebugView.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Diagnostics.CodeAnalysis; 5 | using System.Linq; 6 | 7 | namespace Adamant.Tools.Compiler.Bootstrap.Framework 8 | { 9 | /// 10 | /// This class is used in place of the FixedList[T] class by the debugger for 11 | /// display purposes. It just exposes the collection items as an array at the root. 12 | /// 13 | /// 14 | public sealed class CollectionDebugView 15 | where T : class 16 | { 17 | private readonly IEnumerable collection; 18 | 19 | public CollectionDebugView(IEnumerable collection) 20 | { 21 | this.collection = collection ?? throw new ArgumentNullException(nameof(collection)); 22 | } 23 | 24 | [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)] 25 | [SuppressMessage("Performance", "CA1819:Properties should not return arrays")] 26 | public T[] Items => collection.ToArray(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Framework/DictionaryDebugView.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Diagnostics.CodeAnalysis; 5 | using System.Linq; 6 | 7 | namespace Adamant.Tools.Compiler.Bootstrap.Framework 8 | { 9 | public sealed class DictionaryDebugView 10 | where K : notnull 11 | { 12 | private readonly IReadOnlyDictionary dictionary; 13 | 14 | public DictionaryDebugView(IReadOnlyDictionary dictionary) 15 | { 16 | this.dictionary = dictionary ?? throw new ArgumentNullException(nameof(dictionary)); 17 | } 18 | 19 | [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)] 20 | [SuppressMessage("Performance", "CA1819:Properties should not return arrays")] 21 | public KeyValuePair[] Items => dictionary.ToArray(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Framework/Generator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | 5 | namespace Adamant.Tools.Compiler.Bootstrap.Framework 6 | { 7 | /// 8 | /// Generates an infinite by repeatedly calling 9 | /// a generator function 10 | /// 11 | public class Generator : IEnumerable 12 | { 13 | private readonly Func generator; 14 | 15 | public Generator(Func generator) 16 | { 17 | this.generator = generator; 18 | } 19 | 20 | public IEnumerator GetEnumerator() 21 | { 22 | for (; ; ) 23 | yield return generator(); 24 | } 25 | 26 | IEnumerator IEnumerable.GetEnumerator() 27 | { 28 | return GetEnumerator(); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Framework/QueueExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.Framework 4 | { 5 | public static class QueueExtensions 6 | { 7 | public static void EnqueueRange(this Queue queue, IEnumerable items) 8 | { 9 | foreach (var item in items) 10 | queue.Enqueue(item); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Framework/SetExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.Framework 4 | { 5 | public static class SetExtensions 6 | { 7 | public static void AddRange(this ISet set, IEnumerable values) 8 | { 9 | foreach (var value in values) set.Add(value); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Framework/StackExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.Framework 4 | { 5 | public static class StackExtensions 6 | { 7 | public static void PushRange(this Stack stack, IEnumerable items) 8 | { 9 | foreach (var item in items) 10 | stack.Push(item); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Framework/TypeSet.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Adamant.Tools.Compiler.Bootstrap.Framework 5 | { 6 | /// 7 | /// A set of types 8 | /// 9 | /// The type all types in the set must inherit from 10 | public class TypeSet 11 | { 12 | private readonly ISet types = new HashSet(); 13 | 14 | public bool Add() 15 | where T : TBase 16 | { 17 | return types.Add(typeof(T)); 18 | } 19 | 20 | public bool Contains() 21 | where T : TBase 22 | { 23 | return types.Contains(typeof(T)); 24 | } 25 | 26 | public bool Contains(Type type) 27 | { 28 | return types.Contains(type); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Framework/UnreachableCodeException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | 4 | namespace Adamant.Tools.Compiler.Bootstrap.Framework 5 | { 6 | [Serializable] 7 | public class UnreachableCodeException : Exception 8 | { 9 | public UnreachableCodeException() 10 | { 11 | } 12 | 13 | public UnreachableCodeException(string message) 14 | : base(message) 15 | { 16 | 17 | } 18 | 19 | protected UnreachableCodeException(SerializationInfo info, StreamingContext context) 20 | : base(info, context) 21 | { 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Framework/Void.cs: -------------------------------------------------------------------------------- 1 | namespace Adamant.Tools.Compiler.Bootstrap.Framework 2 | { 3 | public struct Void 4 | { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /IntermediateLanguage/CFG/Block.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | using Adamant.Tools.Compiler.Bootstrap.Framework; 3 | using Adamant.Tools.Compiler.Bootstrap.IntermediateLanguage.CFG.Instructions; 4 | using Adamant.Tools.Compiler.Bootstrap.IntermediateLanguage.CFG.TerminatorInstructions; 5 | 6 | namespace Adamant.Tools.Compiler.Bootstrap.IntermediateLanguage.CFG 7 | { 8 | [DebuggerDisplay("{" + nameof(DebuggerDisplay) + ",nq}")] 9 | public class Block 10 | { 11 | public int Number { get; } 12 | public FixedList Instructions { get; } 13 | public TerminatorInstruction Terminator { get; } 14 | 15 | public Block(int number, FixedList instructions, TerminatorInstruction terminator) 16 | { 17 | Number = number; 18 | Instructions = instructions; 19 | Terminator = terminator; 20 | } 21 | 22 | [DebuggerBrowsable(DebuggerBrowsableState.Never)] 23 | private string DebuggerDisplay => $"BB #{Number}, Instructions={Instructions.Count+1}"; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /IntermediateLanguage/CFG/Instructions/AssignmentInstruction.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Core; 2 | using Adamant.Tools.Compiler.Bootstrap.IntermediateLanguage.CFG.Operands; 3 | using Adamant.Tools.Compiler.Bootstrap.IntermediateLanguage.CFG.Places; 4 | 5 | namespace Adamant.Tools.Compiler.Bootstrap.IntermediateLanguage.CFG.Instructions 6 | { 7 | public class AssignmentInstruction : InstructionWithResult 8 | { 9 | public Operand Operand { get; } 10 | 11 | public AssignmentInstruction(Place resultPlace, Operand operand, TextSpan span, Scope scope) 12 | : base(resultPlace, span, scope) 13 | { 14 | Operand = operand; 15 | } 16 | 17 | public override string ToInstructionString() 18 | { 19 | return $"{ResultPlace} = {Operand};"; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /IntermediateLanguage/CFG/Instructions/BooleanLogicOperator.cs: -------------------------------------------------------------------------------- 1 | using ExhaustiveMatching; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.IntermediateLanguage.CFG.Instructions 4 | { 5 | public enum BooleanLogicOperator 6 | { 7 | And = 1, 8 | Or, 9 | } 10 | 11 | public static class BooleanLogicOperatorExtensions 12 | { 13 | public static string ToInstructionString(this BooleanLogicOperator @operator) 14 | { 15 | return @operator switch 16 | { 17 | BooleanLogicOperator.And => "AND", 18 | BooleanLogicOperator.Or => "OR", 19 | _ => throw ExhaustiveMatch.Failed(@operator) 20 | }; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /IntermediateLanguage/CFG/Instructions/Instruction.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Core; 2 | using ExhaustiveMatching; 3 | 4 | namespace Adamant.Tools.Compiler.Bootstrap.IntermediateLanguage.CFG.Instructions 5 | { 6 | [Closed( 7 | typeof(CallInstruction), 8 | typeof(CallVirtualInstruction), 9 | typeof(InstructionWithResult))] 10 | public abstract class Instruction 11 | { 12 | public TextSpan Span { get; } 13 | public Scope Scope { get; } 14 | 15 | protected Instruction(TextSpan span, Scope scope) 16 | { 17 | Span = span; 18 | Scope = scope; 19 | } 20 | 21 | public override string ToString() 22 | { 23 | return ToInstructionString() + ContextCommentString(); 24 | } 25 | 26 | public abstract string ToInstructionString(); 27 | 28 | public virtual string ContextCommentString() 29 | { 30 | return $" // at {Span} in {Scope}"; 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /IntermediateLanguage/CFG/Instructions/LoadBoolInstruction.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Core; 2 | using Adamant.Tools.Compiler.Bootstrap.IntermediateLanguage.CFG.Places; 3 | using Adamant.Tools.Compiler.Bootstrap.Types; 4 | 5 | namespace Adamant.Tools.Compiler.Bootstrap.IntermediateLanguage.CFG.Instructions 6 | { 7 | public class LoadBoolInstruction : InstructionWithResult 8 | { 9 | public bool Value { get; } 10 | 11 | public LoadBoolInstruction(Place resultPlace, bool value, TextSpan span, Scope scope) 12 | : base(resultPlace, span, scope) 13 | { 14 | Value = value; 15 | } 16 | 17 | public override string ToInstructionString() 18 | { 19 | return $"{ResultPlace} = LOAD[{DataType.Bool}] {Value}"; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /IntermediateLanguage/CFG/Instructions/LoadIntegerInstruction.cs: -------------------------------------------------------------------------------- 1 | using System.Numerics; 2 | using Adamant.Tools.Compiler.Bootstrap.Core; 3 | using Adamant.Tools.Compiler.Bootstrap.IntermediateLanguage.CFG.Places; 4 | using Adamant.Tools.Compiler.Bootstrap.Types; 5 | 6 | namespace Adamant.Tools.Compiler.Bootstrap.IntermediateLanguage.CFG.Instructions 7 | { 8 | public class LoadIntegerInstruction : InstructionWithResult 9 | { 10 | public BigInteger Value { get; } 11 | public IntegerType Type { get; } 12 | 13 | public LoadIntegerInstruction(Place resultPlace, BigInteger value, IntegerType type, TextSpan span, Scope scope) 14 | : base(resultPlace, span, scope) 15 | { 16 | Value = value; 17 | Type = type; 18 | } 19 | 20 | public override string ToInstructionString() 21 | { 22 | return $"{ResultPlace} = LOAD[{Type}] {Value}"; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /IntermediateLanguage/CFG/Instructions/LoadNoneInstruction.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Core; 2 | using Adamant.Tools.Compiler.Bootstrap.IntermediateLanguage.CFG.Places; 3 | using Adamant.Tools.Compiler.Bootstrap.Types; 4 | 5 | namespace Adamant.Tools.Compiler.Bootstrap.IntermediateLanguage.CFG.Instructions 6 | { 7 | public class LoadNoneInstruction : InstructionWithResult 8 | { 9 | public OptionalType Type { get; } 10 | 11 | public LoadNoneInstruction(Place resultPlace, OptionalType type, TextSpan span, Scope scope) 12 | : base(resultPlace, span, scope) 13 | { 14 | Type = type; 15 | } 16 | 17 | public override string ToInstructionString() 18 | { 19 | return $"{ResultPlace} = LOAD[{Type}] none"; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /IntermediateLanguage/CFG/Instructions/LoadStringInstruction.cs: -------------------------------------------------------------------------------- 1 | using System.Text; 2 | using Adamant.Tools.Compiler.Bootstrap.Core; 3 | using Adamant.Tools.Compiler.Bootstrap.Framework; 4 | using Adamant.Tools.Compiler.Bootstrap.IntermediateLanguage.CFG.Places; 5 | 6 | namespace Adamant.Tools.Compiler.Bootstrap.IntermediateLanguage.CFG.Instructions 7 | { 8 | public class LoadStringInstruction : InstructionWithResult 9 | { 10 | public static readonly Encoding Encoding = new UTF8Encoding(false); 11 | 12 | public string Value { get; } 13 | 14 | public LoadStringInstruction(Place resultPlace, string value, TextSpan span, Scope scope) 15 | : base(resultPlace, span, scope) 16 | { 17 | Value = value; 18 | } 19 | 20 | public override string ToInstructionString() 21 | { 22 | return $"{ResultPlace} = LOAD \"{Value.Escape()}\""; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /IntermediateLanguage/CFG/Instructions/NegateInstruction.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Core; 2 | using Adamant.Tools.Compiler.Bootstrap.IntermediateLanguage.CFG.Operands; 3 | using Adamant.Tools.Compiler.Bootstrap.IntermediateLanguage.CFG.Places; 4 | using Adamant.Tools.Compiler.Bootstrap.Types; 5 | 6 | namespace Adamant.Tools.Compiler.Bootstrap.IntermediateLanguage.CFG.Instructions 7 | { 8 | public class NegateInstruction : InstructionWithResult 9 | { 10 | public Operand Operand { get; } 11 | public NumericType Type { get; } 12 | 13 | public NegateInstruction( 14 | Place resultPlace, 15 | NumericType type, 16 | Operand operand, 17 | TextSpan span, 18 | Scope scope) 19 | : base(resultPlace, span, scope) 20 | { 21 | Type = type; 22 | Operand = operand; 23 | } 24 | 25 | public override string ToInstructionString() 26 | { 27 | return $"{ResultPlace} = NEG[{Type}] {Operand}"; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /IntermediateLanguage/CFG/Instructions/NumericInstructionOperator.cs: -------------------------------------------------------------------------------- 1 | using ExhaustiveMatching; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.IntermediateLanguage.CFG.Instructions 4 | { 5 | public enum NumericInstructionOperator 6 | { 7 | Add, 8 | Subtract, 9 | Multiply, 10 | Divide, 11 | } 12 | 13 | public static class NumericInstructionOperatorExtensions 14 | { 15 | public static string ToInstructionString(this NumericInstructionOperator @operator) 16 | { 17 | return @operator switch 18 | { 19 | NumericInstructionOperator.Add => "ADD", 20 | NumericInstructionOperator.Subtract => "SUB", 21 | NumericInstructionOperator.Multiply => "MUL", 22 | NumericInstructionOperator.Divide => "DIV", 23 | _ => throw ExhaustiveMatch.Failed(@operator) 24 | }; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /IntermediateLanguage/CFG/Instructions/SomeInstruction.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Core; 2 | using Adamant.Tools.Compiler.Bootstrap.IntermediateLanguage.CFG.Operands; 3 | using Adamant.Tools.Compiler.Bootstrap.IntermediateLanguage.CFG.Places; 4 | using Adamant.Tools.Compiler.Bootstrap.Types; 5 | 6 | namespace Adamant.Tools.Compiler.Bootstrap.IntermediateLanguage.CFG.Instructions 7 | { 8 | /// 9 | /// Constructs a value of an optional type from the non-optional value 10 | /// 11 | public class SomeInstruction : InstructionWithResult 12 | { 13 | public Operand Operand { get; } 14 | public OptionalType Type { get; } 15 | 16 | public SomeInstruction(Place resultPlace, OptionalType type, Operand operand, TextSpan span, Scope scope) 17 | : base(resultPlace, span, scope) 18 | { 19 | Type = type; 20 | Operand = operand; 21 | } 22 | 23 | public override string ToInstructionString() 24 | { 25 | return $"{ResultPlace} = SOME[{Type}] {Operand}"; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /IntermediateLanguage/CFG/Operands/Operand.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Core; 2 | using ExhaustiveMatching; 3 | 4 | namespace Adamant.Tools.Compiler.Bootstrap.IntermediateLanguage.CFG.Operands 5 | { 6 | [Closed( 7 | typeof(VariableReference))] 8 | public abstract class Operand 9 | { 10 | public TextSpan Span { get; } 11 | 12 | protected Operand(in TextSpan span) 13 | { 14 | Span = span; 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /IntermediateLanguage/CFG/Places/FieldPlace.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Adamant.Tools.Compiler.Bootstrap.Core; 3 | using Adamant.Tools.Compiler.Bootstrap.IntermediateLanguage.CFG.Operands; 4 | using Adamant.Tools.Compiler.Bootstrap.Symbols; 5 | 6 | namespace Adamant.Tools.Compiler.Bootstrap.IntermediateLanguage.CFG.Places 7 | { 8 | public class FieldPlace : Place 9 | { 10 | public Operand Target { get; } 11 | public FieldSymbol Field { get; } 12 | 13 | public FieldPlace(Operand target, FieldSymbol field, TextSpan span) 14 | : base(span) 15 | { 16 | Target = target; 17 | Field = field; 18 | } 19 | 20 | public override Operand ToOperand(TextSpan span) 21 | { 22 | throw new NotImplementedException(); 23 | } 24 | 25 | public override string ToString() 26 | { 27 | return $"({Target}).{Field.Name}"; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /IntermediateLanguage/CFG/Places/Place.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Core; 2 | using Adamant.Tools.Compiler.Bootstrap.IntermediateLanguage.CFG.Operands; 3 | using ExhaustiveMatching; 4 | 5 | namespace Adamant.Tools.Compiler.Bootstrap.IntermediateLanguage.CFG.Places 6 | { 7 | [Closed( 8 | typeof(VariablePlace), 9 | typeof(FieldPlace))] 10 | public abstract class Place 11 | { 12 | public TextSpan Span { get; } 13 | 14 | protected Place(TextSpan span) 15 | { 16 | Span = span; 17 | } 18 | 19 | public abstract Operand ToOperand(TextSpan span); 20 | 21 | public abstract override string ToString(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /IntermediateLanguage/CFG/Places/VariablePlace.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Core; 2 | using Adamant.Tools.Compiler.Bootstrap.IntermediateLanguage.CFG.Operands; 3 | 4 | namespace Adamant.Tools.Compiler.Bootstrap.IntermediateLanguage.CFG.Places 5 | { 6 | public class VariablePlace : Place 7 | { 8 | public Variable Variable { get; } 9 | 10 | public VariablePlace(Variable variable, TextSpan span) 11 | : base(span) 12 | { 13 | Variable = variable; 14 | } 15 | 16 | public override Operand ToOperand(TextSpan span) 17 | { 18 | // TODO is this the correct value semantics? 19 | return new VariableReference(Variable, span); 20 | } 21 | 22 | public override string ToString() 23 | { 24 | return Variable.ToString(); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /IntermediateLanguage/CFG/StringConstant.cs: -------------------------------------------------------------------------------- 1 | using System.Text; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.IntermediateLanguage.CFG 4 | { 5 | public static class StringConstant 6 | { 7 | public static readonly Encoding Encoding = new UTF8Encoding(false); 8 | 9 | public static int GetByteLength(string value) 10 | { 11 | return Encoding.GetByteCount(value); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /IntermediateLanguage/CFG/TerminatorInstructions/GotoInstruction.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Core; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.IntermediateLanguage.CFG.TerminatorInstructions 4 | { 5 | public class GotoInstruction : TerminatorInstruction 6 | { 7 | public int BlockNumber { get; } 8 | 9 | public GotoInstruction(int blockNumber, TextSpan span, Scope scope) 10 | : base(span, scope) 11 | { 12 | BlockNumber = blockNumber; 13 | } 14 | 15 | public override string ToInstructionString() 16 | { 17 | return $"GOTO BB #{BlockNumber}"; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /IntermediateLanguage/CFG/TerminatorInstructions/IfInstruction.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Core; 2 | using Adamant.Tools.Compiler.Bootstrap.IntermediateLanguage.CFG.Operands; 3 | 4 | namespace Adamant.Tools.Compiler.Bootstrap.IntermediateLanguage.CFG.TerminatorInstructions 5 | { 6 | public class IfInstruction : TerminatorInstruction 7 | { 8 | public Operand Condition { get; } 9 | public int ThenBlockNumber { get; } 10 | public int ElseBlockNumber { get; } 11 | 12 | public IfInstruction( 13 | Operand condition, 14 | int thenBlockNumber, 15 | int elseBlockNumber, 16 | TextSpan span, 17 | Scope scope) 18 | : base(span, scope) 19 | { 20 | Condition = condition; 21 | ThenBlockNumber = thenBlockNumber; 22 | ElseBlockNumber = elseBlockNumber; 23 | } 24 | 25 | public override string ToInstructionString() 26 | { 27 | return $"IF {Condition} GOTO BB #{ThenBlockNumber} ELSE GOTO BB #{ElseBlockNumber};"; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /IntermediateLanguage/CFG/TerminatorInstructions/ReturnValueInstruction.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Core; 2 | using Adamant.Tools.Compiler.Bootstrap.IntermediateLanguage.CFG.Operands; 3 | 4 | namespace Adamant.Tools.Compiler.Bootstrap.IntermediateLanguage.CFG.TerminatorInstructions 5 | { 6 | public class ReturnValueInstruction : TerminatorInstruction 7 | { 8 | public Operand Value { get; } 9 | 10 | public ReturnValueInstruction(Operand value, TextSpan span, Scope scope) 11 | : base(span, scope) 12 | { 13 | Value = value; 14 | } 15 | 16 | public override string ToInstructionString() 17 | { 18 | return $"RETURN {Value}"; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /IntermediateLanguage/CFG/TerminatorInstructions/ReturnVoidInstruction.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Core; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.IntermediateLanguage.CFG.TerminatorInstructions 4 | { 5 | public class ReturnVoidInstruction : TerminatorInstruction 6 | { 7 | public ReturnVoidInstruction(TextSpan span, Scope scope) 8 | : base(span, scope) 9 | 10 | { 11 | } 12 | 13 | public override string ToInstructionString() 14 | { 15 | return "RETURN"; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /IntermediateLanguage/ClassIL.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Framework; 2 | using Adamant.Tools.Compiler.Bootstrap.Symbols; 3 | 4 | namespace Adamant.Tools.Compiler.Bootstrap.IntermediateLanguage 5 | { 6 | public class ClassIL : DeclarationIL 7 | { 8 | public FixedList Members { get; } 9 | public new ObjectTypeSymbol Symbol { get; } 10 | 11 | public ClassIL(ObjectTypeSymbol symbol, FixedList members) 12 | : base(false, symbol) 13 | { 14 | Symbol = symbol; 15 | Members = members; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /IntermediateLanguage/DeclarationIL.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Symbols; 2 | using ExhaustiveMatching; 3 | 4 | namespace Adamant.Tools.Compiler.Bootstrap.IntermediateLanguage 5 | { 6 | // TODO consider naming these just Class, Function, Field, Constructor. While they are declarations, the IL is what we think of as actually being the thing of which the code is declaring 7 | [Closed( 8 | typeof(ClassIL), 9 | typeof(FunctionIL), 10 | typeof(MethodDeclarationIL), 11 | typeof(FieldIL), 12 | typeof(ConstructorIL))] 13 | public abstract class DeclarationIL 14 | { 15 | public bool IsMember { get; } 16 | public Symbol Symbol { get; } 17 | 18 | protected DeclarationIL(bool isMember, Symbol symbol) 19 | { 20 | IsMember = isMember; 21 | Symbol = symbol; 22 | } 23 | 24 | public override string ToString() 25 | { 26 | return Symbol.ToString(); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /IntermediateLanguage/FieldIL.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Symbols; 2 | using Adamant.Tools.Compiler.Bootstrap.Types; 3 | 4 | namespace Adamant.Tools.Compiler.Bootstrap.IntermediateLanguage 5 | { 6 | public class FieldIL : DeclarationIL 7 | { 8 | public bool IsMutableBinding => Symbol.IsMutableBinding; 9 | public DataType DataType => Symbol.DataType; 10 | public new FieldSymbol Symbol { get; } 11 | 12 | public FieldIL(FieldSymbol symbol) 13 | : base(true, symbol) 14 | { 15 | Symbol = symbol; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /IntermediateLanguage/FieldInitializationIL.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Symbols; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.IntermediateLanguage 4 | { 5 | /// 6 | /// A field initialization in an initialization caused by a constructor parameter 7 | /// 8 | public class FieldInitializationIL 9 | { 10 | public FieldSymbol Field { get; } 11 | 12 | public FieldInitializationIL(FieldSymbol field) 13 | { 14 | Field = field; 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /IntermediateLanguage/FieldParameterIL.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Symbols; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.IntermediateLanguage 4 | { 5 | public sealed class FieldParameterIL : ParameterIL 6 | { 7 | public new FieldSymbol InitializeField { get; } 8 | 9 | public FieldParameterIL(FieldSymbol initializeField) 10 | : base(null, false, initializeField.DataType, initializeField) 11 | { 12 | InitializeField = initializeField; 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /IntermediateLanguage/IInvocableDeclarationIL.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Framework; 2 | using Adamant.Tools.Compiler.Bootstrap.IntermediateLanguage.CFG; 3 | using ExhaustiveMatching; 4 | 5 | namespace Adamant.Tools.Compiler.Bootstrap.IntermediateLanguage 6 | { 7 | [Closed( 8 | typeof(FunctionIL), 9 | typeof(MethodDeclarationIL), 10 | typeof(ConstructorIL))] 11 | public interface IInvocableDeclarationIL 12 | { 13 | bool IsConstructor { get; } 14 | FixedList Parameters { get; } 15 | ControlFlowGraph? IL { get; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /IntermediateLanguage/NamedParameterIL.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Symbols; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.IntermediateLanguage 4 | { 5 | public sealed class NamedParameterIL : ParameterIL 6 | { 7 | public new VariableSymbol Symbol { get; } 8 | 9 | public NamedParameterIL(VariableSymbol symbol) 10 | : base(symbol, symbol.IsMutableBinding, symbol.DataType) 11 | { 12 | Symbol = symbol; 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /IntermediateLanguage/ParameterIL.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Symbols; 2 | using Adamant.Tools.Compiler.Bootstrap.Types; 3 | using ExhaustiveMatching; 4 | 5 | namespace Adamant.Tools.Compiler.Bootstrap.IntermediateLanguage 6 | { 7 | [Closed( 8 | typeof(SelfParameterIL), 9 | typeof(NamedParameterIL), 10 | typeof(FieldParameterIL))] 11 | public abstract class ParameterIL 12 | { 13 | public BindingSymbol? Symbol { get; } 14 | public bool IsMutableBinding { get; } 15 | public DataType DataType { get; internal set; } 16 | public FieldSymbol? InitializeField { get; } 17 | 18 | protected ParameterIL( 19 | BindingSymbol? symbol, 20 | bool isMutableBinding, 21 | DataType type, 22 | FieldSymbol? initializeField = null) 23 | { 24 | Symbol = symbol; 25 | IsMutableBinding = isMutableBinding; 26 | DataType = type; 27 | InitializeField = initializeField; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /IntermediateLanguage/SelfParameterIL.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Symbols; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.IntermediateLanguage 4 | { 5 | public sealed class SelfParameterIL : ParameterIL 6 | { 7 | public new SelfParameterSymbol Symbol { get; } 8 | 9 | public SelfParameterIL(SelfParameterSymbol symbol) 10 | : base(symbol, symbol.IsMutableBinding, symbol.DataType) 11 | { 12 | Symbol = symbol; 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Jeff Walker 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /LexicalScopes/LexicalScope.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Adamant.Tools.Compiler.Bootstrap.Core; 3 | using Adamant.Tools.Compiler.Bootstrap.Core.Promises; 4 | using Adamant.Tools.Compiler.Bootstrap.Names; 5 | using Adamant.Tools.Compiler.Bootstrap.Symbols; 6 | 7 | namespace Adamant.Tools.Compiler.Bootstrap.LexicalScopes 8 | { 9 | /// 10 | /// Lookup things by name in lexical scopes 11 | /// 12 | public abstract class LexicalScope 13 | { 14 | internal abstract PackagesScope ContainingPackagesScope { get; } 15 | 16 | public virtual PackageSymbol? LookupPackage(Name name) 17 | { 18 | return ContainingPackagesScope.LookupPackage(name); 19 | } 20 | 21 | public abstract IEnumerable> LookupInGlobalScope(TypeName name); 22 | 23 | public abstract IEnumerable> Lookup(TypeName name, bool includeNested = true); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /LexicalScopes/LexicalScopes.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.0 5 | Adamant.Tools.Compiler.Bootstrap.LexicalScopes 6 | Adamant.Tools.Compiler.Bootstrap.LexicalScopes 7 | enable 8 | 9 | 10 | 11 | DEBUG;TRACE 12 | true 13 | 14 | 15 | 16 | true 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Lexing/ITokenIterator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Adamant.Tools.Compiler.Bootstrap.Core; 3 | using Adamant.Tools.Compiler.Bootstrap.Tokens; 4 | 5 | namespace Adamant.Tools.Compiler.Bootstrap.Lexing 6 | { 7 | public interface ITokenIterator 8 | where TToken : class, IToken 9 | { 10 | ParseContext Context { get; } 11 | 12 | bool Next(); 13 | 14 | /// If current is accessed after Next() has returned false 15 | TToken Current { get; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Lexing/TokenIterator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Adamant.Tools.Compiler.Bootstrap.Core; 4 | using Adamant.Tools.Compiler.Bootstrap.Tokens; 5 | 6 | namespace Adamant.Tools.Compiler.Bootstrap.Lexing 7 | { 8 | public class TokenIterator : ITokenIterator 9 | where TToken : class, IToken 10 | { 11 | public ParseContext Context { get; } 12 | private IEnumerator? tokens; 13 | 14 | public TokenIterator(ParseContext context, IEnumerable tokens) 15 | { 16 | Context = context; 17 | this.tokens = tokens.GetEnumerator(); 18 | Next(); 19 | } 20 | 21 | public bool Next() 22 | { 23 | if (tokens is null) 24 | return false; 25 | if (!tokens.MoveNext()) 26 | tokens = null; 27 | return tokens != null; 28 | } 29 | 30 | public TToken Current => (tokens ?? throw new InvalidOperationException("Can't access `TokenIterator.Current` after `Next()` has returned false")).Current; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Parsing/ModifierParser.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Lexing; 2 | using Adamant.Tools.Compiler.Bootstrap.Tokens; 3 | 4 | namespace Adamant.Tools.Compiler.Bootstrap.Parsing 5 | { 6 | internal class ModifierParser : RecursiveDescentParser 7 | { 8 | public ModifierParser(ITokenIterator tokens) 9 | : base(tokens) { } 10 | 11 | public IAccessModifierToken? ParseAccessModifier() 12 | { 13 | return Tokens.Current switch 14 | { 15 | IAccessModifierToken _ => Tokens.RequiredToken(), 16 | _ => null 17 | }; 18 | } 19 | 20 | public IMutableKeywordToken? ParseMutableModifier() 21 | { 22 | return Tokens.Current is IMutableKeywordToken ? Tokens.RequiredToken() : null; 23 | } 24 | 25 | public void ParseEndOfModifiers() 26 | { 27 | while (!(Tokens.Current is IEndOfFileToken)) 28 | { 29 | Tokens.UnexpectedToken(); 30 | } 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Parsing/PackageParser.cs: -------------------------------------------------------------------------------- 1 | namespace Adamant.Tools.Compiler.Bootstrap.Parsing 2 | { 3 | /// 4 | /// Parser for all the files in a package 5 | /// 6 | public class PackageParser 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Parsing/ParseAs.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics.CodeAnalysis; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.Parsing 4 | { 5 | [SuppressMessage("Naming", "CA1717:Only FlagsAttribute enums should have plural names", Justification = "Not Plural")] 6 | public enum ParseAs 7 | { 8 | Expression = 1, 9 | Statement 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Parsing/ParseFailedException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.Parsing 4 | { 5 | /// 6 | /// Used as control flow within the parser. When a parse error requiring us 7 | /// to jump out to a higher syntax node occurs, this is the exception that 8 | /// is thrown. 9 | /// 10 | public class ParseFailedException : Exception 11 | { 12 | public ParseFailedException() 13 | { 14 | } 15 | 16 | public ParseFailedException(string message) 17 | : base(message) 18 | { 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Parsing/Parser.Names.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Parsing.Tree; 2 | using Adamant.Tools.Compiler.Bootstrap.Tokens; 3 | 4 | namespace Adamant.Tools.Compiler.Bootstrap.Parsing 5 | { 6 | public partial class Parser 7 | { 8 | private NameSyntax ParseName() 9 | { 10 | var identifier = Tokens.RequiredToken(); 11 | var name = identifier.Value; 12 | return new NameSyntax(identifier.Span, name); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Parsing/RecursiveDescentParser.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Core; 2 | using Adamant.Tools.Compiler.Bootstrap.Lexing; 3 | using Adamant.Tools.Compiler.Bootstrap.Tokens; 4 | 5 | namespace Adamant.Tools.Compiler.Bootstrap.Parsing 6 | { 7 | public class RecursiveDescentParser 8 | { 9 | protected CodeFile File { get; } 10 | protected ITokenIterator Tokens { get; } 11 | 12 | public RecursiveDescentParser(ITokenIterator tokens) 13 | { 14 | File = tokens.Context.File; 15 | Tokens = tokens; 16 | } 17 | 18 | protected void Add(Diagnostic diagnostic) 19 | { 20 | Tokens.Context.Diagnostics.Add(diagnostic); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Parsing/Tree/ArgumentSyntax.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.CST; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.Parsing.Tree 4 | { 5 | internal class ArgumentSyntax : Syntax, IArgumentSyntax 6 | { 7 | private IExpressionSyntax expression; 8 | public ref IExpressionSyntax Expression => ref expression; 9 | 10 | public ArgumentSyntax(IExpressionSyntax expression) 11 | : base(expression.Span) 12 | { 13 | this.expression = expression; 14 | } 15 | 16 | public override string ToString() 17 | { 18 | return Expression.ToString(); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Parsing/Tree/BodySyntax.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | using Adamant.Tools.Compiler.Bootstrap.Core; 3 | using Adamant.Tools.Compiler.Bootstrap.CST; 4 | using Adamant.Tools.Compiler.Bootstrap.Framework; 5 | 6 | namespace Adamant.Tools.Compiler.Bootstrap.Parsing.Tree 7 | { 8 | internal class BodySyntax : Syntax, IBodySyntax 9 | { 10 | public FixedList Statements { [DebuggerStepThrough] get; } 11 | private readonly FixedList statements; 12 | FixedList IBodyOrBlockSyntax.Statements 13 | { 14 | [DebuggerStepThrough] 15 | get => statements; 16 | } 17 | 18 | public BodySyntax(TextSpan span, FixedList statements) 19 | : base(span) 20 | { 21 | Statements = statements; 22 | this.statements = statements.ToFixedList(); 23 | } 24 | 25 | public override string ToString() 26 | { 27 | return "{ … }"; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Parsing/Tree/BoolLiteralExpressionSyntax.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | using System.Globalization; 3 | using Adamant.Tools.Compiler.Bootstrap.Core; 4 | using Adamant.Tools.Compiler.Bootstrap.CST; 5 | using Adamant.Tools.Compiler.Bootstrap.Tokens; 6 | 7 | namespace Adamant.Tools.Compiler.Bootstrap.Parsing.Tree 8 | { 9 | internal class BoolLiteralExpressionSyntax : LiteralExpressionSyntax, IBoolLiteralExpressionSyntax 10 | { 11 | public bool Value { [DebuggerStepThrough] get; } 12 | 13 | public BoolLiteralExpressionSyntax(TextSpan span, bool value) 14 | : base(span, ExpressionSemantics.Copy) 15 | { 16 | Value = value; 17 | } 18 | 19 | protected override OperatorPrecedence ExpressionPrecedence => OperatorPrecedence.Primary; 20 | 21 | public override string ToString() 22 | { 23 | return Value.ToString(CultureInfo.InvariantCulture); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Parsing/Tree/BreakExpressionSyntax.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Core; 2 | using Adamant.Tools.Compiler.Bootstrap.CST; 3 | using Adamant.Tools.Compiler.Bootstrap.Tokens; 4 | 5 | namespace Adamant.Tools.Compiler.Bootstrap.Parsing.Tree 6 | { 7 | internal class BreakExpressionSyntax : ExpressionSyntax, IBreakExpressionSyntax 8 | { 9 | private IExpressionSyntax? value; 10 | public ref IExpressionSyntax? Value => ref value; 11 | 12 | public BreakExpressionSyntax( 13 | TextSpan span, 14 | IExpressionSyntax? value) 15 | : base(span, ExpressionSemantics.Void) 16 | { 17 | this.value = value; 18 | } 19 | 20 | protected override OperatorPrecedence ExpressionPrecedence => Value != null ? OperatorPrecedence.Min : OperatorPrecedence.Primary; 21 | 22 | public override string ToString() 23 | { 24 | if (Value != null) 25 | return $"break {Value}"; 26 | return "break"; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Parsing/Tree/CanReachAnnotationSyntax.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Core; 2 | using Adamant.Tools.Compiler.Bootstrap.CST; 3 | using Adamant.Tools.Compiler.Bootstrap.Framework; 4 | 5 | namespace Adamant.Tools.Compiler.Bootstrap.Parsing.Tree 6 | { 7 | internal class CanReachAnnotationSyntax : Syntax, ICanReachAnnotationSyntax 8 | { 9 | public FixedList Parameters { get; } 10 | 11 | public CanReachAnnotationSyntax(TextSpan span, FixedList parameters) 12 | : base(span) 13 | { 14 | Parameters = parameters; 15 | } 16 | 17 | public override string ToString() 18 | { 19 | return $"~> {string.Join(", ", Parameters)}"; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Parsing/Tree/CapabilityTypeSyntax.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Core; 2 | using Adamant.Tools.Compiler.Bootstrap.CST; 3 | using Adamant.Tools.Compiler.Bootstrap.Types; 4 | 5 | namespace Adamant.Tools.Compiler.Bootstrap.Parsing.Tree 6 | { 7 | internal class CapabilityTypeSyntax : TypeSyntax, ICapabilityTypeSyntax 8 | { 9 | public ITypeSyntax ReferentType { get; } 10 | public ReferenceCapability Capability { get; } 11 | 12 | public CapabilityTypeSyntax( 13 | ReferenceCapability referenceCapability, 14 | ITypeSyntax referentType, 15 | TextSpan span) 16 | : base(span) 17 | { 18 | ReferentType = referentType; 19 | Capability = referenceCapability; 20 | } 21 | 22 | public override string ToString() 23 | { 24 | var capability = Capability.ToSourceCodeString(); 25 | if (capability.Length == 0) return ReferentType.ToString(); 26 | 27 | return $"{capability} {ReferentType}"; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Parsing/Tree/ExpressionStatementSyntax.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | using Adamant.Tools.Compiler.Bootstrap.Core; 3 | using Adamant.Tools.Compiler.Bootstrap.CST; 4 | 5 | namespace Adamant.Tools.Compiler.Bootstrap.Parsing.Tree 6 | { 7 | internal class ExpressionStatementSyntax : StatementSyntax, IExpressionStatementSyntax 8 | { 9 | private IExpressionSyntax expression; 10 | public ref IExpressionSyntax Expression 11 | { 12 | [DebuggerStepThrough] 13 | get => ref expression; 14 | } 15 | 16 | public ExpressionStatementSyntax(TextSpan span, IExpressionSyntax expression) 17 | : base(span) 18 | { 19 | this.expression = expression; 20 | } 21 | 22 | public override string ToString() 23 | { 24 | return Expression+";"; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Parsing/Tree/IntegerLiteralExpressionSyntax.cs: -------------------------------------------------------------------------------- 1 | using System.Globalization; 2 | using System.Numerics; 3 | using Adamant.Tools.Compiler.Bootstrap.Core; 4 | using Adamant.Tools.Compiler.Bootstrap.CST; 5 | using Adamant.Tools.Compiler.Bootstrap.Tokens; 6 | 7 | namespace Adamant.Tools.Compiler.Bootstrap.Parsing.Tree 8 | { 9 | internal class IntegerLiteralExpressionSyntax : LiteralExpressionSyntax, IIntegerLiteralExpressionSyntax 10 | { 11 | public BigInteger Value { get; } 12 | 13 | public IntegerLiteralExpressionSyntax(TextSpan span, BigInteger value) 14 | : base(span, ExpressionSemantics.Copy) 15 | { 16 | Value = value; 17 | } 18 | 19 | protected override OperatorPrecedence ExpressionPrecedence => OperatorPrecedence.Primary; 20 | 21 | public override string ToString() 22 | { 23 | return Value.ToString(CultureInfo.InvariantCulture); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Parsing/Tree/LiteralExpressionSyntax.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Core; 2 | using Adamant.Tools.Compiler.Bootstrap.CST; 3 | using Adamant.Tools.Compiler.Bootstrap.Tokens; 4 | 5 | namespace Adamant.Tools.Compiler.Bootstrap.Parsing.Tree 6 | { 7 | internal abstract class LiteralExpressionSyntax : ExpressionSyntax, ILiteralExpressionSyntax 8 | { 9 | protected LiteralExpressionSyntax(TextSpan span, ExpressionSemantics? semantics = null) 10 | : base(span, semantics) 11 | { 12 | } 13 | 14 | protected override OperatorPrecedence ExpressionPrecedence => OperatorPrecedence.Primary; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Parsing/Tree/LoopExpressionSyntax.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Core; 2 | using Adamant.Tools.Compiler.Bootstrap.CST; 3 | using Adamant.Tools.Compiler.Bootstrap.Tokens; 4 | 5 | namespace Adamant.Tools.Compiler.Bootstrap.Parsing.Tree 6 | { 7 | internal class LoopExpressionSyntax : ExpressionSyntax, ILoopExpressionSyntax 8 | { 9 | public IBlockExpressionSyntax Block { get; } 10 | 11 | public LoopExpressionSyntax(TextSpan span, IBlockExpressionSyntax block) 12 | : base(span) 13 | { 14 | Block = block; 15 | } 16 | 17 | protected override OperatorPrecedence ExpressionPrecedence => OperatorPrecedence.Primary; 18 | 19 | public override string ToString() 20 | { 21 | return $"loop {Block}"; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Parsing/Tree/NameSyntax.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Core; 2 | using Adamant.Tools.Compiler.Bootstrap.Names; 3 | 4 | namespace Adamant.Tools.Compiler.Bootstrap.Parsing.Tree 5 | { 6 | /// 7 | /// Used within the parse to represent a name that we aren't yet sure whether 8 | /// it is a name expression, or a callable name 9 | /// 10 | internal readonly struct NameSyntax 11 | { 12 | public TextSpan Span { get; } 13 | public Name Name { get; } 14 | 15 | public NameSyntax(TextSpan span, Name name) 16 | { 17 | Span = span; 18 | Name = name; 19 | } 20 | 21 | public NameExpressionSyntax ToExpression() 22 | { 23 | return new NameExpressionSyntax(Span, Name); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Parsing/Tree/NamedParameterNameSyntax.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Core; 2 | using Adamant.Tools.Compiler.Bootstrap.Core.Promises; 3 | using Adamant.Tools.Compiler.Bootstrap.CST; 4 | using Adamant.Tools.Compiler.Bootstrap.Names; 5 | using Adamant.Tools.Compiler.Bootstrap.Symbols; 6 | 7 | namespace Adamant.Tools.Compiler.Bootstrap.Parsing.Tree 8 | { 9 | internal class NamedParameterNameSyntax : Syntax, INamedParameterNameSyntax 10 | { 11 | public Name? Name { get; } 12 | public Promise ReferencedSymbol { get; } = new Promise(); 13 | IPromise IParameterNameSyntax.ReferencedSymbol => ReferencedSymbol; 14 | 15 | public NamedParameterNameSyntax(TextSpan span, Name? name) 16 | : base(span) 17 | { 18 | Name = name; 19 | } 20 | 21 | public override string ToString() 22 | { 23 | return Name?.ToString() ?? "⧼unknown⧽"; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Parsing/Tree/NextExpressionSyntax.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Core; 2 | using Adamant.Tools.Compiler.Bootstrap.CST; 3 | using Adamant.Tools.Compiler.Bootstrap.Tokens; 4 | 5 | namespace Adamant.Tools.Compiler.Bootstrap.Parsing.Tree 6 | { 7 | internal class NextExpressionSyntax : ExpressionSyntax, INextExpressionSyntax 8 | { 9 | public NextExpressionSyntax(TextSpan span) 10 | : base(span, ExpressionSemantics.Never) 11 | { 12 | } 13 | 14 | protected override OperatorPrecedence ExpressionPrecedence => OperatorPrecedence.Primary; 15 | 16 | public override string ToString() 17 | { 18 | return "next"; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Parsing/Tree/NoneLiteralExpressionSyntax.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Core; 2 | using Adamant.Tools.Compiler.Bootstrap.CST; 3 | 4 | namespace Adamant.Tools.Compiler.Bootstrap.Parsing.Tree 5 | { 6 | internal class NoneLiteralExpressionSyntax : LiteralExpressionSyntax, INoneLiteralExpressionSyntax 7 | { 8 | public NoneLiteralExpressionSyntax(TextSpan span) 9 | : base(span, ExpressionSemantics.Copy) 10 | { 11 | } 12 | 13 | public override string ToString() 14 | { 15 | return "none"; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Parsing/Tree/OptionalTypeSyntax.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Core; 2 | using Adamant.Tools.Compiler.Bootstrap.CST; 3 | 4 | namespace Adamant.Tools.Compiler.Bootstrap.Parsing.Tree 5 | { 6 | class OptionalTypeSyntax : TypeSyntax, IOptionalTypeSyntax 7 | { 8 | public ITypeSyntax Referent { get; } 9 | 10 | public OptionalTypeSyntax(TextSpan span, ITypeSyntax referent) 11 | : base(span) 12 | { 13 | Referent = referent; 14 | } 15 | 16 | public override string ToString() 17 | { 18 | return $"{Referent}?"; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Parsing/Tree/ParameterSyntax.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | using Adamant.Tools.Compiler.Bootstrap.Core; 3 | using Adamant.Tools.Compiler.Bootstrap.Core.Promises; 4 | using Adamant.Tools.Compiler.Bootstrap.CST; 5 | using Adamant.Tools.Compiler.Bootstrap.Names; 6 | using Adamant.Tools.Compiler.Bootstrap.Types; 7 | 8 | namespace Adamant.Tools.Compiler.Bootstrap.Parsing.Tree 9 | { 10 | internal abstract class ParameterSyntax : Syntax, IParameterSyntax 11 | { 12 | [DebuggerHidden] 13 | [DebuggerBrowsable(DebuggerBrowsableState.Never)] 14 | public Name? Name { get; } 15 | public abstract IPromise DataType { get; } 16 | public bool Unused { get; } 17 | 18 | protected ParameterSyntax(TextSpan span, Name? name) 19 | : base(span) 20 | { 21 | Name = name; 22 | Unused = name?.Text.StartsWith('_') ?? false; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Parsing/Tree/ReachableFromAnnotationSyntax.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Core; 2 | using Adamant.Tools.Compiler.Bootstrap.CST; 3 | using Adamant.Tools.Compiler.Bootstrap.Framework; 4 | 5 | namespace Adamant.Tools.Compiler.Bootstrap.Parsing.Tree 6 | { 7 | internal class ReachableFromAnnotationSyntax : Syntax, IReachableFromAnnotationSyntax 8 | { 9 | public FixedList Parameters { get; } 10 | 11 | public ReachableFromAnnotationSyntax(TextSpan span, FixedList parameters) 12 | : base(span) 13 | { 14 | Parameters = parameters; 15 | } 16 | 17 | public override string ToString() 18 | { 19 | return $"<~ {string.Join(", ", Parameters)}"; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Parsing/Tree/ResultStatementSyntax.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Core; 2 | using Adamant.Tools.Compiler.Bootstrap.CST; 3 | 4 | namespace Adamant.Tools.Compiler.Bootstrap.Parsing.Tree 5 | { 6 | /// 7 | /// A result statement must be the last statement of the enclosing block 8 | /// 9 | internal class ResultStatementSyntax : StatementSyntax, IResultStatementSyntax 10 | { 11 | private IExpressionSyntax expression; 12 | public ref IExpressionSyntax Expression => ref expression; 13 | 14 | public ResultStatementSyntax( 15 | TextSpan span, 16 | IExpressionSyntax expression) 17 | : base(span) 18 | { 19 | this.expression = expression; 20 | } 21 | 22 | public override string ToString() 23 | { 24 | return $"=> {Expression};"; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Parsing/Tree/SelfExpressionSyntax.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Core; 2 | using Adamant.Tools.Compiler.Bootstrap.Core.Promises; 3 | using Adamant.Tools.Compiler.Bootstrap.CST; 4 | using Adamant.Tools.Compiler.Bootstrap.Symbols; 5 | using Adamant.Tools.Compiler.Bootstrap.Tokens; 6 | 7 | namespace Adamant.Tools.Compiler.Bootstrap.Parsing.Tree 8 | { 9 | internal class SelfExpressionSyntax : ExpressionSyntax, ISelfExpressionSyntax 10 | { 11 | public bool IsImplicit { get; } 12 | public Promise ReferencedSymbol { get; } = new Promise(); 13 | 14 | public SelfExpressionSyntax(TextSpan span, bool isImplicit) 15 | : base(span) 16 | { 17 | IsImplicit = isImplicit; 18 | } 19 | 20 | protected override OperatorPrecedence ExpressionPrecedence => OperatorPrecedence.Primary; 21 | 22 | public override string ToString() 23 | { 24 | return IsImplicit ? "⟦self⟧" : "self"; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Parsing/Tree/SelfParameterNameSyntax.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Core; 2 | using Adamant.Tools.Compiler.Bootstrap.Core.Promises; 3 | using Adamant.Tools.Compiler.Bootstrap.CST; 4 | using Adamant.Tools.Compiler.Bootstrap.Symbols; 5 | 6 | namespace Adamant.Tools.Compiler.Bootstrap.Parsing.Tree 7 | { 8 | internal class SelfParameterNameSyntax : Syntax, ISelfParameterNameSyntax 9 | { 10 | public Promise ReferencedSymbol { get; } = new Promise(); 11 | IPromise IParameterNameSyntax.ReferencedSymbol => ReferencedSymbol; 12 | 13 | public SelfParameterNameSyntax(TextSpan span) 14 | : base(span) 15 | { 16 | } 17 | 18 | public override string ToString() 19 | { 20 | return "self"; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Parsing/Tree/StatementSyntax.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Core; 2 | using Adamant.Tools.Compiler.Bootstrap.CST; 3 | 4 | namespace Adamant.Tools.Compiler.Bootstrap.Parsing.Tree 5 | { 6 | internal abstract class StatementSyntax : Syntax, IStatementSyntax 7 | { 8 | private protected StatementSyntax(TextSpan span) 9 | : base(span) 10 | { 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Parsing/Tree/StringLiteralExpressionSyntax.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | using Adamant.Tools.Compiler.Bootstrap.Core; 3 | using Adamant.Tools.Compiler.Bootstrap.CST; 4 | using Adamant.Tools.Compiler.Bootstrap.Framework; 5 | using Adamant.Tools.Compiler.Bootstrap.Tokens; 6 | 7 | namespace Adamant.Tools.Compiler.Bootstrap.Parsing.Tree 8 | { 9 | internal class StringLiteralExpressionSyntax : LiteralExpressionSyntax, IStringLiteralExpressionSyntax 10 | { 11 | public string Value { [DebuggerStepThrough] get; } 12 | 13 | public StringLiteralExpressionSyntax(TextSpan span, string value) 14 | : base(span, ExpressionSemantics.Share) 15 | { 16 | Value = value; 17 | } 18 | 19 | protected override OperatorPrecedence ExpressionPrecedence => OperatorPrecedence.Primary; 20 | 21 | public override string ToString() 22 | { 23 | return $"\"{Value.Escape()}\""; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Parsing/Tree/Syntax.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | using Adamant.Tools.Compiler.Bootstrap.Core; 3 | using Adamant.Tools.Compiler.Bootstrap.CST; 4 | 5 | namespace Adamant.Tools.Compiler.Bootstrap.Parsing.Tree 6 | { 7 | [DebuggerDisplay("{" + nameof(ToString) + "(),nq}")] 8 | internal abstract class Syntax : ISyntax 9 | { 10 | public TextSpan Span { get; protected set; } 11 | 12 | protected Syntax(TextSpan span) 13 | { 14 | Span = span; 15 | } 16 | 17 | // This exists primarily for debugging use 18 | public abstract override string ToString(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Parsing/Tree/UnsafeExpressionSyntax.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Core; 2 | using Adamant.Tools.Compiler.Bootstrap.CST; 3 | using Adamant.Tools.Compiler.Bootstrap.Tokens; 4 | 5 | namespace Adamant.Tools.Compiler.Bootstrap.Parsing.Tree 6 | { 7 | internal class UnsafeExpressionSyntax : ExpressionSyntax, IUnsafeExpressionSyntax 8 | { 9 | private IExpressionSyntax expression; 10 | 11 | public ref IExpressionSyntax Expression => ref expression; 12 | 13 | public UnsafeExpressionSyntax(TextSpan span, IExpressionSyntax expression) 14 | : base(span) 15 | { 16 | this.expression = expression; 17 | } 18 | 19 | protected override OperatorPrecedence ExpressionPrecedence => OperatorPrecedence.Primary; 20 | 21 | public override string ToString() 22 | { 23 | return $"unsafe ({Expression})"; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Parsing/Tree/UsingDirectiveSyntax.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Core; 2 | using Adamant.Tools.Compiler.Bootstrap.CST; 3 | using Adamant.Tools.Compiler.Bootstrap.Names; 4 | 5 | namespace Adamant.Tools.Compiler.Bootstrap.Parsing.Tree 6 | { 7 | internal class UsingDirectiveSyntax : Syntax, IUsingDirectiveSyntax 8 | { 9 | // For now, we only support namespace names 10 | public NamespaceName Name { get; } 11 | 12 | public UsingDirectiveSyntax(TextSpan span, NamespaceName name) 13 | : base(span) 14 | { 15 | Name = name; 16 | } 17 | 18 | public override string ToString() 19 | { 20 | return $"using {Name};"; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Parsing/Tree/WhileExpressionSyntax.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Core; 2 | using Adamant.Tools.Compiler.Bootstrap.CST; 3 | using Adamant.Tools.Compiler.Bootstrap.Tokens; 4 | 5 | namespace Adamant.Tools.Compiler.Bootstrap.Parsing.Tree 6 | { 7 | internal class WhileExpressionSyntax : ExpressionSyntax, IWhileExpressionSyntax 8 | { 9 | private IExpressionSyntax condition; 10 | public ref IExpressionSyntax Condition => ref condition; 11 | 12 | public IBlockExpressionSyntax Block { get; } 13 | 14 | public WhileExpressionSyntax( 15 | TextSpan span, 16 | IExpressionSyntax condition, 17 | IBlockExpressionSyntax block) 18 | : base(span) 19 | { 20 | this.condition = condition; 21 | Block = block; 22 | } 23 | 24 | protected override OperatorPrecedence ExpressionPrecedence => OperatorPrecedence.Min; 25 | 26 | public override string ToString() 27 | { 28 | return $"while {Condition} {Block}"; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Semantics.Reachability.Graph/Access.cs: -------------------------------------------------------------------------------- 1 | namespace Adamant.Tools.Compiler.Bootstrap.Semantics.Reachability.Graph 2 | { 3 | /// 4 | /// The access rights for a memory place or reference 5 | /// 6 | public enum Access 7 | { 8 | Identify, 9 | ReadOnly, 10 | Mutable, 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Semantics.Reachability.Graph/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.CompilerServices; 2 | 3 | [assembly: InternalsVisibleTo("Adamant.Tools.Compiler.Bootstrap.Tests.Unit.Semantics.Reachability.Graph")] 4 | [assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")] 5 | -------------------------------------------------------------------------------- /Semantics.Reachability.Graph/IReference.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.Semantics.Reachability.Graph 4 | { 5 | public interface IReference 6 | { 7 | Object Referent { get; } 8 | Ownership Ownership { get; } 9 | bool CouldHaveOwnership { get; } 10 | Access DeclaredAccess { get; } 11 | bool DeclaredReadable { get; } 12 | Phase Phase { get; } 13 | bool IsUsed { get; } 14 | bool IsReleased { get; } 15 | internal IEnumerable Borrowers { get; } 16 | Access EffectiveAccess(); 17 | bool IsUsedForBorrow(); 18 | bool IsUsedForBorrowExceptBy(IReference reference); 19 | bool IsOriginFor(IReference reference); 20 | IReference Borrow(); 21 | IReference Share(); 22 | IReference Identify(); 23 | void Use(); 24 | internal void Release(IReferenceGraph graph); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Semantics.Reachability.Graph/Object.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics.CodeAnalysis; 2 | using Adamant.Tools.Compiler.Bootstrap.AST; 3 | 4 | namespace Adamant.Tools.Compiler.Bootstrap.Semantics.Reachability.Graph 5 | { 6 | /// 7 | /// Context objects represent objects whose lifetime is controlled outside 8 | /// the current function. 9 | /// 10 | [SuppressMessage("Naming", "CA1720:Identifier contains type name", Justification = "")] 11 | public class Object : HeapPlace 12 | { 13 | public bool IsContext { get; } 14 | 15 | internal Object(IReferenceGraph graph, bool isContext, IAbstractSyntax syntax, Reference? originOfMutability) 16 | : base(graph, syntax, originOfMutability) 17 | { 18 | IsContext = isContext; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Semantics.Reachability.Graph/Ownership.cs: -------------------------------------------------------------------------------- 1 | namespace Adamant.Tools.Compiler.Bootstrap.Semantics.Reachability.Graph 2 | { 3 | public enum Ownership 4 | { 5 | None, 6 | PotentiallyOwns, 7 | Owns, 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Semantics.Reachability.Graph/Phase.cs: -------------------------------------------------------------------------------- 1 | namespace Adamant.Tools.Compiler.Bootstrap.Semantics.Reachability.Graph 2 | { 3 | public enum Phase 4 | { 5 | Unused, 6 | Used, 7 | Released, 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Semantics.Reachability.Graph/README.md: -------------------------------------------------------------------------------- 1 | # Adamant.Tools.Compiler.Bootstrap.Semantics.Reachability.Graph 2 | 3 | The reachability graph used by reachability analysis. This is in a separate project so the graph can fully encapsulate the allowed transformation as checks. 4 | -------------------------------------------------------------------------------- /Semantics.Reachability.Graph/StackPlace.cs: -------------------------------------------------------------------------------- 1 | namespace Adamant.Tools.Compiler.Bootstrap.Semantics.Reachability.Graph 2 | { 3 | /// 4 | /// A stack place is a place that conceptually stored on the stack and is 5 | /// consequently a root for liveness. While temporary values may not 6 | /// actually be output to the stack, they conceptually stored on the stack 7 | /// because they have stack like storage. 8 | /// 9 | public abstract class StackPlace : MemoryPlace 10 | { 11 | private protected StackPlace(IReferenceGraph graph) 12 | : base(graph) { } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Semantics.Reachability.Graph/TempValue.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.AST; 2 | using Adamant.Tools.Compiler.Bootstrap.Types; 3 | 4 | namespace Adamant.Tools.Compiler.Bootstrap.Semantics.Reachability.Graph 5 | { 6 | public class TempValue : StackPlace 7 | { 8 | private readonly IExpression expression; 9 | public ReferenceType ReferenceType { get; } 10 | 11 | internal TempValue(IReferenceGraph graph, IExpression expression, ReferenceType referenceType) 12 | : base(graph) 13 | { 14 | this.expression = expression; 15 | ReferenceType = referenceType; 16 | } 17 | 18 | public override string ToString() 19 | { 20 | return $"⟦{expression}⟧: {ReferenceType}"; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Semantics/AST/Tree/AbstractSyntax.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | using Adamant.Tools.Compiler.Bootstrap.AST; 3 | using Adamant.Tools.Compiler.Bootstrap.Core; 4 | 5 | namespace Adamant.Tools.Compiler.Bootstrap.Semantics.AST.Tree 6 | { 7 | [DebuggerDisplay("{" + nameof(ToString) + "(),nq}")] 8 | internal abstract class AbstractSyntax : IAbstractSyntax 9 | { 10 | public TextSpan Span { get; } 11 | 12 | protected AbstractSyntax(TextSpan span) 13 | { 14 | Span = span; 15 | } 16 | 17 | public abstract override string ToString(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Semantics/AST/Tree/Body.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.AST; 2 | using Adamant.Tools.Compiler.Bootstrap.Core; 3 | using Adamant.Tools.Compiler.Bootstrap.Framework; 4 | 5 | namespace Adamant.Tools.Compiler.Bootstrap.Semantics.AST.Tree 6 | { 7 | internal class Body : AbstractSyntax, IBody 8 | { 9 | public FixedList Statements { get; } 10 | FixedList IBodyOrBlock.Statements => Statements.ToFixedList(); 11 | 12 | public Body(TextSpan span, FixedList statements) 13 | : base(span) 14 | { 15 | Statements = statements; 16 | } 17 | 18 | public override string ToString() 19 | { 20 | return "{ … }"; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Semantics/AST/Tree/BoolLiteralExpression.cs: -------------------------------------------------------------------------------- 1 | using System.Globalization; 2 | using Adamant.Tools.Compiler.Bootstrap.AST; 3 | using Adamant.Tools.Compiler.Bootstrap.Core; 4 | using Adamant.Tools.Compiler.Bootstrap.Tokens; 5 | using Adamant.Tools.Compiler.Bootstrap.Types; 6 | 7 | namespace Adamant.Tools.Compiler.Bootstrap.Semantics.AST.Tree 8 | { 9 | internal class BoolLiteralExpression : LiteralExpression, IBoolLiteralExpression 10 | { 11 | public bool Value { get; } 12 | 13 | public BoolLiteralExpression( 14 | TextSpan span, 15 | DataType dataType, 16 | ExpressionSemantics semantics, 17 | bool value) 18 | : base(span, dataType, semantics) 19 | { 20 | Value = value; 21 | } 22 | 23 | protected override OperatorPrecedence ExpressionPrecedence => OperatorPrecedence.Primary; 24 | 25 | public override string ToString() 26 | { 27 | return Value.ToString(CultureInfo.InvariantCulture); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Semantics/AST/Tree/BreakExpression.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.AST; 2 | using Adamant.Tools.Compiler.Bootstrap.Core; 3 | using Adamant.Tools.Compiler.Bootstrap.Tokens; 4 | using Adamant.Tools.Compiler.Bootstrap.Types; 5 | 6 | namespace Adamant.Tools.Compiler.Bootstrap.Semantics.AST.Tree 7 | { 8 | internal class BreakExpression : Expression, IBreakExpression 9 | { 10 | public IExpression? Value { get; } 11 | 12 | public BreakExpression( 13 | TextSpan span, 14 | DataType dataType, 15 | ExpressionSemantics semantics, 16 | IExpression? value) 17 | : base(span, dataType, semantics) 18 | { 19 | Value = value; 20 | } 21 | 22 | protected override OperatorPrecedence ExpressionPrecedence => 23 | Value != null ? OperatorPrecedence.Min : OperatorPrecedence.Primary; 24 | 25 | public override string ToString() 26 | { 27 | if (Value != null) return $"break {Value}"; 28 | return "break"; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Semantics/AST/Tree/CanReachAnnotation.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.AST; 2 | using Adamant.Tools.Compiler.Bootstrap.Core; 3 | using Adamant.Tools.Compiler.Bootstrap.Framework; 4 | 5 | namespace Adamant.Tools.Compiler.Bootstrap.Semantics.AST.Tree 6 | { 7 | internal class CanReachAnnotation : AbstractSyntax, ICanReachAnnotation 8 | { 9 | public FixedList Parameters { get; } 10 | 11 | public CanReachAnnotation(TextSpan span, FixedList parameters) 12 | : base(span) 13 | { 14 | Parameters = parameters; 15 | } 16 | 17 | public override string ToString() 18 | { 19 | return $"~> {string.Join(", ", Parameters)}"; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Semantics/AST/Tree/Declaration.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.AST; 2 | using Adamant.Tools.Compiler.Bootstrap.Core; 3 | using Adamant.Tools.Compiler.Bootstrap.Symbols; 4 | 5 | namespace Adamant.Tools.Compiler.Bootstrap.Semantics.AST.Tree 6 | { 7 | internal abstract class Declaration : AbstractSyntax, IDeclaration 8 | { 9 | public CodeFile File { get; } 10 | public Symbol Symbol { get; } 11 | public TextSpan NameSpan { get; } 12 | 13 | protected Declaration(CodeFile file, TextSpan span, Symbol symbol, TextSpan nameSpan) 14 | : base(span) 15 | { 16 | Symbol = symbol; 17 | NameSpan = nameSpan; 18 | File = file; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Semantics/AST/Tree/Expression.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.AST; 2 | using Adamant.Tools.Compiler.Bootstrap.Core; 3 | using Adamant.Tools.Compiler.Bootstrap.Tokens; 4 | using Adamant.Tools.Compiler.Bootstrap.Types; 5 | 6 | namespace Adamant.Tools.Compiler.Bootstrap.Semantics.AST.Tree 7 | { 8 | internal abstract class Expression : AbstractSyntax, IExpression 9 | { 10 | public DataType DataType { get; } 11 | public ExpressionSemantics Semantics { get; } 12 | 13 | protected Expression(TextSpan span, DataType dataType, ExpressionSemantics semantics) 14 | : base(span) 15 | { 16 | DataType = dataType; 17 | Semantics = semantics; 18 | } 19 | 20 | protected abstract OperatorPrecedence ExpressionPrecedence { get; } 21 | 22 | public string ToGroupedString(OperatorPrecedence surroundingPrecedence) 23 | { 24 | return surroundingPrecedence > ExpressionPrecedence ? $"({this})" : ToString(); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Semantics/AST/Tree/ExpressionStatement.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | using Adamant.Tools.Compiler.Bootstrap.AST; 3 | using Adamant.Tools.Compiler.Bootstrap.Core; 4 | 5 | namespace Adamant.Tools.Compiler.Bootstrap.Semantics.AST.Tree 6 | { 7 | internal class ExpressionStatement : Statement, IExpressionStatement 8 | { 9 | public IExpression Expression { [DebuggerStepThrough] get; } 10 | 11 | public ExpressionStatement(TextSpan span, IExpression expression) 12 | : base(span) 13 | { 14 | Expression = expression; 15 | } 16 | 17 | public override string ToString() 18 | { 19 | return Expression + ";"; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Semantics/AST/Tree/FieldDeclaration.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.AST; 2 | using Adamant.Tools.Compiler.Bootstrap.Core; 3 | using Adamant.Tools.Compiler.Bootstrap.Symbols; 4 | 5 | namespace Adamant.Tools.Compiler.Bootstrap.Semantics.AST.Tree 6 | { 7 | internal class FieldDeclaration : Declaration, IFieldDeclaration 8 | { 9 | public IClassDeclaration DeclaringClass { get; } 10 | public new FieldSymbol Symbol { get; } 11 | BindingSymbol IBinding.Symbol => Symbol; 12 | 13 | public FieldDeclaration( 14 | CodeFile file, 15 | TextSpan span, 16 | IClassDeclaration declaringClass, 17 | FieldSymbol symbol, 18 | TextSpan nameSpan) 19 | : base(file, span, symbol, nameSpan) 20 | { 21 | Symbol = symbol; 22 | DeclaringClass = declaringClass; 23 | } 24 | 25 | public override string ToString() 26 | { 27 | return Symbol + ";"; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Semantics/AST/Tree/FieldParameter.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.AST; 2 | using Adamant.Tools.Compiler.Bootstrap.Core; 3 | using Adamant.Tools.Compiler.Bootstrap.Symbols; 4 | 5 | namespace Adamant.Tools.Compiler.Bootstrap.Semantics.AST.Tree 6 | { 7 | internal class FieldParameter : Parameter, IFieldParameter 8 | { 9 | public FieldSymbol ReferencedSymbol { get; } 10 | public IExpression? DefaultValue { get; } 11 | 12 | public FieldParameter( 13 | TextSpan span, 14 | FieldSymbol referencedSymbol, 15 | IExpression? defaultValue) 16 | : base(span, false) 17 | { 18 | ReferencedSymbol = referencedSymbol; 19 | DefaultValue = defaultValue; 20 | } 21 | 22 | public override string ToString() 23 | { 24 | var defaultValue = DefaultValue != null ? " = " + DefaultValue : ""; 25 | return $".{ReferencedSymbol.Name}{defaultValue}"; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Semantics/AST/Tree/ImplicitConversionExpression.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.AST; 2 | using Adamant.Tools.Compiler.Bootstrap.Core; 3 | using Adamant.Tools.Compiler.Bootstrap.Tokens; 4 | using Adamant.Tools.Compiler.Bootstrap.Types; 5 | 6 | namespace Adamant.Tools.Compiler.Bootstrap.Semantics.AST.Tree 7 | { 8 | internal abstract class ImplicitConversionExpression : Expression, IImplicitConversionExpression 9 | { 10 | public IExpression Expression { get; } 11 | 12 | protected ImplicitConversionExpression( 13 | TextSpan span, 14 | DataType dataType, 15 | ExpressionSemantics semantics, 16 | IExpression expression) 17 | : base(span, dataType, semantics) 18 | { 19 | Expression = expression; 20 | } 21 | 22 | protected override OperatorPrecedence ExpressionPrecedence => OperatorPrecedence.Min; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Semantics/AST/Tree/ImplicitImmutabilityConversion.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.AST; 2 | using Adamant.Tools.Compiler.Bootstrap.Core; 3 | using Adamant.Tools.Compiler.Bootstrap.Tokens; 4 | using Adamant.Tools.Compiler.Bootstrap.Types; 5 | 6 | namespace Adamant.Tools.Compiler.Bootstrap.Semantics.AST.Tree 7 | { 8 | internal class ImplicitImmutabilityConversion : ImplicitConversionExpression, IImplicitImmutabilityConversionExpression 9 | { 10 | public ObjectType ConvertToType { get; } 11 | 12 | public ImplicitImmutabilityConversion( 13 | TextSpan span, 14 | DataType dataType, 15 | ExpressionSemantics semantics, 16 | IExpression expression, 17 | ObjectType convertToType) 18 | : base(span, dataType, semantics, expression) 19 | { 20 | ConvertToType = convertToType; 21 | } 22 | 23 | public override string ToString() 24 | { 25 | return $"{Expression.ToGroupedString(OperatorPrecedence.Min)} ⟦as ⟦immutable⟧⟧"; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Semantics/AST/Tree/ImplicitNoneConversionExpression.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.AST; 2 | using Adamant.Tools.Compiler.Bootstrap.Core; 3 | using Adamant.Tools.Compiler.Bootstrap.Tokens; 4 | using Adamant.Tools.Compiler.Bootstrap.Types; 5 | 6 | namespace Adamant.Tools.Compiler.Bootstrap.Semantics.AST.Tree 7 | { 8 | internal class ImplicitNoneConversionExpression : ImplicitConversionExpression, IImplicitNoneConversionExpression 9 | { 10 | public OptionalType ConvertToType { get; } 11 | 12 | public ImplicitNoneConversionExpression( 13 | TextSpan span, 14 | DataType dataType, 15 | ExpressionSemantics semantics, 16 | IExpression expression, 17 | OptionalType convertToType) 18 | : base(span, dataType, semantics, expression) 19 | { 20 | ConvertToType = convertToType; 21 | } 22 | 23 | public override string ToString() 24 | { 25 | return $"{Expression.ToGroupedString(OperatorPrecedence.Min)} ⟦as {ConvertToType}⟧"; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Semantics/AST/Tree/ImplicitNumericConversionExpression.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.AST; 2 | using Adamant.Tools.Compiler.Bootstrap.Core; 3 | using Adamant.Tools.Compiler.Bootstrap.Types; 4 | 5 | namespace Adamant.Tools.Compiler.Bootstrap.Semantics.AST.Tree 6 | { 7 | internal class ImplicitNumericConversionExpression : ImplicitConversionExpression, IImplicitNumericConversionExpression 8 | { 9 | public NumericType ConvertToType { get; } 10 | 11 | public ImplicitNumericConversionExpression( 12 | TextSpan span, 13 | DataType dataType, 14 | ExpressionSemantics semantics, 15 | IExpression expression, 16 | NumericType convertToType) 17 | : base(span, dataType, semantics, expression) 18 | { 19 | ConvertToType = convertToType; 20 | } 21 | 22 | public override string ToString() 23 | { 24 | return $"{{Expression.ToGroupedString(OperatorPrecedence.Min)}} ⟦as {ConvertToType}⟧"; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Semantics/AST/Tree/ImplicitOptionalConversionExpression.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.AST; 2 | using Adamant.Tools.Compiler.Bootstrap.Core; 3 | using Adamant.Tools.Compiler.Bootstrap.Tokens; 4 | using Adamant.Tools.Compiler.Bootstrap.Types; 5 | 6 | namespace Adamant.Tools.Compiler.Bootstrap.Semantics.AST.Tree 7 | { 8 | internal class ImplicitOptionalConversionExpression : ImplicitConversionExpression, IImplicitOptionalConversionExpression 9 | { 10 | public OptionalType ConvertToType { get; } 11 | 12 | public ImplicitOptionalConversionExpression( 13 | TextSpan span, 14 | DataType dataType, 15 | ExpressionSemantics semantics, 16 | IExpression expression, 17 | OptionalType convertToType) 18 | : base(span, dataType, semantics, expression) 19 | { 20 | ConvertToType = convertToType; 21 | } 22 | 23 | public override string ToString() 24 | { 25 | return $"{Expression.ToGroupedString(OperatorPrecedence.Min)} ⟦as {ConvertToType}⟧"; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Semantics/AST/Tree/IntegerLiteralExpression.cs: -------------------------------------------------------------------------------- 1 | using System.Globalization; 2 | using System.Numerics; 3 | using Adamant.Tools.Compiler.Bootstrap.AST; 4 | using Adamant.Tools.Compiler.Bootstrap.Core; 5 | using Adamant.Tools.Compiler.Bootstrap.Tokens; 6 | using Adamant.Tools.Compiler.Bootstrap.Types; 7 | 8 | namespace Adamant.Tools.Compiler.Bootstrap.Semantics.AST.Tree 9 | { 10 | internal class IntegerLiteralExpression : LiteralExpression, IIntegerLiteralExpression 11 | { 12 | public BigInteger Value { get; } 13 | 14 | public IntegerLiteralExpression( 15 | TextSpan span, 16 | DataType dataType, 17 | ExpressionSemantics semantics, 18 | BigInteger value) 19 | : base(span, dataType, semantics) 20 | { 21 | Value = value; 22 | } 23 | 24 | protected override OperatorPrecedence ExpressionPrecedence => OperatorPrecedence.Primary; 25 | 26 | public override string ToString() 27 | { 28 | return Value.ToString(CultureInfo.InvariantCulture); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Semantics/AST/Tree/LiteralExpression.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.AST; 2 | using Adamant.Tools.Compiler.Bootstrap.Core; 3 | using Adamant.Tools.Compiler.Bootstrap.Tokens; 4 | using Adamant.Tools.Compiler.Bootstrap.Types; 5 | 6 | namespace Adamant.Tools.Compiler.Bootstrap.Semantics.AST.Tree 7 | { 8 | internal abstract class LiteralExpression : Expression, ILiteralExpression 9 | { 10 | protected LiteralExpression(TextSpan span, DataType dataType, ExpressionSemantics semantics) 11 | : base(span, dataType, semantics) { } 12 | 13 | protected override OperatorPrecedence ExpressionPrecedence => OperatorPrecedence.Primary; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Semantics/AST/Tree/LoopExpression.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.AST; 2 | using Adamant.Tools.Compiler.Bootstrap.Core; 3 | using Adamant.Tools.Compiler.Bootstrap.Tokens; 4 | using Adamant.Tools.Compiler.Bootstrap.Types; 5 | 6 | namespace Adamant.Tools.Compiler.Bootstrap.Semantics.AST.Tree 7 | { 8 | internal class LoopExpression : Expression, ILoopExpression 9 | { 10 | public IBlockExpression Block { get; } 11 | 12 | public LoopExpression( 13 | TextSpan span, 14 | DataType dataType, 15 | ExpressionSemantics semantics, 16 | IBlockExpression block) 17 | : base(span, dataType, semantics) 18 | { 19 | Block = block; 20 | } 21 | 22 | protected override OperatorPrecedence ExpressionPrecedence => OperatorPrecedence.Primary; 23 | 24 | public override string ToString() 25 | { 26 | return $"loop {Block}"; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Semantics/AST/Tree/NamedParameterName.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.AST; 2 | using Adamant.Tools.Compiler.Bootstrap.Core; 3 | using Adamant.Tools.Compiler.Bootstrap.Symbols; 4 | 5 | namespace Adamant.Tools.Compiler.Bootstrap.Semantics.AST.Tree 6 | { 7 | internal class NamedParameterName : AbstractSyntax, INamedParameterName 8 | { 9 | public VariableSymbol ReferencedSymbol { get; } 10 | BindingSymbol IParameterName.ReferencedSymbol => ReferencedSymbol; 11 | 12 | public NamedParameterName(TextSpan span, VariableSymbol referencedSymbol) 13 | : base(span) 14 | { 15 | ReferencedSymbol = referencedSymbol; 16 | } 17 | 18 | public override string ToString() 19 | { 20 | return ReferencedSymbol.Name.ToString(); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Semantics/AST/Tree/NextExpression.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.AST; 2 | using Adamant.Tools.Compiler.Bootstrap.Core; 3 | using Adamant.Tools.Compiler.Bootstrap.Tokens; 4 | using Adamant.Tools.Compiler.Bootstrap.Types; 5 | 6 | namespace Adamant.Tools.Compiler.Bootstrap.Semantics.AST.Tree 7 | { 8 | internal class NextExpression : Expression, INextExpression 9 | { 10 | public NextExpression(TextSpan span, DataType dataType, ExpressionSemantics semantics) 11 | : base(span, dataType, semantics) { } 12 | 13 | protected override OperatorPrecedence ExpressionPrecedence => OperatorPrecedence.Primary; 14 | 15 | public override string ToString() 16 | { 17 | return "next"; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Semantics/AST/Tree/NoneLiteralExpression.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.AST; 2 | using Adamant.Tools.Compiler.Bootstrap.Core; 3 | using Adamant.Tools.Compiler.Bootstrap.Types; 4 | 5 | namespace Adamant.Tools.Compiler.Bootstrap.Semantics.AST.Tree 6 | { 7 | internal class NoneLiteralExpression : LiteralExpression, INoneLiteralExpression 8 | { 9 | public NoneLiteralExpression(TextSpan span, DataType dataType, ExpressionSemantics semantics) 10 | : base(span, dataType, semantics) { } 11 | 12 | public override string ToString() 13 | { 14 | return "none"; 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Semantics/AST/Tree/Parameter.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.AST; 2 | using Adamant.Tools.Compiler.Bootstrap.Core; 3 | 4 | namespace Adamant.Tools.Compiler.Bootstrap.Semantics.AST.Tree 5 | { 6 | internal abstract class Parameter : AbstractSyntax, IParameter 7 | { 8 | public bool Unused { get; } 9 | 10 | protected Parameter(TextSpan span, bool unused) 11 | : base(span) 12 | { 13 | Unused = unused; 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Semantics/AST/Tree/ReachableFromAnnotation.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.AST; 2 | using Adamant.Tools.Compiler.Bootstrap.Core; 3 | using Adamant.Tools.Compiler.Bootstrap.Framework; 4 | 5 | namespace Adamant.Tools.Compiler.Bootstrap.Semantics.AST.Tree 6 | { 7 | internal class ReachableFromAnnotation : AbstractSyntax, IReachableFromAnnotation 8 | { 9 | public FixedList Parameters { get; } 10 | 11 | public ReachableFromAnnotation(TextSpan span, FixedList parameters) 12 | : base(span) 13 | { 14 | Parameters = parameters; 15 | } 16 | 17 | public override string ToString() 18 | { 19 | return $"<~ {string.Join(", ", Parameters)}"; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Semantics/AST/Tree/ResultStatement.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.AST; 2 | using Adamant.Tools.Compiler.Bootstrap.Core; 3 | 4 | namespace Adamant.Tools.Compiler.Bootstrap.Semantics.AST.Tree 5 | { 6 | internal class ResultStatement : Statement, IResultStatement 7 | { 8 | public IExpression Expression { get; } 9 | 10 | public ResultStatement(TextSpan span, IExpression expression) 11 | : base(span) 12 | { 13 | Expression = expression; 14 | } 15 | 16 | public override string ToString() 17 | { 18 | return $"=> {Expression};"; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Semantics/AST/Tree/ReturnExpression.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.AST; 2 | using Adamant.Tools.Compiler.Bootstrap.Core; 3 | using Adamant.Tools.Compiler.Bootstrap.Tokens; 4 | using Adamant.Tools.Compiler.Bootstrap.Types; 5 | 6 | namespace Adamant.Tools.Compiler.Bootstrap.Semantics.AST.Tree 7 | { 8 | internal class ReturnExpression : Expression, IReturnExpression 9 | { 10 | public IExpression? Value { get; } 11 | 12 | public ReturnExpression( 13 | TextSpan span, 14 | DataType dataType, 15 | ExpressionSemantics semantics, 16 | IExpression? value) 17 | : base(span, dataType, semantics) 18 | { 19 | Value = value; 20 | } 21 | 22 | protected override OperatorPrecedence ExpressionPrecedence => OperatorPrecedence.Min; 23 | 24 | public override string ToString() 25 | { 26 | return Value is null ? "return" : $"return {Value}"; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Semantics/AST/Tree/SelfParameter.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.AST; 2 | using Adamant.Tools.Compiler.Bootstrap.Core; 3 | using Adamant.Tools.Compiler.Bootstrap.Symbols; 4 | 5 | namespace Adamant.Tools.Compiler.Bootstrap.Semantics.AST.Tree 6 | { 7 | internal class SelfParameter : Parameter, ISelfParameter 8 | { 9 | public SelfParameterSymbol Symbol { get; } 10 | BindingSymbol IBinding.Symbol => Symbol; 11 | public SelfParameter(TextSpan span, SelfParameterSymbol symbol, bool unused) 12 | : base(span, unused) 13 | { 14 | Symbol = symbol; 15 | } 16 | 17 | public override string ToString() 18 | { 19 | var value = "self"; 20 | if (Symbol.IsMutableBinding) value = "mut " + value; 21 | return value; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Semantics/AST/Tree/SelfParameterName.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.AST; 2 | using Adamant.Tools.Compiler.Bootstrap.Core; 3 | using Adamant.Tools.Compiler.Bootstrap.Symbols; 4 | 5 | namespace Adamant.Tools.Compiler.Bootstrap.Semantics.AST.Tree 6 | { 7 | internal class SelfParameterName : AbstractSyntax, ISelfParameterName 8 | { 9 | public SelfParameterSymbol ReferencedSymbol { get; } 10 | BindingSymbol IParameterName.ReferencedSymbol => ReferencedSymbol; 11 | 12 | public SelfParameterName(TextSpan span, SelfParameterSymbol referencedSymbol) 13 | : base(span) 14 | { 15 | ReferencedSymbol = referencedSymbol; 16 | } 17 | 18 | public override string ToString() 19 | { 20 | return "self"; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Semantics/AST/Tree/Statement.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.AST; 2 | using Adamant.Tools.Compiler.Bootstrap.Core; 3 | 4 | namespace Adamant.Tools.Compiler.Bootstrap.Semantics.AST.Tree 5 | { 6 | internal abstract class Statement : AbstractSyntax, IStatement 7 | { 8 | protected Statement(TextSpan span) 9 | : base(span) { } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Semantics/AST/Tree/StringLiteralExpression.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.AST; 2 | using Adamant.Tools.Compiler.Bootstrap.Core; 3 | using Adamant.Tools.Compiler.Bootstrap.Framework; 4 | using Adamant.Tools.Compiler.Bootstrap.Tokens; 5 | using Adamant.Tools.Compiler.Bootstrap.Types; 6 | 7 | namespace Adamant.Tools.Compiler.Bootstrap.Semantics.AST.Tree 8 | { 9 | internal class StringLiteralExpression : LiteralExpression, IStringLiteralExpression 10 | { 11 | public string Value { get; } 12 | 13 | public StringLiteralExpression( 14 | TextSpan span, 15 | DataType dataType, 16 | ExpressionSemantics semantics, 17 | string value) 18 | : base(span, dataType, semantics) 19 | { 20 | Value = value; 21 | } 22 | 23 | protected override OperatorPrecedence ExpressionPrecedence => OperatorPrecedence.Primary; 24 | 25 | public override string ToString() 26 | { 27 | return $"\"{Value.Escape()}\""; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Semantics/AST/Tree/UnsafeExpression.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.AST; 2 | using Adamant.Tools.Compiler.Bootstrap.Core; 3 | using Adamant.Tools.Compiler.Bootstrap.Tokens; 4 | using Adamant.Tools.Compiler.Bootstrap.Types; 5 | 6 | namespace Adamant.Tools.Compiler.Bootstrap.Semantics.AST.Tree 7 | { 8 | internal class UnsafeExpression : Expression, IUnsafeExpression 9 | { 10 | public IExpression Expression { get; } 11 | 12 | public UnsafeExpression( 13 | TextSpan span, 14 | DataType dataType, 15 | ExpressionSemantics semantics, 16 | IExpression expression) 17 | : base(span, dataType, semantics) 18 | { 19 | Expression = expression; 20 | } 21 | 22 | protected override OperatorPrecedence ExpressionPrecedence => OperatorPrecedence.Primary; 23 | 24 | public override string ToString() 25 | { 26 | return $"unsafe ({Expression})"; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Semantics/AST/Tree/WhileExpression.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.AST; 2 | using Adamant.Tools.Compiler.Bootstrap.Core; 3 | using Adamant.Tools.Compiler.Bootstrap.Tokens; 4 | using Adamant.Tools.Compiler.Bootstrap.Types; 5 | 6 | namespace Adamant.Tools.Compiler.Bootstrap.Semantics.AST.Tree 7 | { 8 | internal class WhileExpression : Expression, IWhileExpression 9 | { 10 | public IExpression Condition { get; } 11 | public IBlockExpression Block { get; } 12 | 13 | public WhileExpression( 14 | TextSpan span, 15 | DataType dataType, 16 | ExpressionSemantics semantics, 17 | IExpression condition, 18 | IBlockExpression block) 19 | : base(span, dataType, semantics) 20 | { 21 | Condition = condition; 22 | Block = block; 23 | } 24 | 25 | protected override OperatorPrecedence ExpressionPrecedence => OperatorPrecedence.Min; 26 | 27 | public override string ToString() 28 | { 29 | return $"while {Condition} {Block}"; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Semantics/Basic/ImplicitOperations/ImplicitImmutabilityConversionExpression.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.CST; 2 | using Adamant.Tools.Compiler.Bootstrap.Tokens; 3 | using Adamant.Tools.Compiler.Bootstrap.Types; 4 | 5 | namespace Adamant.Tools.Compiler.Bootstrap.Semantics.Basic.ImplicitOperations 6 | { 7 | // TODO No error is reported if IImplicitImmutabilityConversionExpression is missing 8 | internal class ImplicitImmutabilityConversionExpression : ImplicitConversionExpression, IImplicitImmutabilityConversionExpressionSyntax 9 | { 10 | public ObjectType ConvertToType { get; } 11 | 12 | public ImplicitImmutabilityConversionExpression( 13 | IExpressionSyntax expression, 14 | ObjectType convertToType) 15 | : base(expression.Span, convertToType, expression, expression.Semantics.Assigned()) 16 | { 17 | ConvertToType = convertToType; 18 | } 19 | 20 | public override string ToString() 21 | { 22 | return $"{Expression.ToGroupedString(OperatorPrecedence.Min)} ⟦as ⟦immutable⟧⟧"; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Semantics/Basic/ImplicitOperations/ImplicitNumericConversionExpression.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Core; 2 | using Adamant.Tools.Compiler.Bootstrap.CST; 3 | using Adamant.Tools.Compiler.Bootstrap.Tokens; 4 | using Adamant.Tools.Compiler.Bootstrap.Types; 5 | 6 | namespace Adamant.Tools.Compiler.Bootstrap.Semantics.Basic.ImplicitOperations 7 | { 8 | internal class ImplicitNumericConversionExpression : ImplicitConversionExpression, IImplicitNumericConversionExpressionSyntax 9 | { 10 | public NumericType ConvertToType { get; } 11 | 12 | public ImplicitNumericConversionExpression( 13 | IExpressionSyntax expression, 14 | NumericType convertToType) 15 | : base(expression.Span, convertToType, expression, ExpressionSemantics.Copy) 16 | { 17 | ConvertToType = convertToType; 18 | } 19 | 20 | public override string ToString() 21 | { 22 | return $"{Expression.ToGroupedString(OperatorPrecedence.Min)} ⟦as {ConvertToType}⟧"; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Semantics/Basic/ImplicitOperations/ImplicitOptionalConversionExpression.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.CST; 2 | using Adamant.Tools.Compiler.Bootstrap.Tokens; 3 | using Adamant.Tools.Compiler.Bootstrap.Types; 4 | 5 | namespace Adamant.Tools.Compiler.Bootstrap.Semantics.Basic.ImplicitOperations 6 | { 7 | /// 8 | /// An implicit conversion from `T` to `T?` 9 | /// 10 | internal class ImplicitOptionalConversionExpression : ImplicitConversionExpression, IImplicitOptionalConversionExpressionSyntax 11 | { 12 | public OptionalType ConvertToType { get; } 13 | 14 | public ImplicitOptionalConversionExpression( 15 | IExpressionSyntax expression, 16 | OptionalType convertToType) 17 | : base(expression.Span, convertToType, expression, expression.Semantics.Assigned()) 18 | { 19 | ConvertToType = convertToType; 20 | } 21 | 22 | public override string ToString() 23 | { 24 | return $"{Expression.ToGroupedString(OperatorPrecedence.Min)} ⟦as {ConvertToType}⟧"; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Semantics/DataFlow/IBackwardDataFlowAnalysis.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.AST; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.Semantics.DataFlow 4 | { 5 | public interface IBackwardDataFlowAnalysis 6 | { 7 | TState StartState(); 8 | TState Assignment(IAssignmentExpression assignmentExpression, TState state); 9 | TState IdentifierName(INameExpression nameExpression, TState state); 10 | TState VariableDeclaration(IVariableDeclarationStatement variableDeclaration, TState state); 11 | TState VariableDeclaration(IForeachExpression foreachExpression, TState state); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Semantics/DataFlow/IBackwardDataFlowAnalyzer.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.AST; 2 | using Adamant.Tools.Compiler.Bootstrap.Core; 3 | using Adamant.Tools.Compiler.Bootstrap.Symbols.Trees; 4 | 5 | namespace Adamant.Tools.Compiler.Bootstrap.Semantics.DataFlow 6 | { 7 | /// 8 | /// A factory for . This is used 9 | /// to start a new data flow analysis. 10 | /// 11 | public interface IBackwardDataFlowAnalyzer 12 | { 13 | IBackwardDataFlowAnalysis BeginAnalysis( 14 | IExecutableDeclaration declaration, 15 | ISymbolTree symbolTree, 16 | Diagnostics diagnostics); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Semantics/DataFlow/IForwardDataFlowAnalysis.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.AST; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.Semantics.DataFlow 4 | { 5 | public interface IForwardDataFlowAnalysis 6 | { 7 | TState StartState(); 8 | TState Assignment(IAssignmentExpression assignmentExpression, TState state); 9 | TState IdentifierName(INameExpression nameExpression, TState state); 10 | TState VariableDeclaration(IVariableDeclarationStatement variableDeclaration, TState state); 11 | TState VariableDeclaration(IForeachExpression foreachExpression, TState state); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Semantics/DataFlow/IForwardDataFlowAnalyzer.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.AST; 2 | using Adamant.Tools.Compiler.Bootstrap.Core; 3 | using Adamant.Tools.Compiler.Bootstrap.Symbols.Trees; 4 | 5 | namespace Adamant.Tools.Compiler.Bootstrap.Semantics.DataFlow 6 | { 7 | /// 8 | /// A factory for . This is used 9 | /// to start a new data flow analysis. 10 | /// 11 | public interface IForwardDataFlowAnalyzer 12 | { 13 | IForwardDataFlowAnalysis BeginAnalysis( 14 | IExecutableDeclaration declaration, 15 | ISymbolTree symbolTree, 16 | Diagnostics diagnostics); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Semantics/ILGen/IlFactory.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics.CodeAnalysis; 2 | using Adamant.Tools.Compiler.Bootstrap.AST; 3 | using Adamant.Tools.Compiler.Bootstrap.IntermediateLanguage.CFG; 4 | 5 | namespace Adamant.Tools.Compiler.Bootstrap.Semantics.ILGen 6 | { 7 | public class ILFactory 8 | { 9 | [SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "OO")] 10 | public ControlFlowGraph CreateGraph(IConcreteInvocableDeclaration invocableDeclaration) 11 | { 12 | // TODO build control flow graphs for field initializers 13 | 14 | var fabrication = new ControlFlowGraphFabrication(invocableDeclaration); 15 | return fabrication.CreateGraph(); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Semantics/Liveness/LivenessAnalyzer.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.AST; 2 | using Adamant.Tools.Compiler.Bootstrap.Core; 3 | using Adamant.Tools.Compiler.Bootstrap.Semantics.DataFlow; 4 | using Adamant.Tools.Compiler.Bootstrap.Symbols.Trees; 5 | 6 | namespace Adamant.Tools.Compiler.Bootstrap.Semantics.Liveness 7 | { 8 | public class LivenessAnalyzer : IBackwardDataFlowAnalyzer 9 | { 10 | #region Singleton 11 | public static readonly LivenessAnalyzer Instance = new LivenessAnalyzer(); 12 | 13 | private LivenessAnalyzer() { } 14 | #endregion 15 | 16 | public IBackwardDataFlowAnalysis BeginAnalysis( 17 | IExecutableDeclaration declaration, 18 | ISymbolTree symbolTree, 19 | Diagnostics _) 20 | { 21 | return new LivenessAnalysis(declaration, symbolTree); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Semantics/Reachability/Argument.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.AST; 2 | using Adamant.Tools.Compiler.Bootstrap.Semantics.Reachability.Graph; 3 | using Adamant.Tools.Compiler.Bootstrap.Types; 4 | 5 | namespace Adamant.Tools.Compiler.Bootstrap.Semantics.Reachability 6 | { 7 | internal class Argument 8 | { 9 | public TempValue? Value { get; } 10 | public IExpression Expression { get; } 11 | public DataType ParameterDataType { get; } 12 | 13 | public Argument(IExpression expression, DataType parameterDataType, TempValue? value) 14 | { 15 | Value = value; 16 | Expression = expression; 17 | ParameterDataType = parameterDataType; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Semantics/Reachability/VariableScope.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Adamant.Tools.Compiler.Bootstrap.Symbols; 3 | 4 | namespace Adamant.Tools.Compiler.Bootstrap.Semantics.Reachability 5 | { 6 | /// 7 | /// A lexical scope of variable places used to track when variables come into 8 | /// and go out of scope. 9 | /// 10 | internal class VariableScope 11 | { 12 | public VariableScope? ContainingScope { get; } 13 | private readonly HashSet variables = new HashSet(); 14 | public IReadOnlyCollection Variables => variables; 15 | 16 | public VariableScope(VariableScope? containingScope = null) 17 | { 18 | ContainingScope = containingScope; 19 | } 20 | 21 | /// 22 | /// Declare a variable in the current scope 23 | /// 24 | public void VariableDeclared(BindingSymbol symbol) 25 | { 26 | variables.Add(symbol); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Semantics/Variables/BindingMutability/BindingMutabilityAnalyzer.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.AST; 2 | using Adamant.Tools.Compiler.Bootstrap.Core; 3 | using Adamant.Tools.Compiler.Bootstrap.Semantics.DataFlow; 4 | using Adamant.Tools.Compiler.Bootstrap.Symbols.Trees; 5 | 6 | namespace Adamant.Tools.Compiler.Bootstrap.Semantics.Variables.BindingMutability 7 | { 8 | public class BindingMutabilityAnalyzer : IForwardDataFlowAnalyzer 9 | { 10 | #region Singleton 11 | public static readonly BindingMutabilityAnalyzer Instance = new BindingMutabilityAnalyzer(); 12 | 13 | private BindingMutabilityAnalyzer() { } 14 | #endregion 15 | 16 | public IForwardDataFlowAnalysis BeginAnalysis( 17 | IExecutableDeclaration declaration, 18 | ISymbolTree symbolTree, 19 | Diagnostics diagnostics) 20 | { 21 | return new BindingMutabilityAnalysis(declaration, symbolTree, diagnostics); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Semantics/Variables/DefiniteAssignment/DefiniteAssignmentAnalyzer.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.AST; 2 | using Adamant.Tools.Compiler.Bootstrap.Core; 3 | using Adamant.Tools.Compiler.Bootstrap.Semantics.DataFlow; 4 | using Adamant.Tools.Compiler.Bootstrap.Symbols.Trees; 5 | 6 | namespace Adamant.Tools.Compiler.Bootstrap.Semantics.Variables.DefiniteAssignment 7 | { 8 | public class DefiniteAssignmentAnalyzer : IForwardDataFlowAnalyzer 9 | { 10 | #region Singleton 11 | public static readonly DefiniteAssignmentAnalyzer Instance = new DefiniteAssignmentAnalyzer(); 12 | 13 | private DefiniteAssignmentAnalyzer() { } 14 | #endregion 15 | 16 | public IForwardDataFlowAnalysis BeginAnalysis( 17 | IExecutableDeclaration declaration, 18 | ISymbolTree symbolTree, 19 | Diagnostics diagnostics) 20 | { 21 | return new DefiniteAssignmentAnalysis(declaration, symbolTree, diagnostics); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Semantics/Variables/Moves/UseOfMovedValueAnalyzer.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.AST; 2 | using Adamant.Tools.Compiler.Bootstrap.Core; 3 | using Adamant.Tools.Compiler.Bootstrap.Semantics.DataFlow; 4 | using Adamant.Tools.Compiler.Bootstrap.Symbols.Trees; 5 | 6 | namespace Adamant.Tools.Compiler.Bootstrap.Semantics.Variables.Moves 7 | { 8 | public class UseOfMovedValueAnalyzer : IForwardDataFlowAnalyzer 9 | { 10 | #region Singleton 11 | public static readonly UseOfMovedValueAnalyzer Instance = new UseOfMovedValueAnalyzer(); 12 | 13 | private UseOfMovedValueAnalyzer() { } 14 | #endregion 15 | 16 | public IForwardDataFlowAnalysis BeginAnalysis( 17 | IExecutableDeclaration declaration, 18 | ISymbolTree symbolTree, 19 | Diagnostics diagnostics) 20 | { 21 | return new UseOfMovedValueAnalysis(declaration, symbolTree, diagnostics); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Semantics/Variables/Shadowing/BindingScope.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics.CodeAnalysis; 2 | using Adamant.Tools.Compiler.Bootstrap.Names; 3 | 4 | namespace Adamant.Tools.Compiler.Bootstrap.Semantics.Variables.Shadowing 5 | { 6 | public abstract class BindingScope 7 | { 8 | public bool Lookup(Name name, [NotNullWhen(true)] out VariableBinding? binding) 9 | { 10 | return LookupWithoutNumber(name, out binding); 11 | } 12 | 13 | protected abstract bool LookupWithoutNumber(Name name, [NotNullWhen(true)] out VariableBinding? binding); 14 | 15 | /// 16 | /// Indicates that some nested scope declared a variable binding. 17 | /// 18 | protected internal abstract void NestedBindingDeclared(VariableBinding binding); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Semantics/Variables/Shadowing/EmptyBindingScope.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics.CodeAnalysis; 2 | using Adamant.Tools.Compiler.Bootstrap.Names; 3 | 4 | namespace Adamant.Tools.Compiler.Bootstrap.Semantics.Variables.Shadowing 5 | { 6 | public class EmptyBindingScope : BindingScope 7 | { 8 | #region Singleton 9 | public static readonly BindingScope Instance = new EmptyBindingScope(); 10 | 11 | private EmptyBindingScope() { } 12 | #endregion 13 | 14 | protected override bool LookupWithoutNumber(Name name, [NotNullWhen(true)] out VariableBinding? binding) 15 | { 16 | binding = null; 17 | return false; 18 | } 19 | 20 | protected internal override void NestedBindingDeclared(VariableBinding binding) 21 | { 22 | // Empty scope has no bindings, so nested bindings don't matter 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Symbols/BindingSymbol.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Names; 2 | using Adamant.Tools.Compiler.Bootstrap.Types; 3 | using ExhaustiveMatching; 4 | 5 | namespace Adamant.Tools.Compiler.Bootstrap.Symbols 6 | { 7 | [Closed( 8 | typeof(NamedBindingSymbol), 9 | typeof(SelfParameterSymbol))] 10 | public abstract class BindingSymbol : Symbol 11 | { 12 | public override PackageSymbol? Package { get; } 13 | public new Name? Name { get; } 14 | public bool IsMutableBinding { get; } 15 | public DataType DataType { get; } 16 | 17 | protected BindingSymbol(Symbol containingSymbol, Name? name, bool isMutableBinding, DataType dataType) 18 | : base(containingSymbol, name) 19 | { 20 | Package = containingSymbol.Package; 21 | Name = name; 22 | IsMutableBinding = isMutableBinding; 23 | DataType = dataType; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Symbols/FunctionOrMethodSymbol.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Framework; 2 | using Adamant.Tools.Compiler.Bootstrap.Names; 3 | using Adamant.Tools.Compiler.Bootstrap.Symbols.Reachability; 4 | using Adamant.Tools.Compiler.Bootstrap.Types; 5 | using ExhaustiveMatching; 6 | 7 | namespace Adamant.Tools.Compiler.Bootstrap.Symbols 8 | { 9 | [Closed( 10 | typeof(FunctionSymbol), 11 | typeof(MethodSymbol))] 12 | public abstract class FunctionOrMethodSymbol : InvocableSymbol 13 | { 14 | public new Name Name { get; } 15 | 16 | protected FunctionOrMethodSymbol( 17 | Symbol containingSymbol, 18 | Name name, 19 | FixedList parameterDataTypes, 20 | DataType returnDataType, 21 | FixedSet reachabilityAnnotations) 22 | : base(containingSymbol, name, parameterDataTypes, returnDataType, reachabilityAnnotations) 23 | { 24 | Name = name; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Symbols/InternalsVisibleTo.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.CompilerServices; 2 | 3 | [assembly: InternalsVisibleTo("Adamant.Tools.Compiler.Bootstrap.Tests.Unit.Symbols")] 4 | -------------------------------------------------------------------------------- /Symbols/NamedBindingSymbol.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Names; 2 | using Adamant.Tools.Compiler.Bootstrap.Types; 3 | using ExhaustiveMatching; 4 | 5 | namespace Adamant.Tools.Compiler.Bootstrap.Symbols 6 | { 7 | [Closed( 8 | typeof(VariableSymbol), 9 | typeof(FieldSymbol))] 10 | public abstract class NamedBindingSymbol : BindingSymbol 11 | { 12 | public new Name Name { get; } 13 | 14 | protected NamedBindingSymbol( 15 | Symbol containingSymbol, 16 | Name name, 17 | bool isMutableBinding, 18 | DataType dataType) 19 | : base(containingSymbol, name, isMutableBinding, dataType) 20 | { 21 | Name = name; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Symbols/NamespaceOrPackageSymbol.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Names; 2 | using ExhaustiveMatching; 3 | 4 | namespace Adamant.Tools.Compiler.Bootstrap.Symbols 5 | { 6 | [Closed( 7 | typeof(NamespaceSymbol), 8 | typeof(PackageSymbol))] 9 | public abstract class NamespaceOrPackageSymbol : Symbol 10 | { 11 | public NamespaceName NamespaceName { get; } 12 | public new Name Name { get; } 13 | 14 | protected NamespaceOrPackageSymbol(NamespaceOrPackageSymbol? containingSymbol, Name name) 15 | : base(containingSymbol, name) 16 | { 17 | NamespaceName = containingSymbol is null 18 | ? NamespaceName.Global 19 | : containingSymbol.NamespaceName.Qualify(name); 20 | Name = name; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Symbols/README.md: -------------------------------------------------------------------------------- 1 | # Adamant.Tools.Compiler.Bootstrap.Symbols 2 | 3 | A symbol is the pairing of a full name with a type and other data about the symbol. For example, function symbols include symbols for the parameters and a return type. 4 | -------------------------------------------------------------------------------- /Symbols/Reachability/ReachabilityAnnotation.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Framework; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.Symbols.Reachability 4 | { 5 | public class ReachabilityAnnotation : ReachabilityChain 6 | { 7 | public ReachabilityChain CanReach { get; } 8 | 9 | public ReachabilityAnnotation(FixedSet references, ReachabilityChain canReach) 10 | : base(references) 11 | { 12 | CanReach = canReach; 13 | } 14 | 15 | public ReachabilityAnnotation(Reference reference, ReachabilityChain canReach) 16 | : this(new FixedSet(reference.Yield()), canReach) { } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Symbols/Reachability/ReachabilityChain.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Adamant.Tools.Compiler.Bootstrap.Framework; 3 | using ExhaustiveMatching; 4 | 5 | namespace Adamant.Tools.Compiler.Bootstrap.Symbols.Reachability 6 | { 7 | [Closed( 8 | typeof(ReachabilityAnnotation), 9 | typeof(ReachableReferences))] 10 | public abstract class ReachabilityChain 11 | { 12 | public FixedSet References { get; } 13 | 14 | protected ReachabilityChain(FixedSet references) 15 | { 16 | if (references.Count == 0) 17 | throw new ArgumentException("Must not be empty", nameof(references)); 18 | References = references; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Symbols/Reachability/ReachableReferences.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Framework; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.Symbols.Reachability 4 | { 5 | public class ReachableReferences : ReachabilityChain 6 | { 7 | public ReachableReferences(FixedSet references) 8 | : base(references) { } 9 | 10 | public ReachableReferences(Reference reference) 11 | : this(new FixedSet(reference.Yield())) { } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Symbols/Reachability/Reference.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.Symbols.Reachability 4 | { 5 | public abstract class Reference : IEquatable 6 | { 7 | public abstract bool Equals(Reference? other); 8 | 9 | public override bool Equals(object? obj) 10 | { 11 | if (obj is null) return false; 12 | if (ReferenceEquals(this, obj)) return true; 13 | if (obj.GetType() != GetType()) return false; 14 | return Equals((Reference)obj); 15 | } 16 | 17 | public abstract override int GetHashCode(); 18 | 19 | public static bool operator ==(Reference? left, Reference? right) 20 | { 21 | return Equals(left, right); 22 | } 23 | 24 | public static bool operator !=(Reference? left, Reference? right) 25 | { 26 | return !Equals(left, right); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Symbols/Reachability/ReturnReference.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.Symbols.Reachability 4 | { 5 | public class ReturnReference : Reference 6 | { 7 | #region Singleton 8 | 9 | public static readonly ReturnReference Instance = new ReturnReference(); 10 | 11 | private ReturnReference() { } 12 | 13 | #endregion 14 | 15 | public override bool Equals(Reference? other) 16 | { 17 | return ReferenceEquals(this, other); 18 | } 19 | 20 | public override int GetHashCode() 21 | { 22 | return HashCode.Combine(typeof(SelfParameterReference)); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Symbols/Reachability/SelfParameterReference.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.Symbols.Reachability 4 | { 5 | public class SelfParameterReference : Reference 6 | { 7 | #region Singleton 8 | public static readonly SelfParameterReference Instance = new SelfParameterReference(); 9 | 10 | private SelfParameterReference() { } 11 | #endregion 12 | 13 | public override bool Equals(Reference? other) 14 | { 15 | return ReferenceEquals(this, other); 16 | } 17 | 18 | public override int GetHashCode() 19 | { 20 | return HashCode.Combine(typeof(SelfParameterReference)); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Symbols/Trees/ISymbolTree.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.Symbols.Trees 4 | { 5 | /// 6 | /// A symbol tree is a immutable collection of symbols that answers the question: 7 | /// For any given symbol, what are its child symbols. 8 | /// 9 | /// Each symbol tree 10 | /// 11 | public interface ISymbolTree 12 | { 13 | PackageSymbol? Package { get; } 14 | IEnumerable Symbols { get; } 15 | bool Contains(Symbol symbol); 16 | IEnumerable Children(Symbol symbol); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Symbols/TypeSymbol.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Names; 2 | using Adamant.Tools.Compiler.Bootstrap.Types; 3 | using ExhaustiveMatching; 4 | 5 | namespace Adamant.Tools.Compiler.Bootstrap.Symbols 6 | { 7 | [Closed( 8 | typeof(PrimitiveTypeSymbol), 9 | typeof(ObjectTypeSymbol))] 10 | public abstract class TypeSymbol : Symbol 11 | { 12 | public new NamespaceOrPackageSymbol? ContainingSymbol { get; } 13 | public new TypeName Name { get; } 14 | public DataType DeclaresDataType { get; } 15 | 16 | protected TypeSymbol(NamespaceOrPackageSymbol? containingSymbol, TypeName name, DataType declaresDataType) 17 | : base(containingSymbol, name) 18 | { 19 | ContainingSymbol = containingSymbol; 20 | Name = name; 21 | DeclaresDataType = declaresDataType; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Tests.Asserts/DiagnosticAsserts.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Core; 2 | 3 | namespace Xunit 4 | { 5 | public partial class Assert 6 | { 7 | public static void Diagnostic( 8 | Diagnostic diagnostic, 9 | DiagnosticPhase phase, 10 | int errorCode, 11 | int start, 12 | int length) 13 | { 14 | NotNull(diagnostic); 15 | Equal(phase, diagnostic.Phase); 16 | Equal(errorCode, diagnostic.ErrorCode); 17 | True(start == diagnostic.Span.Start, 18 | $"Expected diagnostic start {start}, was {diagnostic.Span.Start}"); 19 | True(length == diagnostic.Span.Length, 20 | $"Expected diagnostic length {length}, was {diagnostic.Span.Length}"); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Tests.Asserts/README.md: -------------------------------------------------------------------------------- 1 | # Adamant.Tools.Compiler.Bootstrap.Tests.Asserts 2 | 3 | The currently officially recommended way of defining custom asserts for xUnit is to reference the `xunit.assert.source` NuGet package which brings the source code of the asserts class into your project as a partial class. However, that code doesn't compile with treat all warnings as errors. Nor is it written with the new C# nullable references. Given that the custom asserts are in a partial class, it must be in the same project and be subject to the same compilation options. As a result, this project can't be configured the way all the other projects are. 4 | -------------------------------------------------------------------------------- /Tests.Asserts/TypeAsserts.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Xunit 4 | { 5 | public partial class Assert 6 | { 7 | public static T OfType(object @object) 8 | { 9 | return IsAssignableFrom(@object); 10 | } 11 | 12 | public static void OfType(Type expectedType, object @object) 13 | { 14 | IsAssignableFrom(expectedType, @object); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Tests.Conformance/GlobalSuppressions.cs: -------------------------------------------------------------------------------- 1 | // This file is used by Code Analysis to maintain SuppressMessage 2 | // attributes that are applied to this project. 3 | // Project-level suppressions either have no target or are given 4 | // a specific target and scoped to a namespace, type, member, etc. 5 | 6 | using System.Diagnostics.CodeAnalysis; 7 | 8 | [assembly: SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Unit test naming")] 9 | -------------------------------------------------------------------------------- /Tests.Conformance/Helpers/CompilerOutputAdapter.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Emit.C; 2 | using Xunit.Abstractions; 3 | 4 | namespace Adamant.Tools.Compiler.Bootstrap.Tests.Conformance.Helpers 5 | { 6 | public class CompilerOutputAdapter : ICompilerOutput 7 | { 8 | private readonly ITestOutputHelper testOutput; 9 | 10 | public CompilerOutputAdapter(ITestOutputHelper testOutput) 11 | { 12 | this.testOutput = testOutput; 13 | } 14 | 15 | public void WriteLine(string message) 16 | { 17 | if (message != null) 18 | testOutput.WriteLine(message); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Tests.Unit.CodeGen/GlobalSuppressions.cs: -------------------------------------------------------------------------------- 1 | // This file is used by Code Analysis to maintain SuppressMessage 2 | // attributes that are applied to this project. 3 | // Project-level suppressions either have no target or are given 4 | // a specific target and scoped to a namespace, type, member, etc. 5 | 6 | using System.Diagnostics.CodeAnalysis; 7 | 8 | [assembly: SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Unit test naming")] 9 | -------------------------------------------------------------------------------- /Tests.Unit.Emit.C/GlobalSuppressions.cs: -------------------------------------------------------------------------------- 1 | // This file is used by Code Analysis to maintain SuppressMessage 2 | // attributes that are applied to this project. 3 | // Project-level suppressions either have no target or are given 4 | // a specific target and scoped to a namespace, type, member, etc. 5 | 6 | using System.Diagnostics.CodeAnalysis; 7 | 8 | [assembly: SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Unit test naming")] 9 | -------------------------------------------------------------------------------- /Tests.Unit.Framework/EnumerableExtensionTests.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using Adamant.Tools.Compiler.Bootstrap.Framework; 3 | using Xunit; 4 | 5 | namespace Adamant.Tools.Compiler.Bootstrap.Tests.Unit.Framework 6 | { 7 | [Trait("Category", "Framework")] 8 | public class EnumerableExtensionTests 9 | { 10 | [Fact] 11 | public void CrossJoinCreatesEveryCombination() 12 | { 13 | var items1 = new[] { 1, 2, 3 }; 14 | var items2 = new[] { "1", "2", "3" }; 15 | var expected = new[] 16 | { 17 | (1, "1"), 18 | (1, "2"), 19 | (1, "3"), 20 | (2, "1"), 21 | (2, "2"), 22 | (2, "3"), 23 | (3, "1"), 24 | (3, "2"), 25 | (3, "3"), 26 | }.ToHashSet(); 27 | Assert.Equal(expected, items1.CrossJoin(items2).ToHashSet()); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Tests.Unit.Framework/FixedListTests.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Framework; 2 | using Xunit; 3 | 4 | namespace Adamant.Tools.Compiler.Bootstrap.Tests.Unit.Framework 5 | { 6 | [Trait("Category", "Framework")] 7 | public class FixedListTests 8 | { 9 | [Fact] 10 | public void Equal_fixed_lists_have_same_hash_code() 11 | { 12 | var l1 = new[] { "foo", "bar", "baz" }.ToFixedList(); 13 | var l2 = new[] { "foo", "bar", "baz" }.ToFixedList(); 14 | 15 | Assert.Equal(l1, l2); 16 | Assert.Equal(l1.GetHashCode(), l2.GetHashCode()); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Tests.Unit.Framework/FixedSetTests.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Framework; 2 | using Xunit; 3 | 4 | namespace Adamant.Tools.Compiler.Bootstrap.Tests.Unit.Framework 5 | { 6 | [Trait("Category", "Framework")] 7 | public class FixedSetTests 8 | { 9 | [Fact] 10 | public void Equal_fixed_sets_have_same_hash_code() 11 | { 12 | var set1 = new[] { "foo", "bar", "baz" }.ToFixedSet(); 13 | var set2 = new[] { "foo", "bar", "baz" }.ToFixedSet(); 14 | 15 | Assert.Equal(set1, set2); 16 | Assert.Equal(set1.GetHashCode(), set2.GetHashCode()); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Tests.Unit.Framework/GlobalSuppressions.cs: -------------------------------------------------------------------------------- 1 | // This file is used by Code Analysis to maintain SuppressMessage 2 | // attributes that are applied to this project. 3 | // Project-level suppressions either have no target or are given 4 | // a specific target and scoped to a namespace, type, member, etc. 5 | 6 | using System.Diagnostics.CodeAnalysis; 7 | 8 | [assembly: SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Unit test naming")] 9 | -------------------------------------------------------------------------------- /Tests.Unit.Lexing/Fakes/FakeParseContext.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Core; 2 | using Adamant.Tools.Compiler.Bootstrap.Tests.Unit.Fakes; 3 | 4 | namespace Adamant.Tools.Compiler.Bootstrap.Tests.Unit.Lexing.Fakes 5 | { 6 | public static class FakeParseContext 7 | { 8 | public static ParseContext For(string text) 9 | { 10 | return new ParseContext(FakeCodeFile.For(text), new Diagnostics()); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Tests.Unit.Lexing/GlobalSuppressions.cs: -------------------------------------------------------------------------------- 1 | // This file is used by Code Analysis to maintain SuppressMessage 2 | // attributes that are applied to this project. 3 | // Project-level suppressions either have no target or are given 4 | // a specific target and scoped to a namespace, type, member, etc. 5 | 6 | using System.Diagnostics.CodeAnalysis; 7 | 8 | [assembly: SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Unit test naming")] 9 | -------------------------------------------------------------------------------- /Tests.Unit.Lexing/Helpers/DebugFormatExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Adamant.Tools.Compiler.Bootstrap.Core; 4 | 5 | namespace Adamant.Tools.Compiler.Bootstrap.Tests.Unit.Lexing.Helpers 6 | { 7 | public static class DebugFormatExtensions 8 | { 9 | public static string DebugFormat(this IEnumerable diagnostics) 10 | { 11 | return string.Join(", ", 12 | diagnostics.Select(d => 13 | $"{d.ErrorCode}@{d.StartPosition.Line}:{d.StartPosition.Column}")); 14 | } 15 | 16 | public static string DebugFormat(this IEnumerable tokens) 17 | { 18 | return string.Join(", ", tokens); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Tests.Unit.Names/GlobalSuppressions.cs: -------------------------------------------------------------------------------- 1 | // This file is used by Code Analysis to maintain SuppressMessage 2 | // attributes that are applied to this project. 3 | // Project-level suppressions either have no target or are given 4 | // a specific target and scoped to a namespace, type, member, etc. 5 | 6 | using System.Diagnostics.CodeAnalysis; 7 | 8 | [assembly: SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Unit test naming")] 9 | -------------------------------------------------------------------------------- /Tests.Unit.Semantics.Reachability.Graph/CallerVariableTests.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Semantics.Reachability.Graph; 2 | using Adamant.Tools.Compiler.Bootstrap.Types; 3 | using Moq; 4 | using Xunit; 5 | 6 | namespace Adamant.Tools.Compiler.Bootstrap.Tests.Unit.Semantics.Reachability.Graph 7 | { 8 | [Trait("Category", "Semantics")] 9 | public class CallerVariableTests : SymbolTestFixture 10 | { 11 | [Fact] 12 | public void Self_parameter_to_string_has_name() 13 | { 14 | var sym = SelfParam(type: DataType("MyType", referenceCapability: ReferenceCapability.Borrowed)); 15 | var mockGraph = new Mock(); 16 | var v = new CallerVariable(mockGraph.Object, sym); 17 | 18 | var actual = v.ToString(); 19 | 20 | Assert.Equal("⟦self⟧: mut MyType", actual); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Tests.Unit.Semantics.Reachability.Graph/GlobalSuppressions.cs: -------------------------------------------------------------------------------- 1 | // This file is used by Code Analysis to maintain SuppressMessage 2 | // attributes that are applied to this project. 3 | // Project-level suppressions either have no target or are given 4 | // a specific target and scoped to a namespace, type, member, etc. 5 | 6 | using System.Diagnostics.CodeAnalysis; 7 | 8 | [assembly: SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Unit test naming")] 9 | -------------------------------------------------------------------------------- /Tests.Unit.Semantics.Reachability.Graph/MoqExtensions.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Core.Promises; 2 | using Adamant.Tools.Compiler.Bootstrap.Types; 3 | using Moq.Language; 4 | using Moq.Language.Flow; 5 | 6 | namespace Adamant.Tools.Compiler.Bootstrap.Tests.Unit.Semantics.Reachability.Graph 7 | { 8 | public static class MoqExtensions 9 | { 10 | public static IReturnsResult Returns(this IReturns> mock, DataType type) 11 | where TMock : class 12 | { 13 | var promise = new AcyclicPromise(); 14 | promise.BeginFulfilling(); 15 | promise.Fulfill(type); 16 | return mock.Returns(promise); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Tests.Unit.Symbols/ConstructorTests.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Symbols; 2 | using Xunit; 3 | 4 | namespace Adamant.Tools.Compiler.Bootstrap.Tests.Unit.Symbols 5 | { 6 | [Trait("Category", "Symbols")] 7 | public class ConstructorTests : SymbolTestFixture 8 | { 9 | [Fact] 10 | public void Default_constructor_has_correct_properties() 11 | { 12 | var type = Type(); 13 | var defaultConstructor = ConstructorSymbol.CreateDefault(type); 14 | 15 | Assert.Equal(type, defaultConstructor.ContainingSymbol); 16 | Assert.Null(defaultConstructor.Name); 17 | Assert.Empty(defaultConstructor.ParameterDataTypes); 18 | Assert.Equal(0, defaultConstructor.Arity); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Tests.Unit.Symbols/GlobalSuppressions.cs: -------------------------------------------------------------------------------- 1 | // This file is used by Code Analysis to maintain SuppressMessage 2 | // attributes that are applied to this project. 3 | // Project-level suppressions either have no target or are given 4 | // a specific target and scoped to a namespace, type, member, etc. 5 | 6 | using System.Diagnostics.CodeAnalysis; 7 | 8 | [assembly: SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Unit test naming")] 9 | -------------------------------------------------------------------------------- /Tests.Unit.Symbols/PackageSymbolTests.cs: -------------------------------------------------------------------------------- 1 | using Xunit; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.Tests.Unit.Symbols 4 | { 5 | [Trait("Category", "Symbols")] 6 | public class PackageSymbolTests : SymbolTestFixture 7 | { 8 | [Fact] 9 | public void Packages_with_same_name_are_equal() 10 | { 11 | var p1 = Package("some.package.name"); 12 | var p2 = Package("some.package.name"); 13 | 14 | Assert.Equal(p1, p2); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Tests.Unit.Symbols/SymbolTests.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Names; 2 | using Adamant.Tools.Compiler.Bootstrap.Symbols; 3 | using Moq; 4 | using Xunit; 5 | 6 | namespace Adamant.Tools.Compiler.Bootstrap.Tests.Unit.Symbols 7 | { 8 | [Trait("Category", "Symbols")] 9 | public class SymbolTests : SymbolTestFixture 10 | { 11 | [Fact] 12 | public void Symbol_not_in_namespace_is_global() 13 | { 14 | var symbol = FakeSymbol(null, Name("My_Class")); 15 | 16 | Assert.True(symbol.IsGlobal); 17 | } 18 | 19 | [Fact] 20 | public void Symbol_in_namespace_is_not_global() 21 | { 22 | var symbol = FakeSymbol(Namespace(), Name("My_Class")); 23 | 24 | Assert.False(symbol.IsGlobal); 25 | } 26 | 27 | private static Symbol FakeSymbol(NamespaceOrPackageSymbol? containing, Name name) 28 | { 29 | return new Mock(MockBehavior.Default, containing, name).Object; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Tests.Unit.Types/DataTypeTests.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Types; 2 | using Xunit; 3 | 4 | namespace Adamant.Tools.Compiler.Bootstrap.Tests.Unit.Types 5 | { 6 | [Trait("Category", "Types")] 7 | public class DataTypeTests 8 | { 9 | [Fact] 10 | public void None_type_is_optional_never() 11 | { 12 | var none = DataType.None; 13 | 14 | Assert.OfType(none); 15 | Assert.Equal(NeverType.Instance, none.Referent); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Tests.Unit.Types/GlobalSuppressions.cs: -------------------------------------------------------------------------------- 1 | // This file is used by Code Analysis to maintain SuppressMessage 2 | // attributes that are applied to this project. 3 | // Project-level suppressions either have no target or are given 4 | // a specific target and scoped to a namespace, type, member, etc. 5 | 6 | using System.Diagnostics.CodeAnalysis; 7 | 8 | [assembly: SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Unit test naming")] 9 | -------------------------------------------------------------------------------- /Tests.Unit.Types/ReferenceCapabilityTests.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Types; 2 | using Xunit; 3 | using static Adamant.Tools.Compiler.Bootstrap.Types.ReferenceCapability; 4 | 5 | namespace Adamant.Tools.Compiler.Bootstrap.Tests.Unit.Types 6 | { 7 | [Trait("Category", "Types")] 8 | public class ReferenceCapabilityTests 9 | { 10 | [Fact] 11 | public void Source_code_string_of_shared_is_empty() 12 | { 13 | var sourceCode = Shared.ToSourceCodeString(); 14 | 15 | Assert.Equal("", sourceCode); 16 | } 17 | 18 | /// 19 | /// It is frequently confusing that shared has no textual keyword. In 20 | /// IL, we make sharing it explicit. 21 | /// 22 | [Fact] 23 | public void IL_string_of_shared_is_empty() 24 | { 25 | var sourceCode = Shared.ToILString(); 26 | 27 | Assert.Equal("shared", sourceCode); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Tests.Unit/CSharpNameResolutionTests.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics.CodeAnalysis; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.Tests.Unit 4 | { 5 | namespace OuterNamespace 6 | { 7 | public class TestClass1 { } 8 | public class TestClass1 { } 9 | 10 | namespace InnerNamespace 11 | { 12 | public class TestClass1 13 | { 14 | } 15 | 16 | public static class Tester 17 | { 18 | [SuppressMessage("Style", "IDE0059:Unnecessary assignment of a value", Justification = "")] 19 | public static void TestMethod() 20 | { 21 | TestClass1 t1 = new TestClass1(); 22 | TestClass1 t2 = new TestClass1(); 23 | } 24 | } 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Tests.Unit/Fakes/FakeCodeFile.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Core; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.Tests.Unit.Fakes 4 | { 5 | public static class FakeCodeFile 6 | { 7 | 8 | public static CodeFile For(string text) 9 | { 10 | return new CodeFile(FakeCodeReference.Instance, new CodeText(text)); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Tests.Unit/Fakes/FakeCodeReference.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Adamant.Tools.Compiler.Bootstrap.Core; 3 | using Adamant.Tools.Compiler.Bootstrap.Framework; 4 | 5 | namespace Adamant.Tools.Compiler.Bootstrap.Tests.Unit.Fakes 6 | { 7 | internal class FakeCodeReference : CodeReference 8 | { 9 | #region Singleton 10 | 11 | public static readonly FakeCodeReference Instance = new FakeCodeReference(); 12 | 13 | private FakeCodeReference() 14 | : base(FixedList.Empty) 15 | { } 16 | #endregion 17 | 18 | public override string ToString() 19 | { 20 | throw new InvalidOperationException("Fake doesn't support ToString()"); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Tests.Unit/Helpers/GeneratorExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.CompilerServices; 3 | using FsCheck; 4 | 5 | namespace Adamant.Tools.Compiler.Bootstrap.Tests.Unit.Helpers 6 | { 7 | public static class GeneratorExtensions 8 | { 9 | public static WeightAndValue> WithWeight( 10 | this Gen generator, 11 | int weight) 12 | { 13 | return new WeightAndValue>(weight, generator); 14 | } 15 | 16 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 17 | 18 | public static T NotNull(this NonNull value, string paramName) 19 | where T : class 20 | { 21 | return (value ?? throw new ArgumentNullException(paramName)).Get; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Tests.Unit/Helpers/SolutionDirectory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Linq; 4 | 5 | namespace Adamant.Tools.Compiler.Bootstrap.Tests.Unit.Helpers 6 | { 7 | public static class SolutionDirectory 8 | { 9 | public static string Get() 10 | { 11 | var directory = Directory.GetCurrentDirectory() ?? throw new InvalidOperationException("Could not get current directory"); 12 | while (directory != null && !Directory.GetFiles(directory, "*.sln", SearchOption.TopDirectoryOnly).Any()) 13 | { 14 | directory = Path.GetDirectoryName(directory) ?? throw new InvalidOperationException("Null directory name"); 15 | } 16 | return directory ?? throw new InvalidOperationException("Compiler is confused, this can't be null"); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Tests.Unit/README.md: -------------------------------------------------------------------------------- 1 | # Adamant.Tools.Compiler.Bootstrap.Tests.Unit 2 | 3 | This is a place for code to make writing tests easier. 4 | -------------------------------------------------------------------------------- /Tokens/BareIdentifierToken.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Core; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.Tokens 4 | { 5 | internal class BareIdentifierToken : IdentifierToken, IBareIdentifierToken 6 | { 7 | public BareIdentifierToken(TextSpan span, string value) 8 | : base(span, value) 9 | { 10 | } 11 | } 12 | 13 | public static partial class TokenFactory 14 | { 15 | public static IIdentifierToken BareIdentifier(TextSpan span, string value) 16 | { 17 | return new BareIdentifierToken(span, value); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Tokens/EscapedIdentifierToken.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Core; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.Tokens 4 | { 5 | internal class EscapedIdentifierToken : IdentifierToken, IEscapedIdentifierToken 6 | { 7 | public EscapedIdentifierToken(TextSpan span, string value) 8 | : base(span, value) 9 | { 10 | } 11 | } 12 | 13 | public static partial class TokenFactory 14 | { 15 | 16 | public static IEscapedIdentifierToken EscapedIdentifier(TextSpan span, string value) 17 | { 18 | return new EscapedIdentifierToken(span, value); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Tokens/FalseKeywordToken.cs: -------------------------------------------------------------------------------- 1 | namespace Adamant.Tools.Compiler.Bootstrap.Tokens 2 | { 3 | internal partial class FalseKeywordToken 4 | { 5 | public bool Value => false; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Tokens/IAccessModifierToken.cs: -------------------------------------------------------------------------------- 1 | using ExhaustiveMatching; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.Tokens 4 | { 5 | [Closed( 6 | typeof(IPublishedKeywordToken), 7 | typeof(IPublicKeywordToken) 8 | )] 9 | public partial interface IAccessModifierToken : IKeywordToken { } 10 | 11 | public partial interface IPublishedKeywordToken : IAccessModifierToken { } 12 | public partial interface IPublicKeywordToken : IAccessModifierToken { } 13 | } 14 | -------------------------------------------------------------------------------- /Tokens/IAccessOperatorToken.cs: -------------------------------------------------------------------------------- 1 | using ExhaustiveMatching; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.Tokens 4 | { 5 | [Closed( 6 | typeof(IDotToken), 7 | typeof(IQuestionDotToken))] 8 | public interface IAccessOperatorToken : IOperatorToken { } 9 | 10 | public partial interface IDotToken : IAccessOperatorToken { } 11 | public partial interface IQuestionDotToken : IAccessOperatorToken { } 12 | } 13 | -------------------------------------------------------------------------------- /Tokens/IAssignmentToken.cs: -------------------------------------------------------------------------------- 1 | using ExhaustiveMatching; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.Tokens 4 | { 5 | [Closed( 6 | typeof(IEqualsToken), 7 | typeof(IPlusEqualsToken), 8 | typeof(IMinusEqualsToken), 9 | typeof(IAsteriskEqualsToken), 10 | typeof(ISlashEqualsToken))] 11 | public interface IAssignmentToken : IOperatorToken { } 12 | 13 | public partial interface IEqualsToken : IAssignmentToken { } 14 | public partial interface IPlusEqualsToken : IAssignmentToken { } 15 | public partial interface IMinusEqualsToken : IAssignmentToken { } 16 | public partial interface IAsteriskEqualsToken : IAssignmentToken { } 17 | public partial interface ISlashEqualsToken : IAssignmentToken { } 18 | } 19 | -------------------------------------------------------------------------------- /Tokens/IBareIdentifierToken.cs: -------------------------------------------------------------------------------- 1 | namespace Adamant.Tools.Compiler.Bootstrap.Tokens 2 | { 3 | /// 4 | /// A bare identifier is one that isn't escaped 5 | /// 6 | public interface IBareIdentifierToken : IIdentifierToken 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Tokens/IBindingToken.cs: -------------------------------------------------------------------------------- 1 | using ExhaustiveMatching; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.Tokens 4 | { 5 | [Closed( 6 | typeof(ILetKeywordToken), 7 | typeof(IVarKeywordToken))] 8 | public interface IBindingToken : IKeywordToken { } 9 | 10 | public partial interface ILetKeywordToken : IBindingToken { } 11 | public partial interface IVarKeywordToken : IBindingToken { } 12 | } 13 | -------------------------------------------------------------------------------- /Tokens/IBooleanLiteralToken.cs: -------------------------------------------------------------------------------- 1 | using ExhaustiveMatching; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.Tokens 4 | { 5 | [Closed( 6 | typeof(ITrueKeywordToken), 7 | typeof(IFalseKeywordToken))] 8 | public partial interface IBooleanLiteralToken : IKeywordToken 9 | { 10 | bool Value { get; } 11 | } 12 | 13 | public partial interface ITrueKeywordToken : IBooleanLiteralToken { } 14 | public partial interface IFalseKeywordToken : IBooleanLiteralToken { } 15 | } 16 | -------------------------------------------------------------------------------- /Tokens/ICapabilityToken.cs: -------------------------------------------------------------------------------- 1 | using ExhaustiveMatching; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.Tokens 4 | { 5 | [Closed( 6 | typeof(IOwnedKeywordToken), 7 | typeof(IIsolatedKeywordToken), 8 | typeof(IHeldKeywordToken), 9 | typeof(IMutableKeywordToken), 10 | typeof(IIdKeywordToken))] 11 | public interface ICapabilityToken : IKeywordToken { } 12 | 13 | public partial interface IOwnedKeywordToken : ICapabilityToken { } 14 | public partial interface IIsolatedKeywordToken : ICapabilityToken { } 15 | public partial interface IHeldKeywordToken : ICapabilityToken { } 16 | public partial interface IMutableKeywordToken : ICapabilityToken { } 17 | public partial interface IIdKeywordToken : ICapabilityToken { } 18 | } 19 | -------------------------------------------------------------------------------- /Tokens/IEscapedIdentifierToken.cs: -------------------------------------------------------------------------------- 1 | namespace Adamant.Tools.Compiler.Bootstrap.Tokens 2 | { 3 | public interface IEscapedIdentifierToken : IIdentifierToken { } 4 | } 5 | -------------------------------------------------------------------------------- /Tokens/IEssentialToken.cs: -------------------------------------------------------------------------------- 1 | using ExhaustiveMatching; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.Tokens 4 | { 5 | /// 6 | /// A token that isn't trivia 7 | /// 8 | [Closed( 9 | typeof(IStringLiteralToken), 10 | typeof(IKeywordToken), 11 | typeof(IIdentifierOrUnderscoreToken), 12 | typeof(IOperatorToken), 13 | typeof(ILiteralToken), 14 | typeof(IPrimitiveTypeToken), 15 | typeof(IBinaryOperatorToken), 16 | typeof(IPunctuationToken), 17 | typeof(IEndOfFileToken))] 18 | public partial interface IEssentialToken : IToken 19 | { 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Tokens/IIdentifierOrUnderscoreToken.cs: -------------------------------------------------------------------------------- 1 | using ExhaustiveMatching; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.Tokens 4 | { 5 | [Closed( 6 | typeof(IIdentifierToken))] 7 | public interface IIdentifierOrUnderscoreToken : IEssentialToken 8 | { 9 | string Value { get; } 10 | } 11 | 12 | public partial interface IIdentifierToken : IIdentifierOrUnderscoreToken { } 13 | //public partial interface IUnderscoreKeywordToken : IIdentifierOrUnderscoreToken { } 14 | 15 | //internal partial class UnderscoreKeywordToken 16 | //{ 17 | // public string Value => "_"; 18 | //} 19 | } 20 | -------------------------------------------------------------------------------- /Tokens/IIntegerLiteralToken.cs: -------------------------------------------------------------------------------- 1 | using System.Numerics; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.Tokens 4 | { 5 | public partial interface IIntegerLiteralToken : ILiteralToken 6 | { 7 | BigInteger Value { get; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Tokens/IKeywordToken.cs: -------------------------------------------------------------------------------- 1 | using ExhaustiveMatching; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.Tokens 4 | { 5 | [Closed( 6 | typeof(IMemberNameToken), 7 | typeof(IBindingToken), 8 | typeof(IModiferToken), 9 | typeof(IAccessModifierToken), 10 | typeof(ITypeKindKeywordToken), 11 | typeof(IBooleanLiteralToken), 12 | typeof(ICapabilityToken))] 13 | public partial interface IKeywordToken : IEssentialToken { } 14 | } 15 | -------------------------------------------------------------------------------- /Tokens/ILiteralToken.cs: -------------------------------------------------------------------------------- 1 | using ExhaustiveMatching; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.Tokens 4 | { 5 | [Closed( 6 | typeof(IBooleanLiteralToken), 7 | typeof(IIntegerLiteralToken), 8 | typeof(IStringLiteralToken), 9 | typeof(INoneKeywordToken) 10 | //typeof(IUninitializedKeywordToken) 11 | )] 12 | public interface ILiteralToken : IEssentialToken { } 13 | 14 | public partial interface IBooleanLiteralToken : ILiteralToken { } 15 | public partial interface IIntegerLiteralToken : ILiteralToken { } 16 | public partial interface IStringLiteralToken : ILiteralToken { } 17 | public partial interface INoneKeywordToken : ILiteralToken { } 18 | //public partial interface IUninitializedKeywordToken : ILiteralToken { } 19 | } 20 | -------------------------------------------------------------------------------- /Tokens/IMemberNameToken.cs: -------------------------------------------------------------------------------- 1 | using ExhaustiveMatching; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.Tokens 4 | { 5 | [Closed( 6 | typeof(IIdentifierToken), 7 | typeof(INewKeywordToken) 8 | //typeof(IInitKeywordToken) 9 | //typeof(IDeleteKeywordToken) 10 | )] 11 | public interface IMemberNameToken : IKeywordToken { } 12 | 13 | [Closed( 14 | typeof(IBareIdentifierToken), 15 | typeof(IEscapedIdentifierToken))] 16 | public partial interface IIdentifierToken : IMemberNameToken { } 17 | public partial interface INewKeywordToken : IMemberNameToken { } 18 | //public partial interface IInitKeywordToken : IMemberNameToken { } 19 | //public partial interface IDeleteKeywordToken : IMemberNameToken { } 20 | } 21 | -------------------------------------------------------------------------------- /Tokens/IModiferToken.cs: -------------------------------------------------------------------------------- 1 | using ExhaustiveMatching; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.Tokens 4 | { 5 | [Closed( 6 | typeof(IAccessModifierToken), 7 | typeof(IMutableKeywordToken), 8 | typeof(IMoveKeywordToken), 9 | typeof(ISafeKeywordToken), 10 | typeof(IUnsafeKeywordToken) 11 | )] 12 | public partial interface IModiferToken : IKeywordToken { } 13 | 14 | public partial interface IAccessModifierToken : IModiferToken { } 15 | public partial interface IMutableKeywordToken : IModiferToken { } 16 | public partial interface IMoveKeywordToken : IModiferToken { } 17 | public partial interface ISafeKeywordToken : IModiferToken { } 18 | public partial interface IUnsafeKeywordToken : IModiferToken { } 19 | } 20 | -------------------------------------------------------------------------------- /Tokens/IPunctuationToken.cs: -------------------------------------------------------------------------------- 1 | using ExhaustiveMatching; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.Tokens 4 | { 5 | [Closed( 6 | typeof(IOpenBraceToken), 7 | typeof(ICloseBraceToken), 8 | typeof(IOpenParenToken), 9 | typeof(ICloseParenToken), 10 | typeof(ISemicolonToken), 11 | typeof(IColonToken), 12 | typeof(IColonColonDotToken), 13 | typeof(ICommaToken))] 14 | public interface IPunctuationToken : IEssentialToken 15 | { 16 | } 17 | 18 | public partial interface IOpenBraceToken : IPunctuationToken { } 19 | public partial interface ICloseBraceToken : IPunctuationToken { } 20 | public partial interface IOpenParenToken : IPunctuationToken { } 21 | public partial interface ICloseParenToken : IPunctuationToken { } 22 | public partial interface ISemicolonToken : IPunctuationToken { } 23 | public partial interface IColonToken : IPunctuationToken { } 24 | public partial interface IColonColonDotToken : IPunctuationToken { } 25 | public partial interface ICommaToken : IPunctuationToken { } 26 | } 27 | -------------------------------------------------------------------------------- /Tokens/IStringLiteralToken.cs: -------------------------------------------------------------------------------- 1 | namespace Adamant.Tools.Compiler.Bootstrap.Tokens 2 | { 3 | public partial interface IStringLiteralToken : IEssentialToken 4 | { 5 | string Value { get; } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Tokens/IToken.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Core; 2 | using ExhaustiveMatching; 3 | 4 | namespace Adamant.Tools.Compiler.Bootstrap.Tokens 5 | { 6 | /// 7 | /// A non-missing token 8 | /// 9 | [Closed( 10 | typeof(IEssentialToken), 11 | typeof(ITriviaToken))] 12 | public partial interface IToken 13 | { 14 | TextSpan Span { get; } 15 | 16 | string Text(CodeText code); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Tokens/ITypeKindKeywordToken.cs: -------------------------------------------------------------------------------- 1 | namespace Adamant.Tools.Compiler.Bootstrap.Tokens 2 | { 3 | public interface ITypeKindKeywordToken : IKeywordToken { } 4 | 5 | public partial interface IClassKeywordToken : ITypeKindKeywordToken { } 6 | //public partial interface IStructKeywordToken : ITypeKindKeywordToken { } 7 | } 8 | -------------------------------------------------------------------------------- /Tokens/IdentifierToken.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Core; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.Tokens 4 | { 5 | internal abstract class IdentifierToken : Token 6 | { 7 | public string Value { get; } 8 | 9 | protected IdentifierToken(TextSpan span, string value) 10 | : base(span) 11 | { 12 | Value = value; 13 | } 14 | 15 | // Helpful for debugging 16 | public override string ToString() 17 | { 18 | return Value; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Tokens/IntegerLiteralToken.cs: -------------------------------------------------------------------------------- 1 | using System.Globalization; 2 | using System.Numerics; 3 | using Adamant.Tools.Compiler.Bootstrap.Core; 4 | 5 | namespace Adamant.Tools.Compiler.Bootstrap.Tokens 6 | { 7 | internal class IntegerLiteralToken : Token, IIntegerLiteralToken 8 | { 9 | public BigInteger Value { get; } 10 | 11 | public IntegerLiteralToken(TextSpan span, BigInteger value) 12 | : base(span) 13 | { 14 | Value = value; 15 | } 16 | 17 | // Helpful for debugging 18 | 19 | public override string ToString() => Value.ToString(CultureInfo.InvariantCulture); 20 | } 21 | 22 | public static partial class TokenFactory 23 | { 24 | 25 | public static IIntegerLiteralToken IntegerLiteral(TextSpan span, BigInteger value) 26 | { 27 | return new IntegerLiteralToken(span, value); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Tokens/OperatorPrecedence.cs: -------------------------------------------------------------------------------- 1 | namespace Adamant.Tools.Compiler.Bootstrap.Tokens 2 | { 3 | public enum OperatorPrecedence 4 | { 5 | Min = Assignment, // The minimum precedence 6 | AboveAssignment = Coalesce, 7 | Assignment = 1, // `=` `+=` `-=` 8 | Coalesce, // `??` 9 | LogicalOr, // `or` 10 | LogicalAnd, // `and` 11 | Equality, // `==` `≠` 12 | Relational, // `<` `<=` `>` `>=` `<:` 13 | Range, // `..` `..<` 14 | Additive, // `+` `-` 15 | Multiplicative, // `*` `/` 16 | Lifetime, // `$` 17 | Unary, // `+` `-` `not` `?` 18 | Primary // `f()` `.` `[]` 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Tokens/StringLiteralToken.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Core; 2 | using Adamant.Tools.Compiler.Bootstrap.Framework; 3 | 4 | namespace Adamant.Tools.Compiler.Bootstrap.Tokens 5 | { 6 | internal class StringLiteralToken : Token, IStringLiteralToken 7 | { 8 | public string Value { get; } 9 | 10 | public StringLiteralToken(TextSpan span, string value) 11 | : base(span) 12 | { 13 | Value = value; 14 | } 15 | 16 | // Helpful for debugging 17 | public override string ToString() 18 | { 19 | return '"' + Value.Escape() + '"'; 20 | } 21 | } 22 | 23 | public static partial class TokenFactory 24 | { 25 | 26 | public static IStringLiteralToken StringLiteral(TextSpan span, string value) 27 | { 28 | return new StringLiteralToken(span, value); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Tokens/Token.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Core; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.Tokens 4 | { 5 | internal abstract class Token 6 | { 7 | public TextSpan Span { get; } 8 | 9 | protected Token(TextSpan span) 10 | { 11 | Span = span; 12 | } 13 | public string Text(CodeText code) 14 | { 15 | return Span.GetText(code.Text); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Tokens/TrueKeywordToken.cs: -------------------------------------------------------------------------------- 1 | namespace Adamant.Tools.Compiler.Bootstrap.Tokens 2 | { 3 | internal partial class TrueKeywordToken 4 | { 5 | public bool Value => true; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Types/BoolType.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Names; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.Types 4 | { 5 | public class BoolType : SimpleType 6 | { 7 | #region Singleton 8 | internal static readonly BoolType Instance = new BoolType(); 9 | 10 | private BoolType() 11 | : base(SpecialTypeName.Bool) 12 | { } 13 | #endregion 14 | 15 | private protected BoolType(SpecialTypeName name) 16 | : base(name) { } 17 | 18 | public override bool IsKnown => true; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Types/IntegerType.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Names; 2 | using ExhaustiveMatching; 3 | 4 | namespace Adamant.Tools.Compiler.Bootstrap.Types 5 | { 6 | [Closed( 7 | typeof(IntegerConstantType), 8 | typeof(FixedSizeIntegerType), 9 | typeof(PointerSizedIntegerType))] 10 | public abstract class IntegerType : NumericType 11 | { 12 | private protected IntegerType(SpecialTypeName name) 13 | : base(name) 14 | { 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Types/InternalsVisibleTo.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.CompilerServices; 2 | 3 | [assembly: InternalsVisibleTo("Adamant.Tools.Compiler.Bootstrap.Tests.Unit.Types")] 4 | -------------------------------------------------------------------------------- /Types/NeverType.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Names; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.Types 4 | { 5 | /// 6 | /// The never or bottom type. That is a type with no values. A function 7 | /// with return type `never` must never return by normal means. It always 8 | /// either throws an exception, abandons the process or doesn't terminate. 9 | /// Because it is the bottom type, it is assignment compatible to all types 10 | /// this makes it particularly useful as the result type of expressions like 11 | /// `throw`, `return` and `break` which never produce a result. It is also 12 | /// used as the type of a `loop` statement with no breaks in it. 13 | /// 14 | public sealed class NeverType : EmptyType 15 | { 16 | #region Singleton 17 | internal static readonly NeverType Instance = new NeverType(); 18 | 19 | private NeverType() 20 | : base(SpecialTypeName.Never) 21 | { } 22 | #endregion 23 | 24 | public override TypeSemantics Semantics => TypeSemantics.Never; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Types/NumericType.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Names; 2 | using ExhaustiveMatching; 3 | 4 | namespace Adamant.Tools.Compiler.Bootstrap.Types 5 | { 6 | [Closed( 7 | //typeof(FloatingPointType), 8 | typeof(IntegerType))] 9 | public abstract class NumericType : SimpleType 10 | { 11 | private protected NumericType(SpecialTypeName name) 12 | : base(name) 13 | { 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Types/PointerSizedIntegerType.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Names; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.Types 4 | { 5 | /// 6 | /// Integer types whose exact bit length is architecture dependent and whose 7 | /// length matches that of pointers 8 | /// 9 | public sealed class PointerSizedIntegerType : IntegerType 10 | { 11 | internal new static readonly PointerSizedIntegerType Size = new PointerSizedIntegerType(SpecialTypeName.Size, false); 12 | internal new static readonly PointerSizedIntegerType Offset = new PointerSizedIntegerType(SpecialTypeName.Offset, true); 13 | 14 | public bool IsSigned { get; } 15 | public override bool IsKnown => true; 16 | 17 | private PointerSizedIntegerType(SpecialTypeName name, bool signed) 18 | : base(name) 19 | { 20 | IsSigned = signed; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Types/ReferenceTypeExtensions.cs: -------------------------------------------------------------------------------- 1 | namespace Adamant.Tools.Compiler.Bootstrap.Types 2 | { 3 | public static class ReferenceTypeExtensions 4 | { 5 | /// 6 | /// Return the same type except with the given reference capability 7 | /// 8 | public static T To(this T type, ReferenceCapability referenceCapability) 9 | where T : ReferenceType 10 | { 11 | return type.To_ReturnsSelf(referenceCapability).Cast(); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Types/StringConstantType.cs: -------------------------------------------------------------------------------- 1 | namespace Adamant.Tools.Compiler.Bootstrap.Types 2 | { 3 | // TODO implement StringConstantType 4 | } 5 | -------------------------------------------------------------------------------- /Types/ValueType.cs: -------------------------------------------------------------------------------- 1 | using ExhaustiveMatching; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.Types 4 | { 5 | [Closed( 6 | typeof(SimpleType), 7 | typeof(OptionalType))] 8 | public abstract class ValueType : DataType 9 | { 10 | private protected ValueType() { } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Types/VoidType.cs: -------------------------------------------------------------------------------- 1 | using Adamant.Tools.Compiler.Bootstrap.Names; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.Types 4 | { 5 | /// 6 | /// The void type behaves similar to a unit type. However it represents the 7 | /// lack of a value. For example, a function returning `void` doesn't return 8 | /// a value. A parameter of type `void` is dropped from the parameter list. 9 | /// 10 | public class VoidType : EmptyType 11 | { 12 | #region Singleton 13 | internal static readonly VoidType Instance = new VoidType(); 14 | 15 | private VoidType() 16 | : base(SpecialTypeName.Void) 17 | { } 18 | #endregion 19 | 20 | public override bool IsEmpty => true; 21 | 22 | public override bool IsKnown => true; 23 | 24 | public override TypeSemantics Semantics => TypeSemantics.Void; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /adamantc/Properties/PublishProfiles/Win-x64.pubxml: -------------------------------------------------------------------------------- 1 |  2 | 5 | 6 | 7 | FileSystem 8 | Release 9 | Any CPU 10 | netcoreapp2.0 11 | bin\publish\win-x64 12 | win-x64 13 | true 14 | <_IsPortable>false 15 | 16 | -------------------------------------------------------------------------------- /docs/CoreFeatures.md: -------------------------------------------------------------------------------- 1 | # Core Features 2 | 3 | This is a list of core features that need to be implemented or at least accounted for in the design of the compiler. 4 | 5 | * Borrow Checking (lifetimes) 6 | * Rebinding of local variables (for `let` and in separate scopes for `var`) 7 | * Binding mutability checking (i.e. `let` vs `var`) 8 | * Local variables 9 | * Parameters 10 | * Self Parameter 11 | * Global Variables 12 | * Mutability 13 | * Reference Types (on class and type declaration) 14 | * Value Types 15 | * Type Checking 16 | * Overload Functions on Arity 17 | * Overload Functions on Type 18 | * Runtime Code Execution 19 | * Generic Types 20 | * Associated Functions 21 | * Generic Types over Values (i.e. fixed length arrays) 22 | * Definite assignment 23 | * Destructor value access rules 24 | * Exception types 25 | * Effect Typing 26 | * Async/await 27 | * Inheritance 28 | * Interface implementation 29 | * Closures (esp. given lifetimes) 30 | * Pseudo references 31 | * Optional Types 32 | * Void type as type parameter 33 | * Unsafe code 34 | * Type Inference 35 | * Constant Evaluation 36 | -------------------------------------------------------------------------------- /docs/Implemented.md: -------------------------------------------------------------------------------- 1 | # Features Implemented 2 | -------------------------------------------------------------------------------- /forge/Build/ProjectReference.cs: -------------------------------------------------------------------------------- 1 | namespace Adamant.Tools.Compiler.Bootstrap.Forge.Build 2 | { 3 | internal class ProjectReference 4 | { 5 | public string Name { get; } 6 | public Project Project { get; } 7 | public bool Trusted { get; } 8 | 9 | public ProjectReference(string name, Project project, bool trusted) 10 | { 11 | Name = name; 12 | Project = project; 13 | Trusted = trusted; 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /forge/CommandOptionExtensions.cs: -------------------------------------------------------------------------------- 1 | using McMaster.Extensions.CommandLineUtils; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.Forge 4 | { 5 | public static class CommandOptionExtensions 6 | { 7 | public static T? OptionalValue(this CommandOption option) 8 | where T : struct 9 | { 10 | // Trying to use just `default` leads to 0 for int 11 | return option.HasValue() ? option.ParsedValue : default(T?); 12 | } 13 | 14 | /// For cases are supported 15 | /// * "--option" returns true 16 | /// * "--option=true" returns true 17 | /// * "--option=false" returns false 18 | /// * "" returns null 19 | public static bool? OptionalValue(this CommandOption option) 20 | { 21 | return option.HasValue() ? (option.Value() is null || option.ParsedValue) : default(bool?); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /forge/Config/ProjectDependencyConfig.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace Adamant.Tools.Compiler.Bootstrap.Forge.Config 4 | { 5 | public class ProjectDependencyConfig 6 | { 7 | [JsonProperty("path")] 8 | public string? Path { get; set; } 9 | 10 | [JsonProperty("trusted")] 11 | public bool? Trusted { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /forge/Config/ProjectTemplate.cs: -------------------------------------------------------------------------------- 1 | namespace Adamant.Tools.Compiler.Bootstrap.Forge.Config 2 | { 3 | internal enum ProjectTemplate 4 | { 5 | App, 6 | Lib, 7 | //Web, // TODO add web template 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /runtime/.gitignore: -------------------------------------------------------------------------------- 1 | .forge-cache/ 2 | -------------------------------------------------------------------------------- /runtime/forge-project.vson: -------------------------------------------------------------------------------- 1 | { 2 | "name": "adamant.tools.compiler.runtime", 3 | "authors": ["Jeff Walker Code Ranger"], 4 | "template": "lib" 5 | } 6 | -------------------------------------------------------------------------------- /runtime/src/Optional.ad: -------------------------------------------------------------------------------- 1 | namespace adamant.tools.compiler.runtime; 2 | 3 | public enum struct Optional[T] 4 | { 5 | Some(T), 6 | None 7 | } 8 | -------------------------------------------------------------------------------- /runtime/src/String.ad: -------------------------------------------------------------------------------- 1 | namespace adamant.tools.compiler.runtime; 2 | 3 | /// String is a good example where treating the psuedo reference lifetime as just 4 | /// $self wouldn't make sense. For example, a string literal would have a "static" 5 | /// lifetime even though the struct referencing it would have a shorter lifetime. 6 | /// Thus the lifetime needs to be a separate lifetime parameter. Thus the new 7 | /// syntax of `ref struct` and the lifetime `$ref`. 8 | public ref struct String 9 | { 10 | public let count: size; 11 | protected let data: @byte; 12 | 13 | // Unsafe because it can violate the invariants that `data` point to a buffer 14 | // of at least `count` bytes and that those bytes be valid UTF-8 15 | public unsafe init(count: size, data: @byte) 16 | { 17 | self.count = count; 18 | self.data = data; 19 | } 20 | 21 | // TODO the string needs to delete the memory if it is owned, but we don't 22 | // have the allocate/free functions in the runtime? 23 | // public safe delete() 24 | // { 25 | 26 | // } 27 | } 28 | --------------------------------------------------------------------------------