mirror of
				https://github.com/GayPizzaSpecifications/pork.git
				synced 2025-11-03 17:39:38 +00:00 
			
		
		
		
	implement support for type definitions
This commit is contained in:
		@ -330,6 +330,13 @@ types:
 | 
				
			|||||||
      type: Symbol
 | 
					      type: Symbol
 | 
				
			||||||
    - name: definitions
 | 
					    - name: definitions
 | 
				
			||||||
      type: List<StringLiteral>
 | 
					      type: List<StringLiteral>
 | 
				
			||||||
 | 
					  NativeTypeDescriptor:
 | 
				
			||||||
 | 
					    parent: Node
 | 
				
			||||||
 | 
					    values:
 | 
				
			||||||
 | 
					    - name: form
 | 
				
			||||||
 | 
					      type: Symbol
 | 
				
			||||||
 | 
					    - name: definitions
 | 
				
			||||||
 | 
					      type: List<StringLiteral>
 | 
				
			||||||
  IndexedBy:
 | 
					  IndexedBy:
 | 
				
			||||||
    parent: Expression
 | 
					    parent: Expression
 | 
				
			||||||
    values:
 | 
					    values:
 | 
				
			||||||
@ -337,3 +344,13 @@ types:
 | 
				
			|||||||
      type: Expression
 | 
					      type: Expression
 | 
				
			||||||
    - name: index
 | 
					    - name: index
 | 
				
			||||||
      type: Expression
 | 
					      type: Expression
 | 
				
			||||||
 | 
					  TypeDefinition:
 | 
				
			||||||
 | 
					    parent: Definition
 | 
				
			||||||
 | 
					    namedElementValue: symbol
 | 
				
			||||||
 | 
					    values:
 | 
				
			||||||
 | 
					    - name: modifiers
 | 
				
			||||||
 | 
					      type: DefinitionModifiers
 | 
				
			||||||
 | 
					    - name: symbol
 | 
				
			||||||
 | 
					      type: Symbol
 | 
				
			||||||
 | 
					    - name: nativeTypeDescriptor
 | 
				
			||||||
 | 
					      type: NativeTypeDescriptor?
 | 
				
			||||||
 | 
				
			|||||||
