diff --git a/ast/src/main/ast/pork.yml b/ast/src/main/ast/pork.yml index 76e763a..5adb4e8 100644 --- a/ast/src/main/ast/pork.yml +++ b/ast/src/main/ast/pork.yml @@ -157,8 +157,8 @@ types: type: List - name: block type: Block? - - name: native - type: Native? + - name: nativeFunctionDescriptor + type: NativeFunctionDescriptor? LetDefinition: parent: Definition namedElementValue: symbol @@ -303,7 +303,7 @@ types: NoneLiteral: parent: Expression values: [] - Native: + NativeFunctionDescriptor: parent: Node values: - name: form diff --git a/ast/src/main/graph/types.dot b/ast/src/main/graph/types.dot index 70d086e..397001e 100644 --- a/ast/src/main/graph/types.dot +++ b/ast/src/main/graph/types.dot @@ -37,7 +37,7 @@ digraph A { type_Break [shape=box,label="Break"] type_Continue [shape=box,label="Continue"] type_NoneLiteral [shape=box,label="NoneLiteral"] - type_Native [shape=box,label="Native"] + type_NativeFunctionDescriptor [shape=box,label="NativeFunctionDescriptor"] type_IndexedBy [shape=box,label="IndexedBy"] type_Node -> type_Expression type_Node -> type_Symbol @@ -48,7 +48,7 @@ digraph A { type_Node -> type_ArgumentSpec type_Node -> type_ImportPath type_Node -> type_ForInItem - type_Node -> type_Native + type_Node -> type_NativeFunctionDescriptor type_Expression -> type_LetAssignment type_Expression -> type_VarAssignment type_Expression -> type_SetAssignment @@ -94,7 +94,7 @@ digraph A { type_FunctionDefinition -> type_Symbol [style=dotted] type_FunctionDefinition -> type_ArgumentSpec [style=dotted] type_FunctionDefinition -> type_Block [style=dotted] - type_FunctionDefinition -> type_Native [style=dotted] + type_FunctionDefinition -> type_NativeFunctionDescriptor [style=dotted] type_LetDefinition -> type_DefinitionModifiers [style=dotted] type_LetDefinition -> type_Symbol [style=dotted] type_LetDefinition -> type_Expression [style=dotted] @@ -116,7 +116,7 @@ digraph A { type_ForIn -> type_ForInItem [style=dotted] type_ForIn -> type_Expression [style=dotted] type_ForIn -> type_Block [style=dotted] - type_Native -> type_Symbol [style=dotted] - type_Native -> type_StringLiteral [style=dotted] + type_NativeFunctionDescriptor -> type_Symbol [style=dotted] + type_NativeFunctionDescriptor -> type_StringLiteral [style=dotted] type_IndexedBy -> type_Expression [style=dotted] } diff --git a/ast/src/main/kotlin/gay/pizza/pork/ast/gen/FunctionDefinition.kt b/ast/src/main/kotlin/gay/pizza/pork/ast/gen/FunctionDefinition.kt index 5b00f66..32c1a19 100644 --- a/ast/src/main/kotlin/gay/pizza/pork/ast/gen/FunctionDefinition.kt +++ b/ast/src/main/kotlin/gay/pizza/pork/ast/gen/FunctionDefinition.kt @@ -6,18 +6,18 @@ import kotlinx.serialization.Serializable @Serializable @SerialName("functionDefinition") -class FunctionDefinition(override val modifiers: DefinitionModifiers, override val symbol: Symbol, val arguments: List, val block: Block?, val native: Native?) : Definition() { +class FunctionDefinition(override val modifiers: DefinitionModifiers, override val symbol: Symbol, val arguments: List, val block: Block?, val nativeFunctionDescriptor: NativeFunctionDescriptor?) : Definition() { override val type: NodeType = NodeType.FunctionDefinition override fun visitChildren(visitor: NodeVisitor): List = - visitor.visitAll(listOf(symbol), arguments, listOf(block), listOf(native)) + visitor.visitAll(listOf(symbol), arguments, listOf(block), listOf(nativeFunctionDescriptor)) override fun visit(visitor: NodeVisitor): 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 && other.native == native + return other.modifiers == modifiers && other.symbol == symbol && other.arguments == arguments && other.block == block && other.nativeFunctionDescriptor == nativeFunctionDescriptor } override fun hashCode(): Int { @@ -25,7 +25,7 @@ class FunctionDefinition(override val modifiers: DefinitionModifiers, override v result = 31 * result + symbol.hashCode() result = 31 * result + arguments.hashCode() result = 31 * result + block.hashCode() - result = 31 * result + native.hashCode() + result = 31 * result + nativeFunctionDescriptor.hashCode() result = 31 * result + type.hashCode() return result } diff --git a/ast/src/main/kotlin/gay/pizza/pork/ast/gen/Native.kt b/ast/src/main/kotlin/gay/pizza/pork/ast/gen/NativeFunctionDescriptor.kt similarity index 67% rename from ast/src/main/kotlin/gay/pizza/pork/ast/gen/Native.kt rename to ast/src/main/kotlin/gay/pizza/pork/ast/gen/NativeFunctionDescriptor.kt index e674ad3..1f335b3 100644 --- a/ast/src/main/kotlin/gay/pizza/pork/ast/gen/Native.kt +++ b/ast/src/main/kotlin/gay/pizza/pork/ast/gen/NativeFunctionDescriptor.kt @@ -5,18 +5,18 @@ import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable -@SerialName("native") -class Native(val form: Symbol, val definitions: List) : Node() { - override val type: NodeType = NodeType.Native +@SerialName("nativeFunctionDescriptor") +class NativeFunctionDescriptor(val form: Symbol, val definitions: List) : Node() { + override val type: NodeType = NodeType.NativeFunctionDescriptor override fun visitChildren(visitor: NodeVisitor): List = visitor.visitAll(listOf(form), definitions) override fun visit(visitor: NodeVisitor): T = - visitor.visitNative(this) + visitor.visitNativeFunctionDescriptor(this) override fun equals(other: Any?): Boolean { - if (other !is Native) return false + if (other !is NativeFunctionDescriptor) return false return other.form == form && other.definitions == definitions } diff --git a/ast/src/main/kotlin/gay/pizza/pork/ast/gen/NodeCoalescer.kt b/ast/src/main/kotlin/gay/pizza/pork/ast/gen/NodeCoalescer.kt index 11ae5de..19c0d62 100644 --- a/ast/src/main/kotlin/gay/pizza/pork/ast/gen/NodeCoalescer.kt +++ b/ast/src/main/kotlin/gay/pizza/pork/ast/gen/NodeCoalescer.kt @@ -65,7 +65,7 @@ class NodeCoalescer(val followChildren: Boolean = true, val handler: (Node) -> U override fun visitLongLiteral(node: LongLiteral): Unit = handle(node) - override fun visitNative(node: Native): Unit = + override fun visitNativeFunctionDescriptor(node: NativeFunctionDescriptor): Unit = handle(node) override fun visitNoneLiteral(node: NoneLiteral): Unit = diff --git a/ast/src/main/kotlin/gay/pizza/pork/ast/gen/NodeParser.kt b/ast/src/main/kotlin/gay/pizza/pork/ast/gen/NodeParser.kt index 5fb0c21..7118477 100644 --- a/ast/src/main/kotlin/gay/pizza/pork/ast/gen/NodeParser.kt +++ b/ast/src/main/kotlin/gay/pizza/pork/ast/gen/NodeParser.kt @@ -50,7 +50,7 @@ interface NodeParser { fun parseLongLiteral(): LongLiteral - fun parseNative(): Native + fun parseNativeFunctionDescriptor(): NativeFunctionDescriptor fun parseNoneLiteral(): NoneLiteral diff --git a/ast/src/main/kotlin/gay/pizza/pork/ast/gen/NodeParserExtensions.kt b/ast/src/main/kotlin/gay/pizza/pork/ast/gen/NodeParserExtensions.kt index fd027c5..4f637b7 100644 --- a/ast/src/main/kotlin/gay/pizza/pork/ast/gen/NodeParserExtensions.kt +++ b/ast/src/main/kotlin/gay/pizza/pork/ast/gen/NodeParserExtensions.kt @@ -36,7 +36,7 @@ fun NodeParser.parse(type: NodeType): Node = NodeType.Break -> parseBreak() NodeType.Continue -> parseContinue() NodeType.NoneLiteral -> parseNoneLiteral() - NodeType.Native -> parseNative() + NodeType.NativeFunctionDescriptor -> parseNativeFunctionDescriptor() NodeType.IndexedBy -> parseIndexedBy() else -> throw RuntimeException("Unable to automatically parse type: ${type.name}") } diff --git a/ast/src/main/kotlin/gay/pizza/pork/ast/gen/NodeType.kt b/ast/src/main/kotlin/gay/pizza/pork/ast/gen/NodeType.kt index 3e2ca7f..5222510 100644 --- a/ast/src/main/kotlin/gay/pizza/pork/ast/gen/NodeType.kt +++ b/ast/src/main/kotlin/gay/pizza/pork/ast/gen/NodeType.kt @@ -27,7 +27,7 @@ enum class NodeType(val parent: NodeType? = null) { LetDefinition(Definition), ListLiteral(Expression), LongLiteral(Expression), - Native(Node), + NativeFunctionDescriptor(Node), NoneLiteral(Expression), Parentheses(Expression), PrefixOperation(Expression), diff --git a/ast/src/main/kotlin/gay/pizza/pork/ast/gen/NodeVisitor.kt b/ast/src/main/kotlin/gay/pizza/pork/ast/gen/NodeVisitor.kt index 9a8b156..5155b62 100644 --- a/ast/src/main/kotlin/gay/pizza/pork/ast/gen/NodeVisitor.kt +++ b/ast/src/main/kotlin/gay/pizza/pork/ast/gen/NodeVisitor.kt @@ -44,7 +44,7 @@ interface NodeVisitor { fun visitLongLiteral(node: LongLiteral): T - fun visitNative(node: Native): T + fun visitNativeFunctionDescriptor(node: NativeFunctionDescriptor): T fun visitNoneLiteral(node: NoneLiteral): T diff --git a/ast/src/main/kotlin/gay/pizza/pork/ast/gen/NodeVisitorExtensions.kt b/ast/src/main/kotlin/gay/pizza/pork/ast/gen/NodeVisitorExtensions.kt index 5b71861..1e12882 100644 --- a/ast/src/main/kotlin/gay/pizza/pork/ast/gen/NodeVisitorExtensions.kt +++ b/ast/src/main/kotlin/gay/pizza/pork/ast/gen/NodeVisitorExtensions.kt @@ -33,7 +33,7 @@ fun NodeVisitor.visit(node: Node): T = is Break -> visitBreak(node) is Continue -> visitContinue(node) is NoneLiteral -> visitNoneLiteral(node) - is Native -> visitNative(node) + is NativeFunctionDescriptor -> visitNativeFunctionDescriptor(node) is IndexedBy -> visitIndexedBy(node) } diff --git a/buildext/build.gradle.kts b/buildext/build.gradle.kts index 46cb9bf..a2c6ea0 100644 --- a/buildext/build.gradle.kts +++ b/buildext/build.gradle.kts @@ -12,8 +12,8 @@ repositories { } dependencies { - implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.10") - implementation("org.jetbrains.kotlin:kotlin-serialization:1.9.10") + implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.20") + implementation("org.jetbrains.kotlin:kotlin-serialization:1.9.20") implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3") implementation("com.charleskorn.kaml:kaml:0.55.0") } diff --git a/evaluator/src/main/kotlin/gay/pizza/pork/evaluator/EvaluationVisitor.kt b/evaluator/src/main/kotlin/gay/pizza/pork/evaluator/EvaluationVisitor.kt index b6290cf..5b55760 100644 --- a/evaluator/src/main/kotlin/gay/pizza/pork/evaluator/EvaluationVisitor.kt +++ b/evaluator/src/main/kotlin/gay/pizza/pork/evaluator/EvaluationVisitor.kt @@ -414,8 +414,8 @@ class EvaluationVisitor(root: Scope, val stack: CallStack) : NodeVisitor { topLevelUsedError("CompilationUnit", "CompilationUnitContext") } - override fun visitNative(node: Native): Any { - topLevelUsedError("Native", "FunctionContext") + override fun visitNativeFunctionDescriptor(node: NativeFunctionDescriptor): Any { + topLevelUsedError("NativeFunctionDescriptor", "FunctionContext") } override fun visitNoneLiteral(node: NoneLiteral): Any = None diff --git a/evaluator/src/main/kotlin/gay/pizza/pork/evaluator/FunctionContext.kt b/evaluator/src/main/kotlin/gay/pizza/pork/evaluator/FunctionContext.kt index 832097a..af24bbb 100644 --- a/evaluator/src/main/kotlin/gay/pizza/pork/evaluator/FunctionContext.kt +++ b/evaluator/src/main/kotlin/gay/pizza/pork/evaluator/FunctionContext.kt @@ -5,10 +5,10 @@ import gay.pizza.pork.ast.gen.FunctionDefinition class FunctionContext(val compilationUnitContext: CompilationUnitContext, val node: FunctionDefinition) : CallableFunction { val name: String = "${compilationUnitContext.name} ${node.symbol.id}" - private fun resolveMaybeNative(): CallableFunction? = if (node.native == null) { + private fun resolveMaybeNative(): CallableFunction? = if (node.nativeFunctionDescriptor == null) { null } else { - val native = node.native!! + val native = node.nativeFunctionDescriptor!! val nativeFunctionProvider = compilationUnitContext.evaluator.nativeFunctionProvider(native.form.id) nativeFunctionProvider.provideNativeFunction(native.definitions.map { it.text }, node.arguments, compilationUnitContext) diff --git a/ffi/src/main/kotlin/gay/pizza/pork/ffi/JavaAutogen.kt b/ffi/src/main/kotlin/gay/pizza/pork/ffi/JavaAutogen.kt index f4a27c8..0bdb5bf 100644 --- a/ffi/src/main/kotlin/gay/pizza/pork/ffi/JavaAutogen.kt +++ b/ffi/src/main/kotlin/gay/pizza/pork/ffi/JavaAutogen.kt @@ -150,12 +150,12 @@ class JavaAutogen(val javaClass: Class<*>) { multiple = false ) }, - native = asNative(functionDefinition), + nativeFunctionDescriptor = asNative(functionDefinition), block = null ) - private fun asNative(functionDefinition: JavaFunctionDefinition): Native = - Native(Symbol("java"), functionDefinition.encode().map { StringLiteral(it) }) + private fun asNative(functionDefinition: JavaFunctionDefinition): NativeFunctionDescriptor = + NativeFunctionDescriptor(Symbol("java"), functionDefinition.encode().map { StringLiteral(it) }) private fun discriminate(parameter: Parameter): String = parameter.type.simpleName.lowercase().replace("[]", "_array") diff --git a/parser/src/main/kotlin/gay/pizza/pork/parser/Parser.kt b/parser/src/main/kotlin/gay/pizza/pork/parser/Parser.kt index 56cdc20..0a800bc 100644 --- a/parser/src/main/kotlin/gay/pizza/pork/parser/Parser.kt +++ b/parser/src/main/kotlin/gay/pizza/pork/parser/Parser.kt @@ -213,10 +213,10 @@ class Parser(source: TokenSource, attribution: NodeAttribution) : } expect(TokenType.RightParentheses) - var native: Native? = null + var native: NativeFunctionDescriptor? = null var block: Block? = null if (peek(TokenType.Native)) { - native = parseNative() + native = parseNativeFunctionDescriptor() } else { block = parseBlock() } @@ -305,13 +305,13 @@ class Parser(source: TokenSource, attribution: NodeAttribution) : LongLiteral(it.text.toLong()) } - override fun parseNative(): Native = expect(NodeType.Native, TokenType.Native) { + override fun parseNativeFunctionDescriptor(): NativeFunctionDescriptor = expect(NodeType.NativeFunctionDescriptor, TokenType.Native) { val form = parseSymbol() val definitions = mutableListOf() while (peek(TokenType.Quote)) { definitions.add(parseStringLiteral()) } - Native(form, definitions) + NativeFunctionDescriptor(form, definitions) } override fun parseNoneLiteral(): NoneLiteral = expect(NodeType.NoneLiteral, TokenType.None) { diff --git a/parser/src/main/kotlin/gay/pizza/pork/parser/Printer.kt b/parser/src/main/kotlin/gay/pizza/pork/parser/Printer.kt index 9ee5f94..1dfaec6 100644 --- a/parser/src/main/kotlin/gay/pizza/pork/parser/Printer.kt +++ b/parser/src/main/kotlin/gay/pizza/pork/parser/Printer.kt @@ -78,7 +78,7 @@ class Printer(buffer: StringBuilder) : NodeVisitor { append(node.value.toString()) } - override fun visitNative(node: Native) { + override fun visitNativeFunctionDescriptor(node: NativeFunctionDescriptor) { append("native ") visit(node.form) append(" ") @@ -208,8 +208,8 @@ class Printer(buffer: StringBuilder) : NodeVisitor { visit(node.block!!) } - if (node.native != null) { - visit(node.native!!) + if (node.nativeFunctionDescriptor != null) { + visit(node.nativeFunctionDescriptor!!) } } diff --git a/stdlib/src/main/pork/ffi/struct.pork b/stdlib/src/main/pork/ffi/struct.pork index bc2f59a..6de85db 100644 --- a/stdlib/src/main/pork/ffi/struct.pork +++ b/stdlib/src/main/pork/ffi/struct.pork @@ -4,8 +4,8 @@ export func ffiStructDefine(items...) export func ffiStructAllocate(struct) native ffi "internal" "ffiStructAllocate" -export func ffiStructValue(struct, field, value) +export func ffiStructValue(def, field, value) native ffi "internal" "ffiStructValue" -export func ffiStructBytes(struct, value) +export func ffiStructBytes(def, value) native ffi "internal" "ffiStructBytes" diff --git a/tokenizer/src/main/kotlin/gay/pizza/pork/tokenizer/TokenType.kt b/tokenizer/src/main/kotlin/gay/pizza/pork/tokenizer/TokenType.kt index 32bd769..f132fa3 100644 --- a/tokenizer/src/main/kotlin/gay/pizza/pork/tokenizer/TokenType.kt +++ b/tokenizer/src/main/kotlin/gay/pizza/pork/tokenizer/TokenType.kt @@ -76,6 +76,7 @@ enum class TokenType(vararg val properties: TokenTypeProperty) { ))), BlockComment(CharConsume(MatchedCharConsumer("/*", "*/")), CommentFamily), LineComment(CharConsume(MatchedCharConsumer("//", "\n", AllowEofTermination)), CommentFamily), + Struct(ManyChars("struct"), KeywordFamily), EndOfFile; val promotions: List =