mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-04-25 15:12:12 +00:00
Support parameter properties; Minor formatting
This commit is contained in:
parent
c80bf35747
commit
38a025950e
@ -5,7 +5,7 @@
|
||||
[](https://travis-ci.org/AssemblyScript/assemblyscript)
|
||||
[](https://build.snapcraft.io/user/AssemblyScript/assemblyscript)
|
||||
|
||||
**AssemblyScript** compiles strictly typed [TypeScript](http://www.typescriptlang.org) to [WebAssembly](http://webassembly.org) using [Binaryen](https://github.com/WebAssembly/binaryen). It generates minimal WebAssembly modules while being just an `npm install` away.
|
||||
**AssemblyScript** compiles strictly typed [TypeScript](http://www.typescriptlang.org) to [WebAssembly](http://webassembly.org) using [Binaryen](https://github.com/WebAssembly/binaryen). It generates lean and mean WebAssembly modules while being just an `npm install` away.
|
||||
|
||||
See [the AssemblyScript wiki](https://github.com/AssemblyScript/assemblyscript/wiki) for further instructions and documentation. You can also try it out in [WebAssembly Studio](https://webassembly.studio)!
|
||||
|
||||
|
2
dist/asc.js
vendored
2
dist/asc.js
vendored
File diff suppressed because one or more lines are too long
2
dist/asc.js.map
vendored
2
dist/asc.js.map
vendored
File diff suppressed because one or more lines are too long
2
dist/assemblyscript.js
vendored
2
dist/assemblyscript.js
vendored
File diff suppressed because one or more lines are too long
2
dist/assemblyscript.js.map
vendored
2
dist/assemblyscript.js.map
vendored
File diff suppressed because one or more lines are too long
@ -80,9 +80,6 @@
|
||||
"no-object-literal-type-assertion": {
|
||||
"severity": "error"
|
||||
},
|
||||
"no-parameter-properties": {
|
||||
"severity": "error"
|
||||
},
|
||||
"no-require-imports": {
|
||||
"severity": "error"
|
||||
},
|
||||
|
@ -1047,6 +1047,8 @@ export class ParameterNode extends Node {
|
||||
type: CommonTypeNode;
|
||||
/** Initializer expression, if present. */
|
||||
initializer: Expression | null;
|
||||
/** Implicit field declaration, if applicable. */
|
||||
implicitFieldDeclaration: FieldDeclaration | null = null;
|
||||
}
|
||||
|
||||
/** Represents a function signature. */
|
||||
@ -1583,6 +1585,9 @@ export class ExpressionStatement extends Statement {
|
||||
/** Represents a field declaration within a `class`. */
|
||||
export class FieldDeclaration extends VariableLikeDeclarationStatement {
|
||||
kind = NodeKind.FIELDDECLARATION;
|
||||
|
||||
/** Parameter index within the constructor, if applicable. */
|
||||
parameterIndex: i32 = -1;
|
||||
}
|
||||
|
||||
/** Represents a `for` statement. */
|
||||
|
@ -108,7 +108,8 @@ import {
|
||||
ArrayLiteralExpression,
|
||||
StringLiteralExpression,
|
||||
UnaryPostfixExpression,
|
||||
UnaryPrefixExpression
|
||||
UnaryPrefixExpression,
|
||||
FieldDeclaration
|
||||
} from "./ast";
|
||||
|
||||
import {
|
||||
@ -5999,21 +6000,25 @@ export function makeAllocate(compiler: Compiler, classInstance: Class, reportNod
|
||||
if (member.kind == ElementKind.FIELD) {
|
||||
let field = <Field>member;
|
||||
let fieldType = field.type;
|
||||
let nativeFieldType = fieldType.toNativeType();
|
||||
let fieldDeclaration = field.prototype.declaration;
|
||||
assert(!field.isAny(CommonFlags.CONST));
|
||||
if (fieldDeclaration.initializer) { // use initializer
|
||||
initializers.push(module.createStore(fieldType.byteSize,
|
||||
module.createGetLocal(tempLocal.index, nativeSizeType),
|
||||
compiler.compileExpression(fieldDeclaration.initializer, fieldType), // reports
|
||||
fieldType.toNativeType(),
|
||||
nativeFieldType,
|
||||
field.memoryOffset
|
||||
));
|
||||
} else { // initialize with zero
|
||||
// TODO: might be unnecessary if the ctor initializes the field
|
||||
initializers.push(module.createStore(field.type.byteSize,
|
||||
let parameterIndex = (<FieldDeclaration>field.prototype.declaration).parameterIndex;
|
||||
initializers.push(module.createStore(fieldType.byteSize,
|
||||
module.createGetLocal(tempLocal.index, nativeSizeType),
|
||||
field.type.toNativeZero(module),
|
||||
field.type.toNativeType(),
|
||||
parameterIndex >= 0 // initialized via parameter
|
||||
? module.createGetLocal(1 + parameterIndex, nativeFieldType)
|
||||
: fieldType.toNativeZero(module),
|
||||
nativeFieldType,
|
||||
field.memoryOffset
|
||||
));
|
||||
}
|
||||
|
@ -72,6 +72,7 @@ export enum DiagnosticCode {
|
||||
Decorators_are_not_valid_here = 1206,
|
||||
_abstract_modifier_can_only_appear_on_a_class_method_or_property_declaration = 1242,
|
||||
A_class_may_only_extend_another_class = 1311,
|
||||
A_parameter_property_cannot_be_declared_using_a_rest_parameter = 1317,
|
||||
Duplicate_identifier_0 = 2300,
|
||||
Cannot_find_name_0 = 2304,
|
||||
Module_0_has_no_exported_member_1 = 2305,
|
||||
@ -176,6 +177,7 @@ export function diagnosticCodeToString(code: DiagnosticCode): string {
|
||||
case 1206: return "Decorators are not valid here.";
|
||||
case 1242: return "'abstract' modifier can only appear on a class, method, or property declaration.";
|
||||
case 1311: return "A class may only extend another class.";
|
||||
case 1317: return "A parameter property cannot be declared using a rest parameter.";
|
||||
case 2300: return "Duplicate identifier '{0}'.";
|
||||
case 2304: return "Cannot find name '{0}'.";
|
||||
case 2305: return "Module '{0}' has no exported member '{1}'.";
|
||||
|
@ -65,6 +65,7 @@
|
||||
"Decorators are not valid here.": 1206,
|
||||
"'abstract' modifier can only appear on a class, method, or property declaration.": 1242,
|
||||
"A class may only extend another class.": 1311,
|
||||
"A parameter property cannot be declared using a rest parameter.": 1317,
|
||||
|
||||
"Duplicate identifier '{0}'.": 2300,
|
||||
"Cannot find name '{0}'.": 2304,
|
||||
|
@ -799,8 +799,11 @@ export class ASTBuilder {
|
||||
sb.push(" {\n");
|
||||
let indentLevel = ++this.indentLevel;
|
||||
for (let i = 0, k = members.length; i < k; ++i) {
|
||||
indent(sb, indentLevel);
|
||||
this.visitNodeAndTerminate(members[i]);
|
||||
let member = members[i];
|
||||
if (member.kind != NodeKind.FIELDDECLARATION || (<FieldDeclaration>member).parameterIndex < 0) {
|
||||
indent(sb, indentLevel);
|
||||
this.visitNodeAndTerminate(member);
|
||||
}
|
||||
}
|
||||
indent(sb, --this.indentLevel);
|
||||
sb.push("}");
|
||||
@ -1368,6 +1371,10 @@ export class ASTBuilder {
|
||||
serializeParameter(node: ParameterNode): void {
|
||||
var sb = this.sb;
|
||||
var kind = node.parameterKind;
|
||||
var implicitFieldDeclaration = node.implicitFieldDeclaration;
|
||||
if (implicitFieldDeclaration) {
|
||||
this.serializeAccessModifiers(implicitFieldDeclaration);
|
||||
}
|
||||
if (kind == ParameterKind.REST) {
|
||||
sb.push("...");
|
||||
}
|
||||
|
115
src/parser.ts
115
src/parser.ts
@ -967,7 +967,8 @@ export class Parser extends DiagnosticEmitter {
|
||||
}
|
||||
|
||||
parseParameters(
|
||||
tn: Tokenizer
|
||||
tn: Tokenizer,
|
||||
isConstructor: bool = false
|
||||
): ParameterNode[] | null {
|
||||
|
||||
// at '(': (Parameter (',' Parameter)*)? ')'
|
||||
@ -979,7 +980,7 @@ export class Parser extends DiagnosticEmitter {
|
||||
|
||||
if (tn.peek() != Token.CLOSEPAREN) {
|
||||
do {
|
||||
let param = this.parseParameter(tn);
|
||||
let param = this.parseParameter(tn, isConstructor);
|
||||
if (!param) return null;
|
||||
if (seenRest && !reportedRest) {
|
||||
this.error(
|
||||
@ -1022,17 +1023,63 @@ export class Parser extends DiagnosticEmitter {
|
||||
|
||||
parseParameter(
|
||||
tn: Tokenizer,
|
||||
suppressErrors: bool = false
|
||||
isConstructor: bool = false
|
||||
): ParameterNode | null {
|
||||
|
||||
// before: '...'? Identifier '?'? (':' Type)? ('=' Expression)?
|
||||
// before: ('public' | 'private' | 'protected' | '...')? Identifier '?'? (':' Type)? ('=' Expression)?
|
||||
|
||||
var isRest = false;
|
||||
var isOptional = false;
|
||||
var startRange: Range | null = null;
|
||||
if (tn.skip(Token.DOT_DOT_DOT)) {
|
||||
isRest = true;
|
||||
var accessFlags: CommonFlags = CommonFlags.NONE;
|
||||
if (tn.skip(Token.PUBLIC)) {
|
||||
startRange = tn.range();
|
||||
if (!isConstructor) {
|
||||
this.error(
|
||||
DiagnosticCode._0_modifier_cannot_be_used_here,
|
||||
startRange, "public"
|
||||
);
|
||||
}
|
||||
accessFlags |= CommonFlags.PUBLIC;
|
||||
} else if (tn.skip(Token.PROTECTED)) {
|
||||
startRange = tn.range();
|
||||
if (!isConstructor) {
|
||||
this.error(
|
||||
DiagnosticCode._0_modifier_cannot_be_used_here,
|
||||
startRange, "protected"
|
||||
);
|
||||
}
|
||||
accessFlags |= CommonFlags.PROTECTED;
|
||||
} else if (tn.skip(Token.PRIVATE)) {
|
||||
startRange = tn.range();
|
||||
if (!isConstructor) {
|
||||
this.error(
|
||||
DiagnosticCode._0_modifier_cannot_be_used_here,
|
||||
startRange, "private"
|
||||
);
|
||||
}
|
||||
accessFlags |= CommonFlags.PRIVATE;
|
||||
}
|
||||
if (tn.skip(Token.READONLY)) {
|
||||
if (!startRange) startRange = tn.range();
|
||||
if (!isConstructor) {
|
||||
this.error(
|
||||
DiagnosticCode._0_modifier_cannot_be_used_here,
|
||||
startRange, "readonly"
|
||||
);
|
||||
}
|
||||
accessFlags |= CommonFlags.READONLY;
|
||||
}
|
||||
if (tn.skip(Token.DOT_DOT_DOT)) {
|
||||
if (accessFlags) {
|
||||
this.error(
|
||||
DiagnosticCode.A_parameter_property_cannot_be_declared_using_a_rest_parameter,
|
||||
tn.range()
|
||||
);
|
||||
} else {
|
||||
startRange = tn.range();
|
||||
}
|
||||
isRest = true;
|
||||
}
|
||||
if (tn.skip(Token.IDENTIFIER)) {
|
||||
if (!isRest) startRange = tn.range();
|
||||
@ -1071,7 +1118,7 @@ export class Parser extends DiagnosticEmitter {
|
||||
initializer = this.parseExpression(tn, Precedence.COMMA + 1);
|
||||
if (!initializer) return null;
|
||||
}
|
||||
return Node.createParameter(
|
||||
let param = Node.createParameter(
|
||||
identifier,
|
||||
type,
|
||||
initializer,
|
||||
@ -1082,6 +1129,8 @@ export class Parser extends DiagnosticEmitter {
|
||||
: ParameterKind.DEFAULT,
|
||||
Range.join(<Range>startRange, tn.range())
|
||||
);
|
||||
param.flags |= accessFlags;
|
||||
return param;
|
||||
} else {
|
||||
this.error(
|
||||
DiagnosticCode.Identifier_expected,
|
||||
@ -1400,14 +1449,7 @@ export class Parser extends DiagnosticEmitter {
|
||||
}
|
||||
|
||||
var members = new Array<DeclarationStatement>();
|
||||
if (!tn.skip(Token.CLOSEBRACE)) {
|
||||
do {
|
||||
let member = this.parseClassMember(tn, flags);
|
||||
if (!member) return null;
|
||||
members.push(<DeclarationStatement>member);
|
||||
} while (!tn.skip(Token.CLOSEBRACE));
|
||||
}
|
||||
return Node.createClassDeclaration(
|
||||
var declaration = Node.createClassDeclaration(
|
||||
identifier,
|
||||
typeParameters,
|
||||
extendsType,
|
||||
@ -1417,11 +1459,20 @@ export class Parser extends DiagnosticEmitter {
|
||||
flags,
|
||||
tn.range(startPos, tn.pos)
|
||||
);
|
||||
if (!tn.skip(Token.CLOSEBRACE)) {
|
||||
do {
|
||||
let member = this.parseClassMember(tn, declaration);
|
||||
if (!member) return null;
|
||||
member.parent = declaration;
|
||||
members.push(<DeclarationStatement>member);
|
||||
} while (!tn.skip(Token.CLOSEBRACE));
|
||||
}
|
||||
return declaration;
|
||||
}
|
||||
|
||||
parseClassMember(
|
||||
tn: Tokenizer,
|
||||
parentFlags: CommonFlags
|
||||
parent: ClassDeclaration
|
||||
): DeclarationStatement | null {
|
||||
|
||||
// before:
|
||||
@ -1440,7 +1491,7 @@ export class Parser extends DiagnosticEmitter {
|
||||
decorators.push(<DecoratorNode>decorator);
|
||||
}
|
||||
|
||||
var flags = parentFlags & CommonFlags.AMBIENT; // inherit
|
||||
var flags = parent.flags & CommonFlags.AMBIENT; // inherit
|
||||
|
||||
if (tn.skip(Token.PUBLIC)) {
|
||||
flags |= CommonFlags.PUBLIC;
|
||||
@ -1466,7 +1517,7 @@ export class Parser extends DiagnosticEmitter {
|
||||
} else {
|
||||
flags |= CommonFlags.INSTANCE;
|
||||
}
|
||||
if (parentFlags & CommonFlags.GENERIC) {
|
||||
if (parent.flags & CommonFlags.GENERIC) {
|
||||
flags |= CommonFlags.GENERIC_CONTEXT;
|
||||
}
|
||||
}
|
||||
@ -1575,10 +1626,32 @@ export class Parser extends DiagnosticEmitter {
|
||||
// method: '(' Parameters (':' Type)? '{' Statement* '}' ';'?
|
||||
if (tn.skip(Token.OPENPAREN)) {
|
||||
let signatureStart = tn.tokenPos;
|
||||
let parameters = this.parseParameters(tn);
|
||||
let parameters = this.parseParameters(tn, isConstructor);
|
||||
if (!parameters) return null;
|
||||
|
||||
if (isGetter) {
|
||||
if (isConstructor) {
|
||||
for (let i = 0, k = parameters.length; i < k; ++i) {
|
||||
let parameter = parameters[i];
|
||||
if (parameter.isAny(
|
||||
CommonFlags.PUBLIC |
|
||||
CommonFlags.PROTECTED |
|
||||
CommonFlags.PRIVATE |
|
||||
CommonFlags.READONLY
|
||||
)) {
|
||||
let implicitFieldDeclaration = Node.createFieldDeclaration(
|
||||
parameter.name,
|
||||
parameter.type,
|
||||
null, // initialized via parameter
|
||||
null,
|
||||
parameter.flags | CommonFlags.INSTANCE,
|
||||
parameter.range
|
||||
);
|
||||
implicitFieldDeclaration.parameterIndex = i;
|
||||
implicitFieldDeclaration.parent = parent;
|
||||
parameter.implicitFieldDeclaration = implicitFieldDeclaration;
|
||||
parent.members.push(implicitFieldDeclaration);
|
||||
}
|
||||
}
|
||||
} else if (isGetter) {
|
||||
if (parameters.length) {
|
||||
this.error(
|
||||
DiagnosticCode.A_get_accessor_cannot_have_parameters,
|
||||
|
@ -111,46 +111,37 @@ export namespace Math {
|
||||
Lg6 = 1.531383769920937332e-01, // 3FC39A09 D078C69F
|
||||
Lg7 = 1.479819860511658591e-01; // 3FC2F112 DF3E5244
|
||||
|
||||
var u = reinterpret<u64>(x);
|
||||
var hfsq: f64, f: f64, s: f64, z: f64, R: f64, w: f64, t1: f64, t2: f64, dk: f64;
|
||||
|
||||
var hx = <u32>(u >> 32);
|
||||
var Ux = reinterpret<u64>(x);
|
||||
var hx = <u32>(Ux >> 32);
|
||||
var k = 0;
|
||||
if (hx < 0x00100000 || <bool>(hx>>31)) {
|
||||
if (u<<1 == 0) {
|
||||
return -1/(x*x); // log(+-0)=-inf
|
||||
}
|
||||
if (hx>>31) {
|
||||
return (x-x)/0.0; // log(-#) = NaN
|
||||
}
|
||||
if (hx < 0x00100000 || <bool>(hx >> 31)) {
|
||||
if (Ux << 1 == 0) return -1 / (x * x); // log(+-0)=-inf
|
||||
if (hx >> 31) return (x - x) / 0.0; // log(-#) = NaN
|
||||
// subnormal number, scale x up
|
||||
k -= 54;
|
||||
x *= 1.8014398509481984e16; // 0x1p54
|
||||
u = reinterpret<u64>(x);
|
||||
hx = <u32>(u>>32);
|
||||
} else if (hx >= 0x7ff00000) {
|
||||
return x;
|
||||
} else if (hx == 0x3ff00000 && u<<32 == 0) {
|
||||
return 0;
|
||||
}
|
||||
Ux = reinterpret<u64>(x);
|
||||
hx = <u32>(Ux >> 32);
|
||||
} else if (hx >= 0x7ff00000) return x;
|
||||
else if (hx == 0x3ff00000 && Ux << 32 == 0) return 0;
|
||||
|
||||
// reduce x into [sqrt(2)/2, sqrt(2)]
|
||||
hx += 0x3ff00000 - 0x3fe6a09e;
|
||||
k += (<i32>hx>>20) - 0x3ff;
|
||||
hx = (hx&0x000fffff) + 0x3fe6a09e;
|
||||
u = <u64>hx<<32 | (u&0xffffffff);
|
||||
x = reinterpret<f64>(u);
|
||||
k += (<i32>hx >> 20) - 0x3ff;
|
||||
hx = (hx & 0x000fffff) + 0x3fe6a09e;
|
||||
Ux = <u64>hx << 32 | (Ux & 0xffffffff);
|
||||
x = reinterpret<f64>(Ux);
|
||||
|
||||
f = x - 1.0;
|
||||
hfsq = 0.5*f*f;
|
||||
s = f/(2.0+f);
|
||||
z = s*s;
|
||||
w = z*z;
|
||||
t1 = w*(Lg2+w*(Lg4+w*Lg6));
|
||||
t2 = z*(Lg1+w*(Lg3+w*(Lg5+w*Lg7)));
|
||||
R = t2 + t1;
|
||||
dk = k;
|
||||
return s*(hfsq+R) + dk*ln2_lo - hfsq + f + dk*ln2_hi;
|
||||
var f = x - 1.0;
|
||||
var hfsq = 0.5 * f * f;
|
||||
var s = f / (2.0 + f);
|
||||
var z = s * s;
|
||||
var w = z * z;
|
||||
var t1 = w * (Lg2 + w * (Lg4 + w * Lg6));
|
||||
var t2 = z * (Lg1 + w * (Lg3 + w * (Lg5 + w * Lg7)));
|
||||
var R = t2 + t1;
|
||||
var dk = k;
|
||||
return s * (hfsq + R) + dk * ln2_lo - hfsq + f + dk * ln2_hi;
|
||||
}
|
||||
|
||||
// export function log2(x: f64): f64 {
|
||||
@ -225,52 +216,41 @@ export namespace Mathf {
|
||||
// software is freely granted, provided that this notice
|
||||
// is preserved.
|
||||
const
|
||||
ln2_hi: f32 = 6.9313812256e-01, // 0x3f317180
|
||||
ln2_lo: f32 = 9.0580006145e-06, // 0x3717f7d1
|
||||
Lg1: f32 = 0.66666662693, // 0xaaaaaa.0p-24
|
||||
Lg2: f32 = 0.40000972152, // 0xccce13.0p-25
|
||||
Lg3: f32 = 0.28498786688, // 0x91e9ee.0p-25
|
||||
Lg4: f32 = 0.24279078841; // 0xf89e26.0p-26
|
||||
ln2_hi = <f32>6.9313812256e-01, // 0x3f317180
|
||||
ln2_lo = <f32>9.0580006145e-06, // 0x3717f7d1
|
||||
Lg1 = <f32>0.66666662693, // 0xaaaaaa.0p-24
|
||||
Lg2 = <f32>0.40000972152, // 0xccce13.0p-25
|
||||
Lg3 = <f32>0.28498786688, // 0x91e9ee.0p-25
|
||||
Lg4 = <f32>0.24279078841; // 0xf89e26.0p-26
|
||||
|
||||
var u = reinterpret<u32>(x);
|
||||
var hfsq: f32, f: f32, s: f32, z: f32, R: f32, w: f32, t1: f32, t2: f32, dk: f32;
|
||||
|
||||
var ix = u;
|
||||
var ux = reinterpret<u32>(x);
|
||||
var k = 0;
|
||||
if (ix < 0x00800000 || <bool>(ix>>31)) { // x < 2**-126
|
||||
if (ix<<1 == 0) {
|
||||
return -1/(x*x); // log(+-0)=-inf
|
||||
}
|
||||
if (ix>>31) {
|
||||
return (x-x)/<f32>0; // log(-#) = NaN
|
||||
}
|
||||
if (ux < 0x00800000 || <bool>(ux >> 31)) { // x < 2**-126
|
||||
if (ux << 1 == 0) return -1 / (x * x); // log(+-0)=-inf
|
||||
if (ux >> 31) return (x - x) / 0; // log(-#) = NaN
|
||||
// subnormal number, scale up x
|
||||
k -= 25;
|
||||
x *= 3.3554432; // 0x1p25f;
|
||||
u = reinterpret<u32>(x);
|
||||
ix = u;
|
||||
} else if (ix >= 0x7f800000) {
|
||||
return x;
|
||||
} else if (ix == 0x3f800000) {
|
||||
return 0;
|
||||
}
|
||||
ux = reinterpret<u32>(x);
|
||||
} else if (ux >= 0x7f800000) return x;
|
||||
else if (ux == 0x3f800000) return 0;
|
||||
|
||||
// reduce x into [sqrt(2)/2, sqrt(2)]
|
||||
ix += 0x3f800000 - 0x3f3504f3;
|
||||
k += <u32>(<i32>ix>>23) - 0x7f;
|
||||
ix = (ix&0x007fffff) + 0x3f3504f3;
|
||||
x = reinterpret<f32>(ix);
|
||||
ux += 0x3f800000 - 0x3f3504f3;
|
||||
k += <u32>(<i32>ux >> 23) - 0x7f;
|
||||
ux = (ux & 0x007fffff) + 0x3f3504f3;
|
||||
x = reinterpret<f32>(ux);
|
||||
|
||||
f = x - 1.0;
|
||||
s = f/(2.0 + f);
|
||||
z = s*s;
|
||||
w = z*z;
|
||||
t1= w*(Lg2+w*Lg4);
|
||||
t2= z*(Lg1+w*Lg3);
|
||||
R = t2 + t1;
|
||||
hfsq = 0.5*f*f;
|
||||
dk = <f32>k;
|
||||
return s*(hfsq+R) + dk*ln2_lo - hfsq + f + dk*ln2_hi;
|
||||
var f = x - 1.0;
|
||||
var s = f / (2.0 + f);
|
||||
var z = s * s;
|
||||
var w = z * z;
|
||||
var t1 = w * (Lg2 + w * Lg4);
|
||||
var t2 = z * (Lg1 + w * Lg3);
|
||||
var R = t2 + t1;
|
||||
var hfsq = <f32>0.5 * f * f;
|
||||
var dk = <f32>k;
|
||||
return s * (hfsq + R) + dk * ln2_lo - hfsq + f + dk * ln2_hi;
|
||||
}
|
||||
|
||||
// export function log2(x: f32): f32 {
|
||||
|
@ -258,10 +258,8 @@
|
||||
)
|
||||
)
|
||||
(f64.mul
|
||||
(tee_local $0
|
||||
(f64.convert_s/i32
|
||||
(get_local $2)
|
||||
)
|
||||
(f64.convert_s/i32
|
||||
(get_local $2)
|
||||
)
|
||||
(f64.const 1.9082149292705877e-10)
|
||||
)
|
||||
@ -271,7 +269,9 @@
|
||||
(get_local $4)
|
||||
)
|
||||
(f64.mul
|
||||
(get_local $0)
|
||||
(f64.convert_s/i32
|
||||
(get_local $2)
|
||||
)
|
||||
(f64.const 0.6931471803691238)
|
||||
)
|
||||
)
|
||||
|
@ -16,17 +16,17 @@
|
||||
(start $start)
|
||||
(func "$(lib)/math/Math.log" (; 3 ;) (type $FF) (param $0 f64) (result f64)
|
||||
(local $1 i64)
|
||||
(local $2 f64)
|
||||
(local $3 f64)
|
||||
(local $4 f64)
|
||||
(local $2 i32)
|
||||
(local $3 i32)
|
||||
(local $4 i32)
|
||||
(local $5 f64)
|
||||
(local $6 f64)
|
||||
(local $7 f64)
|
||||
(local $8 f64)
|
||||
(local $9 f64)
|
||||
(local $10 f64)
|
||||
(local $11 i32)
|
||||
(local $12 i32)
|
||||
(local $11 f64)
|
||||
(local $12 f64)
|
||||
(local $13 i32)
|
||||
(nop)
|
||||
(set_local $1
|
||||
@ -34,8 +34,7 @@
|
||||
(get_local $0)
|
||||
)
|
||||
)
|
||||
(nop)
|
||||
(set_local $11
|
||||
(set_local $2
|
||||
(i32.wrap/i64
|
||||
(i64.shr_u
|
||||
(get_local $1)
|
||||
@ -43,22 +42,22 @@
|
||||
)
|
||||
)
|
||||
)
|
||||
(set_local $12
|
||||
(set_local $3
|
||||
(i32.const 0)
|
||||
)
|
||||
(if
|
||||
(i32.and
|
||||
(if (result i32)
|
||||
(tee_local $13
|
||||
(tee_local $4
|
||||
(i32.lt_u
|
||||
(get_local $11)
|
||||
(get_local $2)
|
||||
(i32.const 1048576)
|
||||
)
|
||||
)
|
||||
(get_local $13)
|
||||
(get_local $4)
|
||||
(i32.and
|
||||
(i32.shr_u
|
||||
(get_local $11)
|
||||
(get_local $2)
|
||||
(i32.const 31)
|
||||
)
|
||||
(i32.const 1)
|
||||
@ -87,7 +86,7 @@
|
||||
)
|
||||
(if
|
||||
(i32.shr_u
|
||||
(get_local $11)
|
||||
(get_local $2)
|
||||
(i32.const 31)
|
||||
)
|
||||
(return
|
||||
@ -100,9 +99,9 @@
|
||||
)
|
||||
)
|
||||
)
|
||||
(set_local $12
|
||||
(set_local $3
|
||||
(i32.sub
|
||||
(get_local $12)
|
||||
(get_local $3)
|
||||
(i32.const 54)
|
||||
)
|
||||
)
|
||||
@ -117,7 +116,7 @@
|
||||
(get_local $0)
|
||||
)
|
||||
)
|
||||
(set_local $11
|
||||
(set_local $2
|
||||
(i32.wrap/i64
|
||||
(i64.shr_u
|
||||
(get_local $1)
|
||||
@ -128,7 +127,7 @@
|
||||
)
|
||||
(if
|
||||
(i32.ge_u
|
||||
(get_local $11)
|
||||
(get_local $2)
|
||||
(i32.const 2146435072)
|
||||
)
|
||||
(return
|
||||
@ -137,9 +136,9 @@
|
||||
(if
|
||||
(i32.and
|
||||
(if (result i32)
|
||||
(tee_local $13
|
||||
(tee_local $4
|
||||
(i32.eq
|
||||
(get_local $11)
|
||||
(get_local $2)
|
||||
(i32.const 1072693248)
|
||||
)
|
||||
)
|
||||
@ -150,7 +149,7 @@
|
||||
)
|
||||
(i64.const 0)
|
||||
)
|
||||
(get_local $13)
|
||||
(get_local $4)
|
||||
)
|
||||
(i32.const 1)
|
||||
)
|
||||
@ -160,31 +159,31 @@
|
||||
)
|
||||
)
|
||||
)
|
||||
(set_local $11
|
||||
(set_local $2
|
||||
(i32.add
|
||||
(get_local $11)
|
||||
(get_local $2)
|
||||
(i32.sub
|
||||
(i32.const 1072693248)
|
||||
(i32.const 1072079006)
|
||||
)
|
||||
)
|
||||
)
|
||||
(set_local $12
|
||||
(set_local $3
|
||||
(i32.add
|
||||
(get_local $12)
|
||||
(get_local $3)
|
||||
(i32.sub
|
||||
(i32.shr_s
|
||||
(get_local $11)
|
||||
(get_local $2)
|
||||
(i32.const 20)
|
||||
)
|
||||
(i32.const 1023)
|
||||
)
|
||||
)
|
||||
)
|
||||
(set_local $11
|
||||
(set_local $2
|
||||
(i32.add
|
||||
(i32.and
|
||||
(get_local $11)
|
||||
(get_local $2)
|
||||
(i32.const 1048575)
|
||||
)
|
||||
(i32.const 1072079006)
|
||||
@ -194,7 +193,7 @@
|
||||
(i64.or
|
||||
(i64.shl
|
||||
(i64.extend_u/i32
|
||||
(get_local $11)
|
||||
(get_local $2)
|
||||
)
|
||||
(i64.const 32)
|
||||
)
|
||||
@ -209,53 +208,53 @@
|
||||
(get_local $1)
|
||||
)
|
||||
)
|
||||
(set_local $3
|
||||
(set_local $5
|
||||
(f64.sub
|
||||
(get_local $0)
|
||||
(f64.const 1)
|
||||
)
|
||||
)
|
||||
(set_local $2
|
||||
(set_local $6
|
||||
(f64.mul
|
||||
(f64.mul
|
||||
(f64.const 0.5)
|
||||
(get_local $3)
|
||||
(get_local $5)
|
||||
)
|
||||
(get_local $3)
|
||||
)
|
||||
)
|
||||
(set_local $4
|
||||
(f64.div
|
||||
(get_local $3)
|
||||
(f64.add
|
||||
(f64.const 2)
|
||||
(get_local $3)
|
||||
)
|
||||
)
|
||||
)
|
||||
(set_local $5
|
||||
(f64.mul
|
||||
(get_local $4)
|
||||
(get_local $4)
|
||||
(get_local $5)
|
||||
)
|
||||
)
|
||||
(set_local $7
|
||||
(f64.mul
|
||||
(get_local $5)
|
||||
(f64.div
|
||||
(get_local $5)
|
||||
(f64.add
|
||||
(f64.const 2)
|
||||
(get_local $5)
|
||||
)
|
||||
)
|
||||
)
|
||||
(set_local $8
|
||||
(f64.mul
|
||||
(get_local $7)
|
||||
(get_local $7)
|
||||
)
|
||||
)
|
||||
(set_local $9
|
||||
(f64.mul
|
||||
(get_local $8)
|
||||
(get_local $8)
|
||||
)
|
||||
)
|
||||
(set_local $10
|
||||
(f64.mul
|
||||
(get_local $9)
|
||||
(f64.add
|
||||
(f64.const 0.3999999999940942)
|
||||
(f64.mul
|
||||
(get_local $7)
|
||||
(get_local $9)
|
||||
(f64.add
|
||||
(f64.const 0.22222198432149784)
|
||||
(f64.mul
|
||||
(get_local $7)
|
||||
(get_local $9)
|
||||
(f64.const 0.15313837699209373)
|
||||
)
|
||||
)
|
||||
@ -263,21 +262,21 @@
|
||||
)
|
||||
)
|
||||
)
|
||||
(set_local $9
|
||||
(set_local $11
|
||||
(f64.mul
|
||||
(get_local $5)
|
||||
(get_local $8)
|
||||
(f64.add
|
||||
(f64.const 0.6666666666666735)
|
||||
(f64.mul
|
||||
(get_local $7)
|
||||
(get_local $9)
|
||||
(f64.add
|
||||
(f64.const 0.2857142874366239)
|
||||
(f64.mul
|
||||
(get_local $7)
|
||||
(get_local $9)
|
||||
(f64.add
|
||||
(f64.const 0.1818357216161805)
|
||||
(f64.mul
|
||||
(get_local $7)
|
||||
(get_local $9)
|
||||
(f64.const 0.14798198605116586)
|
||||
)
|
||||
)
|
||||
@ -287,16 +286,14 @@
|
||||
)
|
||||
)
|
||||
)
|
||||
(set_local $6
|
||||
(set_local $12
|
||||
(f64.add
|
||||
(get_local $9)
|
||||
(get_local $8)
|
||||
(get_local $11)
|
||||
(get_local $10)
|
||||
)
|
||||
)
|
||||
(set_local $10
|
||||
(f64.convert_s/i32
|
||||
(get_local $12)
|
||||
)
|
||||
(set_local $13
|
||||
(get_local $3)
|
||||
)
|
||||
(return
|
||||
(f64.add
|
||||
@ -304,23 +301,27 @@
|
||||
(f64.sub
|
||||
(f64.add
|
||||
(f64.mul
|
||||
(get_local $4)
|
||||
(get_local $7)
|
||||
(f64.add
|
||||
(get_local $2)
|
||||
(get_local $6)
|
||||
(get_local $12)
|
||||
)
|
||||
)
|
||||
(f64.mul
|
||||
(get_local $10)
|
||||
(f64.convert_s/i32
|
||||
(get_local $13)
|
||||
)
|
||||
(f64.const 1.9082149292705877e-10)
|
||||
)
|
||||
)
|
||||
(get_local $2)
|
||||
(get_local $6)
|
||||
)
|
||||
(get_local $3)
|
||||
(get_local $5)
|
||||
)
|
||||
(f64.mul
|
||||
(get_local $10)
|
||||
(f64.convert_s/i32
|
||||
(get_local $13)
|
||||
)
|
||||
(f64.const 0.6931471803691238)
|
||||
)
|
||||
)
|
||||
@ -328,8 +329,8 @@
|
||||
)
|
||||
(func "$(lib)/math/Mathf.log" (; 4 ;) (type $ff) (param $0 f32) (result f32)
|
||||
(local $1 i32)
|
||||
(local $2 f32)
|
||||
(local $3 f32)
|
||||
(local $2 i32)
|
||||
(local $3 i32)
|
||||
(local $4 f32)
|
||||
(local $5 f32)
|
||||
(local $6 f32)
|
||||
@ -337,35 +338,30 @@
|
||||
(local $8 f32)
|
||||
(local $9 f32)
|
||||
(local $10 f32)
|
||||
(local $11 i32)
|
||||
(local $12 i32)
|
||||
(local $13 i32)
|
||||
(local $11 f32)
|
||||
(local $12 f32)
|
||||
(nop)
|
||||
(set_local $1
|
||||
(i32.reinterpret/f32
|
||||
(get_local $0)
|
||||
)
|
||||
)
|
||||
(nop)
|
||||
(set_local $11
|
||||
(get_local $1)
|
||||
)
|
||||
(set_local $12
|
||||
(set_local $2
|
||||
(i32.const 0)
|
||||
)
|
||||
(if
|
||||
(i32.and
|
||||
(if (result i32)
|
||||
(tee_local $13
|
||||
(tee_local $3
|
||||
(i32.lt_u
|
||||
(get_local $11)
|
||||
(get_local $1)
|
||||
(i32.const 8388608)
|
||||
)
|
||||
)
|
||||
(get_local $13)
|
||||
(get_local $3)
|
||||
(i32.and
|
||||
(i32.shr_u
|
||||
(get_local $11)
|
||||
(get_local $1)
|
||||
(i32.const 31)
|
||||
)
|
||||
(i32.const 1)
|
||||
@ -377,7 +373,7 @@
|
||||
(if
|
||||
(i32.eq
|
||||
(i32.shl
|
||||
(get_local $11)
|
||||
(get_local $1)
|
||||
(i32.const 1)
|
||||
)
|
||||
(i32.const 0)
|
||||
@ -394,7 +390,7 @@
|
||||
)
|
||||
(if
|
||||
(i32.shr_u
|
||||
(get_local $11)
|
||||
(get_local $1)
|
||||
(i32.const 31)
|
||||
)
|
||||
(return
|
||||
@ -407,9 +403,9 @@
|
||||
)
|
||||
)
|
||||
)
|
||||
(set_local $12
|
||||
(set_local $2
|
||||
(i32.sub
|
||||
(get_local $12)
|
||||
(get_local $2)
|
||||
(i32.const 25)
|
||||
)
|
||||
)
|
||||
@ -424,13 +420,10 @@
|
||||
(get_local $0)
|
||||
)
|
||||
)
|
||||
(set_local $11
|
||||
(get_local $1)
|
||||
)
|
||||
)
|
||||
(if
|
||||
(i32.ge_u
|
||||
(get_local $11)
|
||||
(get_local $1)
|
||||
(i32.const 2139095040)
|
||||
)
|
||||
(return
|
||||
@ -438,7 +431,7 @@
|
||||
)
|
||||
(if
|
||||
(i32.eq
|
||||
(get_local $11)
|
||||
(get_local $1)
|
||||
(i32.const 1065353216)
|
||||
)
|
||||
(return
|
||||
@ -447,31 +440,31 @@
|
||||
)
|
||||
)
|
||||
)
|
||||
(set_local $11
|
||||
(set_local $1
|
||||
(i32.add
|
||||
(get_local $11)
|
||||
(get_local $1)
|
||||
(i32.sub
|
||||
(i32.const 1065353216)
|
||||
(i32.const 1060439283)
|
||||
)
|
||||
)
|
||||
)
|
||||
(set_local $12
|
||||
(set_local $2
|
||||
(i32.add
|
||||
(get_local $12)
|
||||
(get_local $2)
|
||||
(i32.sub
|
||||
(i32.shr_s
|
||||
(get_local $11)
|
||||
(get_local $1)
|
||||
(i32.const 23)
|
||||
)
|
||||
(i32.const 127)
|
||||
)
|
||||
)
|
||||
)
|
||||
(set_local $11
|
||||
(set_local $1
|
||||
(i32.add
|
||||
(i32.and
|
||||
(get_local $11)
|
||||
(get_local $1)
|
||||
(i32.const 8388607)
|
||||
)
|
||||
(i32.const 1060439283)
|
||||
@ -479,34 +472,34 @@
|
||||
)
|
||||
(set_local $0
|
||||
(f32.reinterpret/i32
|
||||
(get_local $11)
|
||||
(get_local $1)
|
||||
)
|
||||
)
|
||||
(set_local $3
|
||||
(set_local $4
|
||||
(f32.sub
|
||||
(get_local $0)
|
||||
(f32.const 1)
|
||||
)
|
||||
)
|
||||
(set_local $4
|
||||
(set_local $5
|
||||
(f32.div
|
||||
(get_local $3)
|
||||
(get_local $4)
|
||||
(f32.add
|
||||
(f32.const 2)
|
||||
(get_local $3)
|
||||
(get_local $4)
|
||||
)
|
||||
)
|
||||
)
|
||||
(set_local $5
|
||||
(set_local $6
|
||||
(f32.mul
|
||||
(get_local $4)
|
||||
(get_local $4)
|
||||
(get_local $5)
|
||||
(get_local $5)
|
||||
)
|
||||
)
|
||||
(set_local $7
|
||||
(f32.mul
|
||||
(get_local $5)
|
||||
(get_local $5)
|
||||
(get_local $6)
|
||||
(get_local $6)
|
||||
)
|
||||
)
|
||||
(set_local $8
|
||||
@ -523,7 +516,7 @@
|
||||
)
|
||||
(set_local $9
|
||||
(f32.mul
|
||||
(get_local $5)
|
||||
(get_local $6)
|
||||
(f32.add
|
||||
(f32.const 0.6666666269302368)
|
||||
(f32.mul
|
||||
@ -533,24 +526,24 @@
|
||||
)
|
||||
)
|
||||
)
|
||||
(set_local $6
|
||||
(set_local $10
|
||||
(f32.add
|
||||
(get_local $9)
|
||||
(get_local $8)
|
||||
)
|
||||
)
|
||||
(set_local $2
|
||||
(set_local $11
|
||||
(f32.mul
|
||||
(f32.mul
|
||||
(f32.const 0.5)
|
||||
(get_local $3)
|
||||
(get_local $4)
|
||||
)
|
||||
(get_local $3)
|
||||
(get_local $4)
|
||||
)
|
||||
)
|
||||
(set_local $10
|
||||
(set_local $12
|
||||
(f32.convert_s/i32
|
||||
(get_local $12)
|
||||
(get_local $2)
|
||||
)
|
||||
)
|
||||
(return
|
||||
@ -559,23 +552,23 @@
|
||||
(f32.sub
|
||||
(f32.add
|
||||
(f32.mul
|
||||
(get_local $4)
|
||||
(get_local $5)
|
||||
(f32.add
|
||||
(get_local $2)
|
||||
(get_local $6)
|
||||
(get_local $11)
|
||||
(get_local $10)
|
||||
)
|
||||
)
|
||||
(f32.mul
|
||||
(get_local $10)
|
||||
(get_local $12)
|
||||
(f32.const 9.05800061445916e-06)
|
||||
)
|
||||
)
|
||||
(get_local $2)
|
||||
(get_local $11)
|
||||
)
|
||||
(get_local $3)
|
||||
(get_local $4)
|
||||
)
|
||||
(f32.mul
|
||||
(get_local $10)
|
||||
(get_local $12)
|
||||
(f32.const 0.6931381225585938)
|
||||
)
|
||||
)
|
||||
|
9
tests/parser/constructor.ts
Normal file
9
tests/parser/constructor.ts
Normal file
@ -0,0 +1,9 @@
|
||||
class MyClass {
|
||||
constructor() {}
|
||||
constructor(a: i32) {}
|
||||
constructor(a: i32, b: i32) {}
|
||||
}
|
||||
|
||||
class MyClassImplicit {
|
||||
constructor(public a: i32, private readonly b: i32 = 2, c: i32 = 3) {}
|
||||
}
|
8
tests/parser/constructor.ts.fixture.ts
Normal file
8
tests/parser/constructor.ts.fixture.ts
Normal file
@ -0,0 +1,8 @@
|
||||
class MyClass {
|
||||
constructor() {}
|
||||
constructor(a: i32) {}
|
||||
constructor(a: i32, b: i32) {}
|
||||
}
|
||||
class MyClassImplicit {
|
||||
constructor(public a: i32, private readonly b: i32 = 2, c: i32 = 3) {}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user