Skip to content

Commit 5d212c1

Browse files
committed
fix i64 conversion
1 parent 00c97c8 commit 5d212c1

3 files changed

Lines changed: 13 additions & 7 deletions

File tree

common/integer.rv

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ fn Float64(Int(x)) {
117117
wasm f64.convert_i64_s(x: i64): f64
118118
}
119119

120+
fn oftype(to: Int, x: Float64) {
121+
# TODO catch out of range
122+
oftype(to, wasm i64.trunc_f64_s(x): i64)
123+
}
124+
120125
fn (a: Int) / (b: Int) { Float64(a) / Float64(b) }
121126

122127
fn js(x: Int) { js(Float64(x)) }

common/wasm/js.rv

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,8 @@ fn Float64(obj: JSObject) {
117117
return x
118118
}
119119

120-
@extend
121-
fn Int32(obj: JSObject) {
122-
x = wasm call(support.identity, jsref(obj)): i32
123-
return Int32(x)
124-
}
125-
126120
fn oftype(to: Int, from: JSObject) {
127-
oftype(to, Int32(from))
121+
oftype(to, Float64(from))
128122
}
129123

130124
fn oftype(to: UInt, from: JSObject) {

test/language.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,13 @@ test('allocs', async () => {
927927
`)
928928
})
929929

930+
test('js int conversion', async () => {
931+
await rv(`
932+
test Int64(js(2828255673)) == 2828255673
933+
test Int32(js(2828255673)) == -1466711623
934+
`)
935+
})
936+
930937
test('wasi', async () => {
931938
await compile(path.join(__dirname, 'language', 'wasi.rv'),
932939
{ options: { memcheck: false } })

0 commit comments

Comments
 (0)