mirror of
https://github.com/GayPizzaSpecifications/pork.git
synced 2025-08-03 21:21:33 +00:00
language: floating point support
This commit is contained in:
@ -114,11 +114,16 @@ types:
|
||||
type: Symbol
|
||||
- name: components
|
||||
type: List<Symbol>
|
||||
IntLiteral:
|
||||
IntegerLiteral:
|
||||
parent: Expression
|
||||
values:
|
||||
- name: value
|
||||
type: Int
|
||||
DoubleLiteral:
|
||||
parent: Expression
|
||||
values:
|
||||
- name: value
|
||||
type: Double
|
||||
ListLiteral:
|
||||
parent: Expression
|
||||
values:
|
||||
|
@ -5,15 +5,15 @@ import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
@SerialName("intLiteral")
|
||||
class IntLiteral(val value: Int) : Expression() {
|
||||
override val type: NodeType = NodeType.IntLiteral
|
||||
@SerialName("doubleLiteral")
|
||||
class DoubleLiteral(val value: Double) : Expression() {
|
||||
override val type: NodeType = NodeType.DoubleLiteral
|
||||
|
||||
override fun <T> visit(visitor: NodeVisitor<T>): T =
|
||||
visitor.visitIntLiteral(this)
|
||||
visitor.visitDoubleLiteral(this)
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is IntLiteral) return false
|
||||
if (other !is DoubleLiteral) return false
|
||||
return other.value == value
|
||||
}
|
||||
|
25
ast/src/main/kotlin/gay/pizza/pork/ast/IntegerLiteral.kt
Normal file
25
ast/src/main/kotlin/gay/pizza/pork/ast/IntegerLiteral.kt
Normal file
@ -0,0 +1,25 @@
|
||||
// GENERATED CODE FROM PORK AST CODEGEN
|
||||
package gay.pizza.pork.ast
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
@SerialName("integerLiteral")
|
||||
class IntegerLiteral(val value: Int) : Expression() {
|
||||
override val type: NodeType = NodeType.IntegerLiteral
|
||||
|
||||
override fun <T> visit(visitor: NodeVisitor<T>): T =
|
||||
visitor.visitIntegerLiteral(this)
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is IntegerLiteral) return false
|
||||
return other.value == value
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = value.hashCode()
|
||||
result = 31 * result + type.hashCode()
|
||||
return result
|
||||
}
|
||||
}
|
@ -17,6 +17,9 @@ class NodeCoalescer(val handler: (Node) -> Unit) : NodeVisitor<Unit> {
|
||||
override fun visitContinue(node: Continue): Unit =
|
||||
handle(node)
|
||||
|
||||
override fun visitDoubleLiteral(node: DoubleLiteral): Unit =
|
||||
handle(node)
|
||||
|
||||
override fun visitFunctionCall(node: FunctionCall): Unit =
|
||||
handle(node)
|
||||
|
||||
@ -32,7 +35,7 @@ class NodeCoalescer(val handler: (Node) -> Unit) : NodeVisitor<Unit> {
|
||||
override fun visitInfixOperation(node: InfixOperation): Unit =
|
||||
handle(node)
|
||||
|
||||
override fun visitIntLiteral(node: IntLiteral): Unit =
|
||||
override fun visitIntegerLiteral(node: IntegerLiteral): Unit =
|
||||
handle(node)
|
||||
|
||||
override fun visitLetAssignment(node: LetAssignment): Unit =
|
||||
|
@ -11,12 +11,13 @@ enum class NodeType(val parent: NodeType? = null) {
|
||||
Continue(Expression),
|
||||
Declaration(Node),
|
||||
Definition(Node),
|
||||
DoubleLiteral(Expression),
|
||||
FunctionCall(Expression),
|
||||
FunctionDefinition(Definition),
|
||||
If(Expression),
|
||||
ImportDeclaration(Declaration),
|
||||
InfixOperation(Expression),
|
||||
IntLiteral(Expression),
|
||||
IntegerLiteral(Expression),
|
||||
LetAssignment(Expression),
|
||||
ListLiteral(Expression),
|
||||
Native(Node),
|
||||
|
@ -12,6 +12,8 @@ interface NodeVisitor<T> {
|
||||
|
||||
fun visitContinue(node: Continue): T
|
||||
|
||||
fun visitDoubleLiteral(node: DoubleLiteral): T
|
||||
|
||||
fun visitFunctionCall(node: FunctionCall): T
|
||||
|
||||
fun visitFunctionDefinition(node: FunctionDefinition): T
|
||||
@ -22,7 +24,7 @@ interface NodeVisitor<T> {
|
||||
|
||||
fun visitInfixOperation(node: InfixOperation): T
|
||||
|
||||
fun visitIntLiteral(node: IntLiteral): T
|
||||
fun visitIntegerLiteral(node: IntegerLiteral): T
|
||||
|
||||
fun visitLetAssignment(node: LetAssignment): T
|
||||
|
||||
|
@ -13,7 +13,8 @@ fun <T> NodeVisitor<T>.visit(node: Node): T =
|
||||
is FunctionDefinition -> visitFunctionDefinition(node)
|
||||
is If -> visitIf(node)
|
||||
is ImportDeclaration -> visitImportDeclaration(node)
|
||||
is IntLiteral -> visitIntLiteral(node)
|
||||
is IntegerLiteral -> visitIntegerLiteral(node)
|
||||
is DoubleLiteral -> visitDoubleLiteral(node)
|
||||
is ListLiteral -> visitListLiteral(node)
|
||||
is Parentheses -> visitParentheses(node)
|
||||
is PrefixOperation -> visitPrefixOperation(node)
|
||||
|
Reference in New Issue
Block a user