forked from rustwasm/wasm-bindgen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for i128 and u128 (rustwasm#4222)
- Loading branch information
1 parent
2463d0d
commit df9893b
Showing
17 changed files
with
397 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* tslint:disable */ | ||
/* eslint-disable */ | ||
export function echo_i128(a: bigint): bigint; | ||
export function echo_u128(a: bigint): bigint; | ||
export function echo_option_i128(a?: bigint): bigint | undefined; | ||
export function echo_option_u128(a?: bigint): bigint | undefined; | ||
export function throw_i128(): bigint; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
let wasm; | ||
export function __wbg_set_wasm(val) { | ||
wasm = val; | ||
} | ||
|
||
/** | ||
* @param {bigint} a | ||
* @returns {bigint} | ||
*/ | ||
export function echo_i128(a) { | ||
const ret = wasm.echo_i128(a, a >> BigInt(64)); | ||
return (BigInt.asUintN(64, ret[0]) | (ret[1] << BigInt(64))); | ||
} | ||
|
||
/** | ||
* @param {bigint} a | ||
* @returns {bigint} | ||
*/ | ||
export function echo_u128(a) { | ||
const ret = wasm.echo_u128(a, a >> BigInt(64)); | ||
return (BigInt.asUintN(64, ret[0]) | (BigInt.asUintN(64, ret[1]) << BigInt(64))); | ||
} | ||
|
||
function isLikeNone(x) { | ||
return x === undefined || x === null; | ||
} | ||
/** | ||
* @param {bigint | undefined} [a] | ||
* @returns {bigint | undefined} | ||
*/ | ||
export function echo_option_i128(a) { | ||
const ret = wasm.echo_option_i128(!isLikeNone(a), isLikeNone(a) ? BigInt(0) : a, isLikeNone(a) ? BigInt(0) : a >> BigInt(64)); | ||
return ret[0] === 0 ? undefined : (BigInt.asUintN(64, ret[1]) | (ret[2] << BigInt(64))); | ||
} | ||
|
||
/** | ||
* @param {bigint | undefined} [a] | ||
* @returns {bigint | undefined} | ||
*/ | ||
export function echo_option_u128(a) { | ||
const ret = wasm.echo_option_u128(!isLikeNone(a), isLikeNone(a) ? BigInt(0) : a, isLikeNone(a) ? BigInt(0) : a >> BigInt(64)); | ||
return ret[0] === 0 ? undefined : (BigInt.asUintN(64, ret[1]) | (BigInt.asUintN(64, ret[2]) << BigInt(64))); | ||
} | ||
|
||
const heap = new Array(128).fill(undefined); | ||
|
||
heap.push(undefined, null, true, false); | ||
|
||
function getObject(idx) { return heap[idx]; } | ||
|
||
let heap_next = heap.length; | ||
|
||
function dropObject(idx) { | ||
if (idx < 132) return; | ||
heap[idx] = heap_next; | ||
heap_next = idx; | ||
} | ||
|
||
function takeObject(idx) { | ||
const ret = getObject(idx); | ||
dropObject(idx); | ||
return ret; | ||
} | ||
/** | ||
* @returns {bigint} | ||
*/ | ||
export function throw_i128() { | ||
const ret = wasm.throw_i128(); | ||
if (ret[3]) { | ||
throw takeObject(ret[2]); | ||
} | ||
return (BigInt.asUintN(64, ret[0]) | (ret[1] << BigInt(64))); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use wasm_bindgen::prelude::*; | ||
|
||
#[wasm_bindgen] | ||
pub fn echo_i128(a: i128) -> i128 { | ||
a | ||
} | ||
#[wasm_bindgen] | ||
pub fn echo_u128(a: u128) -> u128 { | ||
a | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn echo_option_i128(a: Option<i128>) -> Option<i128> { | ||
a | ||
} | ||
#[wasm_bindgen] | ||
pub fn echo_option_u128(a: Option<u128>) -> Option<u128> { | ||
a | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn throw_i128() -> Result<i128, JsError> { | ||
Ok(0_i128) | ||
} | ||
// #[wasm_bindgen] | ||
// pub fn throw_option_i128() -> Result<Option<i128>, JsError> { | ||
// Ok(None) | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
(module $reference_test.wasm | ||
(type (;0;) (func (result i64 i64 i32 i32))) | ||
(type (;1;) (func (param i32 i64 i64) (result i32 i64 i64))) | ||
(type (;2;) (func (param i64 i64) (result i64 i64))) | ||
(func $"echo_option_i128 multivalue shim" (;0;) (type 1) (param i32 i64 i64) (result i32 i64 i64)) | ||
(func $"echo_option_u128 multivalue shim" (;1;) (type 1) (param i32 i64 i64) (result i32 i64 i64)) | ||
(func $"throw_i128 multivalue shim" (;2;) (type 0) (result i64 i64 i32 i32)) | ||
(func $"echo_i128 multivalue shim" (;3;) (type 2) (param i64 i64) (result i64 i64)) | ||
(func $"echo_u128 multivalue shim" (;4;) (type 2) (param i64 i64) (result i64 i64)) | ||
(memory (;0;) 17) | ||
(export "memory" (memory 0)) | ||
(export "echo_i128" (func $"echo_i128 multivalue shim")) | ||
(export "echo_u128" (func $"echo_u128 multivalue shim")) | ||
(export "echo_option_i128" (func $"echo_option_i128 multivalue shim")) | ||
(export "echo_option_u128" (func $"echo_option_u128 multivalue shim")) | ||
(export "throw_i128" (func $"throw_i128 multivalue shim")) | ||
(@custom "target_features" (after code) "\04+\0amultivalue+\0fmutable-globals+\0freference-types+\08sign-ext") | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.