mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-17 08:51:34 +00:00
Implement reference counting (#592)
This commit is contained in:
11
lib/libm/README.md
Normal file
11
lib/libm/README.md
Normal file
@ -0,0 +1,11 @@
|
||||
#  libm
|
||||
|
||||
AssemblyScript's math routines for double and single precision as a library.
|
||||
|
||||
```ts
|
||||
const libm = require("@assemblyscript/libm");
|
||||
const libmf = libm.libmf;
|
||||
...
|
||||
```
|
||||
|
||||
Both `libm` and `libmf` have the same general interface as JavaScript's `Math`, with `libmf` doing single precision math.
|
144
lib/libm/assembly/libm.ts
Normal file
144
lib/libm/assembly/libm.ts
Normal file
@ -0,0 +1,144 @@
|
||||
export const E = Math.E;
|
||||
export const LN10 = Math.LN10;
|
||||
export const LN2 = Math.LN2;
|
||||
export const LOG10E = Math.LOG10E;
|
||||
export const LOG2E = Math.LOG2E;
|
||||
export const PI = Math.PI;
|
||||
export const SQRT1_2 = Math.SQRT1_2;
|
||||
export const SQRT2 = Math.SQRT2;
|
||||
|
||||
export function abs(x: f64): f64 {
|
||||
return Math.abs(x);
|
||||
}
|
||||
|
||||
export function acos(x: f64): f64 {
|
||||
return Math.acos(x);
|
||||
}
|
||||
|
||||
export function acosh(x: f64): f64 {
|
||||
return Math.acosh(x);
|
||||
}
|
||||
|
||||
export function asin(x: f64): f64 {
|
||||
return Math.asin(x);
|
||||
}
|
||||
|
||||
export function asinh(x: f64): f64 {
|
||||
return Math.asinh(x);
|
||||
}
|
||||
|
||||
export function atan(x: f64): f64 {
|
||||
return Math.atan(x);
|
||||
}
|
||||
|
||||
export function atanh(x: f64): f64 {
|
||||
return Math.atanh(x);
|
||||
}
|
||||
|
||||
export function atan2(y: f64, x: f64): f64 {
|
||||
return Math.atan2(y, x);
|
||||
}
|
||||
|
||||
export function cbrt(x: f64): f64 {
|
||||
return Math.cbrt(x);
|
||||
}
|
||||
|
||||
export function ceil(x: f64): f64 {
|
||||
return Math.ceil(x);
|
||||
}
|
||||
|
||||
export function clz32(x: f64): f64 {
|
||||
return Math.clz32(x);
|
||||
}
|
||||
|
||||
export function cos(x: f64): f64 {
|
||||
return Math.cos(x);
|
||||
}
|
||||
|
||||
export function cosh(x: f64): f64 {
|
||||
return Math.cosh(x);
|
||||
}
|
||||
|
||||
export function exp(x: f64): f64 {
|
||||
return Math.exp(x);
|
||||
}
|
||||
|
||||
export function expm1(x: f64): f64 {
|
||||
return Math.expm1(x);
|
||||
}
|
||||
|
||||
export function floor(x: f64): f64 {
|
||||
return Math.floor(x);
|
||||
}
|
||||
|
||||
export function fround(x: f64): f64 {
|
||||
return Math.fround(x);
|
||||
}
|
||||
|
||||
export function hypot(a: f64, b: f64): f64 {
|
||||
return Math.hypot(a, b);
|
||||
}
|
||||
|
||||
export function imul(a: f64, b: f64): f64 {
|
||||
return Math.imul(a, b);
|
||||
}
|
||||
|
||||
export function log(x: f64): f64 {
|
||||
return Math.log(x);
|
||||
}
|
||||
|
||||
export function log10(x: f64): f64 {
|
||||
return Math.log10(x);
|
||||
}
|
||||
|
||||
export function log1p(x: f64): f64 {
|
||||
return Math.log1p(x);
|
||||
}
|
||||
|
||||
export function log2(x: f64): f64 {
|
||||
return Math.log2(x);
|
||||
}
|
||||
|
||||
export function max(a: f64, b: f64): f64 {
|
||||
return Math.max(a, b);
|
||||
}
|
||||
|
||||
export function min(a: f64, b: f64): f64 {
|
||||
return Math.min(a, b);
|
||||
}
|
||||
|
||||
export function pow(x: f64, y: f64): f64 {
|
||||
return Math.pow(x, y);
|
||||
}
|
||||
|
||||
export function round(x: f64): f64 {
|
||||
return Math.round(x);
|
||||
}
|
||||
|
||||
export function sign(x: f64): f64 {
|
||||
return Math.sign(x);
|
||||
}
|
||||
|
||||
export function sin(x: f64): f64 {
|
||||
return Math.sin(x);
|
||||
}
|
||||
|
||||
export function sinh(x: f64): f64 {
|
||||
return Math.sinh(x);
|
||||
}
|
||||
|
||||
export function sqrt(x: f64): f64 {
|
||||
return Math.sqrt(x);
|
||||
}
|
||||
|
||||
export function tan(x: f64): f64 {
|
||||
return Math.tan(x);
|
||||
}
|
||||
|
||||
export function tanh(x: f64): f64 {
|
||||
return Math.tanh(x);
|
||||
}
|
||||
|
||||
export function trunc(x: f64): f64 {
|
||||
return Math.trunc(x);
|
||||
}
|
144
lib/libm/assembly/libmf.ts
Normal file
144
lib/libm/assembly/libmf.ts
Normal file
@ -0,0 +1,144 @@
|
||||
export const E = Mathf.E;
|
||||
export const LN10 = Mathf.LN10;
|
||||
export const LN2 = Mathf.LN2;
|
||||
export const LOG10E = Mathf.LOG10E;
|
||||
export const LOG2E = Mathf.LOG2E;
|
||||
export const PI = Mathf.PI;
|
||||
export const SQRT1_2 = Mathf.SQRT1_2;
|
||||
export const SQRT2 = Mathf.SQRT2;
|
||||
|
||||
export function abs(x: f32): f32 {
|
||||
return Mathf.abs(x);
|
||||
}
|
||||
|
||||
export function acos(x: f32): f32 {
|
||||
return Mathf.acos(x);
|
||||
}
|
||||
|
||||
export function acosh(x: f32): f32 {
|
||||
return Mathf.acosh(x);
|
||||
}
|
||||
|
||||
export function asin(x: f32): f32 {
|
||||
return Mathf.asin(x);
|
||||
}
|
||||
|
||||
export function asinh(x: f32): f32 {
|
||||
return Mathf.asinh(x);
|
||||
}
|
||||
|
||||
export function atan(x: f32): f32 {
|
||||
return Mathf.atan(x);
|
||||
}
|
||||
|
||||
export function atanh(x: f32): f32 {
|
||||
return Mathf.atanh(x);
|
||||
}
|
||||
|
||||
export function atan2(y: f32, x: f32): f32 {
|
||||
return Mathf.atan2(y, x);
|
||||
}
|
||||
|
||||
export function cbrt(x: f32): f32 {
|
||||
return Mathf.cbrt(x);
|
||||
}
|
||||
|
||||
export function ceil(x: f32): f32 {
|
||||
return Mathf.ceil(x);
|
||||
}
|
||||
|
||||
export function clz32(x: f32): f32 {
|
||||
return Mathf.clz32(x);
|
||||
}
|
||||
|
||||
export function cos(x: f32): f32 {
|
||||
return Mathf.cos(x);
|
||||
}
|
||||
|
||||
export function cosh(x: f32): f32 {
|
||||
return Mathf.cosh(x);
|
||||
}
|
||||
|
||||
export function exp(x: f32): f32 {
|
||||
return Mathf.exp(x);
|
||||
}
|
||||
|
||||
export function expm1(x: f32): f32 {
|
||||
return Mathf.expm1(x);
|
||||
}
|
||||
|
||||
export function floor(x: f32): f32 {
|
||||
return Mathf.floor(x);
|
||||
}
|
||||
|
||||
export function fround(x: f32): f32 {
|
||||
return Mathf.fround(x);
|
||||
}
|
||||
|
||||
export function hypot(a: f32, b: f32): f32 {
|
||||
return Mathf.hypot(a, b);
|
||||
}
|
||||
|
||||
export function imul(a: f32, b: f32): f32 {
|
||||
return Mathf.imul(a, b);
|
||||
}
|
||||
|
||||
export function log(x: f32): f32 {
|
||||
return Mathf.log(x);
|
||||
}
|
||||
|
||||
export function log10(x: f32): f32 {
|
||||
return Mathf.log10(x);
|
||||
}
|
||||
|
||||
export function log1p(x: f32): f32 {
|
||||
return Mathf.log1p(x);
|
||||
}
|
||||
|
||||
export function log2(x: f32): f32 {
|
||||
return Mathf.log2(x);
|
||||
}
|
||||
|
||||
export function max(a: f32, b: f32): f32 {
|
||||
return Mathf.max(a, b);
|
||||
}
|
||||
|
||||
export function min(a: f32, b: f32): f32 {
|
||||
return Mathf.min(a, b);
|
||||
}
|
||||
|
||||
export function pow(x: f32, y: f32): f32 {
|
||||
return Mathf.pow(x, y);
|
||||
}
|
||||
|
||||
export function round(x: f32): f32 {
|
||||
return Mathf.round(x);
|
||||
}
|
||||
|
||||
export function sign(x: f32): f32 {
|
||||
return Mathf.sign(x);
|
||||
}
|
||||
|
||||
export function sin(x: f32): f32 {
|
||||
return Mathf.sin(x);
|
||||
}
|
||||
|
||||
export function sinh(x: f32): f32 {
|
||||
return Mathf.sinh(x);
|
||||
}
|
||||
|
||||
export function sqrt(x: f32): f32 {
|
||||
return Mathf.sqrt(x);
|
||||
}
|
||||
|
||||
export function tan(x: f32): f32 {
|
||||
return Mathf.tan(x);
|
||||
}
|
||||
|
||||
export function tanh(x: f32): f32 {
|
||||
return Mathf.tanh(x);
|
||||
}
|
||||
|
||||
export function trunc(x: f32): f32 {
|
||||
return Mathf.trunc(x);
|
||||
}
|
6
lib/libm/assembly/tsconfig.json
Normal file
6
lib/libm/assembly/tsconfig.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"extends": "../../../std/assembly.json",
|
||||
"include": [
|
||||
"./**/*.ts"
|
||||
]
|
||||
}
|
2
lib/libm/build/.gitignore
vendored
Normal file
2
lib/libm/build/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
*.wasm
|
||||
*.wasm.map
|
3934
lib/libm/build/libm.wat
Normal file
3934
lib/libm/build/libm.wat
Normal file
File diff suppressed because it is too large
Load Diff
4763
lib/libm/build/libmf.wat
Normal file
4763
lib/libm/build/libmf.wat
Normal file
File diff suppressed because it is too large
Load Diff
2
lib/libm/index.d.ts
vendored
Normal file
2
lib/libm/index.d.ts
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
declare const libm: typeof Math & { libm: typeof Math, libmf: typeof Math };
|
||||
export = libm;
|
7
lib/libm/index.js
Normal file
7
lib/libm/index.js
Normal file
@ -0,0 +1,7 @@
|
||||
const fs = require("fs");
|
||||
const libm = new WebAssembly.Instance(new WebAssembly.Module(fs.readFileSync("./build/libm.wasm")), { Math }).exports;
|
||||
const libmf = new WebAssembly.Instance(new WebAssembly.Module(fs.readFileSync("./build/libmf.wasm")), {}).exports;
|
||||
module.exports = Object.create(libm, {
|
||||
libm: { value: libm, enumerable: true },
|
||||
libmf: { value: libmf, enumerable: true }
|
||||
});
|
23
lib/libm/package.json
Normal file
23
lib/libm/package.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"name": "@assemblyscript/libm",
|
||||
"version": "1.0.0",
|
||||
"license": "Apache-2.0",
|
||||
"main": "index.js",
|
||||
"types": "index.d.ts",
|
||||
"scripts": {
|
||||
"asbuild": "npm run asbuild:libm && npm run asbuild:libmf",
|
||||
"asbuild:libm": "asc assembly/libm.ts -O3 -b build/libm.wasm -t build/libm.wat --runtime none --validate",
|
||||
"asbuild:libmf": "asc assembly/libmf.ts -O3 -b build/libmf.wasm -t build/libmf.wat --runtime none --validate"
|
||||
},
|
||||
"files": [
|
||||
"package.json",
|
||||
"index.d.ts",
|
||||
"index.js",
|
||||
"build/*.wasm",
|
||||
"README.md"
|
||||
],
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"assemblyscript": "AssemblyScript/assemblyscript"
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user