mirror of
https://github.com/GayPizzaSpecifications/pork.git
synced 2025-08-03 13:11:32 +00:00
WIP on IR
This commit is contained in:
7
bir/build.gradle.kts
Normal file
7
bir/build.gradle.kts
Normal file
@ -0,0 +1,7 @@
|
||||
plugins {
|
||||
id("gay.pizza.pork.module")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(project(":common"))
|
||||
}
|
7
bir/src/main/kotlin/gay/pizza/pork/bir/IrAccess.kt
Normal file
7
bir/src/main/kotlin/gay/pizza/pork/bir/IrAccess.kt
Normal file
@ -0,0 +1,7 @@
|
||||
package gay.pizza.pork.bir
|
||||
|
||||
data class IrAccess(val target: IrSymbol) : IrCodeElement {
|
||||
override fun crawl(block: (IrElement) -> Unit) {
|
||||
block(target)
|
||||
}
|
||||
}
|
7
bir/src/main/kotlin/gay/pizza/pork/bir/IrBreak.kt
Normal file
7
bir/src/main/kotlin/gay/pizza/pork/bir/IrBreak.kt
Normal file
@ -0,0 +1,7 @@
|
||||
package gay.pizza.pork.bir
|
||||
|
||||
data class IrBreak(val target: IrSymbol) : IrCodeElement {
|
||||
override fun crawl(block: (IrElement) -> Unit) {
|
||||
block(target)
|
||||
}
|
||||
}
|
13
bir/src/main/kotlin/gay/pizza/pork/bir/IrCall.kt
Normal file
13
bir/src/main/kotlin/gay/pizza/pork/bir/IrCall.kt
Normal file
@ -0,0 +1,13 @@
|
||||
package gay.pizza.pork.bir
|
||||
|
||||
data class IrCall(
|
||||
val target: IrSymbol,
|
||||
val arguments: List<IrCodeElement>,
|
||||
val variableArguments: List<IrCodeElement>?
|
||||
) : IrCodeElement {
|
||||
override fun crawl(block: (IrElement) -> Unit) {
|
||||
block(target)
|
||||
arguments.forEach(block)
|
||||
variableArguments?.forEach(block)
|
||||
}
|
||||
}
|
3
bir/src/main/kotlin/gay/pizza/pork/bir/IrCodeBlock.kt
Normal file
3
bir/src/main/kotlin/gay/pizza/pork/bir/IrCodeBlock.kt
Normal file
@ -0,0 +1,3 @@
|
||||
package gay.pizza.pork.bir
|
||||
|
||||
data class IrCodeBlock(val items: List<IrCodeElement>) : IrCodeElement
|
3
bir/src/main/kotlin/gay/pizza/pork/bir/IrCodeElement.kt
Normal file
3
bir/src/main/kotlin/gay/pizza/pork/bir/IrCodeElement.kt
Normal file
@ -0,0 +1,3 @@
|
||||
package gay.pizza.pork.bir
|
||||
|
||||
sealed interface IrCodeElement : IrElement
|
13
bir/src/main/kotlin/gay/pizza/pork/bir/IrConditional.kt
Normal file
13
bir/src/main/kotlin/gay/pizza/pork/bir/IrConditional.kt
Normal file
@ -0,0 +1,13 @@
|
||||
package gay.pizza.pork.bir
|
||||
|
||||
data class IrConditional(
|
||||
val conditional: IrCodeElement,
|
||||
val ifTrue: IrCodeElement,
|
||||
val ifFalse: IrCodeElement
|
||||
) : IrCodeElement {
|
||||
override fun crawl(block: (IrElement) -> Unit) {
|
||||
block(conditional)
|
||||
block(ifTrue)
|
||||
block(ifFalse)
|
||||
}
|
||||
}
|
12
bir/src/main/kotlin/gay/pizza/pork/bir/IrConstant.kt
Normal file
12
bir/src/main/kotlin/gay/pizza/pork/bir/IrConstant.kt
Normal file
@ -0,0 +1,12 @@
|
||||
package gay.pizza.pork.bir
|
||||
|
||||
sealed interface IrConstant : IrCodeElement {
|
||||
override fun crawl(block: (IrElement) -> Unit) {}
|
||||
}
|
||||
|
||||
data class IrIntegerConstant(val value: Int) : IrConstant
|
||||
data class IrLongConstant(val value: Long) : IrConstant
|
||||
data class IrDoubleConstant(val value: Double) : IrConstant
|
||||
data class IrStringConstant(val value: String) : IrConstant
|
||||
data class IrBooleanConstant(val value: Boolean) : IrConstant
|
||||
data object IrNoneConstant : IrConstant
|
7
bir/src/main/kotlin/gay/pizza/pork/bir/IrContinue.kt
Normal file
7
bir/src/main/kotlin/gay/pizza/pork/bir/IrContinue.kt
Normal file
@ -0,0 +1,7 @@
|
||||
package gay.pizza.pork.bir
|
||||
|
||||
data class IrContinue(val target: IrSymbol) : IrCodeElement {
|
||||
override fun crawl(block: (IrElement) -> Unit) {
|
||||
block(target)
|
||||
}
|
||||
}
|
12
bir/src/main/kotlin/gay/pizza/pork/bir/IrDefinition.kt
Normal file
12
bir/src/main/kotlin/gay/pizza/pork/bir/IrDefinition.kt
Normal file
@ -0,0 +1,12 @@
|
||||
package gay.pizza.pork.bir
|
||||
|
||||
data class IrDefinition(
|
||||
val symbol: IrSymbol,
|
||||
val type: IrDefinitionType,
|
||||
val code: IrCodeBlock
|
||||
) : IrElement {
|
||||
override fun crawl(block: (IrElement) -> Unit) {
|
||||
block(symbol)
|
||||
block(code)
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package gay.pizza.pork.bir
|
||||
|
||||
enum class IrDefinitionType {
|
||||
Variable,
|
||||
Function
|
||||
}
|
5
bir/src/main/kotlin/gay/pizza/pork/bir/IrElement.kt
Normal file
5
bir/src/main/kotlin/gay/pizza/pork/bir/IrElement.kt
Normal file
@ -0,0 +1,5 @@
|
||||
package gay.pizza.pork.bir
|
||||
|
||||
sealed interface IrElement {
|
||||
fun crawl(block: (IrElement) -> Unit)
|
||||
}
|
8
bir/src/main/kotlin/gay/pizza/pork/bir/IrInfix.kt
Normal file
8
bir/src/main/kotlin/gay/pizza/pork/bir/IrInfix.kt
Normal file
@ -0,0 +1,8 @@
|
||||
package gay.pizza.pork.bir
|
||||
|
||||
data class IrInfix(val op: IrInfixOp, val left: IrCodeElement, val right: IrCodeElement) : IrCodeElement {
|
||||
override fun crawl(block: (IrElement) -> Unit) {
|
||||
block(left)
|
||||
block(right)
|
||||
}
|
||||
}
|
21
bir/src/main/kotlin/gay/pizza/pork/bir/IrInfixOp.kt
Normal file
21
bir/src/main/kotlin/gay/pizza/pork/bir/IrInfixOp.kt
Normal file
@ -0,0 +1,21 @@
|
||||
package gay.pizza.pork.bir
|
||||
|
||||
enum class IrInfixOp {
|
||||
Add,
|
||||
Subtract,
|
||||
Multiply,
|
||||
Divide,
|
||||
Equals,
|
||||
NotEquals,
|
||||
EuclideanModulo,
|
||||
Remainder,
|
||||
Lesser,
|
||||
Greater,
|
||||
LesserEqual,
|
||||
GreaterEqual,
|
||||
BooleanAnd,
|
||||
BooleanOr,
|
||||
BinaryAnd,
|
||||
BinaryOr,
|
||||
BinaryExclusiveOr
|
||||
}
|
7
bir/src/main/kotlin/gay/pizza/pork/bir/IrList.kt
Normal file
7
bir/src/main/kotlin/gay/pizza/pork/bir/IrList.kt
Normal file
@ -0,0 +1,7 @@
|
||||
package gay.pizza.pork.bir
|
||||
|
||||
data class IrList(val items: List<IrCodeElement>) : IrCodeElement {
|
||||
override fun crawl(block: (IrElement) -> Unit) {
|
||||
items.forEach(block)
|
||||
}
|
||||
}
|
7
bir/src/main/kotlin/gay/pizza/pork/bir/IrLoad.kt
Normal file
7
bir/src/main/kotlin/gay/pizza/pork/bir/IrLoad.kt
Normal file
@ -0,0 +1,7 @@
|
||||
package gay.pizza.pork.bir
|
||||
|
||||
data class IrLoad(val symbol: IrSymbol) : IrCodeElement {
|
||||
override fun crawl(block: (IrElement) -> Unit) {
|
||||
block(symbol)
|
||||
}
|
||||
}
|
9
bir/src/main/kotlin/gay/pizza/pork/bir/IrLoop.kt
Normal file
9
bir/src/main/kotlin/gay/pizza/pork/bir/IrLoop.kt
Normal file
@ -0,0 +1,9 @@
|
||||
package gay.pizza.pork.bir
|
||||
|
||||
data class IrLoop(val symbol: IrSymbol, val condition: IrCodeElement, val inner: IrCodeElement) : IrCodeElement {
|
||||
override fun crawl(block: (IrElement) -> Unit) {
|
||||
block(symbol)
|
||||
block(condition)
|
||||
block(inner)
|
||||
}
|
||||
}
|
7
bir/src/main/kotlin/gay/pizza/pork/bir/IrPrefix.kt
Normal file
7
bir/src/main/kotlin/gay/pizza/pork/bir/IrPrefix.kt
Normal file
@ -0,0 +1,7 @@
|
||||
package gay.pizza.pork.bir
|
||||
|
||||
data class IrPrefix(val op: IrPrefixOp, val value: IrCodeElement) : IrCodeElement {
|
||||
override fun crawl(block: (IrElement) -> Unit) {
|
||||
block(value)
|
||||
}
|
||||
}
|
8
bir/src/main/kotlin/gay/pizza/pork/bir/IrPrefixOp.kt
Normal file
8
bir/src/main/kotlin/gay/pizza/pork/bir/IrPrefixOp.kt
Normal file
@ -0,0 +1,8 @@
|
||||
package gay.pizza.pork.bir
|
||||
|
||||
enum class IrPrefixOp {
|
||||
BooleanNot,
|
||||
UnaryPlus,
|
||||
UnaryMinus,
|
||||
BinaryNot
|
||||
}
|
8
bir/src/main/kotlin/gay/pizza/pork/bir/IrReturn.kt
Normal file
8
bir/src/main/kotlin/gay/pizza/pork/bir/IrReturn.kt
Normal file
@ -0,0 +1,8 @@
|
||||
package gay.pizza.pork.bir
|
||||
|
||||
data class IrReturn(val from: IrSymbol, val value: IrCodeElement) : IrCodeElement {
|
||||
override fun crawl(block: (IrElement) -> Unit) {
|
||||
block(from)
|
||||
block(value)
|
||||
}
|
||||
}
|
11
bir/src/main/kotlin/gay/pizza/pork/bir/IrSlab.kt
Normal file
11
bir/src/main/kotlin/gay/pizza/pork/bir/IrSlab.kt
Normal file
@ -0,0 +1,11 @@
|
||||
package gay.pizza.pork.bir
|
||||
|
||||
data class IrSlab(
|
||||
val location: IrSlabLocation,
|
||||
val definitions: List<IrDefinition>
|
||||
) : IrElement {
|
||||
override fun crawl(block: (IrElement) -> Unit) {
|
||||
block(location)
|
||||
definitions.forEach(block)
|
||||
}
|
||||
}
|
8
bir/src/main/kotlin/gay/pizza/pork/bir/IrSlabLocation.kt
Normal file
8
bir/src/main/kotlin/gay/pizza/pork/bir/IrSlabLocation.kt
Normal file
@ -0,0 +1,8 @@
|
||||
package gay.pizza.pork.bir
|
||||
|
||||
data class IrSlabLocation(
|
||||
val form: String,
|
||||
val path: String
|
||||
) : IrElement {
|
||||
override fun crawl(block: (IrElement) -> Unit) {}
|
||||
}
|
7
bir/src/main/kotlin/gay/pizza/pork/bir/IrStore.kt
Normal file
7
bir/src/main/kotlin/gay/pizza/pork/bir/IrStore.kt
Normal file
@ -0,0 +1,7 @@
|
||||
package gay.pizza.pork.bir
|
||||
|
||||
data class IrStore(val symbol: IrSymbol, val value: IrCodeElement) : IrCodeElement {
|
||||
override fun crawl(block: (IrElement) -> Unit) {
|
||||
value.crawl(block)
|
||||
}
|
||||
}
|
5
bir/src/main/kotlin/gay/pizza/pork/bir/IrSymbol.kt
Normal file
5
bir/src/main/kotlin/gay/pizza/pork/bir/IrSymbol.kt
Normal file
@ -0,0 +1,5 @@
|
||||
package gay.pizza.pork.bir
|
||||
|
||||
data class IrSymbol(val id: UInt, val tag: IrSymbolTag) : IrElement {
|
||||
override fun crawl(block: (IrElement) -> Unit) {}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package gay.pizza.pork.bir
|
||||
|
||||
class IrSymbolAssignment {
|
||||
private var index = 0u
|
||||
|
||||
private fun nextSymbolId(): UInt = index++
|
||||
fun next(tag: IrSymbolTag): IrSymbol = IrSymbol(nextSymbolId(), tag)
|
||||
}
|
8
bir/src/main/kotlin/gay/pizza/pork/bir/IrSymbolTag.kt
Normal file
8
bir/src/main/kotlin/gay/pizza/pork/bir/IrSymbolTag.kt
Normal file
@ -0,0 +1,8 @@
|
||||
package gay.pizza.pork.bir
|
||||
|
||||
enum class IrSymbolTag {
|
||||
Function,
|
||||
Variable,
|
||||
Local,
|
||||
Loop
|
||||
}
|
Reference in New Issue
Block a user