mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-04-25 23:12:19 +00:00
Better resolve infrastructure; Instance fields
This commit is contained in:
parent
fb2b7aa96b
commit
ae99adefce
419
src/compiler.ts
419
src/compiler.ts
@ -441,9 +441,9 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
this.compileEnum(<Enum>element);
|
this.compileEnum(<Enum>element);
|
||||||
}
|
}
|
||||||
|
|
||||||
compileEnum(element: Enum): void {
|
compileEnum(element: Enum): bool {
|
||||||
if (element.isCompiled)
|
if (element.isCompiled)
|
||||||
return;
|
return true;
|
||||||
|
|
||||||
var previousValue: EnumValue | null = null;
|
var previousValue: EnumValue | null = null;
|
||||||
if (element.members)
|
if (element.members)
|
||||||
@ -500,7 +500,7 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
throw new Error("declaration expected");
|
throw new Error("declaration expected");
|
||||||
previousValue = <EnumValue>val;
|
previousValue = <EnumValue>val;
|
||||||
}
|
}
|
||||||
element.isCompiled = true;
|
return element.isCompiled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// functions
|
// functions
|
||||||
@ -2104,144 +2104,137 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
compileAssignment(expression: Expression, valueExpression: Expression, contextualType: Type): ExpressionRef {
|
compileAssignment(expression: Expression, valueExpression: Expression, contextualType: Type): ExpressionRef {
|
||||||
var element: Element | null = null;
|
var resolved = this.program.resolveExpression(expression, this.currentFunction); // reports
|
||||||
switch (expression.kind) {
|
if (!resolved)
|
||||||
|
|
||||||
case NodeKind.IDENTIFIER:
|
|
||||||
element = this.program.resolveIdentifier(<IdentifierExpression>expression, this.currentFunction); // reports
|
|
||||||
break;
|
|
||||||
|
|
||||||
case NodeKind.PROPERTYACCESS:
|
|
||||||
element = this.program.resolvePropertyAccess(<PropertyAccessExpression>expression, this.currentFunction); // reports
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
this.error(DiagnosticCode.Operation_not_supported, expression.range);
|
|
||||||
}
|
|
||||||
if (!element)
|
|
||||||
return this.module.createUnreachable();
|
return this.module.createUnreachable();
|
||||||
|
|
||||||
var type: Type | null = null;
|
var element = resolved.element;
|
||||||
|
var elementType: Type;
|
||||||
switch (element.kind) {
|
switch (element.kind) {
|
||||||
|
|
||||||
case ElementKind.LOCAL:
|
case ElementKind.LOCAL:
|
||||||
type = (<Local>element).type;
|
elementType = (<Local>element).type;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ElementKind.GLOBAL:
|
case ElementKind.GLOBAL:
|
||||||
if (this.compileGlobal(<Global>element))
|
if (!this.compileGlobal(<Global>element)) // reports
|
||||||
type = (<Global>element).type;
|
return this.module.createUnreachable();
|
||||||
|
assert((<Global>element).type != null);
|
||||||
|
elementType = <Type>(<Global>element).type;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ElementKind.FIELD:
|
||||||
|
elementType = (<Field>element).type;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ElementKind.PROPERTY:
|
case ElementKind.PROPERTY:
|
||||||
var setterPrototype = (<Property>element).setterPrototype;
|
var setterPrototype = (<Property>element).setterPrototype;
|
||||||
if (setterPrototype) {
|
if (setterPrototype) {
|
||||||
var setterInstance = setterPrototype.resolve(); // reports
|
var setterInstance = setterPrototype.resolve(); // reports
|
||||||
if (setterInstance) {
|
if (!setterInstance)
|
||||||
if (contextualType == Type.void) { // just set if dropped anyway
|
return this.module.createUnreachable();
|
||||||
return this.compileCall(setterInstance, [ valueExpression ], expression);
|
elementType = setterInstance.parameters[0].type;
|
||||||
} else { // otherwise do a set followed by a get
|
break;
|
||||||
var getterPrototype = (<Property>element).getterPrototype;
|
}
|
||||||
if (getterPrototype) {
|
this.error(DiagnosticCode.Cannot_assign_to_0_because_it_is_a_constant_or_a_read_only_property, expression.range, (<Property>element).internalName);
|
||||||
var getterInstance = getterPrototype.resolve(); // reports
|
|
||||||
if (getterInstance) {
|
|
||||||
return this.module.createBlock(null, [
|
|
||||||
this.compileCall(setterInstance, [ valueExpression ], expression),
|
|
||||||
this.compileCall(getterInstance, [], expression)
|
|
||||||
], getterInstance.returnType.toNativeType());
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
this.error(DiagnosticCode.Property_0_does_not_exist_on_type_1, expression.range, (<Property>element).simpleName, (<Property>element).parent.internalName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
this.error(DiagnosticCode.Property_0_does_not_exist_on_type_1, expression.range, (<Property>element).simpleName, (<Property>element).parent.internalName);
|
|
||||||
return this.module.createUnreachable();
|
return this.module.createUnreachable();
|
||||||
|
|
||||||
default:
|
default:
|
||||||
this.error(DiagnosticCode.Operation_not_supported, expression.range);
|
this.error(DiagnosticCode.Operation_not_supported, expression.range);
|
||||||
|
return this.module.createUnreachable();
|
||||||
}
|
}
|
||||||
if (!type)
|
if (!elementType)
|
||||||
return this.module.createUnreachable();
|
return this.module.createUnreachable();
|
||||||
|
|
||||||
this.currentType = type;
|
this.currentType = elementType;
|
||||||
return this.compileAssignmentWithValue(expression, this.compileExpression(valueExpression, type, ConversionKind.IMPLICIT), contextualType != Type.void);
|
return this.compileAssignmentWithValue(expression, this.compileExpression(valueExpression, elementType, ConversionKind.IMPLICIT), contextualType != Type.void);
|
||||||
}
|
}
|
||||||
|
|
||||||
compileAssignmentWithValue(expression: Expression, valueWithCorrectType: ExpressionRef, tee: bool = false): ExpressionRef {
|
compileAssignmentWithValue(expression: Expression, valueWithCorrectType: ExpressionRef, tee: bool = false): ExpressionRef {
|
||||||
var element: Element | null = null;
|
var resolved = this.program.resolveExpression(expression, this.currentFunction); // reports
|
||||||
switch (expression.kind) {
|
if (!resolved)
|
||||||
|
|
||||||
case NodeKind.IDENTIFIER:
|
|
||||||
element = this.program.resolveIdentifier(<IdentifierExpression>expression, this.currentFunction);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case NodeKind.PROPERTYACCESS:
|
|
||||||
element = this.program.resolvePropertyAccess(<PropertyAccessExpression>expression, this.currentFunction);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
this.error(DiagnosticCode.Operation_not_supported, expression.range);
|
|
||||||
}
|
|
||||||
if (!element)
|
|
||||||
return this.module.createUnreachable();
|
return this.module.createUnreachable();
|
||||||
|
|
||||||
if (element.kind == ElementKind.LOCAL) {
|
var element = resolved.element;
|
||||||
assert((<Local>element).type != null);
|
switch (element.kind) {
|
||||||
if (tee) {
|
|
||||||
this.currentType = <Type>(<Local>element).type;
|
|
||||||
return this.module.createTeeLocal((<Local>element).index, valueWithCorrectType);
|
|
||||||
}
|
|
||||||
this.currentType = Type.void;
|
|
||||||
return this.module.createSetLocal((<Local>element).index, valueWithCorrectType);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (element.kind == ElementKind.GLOBAL) {
|
case ElementKind.LOCAL:
|
||||||
if (!this.compileGlobal(<Global>element))
|
this.currentType = select<Type>((<Local>element).type, Type.void, tee);
|
||||||
return this.module.createUnreachable();
|
if ((<Local>element).isConstant) {
|
||||||
this.currentType = <Type>(<Global>element).type;
|
this.error(DiagnosticCode.Cannot_assign_to_0_because_it_is_a_constant_or_a_read_only_property, expression.range, (<Local>element).internalName);
|
||||||
if (!(<Global>element).isMutable) {
|
return this.module.createUnreachable();
|
||||||
this.error(DiagnosticCode.Cannot_assign_to_0_because_it_is_a_constant_or_a_read_only_property, expression.range, element.internalName);
|
}
|
||||||
return this.module.createUnreachable();
|
return tee
|
||||||
}
|
? this.module.createTeeLocal((<Local>element).index, valueWithCorrectType)
|
||||||
if (tee) {
|
: this.module.createSetLocal((<Local>element).index, valueWithCorrectType);
|
||||||
|
|
||||||
|
case ElementKind.GLOBAL:
|
||||||
|
if (!this.compileGlobal(<Global>element))
|
||||||
|
return this.module.createUnreachable();
|
||||||
|
assert((<Global>element).type != null);
|
||||||
|
this.currentType = select<Type>(<Type>(<Global>element).type, Type.void, tee);
|
||||||
|
if ((<Local>element).isConstant) {
|
||||||
|
this.error(DiagnosticCode.Cannot_assign_to_0_because_it_is_a_constant_or_a_read_only_property, expression.range, (<Local>element).internalName);
|
||||||
|
return this.module.createUnreachable();
|
||||||
|
}
|
||||||
|
if (!tee)
|
||||||
|
return this.module.createSetGlobal((<Global>element).internalName, valueWithCorrectType);
|
||||||
var globalNativeType = (<Type>(<Global>element).type).toNativeType();
|
var globalNativeType = (<Type>(<Global>element).type).toNativeType();
|
||||||
return this.module.createBlock(null, [ // teeGlobal
|
return this.module.createBlock(null, [ // emulated teeGlobal
|
||||||
this.module.createSetGlobal((<Global>element).internalName, valueWithCorrectType),
|
this.module.createSetGlobal((<Global>element).internalName, valueWithCorrectType),
|
||||||
this.module.createGetGlobal((<Global>element).internalName, globalNativeType)
|
this.module.createGetGlobal((<Global>element).internalName, globalNativeType)
|
||||||
], globalNativeType);
|
], globalNativeType);
|
||||||
}
|
|
||||||
this.currentType = Type.void;
|
case ElementKind.FIELD:
|
||||||
return this.module.createSetGlobal((<Global>element).internalName, valueWithCorrectType);
|
if ((<Field>element).prototype.isReadonly) {
|
||||||
|
this.error(DiagnosticCode.Cannot_assign_to_0_because_it_is_a_constant_or_a_read_only_property, expression.range, (<Field>element).internalName);
|
||||||
|
return this.module.createUnreachable();
|
||||||
|
}
|
||||||
|
assert(resolved.targetExpression != null);
|
||||||
|
var targetExpr = this.compileExpression(<Expression>resolved.targetExpression, Type.usize32);
|
||||||
|
this.currentType = select<Type>((<Field>element).type, Type.void, tee);
|
||||||
|
var elementNativeType = (<Field>element).type.toNativeType();
|
||||||
|
if (!tee)
|
||||||
|
return this.module.createStore((<Field>element).type.byteSize, targetExpr, valueWithCorrectType, elementNativeType, (<Field>element).memoryOffset);
|
||||||
|
var tempLocal = this.currentFunction.getAndFreeTempLocal((<Field>element).type);
|
||||||
|
return this.module.createBlock(null, [ // TODO: simplify if valueWithCorrectType has no side effects
|
||||||
|
this.module.createSetLocal(tempLocal.index, valueWithCorrectType),
|
||||||
|
this.module.createStore((<Field>element).type.byteSize, targetExpr, this.module.createGetLocal(tempLocal.index, elementNativeType), elementNativeType, (<Field>element).memoryOffset),
|
||||||
|
this.module.createGetLocal(tempLocal.index, elementNativeType)
|
||||||
|
], elementNativeType);
|
||||||
|
|
||||||
|
case ElementKind.PROPERTY:
|
||||||
|
var setterPrototype = (<Property>element).setterPrototype;
|
||||||
|
if (setterPrototype) {
|
||||||
|
var setterInstance = setterPrototype.resolve(); // reports
|
||||||
|
if (setterInstance) {
|
||||||
|
if (!tee)
|
||||||
|
return this.makeCall(setterInstance, [ valueWithCorrectType ]);
|
||||||
|
var getterPrototype = (<Property>element).getterPrototype;
|
||||||
|
assert(getterPrototype != null);
|
||||||
|
var getterInstance = (<FunctionPrototype>getterPrototype).resolve(); // reports
|
||||||
|
if (getterInstance)
|
||||||
|
return this.module.createBlock(null, [
|
||||||
|
this.makeCall(setterInstance, [ valueWithCorrectType ]),
|
||||||
|
this.makeCall(getterInstance)
|
||||||
|
], getterInstance.returnType.toNativeType());
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
this.error(DiagnosticCode.Cannot_assign_to_0_because_it_is_a_constant_or_a_read_only_property, expression.range, (<Property>element).internalName);
|
||||||
|
return this.module.createUnreachable();
|
||||||
|
|
||||||
|
default:
|
||||||
|
this.error(DiagnosticCode.Operation_not_supported, expression.range);
|
||||||
|
return this.module.createUnreachable();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: fields, (setters)
|
|
||||||
|
|
||||||
throw new Error("not implemented");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
compileCallExpression(expression: CallExpression, contextualType: Type): ExpressionRef {
|
compileCallExpression(expression: CallExpression, contextualType: Type): ExpressionRef {
|
||||||
var element: Element | null = null;
|
var resolved = this.program.resolveExpression(expression.expression, this.currentFunction); // reports
|
||||||
var thisExpression: Expression;
|
if (!resolved)
|
||||||
switch (expression.expression.kind) {
|
|
||||||
// case NodeKind.THIS:
|
|
||||||
// case NodeKind.SUPER:
|
|
||||||
|
|
||||||
case NodeKind.IDENTIFIER:
|
|
||||||
element = this.program.resolveIdentifier(thisExpression = <IdentifierExpression>expression.expression, this.currentFunction);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case NodeKind.PROPERTYACCESS:
|
|
||||||
element = this.program.resolvePropertyAccess(<PropertyAccessExpression>expression.expression, this.currentFunction);
|
|
||||||
thisExpression = (<PropertyAccessExpression>expression.expression).expression;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
throw new Error("not implemented");
|
|
||||||
}
|
|
||||||
if (!element)
|
|
||||||
return this.module.createUnreachable();
|
return this.module.createUnreachable();
|
||||||
|
|
||||||
|
var element = resolved.element;
|
||||||
if (element.kind == ElementKind.FUNCTION_PROTOTYPE) {
|
if (element.kind == ElementKind.FUNCTION_PROTOTYPE) {
|
||||||
var functionPrototype = <FunctionPrototype>element;
|
var functionPrototype = <FunctionPrototype>element;
|
||||||
var functionInstance: Function | null = null;
|
var functionInstance: Function | null = null;
|
||||||
@ -2283,8 +2276,10 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
var argumentIndex = 0;
|
var argumentIndex = 0;
|
||||||
|
|
||||||
var args = new Array<Expression>(numArgumentsInclThis);
|
var args = new Array<Expression>(numArgumentsInclThis);
|
||||||
if (functionInstance.instanceMethodOf)
|
if (functionInstance.instanceMethodOf) {
|
||||||
args[argumentIndex++] = thisExpression;
|
assert(resolved.targetExpression != null);
|
||||||
|
args[argumentIndex++] = <Expression>resolved.targetExpression;
|
||||||
|
}
|
||||||
for (i = 0; i < numArguments; ++i)
|
for (i = 0; i < numArguments; ++i)
|
||||||
args[argumentIndex++] = expression.arguments[i];
|
args[argumentIndex++] = expression.arguments[i];
|
||||||
return this.compileCall(functionInstance, args, expression);
|
return this.compileCall(functionInstance, args, expression);
|
||||||
@ -2341,9 +2336,12 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.currentType = functionInstance.returnType;
|
this.currentType = functionInstance.returnType;
|
||||||
|
return this.makeCall(functionInstance, operands);
|
||||||
|
}
|
||||||
|
|
||||||
if (!functionInstance.isCompiled)
|
private makeCall(functionInstance: Function, operands: ExpressionRef[] | null = null): ExpressionRef {
|
||||||
this.compileFunction(functionInstance);
|
if (!(functionInstance.isCompiled || this.compileFunction(functionInstance)))
|
||||||
|
return this.module.createUnreachable();
|
||||||
|
|
||||||
// imported function
|
// imported function
|
||||||
if (functionInstance.isDeclared)
|
if (functionInstance.isDeclared)
|
||||||
@ -2354,31 +2352,15 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
compileElementAccessExpression(expression: ElementAccessExpression, contextualType: Type): ExpressionRef {
|
compileElementAccessExpression(expression: ElementAccessExpression, contextualType: Type): ExpressionRef {
|
||||||
var targetExpression = expression.expression;
|
var resolved = this.program.resolveElementAccess(expression, this.currentFunction); // reports
|
||||||
var target: Element | null = null;
|
if (!resolved)
|
||||||
switch (targetExpression.kind) {
|
|
||||||
|
|
||||||
// case NodeKind.THIS:
|
|
||||||
|
|
||||||
case NodeKind.IDENTIFIER:
|
|
||||||
target = this.program.resolveIdentifier(<IdentifierExpression>targetExpression, this.currentFunction);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case NodeKind.PROPERTYACCESS:
|
|
||||||
target = this.program.resolvePropertyAccess(<PropertyAccessExpression>targetExpression, this.currentFunction);
|
|
||||||
break;
|
|
||||||
|
|
||||||
// case NodeKind.ELEMENTACCESS:
|
|
||||||
|
|
||||||
default:
|
|
||||||
this.error(DiagnosticCode.Operation_not_supported, expression.range);
|
|
||||||
}
|
|
||||||
if (!target)
|
|
||||||
return this.module.createUnreachable();
|
return this.module.createUnreachable();
|
||||||
throw new Error("not implemented");
|
|
||||||
|
throw new Error("not implemented"); // TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
compileIdentifierExpression(expression: IdentifierExpression, contextualType: Type): ExpressionRef {
|
compileIdentifierExpression(expression: IdentifierExpression, contextualType: Type): ExpressionRef {
|
||||||
|
// check special keywords first
|
||||||
switch (expression.kind) {
|
switch (expression.kind) {
|
||||||
|
|
||||||
case NodeKind.NULL:
|
case NodeKind.NULL:
|
||||||
@ -2406,22 +2388,32 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
case NodeKind.THIS:
|
case NodeKind.THIS:
|
||||||
if (this.currentFunction.instanceMethodOf) {
|
if (this.currentFunction.instanceMethodOf) {
|
||||||
this.currentType = this.currentFunction.instanceMethodOf.type;
|
this.currentType = this.currentFunction.instanceMethodOf.type;
|
||||||
return this.module.createGetLocal(0, this.options.target == Target.WASM64 ? NativeType.I64 : NativeType.I32);
|
return this.module.createGetLocal(0, this.currentType.toNativeType());
|
||||||
}
|
}
|
||||||
|
this.currentType = select<Type>(Type.usize64, Type.usize32, this.options.target == Target.WASM64);
|
||||||
this.error(DiagnosticCode._this_cannot_be_referenced_in_current_location, expression.range);
|
this.error(DiagnosticCode._this_cannot_be_referenced_in_current_location, expression.range);
|
||||||
this.currentType = this.options.target == Target.WASM64 ? Type.u64 : Type.u32;
|
return this.module.createUnreachable();
|
||||||
|
|
||||||
|
case NodeKind.SUPER:
|
||||||
|
if (this.currentFunction.instanceMethodOf && this.currentFunction.instanceMethodOf.base) {
|
||||||
|
this.currentType = this.currentFunction.instanceMethodOf.base.type;
|
||||||
|
return this.module.createGetLocal(0, this.currentType.toNativeType());
|
||||||
|
}
|
||||||
|
this.currentType = select<Type>(Type.usize64, Type.usize32, this.options.target == Target.WASM64);
|
||||||
|
this.error(DiagnosticCode._super_can_only_be_referenced_in_a_derived_class, expression.range);
|
||||||
return this.module.createUnreachable();
|
return this.module.createUnreachable();
|
||||||
}
|
}
|
||||||
|
|
||||||
var element = this.program.resolveElement(expression, this.currentFunction); // reports
|
// otherwise resolve
|
||||||
if (!element)
|
var resolved = this.program.resolveIdentifier(expression, this.currentFunction); // reports
|
||||||
|
if (!resolved)
|
||||||
return this.module.createUnreachable();
|
return this.module.createUnreachable();
|
||||||
|
|
||||||
|
var element = resolved.element;
|
||||||
switch (element.kind) {
|
switch (element.kind) {
|
||||||
|
|
||||||
case ElementKind.LOCAL:
|
case ElementKind.LOCAL:
|
||||||
assert((<Local>element).type != null);
|
this.currentType = (<Local>element).type;
|
||||||
this.currentType = <Type>(<Local>element).type;
|
|
||||||
if ((<Local>element).hasConstantValue)
|
if ((<Local>element).hasConstantValue)
|
||||||
return makeInlineConstant(<Local>element, this.module);
|
return makeInlineConstant(<Local>element, this.module);
|
||||||
assert((<Local>element).index >= 0);
|
assert((<Local>element).index >= 0);
|
||||||
@ -2430,23 +2422,16 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
case ElementKind.GLOBAL:
|
case ElementKind.GLOBAL:
|
||||||
if (element.isBuiltIn)
|
if (element.isBuiltIn)
|
||||||
return compileBuiltinGetConstant(this, <Global>element);
|
return compileBuiltinGetConstant(this, <Global>element);
|
||||||
|
if (!this.compileGlobal(<Global>element)) // reports
|
||||||
var global = <Global>element;
|
|
||||||
if (!this.compileGlobal(global)) // reports
|
|
||||||
return this.module.createUnreachable();
|
return this.module.createUnreachable();
|
||||||
assert(global.type != null); // has been resolved when compileGlobal succeeds
|
assert((<Global>element).type != null);
|
||||||
this.currentType = <Type>global.type;
|
this.currentType = <Type>(<Global>element).type;
|
||||||
if (global.hasConstantValue)
|
if ((<Global>element).hasConstantValue)
|
||||||
return makeInlineConstant(global, this.module);
|
return makeInlineConstant(<Global>element, this.module);
|
||||||
else
|
return this.module.createGetGlobal((<Global>element).internalName, this.currentType.toNativeType());
|
||||||
return this.module.createGetGlobal((<Global>element).internalName, this.currentType.toNativeType());
|
|
||||||
|
|
||||||
// case ElementKind.FIELD
|
|
||||||
|
|
||||||
default:
|
|
||||||
this.error(DiagnosticCode.Operation_not_supported, expression.range);
|
|
||||||
return this.module.createUnreachable();
|
|
||||||
}
|
}
|
||||||
|
this.error(DiagnosticCode.Operation_not_supported, expression.range);
|
||||||
|
return this.module.createUnreachable();
|
||||||
}
|
}
|
||||||
|
|
||||||
compileLiteralExpression(expression: LiteralExpression, contextualType: Type): ExpressionRef {
|
compileLiteralExpression(expression: LiteralExpression, contextualType: Type): ExpressionRef {
|
||||||
@ -2502,124 +2487,50 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
compilePropertyAccessExpression(propertyAccess: PropertyAccessExpression, contextualType: Type): ExpressionRef {
|
compilePropertyAccessExpression(propertyAccess: PropertyAccessExpression, contextualType: Type): ExpressionRef {
|
||||||
var expression = propertyAccess.expression;
|
var resolved = this.program.resolvePropertyAccess(propertyAccess, this.currentFunction); // reports
|
||||||
var propertyName = propertyAccess.property.name;
|
if (!resolved)
|
||||||
|
|
||||||
// the lhs expression is either 'this', 'super', an identifier or another property access
|
|
||||||
var target: Element | null;
|
|
||||||
switch (expression.kind) {
|
|
||||||
|
|
||||||
case NodeKind.THIS:
|
|
||||||
if (!this.currentFunction.instanceMethodOf) {
|
|
||||||
this.error(DiagnosticCode._this_cannot_be_referenced_in_current_location, expression.range);
|
|
||||||
return this.module.createUnreachable();
|
|
||||||
}
|
|
||||||
target = this.currentFunction.instanceMethodOf;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case NodeKind.SUPER:
|
|
||||||
if (!(this.currentFunction.instanceMethodOf && this.currentFunction.instanceMethodOf.base)) {
|
|
||||||
this.error(DiagnosticCode._super_can_only_be_referenced_in_a_derived_class, expression.range);
|
|
||||||
return this.module.createUnreachable();
|
|
||||||
}
|
|
||||||
target = this.currentFunction.instanceMethodOf.base;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case NodeKind.IDENTIFIER:
|
|
||||||
target = this.program.resolveIdentifier(<IdentifierExpression>expression, this.currentFunction); // reports
|
|
||||||
break;
|
|
||||||
|
|
||||||
case NodeKind.PROPERTYACCESS:
|
|
||||||
target = this.program.resolvePropertyAccess(<PropertyAccessExpression>expression, this.currentFunction); // reports
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
throw new Error("lhs expression expected");
|
|
||||||
}
|
|
||||||
if (!target)
|
|
||||||
return this.module.createUnreachable();
|
return this.module.createUnreachable();
|
||||||
|
|
||||||
// look up the property within the target to obtain the actual element
|
var element = resolved.element;
|
||||||
var element: Element | null;
|
|
||||||
switch (target.kind) {
|
|
||||||
|
|
||||||
case ElementKind.LOCAL:
|
|
||||||
assert((<Local>target).type != null);
|
|
||||||
element = (<Type>(<Local>target).type).classType;
|
|
||||||
if (!element) {
|
|
||||||
this.error(DiagnosticCode.Property_0_does_not_exist_on_type_1, propertyAccess.property.range, propertyName, (<Type>(<Local>target).type).toString());
|
|
||||||
return this.module.createUnreachable();
|
|
||||||
}
|
|
||||||
target = element;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ElementKind.GLOBAL:
|
|
||||||
if (!this.compileGlobal(<Global>target))
|
|
||||||
return this.module.createUnreachable();
|
|
||||||
element = (<Type>(<Global>target).type).classType;
|
|
||||||
if (!element) {
|
|
||||||
this.error(DiagnosticCode.Property_0_does_not_exist_on_type_1, propertyAccess.property.range, propertyName, (<Type>(<Local>target).type).toString());
|
|
||||||
return this.module.createUnreachable();
|
|
||||||
}
|
|
||||||
target = element;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
if (target.members) {
|
|
||||||
element = target.members.get(propertyName);
|
|
||||||
if (!element) {
|
|
||||||
this.error(DiagnosticCode.Property_0_does_not_exist_on_type_1, propertyAccess.property.range, propertyName, target.internalName);
|
|
||||||
return this.module.createUnreachable();
|
|
||||||
}
|
|
||||||
|
|
||||||
// handle enum values right away
|
|
||||||
if (element.kind == ElementKind.ENUMVALUE) {
|
|
||||||
this.currentType = Type.i32;
|
|
||||||
if ((<EnumValue>element).hasConstantValue)
|
|
||||||
return this.module.createI32((<EnumValue>element).constantValue);
|
|
||||||
this.compileEnum((<EnumValue>element).enum);
|
|
||||||
return this.module.createGetGlobal((<EnumValue>element).internalName, NativeType.I32);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.error(DiagnosticCode.Property_0_does_not_exist_on_type_1, propertyAccess.property.range, propertyName, target.internalName);
|
|
||||||
return this.module.createUnreachable();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// handle the element
|
|
||||||
switch (element.kind) {
|
switch (element.kind) {
|
||||||
|
|
||||||
case ElementKind.LOCAL:
|
case ElementKind.GLOBAL: // static property
|
||||||
assert((<Local>element).type != null);
|
|
||||||
return this.module.createGetLocal((<Local>element).index, (this.currentType = <Type>(<Local>element).type).toNativeType());
|
|
||||||
|
|
||||||
case ElementKind.GLOBAL:
|
|
||||||
if (!this.compileGlobal(<Global>element))
|
if (!this.compileGlobal(<Global>element))
|
||||||
return this.module.createUnreachable();
|
return this.module.createUnreachable();
|
||||||
assert((<Global>element).type != null);
|
assert((<Global>element).type != null);
|
||||||
this.currentType = <Type>(<Global>element).type;
|
this.currentType = <Type>(<Global>element).type;
|
||||||
if ((<Global>element).hasConstantValue)
|
if ((<Global>element).hasConstantValue)
|
||||||
return makeInlineConstant(<Global>element, this.module);
|
return makeInlineConstant(<Global>element, this.module);
|
||||||
else
|
return this.module.createGetGlobal((<Global>element).internalName, this.currentType.toNativeType());
|
||||||
return this.module.createGetGlobal((<Global>element).internalName, this.currentType.toNativeType());
|
|
||||||
|
|
||||||
case ElementKind.PROPERTY: // getter
|
case ElementKind.ENUMVALUE: // enum value
|
||||||
var getterPrototype = (<Property>element).getterPrototype;
|
if (!this.compileEnum((<EnumValue>element).enum))
|
||||||
if (getterPrototype) {
|
|
||||||
var getterInstance = getterPrototype.resolve([], this.currentFunction.contextualTypeArguments);
|
|
||||||
if (getterInstance) {
|
|
||||||
return this.compileCall(getterInstance, [], propertyAccess);
|
|
||||||
} else {
|
|
||||||
return this.module.createUnreachable();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.error(DiagnosticCode.Property_0_does_not_exist_on_type_1, propertyAccess.property.range, propertyName, target.internalName);
|
|
||||||
return this.module.createUnreachable();
|
return this.module.createUnreachable();
|
||||||
}
|
this.currentType = Type.i32;
|
||||||
|
if ((<EnumValue>element).hasConstantValue)
|
||||||
|
return this.module.createI32((<EnumValue>element).constantValue);
|
||||||
|
return this.module.createGetGlobal((<EnumValue>element).internalName, NativeType.I32);
|
||||||
|
|
||||||
|
case ElementKind.FIELD: // instance field
|
||||||
|
assert(resolved.target != null);
|
||||||
|
assert(resolved.targetExpression != null);
|
||||||
|
assert((<Field>element).memoryOffset >= 0);
|
||||||
|
return this.module.createLoad((<Field>element).type.byteSize, (<Field>element).type.isSignedInteger,
|
||||||
|
this.compileExpression(<Expression>resolved.targetExpression, select<Type>(Type.usize64, Type.usize32, this.options.target == Target.WASM64)),
|
||||||
|
(<Field>element).type.toNativeType(),
|
||||||
|
(<Field>element).memoryOffset
|
||||||
|
);
|
||||||
|
|
||||||
|
case ElementKind.PROPERTY: // instance property (here: getter)
|
||||||
|
var getter = (<Property>element).getterPrototype;
|
||||||
|
assert(getter != null);
|
||||||
|
var getterInstance = (<FunctionPrototype>getter).resolve(); // reports
|
||||||
|
if (!getterInstance)
|
||||||
|
return this.module.createUnreachable();
|
||||||
|
return this.compileCall(getterInstance, [], propertyAccess);
|
||||||
}
|
}
|
||||||
this.error(DiagnosticCode.Operation_not_supported, propertyAccess.range);
|
this.error(DiagnosticCode.Operation_not_supported, propertyAccess.range);
|
||||||
throw new Error("not implemented");
|
return this.module.createUnreachable();
|
||||||
}
|
}
|
||||||
|
|
||||||
compileTernaryExpression(expression: TernaryExpression, contextualType: Type): ExpressionRef {
|
compileTernaryExpression(expression: TernaryExpression, contextualType: Type): ExpressionRef {
|
||||||
|
@ -496,24 +496,24 @@ export class Module {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
createCall(target: string, operands: ExpressionRef[], returnType: NativeType): ExpressionRef {
|
createCall(target: string, operands: ExpressionRef[] | null, returnType: NativeType): ExpressionRef {
|
||||||
if (this.noEmit) return 0;
|
if (this.noEmit) return 0;
|
||||||
var cStr = allocString(target);
|
var cStr = allocString(target);
|
||||||
var cArr = allocI32Array(operands);
|
var cArr = allocI32Array(operands);
|
||||||
try {
|
try {
|
||||||
return _BinaryenCall(this.ref, cStr, cArr, operands.length, returnType);
|
return _BinaryenCall(this.ref, cStr, cArr, operands && operands.length || 0, returnType);
|
||||||
} finally {
|
} finally {
|
||||||
Heap.dispose(cArr);
|
Heap.dispose(cArr);
|
||||||
Heap.dispose(cStr);
|
Heap.dispose(cStr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
createCallImport(target: string, operands: ExpressionRef[], returnType: NativeType): ExpressionRef {
|
createCallImport(target: string, operands: ExpressionRef[] | null, returnType: NativeType): ExpressionRef {
|
||||||
if (this.noEmit) return 0;
|
if (this.noEmit) return 0;
|
||||||
var cStr = allocString(target);
|
var cStr = allocString(target);
|
||||||
var cArr = allocI32Array(operands);
|
var cArr = allocI32Array(operands);
|
||||||
try {
|
try {
|
||||||
return _BinaryenCallImport(this.ref, cStr, cArr, operands.length, returnType);
|
return _BinaryenCallImport(this.ref, cStr, cArr, operands && operands.length || 0, returnType);
|
||||||
} finally {
|
} finally {
|
||||||
Heap.dispose(cArr);
|
Heap.dispose(cArr);
|
||||||
Heap.dispose(cStr);
|
Heap.dispose(cStr);
|
||||||
|
142
src/program.ts
142
src/program.ts
@ -67,7 +67,10 @@ import {
|
|||||||
|
|
||||||
hasDecorator,
|
hasDecorator,
|
||||||
hasModifier,
|
hasModifier,
|
||||||
mangleInternalName
|
mangleInternalName,
|
||||||
|
ElementAccessExpression,
|
||||||
|
ThisExpression,
|
||||||
|
SuperExpression
|
||||||
} from "./ast";
|
} from "./ast";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@ -896,11 +899,11 @@ export class Program extends DiagnosticEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Resolves an identifier to the element it refers to. */
|
/** Resolves an identifier to the element it refers to. */
|
||||||
resolveIdentifier(identifier: IdentifierExpression, contextualFunction: Function): Element | null {
|
resolveIdentifier(identifier: IdentifierExpression, contextualFunction: Function): ResolvedElement | null {
|
||||||
var name = identifier.name;
|
var name = identifier.name;
|
||||||
var local = contextualFunction.locals.get(name);
|
var local = contextualFunction.locals.get(name);
|
||||||
if (local)
|
if (local)
|
||||||
return local;
|
return resolvedElement.set(local);
|
||||||
|
|
||||||
var element: Element | null;
|
var element: Element | null;
|
||||||
var namespace: Element | null;
|
var namespace: Element | null;
|
||||||
@ -909,96 +912,131 @@ export class Program extends DiagnosticEmitter {
|
|||||||
if (contextualFunction && (namespace = contextualFunction.prototype.namespace)) {
|
if (contextualFunction && (namespace = contextualFunction.prototype.namespace)) {
|
||||||
do {
|
do {
|
||||||
if (element = this.elements.get(namespace.internalName + STATIC_DELIMITER + name))
|
if (element = this.elements.get(namespace.internalName + STATIC_DELIMITER + name))
|
||||||
return element;
|
return resolvedElement.set(element);
|
||||||
} while (namespace = namespace.namespace);
|
} while (namespace = namespace.namespace);
|
||||||
}
|
}
|
||||||
|
|
||||||
// search current file
|
// search current file
|
||||||
if (element = this.elements.get(identifier.range.source.internalPath + PATH_DELIMITER + name))
|
if (element = this.elements.get(identifier.range.source.internalPath + PATH_DELIMITER + name))
|
||||||
return element;
|
return resolvedElement.set(element);
|
||||||
|
|
||||||
// search global scope
|
// search global scope
|
||||||
if (element = this.elements.get(name))
|
if (element = this.elements.get(name))
|
||||||
return element;
|
return resolvedElement.set(element);
|
||||||
|
|
||||||
this.error(DiagnosticCode.Cannot_find_name_0, identifier.range, name);
|
this.error(DiagnosticCode.Cannot_find_name_0, identifier.range, name);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Resolves a property access to the element it refers to. */
|
/** Resolves a property access to the element it refers to. */
|
||||||
resolvePropertyAccess(propertyAccess: PropertyAccessExpression, contextualFunction: Function): Element | null {
|
resolvePropertyAccess(propertyAccess: PropertyAccessExpression, contextualFunction: Function): ResolvedElement | null {
|
||||||
var expression = propertyAccess.expression;
|
var resolved: ResolvedElement | null;
|
||||||
var target: Element | null = null;
|
|
||||||
switch (expression.kind) {
|
|
||||||
|
|
||||||
case NodeKind.IDENTIFIER:
|
// start by resolving the lhs target (expression before the last dot)
|
||||||
target = this.resolveIdentifier(<IdentifierExpression>expression, contextualFunction);
|
var targetExpression = propertyAccess.expression;
|
||||||
break;
|
if (!(resolved = this.resolveExpression(targetExpression, contextualFunction)))
|
||||||
|
|
||||||
case NodeKind.PROPERTYACCESS:
|
|
||||||
target = this.resolvePropertyAccess(<PropertyAccessExpression>expression, contextualFunction);
|
|
||||||
break;
|
|
||||||
|
|
||||||
// case NodeKind.ELEMENTACCESS:
|
|
||||||
|
|
||||||
default:
|
|
||||||
throw new Error("property target expected");
|
|
||||||
}
|
|
||||||
if (!target)
|
|
||||||
return null;
|
return null;
|
||||||
|
var target = resolved.element;
|
||||||
|
|
||||||
|
// at this point we know exactly what the target is, so look up the element within
|
||||||
var propertyName = propertyAccess.property.name;
|
var propertyName = propertyAccess.property.name;
|
||||||
|
var targetType: Type | null;
|
||||||
switch (target.kind) {
|
switch (target.kind) {
|
||||||
|
|
||||||
case ElementKind.GLOBAL:
|
case ElementKind.GLOBAL:
|
||||||
case ElementKind.LOCAL:
|
case ElementKind.LOCAL:
|
||||||
var type = (<VariableLikeElement>target).type;
|
targetType = (<VariableLikeElement>target).type;
|
||||||
assert(type != null); // locals don't have lazy types, unlike globals
|
if (!targetType) // FIXME: are globals always resolved here?
|
||||||
if ((<Type>type).classType) {
|
throw new Error("type expected");
|
||||||
target = <Class>(<Type>type).classType;
|
if (targetType.classType)
|
||||||
|
target = targetType.classType;
|
||||||
// fall-through
|
// fall-through
|
||||||
} else
|
else
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (target.members) {
|
if (target.members) {
|
||||||
var member = target.members.get(propertyName);
|
var member = target.members.get(propertyName);
|
||||||
if (member)
|
if (member)
|
||||||
return member;
|
return resolvedElement.set(member).withTarget(target, targetExpression);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
this.error(DiagnosticCode.Property_0_does_not_exist_on_type_1, propertyAccess.property.range, propertyAccess.property.name, target.internalName);
|
this.error(DiagnosticCode.Property_0_does_not_exist_on_type_1, propertyAccess.property.range, propertyName, target.internalName);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
resolveElement(expression: Expression, contextualFunction: Function): Element | null {
|
resolveElementAccess(elementAccess: ElementAccessExpression, contextualFunction: Function): ResolvedElement | null {
|
||||||
|
var resolved: ResolvedElement | null;
|
||||||
|
|
||||||
// this -> Class
|
// start by resolving the lhs target (expression before the last dot)
|
||||||
if (expression.kind == NodeKind.THIS) {
|
var targetExpression = elementAccess.expression;
|
||||||
if (contextualFunction.instanceMethodOf)
|
if (!(resolved = this.resolveExpression(targetExpression, contextualFunction)))
|
||||||
return contextualFunction.instanceMethodOf;
|
|
||||||
this.error(DiagnosticCode._this_cannot_be_referenced_in_current_location, expression.range);
|
|
||||||
return null;
|
return null;
|
||||||
}
|
var target = resolved.element;
|
||||||
|
|
||||||
// local or global name
|
|
||||||
if (expression.kind == NodeKind.IDENTIFIER) {
|
|
||||||
return this.resolveIdentifier(<IdentifierExpression>expression, contextualFunction);
|
|
||||||
|
|
||||||
// static or instance property (incl. enum values) or method
|
|
||||||
} else if (expression.kind == NodeKind.PROPERTYACCESS) {
|
|
||||||
return this.resolvePropertyAccess(<PropertyAccessExpression>expression, contextualFunction);
|
|
||||||
|
|
||||||
// instantiation
|
|
||||||
} else if (expression.kind == NodeKind.NEW) {
|
|
||||||
return this.resolveElement((<NewExpression>expression).expression, contextualFunction);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// at this point we know exactly what the target is, so make sure it is an array and look up the element within
|
||||||
throw new Error("not implemented");
|
throw new Error("not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resolveExpression(expression: Expression, contextualFunction: Function): ResolvedElement | null {
|
||||||
|
var classType: Class | null;
|
||||||
|
switch (expression.kind) {
|
||||||
|
|
||||||
|
case NodeKind.THIS: // -> Class
|
||||||
|
if (classType = contextualFunction.instanceMethodOf)
|
||||||
|
return resolvedElement.set(classType);
|
||||||
|
this.error(DiagnosticCode._this_cannot_be_referenced_in_current_location, expression.range);
|
||||||
|
return null;
|
||||||
|
|
||||||
|
case NodeKind.SUPER: // -> Class
|
||||||
|
if ((classType = contextualFunction.instanceMethodOf) && (classType = classType.base))
|
||||||
|
return resolvedElement.set(classType);
|
||||||
|
this.error(DiagnosticCode._super_can_only_be_referenced_in_a_derived_class, expression.range);
|
||||||
|
return null;
|
||||||
|
|
||||||
|
case NodeKind.IDENTIFIER:
|
||||||
|
return this.resolveIdentifier(<IdentifierExpression>expression, contextualFunction);
|
||||||
|
|
||||||
|
case NodeKind.PROPERTYACCESS:
|
||||||
|
return this.resolvePropertyAccess(<PropertyAccessExpression>expression, contextualFunction);
|
||||||
|
|
||||||
|
case NodeKind.ELEMENTACCESS:
|
||||||
|
return this.resolveElementAccess(<ElementAccessExpression>expression, contextualFunction);
|
||||||
|
|
||||||
|
default:
|
||||||
|
this.error(DiagnosticCode.Operation_not_supported, expression.range);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Common result structure returned when calling any of the resolve functions on a {@link Program}. */
|
||||||
|
export class ResolvedElement {
|
||||||
|
|
||||||
|
/** The target element, if a property or element access */
|
||||||
|
target: Element | null;
|
||||||
|
/** The target element's sub-expression, if a property or element access. */
|
||||||
|
targetExpression: Expression | null;
|
||||||
|
/** The element being accessed. */
|
||||||
|
element: Element;
|
||||||
|
|
||||||
|
set(element: Element): this {
|
||||||
|
this.target = null;
|
||||||
|
this.targetExpression = null;
|
||||||
|
this.element = element;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
withTarget(target: Element, targetExpression: Expression): this {
|
||||||
|
this.target = target;
|
||||||
|
this.targetExpression = targetExpression;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var resolvedElement = new ResolvedElement();
|
||||||
|
|
||||||
/** Indicates the specific kind of an {@link Element}. */
|
/** Indicates the specific kind of an {@link Element}. */
|
||||||
export enum ElementKind {
|
export enum ElementKind {
|
||||||
/** A {@link Global}. */
|
/** A {@link Global}. */
|
||||||
@ -1288,6 +1326,7 @@ export class Local extends VariableLikeElement {
|
|||||||
|
|
||||||
kind = ElementKind.LOCAL;
|
kind = ElementKind.LOCAL;
|
||||||
|
|
||||||
|
type: Type; // more specific
|
||||||
/** Local index. */
|
/** Local index. */
|
||||||
index: i32;
|
index: i32;
|
||||||
|
|
||||||
@ -1685,6 +1724,7 @@ export class Field extends Element {
|
|||||||
/** Constructs a new field. */
|
/** Constructs a new field. */
|
||||||
constructor(prototype: FieldPrototype, internalName: string, type: Type) {
|
constructor(prototype: FieldPrototype, internalName: string, type: Type) {
|
||||||
super(prototype.program, prototype.simpleName, internalName);
|
super(prototype.program, prototype.simpleName, internalName);
|
||||||
|
this.prototype = prototype;
|
||||||
this.flags = prototype.flags;
|
this.flags = prototype.flags;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,8 @@ glob.sync(filter, { cwd: __dirname + "/compiler" }).forEach(filename => {
|
|||||||
module.interpret();
|
module.interpret();
|
||||||
console.log(chalk.default.green("interpret OK"));
|
console.log(chalk.default.green("interpret OK"));
|
||||||
try {
|
try {
|
||||||
var wasmModule = new WebAssembly.Module(module.toBinary());
|
var binary = module.toBinary();
|
||||||
|
var wasmModule = new WebAssembly.Module(binary);
|
||||||
var wasmInstance = new WebAssembly.Instance(wasmModule, {
|
var wasmInstance = new WebAssembly.Instance(wasmModule, {
|
||||||
env: {
|
env: {
|
||||||
externalFunc: function() {},
|
externalFunc: function() {},
|
||||||
|
@ -63,6 +63,33 @@
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
(drop
|
||||||
|
(i32.load
|
||||||
|
(get_local $0)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(drop
|
||||||
|
(i32.load16_s offset=4
|
||||||
|
(get_local $0)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(drop
|
||||||
|
(i32.load8_s offset=6
|
||||||
|
(get_local $0)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(i32.store
|
||||||
|
(get_local $0)
|
||||||
|
(i32.const 1)
|
||||||
|
)
|
||||||
|
(i32.store16 offset=4
|
||||||
|
(get_local $0)
|
||||||
|
(i32.const 2)
|
||||||
|
)
|
||||||
|
(i32.store8 offset=6
|
||||||
|
(get_local $0)
|
||||||
|
(i32.const 3)
|
||||||
|
)
|
||||||
(get_local $0)
|
(get_local $0)
|
||||||
)
|
)
|
||||||
(func $start (; 1 ;) (type $v)
|
(func $start (; 1 ;) (type $v)
|
||||||
|
@ -65,6 +65,33 @@
|
|||||||
(f32.const 2)
|
(f32.const 2)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
(drop
|
||||||
|
(i32.load
|
||||||
|
(get_local $0)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(drop
|
||||||
|
(i32.load16_s offset=4
|
||||||
|
(get_local $0)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(drop
|
||||||
|
(i32.load8_s offset=6
|
||||||
|
(get_local $0)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(i32.store
|
||||||
|
(get_local $0)
|
||||||
|
(i32.const 1)
|
||||||
|
)
|
||||||
|
(i32.store16 offset=4
|
||||||
|
(get_local $0)
|
||||||
|
(i32.const 2)
|
||||||
|
)
|
||||||
|
(i32.store8 offset=6
|
||||||
|
(get_local $0)
|
||||||
|
(i32.const 3)
|
||||||
|
)
|
||||||
(get_local $0)
|
(get_local $0)
|
||||||
)
|
)
|
||||||
(func $start (; 5 ;) (type $v)
|
(func $start (; 5 ;) (type $v)
|
||||||
|
@ -20,6 +20,14 @@ export function test(animal: Animal<f64>): Animal<f64> {
|
|||||||
animal.instanceAdd(1, 2);
|
animal.instanceAdd(1, 2);
|
||||||
animal.instanceSub<f32>(1, 2);
|
animal.instanceSub<f32>(1, 2);
|
||||||
|
|
||||||
|
animal.one;
|
||||||
|
animal.two;
|
||||||
|
animal.three;
|
||||||
|
|
||||||
|
animal.one = 0 + 1;
|
||||||
|
animal.two = 1 + 1;
|
||||||
|
animal.three = 1 + 1 + 1;
|
||||||
|
|
||||||
var ptr = changetype<usize>(animal);
|
var ptr = changetype<usize>(animal);
|
||||||
var cls = changetype<Animal<f64>>(ptr);
|
var cls = changetype<Animal<f64>>(ptr);
|
||||||
return cls;
|
return cls;
|
||||||
|
@ -76,6 +76,45 @@
|
|||||||
(f32.const 2)
|
(f32.const 2)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
(drop
|
||||||
|
(i32.load
|
||||||
|
(get_local $0)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(drop
|
||||||
|
(i32.load16_s offset=4
|
||||||
|
(get_local $0)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(drop
|
||||||
|
(i32.load8_s offset=6
|
||||||
|
(get_local $0)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(i32.store
|
||||||
|
(get_local $0)
|
||||||
|
(i32.add
|
||||||
|
(i32.const 0)
|
||||||
|
(i32.const 1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(i32.store16 offset=4
|
||||||
|
(get_local $0)
|
||||||
|
(i32.add
|
||||||
|
(i32.const 1)
|
||||||
|
(i32.const 1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(i32.store8 offset=6
|
||||||
|
(get_local $0)
|
||||||
|
(i32.add
|
||||||
|
(i32.add
|
||||||
|
(i32.const 1)
|
||||||
|
(i32.const 1)
|
||||||
|
)
|
||||||
|
(i32.const 1)
|
||||||
|
)
|
||||||
|
)
|
||||||
(block
|
(block
|
||||||
(set_local $1
|
(set_local $1
|
||||||
(get_local $0)
|
(get_local $0)
|
||||||
|
4
tests/compiler/empty.optimized.wast
Normal file
4
tests/compiler/empty.optimized.wast
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
(module
|
||||||
|
(memory $0 1)
|
||||||
|
(export "memory" (memory $0))
|
||||||
|
)
|
0
tests/compiler/empty.ts
Normal file
0
tests/compiler/empty.ts
Normal file
54
tests/compiler/empty.wast
Normal file
54
tests/compiler/empty.wast
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
(module
|
||||||
|
(global $HEAP_BASE i32 (i32.const 4))
|
||||||
|
(memory $0 1)
|
||||||
|
(export "memory" (memory $0))
|
||||||
|
)
|
||||||
|
(;
|
||||||
|
[program.elements]
|
||||||
|
GLOBAL: NaN
|
||||||
|
GLOBAL: Infinity
|
||||||
|
FUNCTION_PROTOTYPE: isNaN
|
||||||
|
FUNCTION_PROTOTYPE: isFinite
|
||||||
|
FUNCTION_PROTOTYPE: clz
|
||||||
|
FUNCTION_PROTOTYPE: ctz
|
||||||
|
FUNCTION_PROTOTYPE: popcnt
|
||||||
|
FUNCTION_PROTOTYPE: rotl
|
||||||
|
FUNCTION_PROTOTYPE: rotr
|
||||||
|
FUNCTION_PROTOTYPE: abs
|
||||||
|
FUNCTION_PROTOTYPE: max
|
||||||
|
FUNCTION_PROTOTYPE: min
|
||||||
|
FUNCTION_PROTOTYPE: ceil
|
||||||
|
FUNCTION_PROTOTYPE: floor
|
||||||
|
FUNCTION_PROTOTYPE: copysign
|
||||||
|
FUNCTION_PROTOTYPE: nearest
|
||||||
|
FUNCTION_PROTOTYPE: reinterpret
|
||||||
|
FUNCTION_PROTOTYPE: sqrt
|
||||||
|
FUNCTION_PROTOTYPE: trunc
|
||||||
|
FUNCTION_PROTOTYPE: load
|
||||||
|
FUNCTION_PROTOTYPE: store
|
||||||
|
FUNCTION_PROTOTYPE: sizeof
|
||||||
|
FUNCTION_PROTOTYPE: select
|
||||||
|
FUNCTION_PROTOTYPE: unreachable
|
||||||
|
FUNCTION_PROTOTYPE: current_memory
|
||||||
|
FUNCTION_PROTOTYPE: grow_memory
|
||||||
|
FUNCTION_PROTOTYPE: parseInt
|
||||||
|
FUNCTION_PROTOTYPE: parseFloat
|
||||||
|
FUNCTION_PROTOTYPE: changetype
|
||||||
|
FUNCTION_PROTOTYPE: assert
|
||||||
|
FUNCTION_PROTOTYPE: i8
|
||||||
|
FUNCTION_PROTOTYPE: i16
|
||||||
|
FUNCTION_PROTOTYPE: i32
|
||||||
|
FUNCTION_PROTOTYPE: i64
|
||||||
|
FUNCTION_PROTOTYPE: u8
|
||||||
|
FUNCTION_PROTOTYPE: u16
|
||||||
|
FUNCTION_PROTOTYPE: u32
|
||||||
|
FUNCTION_PROTOTYPE: u64
|
||||||
|
FUNCTION_PROTOTYPE: bool
|
||||||
|
FUNCTION_PROTOTYPE: f32
|
||||||
|
FUNCTION_PROTOTYPE: f64
|
||||||
|
FUNCTION_PROTOTYPE: isize
|
||||||
|
FUNCTION_PROTOTYPE: usize
|
||||||
|
GLOBAL: HEAP_BASE
|
||||||
|
[program.exports]
|
||||||
|
|
||||||
|
;)
|
@ -1,8 +1,10 @@
|
|||||||
(module
|
(module
|
||||||
(type $FFF (func (param f64 f64) (result f64)))
|
(type $FFF (func (param f64 f64) (result f64)))
|
||||||
|
(type $fff (func (param f32 f32) (result f32)))
|
||||||
(type $v (func))
|
(type $v (func))
|
||||||
(memory $0 1)
|
(memory $0 1)
|
||||||
(export "fmod" (func $fmod/fmod))
|
(export "fmod" (func $fmod/fmod))
|
||||||
|
(export "fmodf" (func $fmod/fmodf))
|
||||||
(export "memory" (memory $0))
|
(export "memory" (memory $0))
|
||||||
(start $start)
|
(start $start)
|
||||||
(func $fmod/fmod (; 0 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64)
|
(func $fmod/fmod (; 0 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64)
|
||||||
@ -391,8 +393,374 @@
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
(func $start (; 1 ;) (type $v)
|
(func $fmod/fmodf (; 1 ;) (type $fff) (param $0 f32) (param $1 f32) (result f32)
|
||||||
|
(local $2 i32)
|
||||||
|
(local $3 i32)
|
||||||
|
(local $4 i32)
|
||||||
|
(local $5 i32)
|
||||||
|
(local $6 i32)
|
||||||
|
(local $7 i32)
|
||||||
|
(local $8 f32)
|
||||||
|
(set_local $4
|
||||||
|
(i32.and
|
||||||
|
(i32.shr_u
|
||||||
|
(tee_local $2
|
||||||
|
(i32.reinterpret/f32
|
||||||
|
(get_local $0)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(i32.const 23)
|
||||||
|
)
|
||||||
|
(i32.const 255)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(set_local $6
|
||||||
|
(i32.and
|
||||||
|
(i32.shr_u
|
||||||
|
(tee_local $5
|
||||||
|
(i32.reinterpret/f32
|
||||||
|
(get_local $1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(i32.const 23)
|
||||||
|
)
|
||||||
|
(i32.const 255)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(set_local $7
|
||||||
|
(i32.and
|
||||||
|
(get_local $2)
|
||||||
|
(i32.const -2147483648)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(if
|
||||||
|
(if (result i32)
|
||||||
|
(if (result i32)
|
||||||
|
(tee_local $3
|
||||||
|
(i32.eqz
|
||||||
|
(i32.shl
|
||||||
|
(get_local $5)
|
||||||
|
(i32.const 1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(get_local $3)
|
||||||
|
(tee_local $3
|
||||||
|
(f32.ne
|
||||||
|
(tee_local $8
|
||||||
|
(get_local $1)
|
||||||
|
)
|
||||||
|
(get_local $8)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(get_local $3)
|
||||||
|
(i32.eq
|
||||||
|
(get_local $4)
|
||||||
|
(i32.const 255)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(return
|
||||||
|
(f32.div
|
||||||
|
(f32.mul
|
||||||
|
(get_local $0)
|
||||||
|
(get_local $1)
|
||||||
|
)
|
||||||
|
(f32.mul
|
||||||
|
(get_local $0)
|
||||||
|
(get_local $1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(if
|
||||||
|
(i32.le_u
|
||||||
|
(i32.shl
|
||||||
|
(get_local $2)
|
||||||
|
(i32.const 1)
|
||||||
|
)
|
||||||
|
(i32.shl
|
||||||
|
(get_local $5)
|
||||||
|
(i32.const 1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(block
|
||||||
|
(if
|
||||||
|
(i32.eq
|
||||||
|
(i32.shl
|
||||||
|
(get_local $2)
|
||||||
|
(i32.const 1)
|
||||||
|
)
|
||||||
|
(i32.shl
|
||||||
|
(get_local $5)
|
||||||
|
(i32.const 1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(return
|
||||||
|
(f32.mul
|
||||||
|
(f32.const 0)
|
||||||
|
(get_local $0)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(return
|
||||||
|
(get_local $0)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(set_local $2
|
||||||
|
(if (result i32)
|
||||||
|
(get_local $4)
|
||||||
|
(i32.or
|
||||||
|
(i32.and
|
||||||
|
(get_local $2)
|
||||||
|
(i32.const 8388607)
|
||||||
|
)
|
||||||
|
(i32.const 8388608)
|
||||||
|
)
|
||||||
|
(block (result i32)
|
||||||
|
(set_local $3
|
||||||
|
(i32.shl
|
||||||
|
(get_local $2)
|
||||||
|
(i32.const 9)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(loop $continue|0
|
||||||
|
(if
|
||||||
|
(i32.eqz
|
||||||
|
(i32.shr_u
|
||||||
|
(get_local $3)
|
||||||
|
(i32.const 31)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(block
|
||||||
|
(set_local $4
|
||||||
|
(i32.sub
|
||||||
|
(get_local $4)
|
||||||
|
(i32.const 1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(set_local $3
|
||||||
|
(i32.shl
|
||||||
|
(get_local $3)
|
||||||
|
(i32.const 1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(br $continue|0)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(i32.shl
|
||||||
|
(get_local $2)
|
||||||
|
(i32.add
|
||||||
|
(i32.sub
|
||||||
|
(i32.const 0)
|
||||||
|
(get_local $4)
|
||||||
|
)
|
||||||
|
(i32.const 1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(set_local $5
|
||||||
|
(if (result i32)
|
||||||
|
(get_local $6)
|
||||||
|
(i32.or
|
||||||
|
(i32.and
|
||||||
|
(get_local $5)
|
||||||
|
(i32.const 8388607)
|
||||||
|
)
|
||||||
|
(i32.const 8388608)
|
||||||
|
)
|
||||||
|
(block (result i32)
|
||||||
|
(set_local $3
|
||||||
|
(i32.shl
|
||||||
|
(get_local $5)
|
||||||
|
(i32.const 9)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(loop $continue|1
|
||||||
|
(if
|
||||||
|
(i32.eqz
|
||||||
|
(i32.shr_u
|
||||||
|
(get_local $3)
|
||||||
|
(i32.const 31)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(block
|
||||||
|
(set_local $6
|
||||||
|
(i32.sub
|
||||||
|
(get_local $6)
|
||||||
|
(i32.const 1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(set_local $3
|
||||||
|
(i32.shl
|
||||||
|
(get_local $3)
|
||||||
|
(i32.const 1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(br $continue|1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(i32.shl
|
||||||
|
(get_local $5)
|
||||||
|
(i32.add
|
||||||
|
(i32.sub
|
||||||
|
(i32.const 0)
|
||||||
|
(get_local $6)
|
||||||
|
)
|
||||||
|
(i32.const 1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(loop $continue|2
|
||||||
|
(if
|
||||||
|
(i32.gt_s
|
||||||
|
(get_local $4)
|
||||||
|
(get_local $6)
|
||||||
|
)
|
||||||
|
(block
|
||||||
|
(if
|
||||||
|
(i32.eqz
|
||||||
|
(i32.shr_u
|
||||||
|
(tee_local $3
|
||||||
|
(i32.sub
|
||||||
|
(get_local $2)
|
||||||
|
(get_local $5)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(i32.const 31)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(block
|
||||||
|
(if
|
||||||
|
(i32.eqz
|
||||||
|
(get_local $3)
|
||||||
|
)
|
||||||
|
(return
|
||||||
|
(f32.mul
|
||||||
|
(f32.const 0)
|
||||||
|
(get_local $0)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(set_local $2
|
||||||
|
(get_local $3)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(set_local $2
|
||||||
|
(i32.shl
|
||||||
|
(get_local $2)
|
||||||
|
(i32.const 1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(set_local $4
|
||||||
|
(i32.sub
|
||||||
|
(get_local $4)
|
||||||
|
(i32.const 1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(br $continue|2)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(if
|
||||||
|
(i32.eqz
|
||||||
|
(i32.shr_u
|
||||||
|
(tee_local $3
|
||||||
|
(i32.sub
|
||||||
|
(get_local $2)
|
||||||
|
(get_local $5)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(i32.const 31)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(block
|
||||||
|
(if
|
||||||
|
(i32.eqz
|
||||||
|
(get_local $3)
|
||||||
|
)
|
||||||
|
(return
|
||||||
|
(f32.mul
|
||||||
|
(f32.const 0)
|
||||||
|
(get_local $0)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(set_local $2
|
||||||
|
(get_local $3)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(loop $continue|3
|
||||||
|
(if
|
||||||
|
(i32.eqz
|
||||||
|
(i32.shr_u
|
||||||
|
(get_local $2)
|
||||||
|
(i32.const 23)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(block
|
||||||
|
(set_local $4
|
||||||
|
(i32.sub
|
||||||
|
(get_local $4)
|
||||||
|
(i32.const 1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(set_local $2
|
||||||
|
(i32.shl
|
||||||
|
(get_local $2)
|
||||||
|
(i32.const 1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(br $continue|3)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(f32.reinterpret/i32
|
||||||
|
(i32.or
|
||||||
|
(tee_local $2
|
||||||
|
(if (result i32)
|
||||||
|
(i32.gt_s
|
||||||
|
(get_local $4)
|
||||||
|
(i32.const 0)
|
||||||
|
)
|
||||||
|
(i32.or
|
||||||
|
(i32.sub
|
||||||
|
(get_local $2)
|
||||||
|
(i32.const 8388608)
|
||||||
|
)
|
||||||
|
(i32.shl
|
||||||
|
(get_local $4)
|
||||||
|
(i32.const 23)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(i32.shr_u
|
||||||
|
(get_local $2)
|
||||||
|
(i32.add
|
||||||
|
(i32.sub
|
||||||
|
(i32.const 0)
|
||||||
|
(get_local $4)
|
||||||
|
)
|
||||||
|
(i32.const 1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(get_local $7)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(func $start (; 2 ;) (type $v)
|
||||||
(local $0 f64)
|
(local $0 f64)
|
||||||
|
(local $1 f32)
|
||||||
(if
|
(if
|
||||||
(f64.eq
|
(f64.eq
|
||||||
(tee_local $0
|
(tee_local $0
|
||||||
@ -445,5 +813,57 @@
|
|||||||
)
|
)
|
||||||
(unreachable)
|
(unreachable)
|
||||||
)
|
)
|
||||||
|
(if
|
||||||
|
(f32.eq
|
||||||
|
(tee_local $1
|
||||||
|
(call $fmod/fmodf
|
||||||
|
(f32.const 1)
|
||||||
|
(f32.const nan:0x400000)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(get_local $1)
|
||||||
|
)
|
||||||
|
(unreachable)
|
||||||
|
)
|
||||||
|
(if
|
||||||
|
(f32.ne
|
||||||
|
(call $fmod/fmodf
|
||||||
|
(f32.const 1.5)
|
||||||
|
(f32.const 1)
|
||||||
|
)
|
||||||
|
(f32.const 0.5)
|
||||||
|
)
|
||||||
|
(unreachable)
|
||||||
|
)
|
||||||
|
(if
|
||||||
|
(i32.eqz
|
||||||
|
(f32.lt
|
||||||
|
(f32.sub
|
||||||
|
(call $fmod/fmodf
|
||||||
|
(f32.const 9.199999809265137)
|
||||||
|
(f32.const 2)
|
||||||
|
)
|
||||||
|
(f32.const 1.2000000476837158)
|
||||||
|
)
|
||||||
|
(f32.const 1.1920928955078125e-07)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(unreachable)
|
||||||
|
)
|
||||||
|
(if
|
||||||
|
(i32.eqz
|
||||||
|
(f32.lt
|
||||||
|
(f32.sub
|
||||||
|
(call $fmod/fmodf
|
||||||
|
(f32.const 9.199999809265137)
|
||||||
|
(f32.const 3.700000047683716)
|
||||||
|
)
|
||||||
|
(f32.const 1.7999999523162842)
|
||||||
|
)
|
||||||
|
(f32.const 1.1920928955078125e-07)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(unreachable)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -14,6 +14,7 @@ export function fmod(x: f64, y: f64): f64 {
|
|||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// normalize x and y
|
||||||
if (!ex) {
|
if (!ex) {
|
||||||
for (var i = ux << 12; !(i >> 63); i <<= 1)
|
for (var i = ux << 12; !(i >> 63); i <<= 1)
|
||||||
--ex;
|
--ex;
|
||||||
@ -31,6 +32,7 @@ export function fmod(x: f64, y: f64): f64 {
|
|||||||
uy |= 1 << 52;
|
uy |= 1 << 52;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// x mod y
|
||||||
for (; ex > ey; ex--) {
|
for (; ex > ey; ex--) {
|
||||||
i = ux - uy;
|
i = ux - uy;
|
||||||
if (!(i >> 63)) {
|
if (!(i >> 63)) {
|
||||||
@ -49,6 +51,7 @@ export function fmod(x: f64, y: f64): f64 {
|
|||||||
for (; !(ux >> 52); ux <<= 1)
|
for (; !(ux >> 52); ux <<= 1)
|
||||||
--ex;
|
--ex;
|
||||||
|
|
||||||
|
// scale result
|
||||||
if (ex > 0) {
|
if (ex > 0) {
|
||||||
ux -= 1 << 52;
|
ux -= 1 << 52;
|
||||||
ux |= <u64>ex << 52;
|
ux |= <u64>ex << 52;
|
||||||
@ -63,3 +66,72 @@ assert(isNaN<f64>(fmod(1, NaN)));
|
|||||||
assert(fmod(1.5, 1.0) == 0.5); // exactly 0.5 (as in C)
|
assert(fmod(1.5, 1.0) == 0.5); // exactly 0.5 (as in C)
|
||||||
assert(fmod(9.2, 2.0) - 1.2 < f64.EPSILON); // not exactly 1.2 (as in C)
|
assert(fmod(9.2, 2.0) - 1.2 < f64.EPSILON); // not exactly 1.2 (as in C)
|
||||||
assert(fmod(9.2, 3.7) - 1.8 < f64.EPSILON); // not exactly 1.8 (as in C)
|
assert(fmod(9.2, 3.7) - 1.8 < f64.EPSILON); // not exactly 1.8 (as in C)
|
||||||
|
|
||||||
|
export function fmodf(x: f32, y: f32): f32 {
|
||||||
|
// the following is based on musl's implementation of fmodf
|
||||||
|
var ux = reinterpret<f32,u32>(x);
|
||||||
|
var uy = reinterpret<f32,u32>(y);
|
||||||
|
var ex = <i32>(ux >> 23 & 0xff);
|
||||||
|
var ey = <i32>(uy >> 23 & 0xff);
|
||||||
|
var sx = ux & 0x80000000;
|
||||||
|
|
||||||
|
if (uy << 1 == 0 || isNaN<f32>(y) || ex == 0xff)
|
||||||
|
return (x * y) / (x * y);
|
||||||
|
if (ux << 1 <= uy << 1) {
|
||||||
|
if (ux << 1 == uy << 1)
|
||||||
|
return 0 * x;
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
// normalize x and y
|
||||||
|
if (!ex) {
|
||||||
|
for (var i = ux << 9; !(i >> 31); i <<= 1)
|
||||||
|
--ex;
|
||||||
|
ux <<= -ex + 1;
|
||||||
|
} else {
|
||||||
|
ux &= -1 >> 9;
|
||||||
|
ux |= 1 << 23;
|
||||||
|
}
|
||||||
|
if (!ey) {
|
||||||
|
for (i = uy << 9; !(i >> 31); i <<= 1)
|
||||||
|
--ey;
|
||||||
|
uy <<= -ey + 1;
|
||||||
|
} else {
|
||||||
|
uy &= -1 >> 9;
|
||||||
|
uy |= 1 << 23;
|
||||||
|
}
|
||||||
|
|
||||||
|
// x mod y
|
||||||
|
for (; ex > ey; --ex) {
|
||||||
|
i = ux - uy;
|
||||||
|
if (!(i >> 31)) {
|
||||||
|
if (!i)
|
||||||
|
return 0 * x;
|
||||||
|
ux = i;
|
||||||
|
}
|
||||||
|
ux <<= 1;
|
||||||
|
}
|
||||||
|
i = ux - uy;
|
||||||
|
if (!(i >> 31)) {
|
||||||
|
if (!i)
|
||||||
|
return 0 * x;
|
||||||
|
ux = i;
|
||||||
|
}
|
||||||
|
for (; !(ux >> 23); ux <<= 1)
|
||||||
|
--ex;
|
||||||
|
|
||||||
|
// scale result
|
||||||
|
if (ex > 0) {
|
||||||
|
ux -= 1 << 23;
|
||||||
|
ux |= <u32>ex << 23;
|
||||||
|
} else {
|
||||||
|
ux >>= -ex + 1;
|
||||||
|
}
|
||||||
|
ux |= sx;
|
||||||
|
return reinterpret<i32,f32>(ux);
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(isNaN<f32>(fmodf(1, NaN)));
|
||||||
|
assert(fmodf(1.5, 1.0) == 0.5);
|
||||||
|
assert(fmodf(9.2, 2.0) - 1.2 < f32.EPSILON);
|
||||||
|
assert(fmodf(9.2, 3.7) - 1.8 < f32.EPSILON);
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
(module
|
(module
|
||||||
(type $FFF (func (param f64 f64) (result f64)))
|
(type $FFF (func (param f64 f64) (result f64)))
|
||||||
|
(type $fff (func (param f32 f32) (result f32)))
|
||||||
(type $v (func))
|
(type $v (func))
|
||||||
(global $f64.EPSILON f64 (f64.const 2.220446049250313e-16))
|
(global $f64.EPSILON f64 (f64.const 2.220446049250313e-16))
|
||||||
|
(global $f32.EPSILON f32 (f32.const 1.1920928955078125e-07))
|
||||||
(global $HEAP_BASE i32 (i32.const 4))
|
(global $HEAP_BASE i32 (i32.const 4))
|
||||||
(memory $0 1)
|
(memory $0 1)
|
||||||
(export "fmod" (func $fmod/fmod))
|
(export "fmod" (func $fmod/fmod))
|
||||||
|
(export "fmodf" (func $fmod/fmodf))
|
||||||
(export "memory" (memory $0))
|
(export "memory" (memory $0))
|
||||||
(start $start)
|
(start $start)
|
||||||
(func $fmod/fmod (; 0 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64)
|
(func $fmod/fmod (; 0 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64)
|
||||||
@ -481,8 +484,456 @@
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
(func $start (; 1 ;) (type $v)
|
(func $fmod/fmodf (; 1 ;) (type $fff) (param $0 f32) (param $1 f32) (result f32)
|
||||||
|
(local $2 i32)
|
||||||
|
(local $3 i32)
|
||||||
|
(local $4 i32)
|
||||||
|
(local $5 i32)
|
||||||
|
(local $6 i32)
|
||||||
|
(local $7 f32)
|
||||||
|
(local $8 i32)
|
||||||
|
(local $9 i32)
|
||||||
|
(block
|
||||||
|
(set_local $2
|
||||||
|
(i32.reinterpret/f32
|
||||||
|
(get_local $0)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(block
|
||||||
|
(set_local $3
|
||||||
|
(i32.reinterpret/f32
|
||||||
|
(get_local $1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(block
|
||||||
|
(set_local $4
|
||||||
|
(i32.and
|
||||||
|
(i32.shr_u
|
||||||
|
(get_local $2)
|
||||||
|
(i32.const 23)
|
||||||
|
)
|
||||||
|
(i32.const 255)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(block
|
||||||
|
(set_local $5
|
||||||
|
(i32.and
|
||||||
|
(i32.shr_u
|
||||||
|
(get_local $3)
|
||||||
|
(i32.const 23)
|
||||||
|
)
|
||||||
|
(i32.const 255)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(block
|
||||||
|
(set_local $6
|
||||||
|
(i32.and
|
||||||
|
(get_local $2)
|
||||||
|
(i32.const -2147483648)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(if
|
||||||
|
(if (result i32)
|
||||||
|
(tee_local $8
|
||||||
|
(if (result i32)
|
||||||
|
(tee_local $8
|
||||||
|
(i32.eq
|
||||||
|
(i32.shl
|
||||||
|
(get_local $3)
|
||||||
|
(i32.const 1)
|
||||||
|
)
|
||||||
|
(i32.const 0)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(get_local $8)
|
||||||
|
(f32.ne
|
||||||
|
(tee_local $7
|
||||||
|
(get_local $1)
|
||||||
|
)
|
||||||
|
(get_local $7)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(get_local $8)
|
||||||
|
(i32.eq
|
||||||
|
(get_local $4)
|
||||||
|
(i32.const 255)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(return
|
||||||
|
(f32.div
|
||||||
|
(f32.mul
|
||||||
|
(get_local $0)
|
||||||
|
(get_local $1)
|
||||||
|
)
|
||||||
|
(f32.mul
|
||||||
|
(get_local $0)
|
||||||
|
(get_local $1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(if
|
||||||
|
(i32.le_u
|
||||||
|
(i32.shl
|
||||||
|
(get_local $2)
|
||||||
|
(i32.const 1)
|
||||||
|
)
|
||||||
|
(i32.shl
|
||||||
|
(get_local $3)
|
||||||
|
(i32.const 1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(block
|
||||||
|
(if
|
||||||
|
(i32.eq
|
||||||
|
(i32.shl
|
||||||
|
(get_local $2)
|
||||||
|
(i32.const 1)
|
||||||
|
)
|
||||||
|
(i32.shl
|
||||||
|
(get_local $3)
|
||||||
|
(i32.const 1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(return
|
||||||
|
(f32.mul
|
||||||
|
(f32.const 0)
|
||||||
|
(get_local $0)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(return
|
||||||
|
(get_local $0)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(if
|
||||||
|
(i32.eqz
|
||||||
|
(get_local $4)
|
||||||
|
)
|
||||||
|
(block
|
||||||
|
(block $break|0
|
||||||
|
(block
|
||||||
|
(set_local $9
|
||||||
|
(i32.shl
|
||||||
|
(get_local $2)
|
||||||
|
(i32.const 9)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(loop $continue|0
|
||||||
|
(if
|
||||||
|
(i32.eqz
|
||||||
|
(i32.shr_u
|
||||||
|
(get_local $9)
|
||||||
|
(i32.const 31)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(block
|
||||||
|
(set_local $4
|
||||||
|
(i32.sub
|
||||||
|
(get_local $4)
|
||||||
|
(i32.const 1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(set_local $9
|
||||||
|
(i32.shl
|
||||||
|
(get_local $9)
|
||||||
|
(i32.const 1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(br $continue|0)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(set_local $2
|
||||||
|
(i32.shl
|
||||||
|
(get_local $2)
|
||||||
|
(i32.add
|
||||||
|
(i32.sub
|
||||||
|
(i32.const 0)
|
||||||
|
(get_local $4)
|
||||||
|
)
|
||||||
|
(i32.const 1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(block
|
||||||
|
(set_local $2
|
||||||
|
(i32.and
|
||||||
|
(get_local $2)
|
||||||
|
(i32.shr_u
|
||||||
|
(i32.sub
|
||||||
|
(i32.const 0)
|
||||||
|
(i32.const 1)
|
||||||
|
)
|
||||||
|
(i32.const 9)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(set_local $2
|
||||||
|
(i32.or
|
||||||
|
(get_local $2)
|
||||||
|
(i32.shl
|
||||||
|
(i32.const 1)
|
||||||
|
(i32.const 23)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(if
|
||||||
|
(i32.eqz
|
||||||
|
(get_local $5)
|
||||||
|
)
|
||||||
|
(block
|
||||||
|
(block $break|1
|
||||||
|
(set_local $9
|
||||||
|
(i32.shl
|
||||||
|
(get_local $3)
|
||||||
|
(i32.const 9)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(loop $continue|1
|
||||||
|
(if
|
||||||
|
(i32.eqz
|
||||||
|
(i32.shr_u
|
||||||
|
(get_local $9)
|
||||||
|
(i32.const 31)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(block
|
||||||
|
(set_local $5
|
||||||
|
(i32.sub
|
||||||
|
(get_local $5)
|
||||||
|
(i32.const 1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(set_local $9
|
||||||
|
(i32.shl
|
||||||
|
(get_local $9)
|
||||||
|
(i32.const 1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(br $continue|1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(set_local $3
|
||||||
|
(i32.shl
|
||||||
|
(get_local $3)
|
||||||
|
(i32.add
|
||||||
|
(i32.sub
|
||||||
|
(i32.const 0)
|
||||||
|
(get_local $5)
|
||||||
|
)
|
||||||
|
(i32.const 1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(block
|
||||||
|
(set_local $3
|
||||||
|
(i32.and
|
||||||
|
(get_local $3)
|
||||||
|
(i32.shr_u
|
||||||
|
(i32.sub
|
||||||
|
(i32.const 0)
|
||||||
|
(i32.const 1)
|
||||||
|
)
|
||||||
|
(i32.const 9)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(set_local $3
|
||||||
|
(i32.or
|
||||||
|
(get_local $3)
|
||||||
|
(i32.shl
|
||||||
|
(i32.const 1)
|
||||||
|
(i32.const 23)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(block $break|2
|
||||||
|
(nop)
|
||||||
|
(loop $continue|2
|
||||||
|
(if
|
||||||
|
(i32.gt_s
|
||||||
|
(get_local $4)
|
||||||
|
(get_local $5)
|
||||||
|
)
|
||||||
|
(block
|
||||||
|
(block
|
||||||
|
(set_local $9
|
||||||
|
(i32.sub
|
||||||
|
(get_local $2)
|
||||||
|
(get_local $3)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(if
|
||||||
|
(i32.eqz
|
||||||
|
(i32.shr_u
|
||||||
|
(get_local $9)
|
||||||
|
(i32.const 31)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(block
|
||||||
|
(if
|
||||||
|
(i32.eqz
|
||||||
|
(get_local $9)
|
||||||
|
)
|
||||||
|
(return
|
||||||
|
(f32.mul
|
||||||
|
(f32.const 0)
|
||||||
|
(get_local $0)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(set_local $2
|
||||||
|
(get_local $9)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(set_local $2
|
||||||
|
(i32.shl
|
||||||
|
(get_local $2)
|
||||||
|
(i32.const 1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(set_local $4
|
||||||
|
(i32.sub
|
||||||
|
(get_local $4)
|
||||||
|
(i32.const 1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(br $continue|2)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(set_local $9
|
||||||
|
(i32.sub
|
||||||
|
(get_local $2)
|
||||||
|
(get_local $3)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(if
|
||||||
|
(i32.eqz
|
||||||
|
(i32.shr_u
|
||||||
|
(get_local $9)
|
||||||
|
(i32.const 31)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(block
|
||||||
|
(if
|
||||||
|
(i32.eqz
|
||||||
|
(get_local $9)
|
||||||
|
)
|
||||||
|
(return
|
||||||
|
(f32.mul
|
||||||
|
(f32.const 0)
|
||||||
|
(get_local $0)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(set_local $2
|
||||||
|
(get_local $9)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(block $break|3
|
||||||
|
(nop)
|
||||||
|
(loop $continue|3
|
||||||
|
(if
|
||||||
|
(i32.eqz
|
||||||
|
(i32.shr_u
|
||||||
|
(get_local $2)
|
||||||
|
(i32.const 23)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(block
|
||||||
|
(set_local $4
|
||||||
|
(i32.sub
|
||||||
|
(get_local $4)
|
||||||
|
(i32.const 1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(set_local $2
|
||||||
|
(i32.shl
|
||||||
|
(get_local $2)
|
||||||
|
(i32.const 1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(br $continue|3)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(if
|
||||||
|
(i32.gt_s
|
||||||
|
(get_local $4)
|
||||||
|
(i32.const 0)
|
||||||
|
)
|
||||||
|
(block
|
||||||
|
(set_local $2
|
||||||
|
(i32.sub
|
||||||
|
(get_local $2)
|
||||||
|
(i32.shl
|
||||||
|
(i32.const 1)
|
||||||
|
(i32.const 23)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(set_local $2
|
||||||
|
(i32.or
|
||||||
|
(get_local $2)
|
||||||
|
(i32.shl
|
||||||
|
(get_local $4)
|
||||||
|
(i32.const 23)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(set_local $2
|
||||||
|
(i32.shr_u
|
||||||
|
(get_local $2)
|
||||||
|
(i32.add
|
||||||
|
(i32.sub
|
||||||
|
(i32.const 0)
|
||||||
|
(get_local $4)
|
||||||
|
)
|
||||||
|
(i32.const 1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(set_local $2
|
||||||
|
(i32.or
|
||||||
|
(get_local $2)
|
||||||
|
(get_local $6)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(return
|
||||||
|
(f32.reinterpret/i32
|
||||||
|
(get_local $2)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(func $start (; 2 ;) (type $v)
|
||||||
(local $0 f64)
|
(local $0 f64)
|
||||||
|
(local $1 f32)
|
||||||
(if
|
(if
|
||||||
(i32.eqz
|
(i32.eqz
|
||||||
(f64.ne
|
(f64.ne
|
||||||
@ -539,6 +990,62 @@
|
|||||||
)
|
)
|
||||||
(unreachable)
|
(unreachable)
|
||||||
)
|
)
|
||||||
|
(if
|
||||||
|
(i32.eqz
|
||||||
|
(f32.ne
|
||||||
|
(tee_local $1
|
||||||
|
(call $fmod/fmodf
|
||||||
|
(f32.const 1)
|
||||||
|
(f32.const nan:0x400000)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(get_local $1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(unreachable)
|
||||||
|
)
|
||||||
|
(if
|
||||||
|
(i32.eqz
|
||||||
|
(f32.eq
|
||||||
|
(call $fmod/fmodf
|
||||||
|
(f32.const 1.5)
|
||||||
|
(f32.const 1)
|
||||||
|
)
|
||||||
|
(f32.const 0.5)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(unreachable)
|
||||||
|
)
|
||||||
|
(if
|
||||||
|
(i32.eqz
|
||||||
|
(f32.lt
|
||||||
|
(f32.sub
|
||||||
|
(call $fmod/fmodf
|
||||||
|
(f32.const 9.199999809265137)
|
||||||
|
(f32.const 2)
|
||||||
|
)
|
||||||
|
(f32.const 1.2000000476837158)
|
||||||
|
)
|
||||||
|
(f32.const 1.1920928955078125e-07)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(unreachable)
|
||||||
|
)
|
||||||
|
(if
|
||||||
|
(i32.eqz
|
||||||
|
(f32.lt
|
||||||
|
(f32.sub
|
||||||
|
(call $fmod/fmodf
|
||||||
|
(f32.const 9.199999809265137)
|
||||||
|
(f32.const 3.700000047683716)
|
||||||
|
)
|
||||||
|
(f32.const 1.7999999523162842)
|
||||||
|
)
|
||||||
|
(f32.const 1.1920928955078125e-07)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(unreachable)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
(;
|
(;
|
||||||
@ -588,6 +1095,8 @@
|
|||||||
FUNCTION_PROTOTYPE: usize
|
FUNCTION_PROTOTYPE: usize
|
||||||
GLOBAL: HEAP_BASE
|
GLOBAL: HEAP_BASE
|
||||||
FUNCTION_PROTOTYPE: fmod/fmod
|
FUNCTION_PROTOTYPE: fmod/fmod
|
||||||
|
FUNCTION_PROTOTYPE: fmod/fmodf
|
||||||
[program.exports]
|
[program.exports]
|
||||||
FUNCTION_PROTOTYPE: fmod/fmod
|
FUNCTION_PROTOTYPE: fmod/fmod
|
||||||
|
FUNCTION_PROTOTYPE: fmod/fmodf
|
||||||
;)
|
;)
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
(type $i (func (result i32)))
|
(type $i (func (result i32)))
|
||||||
(type $v (func))
|
(type $v (func))
|
||||||
(global $namespace/Outer.Inner.aVar (mut i32) (i32.const 0))
|
(global $namespace/Outer.Inner.aVar (mut i32) (i32.const 0))
|
||||||
(global $namespace/Joined.THREE i32 (i32.const 3))
|
|
||||||
(memory $0 1)
|
(memory $0 1)
|
||||||
(export "memory" (memory $0))
|
(export "memory" (memory $0))
|
||||||
(start $start)
|
(start $start)
|
||||||
@ -17,7 +16,7 @@
|
|||||||
(drop
|
(drop
|
||||||
(block (result i32)
|
(block (result i32)
|
||||||
(block $__inlined_func$namespace/Joined.anotherFunc (result i32)
|
(block $__inlined_func$namespace/Joined.anotherFunc (result i32)
|
||||||
(get_global $namespace/Joined.THREE)
|
(i32.const 3)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
(type $i (func (result i32)))
|
(type $i (func (result i32)))
|
||||||
(type $v (func))
|
(type $v (func))
|
||||||
(global $namespace/Outer.Inner.aVar (mut i32) (i32.const 0))
|
(global $namespace/Outer.Inner.aVar (mut i32) (i32.const 0))
|
||||||
(global $namespace/Joined.THREE i32 (i32.const 3))
|
|
||||||
(memory $0 1)
|
(memory $0 1)
|
||||||
(export "memory" (memory $0))
|
(export "memory" (memory $0))
|
||||||
(start $start)
|
(start $start)
|
||||||
@ -10,7 +9,7 @@
|
|||||||
(get_global $namespace/Outer.Inner.aVar)
|
(get_global $namespace/Outer.Inner.aVar)
|
||||||
)
|
)
|
||||||
(func $namespace/Joined.anotherFunc (; 1 ;) (type $i) (result i32)
|
(func $namespace/Joined.anotherFunc (; 1 ;) (type $i) (result i32)
|
||||||
(get_global $namespace/Joined.THREE)
|
(i32.const 3)
|
||||||
)
|
)
|
||||||
(func $start (; 2 ;) (type $v)
|
(func $start (; 2 ;) (type $v)
|
||||||
(drop
|
(drop
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
)
|
)
|
||||||
(func $namespace/Joined.anotherFunc (; 1 ;) (type $i) (result i32)
|
(func $namespace/Joined.anotherFunc (; 1 ;) (type $i) (result i32)
|
||||||
(return
|
(return
|
||||||
(get_global $namespace/Joined.THREE)
|
(i32.const 3)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
(func $start (; 2 ;) (type $v)
|
(func $start (; 2 ;) (type $v)
|
||||||
@ -27,7 +27,7 @@
|
|||||||
(call $namespace/Outer.Inner.aFunc)
|
(call $namespace/Outer.Inner.aFunc)
|
||||||
)
|
)
|
||||||
(drop
|
(drop
|
||||||
(get_global $namespace/Outer.Inner.anEnum.ONE)
|
(i32.const 1)
|
||||||
)
|
)
|
||||||
(drop
|
(drop
|
||||||
(call $namespace/Joined.anotherFunc)
|
(call $namespace/Joined.anotherFunc)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user