-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
compiler: full support for IR based compilation
- Loading branch information
Showing
32 changed files
with
553 additions
and
399 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
package gay.pizza.pork.bir | ||
|
||
data class IrCodeBlock(val items: List<IrCodeElement>) : IrCodeElement | ||
data class IrCodeBlock(val items: List<IrCodeElement>) : IrCodeElement { | ||
override fun crawl(block: (IrElement) -> Unit) { | ||
items.forEach(block) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
package gay.pizza.pork.bir | ||
|
||
data class IrDefinition( | ||
val symbol: IrSymbol, | ||
override val symbol: IrSymbol, | ||
val type: IrDefinitionType, | ||
val arguments: List<IrFunctionArgument>, | ||
val code: IrCodeBlock | ||
) : IrElement { | ||
) : IrElement, IrSymbolOwner { | ||
override fun crawl(block: (IrElement) -> Unit) { | ||
block(symbol) | ||
arguments.forEach(block) | ||
block(code) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,6 @@ package gay.pizza.pork.bir | |
|
||
enum class IrDefinitionType { | ||
Variable, | ||
Function | ||
CodeFunction, | ||
NativeFunction | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package gay.pizza.pork.bir | ||
|
||
data class IrFunctionArgument(override val symbol: IrSymbol) : IrSymbolOwner { | ||
override fun crawl(block: (IrElement) -> Unit) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
package gay.pizza.pork.bir | ||
|
||
data class IrLoad(val symbol: IrSymbol) : IrCodeElement { | ||
data class IrLoad(override val target: IrSymbol) : IrCodeElement, IrSymbolUser { | ||
override fun crawl(block: (IrElement) -> Unit) { | ||
block(symbol) | ||
block(target) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package gay.pizza.pork.bir | ||
|
||
data class IrNativeDefinition(val form: String, val definitions: List<String>) : IrCodeElement { | ||
override fun crawl(block: (IrElement) -> Unit) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package gay.pizza.pork.bir | ||
|
||
data class IrSuffix(val op: IrSuffixOp, override val target: IrSymbol) : IrCodeElement, IrSymbolUser { | ||
override fun crawl(block: (IrElement) -> Unit) { | ||
block(target) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package gay.pizza.pork.bir | ||
|
||
enum class IrSuffixOp { | ||
Increment, | ||
Decrement | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package gay.pizza.pork.bir | ||
|
||
class IrSymbolGraph { | ||
private val edges = mutableSetOf<Pair<IrSymbolUser, IrSymbolOwner>>() | ||
|
||
private fun crawlForKnown(known: MutableMap<IrSymbol, IrSymbolOwner>, root: IrElement) { | ||
if (root is IrSymbolOwner) { | ||
known[root.symbol] = root | ||
} | ||
|
||
root.crawl { item -> | ||
crawlForKnown(known, item) | ||
} | ||
} | ||
|
||
private fun crawlForAssociations(known: Map<IrSymbol, IrSymbolOwner>, root: IrElement) { | ||
if (root is IrSymbolUser) { | ||
val what = known[root.target] | ||
if (what != null) { | ||
edges.add(root to what) | ||
} | ||
} | ||
|
||
root.crawl { item -> | ||
crawlForAssociations(known, item) | ||
} | ||
} | ||
|
||
fun crawl(root: IrElement) { | ||
val known = mutableMapOf<IrSymbol, IrSymbolOwner>() | ||
crawlForKnown(known, root) | ||
crawlForAssociations(known, root) | ||
} | ||
|
||
fun forEachEdge(block: (IrSymbolUser, IrSymbolOwner) -> Unit) { | ||
for ((from, to) in edges) { | ||
block(from, to) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package gay.pizza.pork.bir | ||
|
||
sealed interface IrSymbolOwner : IrElement { | ||
val symbol: IrSymbol | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package gay.pizza.pork.bir | ||
|
||
sealed interface IrSymbolUser : IrElement { | ||
val target: IrSymbol | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package gay.pizza.pork.bir | ||
|
||
interface IrVisitor<T> { | ||
fun visitIrSlab(ir: IrSlab): T | ||
fun visitIrSlabLocation(ir: IrSlabLocation): T | ||
fun visitIrDefinition(ir: IrDefinition): T | ||
fun visitIrSymbol(ir: IrSymbol): T | ||
fun visitIrBeak(ir: IrBreak): T | ||
fun visitIrCall(ir: IrCall): T | ||
fun visitIrCodeBlock(ir: IrCodeBlock): T | ||
fun visitIrConditional(ir: IrConditional): T | ||
fun visitIrBooleanConstant(ir: IrBooleanConstant): T | ||
fun visitIrIntegerConstant(ir: IrIntegerConstant): T | ||
fun visitIrLongConstant(ir: IrLongConstant): T | ||
fun visitIrDoubleConstant(ir: IrDoubleConstant): T | ||
fun visitIrStringConstant(ir: IrStringConstant): T | ||
fun visitIrNoneConstant(ir: IrNoneConstant): T | ||
fun visitIrContinue(ir: IrContinue): T | ||
fun visitIrInfix(ir: IrInfix): T | ||
fun visitIrList(ir: IrList): T | ||
fun visitIrLoad(ir: IrLoad): T | ||
fun visitIrLoop(ir: IrLoop): T | ||
fun visitIrPrefix(ir: IrPrefix): T | ||
fun visitIrReturn(ir: IrReturn): T | ||
fun visitIrStore(ir: IrStore): T | ||
fun visitIrSuffix(ir: IrSuffix): T | ||
fun visitIrWorld(ir: IrWorld): T | ||
fun visitIrNativeDefinition(ir: IrNativeDefinition): T | ||
fun visitIrFunctionArgument(ir: IrFunctionArgument): T | ||
|
||
fun visit(ir: IrElement): T = when (ir) { | ||
is IrBreak -> visitIrBeak(ir) | ||
is IrCall -> visitIrCall(ir) | ||
is IrCodeBlock -> visitIrCodeBlock(ir) | ||
is IrConditional -> visitIrConditional(ir) | ||
is IrBooleanConstant -> visitIrBooleanConstant(ir) | ||
is IrDoubleConstant -> visitIrDoubleConstant(ir) | ||
is IrIntegerConstant -> visitIrIntegerConstant(ir) | ||
is IrLongConstant -> visitIrLongConstant(ir) | ||
is IrNoneConstant -> visitIrNoneConstant(ir) | ||
is IrStringConstant -> visitIrStringConstant(ir) | ||
is IrContinue -> visitIrContinue(ir) | ||
is IrInfix -> visitIrInfix(ir) | ||
is IrList -> visitIrList(ir) | ||
is IrLoad -> visitIrLoad(ir) | ||
is IrLoop -> visitIrLoop(ir) | ||
is IrPrefix -> visitIrPrefix(ir) | ||
is IrReturn -> visitIrReturn(ir) | ||
is IrStore -> visitIrStore(ir) | ||
is IrSuffix -> visitIrSuffix(ir) | ||
is IrDefinition -> visitIrDefinition(ir) | ||
is IrSlab -> visitIrSlab(ir) | ||
is IrSlabLocation -> visitIrSlabLocation(ir) | ||
is IrSymbol -> visitIrSymbol(ir) | ||
is IrWorld -> visitIrWorld(ir) | ||
is IrNativeDefinition -> visitIrNativeDefinition(ir) | ||
is IrFunctionArgument -> visitIrFunctionArgument(ir) | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
...ain/kotlin/gay/pizza/pork/bir/IrAccess.kt → ...main/kotlin/gay/pizza/pork/bir/IrWorld.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
package gay.pizza.pork.bir | ||
|
||
data class IrAccess(val target: IrSymbol) : IrCodeElement { | ||
data class IrWorld(val slabs: List<IrSlab>) : IrElement { | ||
override fun crawl(block: (IrElement) -> Unit) { | ||
block(target) | ||
slabs.forEach(block) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
package gay.pizza.pork.bytecode | ||
|
||
class MutableRel(var rel: UInt) | ||
data class MutableRel(var rel: UInt) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.