mirror of
https://github.com/GayPizzaSpecifications/pork.git
synced 2025-08-02 12:50:55 +00:00
code cleanup
This commit is contained in:
parent
a262c09219
commit
08f9b6f2ae
@ -2,7 +2,6 @@ package gay.pizza.pork.buildext
|
||||
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.Task
|
||||
import org.gradle.api.tasks.TaskProvider
|
||||
import org.gradle.kotlin.dsl.create
|
||||
import org.gradle.kotlin.dsl.getByType
|
||||
|
@ -3,7 +3,6 @@ package gay.pizza.pork.buildext
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.tasks.TaskProvider
|
||||
import org.gradle.kotlin.dsl.create
|
||||
import org.gradle.kotlin.dsl.register
|
||||
|
||||
class PorkStdlibPlugin : Plugin<Project> {
|
||||
|
@ -1,6 +1,6 @@
|
||||
package gay.pizza.pork.buildext.ast
|
||||
|
||||
enum class AstPrimitive(val id: kotlin.String) {
|
||||
enum class AstPrimitive(val id: String) {
|
||||
Boolean("Boolean"),
|
||||
String("String"),
|
||||
Int("Int"),
|
||||
|
@ -1,9 +1,9 @@
|
||||
package gay.pizza.pork.common
|
||||
|
||||
@Suppress("NOTHING_TO_INLINE", "UnusedReceiverParameter", "unused")
|
||||
@Suppress("NOTHING_TO_INLINE", "UnusedReceiverParameter")
|
||||
inline fun Any?.markIsUnused() {}
|
||||
|
||||
@Suppress("NOTHING_TO_INLINE", "unused")
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline fun unused(value: Any?) {
|
||||
value.markIsUnused()
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ import gay.pizza.pork.ast.gen.Symbol
|
||||
import gay.pizza.pork.execution.ExecutionContext
|
||||
import gay.pizza.pork.execution.ExecutionContextProvider
|
||||
import gay.pizza.pork.execution.ExecutionOptions
|
||||
import gay.pizza.pork.execution.NativeRegistry
|
||||
import gay.pizza.pork.frontend.ImportLocator
|
||||
import gay.pizza.pork.frontend.World
|
||||
|
||||
|
@ -5,8 +5,8 @@ import com.kenai.jffi.MemoryIO
|
||||
import gay.pizza.pork.execution.None
|
||||
|
||||
enum class FfiPrimitiveType(
|
||||
val id: kotlin.String,
|
||||
override val size: kotlin.Long,
|
||||
val id: String,
|
||||
override val size: Long,
|
||||
val numberConvert: (Number.() -> Number)? = null,
|
||||
val nullableConversion: (Any?.() -> Any)? = null,
|
||||
val notNullConversion: (Any.() -> Any)? = null
|
||||
@ -22,9 +22,7 @@ enum class FfiPrimitiveType(
|
||||
UnsignedLong("unsigned long", 8, numberConvert = { toLong() }),
|
||||
Double("double", 8, numberConvert = { toDouble() }),
|
||||
String("char*", 8, nullableConversion = {
|
||||
if (this is FfiString) {
|
||||
this
|
||||
} else FfiString.allocate(toString())
|
||||
this as? FfiString ?: FfiString.allocate(toString())
|
||||
}),
|
||||
Pointer("void*", 8, nullableConversion = {
|
||||
when (this) {
|
||||
@ -52,7 +50,7 @@ enum class FfiPrimitiveType(
|
||||
}
|
||||
}
|
||||
|
||||
private fun <T> notNullConvert(type: kotlin.String, value: Any?, into: Any.() -> T): T {
|
||||
private fun <T> notNullConvert(type: String, value: Any?, into: Any.() -> T): T {
|
||||
if (value == null) {
|
||||
throw RuntimeException("Null values cannot be used for converting to type $type")
|
||||
}
|
||||
@ -66,7 +64,7 @@ enum class FfiPrimitiveType(
|
||||
return into(value)
|
||||
}
|
||||
|
||||
private fun <T> numberConvert(type: kotlin.String, value: Any?, into: Number.() -> T): T {
|
||||
private fun <T> numberConvert(type: String, value: Any?, into: Number.() -> T): T {
|
||||
if (value == null || value == None) {
|
||||
throw RuntimeException("Null values cannot be used for converting to numeric type $type")
|
||||
}
|
||||
@ -90,7 +88,7 @@ enum class FfiPrimitiveType(
|
||||
return ffi
|
||||
}
|
||||
|
||||
override fun read(address: FfiAddress, offset: kotlin.Int): Any {
|
||||
override fun read(address: FfiAddress, offset: Int): Any {
|
||||
val actual = address.location + offset
|
||||
return when (this) {
|
||||
UnsignedByte, Byte -> MemoryIO.getInstance().getByte(actual)
|
||||
@ -107,10 +105,10 @@ enum class FfiPrimitiveType(
|
||||
|
||||
companion object {
|
||||
fun push(buffer: InvocationBuffer, value: Any): Unit = when (value) {
|
||||
is kotlin.Byte -> buffer.putByte(value.toInt())
|
||||
is kotlin.Short -> buffer.putShort(value.toInt())
|
||||
is kotlin.Int -> buffer.putInt(value)
|
||||
is kotlin.Long -> buffer.putLong(value)
|
||||
is Byte -> buffer.putByte(value.toInt())
|
||||
is Short -> buffer.putShort(value.toInt())
|
||||
is Int -> buffer.putInt(value)
|
||||
is Long -> buffer.putLong(value)
|
||||
is FfiAddress -> buffer.putAddress(value.location)
|
||||
is FfiString -> buffer.putAddress(value.address.location)
|
||||
else -> throw RuntimeException("Unknown buffer insertion: $value (${value.javaClass.name})")
|
||||
|
@ -1,7 +1,5 @@
|
||||
package gay.pizza.pork.ffi
|
||||
|
||||
import java.nio.file.Path
|
||||
|
||||
object FfiUnixPlatform : FfiPlatform {
|
||||
override fun findLibrary(name: String): String? = null
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
package gay.pizza.pork.ffi
|
||||
|
||||
import java.nio.file.Path
|
||||
|
||||
object FfiWindowsPlatform : FfiPlatform {
|
||||
override fun findLibrary(name: String): String? = null
|
||||
}
|
||||
|
@ -4,15 +4,10 @@ import gay.pizza.pork.ast.gen.CompilationUnit
|
||||
import gay.pizza.pork.ast.gen.NodeVisitor
|
||||
import gay.pizza.pork.ast.gen.Symbol
|
||||
import gay.pizza.pork.ast.gen.visit
|
||||
import gay.pizza.pork.evaluator.*
|
||||
import gay.pizza.pork.execution.ExecutionContext
|
||||
import gay.pizza.pork.execution.ExecutionContextProvider
|
||||
import gay.pizza.pork.execution.ExecutionOptions
|
||||
import gay.pizza.pork.execution.InternalNativeProvider
|
||||
import gay.pizza.pork.execution.NativeRegistry
|
||||
import gay.pizza.pork.ffi.FfiNativeProvider
|
||||
import gay.pizza.pork.ffi.JavaAutogenContentSource
|
||||
import gay.pizza.pork.ffi.JavaNativeProvider
|
||||
import gay.pizza.pork.frontend.ContentSource
|
||||
import gay.pizza.pork.frontend.ImportLocator
|
||||
import gay.pizza.pork.frontend.DynamicImportSource
|
||||
|
@ -6,11 +6,7 @@ import gay.pizza.pork.ast.gen.NodeType
|
||||
import gay.pizza.pork.tokenizer.*
|
||||
|
||||
abstract class ParserBase(source: TokenSource, val attribution: NodeAttribution) : NodeParser {
|
||||
val source: TokenSource = if (source is ParserAwareTokenSource) {
|
||||
source
|
||||
} else {
|
||||
LazySkippingTokenSource(source, TokenType.ParserIgnoredTypes)
|
||||
}
|
||||
val source: TokenSource = source as? ParserAwareTokenSource ?: LazySkippingTokenSource(source, TokenType.ParserIgnoredTypes)
|
||||
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
protected inline fun <T: Node> produce(type: NodeType, noinline block: () -> T): T =
|
||||
|
@ -1,6 +1,5 @@
|
||||
package gay.pizza.pork.tokenizer
|
||||
|
||||
@Suppress("CanBeParameter")
|
||||
class MatchedCharConsumer(
|
||||
val start: CharSequence,
|
||||
val end: CharSequence,
|
||||
|
@ -26,7 +26,7 @@ class InternalMachine(val world: CompiledWorld, val nativeRegistry: NativeRegist
|
||||
if (debug) {
|
||||
val frame = frame(inst)
|
||||
println("vm: step: in slab ${frame?.symbolInfo?.slab ?: "unknown"}: symbol ${frame?.symbolInfo?.symbol ?: "unknown"}: $inst ${op.code}${if (op.args.isEmpty()) "" else " " + op.args.joinToString(" ")}")
|
||||
println("vm: step: stack: ${stack}")
|
||||
println("vm: step: stack: $stack")
|
||||
}
|
||||
|
||||
handler.handle(this, op)
|
||||
|
@ -4,7 +4,6 @@ import gay.pizza.pork.bytecode.Op
|
||||
import gay.pizza.pork.bytecode.Opcode
|
||||
import gay.pizza.pork.vm.InternalMachine
|
||||
import gay.pizza.pork.vm.OpHandler
|
||||
import gay.pizza.pork.vm.VirtualMachineException
|
||||
|
||||
object JumpIfOpHandler : OpHandler(Opcode.JumpIf) {
|
||||
override fun handle(machine: InternalMachine, op: Op) {
|
||||
|
@ -2,7 +2,6 @@ package gay.pizza.pork.vm.ops
|
||||
|
||||
import gay.pizza.pork.bytecode.Op
|
||||
import gay.pizza.pork.bytecode.Opcode
|
||||
import gay.pizza.pork.execution.NativeFunction
|
||||
import gay.pizza.pork.execution.NativeType
|
||||
import gay.pizza.pork.execution.None
|
||||
import gay.pizza.pork.vm.InternalMachine
|
||||
|
Loading…
Reference in New Issue
Block a user