mirror of
				https://github.com/GayPizzaSpecifications/pork.git
				synced 2025-11-03 17:39:38 +00:00 
			
		
		
		
	language: none support
This commit is contained in:
		@ -276,6 +276,9 @@ types:
 | 
				
			|||||||
  Continue:
 | 
					  Continue:
 | 
				
			||||||
    parent: Expression
 | 
					    parent: Expression
 | 
				
			||||||
    values: []
 | 
					    values: []
 | 
				
			||||||
 | 
					  NoneLiteral:
 | 
				
			||||||
 | 
					    parent: Expression
 | 
				
			||||||
 | 
					    values: []
 | 
				
			||||||
  Native:
 | 
					  Native:
 | 
				
			||||||
    parent: Node
 | 
					    parent: Node
 | 
				
			||||||
    values:
 | 
					    values:
 | 
				
			||||||
 | 
				
			|||||||
@ -34,6 +34,7 @@ digraph A {
 | 
				
			|||||||
  type_ForIn [shape=box,label="ForIn"]
 | 
					  type_ForIn [shape=box,label="ForIn"]
 | 
				
			||||||
  type_Break [shape=box,label="Break"]
 | 
					  type_Break [shape=box,label="Break"]
 | 
				
			||||||
  type_Continue [shape=box,label="Continue"]
 | 
					  type_Continue [shape=box,label="Continue"]
 | 
				
			||||||
 | 
					  type_NoneLiteral [shape=box,label="NoneLiteral"]
 | 
				
			||||||
  type_Native [shape=box,label="Native"]
 | 
					  type_Native [shape=box,label="Native"]
 | 
				
			||||||
  type_Node -> type_Expression
 | 
					  type_Node -> type_Expression
 | 
				
			||||||
  type_Node -> type_Symbol
 | 
					  type_Node -> type_Symbol
 | 
				
			||||||
@ -62,6 +63,7 @@ digraph A {
 | 
				
			|||||||
  type_Expression -> type_ForIn
 | 
					  type_Expression -> type_ForIn
 | 
				
			||||||
  type_Expression -> type_Break
 | 
					  type_Expression -> type_Break
 | 
				
			||||||
  type_Expression -> type_Continue
 | 
					  type_Expression -> type_Continue
 | 
				
			||||||
 | 
					  type_Expression -> type_NoneLiteral
 | 
				
			||||||
  type_Definition -> type_FunctionDefinition
 | 
					  type_Definition -> type_FunctionDefinition
 | 
				
			||||||
  type_Definition -> type_LetDefinition
 | 
					  type_Definition -> type_LetDefinition
 | 
				
			||||||
  type_Declaration -> type_ImportDeclaration
 | 
					  type_Declaration -> type_ImportDeclaration
 | 
				
			||||||
 | 
				
			|||||||
@ -56,6 +56,9 @@ class NodeCoalescer(val handler: (Node) -> Unit) : NodeVisitor<Unit> {
 | 
				
			|||||||
  override fun visitNative(node: Native): Unit =
 | 
					  override fun visitNative(node: Native): Unit =
 | 
				
			||||||
    handle(node)
 | 
					    handle(node)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  override fun visitNoneLiteral(node: NoneLiteral): Unit =
 | 
				
			||||||
 | 
					    handle(node)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  override fun visitParentheses(node: Parentheses): Unit =
 | 
					  override fun visitParentheses(node: Parentheses): Unit =
 | 
				
			||||||
    handle(node)
 | 
					    handle(node)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -24,6 +24,7 @@ enum class NodeType(val parent: NodeType? = null) {
 | 
				
			|||||||
  ListLiteral(Expression),
 | 
					  ListLiteral(Expression),
 | 
				
			||||||
  LongLiteral(Expression),
 | 
					  LongLiteral(Expression),
 | 
				
			||||||
  Native(Node),
 | 
					  Native(Node),
 | 
				
			||||||
 | 
					  NoneLiteral(Expression),
 | 
				
			||||||
  Parentheses(Expression),
 | 
					  Parentheses(Expression),
 | 
				
			||||||
  PrefixOperation(Expression),
 | 
					  PrefixOperation(Expression),
 | 
				
			||||||
  SetAssignment(Expression),
 | 
					  SetAssignment(Expression),
 | 
				
			||||||
 | 
				
			|||||||
@ -38,6 +38,8 @@ interface NodeVisitor<T> {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  fun visitNative(node: Native): T
 | 
					  fun visitNative(node: Native): T
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  fun visitNoneLiteral(node: NoneLiteral): T
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  fun visitParentheses(node: Parentheses): T
 | 
					  fun visitParentheses(node: Parentheses): T
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  fun visitPrefixOperation(node: PrefixOperation): T
 | 
					  fun visitPrefixOperation(node: PrefixOperation): T
 | 
				
			||||||
 | 
				
			|||||||
@ -29,6 +29,7 @@ fun <T> NodeVisitor<T>.visit(node: Node): T =
 | 
				
			|||||||
    is ForIn -> visitForIn(node)
 | 
					    is ForIn -> visitForIn(node)
 | 
				
			||||||
    is Break -> visitBreak(node)
 | 
					    is Break -> visitBreak(node)
 | 
				
			||||||
    is Continue -> visitContinue(node)
 | 
					    is Continue -> visitContinue(node)
 | 
				
			||||||
 | 
					    is NoneLiteral -> visitNoneLiteral(node)
 | 
				
			||||||
    is Native -> visitNative(node)
 | 
					    is Native -> visitNative(node)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										22
									
								
								ast/src/main/kotlin/gay/pizza/pork/ast/NoneLiteral.kt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								ast/src/main/kotlin/gay/pizza/pork/ast/NoneLiteral.kt
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,22 @@
 | 
				
			|||||||
 | 
					// GENERATED CODE FROM PORK AST CODEGEN
 | 
				
			||||||
 | 
					package gay.pizza.pork.ast
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import kotlinx.serialization.SerialName
 | 
				
			||||||
 | 
					import kotlinx.serialization.Serializable
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@Serializable
 | 
				
			||||||
 | 
					@SerialName("noneLiteral")
 | 
				
			||||||
 | 
					class NoneLiteral : Expression() {
 | 
				
			||||||
 | 
					  override val type: NodeType = NodeType.NoneLiteral
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  override fun <T> visit(visitor: NodeVisitor<T>): T =
 | 
				
			||||||
 | 
					    visitor.visitNoneLiteral(this)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  override fun equals(other: Any?): Boolean {
 | 
				
			||||||
 | 
					    if (other !is NoneLiteral) return false
 | 
				
			||||||
 | 
					    return true
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  override fun hashCode(): Int =
 | 
				
			||||||
 | 
					    31 * type.hashCode()
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -374,6 +374,8 @@ class EvaluationVisitor(root: Scope) : NodeVisitor<Any> {
 | 
				
			|||||||
    topLevelUsedError("Native", "FunctionContext")
 | 
					    topLevelUsedError("Native", "FunctionContext")
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  override fun visitNoneLiteral(node: NoneLiteral): Any = None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  override fun visitContinue(node: Continue): Any = ContinueMarker
 | 
					  override fun visitContinue(node: Continue): Any = ContinueMarker
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  private inline fun <T> scoped(block: () -> T): T {
 | 
					  private inline fun <T> scoped(block: () -> T): T {
 | 
				
			||||||
 | 
				
			|||||||
@ -1,15 +1,18 @@
 | 
				
			|||||||
package gay.pizza.pork.ffi
 | 
					package gay.pizza.pork.ffi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.sun.jna.Function
 | 
					import com.sun.jna.Function
 | 
				
			||||||
 | 
					import com.sun.jna.NativeLibrary
 | 
				
			||||||
import com.sun.jna.Pointer
 | 
					import com.sun.jna.Pointer
 | 
				
			||||||
import gay.pizza.pork.ast.ArgumentSpec
 | 
					import gay.pizza.pork.ast.ArgumentSpec
 | 
				
			||||||
import gay.pizza.pork.evaluator.CallableFunction
 | 
					import gay.pizza.pork.evaluator.CallableFunction
 | 
				
			||||||
import gay.pizza.pork.evaluator.NativeProvider
 | 
					import gay.pizza.pork.evaluator.NativeProvider
 | 
				
			||||||
 | 
					import gay.pizza.pork.evaluator.None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class JnaNativeProvider : NativeProvider {
 | 
					class JnaNativeProvider : NativeProvider {
 | 
				
			||||||
  override fun provideNativeFunction(definition: String, arguments: List<ArgumentSpec>): CallableFunction {
 | 
					  override fun provideNativeFunction(definition: String, arguments: List<ArgumentSpec>): CallableFunction {
 | 
				
			||||||
    val functionDefinition = FfiFunctionDefinition.parse(definition)
 | 
					    val functionDefinition = FfiFunctionDefinition.parse(definition)
 | 
				
			||||||
    val function = Function.getFunction(functionDefinition.library, functionDefinition.function)
 | 
					    val library = NativeLibrary.getInstance(functionDefinition.library)
 | 
				
			||||||
 | 
					    val function = library.getFunction(functionDefinition.function)
 | 
				
			||||||
      ?: throw RuntimeException("Failed to find function ${functionDefinition.function} in library ${functionDefinition.library}")
 | 
					      ?: throw RuntimeException("Failed to find function ${functionDefinition.function} in library ${functionDefinition.library}")
 | 
				
			||||||
    return CallableFunction { functionArgs ->
 | 
					    return CallableFunction { functionArgs ->
 | 
				
			||||||
      val ffiArgs = mutableListOf<Any?>()
 | 
					      val ffiArgs = mutableListOf<Any?>()
 | 
				
			||||||
@ -38,7 +41,7 @@ class JnaNativeProvider : NativeProvider {
 | 
				
			|||||||
    "void" -> function.invokeVoid(values)
 | 
					    "void" -> function.invokeVoid(values)
 | 
				
			||||||
    "char*" -> function.invokeString(values, false)
 | 
					    "char*" -> function.invokeString(values, false)
 | 
				
			||||||
    else -> throw RuntimeException("Unsupported ffi return type: $type")
 | 
					    else -> throw RuntimeException("Unsupported ffi return type: $type")
 | 
				
			||||||
  }
 | 
					  } ?: None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  private fun rewriteType(type: String): String = when (type) {
 | 
					  private fun rewriteType(type: String): String = when (type) {
 | 
				
			||||||
    "size_t" -> "long"
 | 
					    "size_t" -> "long"
 | 
				
			||||||
@ -55,7 +58,13 @@ class JnaNativeProvider : NativeProvider {
 | 
				
			|||||||
    "double" -> numberConvert(type, value) { toDouble() }
 | 
					    "double" -> numberConvert(type, value) { toDouble() }
 | 
				
			||||||
    "float" -> numberConvert(type, value) { toFloat() }
 | 
					    "float" -> numberConvert(type, value) { toFloat() }
 | 
				
			||||||
    "char*" -> notNullConvert(type, value) { toString() }
 | 
					    "char*" -> notNullConvert(type, value) { toString() }
 | 
				
			||||||
    "void*" -> nullableConvert(value) { this as Pointer }
 | 
					    "void*" -> nullableConvert(value) {
 | 
				
			||||||
 | 
					      if (value is Long) {
 | 
				
			||||||
 | 
					        Pointer(value)
 | 
				
			||||||
 | 
					      } else {
 | 
				
			||||||
 | 
					        value as Pointer
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    else -> throw RuntimeException("Unsupported ffi type: $type")
 | 
					    else -> throw RuntimeException("Unsupported ffi type: $type")
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -67,14 +76,14 @@ class JnaNativeProvider : NativeProvider {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  private fun <T> nullableConvert(value: Any?, into: Any.() -> T): T? {
 | 
					  private fun <T> nullableConvert(value: Any?, into: Any.() -> T): T? {
 | 
				
			||||||
    if (value == null) {
 | 
					    if (value == null || value == None) {
 | 
				
			||||||
      return null
 | 
					      return null
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    return into(value)
 | 
					    return into(value)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  private fun <T> numberConvert(type: String, value: Any?, into: Number.() -> T): T {
 | 
					  private fun <T> numberConvert(type: String, value: Any?, into: Number.() -> T): T {
 | 
				
			||||||
    if (value == null) {
 | 
					    if (value == null || value == None) {
 | 
				
			||||||
      throw RuntimeException("Null values cannot be used for converting to numeric type $type")
 | 
					      throw RuntimeException("Null values cannot be used for converting to numeric type $type")
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -192,6 +192,11 @@ class Parser(source: PeekableSource<Token>, val attribution: NodeAttribution) {
 | 
				
			|||||||
        Continue()
 | 
					        Continue()
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      TokenType.None -> {
 | 
				
			||||||
 | 
					        expect(TokenType.None)
 | 
				
			||||||
 | 
					        NoneLiteral()
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      else -> {
 | 
					      else -> {
 | 
				
			||||||
        throw ParseError(
 | 
					        throw ParseError(
 | 
				
			||||||
          "Failed to parse token: ${token.type} '${token.text}' as" +
 | 
					          "Failed to parse token: ${token.type} '${token.text}' as" +
 | 
				
			||||||
 | 
				
			|||||||
@ -81,6 +81,10 @@ class Printer(buffer: StringBuilder) : NodeVisitor<Unit> {
 | 
				
			|||||||
    visit(node.definition)
 | 
					    visit(node.definition)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  override fun visitNoneLiteral(node: NoneLiteral) {
 | 
				
			||||||
 | 
					    append("none")
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  override fun visitSymbol(node: Symbol) {
 | 
					  override fun visitSymbol(node: Symbol) {
 | 
				
			||||||
    append(node.id)
 | 
					    append(node.id)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
				
			|||||||
@ -14,7 +14,8 @@ enum class TokenType(vararg properties: TokenTypeProperty) {
 | 
				
			|||||||
  StringLiteral(StringLiteralFamily),
 | 
					  StringLiteral(StringLiteralFamily),
 | 
				
			||||||
  Equality(OperatorFamily),
 | 
					  Equality(OperatorFamily),
 | 
				
			||||||
  Inequality(ManyChars("!="), OperatorFamily),
 | 
					  Inequality(ManyChars("!="), OperatorFamily),
 | 
				
			||||||
  ExclaimationPoint(SingleChar('!'), Promotion('=', Inequality)),
 | 
					  ExclamationPoint(SingleChar('!'), Promotion('=', Inequality)),
 | 
				
			||||||
 | 
					  None(ManyChars("None"), KeywordFamily),
 | 
				
			||||||
  Equals(SingleChar('='), Promotion('=', Equality)),
 | 
					  Equals(SingleChar('='), Promotion('=', Equality)),
 | 
				
			||||||
  PlusPlus(ManyChars("++"), OperatorFamily),
 | 
					  PlusPlus(ManyChars("++"), OperatorFamily),
 | 
				
			||||||
  MinusMinus(ManyChars("--"), OperatorFamily),
 | 
					  MinusMinus(ManyChars("--"), OperatorFamily),
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user