Add an option to alias global objects

This for example allows to switch the default 'Math' implementation a program will use. Uses 'NativeMath' by default.
This commit is contained in:
dcodeIO 2018-03-26 16:54:25 +02:00
parent e75d006d26
commit 792202ac5a
14 changed files with 186 additions and 167 deletions

View File

@ -363,6 +363,22 @@ exports.main = function main(argv, options, callback) {
assemblyscript.setImportTable(compilerOptions, !!args.importTable);
assemblyscript.setMemoryBase(compilerOptions, args.memoryBase >>> 0);
assemblyscript.setSourceMap(compilerOptions, args.sourceMap != null);
assemblyscript.setGlobalAlias(compilerOptions, "Math", "NativeMath");
// Add or override global aliases if specified
var aliases = args.use;
if (aliases != null) {
if (typeof aliases === "string") aliases = aliases.split(",");
for (let i = 0, k = aliases.length; i < k; ++i) {
let part = aliases[i];
let p = part.indexOf("=");
if (p < 0) return callback(Error("Global alias '" + part + "' is invalid."));
let name = part.substring(0, p).trim();
let alias = part.substring(p + 1).trim();
if (!name.length || !alias.length) return callback(Error("Global alias '" + part + "' is invalid."));
assemblyscript.setGlobalAlias(compilerOptions, name, alias);
}
}
var module;
stats.compileCount++;

View File

@ -122,6 +122,14 @@
],
"type": "string"
},
"use": {
"desc": [
"Aliases a global object under another name, e.g., to switch",
"the default 'Math' implementation used: --use Math=JSMath"
],
"type": "string",
"aliases": [ "u" ]
},
"trapMode": {
"desc": [
"Sets the trap mode to use.",

2
dist/asc.js vendored

File diff suppressed because one or more lines are too long

2
dist/asc.js.map vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -155,6 +155,8 @@ export class Options {
memoryBase: u32 = 0;
/** If true, generates information necessary for source maps. */
sourceMap: bool = false;
/** Global aliases. */
globalAliases: Map<string,string> | null = null;
/** Tests if the target is WASM64 or, otherwise, WASM32. */
get isWasm64(): bool {

View File

@ -125,6 +125,13 @@ export function setMemoryBase(options: Options, memoryBase: u32): void {
options.memoryBase = memoryBase;
}
/** Sets a 'globalAliases' value. */
export function setGlobalAlias(options: Options, name: string, alias: string): void {
var globalAliases = options.globalAliases;
if (!globalAliases) options.globalAliases = globalAliases = new Map();
globalAliases.set(name, alias);
}
/** Finishes parsing. */
export function finishParsing(parser: Parser): Program {
return parser.finish();

View File

@ -298,6 +298,15 @@ export class Program extends DiagnosticEmitter {
);
}
}
// set up global aliases
var globalAliases = options.globalAliases;
if (globalAliases) {
for (let [alias, name] of globalAliases) {
let element = this.elementsLookup.get(name); // TODO: error? has no source range
if (element) this.elementsLookup.set(alias, element);
}
}
}
/** Tries to resolve an import by traversing exports and queued exports. */
@ -319,8 +328,8 @@ export class Program extends DiagnosticEmitter {
} while (true);
}
/** Processes internal decorators, if present. */
private checkInternalDecorators(
/** Processes global options, if present. */
private checkGlobalOptions(
element: Element,
declaration: DeclarationStatement
): void {
@ -469,7 +478,7 @@ export class Program extends DiagnosticEmitter {
}
}
this.checkInternalDecorators(prototype, declaration);
this.checkGlobalOptions(prototype, declaration);
// check and possibly register string type
if (
@ -909,7 +918,7 @@ export class Program extends DiagnosticEmitter {
this.initializeEnumValue(values[i], element);
}
this.checkInternalDecorators(element, declaration);
this.checkGlobalOptions(element, declaration);
}
private initializeEnumValue(
@ -1133,7 +1142,7 @@ export class Program extends DiagnosticEmitter {
}
}
this.checkInternalDecorators(prototype, declaration);
this.checkGlobalOptions(prototype, declaration);
}
private initializeImports(
@ -1292,7 +1301,7 @@ export class Program extends DiagnosticEmitter {
}
}
this.checkInternalDecorators(prototype, declaration);
this.checkGlobalOptions(prototype, declaration);
}
private initializeNamespace(
@ -1307,7 +1316,7 @@ export class Program extends DiagnosticEmitter {
namespace = new Namespace(this, simpleName, internalName, declaration);
namespace.namespace = parentNamespace;
this.elementsLookup.set(internalName, namespace);
this.checkInternalDecorators(namespace, declaration);
this.checkGlobalOptions(namespace, declaration);
}
if (parentNamespace) {
@ -1472,7 +1481,7 @@ export class Program extends DiagnosticEmitter {
this.moduleLevelExports.set(internalName, global);
}
}
this.checkInternalDecorators(global, declaration);
this.checkGlobalOptions(global, declaration);
}
}

