diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 4e561b5..bf45221 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -1,4 +1,4 @@ -name: Gwydion CI/CD +name: Selene CI/CD on: push: @@ -48,9 +48,9 @@ jobs: - name: Rename and upload compiler artifacts run: | mkdir -p artifacts - cp compiler/build/libs/gwydion.jar artifacts/gwydion-compiler-jvm.jar - cp compiler/build/bin/linuxX64/releaseExecutable/compiler.kexe artifacts/gwydion-compiler-linuxX64 - cp compiler/build/bin/windowsX64/releaseExecutable/compiler.exe artifacts/gwydion-compiler-windowsX64.exe + cp compiler/build/libs/selene.jar artifacts/selene-compiler-jvm.jar + cp compiler/build/bin/linuxX64/releaseExecutable/compiler.kexe artifacts/selene-compiler-linuxX64 + cp compiler/build/bin/windowsX64/releaseExecutable/compiler.exe artifacts/selene-compiler-windowsX64.exe - uses: actions/upload-artifact@v3 with: name: compiler-artifacts @@ -80,9 +80,9 @@ jobs: uses: softprops/action-gh-release@v1 with: files: | - compiler-artifacts/gwydion-compiler-jvm.jar - compiler-artifacts/gwydion-compiler-linuxX64 - compiler-artifacts/gwydion-compiler-windowsX64.exe + compiler-artifacts/selene-compiler-jvm.jar + compiler-artifacts/selene-compiler-linuxX64 + compiler-artifacts/selene-compiler-windowsX64.exe jester/jester env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/README.md b/README.md index 2318052..0dd40a4 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,14 @@ -# 🐉 gwydion +# 🍂 selene --- -This is a project I created to learn more about low-level programming and delve into the world of compilers. The goal is to create a simple programming language that compiles to LLVM IR. +Selene is a statically-typed, imperative and procedural programming language compiled to LLVM IR. -You may look at the code and think the means to my desired end are incorrect and/or inefficient. That's not a bug, but a feature, as they say in San Francisco. I'm doing this to learn and mess around, so I won't hesitate to break stuff if it means I'll learn something new. +The language is designed to be as easy to grasp as possible, while still providing a powerful set of features. It aims to combine the best of all worlds, providing a simple and easy-to-understand syntax, while still being powerful enough to be used in real-world applications. --- -# Example +# Examples Basic input/output: ```go diff --git a/analysis/src/commonMain/kotlin/Errors.kt b/analysis/src/commonMain/kotlin/Errors.kt index f42723e..010c260 100644 --- a/analysis/src/commonMain/kotlin/Errors.kt +++ b/analysis/src/commonMain/kotlin/Errors.kt @@ -1,9 +1,9 @@ -package me.gabriel.gwydion.analysis +package me.gabriel.selene.analysis -import me.gabriel.gwydion.frontend.GwydionType -import me.gabriel.gwydion.frontend.lexing.TokenKind -import me.gabriel.gwydion.frontend.parsing.CallNode -import me.gabriel.gwydion.frontend.parsing.SyntaxTreeNode +import me.gabriel.selene.frontend.SeleneType +import me.gabriel.selene.frontend.lexing.TokenKind +import me.gabriel.selene.frontend.parsing.CallNode +import me.gabriel.selene.frontend.parsing.SyntaxTreeNode data class AnalysisResult( val errors: MutableList = mutableListOf(), @@ -11,7 +11,7 @@ data class AnalysisResult( ) sealed class AnalysisError(val message: String, val node: SyntaxTreeNode) { - class InvalidOperation(node: SyntaxTreeNode, leftType: GwydionType, operator: TokenKind, rightType: GwydionType) : AnalysisError( + class InvalidOperation(node: SyntaxTreeNode, leftType: SeleneType, operator: TokenKind, rightType: SeleneType) : AnalysisError( "invalid operation: cannot run $operator.sig on ${leftType.signature} and ${rightType.signature}", node ) @@ -24,7 +24,7 @@ sealed class AnalysisError(val message: String, val node: SyntaxTreeNode) { node ) - class ReturnTypeMismatch(node: SyntaxTreeNode, expected: GwydionType, actual: GwydionType) : AnalysisError( + class ReturnTypeMismatch(node: SyntaxTreeNode, expected: SeleneType, actual: SeleneType) : AnalysisError( "return type mismatch: expected ${expected.signature}, got ${actual.signature}", node ) @@ -44,12 +44,12 @@ sealed class AnalysisError(val message: String, val node: SyntaxTreeNode) { node ) - class UnknownType(node: SyntaxTreeNode, type: GwydionType) : AnalysisError( + class UnknownType(node: SyntaxTreeNode, type: SeleneType) : AnalysisError( "unknown type: ${type.signature}", node ) - class InvalidCondition(node: SyntaxTreeNode, type: GwydionType) : AnalysisError( + class InvalidCondition(node: SyntaxTreeNode, type: SeleneType) : AnalysisError( "invalid condition: condition must be a boolean expression, got ${type.signature}", node ) @@ -58,7 +58,7 @@ sealed class AnalysisError(val message: String, val node: SyntaxTreeNode) { "undefined array: $name", node ) - class NotAnArray(node: SyntaxTreeNode, type: GwydionType) : AnalysisError( + class NotAnArray(node: SyntaxTreeNode, type: SeleneType) : AnalysisError( "not an array: ${type.signature}", node ) @@ -71,7 +71,7 @@ sealed class AnalysisError(val message: String, val node: SyntaxTreeNode) { class MissingArgumentsForInstantiation( node: SyntaxTreeNode, name: String, - arguments: Map + arguments: Map ) : AnalysisError( "missing arguments for instantiation of $name: ${arguments.keys.joinToString(", ") { "$it (${arguments[it]!!.signature})" @@ -122,7 +122,7 @@ sealed class AnalysisError(val message: String, val node: SyntaxTreeNode) { function: String, trait: String, struct: String, - correct: List, + correct: List, ) : AnalysisError( "wrong function signature `$function` in trait impl $trait for $struct, expected${ if (correct.isEmpty()) " no parameters" @@ -131,7 +131,7 @@ sealed class AnalysisError(val message: String, val node: SyntaxTreeNode) { node ) - class BinaryOpTypeMismatch(node: SyntaxTreeNode, left: GwydionType, right: GwydionType) : AnalysisError( + class BinaryOpTypeMismatch(node: SyntaxTreeNode, left: SeleneType, right: SeleneType) : AnalysisError( "binary operation type mismatch: ${left.signature} and ${right.signature}", node ) @@ -141,7 +141,7 @@ sealed class AnalysisError(val message: String, val node: SyntaxTreeNode) { node ) - class WrongArgumentTypeForInstantiation(node: SyntaxTreeNode, expected: GwydionType, provided: GwydionType) : AnalysisError( + class WrongArgumentTypeForInstantiation(node: SyntaxTreeNode, expected: SeleneType, provided: SeleneType) : AnalysisError( "wrong argument type for instantiation: expected ${expected.signature}, got ${provided.signature}", node ) @@ -162,19 +162,19 @@ sealed class AnalysisError(val message: String, val node: SyntaxTreeNode) { class ArrayElementTypeMismatch( node: SyntaxTreeNode, index: Int, - provided: GwydionType, - expected: GwydionType + provided: SeleneType, + expected: SeleneType ): AnalysisError( "array element type mismatch: expected ${expected.signature}, got ${provided.signature} at index $index", node ) - class NotADataStructure(node: SyntaxTreeNode, type: GwydionType) : AnalysisError( + class NotADataStructure(node: SyntaxTreeNode, type: SeleneType) : AnalysisError( "not a data structure: ${type.signature}", node ) - class InvalidStructAccess(node: SyntaxTreeNode, struct: GwydionType) : AnalysisError( + class InvalidStructAccess(node: SyntaxTreeNode, struct: SeleneType) : AnalysisError( "invalid struct access: ${struct.signature}", node ) @@ -184,12 +184,12 @@ sealed class AnalysisError(val message: String, val node: SyntaxTreeNode) { node ) - class WrongArgumentTypeForFunctionCall(node: SyntaxTreeNode, expected: GwydionType, actual: GwydionType) : AnalysisError( + class WrongArgumentTypeForFunctionCall(node: SyntaxTreeNode, expected: SeleneType, actual: SeleneType) : AnalysisError( "wrong argument type for function call: expected ${expected.signature}, got ${actual.signature}", node ) - class TypeCannotBeMutable(node: SyntaxTreeNode, type: GwydionType) : AnalysisError( + class TypeCannotBeMutable(node: SyntaxTreeNode, type: SeleneType) : AnalysisError( "type cannot be mutable: ${type.signature}", node ) diff --git a/analysis/src/commonMain/kotlin/SemanticAnalysisManager.kt b/analysis/src/commonMain/kotlin/SemanticAnalysisManager.kt index 76c1af8..02e85f0 100644 --- a/analysis/src/commonMain/kotlin/SemanticAnalysisManager.kt +++ b/analysis/src/commonMain/kotlin/SemanticAnalysisManager.kt @@ -1,15 +1,15 @@ -package me.gabriel.gwydion.analysis +package me.gabriel.selene.analysis -import me.gabriel.gwydion.analysis.analyzers.ISemanticAnalyzer -import me.gabriel.gwydion.analysis.analyzers.TypeInferenceVisitor -import me.gabriel.gwydion.analysis.analyzers.impl.* -import me.gabriel.gwydion.analysis.signature.Signatures -import me.gabriel.gwydion.frontend.parsing.* -import me.gabriel.gwydion.tools.GwydionLogger -import me.gabriel.gwydion.tools.LogLevel +import me.gabriel.selene.analysis.analyzers.ISemanticAnalyzer +import me.gabriel.selene.analysis.analyzers.TypeInferenceVisitor +import me.gabriel.selene.analysis.analyzers.impl.* +import me.gabriel.selene.analysis.signature.Signatures +import me.gabriel.selene.frontend.parsing.* +import me.gabriel.selene.tools.SeleneLogger +import me.gabriel.selene.tools.LogLevel class SemanticAnalysisManager( - private val logger: GwydionLogger, + private val logger: SeleneLogger, private val symbols: SymbolRepository, private val signatures: Signatures, ) { @@ -65,7 +65,7 @@ class SemanticAnalysisManager( } val newBlock = analyzers.map { analyzer -> - val visitor = TypeInferenceVisitor(node) + val visitor = TypeInferenceVisitor() val switchBlock = @Suppress("UNCHECKED_CAST") (analyzer as ISemanticAnalyzer).register(block, node, signatures, visitor) diff --git a/analysis/src/commonMain/kotlin/SymbolBlock.kt b/analysis/src/commonMain/kotlin/SymbolBlock.kt index c519e2e..784b3e8 100644 --- a/analysis/src/commonMain/kotlin/SymbolBlock.kt +++ b/analysis/src/commonMain/kotlin/SymbolBlock.kt @@ -1,7 +1,7 @@ -package me.gabriel.gwydion.analysis +package me.gabriel.selene.analysis -import me.gabriel.gwydion.frontend.GwydionType -import me.gabriel.gwydion.frontend.parsing.* +import me.gabriel.selene.frontend.SeleneType +import me.gabriel.selene.frontend.parsing.* class SymbolRepository(val module: String) { val root = SymbolBlock( @@ -14,7 +14,7 @@ class SymbolRepository(val module: String) { fun createBlock( id: SyntaxTreeNode, parent: SymbolBlock, - self: GwydionType? = parent.self + self: SeleneType? = parent.self ): SymbolBlock { val block = SymbolBlock(module, id, parent, mutableListOf(), self) parent.children.add(block) @@ -27,10 +27,10 @@ class SymbolBlock( val id: SyntaxTreeNode?, val parent: SymbolBlock?, val children: MutableList = mutableListOf(), - var self: GwydionType? = parent?.self + var self: SeleneType? = parent?.self ) { - private val symbols = mutableMapOf() - private val definitions = mutableMapOf() + private val symbols = mutableMapOf() + private val definitions = mutableMapOf() val name get() = when (id) { is FunctionNode -> id.name @@ -40,7 +40,7 @@ class SymbolBlock( fun createChild( id: SyntaxTreeNode, - self: GwydionType? = this.self + self: SeleneType? = this.self ): SymbolBlock { val block = SymbolBlock(module, id, this, mutableListOf(), self) children.add(block) @@ -51,19 +51,19 @@ class SymbolBlock( return children.find { it.id == id } } - fun declareSymbol(name: String, type: GwydionType) { + fun declareSymbol(name: String, type: SeleneType) { symbols[name] = type } - fun defineSymbol(node: SyntaxTreeNode, type: GwydionType) { + fun defineSymbol(node: SyntaxTreeNode, type: SeleneType) { definitions[node] = type } - fun resolveSymbol(name: String): GwydionType? { + fun resolveSymbol(name: String): SeleneType? { return symbols[name] ?: parent?.resolveSymbol(name) } - fun resolveExpression(node: SyntaxTreeNode): GwydionType? { + fun resolveExpression(node: SyntaxTreeNode): SeleneType? { return when (node) { is TypedSyntaxTreeNode -> node.type is VariableReferenceNode -> resolveSymbol(node.name) diff --git a/analysis/src/commonMain/kotlin/analyzers/ISemanticAnalyzer.kt b/analysis/src/commonMain/kotlin/analyzers/ISemanticAnalyzer.kt index 2c651f3..e9a9c8a 100644 --- a/analysis/src/commonMain/kotlin/analyzers/ISemanticAnalyzer.kt +++ b/analysis/src/commonMain/kotlin/analyzers/ISemanticAnalyzer.kt @@ -1,9 +1,9 @@ -package me.gabriel.gwydion.analysis.analyzers +package me.gabriel.selene.analysis.analyzers -import me.gabriel.gwydion.analysis.AnalysisResult -import me.gabriel.gwydion.analysis.SymbolBlock -import me.gabriel.gwydion.analysis.signature.Signatures -import me.gabriel.gwydion.frontend.parsing.SyntaxTreeNode +import me.gabriel.selene.analysis.AnalysisResult +import me.gabriel.selene.analysis.SymbolBlock +import me.gabriel.selene.analysis.signature.Signatures +import me.gabriel.selene.frontend.parsing.SyntaxTreeNode interface ISemanticAnalyzer { fun handles(node: SyntaxTreeNode): Boolean diff --git a/analysis/src/commonMain/kotlin/analyzers/SingleNodeAnalyzer.kt b/analysis/src/commonMain/kotlin/analyzers/SingleNodeAnalyzer.kt index 8227a82..5e444ee 100644 --- a/analysis/src/commonMain/kotlin/analyzers/SingleNodeAnalyzer.kt +++ b/analysis/src/commonMain/kotlin/analyzers/SingleNodeAnalyzer.kt @@ -1,6 +1,6 @@ -package me.gabriel.gwydion.analysis.analyzers +package me.gabriel.selene.analysis.analyzers -import me.gabriel.gwydion.frontend.parsing.SyntaxTreeNode +import me.gabriel.selene.frontend.parsing.SyntaxTreeNode import kotlin.reflect.KClass abstract class SingleNodeAnalyzer( diff --git a/analysis/src/commonMain/kotlin/analyzers/TypeInferenceVisitor.kt b/analysis/src/commonMain/kotlin/analyzers/TypeInferenceVisitor.kt index 696db4a..873d92e 100644 --- a/analysis/src/commonMain/kotlin/analyzers/TypeInferenceVisitor.kt +++ b/analysis/src/commonMain/kotlin/analyzers/TypeInferenceVisitor.kt @@ -1,8 +1,8 @@ -package me.gabriel.gwydion.analysis.analyzers +package me.gabriel.selene.analysis.analyzers -import me.gabriel.gwydion.frontend.parsing.SyntaxTreeNode +import me.gabriel.selene.frontend.parsing.SyntaxTreeNode -class TypeInferenceVisitor(private val node: SyntaxTreeNode) { +class TypeInferenceVisitor { val queuedVisits = mutableListOf Any>>() fun visit(node: SyntaxTreeNode, block: () -> T) { diff --git a/analysis/src/commonMain/kotlin/analyzers/impl/ArrayAccessAnalyzer.kt b/analysis/src/commonMain/kotlin/analyzers/impl/ArrayAccessAnalyzer.kt index 0473c45..eb67d32 100644 --- a/analysis/src/commonMain/kotlin/analyzers/impl/ArrayAccessAnalyzer.kt +++ b/analysis/src/commonMain/kotlin/analyzers/impl/ArrayAccessAnalyzer.kt @@ -1,13 +1,13 @@ -package me.gabriel.gwydion.analysis.analyzers.impl +package me.gabriel.selene.analysis.analyzers.impl -import me.gabriel.gwydion.analysis.AnalysisResult -import me.gabriel.gwydion.analysis.SymbolBlock -import me.gabriel.gwydion.analysis.analyzers.SingleNodeAnalyzer -import me.gabriel.gwydion.analysis.analyzers.TypeInferenceVisitor -import me.gabriel.gwydion.analysis.signature.Signatures -import me.gabriel.gwydion.frontend.GwydionType -import me.gabriel.gwydion.frontend.parsing.ArrayAccessNode -import me.gabriel.gwydion.frontend.workingBase +import me.gabriel.selene.analysis.AnalysisResult +import me.gabriel.selene.analysis.SymbolBlock +import me.gabriel.selene.analysis.analyzers.SingleNodeAnalyzer +import me.gabriel.selene.analysis.analyzers.TypeInferenceVisitor +import me.gabriel.selene.analysis.signature.Signatures +import me.gabriel.selene.frontend.SeleneType +import me.gabriel.selene.frontend.parsing.ArrayAccessNode +import me.gabriel.selene.frontend.workingBase class ArrayAccessAnalyzer: SingleNodeAnalyzer(ArrayAccessNode::class) { override fun register( @@ -18,8 +18,8 @@ class ArrayAccessAnalyzer: SingleNodeAnalyzer(ArrayAccessNode:: ): SymbolBlock { val resolved = block.resolveExpression(node.array) ?: return block val type = when (val base = resolved.workingBase()) { - is GwydionType.FixedArray -> base.baseType - is GwydionType.DynamicArray -> base.baseType + is SeleneType.FixedArray -> base.baseType + is SeleneType.DynamicArray -> base.baseType else -> return block } diff --git a/analysis/src/commonMain/kotlin/analyzers/impl/ArrayAnalyzer.kt b/analysis/src/commonMain/kotlin/analyzers/impl/ArrayAnalyzer.kt index bf84e97..842a77b 100644 --- a/analysis/src/commonMain/kotlin/analyzers/impl/ArrayAnalyzer.kt +++ b/analysis/src/commonMain/kotlin/analyzers/impl/ArrayAnalyzer.kt @@ -1,15 +1,15 @@ -package me.gabriel.gwydion.analysis.analyzers.impl +package me.gabriel.selene.analysis.analyzers.impl -import me.gabriel.gwydion.analysis.AnalysisError -import me.gabriel.gwydion.analysis.AnalysisResult -import me.gabriel.gwydion.analysis.SymbolBlock -import me.gabriel.gwydion.analysis.analyzers.SingleNodeAnalyzer -import me.gabriel.gwydion.analysis.analyzers.TypeInferenceVisitor -import me.gabriel.gwydion.analysis.signature.Signatures -import me.gabriel.gwydion.analysis.util.doesProvidedTypeAccordToExpectedType -import me.gabriel.gwydion.frontend.GwydionType -import me.gabriel.gwydion.frontend.parsing.ArrayNode -import me.gabriel.gwydion.frontend.workingBase +import me.gabriel.selene.analysis.AnalysisError +import me.gabriel.selene.analysis.AnalysisResult +import me.gabriel.selene.analysis.SymbolBlock +import me.gabriel.selene.analysis.analyzers.SingleNodeAnalyzer +import me.gabriel.selene.analysis.analyzers.TypeInferenceVisitor +import me.gabriel.selene.analysis.signature.Signatures +import me.gabriel.selene.analysis.util.doesProvidedTypeAccordToExpectedType +import me.gabriel.selene.frontend.SeleneType +import me.gabriel.selene.frontend.parsing.ArrayNode +import me.gabriel.selene.frontend.workingBase class ArrayAnalyzer: SingleNodeAnalyzer(ArrayNode::class) { override fun register( @@ -20,12 +20,12 @@ class ArrayAnalyzer: SingleNodeAnalyzer(ArrayNode::class) { ): SymbolBlock { val baseType = node.elements.firstOrNull()?.let { block.resolveExpression(it) - } ?: GwydionType.Unknown + } ?: SeleneType.Unknown val arrayType = if (node.dynamic) { - GwydionType.DynamicArray(baseType) + SeleneType.DynamicArray(baseType) } else { - GwydionType.FixedArray(baseType, node.elements.size) + SeleneType.FixedArray(baseType, node.elements.size) } block.defineSymbol(node, arrayType) @@ -43,8 +43,8 @@ class ArrayAnalyzer: SingleNodeAnalyzer(ArrayNode::class) { ?: error("Type for ArrayNode was not previously defined") val desiredType = when (arrayType) { - is GwydionType.FixedArray -> arrayType.baseType - is GwydionType.DynamicArray -> arrayType.baseType + is SeleneType.FixedArray -> arrayType.baseType + is SeleneType.DynamicArray -> arrayType.baseType else -> error("Array type was not previously defined") } diff --git a/analysis/src/commonMain/kotlin/analyzers/impl/AssignmentAnalyzer.kt b/analysis/src/commonMain/kotlin/analyzers/impl/AssignmentAnalyzer.kt index 3ecc8ce..737269c 100644 --- a/analysis/src/commonMain/kotlin/analyzers/impl/AssignmentAnalyzer.kt +++ b/analysis/src/commonMain/kotlin/analyzers/impl/AssignmentAnalyzer.kt @@ -1,12 +1,12 @@ -package me.gabriel.gwydion.analysis.analyzers.impl +package me.gabriel.selene.analysis.analyzers.impl -import me.gabriel.gwydion.analysis.AnalysisResult -import me.gabriel.gwydion.analysis.SymbolBlock -import me.gabriel.gwydion.analysis.analyzers.SingleNodeAnalyzer -import me.gabriel.gwydion.analysis.analyzers.TypeInferenceVisitor -import me.gabriel.gwydion.analysis.signature.Signatures -import me.gabriel.gwydion.frontend.GwydionType -import me.gabriel.gwydion.frontend.parsing.AssignmentNode +import me.gabriel.selene.analysis.AnalysisResult +import me.gabriel.selene.analysis.SymbolBlock +import me.gabriel.selene.analysis.analyzers.SingleNodeAnalyzer +import me.gabriel.selene.analysis.analyzers.TypeInferenceVisitor +import me.gabriel.selene.analysis.signature.Signatures +import me.gabriel.selene.frontend.SeleneType +import me.gabriel.selene.frontend.parsing.AssignmentNode class AssignmentAnalyzer: SingleNodeAnalyzer(AssignmentNode::class) { override fun register( @@ -19,7 +19,7 @@ class AssignmentAnalyzer: SingleNodeAnalyzer(AssignmentNode::cla val type = block.resolveExpression(node.expression) ?: return@visit if (node.mutable) { - block.defineSymbol(node, GwydionType.Mutable(type)) + block.defineSymbol(node, SeleneType.Mutable(type)) } else { block.defineSymbol(node, type) } diff --git a/analysis/src/commonMain/kotlin/analyzers/impl/BinaryOpAnalyzer.kt b/analysis/src/commonMain/kotlin/analyzers/impl/BinaryOpAnalyzer.kt index 843c08b..f3cc1e3 100644 --- a/analysis/src/commonMain/kotlin/analyzers/impl/BinaryOpAnalyzer.kt +++ b/analysis/src/commonMain/kotlin/analyzers/impl/BinaryOpAnalyzer.kt @@ -1,14 +1,13 @@ -package me.gabriel.gwydion.analysis.analyzers.impl +package me.gabriel.selene.analysis.analyzers.impl -import me.gabriel.gwydion.analysis.AnalysisError -import me.gabriel.gwydion.analysis.AnalysisResult -import me.gabriel.gwydion.analysis.SymbolBlock -import me.gabriel.gwydion.analysis.analyzers.SingleNodeAnalyzer -import me.gabriel.gwydion.analysis.analyzers.TypeInferenceVisitor -import me.gabriel.gwydion.analysis.signature.Signatures -import me.gabriel.gwydion.analysis.util.doesProvidedTypeAccordToExpectedType -import me.gabriel.gwydion.frontend.GwydionType -import me.gabriel.gwydion.frontend.parsing.BinaryOperatorNode +import me.gabriel.selene.analysis.AnalysisError +import me.gabriel.selene.analysis.AnalysisResult +import me.gabriel.selene.analysis.SymbolBlock +import me.gabriel.selene.analysis.analyzers.SingleNodeAnalyzer +import me.gabriel.selene.analysis.analyzers.TypeInferenceVisitor +import me.gabriel.selene.analysis.signature.Signatures +import me.gabriel.selene.frontend.SeleneType +import me.gabriel.selene.frontend.parsing.BinaryOperatorNode class BinaryOpAnalyzer: SingleNodeAnalyzer(BinaryOperatorNode::class) { override fun register( @@ -18,7 +17,7 @@ class BinaryOpAnalyzer: SingleNodeAnalyzer(BinaryOperatorNod visitor: TypeInferenceVisitor ): SymbolBlock { visitor.visit(node.left) { - block.defineSymbol(node, block.resolveExpression(node.left) ?: GwydionType.Unknown) + block.defineSymbol(node, block.resolveExpression(node.left) ?: SeleneType.Unknown) } return block } @@ -29,8 +28,8 @@ class BinaryOpAnalyzer: SingleNodeAnalyzer(BinaryOperatorNod signatures: Signatures, results: AnalysisResult ): SymbolBlock { - val left = block.resolveExpression(node.left) ?: GwydionType.Unknown - val right = block.resolveExpression(node.right) ?: GwydionType.Unknown + val left = block.resolveExpression(node.left) ?: SeleneType.Unknown + val right = block.resolveExpression(node.right) ?: SeleneType.Unknown if (left != right) { results.errors.add( diff --git a/analysis/src/commonMain/kotlin/analyzers/impl/CallAnalyzer.kt b/analysis/src/commonMain/kotlin/analyzers/impl/CallAnalyzer.kt index f7d6dcc..d4d8ddf 100644 --- a/analysis/src/commonMain/kotlin/analyzers/impl/CallAnalyzer.kt +++ b/analysis/src/commonMain/kotlin/analyzers/impl/CallAnalyzer.kt @@ -1,14 +1,14 @@ -package me.gabriel.gwydion.analysis.analyzers.impl +package me.gabriel.selene.analysis.analyzers.impl -import me.gabriel.gwydion.analysis.AnalysisError -import me.gabriel.gwydion.analysis.AnalysisResult -import me.gabriel.gwydion.analysis.SymbolBlock -import me.gabriel.gwydion.analysis.analyzers.SingleNodeAnalyzer -import me.gabriel.gwydion.analysis.analyzers.TypeInferenceVisitor -import me.gabriel.gwydion.analysis.signature.Signatures -import me.gabriel.gwydion.frontend.GwydionType -import me.gabriel.gwydion.frontend.parsing.CallNode -import me.gabriel.gwydion.frontend.parsing.Modifiers +import me.gabriel.selene.analysis.AnalysisError +import me.gabriel.selene.analysis.AnalysisResult +import me.gabriel.selene.analysis.SymbolBlock +import me.gabriel.selene.analysis.analyzers.SingleNodeAnalyzer +import me.gabriel.selene.analysis.analyzers.TypeInferenceVisitor +import me.gabriel.selene.analysis.signature.Signatures +import me.gabriel.selene.frontend.SeleneType +import me.gabriel.selene.frontend.parsing.CallNode +import me.gabriel.selene.frontend.parsing.Modifiers class CallAnalyzer: SingleNodeAnalyzer(CallNode::class) { override fun register( @@ -18,7 +18,7 @@ class CallAnalyzer: SingleNodeAnalyzer(CallNode::class) { visitor: TypeInferenceVisitor ): SymbolBlock { val potentialLambda = block.resolveSymbol(node.name) - if (potentialLambda is GwydionType.Lambda) { + if (potentialLambda is SeleneType.Lambda) { registerCall(block, node, potentialLambda.parameters, visitor) block.defineSymbol(node, potentialLambda.returnType) return block @@ -35,14 +35,14 @@ class CallAnalyzer: SingleNodeAnalyzer(CallNode::class) { private fun registerCall( block: SymbolBlock, node: CallNode, - parameters: List, + parameters: List, visitor: TypeInferenceVisitor ) { for ((index, argument) in node.arguments.withIndex()) { visitor.visit(argument) { - val type = block.resolveExpression(argument) ?: GwydionType.Unknown - if (type == GwydionType.Unknown) { - val expectedType = parameters.getOrNull(index) ?: GwydionType.Unknown + val type = block.resolveExpression(argument) ?: SeleneType.Unknown + if (type == SeleneType.Unknown) { + val expectedType = parameters.getOrNull(index) ?: SeleneType.Unknown block.defineSymbol(argument, expectedType) } } @@ -58,7 +58,7 @@ class CallAnalyzer: SingleNodeAnalyzer(CallNode::class) { val function = signatures.functions.find { it.name == node.name } if (function == null) { val potentialLambda = block.resolveSymbol(node.name) - if (potentialLambda !is GwydionType.Lambda) { + if (potentialLambda !is SeleneType.Lambda) { results.errors.add(AnalysisError.UndefinedFunction( node = node, )) diff --git a/analysis/src/commonMain/kotlin/analyzers/impl/DataFieldAnalyzer.kt b/analysis/src/commonMain/kotlin/analyzers/impl/DataFieldAnalyzer.kt index 7598ba7..8bbd91e 100644 --- a/analysis/src/commonMain/kotlin/analyzers/impl/DataFieldAnalyzer.kt +++ b/analysis/src/commonMain/kotlin/analyzers/impl/DataFieldAnalyzer.kt @@ -1,14 +1,14 @@ -package me.gabriel.gwydion.analysis.analyzers.impl +package me.gabriel.selene.analysis.analyzers.impl -import me.gabriel.gwydion.analysis.AnalysisError -import me.gabriel.gwydion.analysis.AnalysisResult -import me.gabriel.gwydion.analysis.SymbolBlock -import me.gabriel.gwydion.analysis.analyzers.SingleNodeAnalyzer -import me.gabriel.gwydion.analysis.analyzers.TypeInferenceVisitor -import me.gabriel.gwydion.analysis.signature.Signatures -import me.gabriel.gwydion.analysis.util.unknownReferenceSignatureToType -import me.gabriel.gwydion.frontend.GwydionType -import me.gabriel.gwydion.frontend.parsing.DataFieldNode +import me.gabriel.selene.analysis.AnalysisError +import me.gabriel.selene.analysis.AnalysisResult +import me.gabriel.selene.analysis.SymbolBlock +import me.gabriel.selene.analysis.analyzers.SingleNodeAnalyzer +import me.gabriel.selene.analysis.analyzers.TypeInferenceVisitor +import me.gabriel.selene.analysis.signature.Signatures +import me.gabriel.selene.analysis.util.unknownReferenceSignatureToType +import me.gabriel.selene.frontend.SeleneType +import me.gabriel.selene.frontend.parsing.DataFieldNode class DataFieldAnalyzer: SingleNodeAnalyzer(DataFieldNode::class) { override fun register( @@ -34,7 +34,7 @@ class DataFieldAnalyzer: SingleNodeAnalyzer(DataFieldNode::class) val type = block.resolveExpression(node) ?: error("Type for DataFieldNode was not previously defined") - if (type is GwydionType.Mutable) { + if (type is SeleneType.Mutable) { results.errors.add( AnalysisError.StructFieldCannotBeMutable( node = node, diff --git a/analysis/src/commonMain/kotlin/analyzers/impl/FunctionAnalyzer.kt b/analysis/src/commonMain/kotlin/analyzers/impl/FunctionAnalyzer.kt index 8d9a655..1823c60 100644 --- a/analysis/src/commonMain/kotlin/analyzers/impl/FunctionAnalyzer.kt +++ b/analysis/src/commonMain/kotlin/analyzers/impl/FunctionAnalyzer.kt @@ -1,18 +1,18 @@ -package me.gabriel.gwydion.analysis.analyzers.impl +package me.gabriel.selene.analysis.analyzers.impl -import me.gabriel.gwydion.analysis.AnalysisError -import me.gabriel.gwydion.analysis.AnalysisResult -import me.gabriel.gwydion.analysis.AnalysisWarning -import me.gabriel.gwydion.analysis.SymbolBlock -import me.gabriel.gwydion.analysis.analyzers.SingleNodeAnalyzer -import me.gabriel.gwydion.analysis.analyzers.TypeInferenceVisitor -import me.gabriel.gwydion.analysis.signature.SignatureFunction -import me.gabriel.gwydion.analysis.signature.Signatures -import me.gabriel.gwydion.analysis.util.unknownReferenceSignatureToType -import me.gabriel.gwydion.frontend.GwydionType -import me.gabriel.gwydion.frontend.parsing.FunctionNode -import me.gabriel.gwydion.frontend.parsing.Modifiers -import me.gabriel.gwydion.frontend.parsing.ReturnNode +import me.gabriel.selene.analysis.AnalysisError +import me.gabriel.selene.analysis.AnalysisResult +import me.gabriel.selene.analysis.AnalysisWarning +import me.gabriel.selene.analysis.SymbolBlock +import me.gabriel.selene.analysis.analyzers.SingleNodeAnalyzer +import me.gabriel.selene.analysis.analyzers.TypeInferenceVisitor +import me.gabriel.selene.analysis.signature.SignatureFunction +import me.gabriel.selene.analysis.signature.Signatures +import me.gabriel.selene.analysis.util.unknownReferenceSignatureToType +import me.gabriel.selene.frontend.SeleneType +import me.gabriel.selene.frontend.parsing.FunctionNode +import me.gabriel.selene.frontend.parsing.Modifiers +import me.gabriel.selene.frontend.parsing.ReturnNode class FunctionAnalyzer: SingleNodeAnalyzer(FunctionNode::class) { override fun register( @@ -57,7 +57,7 @@ class FunctionAnalyzer: SingleNodeAnalyzer(FunctionNode::class) { return functionBlock } val returnNode = node.body.getChildren().filter { it is ReturnNode } - if (returnNode.isEmpty() && node.returnType != GwydionType.Void) { + if (returnNode.isEmpty() && node.returnType != SeleneType.Void) { results.errors.add(AnalysisError.MissingReturnStatement(node)) return functionBlock } diff --git a/analysis/src/commonMain/kotlin/analyzers/impl/InstantiationAnalyzer.kt b/analysis/src/commonMain/kotlin/analyzers/impl/InstantiationAnalyzer.kt index 1e542ee..8dfb2b0 100644 --- a/analysis/src/commonMain/kotlin/analyzers/impl/InstantiationAnalyzer.kt +++ b/analysis/src/commonMain/kotlin/analyzers/impl/InstantiationAnalyzer.kt @@ -1,15 +1,14 @@ -package me.gabriel.gwydion.analysis.analyzers.impl +package me.gabriel.selene.analysis.analyzers.impl -import me.gabriel.gwydion.analysis.AnalysisError -import me.gabriel.gwydion.analysis.AnalysisResult -import me.gabriel.gwydion.analysis.SymbolBlock -import me.gabriel.gwydion.analysis.analyzers.SingleNodeAnalyzer -import me.gabriel.gwydion.analysis.analyzers.TypeInferenceVisitor -import me.gabriel.gwydion.analysis.signature.Signatures -import me.gabriel.gwydion.analysis.util.doesProvidedTypeAccordToExpectedType -import me.gabriel.gwydion.frontend.GwydionType -import me.gabriel.gwydion.frontend.parsing.InstantiationNode -import kotlin.math.exp +import me.gabriel.selene.analysis.AnalysisError +import me.gabriel.selene.analysis.AnalysisResult +import me.gabriel.selene.analysis.SymbolBlock +import me.gabriel.selene.analysis.analyzers.SingleNodeAnalyzer +import me.gabriel.selene.analysis.analyzers.TypeInferenceVisitor +import me.gabriel.selene.analysis.signature.Signatures +import me.gabriel.selene.analysis.util.doesProvidedTypeAccordToExpectedType +import me.gabriel.selene.frontend.SeleneType +import me.gabriel.selene.frontend.parsing.InstantiationNode class InstantiationAnalyzer: SingleNodeAnalyzer(InstantiationNode::class) { override fun register( @@ -20,12 +19,12 @@ class InstantiationAnalyzer: SingleNodeAnalyzer(Instantiation ): SymbolBlock { val type = signatures.structs.find { it.name == node.name } ?.let { - GwydionType.Struct( + SeleneType.Struct( it.name, it.fields ) } - ?: GwydionType.Unknown + ?: SeleneType.Unknown block.defineSymbol(node, type) return block @@ -37,7 +36,7 @@ class InstantiationAnalyzer: SingleNodeAnalyzer(Instantiation signatures: Signatures, results: AnalysisResult ): SymbolBlock { - val struct = block.resolveExpression(node) as? GwydionType.Struct + val struct = block.resolveExpression(node) as? SeleneType.Struct if (struct == null) { results.errors.add( diff --git a/analysis/src/commonMain/kotlin/analyzers/impl/LambdaAnalyzer.kt b/analysis/src/commonMain/kotlin/analyzers/impl/LambdaAnalyzer.kt index 6ae41ec..741bf2e 100644 --- a/analysis/src/commonMain/kotlin/analyzers/impl/LambdaAnalyzer.kt +++ b/analysis/src/commonMain/kotlin/analyzers/impl/LambdaAnalyzer.kt @@ -1,13 +1,13 @@ -package me.gabriel.gwydion.analysis.analyzers.impl +package me.gabriel.selene.analysis.analyzers.impl -import me.gabriel.gwydion.analysis.AnalysisError -import me.gabriel.gwydion.analysis.AnalysisResult -import me.gabriel.gwydion.analysis.SymbolBlock -import me.gabriel.gwydion.analysis.analyzers.SingleNodeAnalyzer -import me.gabriel.gwydion.analysis.analyzers.TypeInferenceVisitor -import me.gabriel.gwydion.analysis.signature.Signatures -import me.gabriel.gwydion.frontend.GwydionType -import me.gabriel.gwydion.frontend.parsing.LambdaNode +import me.gabriel.selene.analysis.AnalysisError +import me.gabriel.selene.analysis.AnalysisResult +import me.gabriel.selene.analysis.SymbolBlock +import me.gabriel.selene.analysis.analyzers.SingleNodeAnalyzer +import me.gabriel.selene.analysis.analyzers.TypeInferenceVisitor +import me.gabriel.selene.analysis.signature.Signatures +import me.gabriel.selene.frontend.SeleneType +import me.gabriel.selene.frontend.parsing.LambdaNode class LambdaAnalyzer: SingleNodeAnalyzer(LambdaNode::class) { override fun register( @@ -20,7 +20,7 @@ class LambdaAnalyzer: SingleNodeAnalyzer(LambdaNode::class) { id = node ) - block.defineSymbol(node, GwydionType.Unknown) + block.defineSymbol(node, SeleneType.Unknown) return newBlock } @@ -33,8 +33,8 @@ class LambdaAnalyzer: SingleNodeAnalyzer(LambdaNode::class) { val lambdaBlock = block.surfaceSearchChild(node) ?: error("Lambda block not registered") - val type = block.resolveExpression(node) ?: GwydionType.Unknown - if (type == GwydionType.Unknown) { + val type = block.resolveExpression(node) ?: SeleneType.Unknown + if (type == SeleneType.Unknown) { results.errors.add( AnalysisError.LambdaTypeCannotBeInferred( node diff --git a/analysis/src/commonMain/kotlin/analyzers/impl/LambdaParameterAnalyzer.kt b/analysis/src/commonMain/kotlin/analyzers/impl/LambdaParameterAnalyzer.kt index ae87b9a..d250762 100644 --- a/analysis/src/commonMain/kotlin/analyzers/impl/LambdaParameterAnalyzer.kt +++ b/analysis/src/commonMain/kotlin/analyzers/impl/LambdaParameterAnalyzer.kt @@ -1,11 +1,10 @@ -package me.gabriel.gwydion.analysis.analyzers.impl +package me.gabriel.selene.analysis.analyzers.impl -import me.gabriel.gwydion.analysis.AnalysisResult -import me.gabriel.gwydion.analysis.SymbolBlock -import me.gabriel.gwydion.analysis.analyzers.SingleNodeAnalyzer -import me.gabriel.gwydion.analysis.analyzers.TypeInferenceVisitor -import me.gabriel.gwydion.analysis.signature.Signatures -import me.gabriel.gwydion.frontend.parsing.LambdaParameterNode +import me.gabriel.selene.analysis.SymbolBlock +import me.gabriel.selene.analysis.analyzers.SingleNodeAnalyzer +import me.gabriel.selene.analysis.analyzers.TypeInferenceVisitor +import me.gabriel.selene.analysis.signature.Signatures +import me.gabriel.selene.frontend.parsing.LambdaParameterNode class LambdaParameterAnalyzer: SingleNodeAnalyzer(LambdaParameterNode::class) { override fun register( diff --git a/analysis/src/commonMain/kotlin/analyzers/impl/ParameterAnalyzer.kt b/analysis/src/commonMain/kotlin/analyzers/impl/ParameterAnalyzer.kt index 64c795c..993a23d 100644 --- a/analysis/src/commonMain/kotlin/analyzers/impl/ParameterAnalyzer.kt +++ b/analysis/src/commonMain/kotlin/analyzers/impl/ParameterAnalyzer.kt @@ -1,13 +1,13 @@ -package me.gabriel.gwydion.analysis.analyzers.impl +package me.gabriel.selene.analysis.analyzers.impl -import me.gabriel.gwydion.analysis.AnalysisResult -import me.gabriel.gwydion.analysis.SymbolBlock -import me.gabriel.gwydion.analysis.analyzers.SingleNodeAnalyzer -import me.gabriel.gwydion.analysis.analyzers.TypeInferenceVisitor -import me.gabriel.gwydion.analysis.signature.Signatures -import me.gabriel.gwydion.analysis.util.unknownReferenceSignatureToType -import me.gabriel.gwydion.frontend.GwydionType -import me.gabriel.gwydion.frontend.parsing.ParameterNode +import me.gabriel.selene.analysis.AnalysisResult +import me.gabriel.selene.analysis.SymbolBlock +import me.gabriel.selene.analysis.analyzers.SingleNodeAnalyzer +import me.gabriel.selene.analysis.analyzers.TypeInferenceVisitor +import me.gabriel.selene.analysis.signature.Signatures +import me.gabriel.selene.analysis.util.unknownReferenceSignatureToType +import me.gabriel.selene.frontend.SeleneType +import me.gabriel.selene.frontend.parsing.ParameterNode class ParameterAnalyzer: SingleNodeAnalyzer(ParameterNode::class) { override fun register( @@ -18,7 +18,7 @@ class ParameterAnalyzer: SingleNodeAnalyzer(ParameterNode::class) ): SymbolBlock { val type = unknownReferenceSignatureToType(signatures, node.type) - if (type == GwydionType.Self && block.self != null) { + if (type == SeleneType.Self && block.self != null) { block.defineSymbol(node, block.self!!) block.declareSymbol(node.name, block.self!!) } else { diff --git a/analysis/src/commonMain/kotlin/analyzers/impl/StructAccessAnalyzer.kt b/analysis/src/commonMain/kotlin/analyzers/impl/StructAccessAnalyzer.kt index b659598..bd8d546 100644 --- a/analysis/src/commonMain/kotlin/analyzers/impl/StructAccessAnalyzer.kt +++ b/analysis/src/commonMain/kotlin/analyzers/impl/StructAccessAnalyzer.kt @@ -1,13 +1,13 @@ -package me.gabriel.gwydion.analysis.analyzers.impl +package me.gabriel.selene.analysis.analyzers.impl -import me.gabriel.gwydion.analysis.AnalysisResult -import me.gabriel.gwydion.analysis.SymbolBlock -import me.gabriel.gwydion.analysis.analyzers.SingleNodeAnalyzer -import me.gabriel.gwydion.analysis.analyzers.TypeInferenceVisitor -import me.gabriel.gwydion.analysis.signature.Signatures -import me.gabriel.gwydion.frontend.GwydionType -import me.gabriel.gwydion.frontend.parsing.StructAccessNode -import me.gabriel.gwydion.frontend.workingBase +import me.gabriel.selene.analysis.AnalysisResult +import me.gabriel.selene.analysis.SymbolBlock +import me.gabriel.selene.analysis.analyzers.SingleNodeAnalyzer +import me.gabriel.selene.analysis.analyzers.TypeInferenceVisitor +import me.gabriel.selene.analysis.signature.Signatures +import me.gabriel.selene.frontend.SeleneType +import me.gabriel.selene.frontend.parsing.StructAccessNode +import me.gabriel.selene.frontend.workingBase class StructAccessAnalyzer: SingleNodeAnalyzer(StructAccessNode::class) { override fun register( @@ -17,9 +17,9 @@ class StructAccessAnalyzer: SingleNodeAnalyzer(StructAccessNod visitor: TypeInferenceVisitor ): SymbolBlock { val resolved = block.resolveExpression(node.struct) ?: return block - val struct: GwydionType.Struct = when (val base = resolved.workingBase()) { - is GwydionType.Struct -> base - is GwydionType.Self -> block.self as? GwydionType.Struct ?: return block + val struct: SeleneType.Struct = when (val base = resolved.workingBase()) { + is SeleneType.Struct -> base + is SeleneType.Self -> block.self as? SeleneType.Struct ?: return block else -> return block } diff --git a/analysis/src/commonMain/kotlin/analyzers/impl/StructAnalyzer.kt b/analysis/src/commonMain/kotlin/analyzers/impl/StructAnalyzer.kt index dc00c46..20daafb 100644 --- a/analysis/src/commonMain/kotlin/analyzers/impl/StructAnalyzer.kt +++ b/analysis/src/commonMain/kotlin/analyzers/impl/StructAnalyzer.kt @@ -1,15 +1,14 @@ -package me.gabriel.gwydion.analysis.analyzers.impl +package me.gabriel.selene.analysis.analyzers.impl -import me.gabriel.gwydion.analysis.AnalysisError -import me.gabriel.gwydion.analysis.AnalysisResult -import me.gabriel.gwydion.analysis.SymbolBlock -import me.gabriel.gwydion.analysis.analyzers.SingleNodeAnalyzer -import me.gabriel.gwydion.analysis.analyzers.TypeInferenceVisitor -import me.gabriel.gwydion.analysis.signature.SignatureStruct -import me.gabriel.gwydion.analysis.signature.Signatures -import me.gabriel.gwydion.analysis.util.unknownReferenceSignatureToType -import me.gabriel.gwydion.frontend.GwydionType -import me.gabriel.gwydion.frontend.parsing.DataStructureNode +import me.gabriel.selene.analysis.AnalysisResult +import me.gabriel.selene.analysis.SymbolBlock +import me.gabriel.selene.analysis.analyzers.SingleNodeAnalyzer +import me.gabriel.selene.analysis.analyzers.TypeInferenceVisitor +import me.gabriel.selene.analysis.signature.SignatureStruct +import me.gabriel.selene.analysis.signature.Signatures +import me.gabriel.selene.analysis.util.unknownReferenceSignatureToType +import me.gabriel.selene.frontend.SeleneType +import me.gabriel.selene.frontend.parsing.DataStructureNode class StructAnalyzer: SingleNodeAnalyzer(DataStructureNode::class) { override fun register( @@ -27,7 +26,7 @@ class StructAnalyzer: SingleNodeAnalyzer(DataStructureNode::c fields = fields ) ) - block.defineSymbol(node, GwydionType.Struct( + block.defineSymbol(node, SeleneType.Struct( identifier = node.name, fields = fields )) diff --git a/analysis/src/commonMain/kotlin/analyzers/impl/StructReferenceAnalyzer.kt b/analysis/src/commonMain/kotlin/analyzers/impl/StructReferenceAnalyzer.kt index dc9bb6d..7c804c4 100644 --- a/analysis/src/commonMain/kotlin/analyzers/impl/StructReferenceAnalyzer.kt +++ b/analysis/src/commonMain/kotlin/analyzers/impl/StructReferenceAnalyzer.kt @@ -1,12 +1,12 @@ -package me.gabriel.gwydion.analysis.analyzers.impl +package me.gabriel.selene.analysis.analyzers.impl -import me.gabriel.gwydion.analysis.AnalysisResult -import me.gabriel.gwydion.analysis.SymbolBlock -import me.gabriel.gwydion.analysis.analyzers.SingleNodeAnalyzer -import me.gabriel.gwydion.analysis.analyzers.TypeInferenceVisitor -import me.gabriel.gwydion.analysis.signature.Signatures -import me.gabriel.gwydion.frontend.GwydionType -import me.gabriel.gwydion.frontend.parsing.DataStructureReferenceNode +import me.gabriel.selene.analysis.AnalysisResult +import me.gabriel.selene.analysis.SymbolBlock +import me.gabriel.selene.analysis.analyzers.SingleNodeAnalyzer +import me.gabriel.selene.analysis.analyzers.TypeInferenceVisitor +import me.gabriel.selene.analysis.signature.Signatures +import me.gabriel.selene.frontend.SeleneType +import me.gabriel.selene.frontend.parsing.DataStructureReferenceNode class StructReferenceAnalyzer: SingleNodeAnalyzer(DataStructureReferenceNode::class) { override fun register( @@ -19,7 +19,7 @@ class StructReferenceAnalyzer: SingleNodeAnalyzer(Da it.name == node.name } ?: return block - block.defineSymbol(node, GwydionType.Struct(struct.name, struct.fields)) + block.defineSymbol(node, SeleneType.Struct(struct.name, struct.fields)) return block } diff --git a/analysis/src/commonMain/kotlin/analyzers/impl/TraitAnalyzer.kt b/analysis/src/commonMain/kotlin/analyzers/impl/TraitAnalyzer.kt index eabe049..1e8f529 100644 --- a/analysis/src/commonMain/kotlin/analyzers/impl/TraitAnalyzer.kt +++ b/analysis/src/commonMain/kotlin/analyzers/impl/TraitAnalyzer.kt @@ -1,13 +1,13 @@ -package me.gabriel.gwydion.analysis.analyzers.impl +package me.gabriel.selene.analysis.analyzers.impl -import me.gabriel.gwydion.analysis.SymbolBlock -import me.gabriel.gwydion.analysis.analyzers.SingleNodeAnalyzer -import me.gabriel.gwydion.analysis.analyzers.TypeInferenceVisitor -import me.gabriel.gwydion.analysis.signature.SignatureFunction -import me.gabriel.gwydion.analysis.signature.SignatureTrait -import me.gabriel.gwydion.analysis.signature.Signatures -import me.gabriel.gwydion.analysis.util.unknownReferenceSignatureToType -import me.gabriel.gwydion.frontend.parsing.TraitNode +import me.gabriel.selene.analysis.SymbolBlock +import me.gabriel.selene.analysis.analyzers.SingleNodeAnalyzer +import me.gabriel.selene.analysis.analyzers.TypeInferenceVisitor +import me.gabriel.selene.analysis.signature.SignatureFunction +import me.gabriel.selene.analysis.signature.SignatureTrait +import me.gabriel.selene.analysis.signature.Signatures +import me.gabriel.selene.analysis.util.unknownReferenceSignatureToType +import me.gabriel.selene.frontend.parsing.TraitNode class TraitAnalyzer: SingleNodeAnalyzer(TraitNode::class) { override fun register( diff --git a/analysis/src/commonMain/kotlin/analyzers/impl/TraitFunctionCallAnalyzer.kt b/analysis/src/commonMain/kotlin/analyzers/impl/TraitFunctionCallAnalyzer.kt index 6e1ad37..c6ba007 100644 --- a/analysis/src/commonMain/kotlin/analyzers/impl/TraitFunctionCallAnalyzer.kt +++ b/analysis/src/commonMain/kotlin/analyzers/impl/TraitFunctionCallAnalyzer.kt @@ -1,13 +1,13 @@ -package me.gabriel.gwydion.analysis.analyzers.impl +package me.gabriel.selene.analysis.analyzers.impl -import me.gabriel.gwydion.analysis.AnalysisResult -import me.gabriel.gwydion.analysis.SymbolBlock -import me.gabriel.gwydion.analysis.analyzers.SingleNodeAnalyzer -import me.gabriel.gwydion.analysis.analyzers.TypeInferenceVisitor -import me.gabriel.gwydion.analysis.signature.Signatures -import me.gabriel.gwydion.analysis.util.resolveTraitForExpression -import me.gabriel.gwydion.frontend.GwydionType -import me.gabriel.gwydion.frontend.parsing.TraitFunctionCallNode +import me.gabriel.selene.analysis.AnalysisResult +import me.gabriel.selene.analysis.SymbolBlock +import me.gabriel.selene.analysis.analyzers.SingleNodeAnalyzer +import me.gabriel.selene.analysis.analyzers.TypeInferenceVisitor +import me.gabriel.selene.analysis.signature.Signatures +import me.gabriel.selene.analysis.util.resolveTraitForExpression +import me.gabriel.selene.frontend.SeleneType +import me.gabriel.selene.frontend.parsing.TraitFunctionCallNode class TraitFunctionCallAnalyzer: SingleNodeAnalyzer(TraitFunctionCallNode::class) { override fun register( @@ -20,7 +20,7 @@ class TraitFunctionCallAnalyzer: SingleNodeAnalyzer(Trait block.resolveExpression(node.trait) ?: return@visit } - if (traitType is GwydionType.Trait) { + if (traitType is SeleneType.Trait) { val function = traitType.functions.firstOrNull { it.name == node.function } if (function != null) { block.defineSymbol(node, function.returnType) diff --git a/analysis/src/commonMain/kotlin/analyzers/impl/TraitImplAnalyzer.kt b/analysis/src/commonMain/kotlin/analyzers/impl/TraitImplAnalyzer.kt index e5aa9bd..835cd7b 100644 --- a/analysis/src/commonMain/kotlin/analyzers/impl/TraitImplAnalyzer.kt +++ b/analysis/src/commonMain/kotlin/analyzers/impl/TraitImplAnalyzer.kt @@ -1,18 +1,17 @@ -package me.gabriel.gwydion.analysis.analyzers.impl +package me.gabriel.selene.analysis.analyzers.impl -import me.gabriel.gwydion.analysis.AnalysisError -import me.gabriel.gwydion.analysis.AnalysisResult -import me.gabriel.gwydion.analysis.SymbolBlock -import me.gabriel.gwydion.analysis.analyzers.SingleNodeAnalyzer -import me.gabriel.gwydion.analysis.analyzers.TypeInferenceVisitor -import me.gabriel.gwydion.analysis.signature.SignatureFunction -import me.gabriel.gwydion.analysis.signature.SignatureTraitImpl -import me.gabriel.gwydion.analysis.signature.Signatures -import me.gabriel.gwydion.analysis.util.unknownReferenceSignatureToType -import me.gabriel.gwydion.frontend.GwydionType -import me.gabriel.gwydion.frontend.parsing.FunctionNode -import me.gabriel.gwydion.frontend.parsing.ParameterNode -import me.gabriel.gwydion.frontend.parsing.TraitImplNode +import me.gabriel.selene.analysis.AnalysisError +import me.gabriel.selene.analysis.AnalysisResult +import me.gabriel.selene.analysis.SymbolBlock +import me.gabriel.selene.analysis.analyzers.SingleNodeAnalyzer +import me.gabriel.selene.analysis.analyzers.TypeInferenceVisitor +import me.gabriel.selene.analysis.signature.SignatureFunction +import me.gabriel.selene.analysis.signature.SignatureTraitImpl +import me.gabriel.selene.analysis.signature.Signatures +import me.gabriel.selene.analysis.util.unknownReferenceSignatureToType +import me.gabriel.selene.frontend.SeleneType +import me.gabriel.selene.frontend.parsing.FunctionNode +import me.gabriel.selene.frontend.parsing.TraitImplNode class TraitImplAnalyzer: SingleNodeAnalyzer(TraitImplNode::class) { override fun register( @@ -22,7 +21,7 @@ class TraitImplAnalyzer: SingleNodeAnalyzer(TraitImplNode::class) visitor: TypeInferenceVisitor ): SymbolBlock { node.type = unknownReferenceSignatureToType(signatures, node.type) - if (node.type is GwydionType.UnknownReference) return block + if (node.type is SeleneType.UnknownReference) return block val trait = signatures.traits.find { it.name == node.trait } if (trait == null) return block @@ -61,7 +60,7 @@ class TraitImplAnalyzer: SingleNodeAnalyzer(TraitImplNode::class) if (trait == null) return newBlock val missingFunctions = mutableListOf() - val wrongFunctions = mutableMapOf>() + val wrongFunctions = mutableMapOf>() trait.functions.forEach { traitFunction -> val implFunction = node.functions.find { it.name == traitFunction.name } @@ -100,7 +99,7 @@ class TraitImplAnalyzer: SingleNodeAnalyzer(TraitImplNode::class) return newBlock } - private fun doParametersMatch(provided: List, required: List): Boolean { + private fun doParametersMatch(provided: List, required: List): Boolean { if (provided.size != required.size) return false return provided.zip(required).all { (provided, required) -> provided == required diff --git a/analysis/src/commonMain/kotlin/analyzers/impl/VariableReferenceAnalyzer.kt b/analysis/src/commonMain/kotlin/analyzers/impl/VariableReferenceAnalyzer.kt index f23b95e..fb1911d 100644 --- a/analysis/src/commonMain/kotlin/analyzers/impl/VariableReferenceAnalyzer.kt +++ b/analysis/src/commonMain/kotlin/analyzers/impl/VariableReferenceAnalyzer.kt @@ -1,11 +1,11 @@ -package me.gabriel.gwydion.analysis.analyzers.impl +package me.gabriel.selene.analysis.analyzers.impl -import me.gabriel.gwydion.analysis.SymbolBlock -import me.gabriel.gwydion.analysis.analyzers.SingleNodeAnalyzer -import me.gabriel.gwydion.analysis.analyzers.TypeInferenceVisitor -import me.gabriel.gwydion.analysis.signature.Signatures -import me.gabriel.gwydion.frontend.GwydionType -import me.gabriel.gwydion.frontend.parsing.VariableReferenceNode +import me.gabriel.selene.analysis.SymbolBlock +import me.gabriel.selene.analysis.analyzers.SingleNodeAnalyzer +import me.gabriel.selene.analysis.analyzers.TypeInferenceVisitor +import me.gabriel.selene.analysis.signature.Signatures +import me.gabriel.selene.frontend.SeleneType +import me.gabriel.selene.frontend.parsing.VariableReferenceNode class VariableReferenceAnalyzer: SingleNodeAnalyzer(VariableReferenceNode::class) { override fun register( @@ -14,7 +14,7 @@ class VariableReferenceAnalyzer: SingleNodeAnalyzer(Varia signatures: Signatures, visitor: TypeInferenceVisitor ): SymbolBlock { - block.defineSymbol(node, block.resolveSymbol(node.name) ?: GwydionType.Unknown) + block.defineSymbol(node, block.resolveSymbol(node.name) ?: SeleneType.Unknown) return block } } \ No newline at end of file diff --git a/analysis/src/commonMain/kotlin/signature/Signatures.kt b/analysis/src/commonMain/kotlin/signature/Signatures.kt index d952a8e..5915915 100644 --- a/analysis/src/commonMain/kotlin/signature/Signatures.kt +++ b/analysis/src/commonMain/kotlin/signature/Signatures.kt @@ -1,8 +1,8 @@ -package me.gabriel.gwydion.analysis.signature +package me.gabriel.selene.analysis.signature -import me.gabriel.gwydion.frontend.GwydionType +import me.gabriel.selene.frontend.SeleneType import kotlinx.serialization.Serializable -import me.gabriel.gwydion.frontend.parsing.Modifiers +import me.gabriel.selene.frontend.parsing.Modifiers @Serializable data class Signatures( @@ -32,7 +32,7 @@ data class Signatures( data class SignatureStruct( val name: String, val module: String, - val fields: Map + val fields: Map ) @Serializable @@ -46,8 +46,8 @@ data class SignatureTrait( data class SignatureFunction( val module: String, val name: String, - val returnType: GwydionType, - val parameters: List, + val returnType: SeleneType, + val parameters: List, val modifiers: List ) @@ -57,5 +57,5 @@ data class SignatureTraitImpl( val trait: String, var index: Int?, var module: String?, - val types: List + val types: List ) \ No newline at end of file diff --git a/analysis/src/commonMain/kotlin/util/Analysis.kt b/analysis/src/commonMain/kotlin/util/Analysis.kt index 9d117b9..db8d0de 100644 --- a/analysis/src/commonMain/kotlin/util/Analysis.kt +++ b/analysis/src/commonMain/kotlin/util/Analysis.kt @@ -1,25 +1,25 @@ -package me.gabriel.gwydion.analysis.util +package me.gabriel.selene.analysis.util -import me.gabriel.gwydion.analysis.signature.Signatures -import me.gabriel.gwydion.frontend.GwydionType -import me.gabriel.gwydion.frontend.mapBase +import me.gabriel.selene.analysis.signature.Signatures +import me.gabriel.selene.frontend.SeleneType +import me.gabriel.selene.frontend.mapBase internal fun unknownReferenceSignatureToType( signatures: Signatures, - type: GwydionType, -): GwydionType = type.mapBase { unknown -> - if (unknown !is GwydionType.UnknownReference) + type: SeleneType, +): SeleneType = type.mapBase { unknown -> + if (unknown !is SeleneType.UnknownReference) return@mapBase unknown val struct = signatures.structs.find { it.name == unknown.reference } if (struct != null) { - return@mapBase GwydionType.Struct(struct.name, struct.fields) + return@mapBase SeleneType.Struct(struct.name, struct.fields) } val trait = signatures.traits.find { it.name == unknown.reference } if (trait != null) { - return@mapBase GwydionType.Trait(trait.name, trait.functions.map { - GwydionType.VirtualFunction( + return@mapBase SeleneType.Trait(trait.name, trait.functions.map { + SeleneType.VirtualFunction( it.name, it.returnType, it.parameters diff --git a/analysis/src/commonMain/kotlin/util/Strings.kt b/analysis/src/commonMain/kotlin/util/Strings.kt index e507f2f..523517b 100644 --- a/analysis/src/commonMain/kotlin/util/Strings.kt +++ b/analysis/src/commonMain/kotlin/util/Strings.kt @@ -1,13 +1,13 @@ -package me.gabriel.gwydion.analysis.util +package me.gabriel.selene.analysis.util -import me.gabriel.gwydion.frontend.GwydionType +import me.gabriel.selene.frontend.SeleneType -fun String.castToType(type: GwydionType): String = when (type) { - GwydionType.Int8 -> this.toByte().toString() - GwydionType.Int16 -> this.toShort().toString() - GwydionType.Int32 -> this.toInt().toString() - GwydionType.Int64 -> this.toLong().toString() - GwydionType.Float32 -> this.toFloat().toString() - GwydionType.Float64 -> this.toDouble().toString() +fun String.castToType(type: SeleneType): String = when (type) { + SeleneType.Int8 -> this.toByte().toString() + SeleneType.Int16 -> this.toShort().toString() + SeleneType.Int32 -> this.toInt().toString() + SeleneType.Int64 -> this.toLong().toString() + SeleneType.Float32 -> this.toFloat().toString() + SeleneType.Float64 -> this.toDouble().toString() else -> this } \ No newline at end of file diff --git a/analysis/src/commonMain/kotlin/util/Traits.kt b/analysis/src/commonMain/kotlin/util/Traits.kt index 477243f..96937ec 100644 --- a/analysis/src/commonMain/kotlin/util/Traits.kt +++ b/analysis/src/commonMain/kotlin/util/Traits.kt @@ -1,22 +1,22 @@ -package me.gabriel.gwydion.analysis.util +package me.gabriel.selene.analysis.util -import me.gabriel.gwydion.analysis.SymbolBlock -import me.gabriel.gwydion.analysis.signature.SignatureFunction -import me.gabriel.gwydion.analysis.signature.SignatureTrait -import me.gabriel.gwydion.analysis.signature.SignatureTraitImpl -import me.gabriel.gwydion.analysis.signature.Signatures -import me.gabriel.gwydion.frontend.GwydionType -import me.gabriel.gwydion.frontend.parsing.DataStructureReferenceNode -import me.gabriel.gwydion.frontend.parsing.SyntaxTreeNode -import me.gabriel.gwydion.frontend.parsing.VariableReferenceNode -import me.gabriel.gwydion.frontend.workingBase +import me.gabriel.selene.analysis.SymbolBlock +import me.gabriel.selene.analysis.signature.SignatureFunction +import me.gabriel.selene.analysis.signature.SignatureTrait +import me.gabriel.selene.analysis.signature.SignatureTraitImpl +import me.gabriel.selene.analysis.signature.Signatures +import me.gabriel.selene.frontend.SeleneType +import me.gabriel.selene.frontend.parsing.DataStructureReferenceNode +import me.gabriel.selene.frontend.parsing.SyntaxTreeNode +import me.gabriel.selene.frontend.parsing.VariableReferenceNode +import me.gabriel.selene.frontend.workingBase data class TraitFunctionMetadata( val trait: SignatureTrait, val impl: SignatureTraitImpl?, val function: SignatureFunction, - val returnType: GwydionType, - val variableType: GwydionType + val returnType: SeleneType, + val variableType: SeleneType ) fun resolveTraitForExpression( @@ -29,7 +29,7 @@ fun resolveTraitForExpression( is DataStructureReferenceNode -> signatures.structs.find { it.name == variable.name }?.let { - GwydionType.Struct( + SeleneType.Struct( it.name, it.fields ) @@ -40,11 +40,11 @@ fun resolveTraitForExpression( } ?: return null return signatures.traits.firstNotNullOfOrNull { trait -> - val impl = if (resolvedVariable !is GwydionType.Trait) trait.impls.firstOrNull { + val impl = if (resolvedVariable !is SeleneType.Trait) trait.impls.firstOrNull { it.struct == resolvedVariable.workingBase().signature } else null - if (impl != null || resolvedVariable is GwydionType.Trait) { + if (impl != null || resolvedVariable is SeleneType.Trait) { val function = trait.functions.firstOrNull { it.name == call } if (function != null) { return TraitFunctionMetadata(trait, impl, function, function.returnType, resolvedVariable) diff --git a/analysis/src/commonMain/kotlin/util/Types.kt b/analysis/src/commonMain/kotlin/util/Types.kt index 40f524b..eee5549 100644 --- a/analysis/src/commonMain/kotlin/util/Types.kt +++ b/analysis/src/commonMain/kotlin/util/Types.kt @@ -1,24 +1,24 @@ -package me.gabriel.gwydion.analysis.util +package me.gabriel.selene.analysis.util -import me.gabriel.gwydion.analysis.signature.Signatures -import me.gabriel.gwydion.frontend.GwydionType +import me.gabriel.selene.analysis.signature.Signatures +import me.gabriel.selene.frontend.SeleneType fun doesProvidedTypeAccordToExpectedType( - provided: GwydionType, - required: GwydionType, + provided: SeleneType, + required: SeleneType, signatures: Signatures ): Boolean { - if (required == GwydionType.Unknown || required == GwydionType.Any) { + if (required == SeleneType.Unknown || required == SeleneType.Any) { return true } - if (required is GwydionType.Mutable || provided is GwydionType.Mutable) { - if (provided is GwydionType.Mutable && required !is GwydionType.Mutable) { + if (required is SeleneType.Mutable || provided is SeleneType.Mutable) { + if (provided is SeleneType.Mutable && required !is SeleneType.Mutable) { return doesProvidedTypeAccordToExpectedType(required, provided.baseType, signatures) - } else if (provided !is GwydionType.Mutable) { + } else if (provided !is SeleneType.Mutable) { return false } } - if (required is GwydionType.Trait && provided is GwydionType.Struct) { + if (required is SeleneType.Trait && provided is SeleneType.Struct) { val trait = signatures.traits.find { it.name == required.identifier } ?: return false diff --git a/bard/README.md b/bard/README.md index bde4b5a..7bb4017 100644 --- a/bard/README.md +++ b/bard/README.md @@ -1,3 +1,3 @@ # bard -Bard is an incoming build tool and package manager for the Gwydion programming language. This is meant to be a replacement for `jester`, which is a build tool written in Rust. In contrast to `jester`, bard is written in Gwydion itself. \ No newline at end of file +Bard is an incoming build tool and package manager for the Selene programming language. This is meant to be a replacement for `jester`, which is a build tool written in Rust. In contrast to `jester`, bard is written in Selene itself. \ No newline at end of file diff --git a/bard/jester.exe b/bard/jester.exe index 994d7d4..c279b6a 100755 Binary files a/bard/jester.exe and b/bard/jester.exe differ diff --git a/bard/output/ll/bard.ll b/bard/output/ll/bard.ll index 01d236c..aa2f5df 100644 --- a/bard/output/ll/bard.ll +++ b/bard/output/ll/bard.ll @@ -46,24 +46,24 @@ entry: %19 = getelementptr inbounds [14 x i8], [14 x i8]* %4, i32 0, i32 0 call void @println_str(i8* %19) %21 = add i32 2, 0 - call i1 @callback(i32 %21, ptr @lambda_1487500813) + call i1 @callback(i32 %21, ptr @lambda_294658058) %25 = add i32 4, 0 - call i1 @callback(i32 %25, ptr @lambda_1886491834) + call i1 @callback(i32 %25, ptr @lambda_1278852808) %29 = add i32 8, 0 - call i1 @callback(i32 %29, ptr @lambda_1536471117) + call i1 @callback(i32 %29, ptr @lambda_1955920234) ret void } -define i32 @lambda_1487500813(i32 %22) { +define i32 @lambda_294658058(i32 %22) { entry: %33 = add i32 %22, 12 ret i32 %33 } -define i32 @lambda_1886491834(i32 %26) { +define i32 @lambda_1278852808(i32 %26) { entry: %34 = add i32 %26, 24 ret i32 %34 } -define i32 @lambda_1536471117(i32 %30) { +define i32 @lambda_1955920234(i32 %30) { entry: %35 = add i32 %30, 36 ret i32 %35 diff --git a/bard/output/ll/signatures.json b/bard/output/ll/signatures.json index 84d5453..1961084 100644 --- a/bard/output/ll/signatures.json +++ b/bard/output/ll/signatures.json @@ -1 +1 @@ -{"structs":[{"name":"Socket","module":"stdlib","fields":{"id":{"type":"me.gabriel.gwydion.frontend.GwydionType.Int32"},"family":{"type":"me.gabriel.gwydion.frontend.GwydionType.Int32"},"port":{"type":"me.gabriel.gwydion.frontend.GwydionType.Int16"},"ip_address":{"type":"me.gabriel.gwydion.frontend.GwydionType.Int32"}}},{"name":"TcpServer","module":"stdlib","fields":{"ip_address":{"type":"me.gabriel.gwydion.frontend.GwydionType.Int32"},"port":{"type":"me.gabriel.gwydion.frontend.GwydionType.Int16"}}}],"functions":[{"module":"stdlib","name":"length","returnType":{"type":"me.gabriel.gwydion.frontend.GwydionType.Int32"},"parameters":[{"type":"me.gabriel.gwydion.frontend.GwydionType.Self"}],"modifiers":[]},{"module":"stdlib","name":"text","returnType":{"type":"me.gabriel.gwydion.frontend.GwydionType.String"},"parameters":[{"type":"me.gabriel.gwydion.frontend.GwydionType.Self"}],"modifiers":[]},{"module":"stdlib","name":"printf","returnType":{"type":"me.gabriel.gwydion.frontend.GwydionType.Void"},"parameters":[{"type":"me.gabriel.gwydion.frontend.GwydionType.Any"}],"modifiers":["INTRINSIC"]},{"module":"stdlib","name":"println","returnType":{"type":"me.gabriel.gwydion.frontend.GwydionType.Void"},"parameters":[{"type":"me.gabriel.gwydion.frontend.GwydionType.Any"}],"modifiers":["INTRINSIC"]},{"module":"stdlib","name":"readln","returnType":{"type":"me.gabriel.gwydion.frontend.GwydionType.String"},"parameters":[],"modifiers":["INTRINSIC"]},{"module":"stdlib","name":"arraylen","returnType":{"type":"me.gabriel.gwydion.frontend.GwydionType.Int32"},"parameters":[{"type":"me.gabriel.gwydion.frontend.GwydionType.Any"}],"modifiers":["INTRINSIC"]},{"module":"stdlib","name":"sin","returnType":{"type":"me.gabriel.gwydion.frontend.GwydionType.Float64"},"parameters":[{"type":"me.gabriel.gwydion.frontend.GwydionType.Float64"}],"modifiers":["INTRINSIC"]},{"module":"stdlib","name":"cos","returnType":{"type":"me.gabriel.gwydion.frontend.GwydionType.Float64"},"parameters":[{"type":"me.gabriel.gwydion.frontend.GwydionType.Float64"}],"modifiers":["INTRINSIC"]},{"module":"stdlib","name":"tan","returnType":{"type":"me.gabriel.gwydion.frontend.GwydionType.Float64"},"parameters":[{"type":"me.gabriel.gwydion.frontend.GwydionType.Float64"}],"modifiers":["INTRINSIC"]},{"module":"stdlib","name":"asin","returnType":{"type":"me.gabriel.gwydion.frontend.GwydionType.Float64"},"parameters":[{"type":"me.gabriel.gwydion.frontend.GwydionType.Float64"}],"modifiers":["INTRINSIC"]},{"module":"stdlib","name":"acos","returnType":{"type":"me.gabriel.gwydion.frontend.GwydionType.Float64"},"parameters":[{"type":"me.gabriel.gwydion.frontend.GwydionType.Float64"}],"modifiers":["INTRINSIC"]},{"module":"stdlib","name":"atan","returnType":{"type":"me.gabriel.gwydion.frontend.GwydionType.Float64"},"parameters":[{"type":"me.gabriel.gwydion.frontend.GwydionType.Float64"}],"modifiers":["INTRINSIC"]},{"module":"stdlib","name":"atan2","returnType":{"type":"me.gabriel.gwydion.frontend.GwydionType.Float64"},"parameters":[{"type":"me.gabriel.gwydion.frontend.GwydionType.Float64"},{"type":"me.gabriel.gwydion.frontend.GwydionType.Float64"}],"modifiers":["INTRINSIC"]},{"module":"stdlib","name":"socket","returnType":{"type":"me.gabriel.gwydion.frontend.GwydionType.Int32"},"parameters":[{"type":"me.gabriel.gwydion.frontend.GwydionType.Int32"},{"type":"me.gabriel.gwydion.frontend.GwydionType.Int32"},{"type":"me.gabriel.gwydion.frontend.GwydionType.Int32"}],"modifiers":["INTERNAL","INTRINSIC"]},{"module":"stdlib","name":"bind","returnType":{"type":"me.gabriel.gwydion.frontend.GwydionType.Int32"},"parameters":[{"type":"me.gabriel.gwydion.frontend.GwydionType.Int32"},{"type":"me.gabriel.gwydion.frontend.GwydionType.Int8"},{"type":"me.gabriel.gwydion.frontend.GwydionType.Int32"}],"modifiers":["INTERNAL","INTRINSIC"]},{"module":"stdlib","name":"listen","returnType":{"type":"me.gabriel.gwydion.frontend.GwydionType.Int32"},"parameters":[{"type":"me.gabriel.gwydion.frontend.GwydionType.Int32"},{"type":"me.gabriel.gwydion.frontend.GwydionType.Int32"}],"modifiers":["INTERNAL","INTRINSIC"]},{"module":"stdlib","name":"accept","returnType":{"type":"me.gabriel.gwydion.frontend.GwydionType.Int32"},"parameters":[{"type":"me.gabriel.gwydion.frontend.GwydionType.Int32"},{"type":"me.gabriel.gwydion.frontend.GwydionType.Int8"},{"type":"me.gabriel.gwydion.frontend.GwydionType.Int32"}],"modifiers":["INTERNAL","INTRINSIC"]},{"module":"stdlib","name":"receive","returnType":{"type":"me.gabriel.gwydion.frontend.GwydionType.Int32"},"parameters":[{"type":"me.gabriel.gwydion.frontend.GwydionType.Int32"},{"type":"me.gabriel.gwydion.frontend.GwydionType.Int8"},{"type":"me.gabriel.gwydion.frontend.GwydionType.Int32"},{"type":"me.gabriel.gwydion.frontend.GwydionType.Int32"}],"modifiers":["INTERNAL","INTRINSIC"]},{"module":"stdlib","name":"send","returnType":{"type":"me.gabriel.gwydion.frontend.GwydionType.Int32"},"parameters":[{"type":"me.gabriel.gwydion.frontend.GwydionType.Int32"},{"type":"me.gabriel.gwydion.frontend.GwydionType.Int8"},{"type":"me.gabriel.gwydion.frontend.GwydionType.Int32"},{"type":"me.gabriel.gwydion.frontend.GwydionType.Int32"}],"modifiers":["INTERNAL","INTRINSIC"]},{"module":"stdlib","name":"close","returnType":{"type":"me.gabriel.gwydion.frontend.GwydionType.Int32"},"parameters":[{"type":"me.gabriel.gwydion.frontend.GwydionType.Int32"}],"modifiers":["INTERNAL","INTRINSIC"]},{"module":"bard","name":"callback","returnType":{"type":"me.gabriel.gwydion.frontend.GwydionType.Void"},"parameters":[{"type":"me.gabriel.gwydion.frontend.GwydionType.Int32"},{"type":"me.gabriel.gwydion.frontend.GwydionType.Lambda","id":"lambda","signature":"(int32) -> int32","parameters":[{"type":"me.gabriel.gwydion.frontend.GwydionType.Int32"}],"returnType":{"type":"me.gabriel.gwydion.frontend.GwydionType.Int32"}}],"modifiers":[]},{"module":"bard","name":"main","returnType":{"type":"me.gabriel.gwydion.frontend.GwydionType.Void"},"parameters":[],"modifiers":[]}],"traits":[{"name":"Collection","functions":[{"module":"stdlib","name":"size","returnType":{"type":"me.gabriel.gwydion.frontend.GwydionType.Int32"},"parameters":[{"type":"me.gabriel.gwydion.frontend.GwydionType.Self"}],"modifiers":[]},{"module":"stdlib","name":"get","returnType":{"type":"me.gabriel.gwydion.frontend.GwydionType.String"},"parameters":[{"type":"me.gabriel.gwydion.frontend.GwydionType.Self"},{"type":"me.gabriel.gwydion.frontend.GwydionType.Int32"}],"modifiers":[]},{"module":"stdlib","name":"push","returnType":{"type":"me.gabriel.gwydion.frontend.GwydionType.Void"},"parameters":[{"type":"me.gabriel.gwydion.frontend.GwydionType.Mutable","id":"mutate","signature":"mut self","baseType":{"type":"me.gabriel.gwydion.frontend.GwydionType.Self"}},{"type":"me.gabriel.gwydion.frontend.GwydionType.String"}],"modifiers":[]}]},{"name":"Legible","functions":[{"module":"stdlib","name":"text","returnType":{"type":"me.gabriel.gwydion.frontend.GwydionType.String"},"parameters":[{"type":"me.gabriel.gwydion.frontend.GwydionType.Self"}],"modifiers":[]}],"impls":[{"struct":"string","trait":"Legible","index":2001223946,"module":"stdlib","types":[{"type":"me.gabriel.gwydion.frontend.GwydionType.String"}]},{"struct":"int32","trait":"Legible","index":1433666880,"module":"stdlib","types":[{"type":"me.gabriel.gwydion.frontend.GwydionType.String"}]}]},{"name":"CharArray","functions":[{"module":"stdlib","name":"length","returnType":{"type":"me.gabriel.gwydion.frontend.GwydionType.Int32"},"parameters":[{"type":"me.gabriel.gwydion.frontend.GwydionType.Self"}],"modifiers":[]}],"impls":[{"struct":"string","trait":"CharArray","index":294658058,"module":"stdlib","types":[{"type":"me.gabriel.gwydion.frontend.GwydionType.Int32"}]}]}]} \ No newline at end of file +{"structs":[{"name":"Socket","module":"stdlib","fields":{"id":{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},"family":{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},"port":{"type":"me.gabriel.selene.frontend.SeleneType.Int16"},"ip_address":{"type":"me.gabriel.selene.frontend.SeleneType.Int32"}}},{"name":"TcpServer","module":"stdlib","fields":{"ip_address":{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},"port":{"type":"me.gabriel.selene.frontend.SeleneType.Int16"}}}],"functions":[{"module":"stdlib","name":"length","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Self"}],"modifiers":[]},{"module":"stdlib","name":"text","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.String"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Self"}],"modifiers":[]},{"module":"stdlib","name":"printf","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Void"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Any"}],"modifiers":["INTRINSIC"]},{"module":"stdlib","name":"println","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Void"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Any"}],"modifiers":["INTRINSIC"]},{"module":"stdlib","name":"readln","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.String"},"parameters":[],"modifiers":["INTRINSIC"]},{"module":"stdlib","name":"arraylen","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Any"}],"modifiers":["INTRINSIC"]},{"module":"stdlib","name":"sin","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Float64"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Float64"}],"modifiers":["INTRINSIC"]},{"module":"stdlib","name":"cos","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Float64"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Float64"}],"modifiers":["INTRINSIC"]},{"module":"stdlib","name":"tan","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Float64"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Float64"}],"modifiers":["INTRINSIC"]},{"module":"stdlib","name":"asin","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Float64"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Float64"}],"modifiers":["INTRINSIC"]},{"module":"stdlib","name":"acos","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Float64"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Float64"}],"modifiers":["INTRINSIC"]},{"module":"stdlib","name":"atan","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Float64"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Float64"}],"modifiers":["INTRINSIC"]},{"module":"stdlib","name":"atan2","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Float64"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Float64"},{"type":"me.gabriel.selene.frontend.SeleneType.Float64"}],"modifiers":["INTRINSIC"]},{"module":"stdlib","name":"socket","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},{"type":"me.gabriel.selene.frontend.SeleneType.Int32"}],"modifiers":["INTERNAL","INTRINSIC"]},{"module":"stdlib","name":"bind","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},{"type":"me.gabriel.selene.frontend.SeleneType.Int8"},{"type":"me.gabriel.selene.frontend.SeleneType.Int32"}],"modifiers":["INTERNAL","INTRINSIC"]},{"module":"stdlib","name":"listen","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},{"type":"me.gabriel.selene.frontend.SeleneType.Int32"}],"modifiers":["INTERNAL","INTRINSIC"]},{"module":"stdlib","name":"accept","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},{"type":"me.gabriel.selene.frontend.SeleneType.Int8"},{"type":"me.gabriel.selene.frontend.SeleneType.Int32"}],"modifiers":["INTERNAL","INTRINSIC"]},{"module":"stdlib","name":"receive","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},{"type":"me.gabriel.selene.frontend.SeleneType.Int8"},{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},{"type":"me.gabriel.selene.frontend.SeleneType.Int32"}],"modifiers":["INTERNAL","INTRINSIC"]},{"module":"stdlib","name":"send","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},{"type":"me.gabriel.selene.frontend.SeleneType.Int8"},{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},{"type":"me.gabriel.selene.frontend.SeleneType.Int32"}],"modifiers":["INTERNAL","INTRINSIC"]},{"module":"stdlib","name":"close","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Int32"}],"modifiers":["INTERNAL","INTRINSIC"]},{"module":"bard","name":"callback","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Void"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},{"type":"me.gabriel.selene.frontend.SeleneType.Lambda","id":"lambda","signature":"(int32) -> int32","parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Int32"}],"returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Int32"}}],"modifiers":[]},{"module":"bard","name":"main","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Void"},"parameters":[],"modifiers":[]}],"traits":[{"name":"Collection","functions":[{"module":"stdlib","name":"size","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Self"}],"modifiers":[]},{"module":"stdlib","name":"get","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.String"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Self"},{"type":"me.gabriel.selene.frontend.SeleneType.Int32"}],"modifiers":[]},{"module":"stdlib","name":"push","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Void"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Mutable","id":"mutate","signature":"mut self","baseType":{"type":"me.gabriel.selene.frontend.SeleneType.Self"}},{"type":"me.gabriel.selene.frontend.SeleneType.String"}],"modifiers":[]}]},{"name":"Legible","functions":[{"module":"stdlib","name":"text","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.String"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Self"}],"modifiers":[]}],"impls":[{"struct":"string","trait":"Legible","index":90767234,"module":"stdlib","types":[{"type":"me.gabriel.selene.frontend.SeleneType.String"}]},{"struct":"int32","trait":"Legible","index":1522132780,"module":"stdlib","types":[{"type":"me.gabriel.selene.frontend.SeleneType.String"}]}]},{"name":"CharArray","functions":[{"module":"stdlib","name":"length","returnType":{"type":"me.gabriel.selene.frontend.SeleneType.Int32"},"parameters":[{"type":"me.gabriel.selene.frontend.SeleneType.Self"}],"modifiers":[]}],"impls":[{"struct":"string","trait":"CharArray","index":63390,"module":"stdlib","types":[{"type":"me.gabriel.selene.frontend.SeleneType.Int32"}]}]}]} \ No newline at end of file diff --git a/bard/output/ll/stdlib.ll b/bard/output/ll/stdlib.ll index 73bb36c..588eb7c 100644 --- a/bard/output/ll/stdlib.ll +++ b/bard/output/ll/stdlib.ll @@ -1,14 +1,14 @@ -@trait_1433666880 = unnamed_addr constant <{ i16, i16, ptr }> <{ +@trait_1522132780 = unnamed_addr constant <{ i16, i16, ptr }> <{ i16 8, i16 8, ptr @int32.text }>, align 8 -@trait_2001223946 = unnamed_addr constant <{ i16, i16, ptr }> <{ +@trait_90767234 = unnamed_addr constant <{ i16, i16, ptr }> <{ i16 8, i16 8, ptr @string.text }>, align 8 -@trait_294658058 = unnamed_addr constant <{ i16, i16, ptr }> <{ +@trait_63390 = unnamed_addr constant <{ i16, i16, ptr }> <{ i16 8, i16 8, ptr @string.length diff --git a/bard/output/output.exe b/bard/output/output.exe index 6d1d456..c2f489b 100644 Binary files a/bard/output/output.exe and b/bard/output/output.exe differ diff --git a/build.gradle.kts b/build.gradle.kts index 091bdda..4f87d2c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -3,7 +3,7 @@ plugins { alias(libs.plugins.kotlinx.serialization) apply false } -group = "me.gabriel.gwydion" +group = "me.gabriel.selene" version = "0.0.1-ALPHA" repositories { diff --git a/compiler/build.gradle.kts b/compiler/build.gradle.kts index ab0acd0..c195846 100644 --- a/compiler/build.gradle.kts +++ b/compiler/build.gradle.kts @@ -73,9 +73,9 @@ kotlin { } tasks.withType { - archiveFileName.set("gwydion.jar") + archiveFileName.set("selene.jar") } application { - mainClass = "me.gabriel.gwydion.compiler.jvm.JvmLauncherKt" + mainClass = "me.gabriel.selene.compiler.jvm.JvmLauncherKt" } \ No newline at end of file diff --git a/compiler/src/commonMain/kotlin/GwydionCompilerPlatform.kt b/compiler/src/commonMain/kotlin/GwydionCompilerPlatform.kt deleted file mode 100644 index 248989f..0000000 --- a/compiler/src/commonMain/kotlin/GwydionCompilerPlatform.kt +++ /dev/null @@ -1,11 +0,0 @@ -package me.gabriel.gwydion.compiler - -import me.gabriel.gwydion.compiler.io.IoPlatform -import me.gabriel.gwydion.tools.GwydionLogger - -interface GwydionCompilerPlatform { - val io: IoPlatform - val logger: GwydionLogger - - fun exitProcess(status: Int): Nothing -} \ No newline at end of file diff --git a/compiler/src/commonMain/kotlin/GwydionCompiler.kt b/compiler/src/commonMain/kotlin/SeleneCompiler.kt similarity index 81% rename from compiler/src/commonMain/kotlin/GwydionCompiler.kt rename to compiler/src/commonMain/kotlin/SeleneCompiler.kt index 1dd0949..77dfc6e 100644 --- a/compiler/src/commonMain/kotlin/GwydionCompiler.kt +++ b/compiler/src/commonMain/kotlin/SeleneCompiler.kt @@ -1,26 +1,26 @@ -package me.gabriel.gwydion.compiler +package me.gabriel.selene.compiler import com.github.ajalt.mordant.rendering.TextColors -import me.gabriel.gwydion.analysis.SemanticAnalysisManager -import me.gabriel.gwydion.analysis.SymbolRepository -import me.gabriel.gwydion.analysis.signature.Signatures -import me.gabriel.gwydion.compiler.cli.CommandLine -import me.gabriel.gwydion.compiler.io.LoggedResourceManager -import me.gabriel.gwydion.compiler.log.bold -import me.gabriel.gwydion.compiler.log.color -import me.gabriel.gwydion.frontend.lexing.lexers.StringLexer -import me.gabriel.gwydion.frontend.parsing.Parser -import me.gabriel.gwydion.frontend.parsing.SyntaxTree -import me.gabriel.gwydion.ir.LLVMCodeAdapter -import me.gabriel.gwydion.ir.intrinsics.INTRINSICS -import me.gabriel.gwydion.tools.* +import me.gabriel.selene.analysis.SemanticAnalysisManager +import me.gabriel.selene.analysis.SymbolRepository +import me.gabriel.selene.analysis.signature.Signatures +import me.gabriel.selene.compiler.cli.CommandLine +import me.gabriel.selene.compiler.io.LoggedResourceManager +import me.gabriel.selene.compiler.log.bold +import me.gabriel.selene.compiler.log.color +import me.gabriel.selene.frontend.lexing.lexers.StringLexer +import me.gabriel.selene.frontend.parsing.Parser +import me.gabriel.selene.frontend.parsing.SyntaxTree +import me.gabriel.selene.ir.LLVMCodeAdapter +import me.gabriel.selene.ir.intrinsics.INTRINSICS +import me.gabriel.selene.tools.* -class GwydionCompiler( - private val platform: GwydionCompilerPlatform, +class SeleneCompiler( + private val platform: SeleneCompilerPlatform, private val cli: CommandLine ) { fun start() { - println("Gwydion Compiler") // Let's signal that the compiler has been reached, just in case we face an issue with build tools or whatever! + println("Selene Compiler") // Let's signal that the compiler has been reached, just in case we face an issue with build tools or whatever! val logger by platform::logger val resources = LoggedResourceManager( @@ -37,7 +37,7 @@ class GwydionCompiler( val name = cli.moduleNameOrNull() ?: "program" val signatures = resources.parseSignatures() - logger.log(LogLevel.INFO) { +"Starting the Gwydion compiler..." } + logger.log(LogLevel.INFO) { +"Starting the Selene compiler..." } val symbols = SymbolRepository(name) val llvmCodeAdapter = LLVMCodeAdapter() @@ -61,7 +61,7 @@ class GwydionCompiler( platform.exitProcess(0) } - fun parse(logger: GwydionLogger, text: String, symbols: SymbolRepository, signatures: Signatures): SyntaxTree { + fun parse(logger: SeleneLogger, text: String, symbols: SymbolRepository, signatures: Signatures): SyntaxTree { val lexer = StringLexer(text) val result = lexer.tokenize() if (result.isLeft()) { diff --git a/compiler/src/commonMain/kotlin/SeleneCompilerPlatform.kt b/compiler/src/commonMain/kotlin/SeleneCompilerPlatform.kt new file mode 100644 index 0000000..8011863 --- /dev/null +++ b/compiler/src/commonMain/kotlin/SeleneCompilerPlatform.kt @@ -0,0 +1,11 @@ +package me.gabriel.selene.compiler + +import me.gabriel.selene.compiler.io.IoPlatform +import me.gabriel.selene.tools.SeleneLogger + +interface SeleneCompilerPlatform { + val io: IoPlatform + val logger: SeleneLogger + + fun exitProcess(status: Int): Nothing +} \ No newline at end of file diff --git a/compiler/src/commonMain/kotlin/cli/CommandLine.kt b/compiler/src/commonMain/kotlin/cli/CommandLine.kt index 71423b1..09747cf 100644 --- a/compiler/src/commonMain/kotlin/cli/CommandLine.kt +++ b/compiler/src/commonMain/kotlin/cli/CommandLine.kt @@ -1,4 +1,4 @@ -package me.gabriel.gwydion.compiler.cli +package me.gabriel.selene.compiler.cli // Temporary class CommandLine(private val args: Array) { diff --git a/compiler/src/commonMain/kotlin/io/IoPlatform.kt b/compiler/src/commonMain/kotlin/io/IoPlatform.kt index 4958a13..01db825 100644 --- a/compiler/src/commonMain/kotlin/io/IoPlatform.kt +++ b/compiler/src/commonMain/kotlin/io/IoPlatform.kt @@ -1,4 +1,4 @@ -package me.gabriel.gwydion.compiler.io +package me.gabriel.selene.compiler.io import kotlinx.serialization.json.Json import okio.FileSystem diff --git a/compiler/src/commonMain/kotlin/io/LoggedResourceManager.kt b/compiler/src/commonMain/kotlin/io/LoggedResourceManager.kt index 22ee0ba..ed5b7e6 100644 --- a/compiler/src/commonMain/kotlin/io/LoggedResourceManager.kt +++ b/compiler/src/commonMain/kotlin/io/LoggedResourceManager.kt @@ -1,16 +1,16 @@ -package me.gabriel.gwydion.compiler.io +package me.gabriel.selene.compiler.io import kotlinx.serialization.encodeToString -import me.gabriel.gwydion.analysis.signature.Signatures -import me.gabriel.gwydion.compiler.cli.CommandLine -import me.gabriel.gwydion.compiler.util.fileExtensionOrNull -import me.gabriel.gwydion.tools.GwydionLogger -import me.gabriel.gwydion.tools.LogLevel +import me.gabriel.selene.analysis.signature.Signatures +import me.gabriel.selene.compiler.cli.CommandLine +import me.gabriel.selene.compiler.util.fileExtensionOrNull +import me.gabriel.selene.tools.SeleneLogger +import me.gabriel.selene.tools.LogLevel import okio.Path import okio.Path.Companion.toPath class LoggedResourceManager( - private val logger: GwydionLogger, + private val logger: SeleneLogger, private val cli: CommandLine, override val ioPlatform: IoPlatform ): ResourceManager { diff --git a/compiler/src/commonMain/kotlin/io/ResourceManager.kt b/compiler/src/commonMain/kotlin/io/ResourceManager.kt index 61f505c..7969896 100644 --- a/compiler/src/commonMain/kotlin/io/ResourceManager.kt +++ b/compiler/src/commonMain/kotlin/io/ResourceManager.kt @@ -1,6 +1,6 @@ -package me.gabriel.gwydion.compiler.io +package me.gabriel.selene.compiler.io -import me.gabriel.gwydion.analysis.signature.Signatures +import me.gabriel.selene.analysis.signature.Signatures interface ResourceManager { val ioPlatform: IoPlatform diff --git a/compiler/src/commonMain/kotlin/log/MordantLogger.kt b/compiler/src/commonMain/kotlin/log/MordantLogger.kt index 05b848c..80f1127 100644 --- a/compiler/src/commonMain/kotlin/log/MordantLogger.kt +++ b/compiler/src/commonMain/kotlin/log/MordantLogger.kt @@ -1,14 +1,14 @@ -package me.gabriel.gwydion.compiler.log +package me.gabriel.selene.compiler.log import com.github.ajalt.mordant.rendering.AnsiLevel import com.github.ajalt.mordant.rendering.TextColors import com.github.ajalt.mordant.rendering.TextStyles import com.github.ajalt.mordant.terminal.Terminal -import me.gabriel.gwydion.tools.GwydionLogger -import me.gabriel.gwydion.tools.LogBuilder -import me.gabriel.gwydion.tools.LogLevel +import me.gabriel.selene.tools.SeleneLogger +import me.gabriel.selene.tools.LogBuilder +import me.gabriel.selene.tools.LogLevel -class MordantLogger: GwydionLogger { +class MordantLogger: SeleneLogger { private val terminal = Terminal(tabWidth = 4, ansiLevel = AnsiLevel.TRUECOLOR) override fun log(level: LogLevel, message: LogBuilder.() -> Unit) { diff --git a/compiler/src/commonMain/kotlin/util/Okio.kt b/compiler/src/commonMain/kotlin/util/Okio.kt index 3418d33..662bbf4 100644 --- a/compiler/src/commonMain/kotlin/util/Okio.kt +++ b/compiler/src/commonMain/kotlin/util/Okio.kt @@ -1,4 +1,4 @@ -package me.gabriel.gwydion.compiler.util +package me.gabriel.selene.compiler.util import okio.Path diff --git a/compiler/src/jvmMain/kotlin/JvmCompilerPlatform.kt b/compiler/src/jvmMain/kotlin/JvmCompilerPlatform.kt index 495cb4e..fdea408 100644 --- a/compiler/src/jvmMain/kotlin/JvmCompilerPlatform.kt +++ b/compiler/src/jvmMain/kotlin/JvmCompilerPlatform.kt @@ -1,14 +1,14 @@ -package me.gabriel.gwydion.compiler.jvm +package me.gabriel.selene.compiler.jvm import kotlinx.serialization.json.Json -import me.gabriel.gwydion.compiler.GwydionCompilerPlatform -import me.gabriel.gwydion.compiler.io.IoPlatform -import me.gabriel.gwydion.tools.GwydionLogger +import me.gabriel.selene.compiler.SeleneCompilerPlatform +import me.gabriel.selene.compiler.io.IoPlatform +import me.gabriel.selene.tools.SeleneLogger import okio.FileSystem class JvmCompilerPlatform( - override val logger: GwydionLogger -): GwydionCompilerPlatform { + override val logger: SeleneLogger +): SeleneCompilerPlatform { override val io: IoPlatform = Io override fun exitProcess(status: Int): Nothing { diff --git a/compiler/src/jvmMain/kotlin/JvmLauncher.kt b/compiler/src/jvmMain/kotlin/JvmLauncher.kt index 5de9162..451815f 100644 --- a/compiler/src/jvmMain/kotlin/JvmLauncher.kt +++ b/compiler/src/jvmMain/kotlin/JvmLauncher.kt @@ -1,14 +1,14 @@ -package me.gabriel.gwydion.compiler.jvm +package me.gabriel.selene.compiler.jvm -import me.gabriel.gwydion.compiler.GwydionCompiler -import me.gabriel.gwydion.compiler.cli.CommandLine -import me.gabriel.gwydion.compiler.log.MordantLogger +import me.gabriel.selene.compiler.SeleneCompiler +import me.gabriel.selene.compiler.cli.CommandLine +import me.gabriel.selene.compiler.log.MordantLogger fun main(args: Array) { val platform = JvmCompilerPlatform( logger = MordantLogger() ) - val compiler = GwydionCompiler( + val compiler = SeleneCompiler( platform = platform, cli = CommandLine(args) ) diff --git a/compiler/src/nativeMain/kotlin/NativeCompilerPlatform.kt b/compiler/src/nativeMain/kotlin/NativeCompilerPlatform.kt index 0c71c8d..76b39ce 100644 --- a/compiler/src/nativeMain/kotlin/NativeCompilerPlatform.kt +++ b/compiler/src/nativeMain/kotlin/NativeCompilerPlatform.kt @@ -1,12 +1,12 @@ import kotlinx.serialization.json.Json -import me.gabriel.gwydion.compiler.GwydionCompilerPlatform -import me.gabriel.gwydion.compiler.io.IoPlatform -import me.gabriel.gwydion.tools.GwydionLogger +import me.gabriel.selene.compiler.SeleneCompilerPlatform +import me.gabriel.selene.compiler.io.IoPlatform +import me.gabriel.selene.tools.SeleneLogger import okio.FileSystem class NativeCompilerPlatform( - override val logger: GwydionLogger, -): GwydionCompilerPlatform { + override val logger: SeleneLogger, +): SeleneCompilerPlatform { override val io: IoPlatform = Io override fun exitProcess(status: Int): Nothing { diff --git a/compiler/src/nativeMain/kotlin/NativeLauncher.kt b/compiler/src/nativeMain/kotlin/NativeLauncher.kt index 19b70ee..6839507 100644 --- a/compiler/src/nativeMain/kotlin/NativeLauncher.kt +++ b/compiler/src/nativeMain/kotlin/NativeLauncher.kt @@ -1,12 +1,12 @@ -import me.gabriel.gwydion.compiler.GwydionCompiler -import me.gabriel.gwydion.compiler.cli.CommandLine -import me.gabriel.gwydion.compiler.log.MordantLogger +import me.gabriel.selene.compiler.SeleneCompiler +import me.gabriel.selene.compiler.cli.CommandLine +import me.gabriel.selene.compiler.log.MordantLogger fun main(args: Array) { val platform = NativeCompilerPlatform( logger = MordantLogger() ) - val compiler = GwydionCompiler( + val compiler = SeleneCompiler( platform = platform, cli = CommandLine(args) ) diff --git a/frontend/src/commonMain/kotlin/Types.kt b/frontend/src/commonMain/kotlin/Types.kt index 1a9d66b..92b9182 100644 --- a/frontend/src/commonMain/kotlin/Types.kt +++ b/frontend/src/commonMain/kotlin/Types.kt @@ -1,11 +1,11 @@ -package me.gabriel.gwydion.frontend +package me.gabriel.selene.frontend import kotlinx.serialization.Serializable -import me.gabriel.gwydion.frontend.lexing.Token -import me.gabriel.gwydion.frontend.lexing.TokenKind +import me.gabriel.selene.frontend.lexing.Token +import me.gabriel.selene.frontend.lexing.TokenKind @Serializable -sealed class GwydionType( +sealed class SeleneType( val id: kotlin.String, val signature: kotlin.String ) { @@ -14,124 +14,124 @@ sealed class GwydionType( // Replacing `data object` with `object` to avoid Kotlin/Native issues @Serializable - object Any : GwydionType("any") + object Any : SeleneType("any") @Serializable - object Int8 : GwydionType("int8") + object Int8 : SeleneType("int8") @Serializable - object Int16 : GwydionType("int16") + object Int16 : SeleneType("int16") @Serializable - object Int32 : GwydionType("int32") + object Int32 : SeleneType("int32") @Serializable - object Int64 : GwydionType("int64") + object Int64 : SeleneType("int64") @Serializable - object UInt8 : GwydionType("uint8") + object UInt8 : SeleneType("uint8") @Serializable - object UInt16 : GwydionType("uint16") + object UInt16 : SeleneType("uint16") @Serializable - object UInt32 : GwydionType("uint32") + object UInt32 : SeleneType("uint32") @Serializable - object UInt64 : GwydionType("uint64") + object UInt64 : SeleneType("uint64") @Serializable - object Float32 : GwydionType("float32") + object Float32 : SeleneType("float32") @Serializable - object Float64 : GwydionType("float64") + object Float64 : SeleneType("float64") @Serializable - object String : GwydionType("string") + object String : SeleneType("string") @Serializable - object Self: GwydionType("self") + object Self: SeleneType("self") @Serializable - object Void : GwydionType("void") + object Void : SeleneType("void") @Serializable - object Boolean : GwydionType("bool") + object Boolean : SeleneType("bool") @Serializable - object Unknown : GwydionType("unknown") // Marking this as @Serializable + object Unknown : SeleneType("unknown") // Marking this as @Serializable @Serializable - data class UnknownReference(val reference: kotlin.String, val mutable: kotlin.Boolean): GwydionType("unknown", reference) + data class UnknownReference(val reference: kotlin.String, val mutable: kotlin.Boolean): SeleneType("unknown", reference) @Serializable data class DynamicArray( - val baseType: GwydionType, - ): GwydionType("fixed array", "${baseType.signature}[]") + val baseType: SeleneType, + ): SeleneType("fixed array", "${baseType.signature}[]") @Serializable data class FixedArray( - val baseType: GwydionType, + val baseType: SeleneType, val length: Int - ): GwydionType("fixed array", "${baseType.signature}[$length]") + ): SeleneType("fixed array", "${baseType.signature}[$length]") @Serializable data class Struct( val identifier: kotlin.String, - val fields: Map - ): GwydionType("struct", identifier) + val fields: Map + ): SeleneType("struct", identifier) @Serializable data class Trait( val identifier: kotlin.String, val functions: List - ): GwydionType("trait", identifier) + ): SeleneType("trait", identifier) @Serializable data class VirtualFunction( val name: kotlin.String, - val returnType: GwydionType, - val parameters: List + val returnType: SeleneType, + val parameters: List ) @Serializable data class Mutable( - val baseType: GwydionType - ): GwydionType("mutate", "mut ${baseType.signature}") { - override val base: GwydionType + val baseType: SeleneType + ): SeleneType("mutate", "mut ${baseType.signature}") { + override val base: SeleneType get() = baseType } @Serializable data class Lambda( - val parameters: List, - val returnType: GwydionType - ): GwydionType("lambda", "(${parameters.joinToString(", ") { it.signature }}) -> ${returnType.signature}") + val parameters: List, + val returnType: SeleneType + ): SeleneType("lambda", "(${parameters.joinToString(", ") { it.signature }}) -> ${returnType.signature}") - open val base: GwydionType + open val base: SeleneType get() = this override fun toString(): kotlin.String = id } fun tokenKindToType(token: Token, mutable: Boolean) = when (token.kind) { - TokenKind.ANY_TYPE -> GwydionType.Any - TokenKind.INT8_TYPE -> GwydionType.Int8 - TokenKind.INT16_TYPE -> GwydionType.Int16 - TokenKind.INT32_TYPE -> GwydionType.Int32 - TokenKind.INT64_TYPE -> GwydionType.Int64 - TokenKind.UINT8_TYPE -> GwydionType.UInt8 - TokenKind.UINT16_TYPE -> GwydionType.UInt16 - TokenKind.UINT32_TYPE -> GwydionType.UInt32 - TokenKind.UINT64_TYPE -> GwydionType.UInt64 - TokenKind.FLOAT32_TYPE -> GwydionType.Float32 - TokenKind.FLOAT64_TYPE -> GwydionType.Float64 - TokenKind.STRING_TYPE -> GwydionType.String - TokenKind.BOOL_TYPE -> GwydionType.Boolean - TokenKind.IDENTIFIER -> GwydionType.UnknownReference(token.value, mutable) + TokenKind.ANY_TYPE -> SeleneType.Any + TokenKind.INT8_TYPE -> SeleneType.Int8 + TokenKind.INT16_TYPE -> SeleneType.Int16 + TokenKind.INT32_TYPE -> SeleneType.Int32 + TokenKind.INT64_TYPE -> SeleneType.Int64 + TokenKind.UINT8_TYPE -> SeleneType.UInt8 + TokenKind.UINT16_TYPE -> SeleneType.UInt16 + TokenKind.UINT32_TYPE -> SeleneType.UInt32 + TokenKind.UINT64_TYPE -> SeleneType.UInt64 + TokenKind.FLOAT32_TYPE -> SeleneType.Float32 + TokenKind.FLOAT64_TYPE -> SeleneType.Float64 + TokenKind.STRING_TYPE -> SeleneType.String + TokenKind.BOOL_TYPE -> SeleneType.Boolean + TokenKind.IDENTIFIER -> SeleneType.UnknownReference(token.value, mutable) else -> error("Unknown token kind ${token.kind}") } -fun GwydionType.isNumeric(): Boolean = when (this) { - is GwydionType.Int8, is GwydionType.Int16, is GwydionType.Int32, is GwydionType.Int64, - is GwydionType.UInt8, is GwydionType.UInt16, is GwydionType.UInt32, is GwydionType.UInt64, - is GwydionType.Float32, is GwydionType.Float64 -> true +fun SeleneType.isNumeric(): Boolean = when (this) { + is SeleneType.Int8, is SeleneType.Int16, is SeleneType.Int32, is SeleneType.Int64, + is SeleneType.UInt8, is SeleneType.UInt16, is SeleneType.UInt32, is SeleneType.UInt64, + is SeleneType.Float32, is SeleneType.Float64 -> true else -> false } -fun GwydionType.workingBase(): GwydionType = when (this) { - is GwydionType.Mutable -> base.workingBase() +fun SeleneType.workingBase(): SeleneType = when (this) { + is SeleneType.Mutable -> base.workingBase() else -> this } -fun GwydionType.mapBase(mapper: (GwydionType) -> GwydionType): GwydionType = when (this) { - is GwydionType.Mutable -> GwydionType.Mutable(base.mapBase(mapper)) - is GwydionType.DynamicArray -> GwydionType.DynamicArray(baseType.mapBase(mapper)) - is GwydionType.FixedArray -> GwydionType.FixedArray(baseType.mapBase(mapper), length) +fun SeleneType.mapBase(mapper: (SeleneType) -> SeleneType): SeleneType = when (this) { + is SeleneType.Mutable -> SeleneType.Mutable(base.mapBase(mapper)) + is SeleneType.DynamicArray -> SeleneType.DynamicArray(baseType.mapBase(mapper)) + is SeleneType.FixedArray -> SeleneType.FixedArray(baseType.mapBase(mapper), length) else -> mapper(this) } diff --git a/frontend/src/commonMain/kotlin/lexing/Token.kt b/frontend/src/commonMain/kotlin/lexing/Token.kt index 6cbca8c..ce26816 100644 --- a/frontend/src/commonMain/kotlin/lexing/Token.kt +++ b/frontend/src/commonMain/kotlin/lexing/Token.kt @@ -1,7 +1,7 @@ -package me.gabriel.gwydion.frontend.lexing +package me.gabriel.selene.frontend.lexing import kotlinx.serialization.Serializable -import me.gabriel.gwydion.frontend.parsing.Modifiers +import me.gabriel.selene.frontend.parsing.Modifiers @Serializable enum class TokenKind { diff --git a/frontend/src/commonMain/kotlin/lexing/TokenStream.kt b/frontend/src/commonMain/kotlin/lexing/TokenStream.kt index 33db7cf..f400a98 100644 --- a/frontend/src/commonMain/kotlin/lexing/TokenStream.kt +++ b/frontend/src/commonMain/kotlin/lexing/TokenStream.kt @@ -1,4 +1,4 @@ -package me.gabriel.gwydion.frontend.lexing +package me.gabriel.selene.frontend.lexing class TokenStream(private val tokens: List) : Iterator by tokens.iterator() { fun count(): Int = tokens.size diff --git a/frontend/src/commonMain/kotlin/lexing/error/Lexing.kt b/frontend/src/commonMain/kotlin/lexing/error/Lexing.kt index 68c7a52..1b1d8e2 100644 --- a/frontend/src/commonMain/kotlin/lexing/error/Lexing.kt +++ b/frontend/src/commonMain/kotlin/lexing/error/Lexing.kt @@ -1,4 +1,4 @@ -package me.gabriel.gwydion.frontend.lexing.error +package me.gabriel.selene.frontend.lexing.error // I won't use exceptions because they generate too much overhead by default, and I'm not going to use them for control flow. sealed class LexingError(val message: String, val position: Int) { diff --git a/frontend/src/commonMain/kotlin/lexing/error/Parsing.kt b/frontend/src/commonMain/kotlin/lexing/error/Parsing.kt index e180f26..c9b754b 100644 --- a/frontend/src/commonMain/kotlin/lexing/error/Parsing.kt +++ b/frontend/src/commonMain/kotlin/lexing/error/Parsing.kt @@ -1,7 +1,7 @@ -package me.gabriel.gwydion.frontend.lexing.error +package me.gabriel.selene.frontend.lexing.error -import me.gabriel.gwydion.frontend.lexing.Token -import me.gabriel.gwydion.frontend.lexing.TokenKind +import me.gabriel.selene.frontend.lexing.Token +import me.gabriel.selene.frontend.lexing.TokenKind sealed class ParsingError(val message: String, val token: Token) { class UnexpectedToken(token: Token) : ParsingError("unexpected token: ${token.kind}", token) diff --git a/frontend/src/commonMain/kotlin/lexing/lexers/Lexer.kt b/frontend/src/commonMain/kotlin/lexing/lexers/Lexer.kt index 50129b6..0b5a358 100644 --- a/frontend/src/commonMain/kotlin/lexing/lexers/Lexer.kt +++ b/frontend/src/commonMain/kotlin/lexing/lexers/Lexer.kt @@ -1,8 +1,8 @@ -package me.gabriel.gwydion.frontend.lexing.lexers +package me.gabriel.selene.frontend.lexing.lexers -import me.gabriel.gwydion.frontend.lexing.TokenStream -import me.gabriel.gwydion.frontend.lexing.error.LexingError -import me.gabriel.gwydion.tools.Either +import me.gabriel.selene.frontend.lexing.TokenStream +import me.gabriel.selene.frontend.lexing.error.LexingError +import me.gabriel.selene.tools.Either interface Lexer { fun tokenize(): Either diff --git a/frontend/src/commonMain/kotlin/lexing/lexers/StringLexer.kt b/frontend/src/commonMain/kotlin/lexing/lexers/StringLexer.kt index ce72c7c..ef55137 100644 --- a/frontend/src/commonMain/kotlin/lexing/lexers/StringLexer.kt +++ b/frontend/src/commonMain/kotlin/lexing/lexers/StringLexer.kt @@ -1,10 +1,10 @@ -package me.gabriel.gwydion.frontend.lexing.lexers +package me.gabriel.selene.frontend.lexing.lexers -import me.gabriel.gwydion.frontend.lexing.Token -import me.gabriel.gwydion.frontend.lexing.TokenKind -import me.gabriel.gwydion.frontend.lexing.TokenStream -import me.gabriel.gwydion.frontend.lexing.error.LexingError -import me.gabriel.gwydion.tools.Either +import me.gabriel.selene.frontend.lexing.Token +import me.gabriel.selene.frontend.lexing.TokenKind +import me.gabriel.selene.frontend.lexing.TokenStream +import me.gabriel.selene.frontend.lexing.error.LexingError +import me.gabriel.selene.tools.Either class StringLexer(private val data: String): Lexer { private var position = 0 @@ -27,7 +27,7 @@ class StringLexer(private val data: String): Lexer { '"' -> return Either.left(lexString(tokens) ?: continue) in '0'..'9' -> tokens.add(number()) in 'a'..'z', in 'A'..'Z', '_' -> { - val identifier = identifier(token.toString()) + val identifier = identifier() if (identifier.isLeft()) { return Either.Left(identifier.getLeft()) } @@ -104,7 +104,7 @@ class StringLexer(private val data: String): Lexer { return Token(TokenKind.NUMBER, data.substring(start, position), position) } - fun identifier(value: String): Either { + fun identifier(): Either { val start = position while (position < data.length && (data[position].isLetterOrDigit() || data[position] == '_')) { position++ diff --git a/frontend/src/commonMain/kotlin/parsing/Modifiers.kt b/frontend/src/commonMain/kotlin/parsing/Modifiers.kt index 4bd2df7..ad3c505 100644 --- a/frontend/src/commonMain/kotlin/parsing/Modifiers.kt +++ b/frontend/src/commonMain/kotlin/parsing/Modifiers.kt @@ -1,4 +1,4 @@ -package me.gabriel.gwydion.frontend.parsing +package me.gabriel.selene.frontend.parsing import kotlinx.serialization.Serializable diff --git a/frontend/src/commonMain/kotlin/parsing/Parser.kt b/frontend/src/commonMain/kotlin/parsing/Parser.kt index b22b064..4c133fc 100644 --- a/frontend/src/commonMain/kotlin/parsing/Parser.kt +++ b/frontend/src/commonMain/kotlin/parsing/Parser.kt @@ -1,9 +1,9 @@ -package me.gabriel.gwydion.frontend.parsing +package me.gabriel.selene.frontend.parsing -import me.gabriel.gwydion.frontend.GwydionType -import me.gabriel.gwydion.frontend.lexing.* -import me.gabriel.gwydion.frontend.lexing.error.ParsingError -import me.gabriel.gwydion.tools.Either +import me.gabriel.selene.frontend.SeleneType +import me.gabriel.selene.frontend.lexing.* +import me.gabriel.selene.frontend.lexing.error.ParsingError +import me.gabriel.selene.tools.Either class Parser(private val tokens: TokenStream) { private var currentPosition: Int = 0 @@ -215,7 +215,7 @@ class Parser(private val tokens: TokenStream) { consumeToken(TokenKind.DECLARATION).flatMapRight { parseExpression().flatMapRight { expr -> consumeToken(TokenKind.SEMICOLON).mapRight { - AssignmentNode(name.value, expr, true, GwydionType.Unknown, mutToken) + AssignmentNode(name.value, expr, true, SeleneType.Unknown, mutToken) } } } @@ -291,7 +291,7 @@ class Parser(private val tokens: TokenStream) { if (declaration is Either.Left) return Either.Left(declaration.value) return parseExpression().flatMapRight { expr -> consumeToken(TokenKind.SEMICOLON).mapRight { - AssignmentNode(name, expr, false, GwydionType.Unknown, declaration.unwrap()) + AssignmentNode(name, expr, false, SeleneType.Unknown, declaration.unwrap()) } } } @@ -491,7 +491,7 @@ class Parser(private val tokens: TokenStream) { val number = consumeToken(TokenKind.NUMBER) if (number is Either.Left) return Either.Left(number.value) val token = number.unwrap() - return Either.Right(NumberNode(token.value, false, GwydionType.Int32, token)) + return Either.Right(NumberNode(token.value, false, SeleneType.Int32, token)) } private fun parseStringExpression(): Either { @@ -556,19 +556,19 @@ class Parser(private val tokens: TokenStream) { LambdaParameterNode(name.value, type, name) } } else { - Either.Right(LambdaParameterNode(name.value, GwydionType.Unknown, name)) + Either.Right(LambdaParameterNode(name.value, SeleneType.Unknown, name)) } } } - private fun parseType(): Either { + private fun parseType(): Either { if (peekToken().kind == TokenKind.LAMBDA) { consumeToken() return consumeToken(TokenKind.OPENING_PARENTHESES).flatMapRight { parseCommaSeparatedList(::parseType, TokenKind.CLOSING_PARENTHESES).flatMapRight { params -> consumeToken(TokenKind.LAMBDA_RETURN).flatMapRight { parseType().mapRight { returnType -> - GwydionType.Lambda(params, returnType) + SeleneType.Lambda(params, returnType) } } } @@ -581,11 +581,11 @@ class Parser(private val tokens: TokenStream) { return if (peekToken().kind == TokenKind.OPENING_BRACKETS) { parseArrayType(baseType, isMutable) } else { - Either.Right(if (isMutable) GwydionType.Mutable(baseType) else baseType) + Either.Right(if (isMutable) SeleneType.Mutable(baseType) else baseType) } } - private fun parseBaseType(): GwydionType? { + private fun parseBaseType(): SeleneType? { val token = peekToken() return if (token.kind in TYPE_TOKENS) { consumeToken() @@ -595,20 +595,20 @@ class Parser(private val tokens: TokenStream) { } } - private fun parseArrayType(baseType: GwydionType, isMutable: Boolean): Either { + private fun parseArrayType(baseType: SeleneType, isMutable: Boolean): Either { consumeToken() // Consume opening bracket return when (peekToken().kind) { TokenKind.NUMBER -> { val size = consumeToken().value.toInt() consumeToken(TokenKind.CLOSING_BRACKETS).mapRight { - if (isMutable) GwydionType.Mutable(GwydionType.FixedArray(baseType, size)) else GwydionType.FixedArray(baseType, size) + if (isMutable) SeleneType.Mutable(SeleneType.FixedArray(baseType, size)) else SeleneType.FixedArray(baseType, size) } } TokenKind.TIMES -> { consumeToken() consumeToken(TokenKind.CLOSING_BRACKETS).mapRight { - if (isMutable) GwydionType.Mutable(GwydionType.DynamicArray(baseType)) else GwydionType.DynamicArray(baseType) + if (isMutable) SeleneType.Mutable(SeleneType.DynamicArray(baseType)) else SeleneType.DynamicArray(baseType) } } @@ -626,13 +626,13 @@ class Parser(private val tokens: TokenStream) { return when { peekToken().kind == TokenKind.SELF -> { val token = consumeToken() - Either.Right(ParameterNode("self", GwydionType.Self, token)) + Either.Right(ParameterNode("self", SeleneType.Self, token)) } peekToken().kind == TokenKind.MUT && peekNextToken().kind == TokenKind.SELF -> { consumeToken() // Consume MUT val token = consumeToken() // Consume SELF - Either.Right(ParameterNode("self", GwydionType.Mutable(GwydionType.Self), token)) + Either.Right(ParameterNode("self", SeleneType.Mutable(SeleneType.Self), token)) } else -> parseIdentifier().flatMapRight { name -> @@ -651,12 +651,12 @@ class Parser(private val tokens: TokenStream) { } } - private fun parseReturnType(): Either { + private fun parseReturnType(): Either { return if (peekToken().kind == TokenKind.RETURN_TYPE_DECLARATION) { consumeToken() parseType() } else { - Either.Right(GwydionType.Void) + Either.Right(SeleneType.Void) } } @@ -726,26 +726,26 @@ class Parser(private val tokens: TokenStream) { } } - private fun tokenKindToType(token: Token, mutable: Boolean): GwydionType { + private fun tokenKindToType(token: Token, mutable: Boolean): SeleneType { val base = when (token.kind) { - TokenKind.ANY_TYPE -> GwydionType.Any - TokenKind.VOID -> return GwydionType.Void - TokenKind.INT8_TYPE -> GwydionType.Int8 - TokenKind.INT16_TYPE -> GwydionType.Int16 - TokenKind.INT32_TYPE -> GwydionType.Int32 - TokenKind.INT64_TYPE -> GwydionType.Int64 - TokenKind.UINT8_TYPE -> GwydionType.UInt8 - TokenKind.UINT16_TYPE -> GwydionType.UInt16 - TokenKind.UINT32_TYPE -> GwydionType.UInt32 - TokenKind.UINT64_TYPE -> GwydionType.UInt64 - TokenKind.FLOAT32_TYPE -> GwydionType.Float32 - TokenKind.FLOAT64_TYPE -> GwydionType.Float64 - TokenKind.BOOL_TYPE -> GwydionType.Boolean - TokenKind.STRING_TYPE -> GwydionType.String - TokenKind.IDENTIFIER -> GwydionType.UnknownReference(token.value, mutable) + TokenKind.ANY_TYPE -> SeleneType.Any + TokenKind.VOID -> return SeleneType.Void + TokenKind.INT8_TYPE -> SeleneType.Int8 + TokenKind.INT16_TYPE -> SeleneType.Int16 + TokenKind.INT32_TYPE -> SeleneType.Int32 + TokenKind.INT64_TYPE -> SeleneType.Int64 + TokenKind.UINT8_TYPE -> SeleneType.UInt8 + TokenKind.UINT16_TYPE -> SeleneType.UInt16 + TokenKind.UINT32_TYPE -> SeleneType.UInt32 + TokenKind.UINT64_TYPE -> SeleneType.UInt64 + TokenKind.FLOAT32_TYPE -> SeleneType.Float32 + TokenKind.FLOAT64_TYPE -> SeleneType.Float64 + TokenKind.BOOL_TYPE -> SeleneType.Boolean + TokenKind.STRING_TYPE -> SeleneType.String + TokenKind.IDENTIFIER -> SeleneType.UnknownReference(token.value, mutable) else -> throw IllegalArgumentException("Unexpected token kind for type: ${token.kind}") } - return if (mutable) GwydionType.Mutable(base) else base + return if (mutable) SeleneType.Mutable(base) else base } companion object { diff --git a/frontend/src/commonMain/kotlin/parsing/SyntaxTree.kt b/frontend/src/commonMain/kotlin/parsing/SyntaxTree.kt index e1a460e..3d6ce62 100644 --- a/frontend/src/commonMain/kotlin/parsing/SyntaxTree.kt +++ b/frontend/src/commonMain/kotlin/parsing/SyntaxTree.kt @@ -1,8 +1,8 @@ -package me.gabriel.gwydion.frontend.parsing +package me.gabriel.selene.frontend.parsing -import me.gabriel.gwydion.frontend.GwydionType -import me.gabriel.gwydion.frontend.lexing.Token -import me.gabriel.gwydion.frontend.lexing.TokenKind +import me.gabriel.selene.frontend.SeleneType +import me.gabriel.selene.frontend.lexing.Token +import me.gabriel.selene.frontend.lexing.TokenKind data class SyntaxTree(val root: RootNode = RootNode(mutableListOf())) { fun addAllNodes(nodes: List) { @@ -14,7 +14,7 @@ sealed class SyntaxTreeNode(val mark: Token) { abstract fun getChildren(): List } -sealed class TypedSyntaxTreeNode(open var type: GwydionType, mark: Token) : SyntaxTreeNode(mark) +sealed class TypedSyntaxTreeNode(open var type: SeleneType, mark: Token) : SyntaxTreeNode(mark) class RootNode(private val children: MutableList) : SyntaxTreeNode(Token(TokenKind.BOF, "", 0)) { fun addNode(node: SyntaxTreeNode) { @@ -32,7 +32,7 @@ class RootNode(private val children: MutableList) : SyntaxTreeNo class FunctionNode( val name: String, - var returnType: GwydionType, + var returnType: SeleneType, val parameters: List, val body: BlockNode, val modifiers: MutableList, @@ -52,7 +52,7 @@ class BlockNode( class ParameterNode( val name: String, - type: GwydionType, + type: SeleneType, mark: Token ) : TypedSyntaxTreeNode(type, mark) { override fun getChildren(): List = emptyList() @@ -64,7 +64,7 @@ class AssignmentNode( val name: String, val expression: SyntaxTreeNode, val mutable: Boolean, - type: GwydionType, + type: SeleneType, mark: Token ) : TypedSyntaxTreeNode(type, mark) { override fun getChildren(): List = listOf(expression) @@ -135,7 +135,7 @@ class DataStructureReferenceNode( class NumberNode( var value: String, val explicit: Boolean, - override var type: GwydionType, + override var type: SeleneType, mark: Token ) : TypedSyntaxTreeNode(type, mark) { override fun getChildren(): List = emptyList() @@ -147,7 +147,7 @@ class StringNode( val value: String, val segments: List, mark: Token -) : TypedSyntaxTreeNode(GwydionType.String, mark) { +) : TypedSyntaxTreeNode(SeleneType.String, mark) { override fun getChildren(): List = emptyList() sealed class Segment { @@ -162,7 +162,7 @@ class StringNode( class BooleanNode( val value: Boolean, mark: Token -) : TypedSyntaxTreeNode(GwydionType.Boolean, mark) { +) : TypedSyntaxTreeNode(SeleneType.Boolean, mark) { override fun getChildren(): List = emptyList() override fun toString(): String = "BooleanNode(value=$value)" @@ -222,7 +222,7 @@ class DataStructureNode( class DataFieldNode( val name: String, - var type: GwydionType, + var type: SeleneType, mark: Token ) : SyntaxTreeNode(mark) { override fun getChildren(): List = listOf() @@ -242,7 +242,7 @@ class TraitNode( class TraitFunctionNode( val name: String, - var returnType: GwydionType, + var returnType: SeleneType, val parameters: List, mark: Token ) : SyntaxTreeNode(mark) { @@ -252,7 +252,7 @@ class TraitFunctionNode( } class TraitImplNode( - var type: GwydionType, + var type: SeleneType, val trait: String, val functions: List, mark: Token @@ -338,7 +338,7 @@ class LambdaNode( class LambdaParameterNode( val name: String, - val type: GwydionType, + val type: SeleneType, mark: Token ) : SyntaxTreeNode(mark) { override fun getChildren(): List = emptyList() diff --git a/ir/src/commonMain/kotlin/LLVMCodeAdaptationProcess.kt b/ir/src/commonMain/kotlin/LLVMCodeAdaptationProcess.kt index 019edce..5face03 100644 --- a/ir/src/commonMain/kotlin/LLVMCodeAdaptationProcess.kt +++ b/ir/src/commonMain/kotlin/LLVMCodeAdaptationProcess.kt @@ -1,17 +1,17 @@ -package me.gabriel.gwydion.ir - -import me.gabriel.gwydion.analysis.SymbolBlock -import me.gabriel.gwydion.analysis.signature.SignatureTraitImpl -import me.gabriel.gwydion.analysis.signature.Signatures -import me.gabriel.gwydion.analysis.util.castToType -import me.gabriel.gwydion.analysis.util.resolveTraitForExpression -import me.gabriel.gwydion.frontend.GwydionType -import me.gabriel.gwydion.frontend.lexing.TokenKind -import me.gabriel.gwydion.frontend.parsing.* -import me.gabriel.gwydion.ir.intrinsics.IntrinsicFunction -import me.gabriel.gwydion.llvm.LLVMCodeAssembler -import me.gabriel.gwydion.llvm.LLVMCodeGenerator -import me.gabriel.gwydion.llvm.struct.* +package me.gabriel.selene.ir + +import me.gabriel.selene.analysis.SymbolBlock +import me.gabriel.selene.analysis.signature.SignatureTraitImpl +import me.gabriel.selene.analysis.signature.Signatures +import me.gabriel.selene.analysis.util.castToType +import me.gabriel.selene.analysis.util.resolveTraitForExpression +import me.gabriel.selene.frontend.SeleneType +import me.gabriel.selene.frontend.lexing.TokenKind +import me.gabriel.selene.frontend.parsing.* +import me.gabriel.selene.ir.intrinsics.IntrinsicFunction +import me.gabriel.selene.llvm.LLVMCodeAssembler +import me.gabriel.selene.llvm.LLVMCodeGenerator +import me.gabriel.selene.llvm.struct.* /* * I decided to use exceptions instead of errors because the exceptions should be caught in @@ -88,7 +88,7 @@ class LLVMCodeAdaptationProcess( block: SymbolBlock, node: SyntaxTreeNode, store: Boolean = false, - self: GwydionType? = null + self: SeleneType? = null ): Value = when (node) { is RootNode, is BlockNode -> blockAdaptChildren(block, node) is FunctionNode -> generateFunction(block, node, self) @@ -122,14 +122,14 @@ class LLVMCodeAdaptationProcess( return NullMemoryUnit } - private fun generateFunction(block: SymbolBlock, node: FunctionNode, self: GwydionType?): NullMemoryUnit { + private fun generateFunction(block: SymbolBlock, node: FunctionNode, self: SeleneType?): NullMemoryUnit { if (node.modifiers.contains(Modifiers.INTRINSIC)) return NullMemoryUnit val parameters = mutableListOf() val block = block.surfaceSearchChild(node) ?: error("Block ${node.name} not found in block ${block.name}") node.parameters.forEach { param -> - if (param.type is GwydionType.Trait) { + if (param.type is SeleneType.Trait) { val vtable = MemoryUnit.Unsized( register = assembler.nextRegister(), type = LLVMType.Ptr @@ -143,7 +143,7 @@ class LLVMCodeAdaptationProcess( data = data, type = LLVMType.Trait( name = node.name, - functions = (param.type as GwydionType.Trait).functions.size + functions = (param.type as SeleneType.Trait).functions.size ) ) putMemoryUnit(block, param.name, trait) @@ -152,7 +152,7 @@ class LLVMCodeAdaptationProcess( parameters.add(data) return@forEach } - val type = if (param.type.base !is GwydionType.Self) getProperReturnType(param.type) else self?.asLLVM()?.let { LLVMType.Pointer(it) } ?: error("Self type not found") + val type = if (param.type.base !is SeleneType.Self) getProperReturnType(param.type) else self?.asLLVM()?.let { LLVMType.Pointer(it) } ?: error("Self type not found") val unit = MemoryUnit.Sized( register = assembler.nextRegister(), @@ -173,7 +173,7 @@ class LLVMCodeAdaptationProcess( returnType = properReturnType ) { acceptNode(block, node.body) - if (node.returnType == GwydionType.Void) { + if (node.returnType == SeleneType.Void) { assembler.returnVoid() } } @@ -187,7 +187,7 @@ class LLVMCodeAdaptationProcess( store: Boolean ): Value { val potentialLambda = block.resolveSymbol(node.name) - if (potentialLambda != null && potentialLambda is GwydionType.Lambda) { + if (potentialLambda != null && potentialLambda is SeleneType.Lambda) { val parameters = mutableListOf() node.arguments.forEachIndexed { index, arg -> val result = acceptNode(block, arg) @@ -228,16 +228,16 @@ class LLVMCodeAdaptationProcess( } val functionTypeEquivalent = expectedParameters[index] - if (result is MemoryUnit.TraitData && functionTypeEquivalent is GwydionType.Trait) { + if (result is MemoryUnit.TraitData && functionTypeEquivalent is SeleneType.Trait) { arguments.add(result.vtable) arguments.add(result.loadedData ?: error("TraitData was not loaded")) - } else if (functionTypeEquivalent is GwydionType.Trait) { + } else if (functionTypeEquivalent is SeleneType.Trait) { val trait = signatures.traits.firstOrNull { it.name == functionTypeEquivalent.identifier } ?: error("Trait ${functionTypeEquivalent.identifier} not found in signatures") val type = block.resolveExpression(arg) - if (type == null || type is GwydionType.Trait) error("TraitData was not generated from a trait") + if (type == null || type is SeleneType.Trait) error("TraitData was not generated from a trait") val impl = trait.impls.firstOrNull { it.struct == type.signature @@ -365,7 +365,7 @@ class LLVMCodeAdaptationProcess( ?: error("Couldn't resolve binary operation type at ${block.name} for ${node.left}") val op = getBinaryOp(node.operator.kind) - if (type == GwydionType.String) { + if (type == SeleneType.String) { val left = acceptNode(block, node.left) as MemoryUnit.Sized val right = acceptNode(block, node.right) as MemoryUnit.Sized val resultString = assembler.allocateHeapMemory( @@ -639,9 +639,9 @@ class LLVMCodeAdaptationProcess( } else NullMemoryUnit val arguments = mutableListOf() - if (!(node.static || !function.parameters.contains(GwydionType.Self))) { + if (!(node.static || !function.parameters.contains(SeleneType.Self))) { val variableMemory = acceptNode(block, node.trait) - if (variableType !is GwydionType.Trait) { + if (variableType !is SeleneType.Trait) { arguments.add(0, variableMemory) } else { val traitMemory = variableMemory as? MemoryUnit.TraitData ?: error("Trait memory not found") @@ -665,7 +665,7 @@ class LLVMCodeAdaptationProcess( } private fun generateFor(block: SymbolBlock, node: ForNode): NullMemoryUnit { - val type = GwydionType.Int32 + val type = SeleneType.Int32 val llvmType = type.asLLVM() val allocation = assembler.allocateStackMemory( type = llvmType, @@ -743,7 +743,7 @@ class LLVMCodeAdaptationProcess( putMemoryUnit(lambdaBlock, param.name, unit) parameters.add(unit) } - val returnType = (block.resolveExpression(node) as? GwydionType.Lambda)?.returnType + val returnType = (block.resolveExpression(node) as? SeleneType.Lambda)?.returnType ?: error("Return type not found for lambda $node") lambdas.add( @@ -831,6 +831,6 @@ class LLVMCodeAdaptationProcess( val node: LambdaNode, val parameters: List, val block: SymbolBlock, - val returnType: GwydionType, + val returnType: SeleneType, ) } \ No newline at end of file diff --git a/ir/src/commonMain/kotlin/LLVMCodeAdapter.kt b/ir/src/commonMain/kotlin/LLVMCodeAdapter.kt index be77e54..c2b726f 100644 --- a/ir/src/commonMain/kotlin/LLVMCodeAdapter.kt +++ b/ir/src/commonMain/kotlin/LLVMCodeAdapter.kt @@ -1,9 +1,9 @@ -package me.gabriel.gwydion.ir +package me.gabriel.selene.ir -import me.gabriel.gwydion.analysis.SymbolRepository -import me.gabriel.gwydion.analysis.signature.Signatures -import me.gabriel.gwydion.frontend.parsing.SyntaxTree -import me.gabriel.gwydion.ir.intrinsics.IntrinsicFunction +import me.gabriel.selene.analysis.SymbolRepository +import me.gabriel.selene.analysis.signature.Signatures +import me.gabriel.selene.frontend.parsing.SyntaxTree +import me.gabriel.selene.ir.intrinsics.IntrinsicFunction class LLVMCodeAdapter { private val intrinsics = mutableListOf() diff --git a/ir/src/commonMain/kotlin/TypeConversions.kt b/ir/src/commonMain/kotlin/TypeConversions.kt index 6d81aae..104851b 100644 --- a/ir/src/commonMain/kotlin/TypeConversions.kt +++ b/ir/src/commonMain/kotlin/TypeConversions.kt @@ -1,34 +1,34 @@ -package me.gabriel.gwydion.ir +package me.gabriel.selene.ir -import me.gabriel.gwydion.frontend.GwydionType -import me.gabriel.gwydion.llvm.struct.LLVMType +import me.gabriel.selene.frontend.SeleneType +import me.gabriel.selene.llvm.struct.LLVMType -fun GwydionType.asLLVM(): LLVMType = when (this) { - GwydionType.String -> LLVMType.Pointer(LLVMType.I8) - GwydionType.Void -> LLVMType.Void - GwydionType.Any -> LLVMType.I32 - GwydionType.Int8 -> LLVMType.I8 - GwydionType.Int16 -> LLVMType.I16 - GwydionType.Int32 -> LLVMType.I32 - GwydionType.Int64 -> LLVMType.I64 - GwydionType.Float32 -> LLVMType.F32 - GwydionType.Float64 -> LLVMType.F64 - GwydionType.Boolean -> LLVMType.I1 - is GwydionType.FixedArray -> LLVMType.Array( +fun SeleneType.asLLVM(): LLVMType = when (this) { + SeleneType.String -> LLVMType.Pointer(LLVMType.I8) + SeleneType.Void -> LLVMType.Void + SeleneType.Any -> LLVMType.I32 + SeleneType.Int8 -> LLVMType.I8 + SeleneType.Int16 -> LLVMType.I16 + SeleneType.Int32 -> LLVMType.I32 + SeleneType.Int64 -> LLVMType.I64 + SeleneType.Float32 -> LLVMType.F32 + SeleneType.Float64 -> LLVMType.F64 + SeleneType.Boolean -> LLVMType.I1 + is SeleneType.FixedArray -> LLVMType.Array( type = this.baseType.asLLVM(), length = this.length ) - is GwydionType.DynamicArray -> LLVMType.Pointer(this.baseType.asLLVM()) - is GwydionType.Struct -> LLVMType.Struct( + is SeleneType.DynamicArray -> LLVMType.Pointer(this.baseType.asLLVM()) + is SeleneType.Struct -> LLVMType.Struct( name = this.identifier, fields = this.fields.mapValues { getProperReturnType(it.value.asLLVM()) } ) - is GwydionType.Mutable -> this.baseType.asLLVM() - is GwydionType.Lambda -> LLVMType.Ptr + is SeleneType.Mutable -> this.baseType.asLLVM() + is SeleneType.Lambda -> LLVMType.Ptr else -> error("Unsupported LLVM type $this") } -fun getProperReturnType(returnType: GwydionType): LLVMType = +fun getProperReturnType(returnType: SeleneType): LLVMType = getProperReturnType(returnType.asLLVM()) fun getProperReturnType(returnType: LLVMType): LLVMType { diff --git a/ir/src/commonMain/kotlin/intrinsics/Arrays.kt b/ir/src/commonMain/kotlin/intrinsics/Arrays.kt index 3a33ff4..f96608f 100644 --- a/ir/src/commonMain/kotlin/intrinsics/Arrays.kt +++ b/ir/src/commonMain/kotlin/intrinsics/Arrays.kt @@ -1,7 +1,7 @@ -package me.gabriel.gwydion.ir.intrinsics +package me.gabriel.selene.ir.intrinsics -import me.gabriel.gwydion.frontend.GwydionType -import me.gabriel.gwydion.frontend.parsing.CallNode +import me.gabriel.selene.frontend.SeleneType +import me.gabriel.selene.frontend.parsing.CallNode class ArrayLengthFunction: IntrinsicFunction( name = "arraylen", @@ -44,11 +44,11 @@ class ArrayLengthFunction: IntrinsicFunction( ) } - override fun handleCall(call: CallNode, types: Collection, arguments: String): String { + override fun handleCall(call: CallNode, types: Collection, arguments: String): String { val type = types.firstOrNull() return when (type) { - GwydionType.String -> return "call i32 @str_length(${arguments})" - is GwydionType.FixedArray -> "add i32 ${type.length}, 0" + SeleneType.String -> return "call i32 @str_length(${arguments})" + is SeleneType.FixedArray -> "add i32 ${type.length}, 0" else -> error("Invalid type (${type}) for arraylen function") } } diff --git a/ir/src/commonMain/kotlin/intrinsics/Intrinsic.kt b/ir/src/commonMain/kotlin/intrinsics/Intrinsic.kt index 5368869..1d739a2 100644 --- a/ir/src/commonMain/kotlin/intrinsics/Intrinsic.kt +++ b/ir/src/commonMain/kotlin/intrinsics/Intrinsic.kt @@ -1,14 +1,14 @@ -package me.gabriel.gwydion.ir.intrinsics +package me.gabriel.selene.ir.intrinsics -import me.gabriel.gwydion.frontend.GwydionType -import me.gabriel.gwydion.frontend.parsing.CallNode +import me.gabriel.selene.frontend.SeleneType +import me.gabriel.selene.frontend.parsing.CallNode abstract class IntrinsicFunction( val name: String, ) { abstract fun llvmIr(): String - abstract fun handleCall(call: CallNode, types: Collection, arguments: String): String + abstract fun handleCall(call: CallNode, types: Collection, arguments: String): String abstract fun declarations(): List @@ -25,7 +25,7 @@ abstract class IntrinsicMirrorFunction( return "" } - override fun handleCall(call: CallNode, types: Collection, arguments: String): String { + override fun handleCall(call: CallNode, types: Collection, arguments: String): String { return "call $llvmName($arguments)" } @@ -42,6 +42,9 @@ val INTRINSICS = arrayOf( CosFunction(), TanFunction(), AsinFunction(), + AcosFunction(), + AtanFunction(), + Atan2Function(), SqrtFunction(), SocketFunction(), SocketBindFunction(), diff --git a/ir/src/commonMain/kotlin/intrinsics/Math.kt b/ir/src/commonMain/kotlin/intrinsics/Math.kt index 43cb640..cb8c6af 100644 --- a/ir/src/commonMain/kotlin/intrinsics/Math.kt +++ b/ir/src/commonMain/kotlin/intrinsics/Math.kt @@ -1,14 +1,14 @@ -package me.gabriel.gwydion.ir.intrinsics +package me.gabriel.selene.ir.intrinsics -import me.gabriel.gwydion.frontend.GwydionType -import me.gabriel.gwydion.frontend.parsing.CallNode +import me.gabriel.selene.frontend.SeleneType +import me.gabriel.selene.frontend.parsing.CallNode class SinFunction: IntrinsicFunction(name = "sin") { override fun llvmIr(): String { return """""".trimIndent() } - override fun handleCall(call: CallNode, types: Collection, arguments: String): String { + override fun handleCall(call: CallNode, types: Collection, arguments: String): String { return "call double @sin(${arguments})" } @@ -22,7 +22,7 @@ class CosFunction: IntrinsicFunction(name = "cos") { return """""".trimIndent() } - override fun handleCall(call: CallNode, types: Collection, arguments: String): String { + override fun handleCall(call: CallNode, types: Collection, arguments: String): String { return "call double @cos(${arguments})" } @@ -36,7 +36,7 @@ class TanFunction: IntrinsicFunction(name = "tan") { return """""".trimIndent() } - override fun handleCall(call: CallNode, types: Collection, arguments: String): String { + override fun handleCall(call: CallNode, types: Collection, arguments: String): String { return "call double @tan(${arguments})" } @@ -50,7 +50,7 @@ class AsinFunction: IntrinsicFunction(name = "asin") { return """""".trimIndent() } - override fun handleCall(call: CallNode, types: Collection, arguments: String): String { + override fun handleCall(call: CallNode, types: Collection, arguments: String): String { return "call double @asin(double ${arguments})" } @@ -64,7 +64,7 @@ class AcosFunction: IntrinsicFunction(name = "acos") { return """""".trimIndent() } - override fun handleCall(call: CallNode, types: Collection, arguments: String): String { + override fun handleCall(call: CallNode, types: Collection, arguments: String): String { return "call double @acos(${arguments})" } @@ -78,7 +78,7 @@ class AtanFunction: IntrinsicFunction(name = "atan") { return """""".trimIndent() } - override fun handleCall(call: CallNode, types: Collection, arguments: String): String { + override fun handleCall(call: CallNode, types: Collection, arguments: String): String { return "call double @atan(${arguments})" } @@ -92,7 +92,7 @@ class Atan2Function: IntrinsicFunction(name = "atan2") { return """""".trimIndent() } - override fun handleCall(call: CallNode, types: Collection, arguments: String): String { + override fun handleCall(call: CallNode, types: Collection, arguments: String): String { return "call double @atan2(double ${arguments})" } @@ -106,7 +106,7 @@ class SqrtFunction: IntrinsicFunction(name = "sqrt") { return """""".trimIndent() } - override fun handleCall(call: CallNode, types: Collection, arguments: String): String { + override fun handleCall(call: CallNode, types: Collection, arguments: String): String { return "call double @sqrt(double ${arguments})" } diff --git a/ir/src/commonMain/kotlin/intrinsics/Networking.kt b/ir/src/commonMain/kotlin/intrinsics/Networking.kt index f4ab8c3..66998e9 100644 --- a/ir/src/commonMain/kotlin/intrinsics/Networking.kt +++ b/ir/src/commonMain/kotlin/intrinsics/Networking.kt @@ -1,4 +1,4 @@ -package me.gabriel.gwydion.ir.intrinsics +package me.gabriel.selene.ir.intrinsics class SocketFunction : IntrinsicMirrorFunction( name = "socket", diff --git a/ir/src/commonMain/kotlin/intrinsics/Print.kt b/ir/src/commonMain/kotlin/intrinsics/Print.kt index a6768b1..9cf54ee 100644 --- a/ir/src/commonMain/kotlin/intrinsics/Print.kt +++ b/ir/src/commonMain/kotlin/intrinsics/Print.kt @@ -1,7 +1,7 @@ -package me.gabriel.gwydion.ir.intrinsics +package me.gabriel.selene.ir.intrinsics -import me.gabriel.gwydion.frontend.GwydionType -import me.gabriel.gwydion.frontend.parsing.CallNode +import me.gabriel.selene.frontend.SeleneType +import me.gabriel.selene.frontend.parsing.CallNode class PrintlnFunction: IntrinsicFunction( "println", @@ -56,13 +56,13 @@ class PrintlnFunction: IntrinsicFunction( ) } - override fun handleCall(call: CallNode, types: Collection, arguments: String): String { - val type = types.firstOrNull() ?: GwydionType.Unknown + override fun handleCall(call: CallNode, types: Collection, arguments: String): String { + val type = types.firstOrNull() ?: SeleneType.Unknown return when (type) { - GwydionType.String -> "call void @println_str(${arguments})" - GwydionType.Int32 -> "call void @println_i32(${arguments})" - GwydionType.Float64 -> "call void @println_f64(${arguments})" - GwydionType.Boolean -> "call void @println_bool(${arguments})" + SeleneType.String -> "call void @println_str(${arguments})" + SeleneType.Int32 -> "call void @println_i32(${arguments})" + SeleneType.Float64 -> "call void @println_f64(${arguments})" + SeleneType.Boolean -> "call void @println_bool(${arguments})" else -> error("Unsupported type $type for intrinsic $name") } } diff --git a/ir/src/commonMain/kotlin/intrinsics/Readln.kt b/ir/src/commonMain/kotlin/intrinsics/Readln.kt index 4797113..7743ef1 100644 --- a/ir/src/commonMain/kotlin/intrinsics/Readln.kt +++ b/ir/src/commonMain/kotlin/intrinsics/Readln.kt @@ -1,7 +1,7 @@ -package me.gabriel.gwydion.ir.intrinsics +package me.gabriel.selene.ir.intrinsics -import me.gabriel.gwydion.frontend.GwydionType -import me.gabriel.gwydion.frontend.parsing.CallNode +import me.gabriel.selene.frontend.SeleneType +import me.gabriel.selene.frontend.parsing.CallNode class ReadlineFunction: IntrinsicFunction( "readln", @@ -47,7 +47,7 @@ end_read: """.trimIndent() } - override fun handleCall(call: CallNode, types: Collection, arguments: String): String { + override fun handleCall(call: CallNode, types: Collection, arguments: String): String { return "call i8* @readln()" } } \ No newline at end of file diff --git a/jester/src/main.rs b/jester/src/main.rs index db8c02e..61f9ea2 100644 --- a/jester/src/main.rs +++ b/jester/src/main.rs @@ -13,9 +13,9 @@ fn main() { let binding = std::env::current_dir().expect("Failed to get current directory"); let project_root = binding.parent().expect("Failed to get parent directory"); - let gwydion_jar = project_root.join("compiler/build/libs/gwydion.jar"); + let selene_jar = project_root.join("compiler/build/libs/selene.jar"); - if !gwydion_jar.exists() { + if !selene_jar.exists() { return; } @@ -34,7 +34,7 @@ fn main() { &stdlib_props.name, &stdlib, &project_root, - &gwydion_jar, + &selene_jar, native, true, ); @@ -48,7 +48,7 @@ fn main() { &bard_props.name, &bard_dir, &project_root, - &gwydion_jar, + &selene_jar, native, false, ); @@ -101,20 +101,20 @@ fn link_files(project_root: &Path) { fn compile( name: &String, target_root: &Path, - gwydion_root: &Path, - gwydion_jar: &Path, + selene_root: &Path, + selene_jar: &Path, native: bool, is_stdlib: bool ) -> bool { println!("Compiling {:?}", target_root); - let output_dir = gwydion_root.join("bard/output/ll"); + let output_dir = selene_root.join("bard/output/ll"); fs::create_dir_all(&output_dir).expect("Failed to create output directory"); if !native { let mut command = Command::new("java"); command.arg("-jar") - .arg(&gwydion_jar) + .arg(&selene_jar) .arg(target_root) .arg(name) .current_dir(&output_dir); diff --git a/llvm/src/commonMain/kotlin/ILLVMCodeAssembler.kt b/llvm/src/commonMain/kotlin/ILLVMCodeAssembler.kt index d6f1660..dcf85e5 100644 --- a/llvm/src/commonMain/kotlin/ILLVMCodeAssembler.kt +++ b/llvm/src/commonMain/kotlin/ILLVMCodeAssembler.kt @@ -1,9 +1,9 @@ -package me.gabriel.gwydion.llvm +package me.gabriel.selene.llvm -import me.gabriel.gwydion.llvm.struct.BinaryOp -import me.gabriel.gwydion.llvm.struct.LLVMType -import me.gabriel.gwydion.llvm.struct.MemoryUnit -import me.gabriel.gwydion.llvm.struct.Value +import me.gabriel.selene.llvm.struct.BinaryOp +import me.gabriel.selene.llvm.struct.LLVMType +import me.gabriel.selene.llvm.struct.MemoryUnit +import me.gabriel.selene.llvm.struct.Value interface ILLVMCodeAssembler { fun addDependency(dependency: String) diff --git a/llvm/src/commonMain/kotlin/ILLVMCodeGenerator.kt b/llvm/src/commonMain/kotlin/ILLVMCodeGenerator.kt index 29f072a..5b9ffed 100644 --- a/llvm/src/commonMain/kotlin/ILLVMCodeGenerator.kt +++ b/llvm/src/commonMain/kotlin/ILLVMCodeGenerator.kt @@ -1,6 +1,6 @@ -package me.gabriel.gwydion.llvm +package me.gabriel.selene.llvm -import me.gabriel.gwydion.llvm.struct.* +import me.gabriel.selene.llvm.struct.* interface ILLVMCodeGenerator { fun stackMemoryAllocation(type: LLVMType, alignment: Int = type.defaultAlignment): String diff --git a/llvm/src/commonMain/kotlin/LLVMCodeAssembler.kt b/llvm/src/commonMain/kotlin/LLVMCodeAssembler.kt index 96d357e..670601c 100644 --- a/llvm/src/commonMain/kotlin/LLVMCodeAssembler.kt +++ b/llvm/src/commonMain/kotlin/LLVMCodeAssembler.kt @@ -1,7 +1,6 @@ -package me.gabriel.gwydion.llvm +package me.gabriel.selene.llvm -import me.gabriel.gwydion.llvm.struct.* -import kotlin.math.min +import me.gabriel.selene.llvm.struct.* class LLVMCodeAssembler(val generator: ILLVMCodeGenerator): ILLVMCodeAssembler { private val ir = mutableListOf() diff --git a/llvm/src/commonMain/kotlin/LLVMCodeGenerator.kt b/llvm/src/commonMain/kotlin/LLVMCodeGenerator.kt index be0e862..8a82350 100644 --- a/llvm/src/commonMain/kotlin/LLVMCodeGenerator.kt +++ b/llvm/src/commonMain/kotlin/LLVMCodeGenerator.kt @@ -1,6 +1,6 @@ -package me.gabriel.gwydion.llvm +package me.gabriel.selene.llvm -import me.gabriel.gwydion.llvm.struct.* +import me.gabriel.selene.llvm.struct.* class LLVMCodeGenerator: ILLVMCodeGenerator { private val dependencies = mutableSetOf() diff --git a/llvm/src/commonMain/kotlin/struct/Comparison.kt b/llvm/src/commonMain/kotlin/struct/Comparison.kt index d30fe5f..5700498 100644 --- a/llvm/src/commonMain/kotlin/struct/Comparison.kt +++ b/llvm/src/commonMain/kotlin/struct/Comparison.kt @@ -1,4 +1,4 @@ -package me.gabriel.gwydion.llvm.struct +package me.gabriel.selene.llvm.struct sealed class Comparison( val number: String, diff --git a/llvm/src/commonMain/kotlin/struct/MemoryUnit.kt b/llvm/src/commonMain/kotlin/struct/MemoryUnit.kt index 891916a..e44a03b 100644 --- a/llvm/src/commonMain/kotlin/struct/MemoryUnit.kt +++ b/llvm/src/commonMain/kotlin/struct/MemoryUnit.kt @@ -1,4 +1,4 @@ -package me.gabriel.gwydion.llvm.struct +package me.gabriel.selene.llvm.struct sealed interface Value { val type: LLVMType diff --git a/llvm/src/commonMain/kotlin/struct/Op.kt b/llvm/src/commonMain/kotlin/struct/Op.kt index 817a37c..ac6f099 100644 --- a/llvm/src/commonMain/kotlin/struct/Op.kt +++ b/llvm/src/commonMain/kotlin/struct/Op.kt @@ -1,4 +1,4 @@ -package me.gabriel.gwydion.llvm.struct +package me.gabriel.selene.llvm.struct enum class BinaryOp(val llvm: String, val floatLlvm: String) { Addition("add", "fadd"), diff --git a/llvm/src/commonMain/kotlin/struct/Traits.kt b/llvm/src/commonMain/kotlin/struct/Traits.kt index 8987350..68585cc 100644 --- a/llvm/src/commonMain/kotlin/struct/Traits.kt +++ b/llvm/src/commonMain/kotlin/struct/Traits.kt @@ -1,4 +1,4 @@ -package me.gabriel.gwydion.llvm.struct +package me.gabriel.selene.llvm.struct class TraitObject( val prefix: String = PREFIX, diff --git a/llvm/src/commonMain/kotlin/struct/Types.kt b/llvm/src/commonMain/kotlin/struct/Types.kt index bd0b69a..d66de70 100644 --- a/llvm/src/commonMain/kotlin/struct/Types.kt +++ b/llvm/src/commonMain/kotlin/struct/Types.kt @@ -1,4 +1,4 @@ -package me.gabriel.gwydion.llvm.struct +package me.gabriel.selene.llvm.struct sealed class LLVMType( val llvm: String, diff --git a/runestone/src/jsMain/kotlin/index.kt b/runestone/src/jsMain/kotlin/index.kt index c6d63e5..4b4b3cb 100644 --- a/runestone/src/jsMain/kotlin/index.kt +++ b/runestone/src/jsMain/kotlin/index.kt @@ -4,9 +4,8 @@ import kotlinx.html.dom.* import kotlinx.html.js.* import org.w3c.dom.* import org.w3c.dom.events.Event -import me.gabriel.gwydion.frontend.lexing.Token -import me.gabriel.gwydion.frontend.lexing.TokenKind -import me.gabriel.gwydion.frontend.lexing.lexers.StringLexer +import me.gabriel.selene.frontend.lexing.TokenKind +import me.gabriel.selene.frontend.lexing.lexers.StringLexer fun main() { document.body!!.append.div { diff --git a/settings.gradle.kts b/settings.gradle.kts index 1b63e98..bbde102 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,4 +1,4 @@ -rootProject.name = "gwydion" +rootProject.name = "selene" dependencyResolutionManagement { versionCatalogs { diff --git a/tools/src/commonMain/kotlin/Either.kt b/tools/src/commonMain/kotlin/Either.kt index 991c151..36a3697 100644 --- a/tools/src/commonMain/kotlin/Either.kt +++ b/tools/src/commonMain/kotlin/Either.kt @@ -1,4 +1,4 @@ -package me.gabriel.gwydion.tools +package me.gabriel.selene.tools /** * Represents a value of one of two possible types (a disjoint union). diff --git a/tools/src/commonMain/kotlin/Logging.kt b/tools/src/commonMain/kotlin/Logging.kt index fe722fd..b9db7a2 100644 --- a/tools/src/commonMain/kotlin/Logging.kt +++ b/tools/src/commonMain/kotlin/Logging.kt @@ -1,6 +1,6 @@ -package me.gabriel.gwydion.tools +package me.gabriel.selene.tools -interface GwydionLogger { +interface SeleneLogger { fun log(level: LogLevel, message: LogBuilder.() -> Unit) } diff --git a/tools/src/commonMain/kotlin/locs.kt b/tools/src/commonMain/kotlin/locs.kt index 4abbda7..4d9082c 100644 --- a/tools/src/commonMain/kotlin/locs.kt +++ b/tools/src/commonMain/kotlin/locs.kt @@ -1,4 +1,4 @@ -package me.gabriel.gwydion.tools +package me.gabriel.selene.tools data class RowInfo(val content: String, val relativeIndex: Int)