language: floating point support

This commit is contained in:
2023-09-09 00:08:30 -04:00
parent bf474f6b69
commit e8766323ee
19 changed files with 187 additions and 39 deletions

View File

@ -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:

View File

@ -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
}

View 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
}
}

View File

@ -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 =

View File

@ -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),

View File

@ -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

View File

@ -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)