add edge case for i64.const

This commit is contained in:
NikVolf 2017-09-06 19:06:14 +02:00
parent a4e2ec0adb
commit 5f1cf258cc
3 changed files with 23 additions and 19 deletions

Binary file not shown.

View File

@ -1,6 +1,8 @@
(module
(type (;0;) (func (result i32)))
(func (;0;) (type 0) (result i32)
i64.const 9223372036854775807
i64.const -9223372036854775808
i32.const 1024
i32.const 2048
i32.const 4096

View File

@ -22,7 +22,7 @@ impl Default for Module {
magic: 0x6d736100,
version: 1,
sections: Vec::with_capacity(16),
}
}
}
}
@ -83,7 +83,7 @@ impl Module {
for section in self.sections() {
if let &Section::Global(ref section) = section { return Some(section); }
}
None
None
}
/// Exports section, if any.
@ -131,7 +131,7 @@ impl Module {
for section in self.sections() {
if let &Section::Function(ref sect) = section { return Some(sect); }
}
None
None
}
/// Start section, if any.
@ -169,12 +169,12 @@ impl Deserialize for Module {
}
}
Ok(Module {
Ok(Module {
magic: LittleEndian::read_u32(&magic),
version: version,
sections: sections,
})
}
}
}
impl Serialize for Module {
@ -249,7 +249,7 @@ mod integration_tests {
module_new.import_section().expect("import section exists").entries().len(),
"There should be equal amount of import entries before and after serialization"
);
}
}
#[test]
fn serde_code() {
@ -275,20 +275,22 @@ mod integration_tests {
let module = deserialize_file("./res/cases/v1/const.wasm").expect("Should be deserialized");
let func = &module.code_section().expect("Code section to exist").bodies()[0];
assert_eq!(func.code().elements().len(), 14);
assert_eq!(func.code().elements().len(), 16);
assert_eq!(I32Const(1024), func.code().elements()[0]);
assert_eq!(I32Const(2048), func.code().elements()[1]);
assert_eq!(I32Const(4096), func.code().elements()[2]);
assert_eq!(I32Const(8192), func.code().elements()[3]);
assert_eq!(I32Const(16384), func.code().elements()[4]);
assert_eq!(I32Const(32767), func.code().elements()[5]);
assert_eq!(I32Const(-1024), func.code().elements()[6]);
assert_eq!(I32Const(-2048), func.code().elements()[7]);
assert_eq!(I32Const(-4096), func.code().elements()[8]);
assert_eq!(I32Const(-8192), func.code().elements()[9]);
assert_eq!(I32Const(-16384), func.code().elements()[10]);
assert_eq!(I32Const(-32768), func.code().elements()[11]);
assert_eq!(I64Const(9223372036854775807), func.code().elements()[0]);
assert_eq!(I64Const(-9223372036854775808), func.code().elements()[1]);
assert_eq!(I32Const(1024), func.code().elements()[2]);
assert_eq!(I32Const(2048), func.code().elements()[3]);
assert_eq!(I32Const(4096), func.code().elements()[4]);
assert_eq!(I32Const(8192), func.code().elements()[5]);
assert_eq!(I32Const(16384), func.code().elements()[6]);
assert_eq!(I32Const(32767), func.code().elements()[7]);
assert_eq!(I32Const(-1024), func.code().elements()[8]);
assert_eq!(I32Const(-2048), func.code().elements()[9]);
assert_eq!(I32Const(-4096), func.code().elements()[10]);
assert_eq!(I32Const(-8192), func.code().elements()[11]);
assert_eq!(I32Const(-16384), func.code().elements()[12]);
assert_eq!(I32Const(-32768), func.code().elements()[13]);
}
#[test]