Minor cleanup of TODOs and warnings

This commit is contained in:
Chad Retz 2017-04-19 19:37:07 -05:00
parent a9dc8ddd77
commit da1d94dc9e
11 changed files with 24 additions and 23 deletions

View File

@ -433,14 +433,20 @@ sealed class Node {
companion object {
// TODO: why can't I set a val in init?
var strToOpMap = emptyMap<String, InstrOp<*>>(); private set
var classToOpMap = emptyMap<KClass<out Instr>, InstrOp<*>>(); private set
var strToOpcodeMap = emptyMap<String, Short>(); private set
var opcodeToStrMap = emptyMap<Short, String>(); private set
val strToOpMap: Map<String, InstrOp<*>>
val classToOpMap: Map<KClass<out Instr>, InstrOp<*>>
val strToOpcodeMap: Map<String, Short>
val opcodeToStrMap: Map<Short, String>
fun op(opcode: Short) = opcodeToStrMap[opcode]?.let(strToOpMap::get) ?: error("No opcode found: $opcode")
init {
// Local vars, set to vals later
var strToOpMap = emptyMap<String, InstrOp<*>>()
var classToOpMap = emptyMap<KClass<out Instr>, InstrOp<*>>()
var strToOpcodeMap = emptyMap<String, Short>()
var opcodeToStrMap = emptyMap<Short, String>()
// Can't use reification here because inline funcs not allowed in nested context :-(
fun <T> opMapEntry(
name: String,
@ -639,6 +645,11 @@ sealed class Node {
opMapEntry("i64.reinterpret/f64", 0xbd, ReinterpretOp::NoArg, Instr.I64ReinterpretF64, Instr.I64ReinterpretF64::class)
opMapEntry("f32.reinterpret/i32", 0xbe, ReinterpretOp::NoArg, Instr.F32ReinterpretI32, Instr.F32ReinterpretI32::class)
opMapEntry("f64.reinterpret/i64", 0xbf, ReinterpretOp::NoArg, Instr.F64ReinterpretI64, Instr.F64ReinterpretI64::class)
this.strToOpMap = strToOpMap
this.classToOpMap = classToOpMap
this.strToOpcodeMap = strToOpcodeMap
this.opcodeToStrMap = opcodeToStrMap
}
}
}

View File

@ -4,7 +4,6 @@ import asmble.ast.Script
import asmble.compile.jvm.AstToAsm
import asmble.compile.jvm.ClsContext
import asmble.compile.jvm.withComputedFramesAndMaxs
import org.objectweb.asm.ClassWriter
import java.io.FileOutputStream
open class Compile : Command<Compile.Args>() {

View File

@ -179,8 +179,9 @@ val Node.Type.Func.asmDesc: String get() =
(this.ret?.typeRef ?: Void::class.ref).asMethodRetDesc(*this.params.map { it.typeRef }.toTypedArray())
fun ClassNode.withComputedFramesAndMaxs(): ByteArray {
// TODO: compute maxs adds a bunch of NOPs for unreachable code
// See $func12 of block.wast. Is removing these worth the extra visit cycle?
// Note, compute maxs adds a bunch of NOPs for unreachable code.
// See $func12 of block.wast. I don't believe the extra time over the
// instructions to remove the NOPs is worth it.
val cw = ClassWriter(ClassWriter.COMPUTE_FRAMES + ClassWriter.COMPUTE_MAXS)
this.accept(cw)
return cw.toByteArray()

View File

@ -33,7 +33,6 @@ open class AstToAsm {
ctx.cls.fields.add(FieldNode(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL, "table",
Array<MethodHandle>::class.ref.asmDesc, null, null))
// Now all method imports as method handles
// TODO: why does this fail with asm-debug-all but not with just regular asm?
ctx.cls.fields.addAll(ctx.importFuncs.indices.map {
FieldNode(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL, ctx.funcName(it),
MethodHandle::class.ref.asmDesc, null, null)

View File

@ -48,7 +48,7 @@ sealed class CompileErr(message: String, cause: Throwable? = null) : RuntimeExce
override val asmErrString get() = "type mismatch"
}
class IfThenValueWithoutElse() : CompileErr("If has value but no else clause") {
class IfThenValueWithoutElse : CompileErr("If has value but no else clause") {
override val asmErrString get() = "type mismatch"
}

View File

@ -15,8 +15,6 @@ import java.lang.invoke.MethodHandle
open class FuncBuilder {
fun fromFunc(ctx: ClsContext, f: Node.Func, index: Int): Func {
// TODO: validate local size?
// TODO: initialize non-param locals?
ctx.debug { "Building function ${ctx.funcName(index)}" }
ctx.trace { "Function ast:\n${SExprToStr.fromSExpr(AstToSExpr.fromFunc(f))}" }
var func = Func(
@ -145,7 +143,6 @@ open class FuncBuilder {
is Node.Instr.I32Load8S, is Node.Instr.I32Load8U, is Node.Instr.I32Load16U, is Node.Instr.I32Load16S,
is Node.Instr.I64Load8S, is Node.Instr.I64Load8U, is Node.Instr.I64Load16U, is Node.Instr.I64Load16S,
is Node.Instr.I64Load32S, is Node.Instr.I64Load32U ->
// TODO: why do I have to cast?
applyLoadOp(ctx, fn, i as Node.Instr.Args.AlignOffset)
is Node.Instr.I32Store, is Node.Instr.I64Store, is Node.Instr.F32Store, is Node.Instr.F64Store,
is Node.Instr.I32Store8, is Node.Instr.I32Store16, is Node.Instr.I64Store8, is Node.Instr.I64Store16,

View File

@ -39,6 +39,7 @@ interface Mem {
// on the stack after every call.
fun storeOp(ctx: FuncContext, func: Func, insn: Node.Instr.Args.AlignOffset): Func
// Whether or not storeOp leaves a mem instance on the stack
val storeLeavesMemOnStack: Boolean
companion object {

View File

@ -4,8 +4,6 @@ import asmble.util.unsignedToSignedInt
import asmble.util.unsignedToSignedLong
import java.io.ByteArrayOutputStream
import java.math.BigInteger
import java.nio.ByteBuffer
import java.nio.ByteOrder
abstract class ByteWriter {
abstract val written: Int

View File

@ -4,16 +4,15 @@ import asmble.ast.SExpr
open class SExprToStr(val depthBeforeNewline: Int, val countBeforeNewlineAll: Int, val indent: String) {
@Suppress("UNCHECKED_CAST") // TODO: why?
fun fromSExpr(vararg exp: SExpr): String = appendAll(exp.asList(), StringBuilder()).trim().toString()
@Suppress("UNCHECKED_CAST") // TODO: why?
@Suppress("UNCHECKED_CAST")
fun <T : Appendable> append(exp: SExpr, sb: T = StringBuilder() as T, indentLevel: Int = 0) = when(exp) {
is SExpr.Symbol -> appendSymbol(exp, sb)
is SExpr.Multi -> appendMulti(exp, sb, indentLevel)
}
@Suppress("UNCHECKED_CAST") // TODO: why?
@Suppress("UNCHECKED_CAST")
fun <T : Appendable> appendSymbol(exp: SExpr.Symbol, sb: T = StringBuilder() as T): T {
val quoted = exp.quoted || exp.contents.requiresQuote
if (!quoted) sb.append(exp.contents) else {
@ -33,7 +32,7 @@ open class SExprToStr(val depthBeforeNewline: Int, val countBeforeNewlineAll: In
return sb
}
@Suppress("UNCHECKED_CAST") // TODO: why?
@Suppress("UNCHECKED_CAST")
fun <T : Appendable> appendMulti(exp: SExpr.Multi, sb: T = StringBuilder() as T, indentLevel: Int = 0): T {
sb.append('(')
appendAll(exp.vals, sb, indentLevel)
@ -41,7 +40,7 @@ open class SExprToStr(val depthBeforeNewline: Int, val countBeforeNewlineAll: In
return sb
}
@Suppress("UNCHECKED_CAST") // TODO: why?
@Suppress("UNCHECKED_CAST")
fun <T : Appendable> appendAll(exps: List<SExpr>, sb: T = StringBuilder() as T, indentLevel: Int = 0): T {
val newlineAll = exps.sumBy { it.count() } >= countBeforeNewlineAll
var wasLastNewline = false

View File

@ -106,7 +106,6 @@ data class ScriptContext(
}
fun assertReturnNan(ret: Script.Cmd.Assertion.ReturnNan) {
// TODO: validate canonical vs arithmetic
val (retType, retVal) = doAction(ret.action)
when (retType) {
Node.Type.Value.F32 ->

View File

@ -2,12 +2,9 @@ package asmble.io
import org.junit.Assert.assertArrayEquals
import org.junit.Test
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import java.io.PipedInputStream
import java.io.PipedOutputStream
import java.math.BigInteger
import java.nio.ByteBuffer
import kotlin.test.assertEquals
import kotlin.test.assertFails
import kotlin.test.assertFalse