mirror of
https://github.com/GayPizzaSpecifications/pork.git
synced 2025-08-03 13:11:32 +00:00
ast: utilize extension functions to prevent larger stack frames from default interface methods
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
// GENERATED CODE FROM PORK AST CODEGEN
|
||||
package gay.pizza.pork.ast
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
@ -11,6 +12,9 @@ class Block(val expressions: List<Expression>) : Node() {
|
||||
override fun <T> visitChildren(visitor: NodeVisitor<T>): List<T> =
|
||||
visitor.visitAll(expressions)
|
||||
|
||||
override fun <T> visit(visitor: NodeVisitor<T>): T =
|
||||
visitor.visitBlock(this)
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is Block) return false
|
||||
return other.expressions == expressions
|
||||
|
@ -1,3 +1,4 @@
|
||||
// GENERATED CODE FROM PORK AST CODEGEN
|
||||
package gay.pizza.pork.ast
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
@ -8,6 +9,9 @@ import kotlinx.serialization.Serializable
|
||||
class BooleanLiteral(val value: Boolean) : Expression() {
|
||||
override val type: NodeType = NodeType.BooleanLiteral
|
||||
|
||||
override fun <T> visit(visitor: NodeVisitor<T>): T =
|
||||
visitor.visitBooleanLiteral(this)
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is BooleanLiteral) return false
|
||||
return other.value == value
|
||||
|
@ -1,3 +1,4 @@
|
||||
// GENERATED CODE FROM PORK AST CODEGEN
|
||||
package gay.pizza.pork.ast
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
@ -11,6 +12,9 @@ class CompilationUnit(val declarations: List<Declaration>, val definitions: List
|
||||
override fun <T> visitChildren(visitor: NodeVisitor<T>): List<T> =
|
||||
visitor.visitAll(declarations, definitions)
|
||||
|
||||
override fun <T> visit(visitor: NodeVisitor<T>): T =
|
||||
visitor.visitCompilationUnit(this)
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is CompilationUnit) return false
|
||||
return other.declarations == declarations && other.definitions == definitions
|
||||
|
@ -1,3 +1,4 @@
|
||||
// GENERATED CODE FROM PORK AST CODEGEN
|
||||
package gay.pizza.pork.ast
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
|
@ -1,3 +1,4 @@
|
||||
// GENERATED CODE FROM PORK AST CODEGEN
|
||||
package gay.pizza.pork.ast
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
|
@ -1,3 +1,4 @@
|
||||
// GENERATED CODE FROM PORK AST CODEGEN
|
||||
package gay.pizza.pork.ast
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
|
@ -1,3 +1,4 @@
|
||||
// GENERATED CODE FROM PORK AST CODEGEN
|
||||
package gay.pizza.pork.ast
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
|
@ -1,3 +1,4 @@
|
||||
// GENERATED CODE FROM PORK AST CODEGEN
|
||||
package gay.pizza.pork.ast
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
@ -11,6 +12,9 @@ class FunctionCall(val symbol: Symbol, val arguments: List<Expression>) : Expres
|
||||
override fun <T> visitChildren(visitor: NodeVisitor<T>): List<T> =
|
||||
visitor.visitAll(listOf(symbol), arguments)
|
||||
|
||||
override fun <T> visit(visitor: NodeVisitor<T>): T =
|
||||
visitor.visitFunctionCall(this)
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is FunctionCall) return false
|
||||
return other.symbol == symbol && other.arguments == arguments
|
||||
|
@ -1,3 +1,4 @@
|
||||
// GENERATED CODE FROM PORK AST CODEGEN
|
||||
package gay.pizza.pork.ast
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
@ -11,6 +12,9 @@ class FunctionDefinition(override val modifiers: DefinitionModifiers, override v
|
||||
override fun <T> visitChildren(visitor: NodeVisitor<T>): List<T> =
|
||||
visitor.visitAll(listOf(symbol), arguments, listOf(block))
|
||||
|
||||
override fun <T> visit(visitor: NodeVisitor<T>): T =
|
||||
visitor.visitFunctionDefinition(this)
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is FunctionDefinition) return false
|
||||
return other.modifiers == modifiers && other.symbol == symbol && other.arguments == arguments && other.block == block
|
||||
|
@ -1,3 +1,4 @@
|
||||
// GENERATED CODE FROM PORK AST CODEGEN
|
||||
package gay.pizza.pork.ast
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
@ -11,6 +12,9 @@ class If(val condition: Expression, val thenExpression: Expression, val elseExpr
|
||||
override fun <T> visitChildren(visitor: NodeVisitor<T>): List<T> =
|
||||
visitor.visitNodes(condition, thenExpression, elseExpression)
|
||||
|
||||
override fun <T> visit(visitor: NodeVisitor<T>): T =
|
||||
visitor.visitIf(this)
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is If) return false
|
||||
return other.condition == condition && other.thenExpression == thenExpression && other.elseExpression == elseExpression
|
||||
|
@ -1,3 +1,4 @@
|
||||
// GENERATED CODE FROM PORK AST CODEGEN
|
||||
package gay.pizza.pork.ast
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
@ -11,6 +12,9 @@ class ImportDeclaration(val path: StringLiteral) : Declaration() {
|
||||
override fun <T> visitChildren(visitor: NodeVisitor<T>): List<T> =
|
||||
visitor.visitNodes(path)
|
||||
|
||||
override fun <T> visit(visitor: NodeVisitor<T>): T =
|
||||
visitor.visitImportDeclaration(this)
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is ImportDeclaration) return false
|
||||
return other.path == path
|
||||
|
@ -1,3 +1,4 @@
|
||||
// GENERATED CODE FROM PORK AST CODEGEN
|
||||
package gay.pizza.pork.ast
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
@ -11,6 +12,9 @@ class InfixOperation(val left: Expression, val op: InfixOperator, val right: Exp
|
||||
override fun <T> visitChildren(visitor: NodeVisitor<T>): List<T> =
|
||||
visitor.visitNodes(left, right)
|
||||
|
||||
override fun <T> visit(visitor: NodeVisitor<T>): T =
|
||||
visitor.visitInfixOperation(this)
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is InfixOperation) return false
|
||||
return other.left == left && other.op == op && other.right == right
|
||||
|
@ -1,3 +1,4 @@
|
||||
// GENERATED CODE FROM PORK AST CODEGEN
|
||||
package gay.pizza.pork.ast
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
|
@ -1,3 +1,4 @@
|
||||
// GENERATED CODE FROM PORK AST CODEGEN
|
||||
package gay.pizza.pork.ast
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
@ -8,6 +9,9 @@ import kotlinx.serialization.Serializable
|
||||
class IntLiteral(val value: Int) : Expression() {
|
||||
override val type: NodeType = NodeType.IntLiteral
|
||||
|
||||
override fun <T> visit(visitor: NodeVisitor<T>): T =
|
||||
visitor.visitIntLiteral(this)
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is IntLiteral) return false
|
||||
return other.value == value
|
||||
|
@ -1,3 +1,4 @@
|
||||
// GENERATED CODE FROM PORK AST CODEGEN
|
||||
package gay.pizza.pork.ast
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
@ -11,6 +12,9 @@ class Lambda(val arguments: List<Symbol>, val expressions: List<Expression>) : E
|
||||
override fun <T> visitChildren(visitor: NodeVisitor<T>): List<T> =
|
||||
visitor.visitAll(arguments, expressions)
|
||||
|
||||
override fun <T> visit(visitor: NodeVisitor<T>): T =
|
||||
visitor.visitLambda(this)
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is Lambda) return false
|
||||
return other.arguments == arguments && other.expressions == expressions
|
||||
|
@ -1,3 +1,4 @@
|
||||
// GENERATED CODE FROM PORK AST CODEGEN
|
||||
package gay.pizza.pork.ast
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
@ -11,6 +12,9 @@ class LetAssignment(val symbol: Symbol, val value: Expression) : Expression() {
|
||||
override fun <T> visitChildren(visitor: NodeVisitor<T>): List<T> =
|
||||
visitor.visitNodes(symbol, value)
|
||||
|
||||
override fun <T> visit(visitor: NodeVisitor<T>): T =
|
||||
visitor.visitLetAssignment(this)
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is LetAssignment) return false
|
||||
return other.symbol == symbol && other.value == value
|
||||
|
@ -1,3 +1,4 @@
|
||||
// GENERATED CODE FROM PORK AST CODEGEN
|
||||
package gay.pizza.pork.ast
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
@ -11,6 +12,9 @@ class ListLiteral(val items: List<Expression>) : Expression() {
|
||||
override fun <T> visitChildren(visitor: NodeVisitor<T>): List<T> =
|
||||
visitor.visitAll(items)
|
||||
|
||||
override fun <T> visit(visitor: NodeVisitor<T>): T =
|
||||
visitor.visitListLiteral(this)
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is ListLiteral) return false
|
||||
return other.items == items
|
||||
|
@ -1,3 +1,4 @@
|
||||
// GENERATED CODE FROM PORK AST CODEGEN
|
||||
package gay.pizza.pork.ast
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
@ -10,4 +11,7 @@ sealed class Node {
|
||||
|
||||
open fun <T> visitChildren(visitor: NodeVisitor<T>): List<T> =
|
||||
emptyList()
|
||||
|
||||
open fun <T> visit(visitor: NodeVisitor<T>): T =
|
||||
visitor.visit(this)
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
// GENERATED CODE FROM PORK AST CODEGEN
|
||||
package gay.pizza.pork.ast
|
||||
|
||||
class NodeCoalescer(val handler: (Node) -> Unit) : NodeVisitor<Unit> {
|
||||
|
@ -1,3 +1,4 @@
|
||||
// GENERATED CODE FROM PORK AST CODEGEN
|
||||
package gay.pizza.pork.ast
|
||||
|
||||
enum class NodeType(val parent: NodeType? = null) {
|
||||
|
@ -1,3 +1,4 @@
|
||||
// GENERATED CODE FROM PORK AST CODEGEN
|
||||
package gay.pizza.pork.ast
|
||||
|
||||
interface NodeVisitor<T> {
|
||||
@ -34,31 +35,4 @@ interface NodeVisitor<T> {
|
||||
fun visitSymbol(node: Symbol): T
|
||||
|
||||
fun visitSymbolReference(node: SymbolReference): T
|
||||
|
||||
fun visitNodes(vararg nodes: Node?): List<T> =
|
||||
nodes.asSequence().filterNotNull().map { visit(it) }.toList()
|
||||
|
||||
fun visitAll(vararg nodeLists: List<Node>): List<T> =
|
||||
nodeLists.asSequence().flatten().map { visit(it) }.toList()
|
||||
|
||||
fun visit(node: Node): T =
|
||||
when (node) {
|
||||
is Symbol -> visitSymbol(node)
|
||||
is Block -> visitBlock(node)
|
||||
is CompilationUnit -> visitCompilationUnit(node)
|
||||
is LetAssignment -> visitLetAssignment(node)
|
||||
is InfixOperation -> visitInfixOperation(node)
|
||||
is BooleanLiteral -> visitBooleanLiteral(node)
|
||||
is FunctionCall -> visitFunctionCall(node)
|
||||
is FunctionDefinition -> visitFunctionDefinition(node)
|
||||
is If -> visitIf(node)
|
||||
is ImportDeclaration -> visitImportDeclaration(node)
|
||||
is IntLiteral -> visitIntLiteral(node)
|
||||
is Lambda -> visitLambda(node)
|
||||
is ListLiteral -> visitListLiteral(node)
|
||||
is Parentheses -> visitParentheses(node)
|
||||
is PrefixOperation -> visitPrefixOperation(node)
|
||||
is StringLiteral -> visitStringLiteral(node)
|
||||
is SymbolReference -> visitSymbolReference(node)
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,29 @@
|
||||
// GENERATED CODE FROM PORK AST CODEGEN
|
||||
package gay.pizza.pork.ast
|
||||
|
||||
fun <T> NodeVisitor<T>.visit(node: Node): T =
|
||||
when (node) {
|
||||
is Symbol -> visitSymbol(node)
|
||||
is Block -> visitBlock(node)
|
||||
is CompilationUnit -> visitCompilationUnit(node)
|
||||
is LetAssignment -> visitLetAssignment(node)
|
||||
is InfixOperation -> visitInfixOperation(node)
|
||||
is BooleanLiteral -> visitBooleanLiteral(node)
|
||||
is FunctionCall -> visitFunctionCall(node)
|
||||
is FunctionDefinition -> visitFunctionDefinition(node)
|
||||
is If -> visitIf(node)
|
||||
is ImportDeclaration -> visitImportDeclaration(node)
|
||||
is IntLiteral -> visitIntLiteral(node)
|
||||
is Lambda -> visitLambda(node)
|
||||
is ListLiteral -> visitListLiteral(node)
|
||||
is Parentheses -> visitParentheses(node)
|
||||
is PrefixOperation -> visitPrefixOperation(node)
|
||||
is StringLiteral -> visitStringLiteral(node)
|
||||
is SymbolReference -> visitSymbolReference(node)
|
||||
}
|
||||
|
||||
fun <T> NodeVisitor<T>.visitNodes(vararg nodes: Node?): List<T> =
|
||||
nodes.asSequence().filterNotNull().map { visit(it) }.toList()
|
||||
|
||||
fun <T> NodeVisitor<T>.visitAll(vararg nodeLists: List<Node>): List<T> =
|
||||
nodeLists.asSequence().flatten().map { visit(it) }.toList()
|
@ -1,3 +1,4 @@
|
||||
// GENERATED CODE FROM PORK AST CODEGEN
|
||||
package gay.pizza.pork.ast
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
@ -11,6 +12,9 @@ class Parentheses(val expression: Expression) : Expression() {
|
||||
override fun <T> visitChildren(visitor: NodeVisitor<T>): List<T> =
|
||||
visitor.visitNodes(expression)
|
||||
|
||||
override fun <T> visit(visitor: NodeVisitor<T>): T =
|
||||
visitor.visitParentheses(this)
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is Parentheses) return false
|
||||
return other.expression == expression
|
||||
|
@ -1,3 +1,4 @@
|
||||
// GENERATED CODE FROM PORK AST CODEGEN
|
||||
package gay.pizza.pork.ast
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
@ -11,6 +12,9 @@ class PrefixOperation(val op: PrefixOperator, val expression: Expression) : Expr
|
||||
override fun <T> visitChildren(visitor: NodeVisitor<T>): List<T> =
|
||||
visitor.visitNodes(expression)
|
||||
|
||||
override fun <T> visit(visitor: NodeVisitor<T>): T =
|
||||
visitor.visitPrefixOperation(this)
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is PrefixOperation) return false
|
||||
return other.op == op && other.expression == expression
|
||||
|
@ -1,3 +1,4 @@
|
||||
// GENERATED CODE FROM PORK AST CODEGEN
|
||||
package gay.pizza.pork.ast
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
|
@ -1,3 +1,4 @@
|
||||
// GENERATED CODE FROM PORK AST CODEGEN
|
||||
package gay.pizza.pork.ast
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
@ -8,6 +9,9 @@ import kotlinx.serialization.Serializable
|
||||
class StringLiteral(val text: String) : Expression() {
|
||||
override val type: NodeType = NodeType.StringLiteral
|
||||
|
||||
override fun <T> visit(visitor: NodeVisitor<T>): T =
|
||||
visitor.visitStringLiteral(this)
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is StringLiteral) return false
|
||||
return other.text == text
|
||||
|
@ -1,3 +1,4 @@
|
||||
// GENERATED CODE FROM PORK AST CODEGEN
|
||||
package gay.pizza.pork.ast
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
@ -8,6 +9,9 @@ import kotlinx.serialization.Serializable
|
||||
class Symbol(val id: String) : Node() {
|
||||
override val type: NodeType = NodeType.Symbol
|
||||
|
||||
override fun <T> visit(visitor: NodeVisitor<T>): T =
|
||||
visitor.visitSymbol(this)
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is Symbol) return false
|
||||
return other.id == id
|
||||
|
@ -1,3 +1,4 @@
|
||||
// GENERATED CODE FROM PORK AST CODEGEN
|
||||
package gay.pizza.pork.ast
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
@ -11,6 +12,9 @@ class SymbolReference(val symbol: Symbol) : Expression() {
|
||||
override fun <T> visitChildren(visitor: NodeVisitor<T>): List<T> =
|
||||
visitor.visitNodes(symbol)
|
||||
|
||||
override fun <T> visit(visitor: NodeVisitor<T>): T =
|
||||
visitor.visitSymbolReference(this)
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is SymbolReference) return false
|
||||
return other.symbol == symbol
|
||||
|
Reference in New Issue
Block a user