142
std/assembly.d.ts vendored
View File

@ -353,102 +353,56 @@ declare class Set<T> {
clear(): void;
}
declare namespace JSMath {
export const E: f64;
export const LN2: f64;
export const LN10: f64;
export const LOG2E: f64;
export const LOG10E: f64;
export const PI: f64;
export const SQRT1_2: f64;
export const SQRT2: f64;
export function abs(x: f64): f64;
export function acos(x: f64): f64;
export function acosh(x: f64): f64;
export function asin(x: f64): f64;
export function asinh(x: f64): f64;
export function atan(x: f64): f64;
export function atan2(y: f64, x: f64): f64;
export function atanh(x: f64): f64;
export function cbrt(x: f64): f64;
export function ceil(x: f64): f64;
export function clz32(x: f64): i32;
export function cos(x: f64): f64;
export function cosh(x: f64): f64;
export function exp(x: f64): f64;
export function expm1(x: f64): f64;
export function floor(x: f64): f64;
export function fround(x: f64): f32;
export function hypot(value1: f64, value2: f64): f64; // TODO: see std/math
export function imul(a: f64, b: f64): i32;
export function log(x: f64): f64;
export function log10(x: f64): f64;
export function log1p(x: f64): f64;
export function log2(x: f64): f64;
export function max(value1: f64, value2: f64): f64; // TODO: see std/math
export function min(value1: f64, value2: f64): f64; // TODO: see std/math
export function pow(base: f64, exponent: f64): f64;
export function random(): f64;
export function round(x: f64): f64;
export function sign(x: f64): f64;
export function sin(x: f64): f64;
export function sinh(x: f64): f64;
export function sqrt(x: f64): f64;
export function tan(x: f64): f64;
export function tanh(x: f64): f64;
export function trunc(x: f64): f64;
interface IMath<T> {
readonly E: T;
readonly LN2: T;
readonly LN10: T;
readonly LOG2E: T;
readonly LOG10E: T;
readonly PI: T;
readonly SQRT1_2: T;
readonly SQRT2: T;
abs(x: T): T;
acos(x: T): T;
acosh(x: T): T;
asin(x: T): T;
asinh(x: T): T;
atan(x: T): T;
atan2(y: T, x: T): T;
atanh(x: T): T;
cbrt(x: T): T;
ceil(x: T): T;
clz32(x: T): i32;
cos(x: T): T;
cosh(x: T): T;
exp(x: T): T;
expm1(x: T): T;
floor(x: T): T;
fround(x: T): f32;
hypot(value1: T, value2: T): T; // TODO: rest
imul(a: T, b: T): i32;
log(x: T): T;
log10(x: T): T;
log1p(x: T): T;
log2(x: T): T;
max(value1: T, value2: T): T; // TODO: rest
min(value1: T, value2: T): T; // TODO: rest
pow(base: T, exponent: T): T;
random(): T;
round(x: T): T;
sign(x: T): T;
sin(x: T): T;
sinh(x: T): T;
sqrt(x: T): T;
tan(x: T): T;
tanh(x: T): T;
trunc(x: T): T;
}
declare namespace Math {
export const E: f64;
export const LN2: f64;
export const LN10: f64;
export const LOG2E: f64;
export const LOG10E: f64;
export const PI: f64;
export const SQRT1_2: f64;
export const SQRT2: f64;
export function abs(x: f64): f64;
export function ceil(x: f64): f64;
export function clz32(x: f64): i32;
export function exp(x: f64): f64;
export function floor(x: f64): f64;
export function fround(x: f64): f32;
export function imul(a: f64, b: f64): i32;
export function log(x: f64): f64;
export function max(value1: f64, value2: f64): f64; // TODO: see std/math
export function min(value1: f64, value2: f64): f64; // TODO: see std/math
export function pow(x: f64, y: f64): f64;
export function round(x: f64): f64;
export function sign(x: f64): f64;
export function sqrt(x: f64): f64;
export function trunc(x: f64): f64;
}
declare namespace Mathf {
export const E: f32;
export const LN2: f32;
export const LN10: f32;
export const LOG2E: f32;
export const LOG10E: f32;
export const PI: f32;
export const SQRT1_2: f32;
export const SQRT2: f32;
export function abs(x: f32): f32;
export function exp(x: f32): f32;
export function ceil(x: f32): f32;
export function clz32(x: f32): i32;
export function floor(x: f32): f32;
export function imul(a: f32, b: f32): i32;
export function log(x: f32): f32;
export function max(value1: f32, value2: f32): f32; // TODO: see std/math
export function min(value1: f32, value2: f32): f32; // TODO: see std/math
export function pow(x: f32, y: f32): f32;
export function round(x: f32): f32;
export function sign(x: f32): f32;
export function sqrt(x: f32): f32;
export function trunc(x: f32): f32;
}
declare const JSMath: IMath<f64>;
declare const NativeMath: IMath<f64>;
declare const NativeMathf: IMath<f32>;
declare const Math: IMath<f64>;
// Internal decorators

View File

@ -58,14 +58,14 @@ import {
trunc as builtin_trunc
} from "./builtins";
// Math/Mathf.log/exp/pow
// NativeMath/NativeMathf.log/exp/pow
// Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
// Developed at SunPro, a Sun Microsystems, Inc. business.
// Permission to use, copy, modify, and distribute this
// software is freely granted, provided that this notice
// is preserved.
export namespace Math {
export namespace NativeMath {
export const E = 2.7182818284590452354;
export const LN2 = 0.69314718055994530942;
@ -468,16 +468,16 @@ export namespace Math {
}
}
export namespace Mathf {
export namespace NativeMathf {
export const E = <f32>Math.E;
export const LN2 = <f32>Math.LN2;
export const LN10 = <f32>Math.LN10;
export const LOG2E = <f32>Math.LOG2E;
export const LOG10E = <f32>Math.LOG10E;
export const PI = <f32>Math.PI;
export const SQRT1_2 = <f32>Math.SQRT1_2;
export const SQRT2 = <f32>Math.SQRT2;
export const E = <f32>NativeMath.E;
export const LN2 = <f32>NativeMath.LN2;
export const LN10 = <f32>NativeMath.LN10;
export const LOG2E = <f32>NativeMath.LOG2E;
export const LOG10E = <f32>NativeMath.LOG10E;
export const PI = <f32>NativeMath.PI;
export const SQRT1_2 = <f32>NativeMath.SQRT1_2;
export const SQRT2 = <f32>NativeMath.SQRT2;
export function abs(x: f32): f32 {
return builtin_abs(x);

View File

@ -13,6 +13,7 @@
(import "JSMath" "log" (func $(lib)/math/JSMath.log (param f64) (result f64)))
(import "JSMath" "exp" (func $(lib)/math/JSMath.exp (param f64) (result f64)))
(memory $0 1)
(data (i32.const 4) "\0b\00\00\00s\00t\00d\00/\00m\00a\00t\00h\00.\00t\00s")
(export "memory" (memory $0))
(start $start)
(func $fmod (; 2 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64)
@ -869,7 +870,7 @@
(get_local $4)
)
)
(func "$(lib)/math/Math.log" (; 8 ;) (type $FF) (param $0 f64) (result f64)
(func "$(lib)/math/NativeMath.log" (; 8 ;) (type $FF) (param $0 f64) (result f64)
(local $1 i32)
(local $2 i32)
(local $3 i64)
@ -1136,7 +1137,7 @@
)
(func $std/math/test_log (; 9 ;) (type $FFFiv) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32)
(call $std/math/check<f64>
(call "$(lib)/math/Math.log"
(call "$(lib)/math/NativeMath.log"
(get_local $0)
)
(get_local $1)
@ -1152,7 +1153,7 @@
(get_local $3)
)
)
(func "$(lib)/math/Mathf.log" (; 10 ;) (type $ff) (param $0 f32) (result f32)
(func "$(lib)/math/NativeMathf.log" (; 10 ;) (type $ff) (param $0 f32) (result f32)
(local $1 i32)
(local $2 i32)
(local $3 f32)
@ -1357,7 +1358,7 @@
)
(func $std/math/test_logf (; 11 ;) (type $fffiv) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 i32)
(call $std/math/check<f32>
(call "$(lib)/math/Mathf.log"
(call "$(lib)/math/NativeMathf.log"
(get_local $0)
)
(get_local $1)
@ -1479,7 +1480,7 @@
)
)
)
(func "$(lib)/math/Math.exp" (; 13 ;) (type $FF) (param $0 f64) (result f64)
(func "$(lib)/math/NativeMath.exp" (; 13 ;) (type $FF) (param $0 f64) (result f64)
(local $1 i32)
(local $2 f64)
(local $3 f64)
@ -1694,7 +1695,7 @@
)
(func $std/math/test_exp (; 14 ;) (type $FFFiv) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32)
(call $std/math/check<f64>
(call "$(lib)/math/Math.exp"
(call "$(lib)/math/NativeMath.exp"
(get_local $0)
)
(get_local $1)
@ -1822,7 +1823,7 @@
)
)
)
(func "$(lib)/math/Mathf.exp" (; 16 ;) (type $ff) (param $0 f32) (result f32)
(func "$(lib)/math/NativeMathf.exp" (; 16 ;) (type $ff) (param $0 f32) (result f32)
(local $1 i32)
(local $2 i32)
(local $3 f32)
@ -2016,7 +2017,7 @@
)
(func $std/math/test_expf (; 17 ;) (type $fffiv) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 i32)
(call $std/math/check<f32>
(call "$(lib)/math/Mathf.exp"
(call "$(lib)/math/NativeMathf.exp"
(get_local $0)
)
(get_local $1)
@ -2024,12 +2025,12 @@
(get_local $3)
)
)
(func "$(lib)/math/Math.sqrt" (; 18 ;) (type $FF) (param $0 f64) (result f64)
(func "$(lib)/math/NativeMath.sqrt" (; 18 ;) (type $FF) (param $0 f64) (result f64)
(f64.sqrt
(get_local $0)
)
)
(func "$(lib)/math/Math.pow" (; 19 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64)
(func "$(lib)/math/NativeMath.pow" (; 19 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64)
(local $2 f64)
(local $3 f64)
(local $4 i32)
@ -2385,7 +2386,7 @@
(i32.const 0)
)
(return
(call "$(lib)/math/Math.sqrt"
(call "$(lib)/math/NativeMath.sqrt"
(get_local $0)
)
)
@ -3450,7 +3451,7 @@
)
(func $std/math/test_pow (; 20 ;) (type $FFFFiv) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 f64) (param $4 i32)
(call $std/math/check<f64>
(call "$(lib)/math/Math.pow"
(call "$(lib)/math/NativeMath.pow"
(get_local $0)
(get_local $1)
)
@ -3459,7 +3460,7 @@
(get_local $4)
)
)
(func "$(lib)/math/Mathf.pow" (; 21 ;) (type $fff) (param $0 f32) (param $1 f32) (result f32)
(func "$(lib)/math/NativeMathf.pow" (; 21 ;) (type $fff) (param $0 f32) (param $1 f32) (result f32)
(local $2 f32)
(local $3 f32)
(local $4 i32)
@ -4636,7 +4637,7 @@
)
(func $std/math/test_powf (; 22 ;) (type $ffffiv) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 f32) (param $4 i32)
(call $std/math/check<f32>
(call "$(lib)/math/Mathf.pow"
(call "$(lib)/math/NativeMathf.pow"
(get_local $0)
(get_local $1)
)

View File

@ -1,6 +1,8 @@
// based on http://nsz.repo.hu/git/?p=libc-test
// mostly generated from their tests using scripts/hexfloat.html
assert(Math.E == NativeMath.E); // global alias should exist
const INEXACT = 1 << 0;
const INVALID = 1 << 1;
const DIVBYZERO = 1 << 2;
@ -190,7 +192,7 @@ test_fmodf(-1.750000000, -0.5000000000, -0.2500000000, 0.000000000, 0);
// ================================ Math.log ================================
function test_log(value: f64, expected: f64, error: f64, flags: i32): void {
check<f64>(Math.log(value), expected, error, flags);
check<f64>(NativeMath.log(value), expected, error, flags);
check<f64>(JSMath.log(value), expected, error, flags);
}
@ -219,7 +221,7 @@ test_log(NaN, NaN, 0.00000000000000000, 0);
// ================================ Mathf.log ================================
function test_logf(value: f32, expected: f32, error: f32, flags: i32): void {
check<f32>(Mathf.log(value), expected, error, flags);
check<f32>(NativeMathf.log(value), expected, error, flags);
}
// sanity
@ -245,7 +247,7 @@ test_logf(NaN, NaN, 0.000000000, 0);
// ================================ Math.exp ================================
function test_exp(value: f64, expected: f64, error: f64, flags: i32): void {
check<f64>(Math.exp(value), expected, error, flags);
check<f64>(NativeMath.exp(value), expected, error, flags);
check<f64>(JSMath.exp(value), expected, error, flags);
}
@ -277,7 +279,7 @@ test_exp(1.03972148895263672, 2.82842915587641164, -0.226183772087097168, INEXAC
// ================================ Mathf.exp ================================
function test_expf(value: f32, expected: f32, error: f32, flags: i32): void {
check<f32>(Mathf.exp(value), expected, error, flags);
check<f32>(NativeMathf.exp(value), expected, error, flags);
}
// sanity
@ -311,7 +313,7 @@ test_expf(0.3465736210, 1.414213657, 0.4321174324, INEXACT);
// ================================ Math.pow ================================
function test_pow(left: f64, right: f64, expected: f64, error: f64, flags: i32): void {
check<f64>(Math.pow(left, right), expected, error, flags);
check<f64>(NativeMath.pow(left, right), expected, error, flags);
}
// sanity
@ -422,7 +424,7 @@ test_pow(-2.00000000000000000, -1.00000000000000000, -0.500000000000000000, 0.00
// ================================ Mathf.pow ================================
function test_powf(left: f32, right: f32, expected: f32, error: f32, flags: i32): void {
check<f32>(Mathf.pow(left, right), expected, error, flags);
check<f32>(NativeMathf.pow(left, right), expected, error, flags);
}
// sanity

View File

@ -1,4 +1,5 @@
(module
(type $iiiiv (func (param i32 i32 i32 i32)))
(type $i (func (result i32)))
(type $FFFFiv (func (param f64 f64 f64 f64 i32)))
(type $FFF (func (param f64 f64) (result f64)))
@ -13,6 +14,7 @@
(type $FiF (func (param f64 i32) (result f64)))
(type $fif (func (param f32 i32) (result f32)))
(type $v (func))
(import "env" "abort" (func $abort (param i32 i32 i32 i32)))
(import "JSMath" "log" (func $(lib)/math/JSMath.log (param f64) (result f64)))
(import "JSMath" "exp" (func $(lib)/math/JSMath.exp (param f64) (result f64)))
(global $std/math/INEXACT i32 (i32.const 1))
@ -20,11 +22,12 @@
(global $std/math/DIVBYZERO i32 (i32.const 4))
(global $std/math/UNDERFLOW i32 (i32.const 8))
(global $std/math/OVERFLOW i32 (i32.const 16))
(global $HEAP_BASE i32 (i32.const 4))
(global $HEAP_BASE i32 (i32.const 32))
(memory $0 1)
(data (i32.const 4) "\0b\00\00\00s\00t\00d\00/\00m\00a\00t\00h\00.\00t\00s\00")
(export "memory" (memory $0))
(start $start)
(func $fmod (; 2 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64)
(func $fmod (; 3 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64)
(local $2 i64)
(local $3 i64)
(local $4 i32)
@ -479,7 +482,7 @@
)
)
)
(func $std/math/check<f64> (; 3 ;) (type $FFFiv) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32)
(func $std/math/check<f64> (; 4 ;) (type $FFFiv) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32)
(local $4 f64)
(local $5 i32)
(if
@ -536,7 +539,7 @@
)
)
)
(func $std/math/test_fmod (; 4 ;) (type $FFFFiv) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 f64) (param $4 i32)
(func $std/math/test_fmod (; 5 ;) (type $FFFFiv) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 f64) (param $4 i32)
(call $std/math/check<f64>
(call $fmod
(get_local $0)
@ -547,7 +550,7 @@
(get_local $4)
)
)
(func $fmodf (; 5 ;) (type $fff) (param $0 f32) (param $1 f32) (result f32)
(func $fmodf (; 6 ;) (type $fff) (param $0 f32) (param $1 f32) (result f32)
(local $2 i32)
(local $3 i32)
(local $4 i32)
@ -983,7 +986,7 @@
)
)
)
(func $std/math/check<f32> (; 6 ;) (type $fffiv) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 i32)
(func $std/math/check<f32> (; 7 ;) (type $fffiv) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 i32)
(local $4 f32)
(local $5 i32)
(if
@ -1040,7 +1043,7 @@
)
)
)
(func $std/math/test_fmodf (; 7 ;) (type $ffffiv) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 f32) (param $4 i32)
(func $std/math/test_fmodf (; 8 ;) (type $ffffiv) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 f32) (param $4 i32)
(call $std/math/check<f32>
(call $fmodf
(get_local $0)
@ -1051,7 +1054,7 @@
(get_local $4)
)
)
(func "$(lib)/math/Math.log" (; 8 ;) (type $FF) (param $0 f64) (result f64)
(func "$(lib)/math/NativeMath.log" (; 9 ;) (type $FF) (param $0 f64) (result f64)
(local $1 i64)
(local $2 i32)
(local $3 i32)
@ -1364,9 +1367,9 @@
)
)
)
(func $std/math/test_log (; 9 ;) (type $FFFiv) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32)
(func $std/math/test_log (; 10 ;) (type $FFFiv) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32)
(call $std/math/check<f64>
(call "$(lib)/math/Math.log"
(call "$(lib)/math/NativeMath.log"
(get_local $0)
)
(get_local $1)
@ -1382,7 +1385,7 @@
(get_local $3)
)
)
(func "$(lib)/math/Mathf.log" (; 10 ;) (type $ff) (param $0 f32) (result f32)
(func "$(lib)/math/NativeMathf.log" (; 11 ;) (type $ff) (param $0 f32) (result f32)
(local $1 i32)
(local $2 i32)
(local $3 i32)
@ -1629,9 +1632,9 @@
)
)
)
(func $std/math/test_logf (; 11 ;) (type $fffiv) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 i32)
(func $std/math/test_logf (; 12 ;) (type $fffiv) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 i32)
(call $std/math/check<f32>
(call "$(lib)/math/Mathf.log"
(call "$(lib)/math/NativeMathf.log"
(get_local $0)
)
(get_local $1)
@ -1639,7 +1642,7 @@
(get_local $3)
)
)
(func "$(lib)/math/scalbn" (; 12 ;) (type $FiF) (param $0 f64) (param $1 i32) (result f64)
(func "$(lib)/math/scalbn" (; 13 ;) (type $FiF) (param $0 f64) (param $1 i32) (result f64)
(local $2 f64)
(nop)
(set_local $2
@ -1760,7 +1763,7 @@
)
)
)
(func "$(lib)/math/Math.exp" (; 13 ;) (type $FF) (param $0 f64) (result f64)
(func "$(lib)/math/NativeMath.exp" (; 14 ;) (type $FF) (param $0 f64) (result f64)
(local $1 i32)
(local $2 f64)
(local $3 f64)
@ -2009,9 +2012,9 @@
)
)
)
(func $std/math/test_exp (; 14 ;) (type $FFFiv) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32)
(func $std/math/test_exp (; 15 ;) (type $FFFiv) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32)
(call $std/math/check<f64>
(call "$(lib)/math/Math.exp"
(call "$(lib)/math/NativeMath.exp"
(get_local $0)
)
(get_local $1)
@ -2027,7 +2030,7 @@
(get_local $3)
)
)
(func "$(lib)/math/scalbnf" (; 15 ;) (type $fif) (param $0 f32) (param $1 i32) (result f32)
(func "$(lib)/math/scalbnf" (; 16 ;) (type $fif) (param $0 f32) (param $1 i32) (result f32)
(local $2 f32)
(nop)
(set_local $2
@ -2146,7 +2149,7 @@
)
)
)
(func "$(lib)/math/Mathf.exp" (; 16 ;) (type $ff) (param $0 f32) (result f32)
(func "$(lib)/math/NativeMathf.exp" (; 17 ;) (type $ff) (param $0 f32) (result f32)
(local $1 i32)
(local $2 i32)
(local $3 i32)
@ -2367,9 +2370,9 @@
)
)
)
(func $std/math/test_expf (; 17 ;) (type $fffiv) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 i32)
(func $std/math/test_expf (; 18 ;) (type $fffiv) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 i32)
(call $std/math/check<f32>
(call "$(lib)/math/Mathf.exp"
(call "$(lib)/math/NativeMathf.exp"
(get_local $0)
)
(get_local $1)
@ -2377,14 +2380,14 @@
(get_local $3)
)
)
(func "$(lib)/math/Math.sqrt" (; 18 ;) (type $FF) (param $0 f64) (result f64)
(func "$(lib)/math/NativeMath.sqrt" (; 19 ;) (type $FF) (param $0 f64) (result f64)
(return
(f64.sqrt
(get_local $0)
)
)
)
(func "$(lib)/math/Math.pow" (; 19 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64)
(func "$(lib)/math/NativeMath.pow" (; 20 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64)
(local $2 i64)
(local $3 i32)
(local $4 i32)
@ -2782,7 +2785,7 @@
(i32.const 0)
)
(return
(call "$(lib)/math/Math.sqrt"
(call "$(lib)/math/NativeMath.sqrt"
(get_local $0)
)
)
@ -3984,9 +3987,9 @@
)
)
)
(func $std/math/test_pow (; 20 ;) (type $FFFFiv) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 f64) (param $4 i32)
(func $std/math/test_pow (; 21 ;) (type $FFFFiv) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 f64) (param $4 i32)
(call $std/math/check<f64>
(call "$(lib)/math/Math.pow"
(call "$(lib)/math/NativeMath.pow"
(get_local $0)
(get_local $1)
)
@ -3995,7 +3998,7 @@
(get_local $4)
)
)
(func "$(lib)/math/Mathf.pow" (; 21 ;) (type $fff) (param $0 f32) (param $1 f32) (result f32)
(func "$(lib)/math/NativeMathf.pow" (; 22 ;) (type $fff) (param $0 f32) (param $1 f32) (result f32)
(local $2 i32)
(local $3 i32)
(local $4 i32)
@ -5335,9 +5338,9 @@
)
)
)
(func $std/math/test_powf (; 22 ;) (type $ffffiv) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 f32) (param $4 i32)
(func $std/math/test_powf (; 23 ;) (type $ffffiv) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 f32) (param $4 i32)
(call $std/math/check<f32>
(call "$(lib)/math/Mathf.pow"
(call "$(lib)/math/NativeMathf.pow"
(get_local $0)
(get_local $1)
)
@ -5346,7 +5349,24 @@
(get_local $4)
)
)
(func $start (; 23 ;) (type $v)
(func $start (; 24 ;) (type $v)
(if
(i32.eqz
(f64.eq
(f64.const 2.718281828459045)
(f64.const 2.718281828459045)
)
)
(block
(call $abort
(i32.const 0)
(i32.const 4)
(i32.const 4)
(i32.const 0)
)
(unreachable)
)
)
(call $std/math/test_fmod
(f64.const -8.06684839057968)
(f64.const 4.535662560676869)