@ -40,7 +40,9 @@ digraph A {
 | 
				
			|||||||
  type_Return [shape=box,label="Return"]
 | 
					  type_Return [shape=box,label="Return"]
 | 
				
			||||||
  type_NoneLiteral [shape=box,label="NoneLiteral"]
 | 
					  type_NoneLiteral [shape=box,label="NoneLiteral"]
 | 
				
			||||||
  type_NativeFunctionDescriptor [shape=box,label="NativeFunctionDescriptor"]
 | 
					  type_NativeFunctionDescriptor [shape=box,label="NativeFunctionDescriptor"]
 | 
				
			||||||
 | 
					  type_NativeTypeDescriptor [shape=box,label="NativeTypeDescriptor"]
 | 
				
			||||||
  type_IndexedBy [shape=box,label="IndexedBy"]
 | 
					  type_IndexedBy [shape=box,label="IndexedBy"]
 | 
				
			||||||
 | 
					  type_TypeDefinition [shape=box,label="TypeDefinition"]
 | 
				
			||||||
  type_Node -> type_Expression
 | 
					  type_Node -> type_Expression
 | 
				
			||||||
  type_Node -> type_Symbol
 | 
					  type_Node -> type_Symbol
 | 
				
			||||||
  type_Node -> type_Declaration
 | 
					  type_Node -> type_Declaration
 | 
				
			||||||
@ -52,6 +54,7 @@ digraph A {
 | 
				
			|||||||
  type_Node -> type_ImportPath
 | 
					  type_Node -> type_ImportPath
 | 
				
			||||||
  type_Node -> type_ForInItem
 | 
					  type_Node -> type_ForInItem
 | 
				
			||||||
  type_Node -> type_NativeFunctionDescriptor
 | 
					  type_Node -> type_NativeFunctionDescriptor
 | 
				
			||||||
 | 
					  type_Node -> type_NativeTypeDescriptor
 | 
				
			||||||
  type_Expression -> type_LetAssignment
 | 
					  type_Expression -> type_LetAssignment
 | 
				
			||||||
  type_Expression -> type_VarAssignment
 | 
					  type_Expression -> type_VarAssignment
 | 
				
			||||||
  type_Expression -> type_SetAssignment
 | 
					  type_Expression -> type_SetAssignment
 | 
				
			||||||
@ -77,6 +80,7 @@ digraph A {
 | 
				
			|||||||
  type_Expression -> type_IndexedBy
 | 
					  type_Expression -> type_IndexedBy
 | 
				
			||||||
  type_Definition -> type_FunctionDefinition
 | 
					  type_Definition -> type_FunctionDefinition
 | 
				
			||||||
  type_Definition -> type_LetDefinition
 | 
					  type_Definition -> type_LetDefinition
 | 
				
			||||||
 | 
					  type_Definition -> type_TypeDefinition
 | 
				
			||||||
  type_Declaration -> type_ImportDeclaration
 | 
					  type_Declaration -> type_ImportDeclaration
 | 
				
			||||||
  type_Definition -> type_Symbol [style=dotted]
 | 
					  type_Definition -> type_Symbol [style=dotted]
 | 
				
			||||||
  type_Definition -> type_DefinitionModifiers [style=dotted]
 | 
					  type_Definition -> type_DefinitionModifiers [style=dotted]
 | 
				
			||||||
@ -129,5 +133,10 @@ digraph A {
 | 
				
			|||||||
  type_Return -> type_Expression [style=dotted]
 | 
					  type_Return -> type_Expression [style=dotted]
 | 
				
			||||||
  type_NativeFunctionDescriptor -> type_Symbol [style=dotted]
 | 
					  type_NativeFunctionDescriptor -> type_Symbol [style=dotted]
 | 
				
			||||||
  type_NativeFunctionDescriptor -> type_StringLiteral [style=dotted]
 | 
					  type_NativeFunctionDescriptor -> type_StringLiteral [style=dotted]
 | 
				
			||||||
 | 
					  type_NativeTypeDescriptor -> type_Symbol [style=dotted]
 | 
				
			||||||
 | 
					  type_NativeTypeDescriptor -> type_StringLiteral [style=dotted]
 | 
				
			||||||
  type_IndexedBy -> type_Expression [style=dotted]
 | 
					  type_IndexedBy -> type_Expression [style=dotted]
 | 
				
			||||||
 | 
					  type_TypeDefinition -> type_DefinitionModifiers [style=dotted]
 | 
				
			||||||
 | 
					  type_TypeDefinition -> type_Symbol [style=dotted]
 | 
				
			||||||
 | 
					  type_TypeDefinition -> type_NativeTypeDescriptor [style=dotted]
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -23,6 +23,10 @@ abstract class FunctionLevelVisitor<T> : NodeVisitor<T> {
 | 
				
			|||||||
    topLevelUsedError("FunctionDefinition")
 | 
					    topLevelUsedError("FunctionDefinition")
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  override fun visitTypeDefinition(node: TypeDefinition): T {
 | 
				
			||||||
 | 
					    topLevelUsedError("TypeDefinition")
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  override fun visitImportDeclaration(node: ImportDeclaration): T {
 | 
					  override fun visitImportDeclaration(node: ImportDeclaration): T {
 | 
				
			||||||
    topLevelUsedError("ImportDeclaration")
 | 
					    topLevelUsedError("ImportDeclaration")
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@ -39,6 +43,10 @@ abstract class FunctionLevelVisitor<T> : NodeVisitor<T> {
 | 
				
			|||||||
    topLevelUsedError("NativeFunctionDescriptor")
 | 
					    topLevelUsedError("NativeFunctionDescriptor")
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  override fun visitNativeTypeDescriptor(node: NativeTypeDescriptor): T {
 | 
				
			||||||
 | 
					    topLevelUsedError("NativeTypeDescriptor")
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  private fun topLevelUsedError(name: String): Nothing {
 | 
					  private fun topLevelUsedError(name: String): Nothing {
 | 
				
			||||||
    throw RuntimeException("$name cannot be visited in a FunctionVisitor.")
 | 
					    throw RuntimeException("$name cannot be visited in a FunctionVisitor.")
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
				
			|||||||
@ -0,0 +1,29 @@
 | 
				
			|||||||
 | 
					// GENERATED CODE FROM PORK AST CODEGEN
 | 
				
			||||||
 | 
					package gay.pizza.pork.ast.gen
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import kotlinx.serialization.SerialName
 | 
				
			||||||
 | 
					import kotlinx.serialization.Serializable
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@Serializable
 | 
				
			||||||
 | 
					@SerialName("nativeTypeDescriptor")
 | 
				
			||||||
 | 
					class NativeTypeDescriptor(val form: Symbol, val definitions: List<StringLiteral>) : Node() {
 | 
				
			||||||
 | 
					  override val type: NodeType = NodeType.NativeTypeDescriptor
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  override fun <T> visitChildren(visitor: NodeVisitor<T>): List<T> =
 | 
				
			||||||
 | 
					    visitor.visitAll(listOf(form), definitions)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  override fun <T> visit(visitor: NodeVisitor<T>): T =
 | 
				
			||||||
 | 
					    visitor.visitNativeTypeDescriptor(this)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  override fun equals(other: Any?): Boolean {
 | 
				
			||||||
 | 
					    if (other !is NativeTypeDescriptor) return false
 | 
				
			||||||
 | 
					    return other.form == form && other.definitions == definitions
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  override fun hashCode(): Int {
 | 
				
			||||||
 | 
					    var result = form.hashCode()
 | 
				
			||||||
 | 
					    result = 31 * result + definitions.hashCode()
 | 
				
			||||||
 | 
					    result = 31 * result + type.hashCode()
 | 
				
			||||||
 | 
					    return result
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -68,6 +68,9 @@ class NodeCoalescer(val followChildren: Boolean = true, val handler: (Node) -> U
 | 
				
			|||||||
  override fun visitNativeFunctionDescriptor(node: NativeFunctionDescriptor): Unit =
 | 
					  override fun visitNativeFunctionDescriptor(node: NativeFunctionDescriptor): Unit =
 | 
				
			||||||
    handle(node)
 | 
					    handle(node)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  override fun visitNativeTypeDescriptor(node: NativeTypeDescriptor): Unit =
 | 
				
			||||||
 | 
					    handle(node)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  override fun visitNoneLiteral(node: NoneLiteral): Unit =
 | 
					  override fun visitNoneLiteral(node: NoneLiteral): Unit =
 | 
				
			||||||
    handle(node)
 | 
					    handle(node)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -95,6 +98,9 @@ class NodeCoalescer(val followChildren: Boolean = true, val handler: (Node) -> U
 | 
				
			|||||||
  override fun visitSymbolReference(node: SymbolReference): Unit =
 | 
					  override fun visitSymbolReference(node: SymbolReference): Unit =
 | 
				
			||||||
    handle(node)
 | 
					    handle(node)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  override fun visitTypeDefinition(node: TypeDefinition): Unit =
 | 
				
			||||||
 | 
					    handle(node)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  override fun visitTypeSpec(node: TypeSpec): Unit =
 | 
					  override fun visitTypeSpec(node: TypeSpec): Unit =
 | 
				
			||||||
    handle(node)
 | 
					    handle(node)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -52,6 +52,8 @@ interface NodeParser {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  fun parseNativeFunctionDescriptor(): NativeFunctionDescriptor
 | 
					  fun parseNativeFunctionDescriptor(): NativeFunctionDescriptor
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  fun parseNativeTypeDescriptor(): NativeTypeDescriptor
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  fun parseNoneLiteral(): NoneLiteral
 | 
					  fun parseNoneLiteral(): NoneLiteral
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  fun parseParentheses(): Parentheses
 | 
					  fun parseParentheses(): Parentheses
 | 
				
			||||||
@ -70,6 +72,8 @@ interface NodeParser {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  fun parseSymbolReference(): SymbolReference
 | 
					  fun parseSymbolReference(): SymbolReference
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  fun parseTypeDefinition(): TypeDefinition
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  fun parseTypeSpec(): TypeSpec
 | 
					  fun parseTypeSpec(): TypeSpec
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  fun parseVarAssignment(): VarAssignment
 | 
					  fun parseVarAssignment(): VarAssignment
 | 
				
			||||||
 | 
				
			|||||||
@ -39,6 +39,8 @@ fun NodeParser.parse(type: NodeType): Node =
 | 
				
			|||||||
    NodeType.Return -> parseReturn()
 | 
					    NodeType.Return -> parseReturn()
 | 
				
			||||||
    NodeType.NoneLiteral -> parseNoneLiteral()
 | 
					    NodeType.NoneLiteral -> parseNoneLiteral()
 | 
				
			||||||
    NodeType.NativeFunctionDescriptor -> parseNativeFunctionDescriptor()
 | 
					    NodeType.NativeFunctionDescriptor -> parseNativeFunctionDescriptor()
 | 
				
			||||||
 | 
					    NodeType.NativeTypeDescriptor -> parseNativeTypeDescriptor()
 | 
				
			||||||
    NodeType.IndexedBy -> parseIndexedBy()
 | 
					    NodeType.IndexedBy -> parseIndexedBy()
 | 
				
			||||||
 | 
					    NodeType.TypeDefinition -> parseTypeDefinition()
 | 
				
			||||||
    else -> throw RuntimeException("Unable to automatically parse type: ${type.name}")
 | 
					    else -> throw RuntimeException("Unable to automatically parse type: ${type.name}")
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
				
			|||||||
@ -28,6 +28,7 @@ enum class NodeType(val parent: NodeType? = null) {
 | 
				
			|||||||
  ListLiteral(Expression),
 | 
					  ListLiteral(Expression),
 | 
				
			||||||
  LongLiteral(Expression),
 | 
					  LongLiteral(Expression),
 | 
				
			||||||
  NativeFunctionDescriptor(Node),
 | 
					  NativeFunctionDescriptor(Node),
 | 
				
			||||||
 | 
					  NativeTypeDescriptor(Node),
 | 
				
			||||||
  NoneLiteral(Expression),
 | 
					  NoneLiteral(Expression),
 | 
				
			||||||
  Parentheses(Expression),
 | 
					  Parentheses(Expression),
 | 
				
			||||||
  PrefixOperation(Expression),
 | 
					  PrefixOperation(Expression),
 | 
				
			||||||
@ -37,6 +38,7 @@ enum class NodeType(val parent: NodeType? = null) {
 | 
				
			|||||||
  SuffixOperation(Expression),
 | 
					  SuffixOperation(Expression),
 | 
				
			||||||
  Symbol(Node),
 | 
					  Symbol(Node),
 | 
				
			||||||
  SymbolReference(Expression),
 | 
					  SymbolReference(Expression),
 | 
				
			||||||
 | 
					  TypeDefinition(Definition),
 | 
				
			||||||
  TypeSpec(Node),
 | 
					  TypeSpec(Node),
 | 
				
			||||||
  VarAssignment(Expression),
 | 
					  VarAssignment(Expression),
 | 
				
			||||||
  While(Expression)
 | 
					  While(Expression)
 | 
				
			||||||
 | 
				
			|||||||
@ -46,6 +46,8 @@ interface NodeVisitor<T> {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  fun visitNativeFunctionDescriptor(node: NativeFunctionDescriptor): T
 | 
					  fun visitNativeFunctionDescriptor(node: NativeFunctionDescriptor): T
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  fun visitNativeTypeDescriptor(node: NativeTypeDescriptor): T
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  fun visitNoneLiteral(node: NoneLiteral): T
 | 
					  fun visitNoneLiteral(node: NoneLiteral): T
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  fun visitParentheses(node: Parentheses): T
 | 
					  fun visitParentheses(node: Parentheses): T
 | 
				
			||||||
@ -64,6 +66,8 @@ interface NodeVisitor<T> {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  fun visitSymbolReference(node: SymbolReference): T
 | 
					  fun visitSymbolReference(node: SymbolReference): T
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  fun visitTypeDefinition(node: TypeDefinition): T
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  fun visitTypeSpec(node: TypeSpec): T
 | 
					  fun visitTypeSpec(node: TypeSpec): T
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  fun visitVarAssignment(node: VarAssignment): T
 | 
					  fun visitVarAssignment(node: VarAssignment): T
 | 
				
			||||||
 | 
				
			|||||||
@ -36,7 +36,9 @@ fun <T> NodeVisitor<T>.visit(node: Node): T =
 | 
				
			|||||||
    is Return -> visitReturn(node)
 | 
					    is Return -> visitReturn(node)
 | 
				
			||||||
    is NoneLiteral -> visitNoneLiteral(node)
 | 
					    is NoneLiteral -> visitNoneLiteral(node)
 | 
				
			||||||
    is NativeFunctionDescriptor -> visitNativeFunctionDescriptor(node)
 | 
					    is NativeFunctionDescriptor -> visitNativeFunctionDescriptor(node)
 | 
				
			||||||
 | 
					    is NativeTypeDescriptor -> visitNativeTypeDescriptor(node)
 | 
				
			||||||
    is IndexedBy -> visitIndexedBy(node)
 | 
					    is IndexedBy -> visitIndexedBy(node)
 | 
				
			||||||
 | 
					    is TypeDefinition -> visitTypeDefinition(node)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fun <T> NodeVisitor<T>.visitNodes(vararg nodes: Node?): List<T> =
 | 
					fun <T> NodeVisitor<T>.visitNodes(vararg nodes: Node?): List<T> =
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										30
									
								
								ast/src/main/kotlin/gay/pizza/pork/ast/gen/TypeDefinition.kt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								ast/src/main/kotlin/gay/pizza/pork/ast/gen/TypeDefinition.kt
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,30 @@
 | 
				
			|||||||
 | 
					// GENERATED CODE FROM PORK AST CODEGEN
 | 
				
			||||||
 | 
					package gay.pizza.pork.ast.gen
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import kotlinx.serialization.SerialName
 | 
				
			||||||
 | 
					import kotlinx.serialization.Serializable
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@Serializable
 | 
				
			||||||
 | 
					@SerialName("typeDefinition")
 | 
				
			||||||
 | 
					class TypeDefinition(override val modifiers: DefinitionModifiers, override val symbol: Symbol, val nativeTypeDescriptor: NativeTypeDescriptor?) : Definition() {
 | 
				
			||||||
 | 
					  override val type: NodeType = NodeType.TypeDefinition
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  override fun <T> visitChildren(visitor: NodeVisitor<T>): List<T> =
 | 
				
			||||||
 | 
					    visitor.visitNodes(symbol, nativeTypeDescriptor)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  override fun <T> visit(visitor: NodeVisitor<T>): T =
 | 
				
			||||||
 | 
					    visitor.visitTypeDefinition(this)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  override fun equals(other: Any?): Boolean {
 | 
				
			||||||
 | 
					    if (other !is TypeDefinition) return false
 | 
				
			||||||
 | 
					    return other.modifiers == modifiers && other.symbol == symbol && other.nativeTypeDescriptor == nativeTypeDescriptor
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  override fun hashCode(): Int {
 | 
				
			||||||
 | 
					    var result = modifiers.hashCode()
 | 
				
			||||||
 | 
					    result = 31 * result + symbol.hashCode()
 | 
				
			||||||
 | 
					    result = 31 * result + nativeTypeDescriptor.hashCode()
 | 
				
			||||||
 | 
					    result = 31 * result + type.hashCode()
 | 
				
			||||||
 | 
					    return result
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -3,7 +3,9 @@ package gay.pizza.pork.evaluator
 | 
				
			|||||||
import gay.pizza.pork.ast.gen.Definition
 | 
					import gay.pizza.pork.ast.gen.Definition
 | 
				
			||||||
import gay.pizza.pork.ast.gen.FunctionDefinition
 | 
					import gay.pizza.pork.ast.gen.FunctionDefinition
 | 
				
			||||||
import gay.pizza.pork.ast.gen.LetDefinition
 | 
					import gay.pizza.pork.ast.gen.LetDefinition
 | 
				
			||||||
 | 
					import gay.pizza.pork.ast.gen.TypeDefinition
 | 
				
			||||||
import gay.pizza.pork.ast.gen.visit
 | 
					import gay.pizza.pork.ast.gen.visit
 | 
				
			||||||
 | 
					import gay.pizza.pork.execution.None
 | 
				
			||||||
import gay.pizza.pork.frontend.Slab
 | 
					import gay.pizza.pork.frontend.Slab
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class SlabContext(val slab: Slab, val evaluator: Evaluator, rootScope: Scope) {
 | 
					class SlabContext(val slab: Slab, val evaluator: Evaluator, rootScope: Scope) {
 | 
				
			||||||
@ -50,6 +52,7 @@ class SlabContext(val slab: Slab, val evaluator: Evaluator, rootScope: Scope) {
 | 
				
			|||||||
      EvaluationVisitor(internalScope.fork("let ${definition.symbol.id}"), CallStack())
 | 
					      EvaluationVisitor(internalScope.fork("let ${definition.symbol.id}"), CallStack())
 | 
				
			||||||
        .visit(definition.value)
 | 
					        .visit(definition.value)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    is TypeDefinition -> None
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  private fun processFinalImportScopes() {
 | 
					  private fun processFinalImportScopes() {
 | 
				
			||||||
 | 
				
			|||||||
@ -8,11 +8,12 @@ class Parser(source: TokenSource, attribution: NodeAttribution) :
 | 
				
			|||||||
  ParserBase(source, attribution) {
 | 
					  ParserBase(source, attribution) {
 | 
				
			||||||
  override fun parseArgumentSpec(): ArgumentSpec = produce(NodeType.ArgumentSpec) {
 | 
					  override fun parseArgumentSpec(): ArgumentSpec = produce(NodeType.ArgumentSpec) {
 | 
				
			||||||
    val symbol = parseSymbol()
 | 
					    val symbol = parseSymbol()
 | 
				
			||||||
 | 
					    val multiple = next(TokenType.DotDotDot)
 | 
				
			||||||
    var typeSpec: TypeSpec? = null
 | 
					    var typeSpec: TypeSpec? = null
 | 
				
			||||||
    if (next(TokenType.Colon)) {
 | 
					    if (next(TokenType.Colon)) {
 | 
				
			||||||
      typeSpec = parseTypeSpec()
 | 
					      typeSpec = parseTypeSpec()
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    ArgumentSpec(symbol, typeSpec = typeSpec, next(TokenType.DotDotDot))
 | 
					    ArgumentSpec(symbol, typeSpec = typeSpec, multiple = multiple)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  override fun parseBlock(): Block = expect(NodeType.Block, TokenType.LeftCurly) {
 | 
					  override fun parseBlock(): Block = expect(NodeType.Block, TokenType.LeftCurly) {
 | 
				
			||||||
@ -175,6 +176,7 @@ class Parser(source: TokenSource, attribution: NodeAttribution) :
 | 
				
			|||||||
  override fun parseDefinition(): Definition =
 | 
					  override fun parseDefinition(): Definition =
 | 
				
			||||||
    when (val type = peekAheadUntilNotIn(*TokenType.DeclarationModifiers)) {
 | 
					    when (val type = peekAheadUntilNotIn(*TokenType.DeclarationModifiers)) {
 | 
				
			||||||
      TokenType.Func -> parseFunctionDefinition()
 | 
					      TokenType.Func -> parseFunctionDefinition()
 | 
				
			||||||
 | 
					      TokenType.Type -> parseTypeDefinition()
 | 
				
			||||||
      TokenType.Let -> parseLetDefinition()
 | 
					      TokenType.Let -> parseLetDefinition()
 | 
				
			||||||
      else -> throw ParseError(
 | 
					      else -> throw ParseError(
 | 
				
			||||||
        "Failed to parse token: ${type.name} as" +
 | 
					        "Failed to parse token: ${type.name} as" +
 | 
				
			||||||
@ -330,6 +332,15 @@ class Parser(source: TokenSource, attribution: NodeAttribution) :
 | 
				
			|||||||
    NativeFunctionDescriptor(form, definitions)
 | 
					    NativeFunctionDescriptor(form, definitions)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  override fun parseNativeTypeDescriptor(): NativeTypeDescriptor = expect(NodeType.NativeTypeDescriptor, TokenType.Native) {
 | 
				
			||||||
 | 
					    val form = parseSymbol()
 | 
				
			||||||
 | 
					    val definitions = mutableListOf<StringLiteral>()
 | 
				
			||||||
 | 
					    while (peek(TokenType.Quote)) {
 | 
				
			||||||
 | 
					      definitions.add(parseStringLiteral())
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    NativeTypeDescriptor(form = form, definitions = definitions)
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  override fun parseNoneLiteral(): NoneLiteral = expect(NodeType.NoneLiteral, TokenType.None) {
 | 
					  override fun parseNoneLiteral(): NoneLiteral = expect(NodeType.NoneLiteral, TokenType.None) {
 | 
				
			||||||
    NoneLiteral()
 | 
					    NoneLiteral()
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@ -390,6 +401,15 @@ class Parser(source: TokenSource, attribution: NodeAttribution) :
 | 
				
			|||||||
    SymbolReference(parseSymbol())
 | 
					    SymbolReference(parseSymbol())
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  override fun parseTypeDefinition(): TypeDefinition = produce(NodeType.TypeDefinition) {
 | 
				
			||||||
 | 
					    val definitionModifiers = parseDefinitionModifiers()
 | 
				
			||||||
 | 
					    expect(TokenType.Type)
 | 
				
			||||||
 | 
					    val name = parseSymbol()
 | 
				
			||||||
 | 
					    expect(TokenType.Equals)
 | 
				
			||||||
 | 
					    val nativeTypeDescriptor = parseNativeTypeDescriptor()
 | 
				
			||||||
 | 
					    TypeDefinition(modifiers = definitionModifiers, symbol = name, nativeTypeDescriptor = nativeTypeDescriptor)
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  override fun parseTypeSpec(): TypeSpec = produce(NodeType.TypeSpec) {
 | 
					  override fun parseTypeSpec(): TypeSpec = produce(NodeType.TypeSpec) {
 | 
				
			||||||
    TypeSpec(parseSymbol())
 | 
					    TypeSpec(parseSymbol())
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
				
			|||||||
@ -90,6 +90,18 @@ class Printer(buffer: StringBuilder) : NodeVisitor<Unit> {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  override fun visitNativeTypeDescriptor(node: NativeTypeDescriptor) {
 | 
				
			||||||
 | 
					    append("native ")
 | 
				
			||||||
 | 
					    visit(node.form)
 | 
				
			||||||
 | 
					    append(" ")
 | 
				
			||||||
 | 
					    for ((index, argument) in node.definitions.withIndex()) {
 | 
				
			||||||
 | 
					      visit(argument)
 | 
				
			||||||
 | 
					      if (index + 1 != node.definitions.size) {
 | 
				
			||||||
 | 
					        append(" ")
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  override fun visitNoneLiteral(node: NoneLiteral) {
 | 
					  override fun visitNoneLiteral(node: NoneLiteral) {
 | 
				
			||||||
    append("none")
 | 
					    append("none")
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@ -137,6 +149,16 @@ class Printer(buffer: StringBuilder) : NodeVisitor<Unit> {
 | 
				
			|||||||
    visit(node.symbol)
 | 
					    visit(node.symbol)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  override fun visitTypeDefinition(node: TypeDefinition) {
 | 
				
			||||||
 | 
					    visitDefinitionModifiers(node.modifiers)
 | 
				
			||||||
 | 
					    append("type ")
 | 
				
			||||||
 | 
					    visit(node.symbol)
 | 
				
			||||||
 | 
					    append(" = ")
 | 
				
			||||||
 | 
					    if (node.nativeTypeDescriptor != null) {
 | 
				
			||||||
 | 
					      visit(node.nativeTypeDescriptor!!)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  override fun visitTypeSpec(node: TypeSpec) {
 | 
					  override fun visitTypeSpec(node: TypeSpec) {
 | 
				
			||||||
    visit(node.symbol)
 | 
					    visit(node.symbol)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
				
			|||||||
@ -1,11 +1,17 @@
 | 
				
			|||||||
export func print(values...)
 | 
					export type int32 = native internal "int32"
 | 
				
			||||||
 | 
					export type int64 = native internal "int64"
 | 
				
			||||||
 | 
					export type string = native internal "string"
 | 
				
			||||||
 | 
					export type list = native internal "list"
 | 
				
			||||||
 | 
					export type any = native internal "any"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export func print(values...: string)
 | 
				
			||||||
  native internal "print"
 | 
					  native internal "print"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export func println(values...)
 | 
					export func println(values...: string)
 | 
				
			||||||
  native internal "println"
 | 
					  native internal "println"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export func listSet(list, index, value)
 | 
					export func listSet(list: list, index: int32, value: any)
 | 
				
			||||||
  native internal "listSet"
 | 
					  native internal "listSet"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export func listInitWith(size, value)
 | 
					export func listInitWith(size: int32, value: any)
 | 
				
			||||||
  native internal "listInitWith"
 | 
					  native internal "listInitWith"
 | 
				
			||||||
 | 
				
			|||||||
@ -0,0 +1,15 @@
 | 
				
			|||||||
 | 
					// GENERATED CODE FROM PORK AST CODEGEN
 | 
				
			||||||
 | 
					package gay.pizza.pork.idea.psi.gen
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.intellij.lang.ASTNode
 | 
				
			||||||
 | 
					import com.intellij.navigation.ItemPresentation
 | 
				
			||||||
 | 
					import gay.pizza.pork.idea.psi.PorkElementHelpers
 | 
				
			||||||
 | 
					import javax.swing.Icon
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class NativeTypeDescriptorElement(node: ASTNode) : PorkElement(node) {
 | 
				
			||||||
 | 
					  override fun getIcon(flags: Int): Icon? =
 | 
				
			||||||
 | 
					    PorkElementHelpers.iconOf(this)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  override fun getPresentation(): ItemPresentation? =
 | 
				
			||||||
 | 
					    PorkElementHelpers.presentationOf(this)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -43,7 +43,9 @@ object PorkElementFactory {
 | 
				
			|||||||
      NodeType.Return -> ReturnElement(node)
 | 
					      NodeType.Return -> ReturnElement(node)
 | 
				
			||||||
      NodeType.NoneLiteral -> NoneLiteralElement(node)
 | 
					      NodeType.NoneLiteral -> NoneLiteralElement(node)
 | 
				
			||||||
      NodeType.NativeFunctionDescriptor -> NativeFunctionDescriptorElement(node)
 | 
					      NodeType.NativeFunctionDescriptor -> NativeFunctionDescriptorElement(node)
 | 
				
			||||||
 | 
					      NodeType.NativeTypeDescriptor -> NativeTypeDescriptorElement(node)
 | 
				
			||||||
      NodeType.IndexedBy -> IndexedByElement(node)
 | 
					      NodeType.IndexedBy -> IndexedByElement(node)
 | 
				
			||||||
 | 
					      NodeType.TypeDefinition -> TypeDefinitionElement(node)
 | 
				
			||||||
      else -> ASTWrapperPsiElement(node)
 | 
					      else -> ASTWrapperPsiElement(node)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -0,0 +1,25 @@
 | 
				
			|||||||
 | 
					// GENERATED CODE FROM PORK AST CODEGEN
 | 
				
			||||||
 | 
					package gay.pizza.pork.idea.psi.gen
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.intellij.lang.ASTNode
 | 
				
			||||||
 | 
					import com.intellij.navigation.ItemPresentation
 | 
				
			||||||
 | 
					import com.intellij.psi.PsiElement
 | 
				
			||||||
 | 
					import gay.pizza.pork.idea.psi.PorkElementHelpers
 | 
				
			||||||
 | 
					import javax.swing.Icon
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class TypeDefinitionElement(node: ASTNode) : PorkNamedElement(node) {
 | 
				
			||||||
 | 
					  override fun getName(): String? =
 | 
				
			||||||
 | 
					    PorkElementHelpers.nameOfNamedElement(this)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  override fun setName(name: String): PsiElement =
 | 
				
			||||||
 | 
					    PorkElementHelpers.setNameOfNamedElement(this, name)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  override fun getNameIdentifier(): PsiElement? =
 | 
				
			||||||
 | 
					    PorkElementHelpers.nameIdentifierOfNamedElement(this)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  override fun getIcon(flags: Int): Icon? =
 | 
				
			||||||
 | 
					    PorkElementHelpers.iconOf(this)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  override fun getPresentation(): ItemPresentation? =
 | 
				
			||||||
 | 
					    PorkElementHelpers.presentationOf(this)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -67,6 +67,7 @@ enum class TokenType(vararg val properties: TokenTypeProperty) {
 | 
				
			|||||||
  Import(AnyOf("import", "impork", "porkload"), KeywordFamily),
 | 
					  Import(AnyOf("import", "impork", "porkload"), KeywordFamily),
 | 
				
			||||||
  Export(ManyChars("export"), KeywordFamily),
 | 
					  Export(ManyChars("export"), KeywordFamily),
 | 
				
			||||||
  Func(ManyChars("func"), KeywordFamily),
 | 
					  Func(ManyChars("func"), KeywordFamily),
 | 
				
			||||||
 | 
					  Type(ManyChars("type"), KeywordFamily),
 | 
				
			||||||
  Native(ManyChars("native"), KeywordFamily),
 | 
					  Native(ManyChars("native"), KeywordFamily),
 | 
				
			||||||
  Let(ManyChars("let"), KeywordFamily),
 | 
					  Let(ManyChars("let"), KeywordFamily),
 | 
				
			||||||
  Var(ManyChars("var"), KeywordFamily),
 | 
					  Var(ManyChars("var"), KeywordFamily),
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user