mirror of
https://github.com/fluencelabs/asmble
synced 2025-04-25 06:42:22 +00:00
Updated WASM spec tests to latest
This commit is contained in:
parent
706c76a5cd
commit
5430e19a2b
@ -210,7 +210,7 @@ open class AstToAsm {
|
|||||||
fun initializeConstructorGlobals(ctx: ClsContext, func: Func, paramsBeforeImports: Int) =
|
fun initializeConstructorGlobals(ctx: ClsContext, func: Func, paramsBeforeImports: Int) =
|
||||||
ctx.mod.globals.foldIndexed(func) { index, func, global ->
|
ctx.mod.globals.foldIndexed(func) { index, func, global ->
|
||||||
// In the MVP, we can trust the init is constant stuff and a single instr
|
// 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)).
|
func.addInsns(VarInsnNode(Opcodes.ALOAD, 0)).
|
||||||
addInsns(
|
addInsns(
|
||||||
global.init.firstOrNull().let {
|
global.init.firstOrNull().let {
|
||||||
|
@ -114,8 +114,9 @@ sealed class CompileErr(message: String, cause: Throwable? = null) : RuntimeExce
|
|||||||
|
|
||||||
class GlobalInitNotConstant(
|
class GlobalInitNotConstant(
|
||||||
val index: Int
|
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 asmErrString get() = "constant expression required"
|
||||||
|
override val asmErrStrings get() = listOf(asmErrString, "type mismatch")
|
||||||
}
|
}
|
||||||
|
|
||||||
class OffsetNotConstant : CompileErr("Expected offset to be constant") {
|
class OffsetNotConstant : CompileErr("Expected offset to be constant") {
|
||||||
|
@ -269,10 +269,9 @@ open class SExprToAst {
|
|||||||
if (maybeImpExp != null) currIndex++
|
if (maybeImpExp != null) currIndex++
|
||||||
val sig = toGlobalSig(exp.vals[currIndex])
|
val sig = toGlobalSig(exp.vals[currIndex])
|
||||||
currIndex++
|
currIndex++
|
||||||
var (instrs, _) = toInstrs(exp, currIndex, ExprContext(nameMap))
|
val (instrs, _) = toInstrs(exp, currIndex, ExprContext(nameMap))
|
||||||
// Imports can't have instructions
|
// Imports can't have instructions
|
||||||
if (maybeImpExp?.importModule != null) require(instrs.isEmpty())
|
if (maybeImpExp?.importModule != null) require(instrs.isEmpty())
|
||||||
else if (instrs.isEmpty()) instrs = listOf(sig.contentType.zeroConst)
|
|
||||||
return Triple(name, Node.Global(sig, instrs), maybeImpExp)
|
return Triple(name, Node.Global(sig, instrs), maybeImpExp)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -876,12 +875,5 @@ open class SExprToAst {
|
|||||||
return this.vals.first().requireSymbol(contents, quotedCheck)
|
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()
|
companion object : SExprToAst()
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
(memory 1)
|
(memory 1)
|
||||||
|
|
||||||
(global $foo (mut i32) (i32.const 20))
|
(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
|
;; This was breaking because stack diff was wrong for get_global and set_global
|
||||||
(func (export "testGlobals") (param $p i32) (result i32)
|
(func (export "testGlobals") (param $p i32) (result i32)
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit f1b89dfaf379060c7e35eb90b7daeb14d4ade3f7
|
Subproject commit 671b08d0e72829acf512f8fbb5c1e007ca65ae94
|
Loading…
x
Reference in New Issue
Block a user