Updated WASM spec tests to latest

This commit is contained in:
Chad Retz 2017-04-24 17:49:22 -05:00
parent 706c76a5cd
commit 5430e19a2b
5 changed files with 6 additions and 13 deletions

View File

@ -210,7 +210,7 @@ open class AstToAsm {
fun initializeConstructorGlobals(ctx: ClsContext, func: Func, paramsBeforeImports: Int) =
ctx.mod.globals.foldIndexed(func) { index, func, global ->
// In the MVP, we can trust the init is constant stuff and a single instr
if (global.init.size > 1) throw CompileErr.GlobalInitNotConstant(index)
if (global.init.size != 1) throw CompileErr.GlobalInitNotConstant(index)
func.addInsns(VarInsnNode(Opcodes.ALOAD, 0)).
addInsns(
global.init.firstOrNull().let {

View File

@ -114,8 +114,9 @@ sealed class CompileErr(message: String, cause: Throwable? = null) : RuntimeExce
class GlobalInitNotConstant(
val index: Int
) : CompileErr("Expected init for global $index to be constant") {
) : CompileErr("Expected init for global $index to be single constant value") {
override val asmErrString get() = "constant expression required"
override val asmErrStrings get() = listOf(asmErrString, "type mismatch")
}
class OffsetNotConstant : CompileErr("Expected offset to be constant") {

View File

@ -269,10 +269,9 @@ open class SExprToAst {
if (maybeImpExp != null) currIndex++
val sig = toGlobalSig(exp.vals[currIndex])
currIndex++
var (instrs, _) = toInstrs(exp, currIndex, ExprContext(nameMap))
val (instrs, _) = toInstrs(exp, currIndex, ExprContext(nameMap))
// Imports can't have instructions
if (maybeImpExp?.importModule != null) require(instrs.isEmpty())
else if (instrs.isEmpty()) instrs = listOf(sig.contentType.zeroConst)
return Triple(name, Node.Global(sig, instrs), maybeImpExp)
}
@ -876,12 +875,5 @@ open class SExprToAst {
return this.vals.first().requireSymbol(contents, quotedCheck)
}
private val Node.Type.Value.zeroConst: Node.Instr get() = when (this) {
Node.Type.Value.I32 -> Node.Instr.I32Const(0)
Node.Type.Value.I64 -> Node.Instr.I64Const(0)
Node.Type.Value.F32 -> Node.Instr.F32Const(0f)
Node.Type.Value.F64 -> Node.Instr.F64Const(0.0)
}
companion object : SExprToAst()
}

View File

@ -2,7 +2,7 @@
(memory 1)
(global $foo (mut i32) (i32.const 20))
(global $bar (mut f32))
(global $bar (mut f32) (f32.const 0))
;; This was breaking because stack diff was wrong for get_global and set_global
(func (export "testGlobals") (param $p i32) (result i32)

@ -1 +1 @@
Subproject commit f1b89dfaf379060c7e35eb90b7daeb14d4ade3f7
Subproject commit 671b08d0e72829acf512f8fbb5c1e007ca65ae94