Implement function types / indirect calls / trampolines (#39)

This commit is contained in:
Daniel Wirtz 2018-03-12 14:06:39 +01:00 committed by GitHub
parent 5d5f458ab1
commit 423533c6b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
67 changed files with 7499 additions and 5763 deletions

View File

@ -1,4 +1,4 @@
![](https://s.gravatar.com/avatar/f105de3decfafc734b8eabe9a960b25d?size=64) AssemblyScript
![](https://avatars1.githubusercontent.com/u/28916798?s=64) AssemblyScript
=================
[![npm](https://img.shields.io/npm/v/assemblyscript.svg)](https://www.npmjs.com/package/assemblyscript)

2
dist/asc.js vendored

File diff suppressed because one or more lines are too long

2
dist/asc.js.map vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -21,7 +21,7 @@ class ObjectHeader {
///////////////////////////////// Fields ////////////////////////////////////
// the next and prev pointer with tags in the least significant two bits that
// would otherwise be zero (blocks are guaranteed to be aligned to 4/8 bytes)
// would otherwise be zero (blocks are guaranteed to be aligned to 8 bytes)
tagged_next: usize;
tagged_prev: usize;

View File

@ -35,15 +35,18 @@ export class Formatter extends AbstractFormatter {
} else {
var message = this.lastSeverity ? "\n" : "";
switch (this.lastSeverity = failure.getRuleSeverity()) {
case "warning":
case "warning": {
message += colorYellow + "WARNING:" + colorReset;
break;
case "error":
}
case "error": {
message += colorRed + "ERROR:" + colorReset;
break;
default:
}
default: {
message += failure.getRuleSeverity();
break;
}
}
this.lastFailure = failureString;
return message + " " + failureString + " [" + ruleName + "]\n in " + fileName + positionTuple;

View File

@ -12,6 +12,7 @@ export class Rule extends Lint.Rules.AbstractRule {
}
class DiagnosticsWalker extends Lint.RuleWalker {
visitVariableDeclaration(node: ts.VariableDeclaration) {
if (
!node.type && !node.initializer &&
@ -20,16 +21,19 @@ class DiagnosticsWalker extends Lint.RuleWalker {
this.addFailureAtNode(node, Rule.MISSING_TYPE_OR_INITIALIZER);
}
}
visitPropertyDeclaration(node: ts.PropertyDeclaration) {
if (!node.type && !node.initializer) {
this.addFailureAtNode(node, Rule.MISSING_TYPE_OR_INITIALIZER);
}
}
visitParameterDeclaration(node: ts.ParameterDeclaration) {
if (!node.type && !node.initializer) {
this.addFailureAtNode(node, Rule.MISSING_TYPE_OR_INITIALIZER);
}
}
visitFunctionDeclaration(node: ts.FunctionDeclaration) {
if (!node.type) {
this.addFailureAtNode(node, Rule.MISSING_RETURN_TYPE);

View File

@ -0,0 +1,56 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
exports.__esModule = true;
var ts = require("typescript");
var Lint = require("tslint");
var tsutils_1 = require("tsutils");
var Rule = /** @class */ (function (_super) {
__extends(Rule, _super);
function Rule() {
return _super !== null && _super.apply(this, arguments) || this;
}
Rule.prototype.apply = function (sourceFile) {
return this.applyWithWalker(new DiagnosticsWalker(sourceFile, this.getOptions()));
};
Rule.NOT_BRACED = "Multi-line case clauses should be braced.";
return Rule;
}(Lint.Rules.AbstractRule));
exports.Rule = Rule;
var DiagnosticsWalker = /** @class */ (function (_super) {
__extends(DiagnosticsWalker, _super);
function DiagnosticsWalker() {
return _super !== null && _super.apply(this, arguments) || this;
}
DiagnosticsWalker.prototype.visitDefaultClause = function (node) {
this.checkDefaultOrCaseClause(node);
_super.prototype.visitDefaultClause.call(this, node);
};
DiagnosticsWalker.prototype.visitCaseClause = function (node) {
this.checkDefaultOrCaseClause(node);
_super.prototype.visitCaseClause.call(this, node);
};
DiagnosticsWalker.prototype.checkDefaultOrCaseClause = function (node) {
var count = node.statements.length;
if (count > 1) {
this.addFailureAtNode(node, Rule.NOT_BRACED);
}
else if (count == 1) {
var stmt = node.statements[0];
if (stmt.kind != ts.SyntaxKind.Block) {
if (!tsutils_1.isSameLine(node.getSourceFile(), node.getStart(), stmt.getStart())) {
this.addFailureAtNode(node, Rule.NOT_BRACED);
}
}
}
};
return DiagnosticsWalker;
}(Lint.RuleWalker));

View File

@ -0,0 +1,39 @@
import * as ts from "typescript";
import * as Lint from "tslint";
import { isSameLine } from "tsutils";
export class Rule extends Lint.Rules.AbstractRule {
static NOT_BRACED = "Multi-line case clauses should be braced.";
apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
return this.applyWithWalker(new DiagnosticsWalker(sourceFile, this.getOptions()));
}
}
class DiagnosticsWalker extends Lint.RuleWalker {
visitDefaultClause(node: ts.DefaultClause) {
this.checkDefaultOrCaseClause(node);
super.visitDefaultClause(node);
}
visitCaseClause(node: ts.CaseClause) {
this.checkDefaultOrCaseClause(node);
super.visitCaseClause(node);
}
private checkDefaultOrCaseClause(node: ts.DefaultClause | ts.CaseClause) {
var count = node.statements.length;
if (count > 1) {
this.addFailureAtNode(node, Rule.NOT_BRACED);
} else if (count == 1) {
let stmt = node.statements[0];
if (stmt.kind != ts.SyntaxKind.Block) {
if (!isSameLine(node.getSourceFile(), node.getStart(), stmt.getStart())) {
this.addFailureAtNode(node, Rule.NOT_BRACED);
}
}
}
}
}

View File

@ -12,6 +12,7 @@ export class Rule extends Lint.Rules.AbstractRule {
}
class DiagnosticsWalker extends Lint.RuleWalker {
visitPropertyAccessExpression(node: ts.PropertyAccessExpression) {
if (node.expression.kind === ts.SyntaxKind.Identifier) {
if (

View File

@ -1,4 +1,4 @@
![](https://s.gravatar.com/avatar/f105de3decfafc734b8eabe9a960b25d?size=48) utils
![AS](https://avatars1.githubusercontent.com/u/28916798?s=48) utils
=================
Utilities for working with [AssemblyScript](http://assemblyscript.org) modules.

View File

@ -1,4 +1,4 @@
![](https://s.gravatar.com/avatar/f105de3decfafc734b8eabe9a960b25d?size=48) webpack
![AS](https://avatars1.githubusercontent.com/u/28916798?s=48) webpack
=================
[webpack](https://webpack.js.org/) loader for [AssemblyScript](http://assemblyscript.org) modules.

View File

@ -25,6 +25,8 @@ export enum NodeKind {
// types
TYPE,
TYPEPARAMETER,
PARAMETER,
SIGNATURE,
// expressions
IDENTIFIER,
@ -82,11 +84,10 @@ export enum NodeKind {
TYPEDECLARATION,
VARIABLEDECLARATION,
// other
// special
DECORATOR,
EXPORTMEMBER,
MODIFIER,
PARAMETER,
EXPORTMEMBER,
SWITCHCASE
}
@ -103,19 +104,121 @@ export abstract class Node {
// types
static createType(
identifier: IdentifierExpression,
typeArguments: TypeNode[],
name: IdentifierExpression,
typeArguments: CommonTypeNode[] | null,
isNullable: bool,
range: Range
): TypeNode {
var type = new TypeNode();
type.range = range;
type.name = identifier;
type.typeArguments = typeArguments;
type.name = name; name.parent = type;
type.typeArguments = typeArguments; if (typeArguments) setParent(typeArguments, type);
type.isNullable = isNullable;
return type;
}
static createOmittedType(
range: Range
) {
return Node.createType(
Node.createIdentifierExpression("", range),
null,
false,
range
);
}
static createTypeParameter(
name: IdentifierExpression,
extendsType: TypeNode | null,
range: Range
): TypeParameterNode {
var elem = new TypeParameterNode();
elem.range = range;
elem.name = name; name.parent = elem;
elem.extendsType = extendsType; if (extendsType) extendsType.parent = elem;
return elem;
}
static createParameter(
name: IdentifierExpression,
type: CommonTypeNode | null,
initializer: Expression | null,
kind: ParameterKind,
range: Range
): ParameterNode {
var elem = new ParameterNode();
elem.range = range;
elem.name = name; name.parent = elem;
elem.type = type; if (type) type.parent = elem;
elem.initializer = initializer; if (initializer) initializer.parent = elem;
elem.parameterKind = kind;
return elem;
}
static createSignature(
parameters: ParameterNode[],
returnType: CommonTypeNode,
explicitThisType: TypeNode | null,
isNullable: bool,
range: Range
): SignatureNode {
var sig = new SignatureNode();
sig.range = range;
sig.parameterTypes = parameters; setParent(parameters, sig);
sig.returnType = returnType; returnType.parent = sig;
sig.explicitThisType = explicitThisType; if (explicitThisType) explicitThisType.parent = sig;
sig.isNullable = isNullable;
return sig;
}
// special
static createDecorator(
expression: Expression,
args: Expression[] | null,
range: Range
): DecoratorNode {
var stmt = new DecoratorNode();
stmt.range = range;
stmt.name = expression; expression.parent = stmt;
stmt.arguments = args; if (args) setParent(args, stmt);
if (expression.kind == NodeKind.IDENTIFIER) {
switch ((<IdentifierExpression>expression).text) {
case "global": {
stmt.decoratorKind = DecoratorKind.GLOBAL;
break;
}
case "operator": {
stmt.decoratorKind = DecoratorKind.OPERATOR;
break;
}
case "unmanaged": {
stmt.decoratorKind = DecoratorKind.UNMANAGED;
break;
}
case "offset": {
stmt.decoratorKind = DecoratorKind.OFFSET;
break;
}
default: {
stmt.decoratorKind = DecoratorKind.CUSTOM;
break;
}
}
} else {
stmt.decoratorKind = DecoratorKind.CUSTOM;
}
return stmt;
}
static createModifier(kind: ModifierKind, range: Range): ModifierNode {
var elem = new ModifierNode();
elem.range = range;
elem.modifierKind = kind;
return elem;
}
// expressions
static createIdentifierExpression(
@ -128,20 +231,29 @@ export abstract class Node {
return expr;
}
static createEmptyIdentifierExpression(
range: Range
): IdentifierExpression {
var expr = new IdentifierExpression();
expr.range = range;
expr.text = "";
return expr;
}
static createArrayLiteralExpression(
elements: (Expression | null)[],
range: Range
): ArrayLiteralExpression {
var expr = new ArrayLiteralExpression();
expr.range = range;
expr.elementExpressions = elements; setParentOpt(elements, expr);
expr.elementExpressions = elements; setParentIfNotNull(elements, expr);
return expr;
}
static createAssertionExpression(
assertionKind: AssertionKind,
expression: Expression,
toType: TypeNode,
toType: CommonTypeNode,
range: Range
): AssertionExpression {
var expr = new AssertionExpression();
@ -168,7 +280,7 @@ export abstract class Node {
static createCallExpression(
expression: Expression,
typeArgs: TypeNode[] | null,
typeArgs: CommonTypeNode[] | null,
args: Expression[],
range: Range
): CallExpression {
@ -252,7 +364,7 @@ export abstract class Node {
static createNewExpression(
expression: Expression,
typeArgs: TypeNode[] | null,
typeArgs: CommonTypeNode[] | null,
args: Expression[],
range: Range
): NewExpression {
@ -402,12 +514,12 @@ export abstract class Node {
static createClassDeclaration(
identifier: IdentifierExpression,
typeParameters: TypeParameter[],
extendsType: TypeNode | null,
implementsTypes: TypeNode[],
typeParameters: TypeParameterNode[],
extendsType: TypeNode | null, // can't be a function
implementsTypes: TypeNode[], // can't be a function
members: DeclarationStatement[],
modifiers: Modifier[] | null,
decorators: Decorator[] | null,
modifiers: ModifierNode[] | null,
decorators: DecoratorNode[] | null,
range: Range
): ClassDeclaration {
var stmt = new ClassDeclaration();
@ -432,29 +544,6 @@ export abstract class Node {
return stmt;
}
static createDecorator(
expression: Expression,
args: Expression[] | null,
range: Range
): Decorator {
var stmt = new Decorator();
stmt.range = range;
stmt.name = expression; expression.parent = stmt;
stmt.arguments = args; if (args) setParent(args, stmt);
if (expression.kind == NodeKind.IDENTIFIER) {
switch ((<IdentifierExpression>expression).text) {
case "global": stmt.decoratorKind = DecoratorKind.GLOBAL; break;
case "operator": stmt.decoratorKind = DecoratorKind.OPERATOR; break;
case "unmanaged": stmt.decoratorKind = DecoratorKind.UNMANAGED; break;
case "offset": stmt.decoratorKind = DecoratorKind.OFFSET; break;
default: stmt.decoratorKind = DecoratorKind.CUSTOM; break;
}
} else {
stmt.decoratorKind = DecoratorKind.CUSTOM;
}
return stmt;
}
static createDoStatement(
statement: Statement,
condition: Expression,
@ -478,8 +567,8 @@ export abstract class Node {
static createEnumDeclaration(
name: IdentifierExpression,
members: EnumValueDeclaration[],
modifiers: Modifier[] | null,
decorators: Decorator[] | null,
modifiers: ModifierNode[] | null,
decorators: DecoratorNode[] | null,
range: Range
): EnumDeclaration {
var stmt = new EnumDeclaration();
@ -506,7 +595,7 @@ export abstract class Node {
static createExportStatement(
members: ExportMember[],
path: StringLiteralExpression | null,
modifiers: Modifier[] | null,
modifiers: ModifierNode[] | null,
range: Range
): ExportStatement {
var stmt = new ExportStatement();
@ -644,9 +733,9 @@ export abstract class Node {
static createInterfaceDeclaration(
name: IdentifierExpression,
extendsType: TypeNode | null,
extendsType: TypeNode | null, // can't be a function
members: DeclarationStatement[],
modifiers: Modifier[] | null,
modifiers: ModifierNode[] | null,
range: Range
): InterfaceDeclaration {
var stmt = new InterfaceDeclaration();
@ -660,10 +749,10 @@ export abstract class Node {
static createFieldDeclaration(
name: IdentifierExpression,
type: TypeNode | null,
type: CommonTypeNode | null,
initializer: Expression | null,
modifiers: Modifier[] | null,
decorators: Decorator[] | null,
modifiers: ModifierNode[] | null,
decorators: DecoratorNode[] | null,
range: Range
): FieldDeclaration {
var stmt = new FieldDeclaration();
@ -692,50 +781,20 @@ export abstract class Node {
return stmt;
}
static createTypeParameter(
name: IdentifierExpression,
extendsType: TypeNode | null,
range: Range
): TypeParameter {
var elem = new TypeParameter();
elem.range = range;
elem.name = name; name.parent = elem;
elem.extendsType = extendsType; if (extendsType) extendsType.parent = elem;
return elem;
}
static createParameter(
name: IdentifierExpression,
type: TypeNode | null,
initializer: Expression | null,
kind: ParameterKind,
range: Range
): Parameter {
var elem = new Parameter();
elem.range = range;
elem.name = name; name.parent = elem;
elem.type = type; if (type) type.parent = elem;
elem.initializer = initializer; if (initializer) initializer.parent = elem;
elem.parameterKind = kind;
return elem;
}
static createFunctionDeclaration(
name: IdentifierExpression,
typeParameters: TypeParameter[] | null,
parameters: Parameter[],
returnType: TypeNode | null,
typeParameters: TypeParameterNode[] | null,
signature: SignatureNode,
body: Statement | null,
modifiers: Modifier[] | null,
decorators: Decorator[] | null,
modifiers: ModifierNode[] | null,
decorators: DecoratorNode[] | null,
range: Range
): FunctionDeclaration {
var stmt = new FunctionDeclaration();
stmt.range = range;
stmt.name = name; name.parent = stmt;
stmt.typeParameters = typeParameters; if (typeParameters) setParent(typeParameters, stmt);
stmt.parameters = parameters; setParent(parameters, stmt);
stmt.returnType = returnType; if (returnType) returnType.parent = stmt;
stmt.signature = signature; signature.parent = stmt;
stmt.body = body; if (body) body.parent = stmt;
stmt.modifiers = modifiers; if (modifiers) setParent(modifiers, stmt);
stmt.decorators = decorators; if (decorators) setParent(decorators, stmt);
@ -744,38 +803,29 @@ export abstract class Node {
static createMethodDeclaration(
name: IdentifierExpression,
typeParameters: TypeParameter[] | null,
parameters: Parameter[],
returnType: TypeNode | null,
typeParameters: TypeParameterNode[] | null,
signature: SignatureNode,
body: Statement | null,
modifiers: Modifier[] | null,
decorators: Decorator[] | null,
modifiers: ModifierNode[] | null,
decorators: DecoratorNode[] | null,
range: Range
): MethodDeclaration {
var stmt = new MethodDeclaration();
stmt.range = range;
stmt.name = name; name.parent = stmt;
stmt.typeParameters = typeParameters; if (typeParameters) setParent(typeParameters, stmt);
stmt.parameters = parameters; setParent(parameters, stmt);
stmt.returnType = returnType; if (returnType) returnType.parent = stmt;
stmt.signature = signature; signature.parent = stmt;
stmt.body = body; if (body) body.parent = stmt;
stmt.modifiers = modifiers; if (modifiers) setParent(modifiers, stmt);
stmt.decorators = decorators; if (decorators) setParent(decorators, stmt);
return stmt;
}
static createModifier(kind: ModifierKind, range: Range): Modifier {
var elem = new Modifier();
elem.range = range;
elem.modifierKind = kind;
return elem;
}
static createNamespaceDeclaration(
name: IdentifierExpression,
members: Statement[],
modifiers: Modifier[] | null,
decorators: Decorator[] | null,
modifiers: ModifierNode[] | null,
decorators: DecoratorNode[] | null,
range: Range
): NamespaceDeclaration {
var stmt = new NamespaceDeclaration();
@ -852,9 +902,9 @@ export abstract class Node {
static createTypeDeclaration(
name: IdentifierExpression,
alias: TypeNode,
modifiers: Modifier[] | null,
decorators: Decorator[] | null,
alias: CommonTypeNode,
modifiers: ModifierNode[] | null,
decorators: DecoratorNode[] | null,
range: Range
): TypeDeclaration {
var stmt = new TypeDeclaration();
@ -868,8 +918,8 @@ export abstract class Node {
static createVariableStatement(
declarations: VariableDeclaration[],
modifiers: Modifier[] | null,
decorators: Decorator[] | null,
modifiers: ModifierNode[] | null,
decorators: DecoratorNode[] | null,
range: Range
): VariableStatement {
var stmt = new VariableStatement();
@ -882,10 +932,10 @@ export abstract class Node {
static createVariableDeclaration(
name: IdentifierExpression,
type: TypeNode | null,
type: CommonTypeNode | null,
initializer: Expression | null,
modifiers: Modifier[] | null,
decorators: Decorator[] | null,
modifiers: ModifierNode[] | null,
decorators: DecoratorNode[] | null,
range: Range
): VariableDeclaration {
var elem = new VariableDeclaration();
@ -923,26 +973,116 @@ export abstract class Node {
// types
export abstract class CommonTypeNode extends Node {
// kind varies
/** Whether nullable or not. */
isNullable: bool;
}
/** Represents a type annotation. */
export class TypeNode extends Node {
export class TypeNode extends CommonTypeNode {
kind = NodeKind.TYPE;
/** Identifier reference. */
name: IdentifierExpression;
/** Type argument references. */
typeArguments: TypeNode[];
/** Whether nullable or not. */
isNullable: bool;
typeArguments: CommonTypeNode[] | null;
}
/** Represents a type parameter. */
export class TypeParameter extends Node {
export class TypeParameterNode extends Node {
kind = NodeKind.TYPEPARAMETER;
/** Identifier reference. */
name: IdentifierExpression;
/** Extended type reference, if any. */
extendsType: TypeNode | null;
extendsType: TypeNode | null; // can't be a function
}
/** Represents the kind of a parameter. */
export enum ParameterKind {
/** No specific flags. */
DEFAULT,
/** Is an optional parameter. */
OPTIONAL,
/** Is a rest parameter. */
REST
}
/** Represents a function parameter. */
export class ParameterNode extends Node {
kind = NodeKind.PARAMETER;
/** Parameter kind. */
parameterKind: ParameterKind;
/** Parameter name. */
name: IdentifierExpression;
/** Parameter type. */
type: CommonTypeNode | null;
/** Initializer expression, if present. */
initializer: Expression | null;
}
/** Represents a function signature. */
export class SignatureNode extends CommonTypeNode {
kind = NodeKind.SIGNATURE;
/** Accepted parameters. */
parameterTypes: ParameterNode[];
/** Return type. */
returnType: CommonTypeNode | null;
/** Explicitly provided this type, if any. */
explicitThisType: TypeNode | null; // can't be a function
}
// special
/** Built-in decorator kinds. */
export const enum DecoratorKind {
CUSTOM,
GLOBAL,
OPERATOR,
UNMANAGED,
OFFSET
}
/** Depresents a decorator. */
export class DecoratorNode extends Node {
kind = NodeKind.DECORATOR;
/** Built-in kind, if applicable. */
decoratorKind: DecoratorKind;
/** Name expression. */
name: Expression;
/** Argument expressions. */
arguments: Expression[] | null;
}
/** Indicates the specific kind of a modifier. */
export enum ModifierKind {
ASYNC,
CONST,
LET,
DECLARE,
EXPORT,
IMPORT,
STATIC,
ABSTRACT,
PUBLIC,
PRIVATE,
PROTECTED,
READONLY,
GET,
SET,
}
/** Represents a single modifier. */
export class ModifierNode extends Node {
kind = NodeKind.MODIFIER;
/** Specific modifier kind. */
modifierKind: ModifierKind;
}
// expressions
@ -999,7 +1139,7 @@ export class AssertionExpression extends Expression {
/** Expression being asserted. */
expression: Expression;
/** Target type. */
toType: TypeNode;
toType: CommonTypeNode;
}
/** Represents a binary expression. */
@ -1021,7 +1161,7 @@ export class CallExpression extends Expression {
/** Called expression. Usually an identifier or property access expression. */
expression: Expression;
/** Provided type arguments. */
typeArguments: TypeNode[] | null;
typeArguments: CommonTypeNode[] | null;
/** Provided arguments. */
arguments: Expression[];
}
@ -1183,24 +1323,6 @@ export class UnaryPrefixExpression extends UnaryExpression {
// statements
/** Indicates the specific kind of a modifier. */
export enum ModifierKind {
ASYNC,
CONST,
LET,
DECLARE,
EXPORT,
IMPORT,
STATIC,
ABSTRACT,
PUBLIC,
PRIVATE,
PROTECTED,
READONLY,
GET,
SET,
}
/** Base class of all statement nodes. */
export abstract class Statement extends Node { }
@ -1257,9 +1379,9 @@ export abstract class DeclarationStatement extends Statement {
/** Simple name being declared. */
name: IdentifierExpression;
/** Array of modifiers. */
modifiers: Modifier[] | null;
modifiers: ModifierNode[] | null;
/** Array of decorators. */
decorators: Decorator[] | null = null;
decorators: DecoratorNode[] | null = null;
protected cachedProgramLevelInternalName: string | null = null;
protected cachedFileLevelInternalName: string | null = null;
@ -1333,7 +1455,7 @@ export abstract class DeclarationStatement extends Statement {
export abstract class VariableLikeDeclarationStatement extends DeclarationStatement {
/** Variable type. */
type: TypeNode | null;
type: CommonTypeNode | null;
/** Variable initializer. */
initializer: Expression | null;
}
@ -1359,13 +1481,18 @@ export class ClassDeclaration extends DeclarationStatement {
kind = NodeKind.CLASSDECLARATION;
/** Accepted type parameters. */
typeParameters: TypeParameter[];
typeParameters: TypeParameterNode[];
/** Base class type being extended. */
extendsType: TypeNode | null;
extendsType: TypeNode | null; // can't be a function
/** Interface types being implemented. */
implementsTypes: TypeNode[];
implementsTypes: TypeNode[]; // can't be a function
/** Class member declarations. */
members: DeclarationStatement[];
get isGeneric(): bool {
var typeParameters = this.typeParameters;
return typeParameters != null && typeParameters.length > 0;
}
}
/** Represents a `continue` statement. */
@ -1376,27 +1503,6 @@ export class ContinueStatement extends Statement {
label: IdentifierExpression | null;
}
/** Built-in decorator kinds. */
export const enum DecoratorKind {
CUSTOM,
GLOBAL,
OPERATOR,
UNMANAGED,
OFFSET
}
/** Depresents a decorator. */
export class Decorator extends Statement {
kind = NodeKind.DECORATOR;
/** Name expression. */
name: Expression;
/** Argument expressions. */
arguments: Expression[] | null;
/** Built-in kind, if applicable. */
decoratorKind: DecoratorKind;
}
/** Represents a `do` statement. */
export class DoStatement extends Statement {
kind = NodeKind.DO;
@ -1455,7 +1561,7 @@ export class ExportStatement extends Statement {
kind = NodeKind.EXPORT;
/** Array of modifiers. */
modifiers: Modifier[] | null;
modifiers: ModifierNode[] | null;
/** Array of members. */
members: ExportMember[];
/** Path being exported from, if applicable. */
@ -1500,17 +1606,16 @@ export class ForStatement extends Statement {
export class FunctionDeclaration extends DeclarationStatement {
kind = NodeKind.FUNCTIONDECLARATION;
/** Accepted type parameters. */
typeParameters: TypeParameter[] | null;
/** Accepted parameters. */
parameters: Parameter[];
/** Return type. */
returnType: TypeNode | null;
/** Type parameters, if any. */
typeParameters: TypeParameterNode[] | null;
/** Function signature. */
signature: SignatureNode;
/** Body statement. Usually a block. */
body: Statement | null;
get isGeneric(): bool {
return this.typeParameters != null && this.typeParameters.length > 0;
var typeParameters = this.typeParameters;
return typeParameters != null && typeParameters.length > 0;
}
}
@ -1569,38 +1674,6 @@ export class NamespaceDeclaration extends DeclarationStatement {
members: Statement[];
}
/** Represents the kind of a parameter. */
export enum ParameterKind {
/** No specific flags. */
DEFAULT,
/** Is an optional parameter. */
OPTIONAL,
/** Is a rest parameter. */
REST
}
/** Represents a function parameter. */
export class Parameter extends Node {
kind = NodeKind.PARAMETER;
/** Parameter name. */
name: IdentifierExpression;
/** Parameter type. */
type: TypeNode | null;
/** Parameter kind. */
parameterKind: ParameterKind;
/** Initializer expression, if present. */
initializer: Expression | null;
}
/** Represents a single modifier. */
export class Modifier extends Node {
kind = NodeKind.MODIFIER;
/** Specific modifier kind. */
modifierKind: ModifierKind;
}
/** Represents a `return` statement. */
export class ReturnStatement extends Statement {
kind = NodeKind.RETURN;
@ -1656,7 +1729,7 @@ export class TypeDeclaration extends DeclarationStatement {
kind = NodeKind.TYPEDECLARATION;
/** Type being aliased. */
alias: TypeNode;
alias: CommonTypeNode;
}
/** Represents a variable declaration part of a {@link VariableStatement}. */
@ -1664,7 +1737,7 @@ export class VariableDeclaration extends VariableLikeDeclarationStatement {
kind = NodeKind.VARIABLEDECLARATION;
/** Array of modifiers. */
modifiers: Modifier[] | null;
modifiers: ModifierNode[] | null;
}
/** Represents a variable statement wrapping {@link VariableDeclaration}s. */
@ -1672,9 +1745,9 @@ export class VariableStatement extends Statement {
kind = NodeKind.VARIABLE;
/** Array of modifiers. */
modifiers: Modifier[] | null;
modifiers: ModifierNode[] | null;
/** Array of decorators. */
decorators: Decorator[] | null;
decorators: DecoratorNode[] | null;
/** Array of member declarations. */
declarations: VariableDeclaration[];
}
@ -1698,15 +1771,15 @@ export class WhileStatement extends Statement {
}
/** Cached unused modifiers for reuse. */
var reusableModifiers: Modifier[] | null = null;
var reusableModifiers: ModifierNode[] | null = null;
export function setReusableModifiers(modifiers: Modifier[]): void {
export function setReusableModifiers(modifiers: ModifierNode[]): void {
reusableModifiers = modifiers;
}
/** Creates a new modifiers array. */
export function createModifiers(): Modifier[] {
var ret: Modifier[];
export function createModifiers(): ModifierNode[] {
var ret: ModifierNode[];
if (reusableModifiers != null) {
ret = reusableModifiers;
reusableModifiers = null;
@ -1720,14 +1793,14 @@ export function createModifiers(): Modifier[] {
// Utility
/** Adds a modifier to a set of modifiers. Creates a new set if `null`. */
export function addModifier(modifier: Modifier, modifiers: Modifier[] | null): Modifier[] {
export function addModifier(modifier: ModifierNode, modifiers: ModifierNode[] | null): ModifierNode[] {
if (modifiers == null) modifiers = createModifiers();
modifiers.push(modifier);
return modifiers;
}
/** Gets a specific modifier from the specified set of modifiers. */
export function getModifier(kind: ModifierKind, modifiers: Modifier[] | null): Modifier | null {
export function getModifier(kind: ModifierKind, modifiers: ModifierNode[] | null): ModifierNode | null {
if (modifiers) {
for (var i = 0, k = modifiers.length; i < k; ++i) {
if (modifiers[i].modifierKind == kind) {
@ -1739,12 +1812,12 @@ export function getModifier(kind: ModifierKind, modifiers: Modifier[] | null): M
}
/** Tests whether a modifier exists in the specified set of modifiers. */
export function hasModifier(kind: ModifierKind, modifiers: Modifier[] | null): bool {
export function hasModifier(kind: ModifierKind, modifiers: ModifierNode[] | null): bool {
return getModifier(kind, modifiers) != null;
}
/** Gets the first decorator by name within at set of decorators, if present. */
export function getFirstDecorator(name: string, decorators: Decorator[] | null): Decorator | null {
export function getFirstDecorator(name: string, decorators: DecoratorNode[] | null): DecoratorNode | null {
if (decorators) {
for (var i = 0, k = decorators.length; i < k; ++i) {
var decorator = decorators[i];
@ -1758,7 +1831,7 @@ export function getFirstDecorator(name: string, decorators: Decorator[] | null):
}
/** Tests if a specific decorator is present within the specified decorators. */
export function hasDecorator(name: string, decorators: Decorator[] | null): bool {
export function hasDecorator(name: string, decorators: DecoratorNode[] | null): bool {
return getFirstDecorator(name, decorators) != null;
}
@ -1800,13 +1873,15 @@ export function mangleInternalPath(path: string): string {
// Helpers
/** Sets the parent node on an array of nodes. */
function setParent(nodes: Node[], parent: Node): void {
for (var i = 0, k = nodes.length; i < k; ++i) {
nodes[i].parent = parent;
}
}
function setParentOpt(nodes: (Node | null)[], parent: Node): void {
/** Sets the parent node on an array of nullable nodes. */
function setParentIfNotNull(nodes: (Node | null)[], parent: Node): void {
for (var i = 0, k = nodes.length; i < k; ++i) {
var node = nodes[i];
if (node) node.parent = parent;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -66,8 +66,7 @@ export class Decompiler {
var i: Index, k: Index;
switch (id) {
case ExpressionId.Block: // TODO: magic
case ExpressionId.Block: { // TODO: magic
if ((string = readString(_BinaryenBlockGetName(expr))) != null) {
this.push(string);
this.push(": ");
@ -79,8 +78,8 @@ export class Decompiler {
}
this.push("}\n");
return;
case ExpressionId.If:
}
case ExpressionId.If: {
if (type == NativeType.None) {
this.push("if (");
this.decompileExpression(_BinaryenIfGetCondition(expr));
@ -98,8 +97,8 @@ export class Decompiler {
this.decompileExpression(_BinaryenIfGetIfFalse(expr));
}
return;
case ExpressionId.Loop:
}
case ExpressionId.Loop: {
if ((string = readString(_BinaryenLoopGetName(expr))) != null) {
this.push(string);
this.push(": ");
@ -107,8 +106,8 @@ export class Decompiler {
this.push("do ");
this.decompileExpression(_BinaryenLoopGetBody(expr));
this.push("while (0);\n");
case ExpressionId.Break:
}
case ExpressionId.Break: {
if (nested = _BinaryenBreakGetCondition(expr)) {
this.push("if (");
this.decompileExpression(nested);
@ -122,32 +121,30 @@ export class Decompiler {
this.push("break;\n");
}
return;
}
case ExpressionId.Switch:
case ExpressionId.Call:
case ExpressionId.CallImport:
case ExpressionId.CallIndirect:
case ExpressionId.GetLocal:
case ExpressionId.CallIndirect: {
throw new Error("not implemented");
}
case ExpressionId.GetLocal: {
this.push("$");
this.push(_BinaryenGetLocalGetIndex(expr).toString(10));
return;
case ExpressionId.SetLocal:
}
case ExpressionId.SetLocal: {
this.push("$");
this.push(_BinaryenSetLocalGetIndex(expr).toString(10));
this.push(" = ");
this.decompileExpression(_BinaryenSetLocalGetValue(expr));
return;
}
case ExpressionId.GetGlobal:
case ExpressionId.SetGlobal:
case ExpressionId.Load:
case ExpressionId.SetGlobal: {
throw new Error("not implemented");
}
case ExpressionId.Load: {
this.push("load<");
this.push(nativeTypeToType(type));
this.push(">(");
@ -156,8 +153,8 @@ export class Decompiler {
this.decompileExpression(_BinaryenLoadGetPtr(expr));
this.push(")");
return;
case ExpressionId.Store:
}
case ExpressionId.Store: {
this.push("store<");
this.push(nativeTypeToType(type));
this.push(">(");
@ -168,15 +165,14 @@ export class Decompiler {
this.decompileExpression(_BinaryenStoreGetValue(expr));
this.push(")");
return;
case ExpressionId.Const:
}
case ExpressionId.Const: {
switch (type) {
case NativeType.I32:
case NativeType.I32: {
this.push(_BinaryenConstGetValueI32(expr).toString(10));
return;
case NativeType.I64:
}
case NativeType.I64: {
this.push(
i64_to_string(
i64_new(
@ -186,582 +182,583 @@ export class Decompiler {
)
);
return;
case NativeType.F32:
}
case NativeType.F32: {
this.push(_BinaryenConstGetValueF32(expr).toString(10));
return;
case NativeType.F64:
}
case NativeType.F64: {
this.push(_BinaryenConstGetValueF64(expr).toString(10));
return;
}
}
break;
case ExpressionId.Unary:
}
case ExpressionId.Unary: {
switch (_BinaryenUnaryGetOp(expr)) {
case UnaryOp.ClzI32:
case UnaryOp.ClzI32: {
this.push("clz<i32>(");
this.decompileExpression(_BinaryenUnaryGetValue(expr));
this.push(")");
return;
case UnaryOp.CtzI32:
}
case UnaryOp.CtzI32: {
this.push("ctz<i32>(");
this.decompileExpression(_BinaryenUnaryGetValue(expr));
this.push(")");
return;
case UnaryOp.PopcntI32:
}
case UnaryOp.PopcntI32: {
this.push("popcnt<i32>(");
this.decompileExpression(_BinaryenUnaryGetValue(expr));
this.push(")");
return;
}
case UnaryOp.NegF32:
case UnaryOp.NegF64:
case UnaryOp.NegF64: {
this.push("-");
this.decompileExpression(_BinaryenUnaryGetValue(expr));
return;
case UnaryOp.AbsF32:
}
case UnaryOp.AbsF32: {
this.push("abs<f32>(");
this.decompileExpression(_BinaryenUnaryGetValue(expr));
this.push(")");
return;
case UnaryOp.CeilF32:
}
case UnaryOp.CeilF32: {
this.push("ceil<f32>(");
this.decompileExpression(_BinaryenUnaryGetValue(expr));
this.push(")");
return;
case UnaryOp.FloorF32:
}
case UnaryOp.FloorF32: {
this.push("floor<f32>(");
this.decompileExpression(_BinaryenUnaryGetValue(expr));
this.push(")");
return;
case UnaryOp.TruncF32:
}
case UnaryOp.TruncF32: {
this.push("trunc<f32>(");
this.decompileExpression(_BinaryenUnaryGetValue(expr));
this.push(")");
return;
case UnaryOp.NearestF32:
}
case UnaryOp.NearestF32: {
this.push("nearest<i32>(");
this.decompileExpression(_BinaryenUnaryGetValue(expr));
this.push(")");
return;
case UnaryOp.SqrtF32:
}
case UnaryOp.SqrtF32: {
this.push("sqrt<f32>(");
this.decompileExpression(_BinaryenUnaryGetValue(expr));
this.push(")");
return;
}
case UnaryOp.EqzI32:
case UnaryOp.EqzI64:
case UnaryOp.EqzI64: {
this.push("!");
this.decompileExpression(_BinaryenUnaryGetValue(expr));
return;
case UnaryOp.ClzI64:
}
case UnaryOp.ClzI64: {
this.push("clz<i64>(");
this.decompileExpression(_BinaryenUnaryGetValue(expr));
this.push(")");
return;
case UnaryOp.CtzI64:
}
case UnaryOp.CtzI64: {
this.push("ctz<i64>(");
this.decompileExpression(_BinaryenUnaryGetValue(expr));
this.push(")");
return;
case UnaryOp.PopcntI64:
}
case UnaryOp.PopcntI64: {
this.push("popcnt<i64>(");
this.decompileExpression(_BinaryenUnaryGetValue(expr));
this.push(")");
return;
case UnaryOp.AbsF64:
}
case UnaryOp.AbsF64: {
this.push("abs<f64>(");
this.decompileExpression(_BinaryenUnaryGetValue(expr));
this.push(")");
return;
case UnaryOp.CeilF64:
}
case UnaryOp.CeilF64: {
this.push("ceil<f64>(");
this.decompileExpression(_BinaryenUnaryGetValue(expr));
this.push(")");
return;
case UnaryOp.FloorF64:
}
case UnaryOp.FloorF64: {
this.push("floor<f64>(");
this.decompileExpression(_BinaryenUnaryGetValue(expr));
this.push(")");
return;
case UnaryOp.TruncF64:
}
case UnaryOp.TruncF64: {
this.push("trunc<f64>(");
this.decompileExpression(_BinaryenUnaryGetValue(expr));
this.push(")");
return;
case UnaryOp.NearestF64:
}
case UnaryOp.NearestF64: {
this.push("nearest<f64>(");
this.decompileExpression(_BinaryenUnaryGetValue(expr));
this.push(")");
return;
case UnaryOp.SqrtF64:
}
case UnaryOp.SqrtF64: {
this.push("sqrt<f64>(");
this.decompileExpression(_BinaryenUnaryGetValue(expr));
this.push(")");
return;
case UnaryOp.ExtendI32:
}
case UnaryOp.ExtendI32: {
this.push("<i64>");
this.decompileExpression(_BinaryenUnaryGetValue(expr));
return;
case UnaryOp.ExtendU32:
}
case UnaryOp.ExtendU32: {
this.push("<i64><u64>");
this.decompileExpression(_BinaryenUnaryGetValue(expr));
return;
case UnaryOp.WrapI64:
}
case UnaryOp.WrapI64: {
this.push("<i32>");
this.decompileExpression(_BinaryenUnaryGetValue(expr));
return;
case UnaryOp.TruncF32ToI32:
}
case UnaryOp.TruncF32ToI32: {
this.push("<i32>");
this.decompileExpression(_BinaryenUnaryGetValue(expr));
return;
case UnaryOp.TruncF32ToI64:
}
case UnaryOp.TruncF32ToI64: {
this.push("<i64>");
this.decompileExpression(_BinaryenUnaryGetValue(expr));
return;
case UnaryOp.TruncF32ToU32:
}
case UnaryOp.TruncF32ToU32: {
this.push("<i32><u32>");
this.decompileExpression(_BinaryenUnaryGetValue(expr));
return;
case UnaryOp.TruncF32ToU64:
}
case UnaryOp.TruncF32ToU64: {
this.push("<i64><u64>");
this.decompileExpression(_BinaryenUnaryGetValue(expr));
return;
case UnaryOp.TruncF64ToI32:
}
case UnaryOp.TruncF64ToI32: {
this.push("<i32>");
this.decompileExpression(_BinaryenUnaryGetValue(expr));
return;
case UnaryOp.TruncF64ToI64:
}
case UnaryOp.TruncF64ToI64: {
this.push("<i64>");
this.decompileExpression(_BinaryenUnaryGetValue(expr));
return;
case UnaryOp.TruncF64ToU32:
}
case UnaryOp.TruncF64ToU32: {
this.push("<i32><u32>");
this.decompileExpression(_BinaryenUnaryGetValue(expr));
return;
case UnaryOp.TruncF64ToU64:
}
case UnaryOp.TruncF64ToU64: {
this.push("<i64><u64>");
this.decompileExpression(_BinaryenUnaryGetValue(expr));
return;
case UnaryOp.ReinterpretF32:
}
case UnaryOp.ReinterpretF32: {
this.push("reinterpret<f32,i32>(");
this.decompileExpression(_BinaryenUnaryGetValue(expr));
this.push(")");
return;
case UnaryOp.ReinterpretF64:
}
case UnaryOp.ReinterpretF64: {
this.push("reinterpret<f64,i64>(");
this.decompileExpression(_BinaryenUnaryGetValue(expr));
this.push(")");
return;
case UnaryOp.ConvertI32ToF32:
}
case UnaryOp.ConvertI32ToF32: {
this.push("<f32>");
this.decompileExpression(_BinaryenUnaryGetValue(expr));
return;
case UnaryOp.ConvertI32ToF64:
}
case UnaryOp.ConvertI32ToF64: {
this.push("<f64>");
this.decompileExpression(_BinaryenUnaryGetValue(expr));
return;
case UnaryOp.ConvertU32ToF32:
}
case UnaryOp.ConvertU32ToF32: {
this.push("<f32><u32>");
this.decompileExpression(_BinaryenUnaryGetValue(expr));
return;
case UnaryOp.ConvertU32ToF64:
}
case UnaryOp.ConvertU32ToF64: {
this.push("<f64><u32>");
this.decompileExpression(_BinaryenUnaryGetValue(expr));
return;
case UnaryOp.ConvertI64ToF32:
}
case UnaryOp.ConvertI64ToF32: {
this.push("<f32>");
this.decompileExpression(_BinaryenUnaryGetValue(expr));
return;
case UnaryOp.ConvertI64ToF64:
}
case UnaryOp.ConvertI64ToF64: {
this.push("<f64>");
this.decompileExpression(_BinaryenUnaryGetValue(expr));
return;
case UnaryOp.ConvertU64ToF32:
}
case UnaryOp.ConvertU64ToF32: {
this.push("<f32><u64>");
this.decompileExpression(_BinaryenUnaryGetValue(expr));
return;
case UnaryOp.ConvertU64ToF64:
}
case UnaryOp.ConvertU64ToF64: {
this.push("<f64><u64>");
this.decompileExpression(_BinaryenUnaryGetValue(expr));
return;
case UnaryOp.PromoteF32:
}
case UnaryOp.PromoteF32: {
this.push("<f64>");
this.decompileExpression(_BinaryenUnaryGetValue(expr));
return;
case UnaryOp.DemoteF64:
}
case UnaryOp.DemoteF64: {
this.push("<f32>");
this.decompileExpression(_BinaryenUnaryGetValue(expr));
return;
case UnaryOp.ReinterpretI32:
}
case UnaryOp.ReinterpretI32: {
this.push("reinterpret<i32,f32>(");
this.decompileExpression(_BinaryenUnaryGetValue(expr));
this.push(")");
return;
case UnaryOp.ReinterpretI64:
}
case UnaryOp.ReinterpretI64: {
this.push("reinterpret<i64,f64>(");
this.decompileExpression(_BinaryenUnaryGetValue(expr));
this.push(")");
return;
}
}
break;
case ExpressionId.Binary: // TODO: precedence
}
case ExpressionId.Binary: { // TODO: precedence
switch (_BinaryenBinaryGetOp(expr)) {
case BinaryOp.AddI32:
case BinaryOp.AddI64:
case BinaryOp.AddF32:
case BinaryOp.AddF64:
case BinaryOp.AddF64: {
this.decompileExpression(_BinaryenBinaryGetLeft(expr));
this.push(" + ");
this.decompileExpression(_BinaryenBinaryGetRight(expr));
return;
}
case BinaryOp.SubI32:
case BinaryOp.SubI64:
case BinaryOp.SubF32:
case BinaryOp.SubF64:
case BinaryOp.SubF64: {
this.decompileExpression(_BinaryenBinaryGetLeft(expr));
this.push(" - ");
this.decompileExpression(_BinaryenBinaryGetRight(expr));
return;
}
case BinaryOp.MulI32:
case BinaryOp.MulI64:
case BinaryOp.MulF32:
case BinaryOp.MulF64:
case BinaryOp.MulF64: {
this.decompileExpression(_BinaryenBinaryGetLeft(expr));
this.push(" * ");
this.decompileExpression(_BinaryenBinaryGetRight(expr));
return;
}
case BinaryOp.DivI32:
case BinaryOp.DivI64:
case BinaryOp.DivF32:
case BinaryOp.DivF64:
case BinaryOp.DivF64: {
this.decompileExpression(_BinaryenBinaryGetLeft(expr));
this.push(" / ");
this.decompileExpression(_BinaryenBinaryGetRight(expr));
return;
case BinaryOp.DivU32:
}
case BinaryOp.DivU32: {
this.push("<i32>(<u32>");
this.decompileExpression(_BinaryenBinaryGetLeft(expr));
this.push(" / <u32>");
this.decompileExpression(_BinaryenBinaryGetRight(expr));
this.push(")");
return;
}
case BinaryOp.RemI32:
case BinaryOp.RemI64:
case BinaryOp.RemI64: {
this.decompileExpression(_BinaryenBinaryGetLeft(expr));
this.push(" % ");
this.decompileExpression(_BinaryenBinaryGetRight(expr));
return;
case BinaryOp.RemU32:
}
case BinaryOp.RemU32: {
this.push("<i32>(<u32>");
this.decompileExpression(_BinaryenBinaryGetLeft(expr));
this.push(" / <u32>");
this.decompileExpression(_BinaryenBinaryGetRight(expr));
this.push(")");
return;
}
case BinaryOp.AndI32:
case BinaryOp.AndI64:
case BinaryOp.AndI64: {
this.decompileExpression(_BinaryenBinaryGetLeft(expr));
this.push(" & ");
this.decompileExpression(_BinaryenBinaryGetRight(expr));
return;
}
case BinaryOp.OrI32:
case BinaryOp.OrI64:
case BinaryOp.OrI64: {
this.decompileExpression(_BinaryenBinaryGetLeft(expr));
this.push(" | ");
this.decompileExpression(_BinaryenBinaryGetRight(expr));
return;
}
case BinaryOp.XorI32:
case BinaryOp.XorI64:
case BinaryOp.XorI64: {
this.decompileExpression(_BinaryenBinaryGetLeft(expr));
this.push(" ^ ");
this.decompileExpression(_BinaryenBinaryGetRight(expr));
return;
}
case BinaryOp.ShlI32:
case BinaryOp.ShlI64:
case BinaryOp.ShlI64: {
this.decompileExpression(_BinaryenBinaryGetLeft(expr));
this.push(" << ");
this.decompileExpression(_BinaryenBinaryGetRight(expr));
return;
}
case BinaryOp.ShrU32:
case BinaryOp.ShrU64:
case BinaryOp.ShrU64: {
this.decompileExpression(_BinaryenBinaryGetLeft(expr));
this.push(" >>> ");
this.decompileExpression(_BinaryenBinaryGetRight(expr));
return;
}
case BinaryOp.ShrI32:
case BinaryOp.ShrI64:
case BinaryOp.ShrI64: {
this.decompileExpression(_BinaryenBinaryGetLeft(expr));
this.push(" >> ");
this.decompileExpression(_BinaryenBinaryGetRight(expr));
return;
case BinaryOp.RotlI32:
}
case BinaryOp.RotlI32: {
this.push("rotl<i32>(");
this.decompileExpression(_BinaryenBinaryGetLeft(expr));
this.push(", ");
this.decompileExpression(_BinaryenBinaryGetRight(expr));
this.push(")");
return;
case BinaryOp.RotrI32:
}
case BinaryOp.RotrI32: {
this.push("rotr<i32>(");
this.decompileExpression(_BinaryenBinaryGetLeft(expr));
this.push(", ");
this.decompileExpression(_BinaryenBinaryGetRight(expr));
this.push(")");
return;
}
case BinaryOp.EqI32:
case BinaryOp.EqI64:
case BinaryOp.EqF32:
case BinaryOp.EqF64:
case BinaryOp.EqF64: {
this.decompileExpression(_BinaryenBinaryGetLeft(expr));
this.push(" == ");
this.decompileExpression(_BinaryenBinaryGetRight(expr));
return;
}
case BinaryOp.NeI32:
case BinaryOp.NeI64:
case BinaryOp.NeF32:
case BinaryOp.NeF64:
case BinaryOp.NeF64: {
this.decompileExpression(_BinaryenBinaryGetLeft(expr));
this.push(" != ");
this.decompileExpression(_BinaryenBinaryGetRight(expr));
return;
}
case BinaryOp.LtI32:
case BinaryOp.LtI64:
case BinaryOp.LtF32:
case BinaryOp.LtF64:
case BinaryOp.LtF64: {
this.decompileExpression(_BinaryenBinaryGetLeft(expr));
this.push(" < ");
this.decompileExpression(_BinaryenBinaryGetRight(expr));
return;
case BinaryOp.LtU32:
}
case BinaryOp.LtU32: {
this.push("<u32>");
this.decompileExpression(_BinaryenBinaryGetLeft(expr));
this.push(" < <u32>");
this.decompileExpression(_BinaryenBinaryGetRight(expr));
return;
}
case BinaryOp.LeI32:
case BinaryOp.LeI64:
case BinaryOp.LeF32:
case BinaryOp.LeF64:
case BinaryOp.LeF64: {
this.decompileExpression(_BinaryenBinaryGetLeft(expr));
this.push(" <= ");
this.decompileExpression(_BinaryenBinaryGetRight(expr));
return;
case BinaryOp.LeU32:
}
case BinaryOp.LeU32: {
this.push("<u32>");
this.decompileExpression(_BinaryenBinaryGetLeft(expr));
this.push(" <= <u32>");
this.decompileExpression(_BinaryenBinaryGetRight(expr));
return;
}
case BinaryOp.GtI32:
case BinaryOp.GtI64:
case BinaryOp.GtF32:
case BinaryOp.GtF64:
case BinaryOp.GtF64: {
this.decompileExpression(_BinaryenBinaryGetLeft(expr));
this.push(" > ");
this.decompileExpression(_BinaryenBinaryGetRight(expr));
return;
case BinaryOp.GtU32:
}
case BinaryOp.GtU32: {
this.push("<u32>");
this.decompileExpression(_BinaryenBinaryGetLeft(expr));
this.push(" > <u32>");
this.decompileExpression(_BinaryenBinaryGetRight(expr));
return;
}
case BinaryOp.GeI32:
case BinaryOp.GeI64:
case BinaryOp.GeF32:
case BinaryOp.GeF64:
case BinaryOp.GeF64: {
this.decompileExpression(_BinaryenBinaryGetLeft(expr));
this.push(" >= ");
this.decompileExpression(_BinaryenBinaryGetRight(expr));
return;
case BinaryOp.GeU32:
}
case BinaryOp.GeU32: {
this.push("<u32>");
this.decompileExpression(_BinaryenBinaryGetLeft(expr));
this.push(" >= <u32>");
this.decompileExpression(_BinaryenBinaryGetRight(expr));
return;
case BinaryOp.DivU64:
}
case BinaryOp.DivU64: {
this.push("<u64>");
this.decompileExpression(_BinaryenBinaryGetLeft(expr));
this.push(" / <u64>");
this.decompileExpression(_BinaryenBinaryGetRight(expr));
return;
case BinaryOp.RemU64:
}
case BinaryOp.RemU64: {
this.push("<u64>");
this.decompileExpression(_BinaryenBinaryGetLeft(expr));
this.push(" % <u64>");
this.decompileExpression(_BinaryenBinaryGetRight(expr));
return;
case BinaryOp.RotlI64:
}
case BinaryOp.RotlI64: {
this.push("rotl<i64>(");
this.decompileExpression(_BinaryenBinaryGetLeft(expr));
this.push(", ");
this.decompileExpression(_BinaryenBinaryGetRight(expr));
this.push(")");
return;
case BinaryOp.RotrI64:
}
case BinaryOp.RotrI64: {
this.push("rotr<i64>(");
this.decompileExpression(_BinaryenBinaryGetLeft(expr));
this.push(", ");
this.decompileExpression(_BinaryenBinaryGetRight(expr));
this.push(")");
return;
case BinaryOp.LtU64:
}
case BinaryOp.LtU64: {
this.push("<u64>");
this.decompileExpression(_BinaryenBinaryGetLeft(expr));
this.push(" < <u64>");
this.decompileExpression(_BinaryenBinaryGetRight(expr));
return;
case BinaryOp.LeU64:
}
case BinaryOp.LeU64: {
this.push("<u64>");
this.decompileExpression(_BinaryenBinaryGetLeft(expr));
this.push(" <= <u64>");
this.decompileExpression(_BinaryenBinaryGetRight(expr));
return;
case BinaryOp.GtU64:
}
case BinaryOp.GtU64: {
this.push("<u64>");
this.decompileExpression(_BinaryenBinaryGetLeft(expr));
this.push(" > <u64>");
this.decompileExpression(_BinaryenBinaryGetRight(expr));
return;
case BinaryOp.GeU64:
}
case BinaryOp.GeU64: {
this.push("<u64>");
this.decompileExpression(_BinaryenBinaryGetLeft(expr));
this.push(" >= <u64>");
this.decompileExpression(_BinaryenBinaryGetRight(expr));
return;
case BinaryOp.CopysignF32:
}
case BinaryOp.CopysignF32: {
this.push("copysign<f32>(");
this.decompileExpression(_BinaryenBinaryGetLeft(expr));
this.push(", ");
this.decompileExpression(_BinaryenBinaryGetRight(expr));
this.push(")");
return;
case BinaryOp.MinF32:
}
case BinaryOp.MinF32: {
this.push("min<f32>(");
this.decompileExpression(_BinaryenBinaryGetLeft(expr));
this.push(", ");
this.decompileExpression(_BinaryenBinaryGetRight(expr));
this.push(")");
return;
case BinaryOp.MaxF32:
}
case BinaryOp.MaxF32: {
this.push("max<f32>(");
this.decompileExpression(_BinaryenBinaryGetLeft(expr));
this.push(", ");
this.decompileExpression(_BinaryenBinaryGetRight(expr));
this.push(")");
return;
case BinaryOp.CopysignF64:
}
case BinaryOp.CopysignF64: {
this.push("copysign<f64>(");
this.decompileExpression(_BinaryenBinaryGetLeft(expr));
this.push(", ");
this.decompileExpression(_BinaryenBinaryGetRight(expr));
this.push(")");
return;
case BinaryOp.MinF64:
}
case BinaryOp.MinF64: {
this.push("min<f64>(");
this.decompileExpression(_BinaryenBinaryGetLeft(expr));
this.push(", ");
this.decompileExpression(_BinaryenBinaryGetRight(expr));
this.push(")");
return;
case BinaryOp.MaxF64:
}
case BinaryOp.MaxF64: {
this.push("max<f64>(");
this.decompileExpression(_BinaryenBinaryGetLeft(expr));
this.push(", ");
this.decompileExpression(_BinaryenBinaryGetRight(expr));
this.push(")");
return;
}
}
return;
case ExpressionId.Select:
}
case ExpressionId.Select: {
this.push("select<");
this.push(nativeTypeToType(type));
this.push(">(");
@ -772,13 +769,13 @@ export class Decompiler {
this.decompileExpression(_BinaryenSelectGetCondition(expr));
this.push(")");
return;
case ExpressionId.Drop:
}
case ExpressionId.Drop: {
this.decompileExpression(_BinaryenDropGetValue(expr));
this.push(";\n");
return;
case ExpressionId.Return:
}
case ExpressionId.Return: {
if (nested = _BinaryenReturnGetValue(expr)) {
this.push("return ");
this.decompileExpression(nested);
@ -787,34 +784,33 @@ export class Decompiler {
this.push("return;\n");
}
return;
case ExpressionId.Host:
}
case ExpressionId.Host: {
switch (_BinaryenHostGetOp(expr)) {
case HostOp.CurrentMemory:
case HostOp.CurrentMemory: {
this.push("current_memory()");
return;
case HostOp.GrowMemory:
}
case HostOp.GrowMemory: {
this.push("grow_memory(");
this.decompileExpression(_BinaryenHostGetOperand(expr, 0));
this.push(")");
return;
}
}
break;
case ExpressionId.Nop:
}
case ExpressionId.Nop: {
this.push(";\n");
return;
case ExpressionId.Unreachable:
}
case ExpressionId.Unreachable: {
this.push("unreachable()");
return;
}
case ExpressionId.AtomicCmpxchg:
case ExpressionId.AtomicRMW:
case ExpressionId.AtomicWait:
case ExpressionId.AtomicWake:
}
throw new Error("not implemented");

View File

@ -7,8 +7,10 @@ import {
NodeKind,
Source,
CommonTypeNode,
TypeNode,
TypeParameter,
TypeParameterNode,
SignatureNode,
Expression,
IdentifierExpression,
@ -65,10 +67,10 @@ import {
TypeDeclaration,
VariableDeclaration,
Decorator,
Modifier,
DecoratorNode,
ModifierNode,
ModifierKind,
Parameter,
ParameterNode,
ParameterKind,
ExportMember,
SwitchCase,
@ -79,6 +81,7 @@ import {
import {
CharCode
} from "../util/charcode";
import { Signature } from "../types";
export function serializeNode(node: Node, sb: string[]): void {
switch (node.kind) {
@ -94,7 +97,7 @@ export function serializeNode(node: Node, sb: string[]): void {
break;
case NodeKind.TYPEPARAMETER:
serializeTypeParameter(<TypeParameter>node, sb);
serializeTypeParameter(<TypeParameterNode>node, sb);
break;
// expressions
@ -277,7 +280,7 @@ export function serializeNode(node: Node, sb: string[]): void {
// other
case NodeKind.DECORATOR:
serializeDecorator(<Decorator>node, sb);
serializeDecorator(<DecoratorNode>node, sb);
break;
case NodeKind.EXPORTMEMBER:
@ -285,11 +288,11 @@ export function serializeNode(node: Node, sb: string[]): void {
break;
case NodeKind.MODIFIER:
serializeModifier(<Modifier>node, sb);
serializeModifier(<ModifierNode>node, sb);
break;
case NodeKind.PARAMETER:
serializeParameter(<Parameter>node, sb);
serializeParameter(<ParameterNode>node, sb);
break;
case NodeKind.SWITCHCASE:
@ -310,29 +313,64 @@ export function serializeSource(source: Source, sb: string[]): void {
// types
export function serializeTypeNode(node: TypeNode, sb: string[]): void {
serializeIdentifierExpression(<IdentifierExpression>node.name, sb);
var k = node.typeArguments.length;
if (k) {
sb.push("<");
serializeTypeNode(node.typeArguments[0], sb);
for (var i = 1; i < k; ++i) {
sb.push(", ");
serializeTypeNode(node.typeArguments[i], sb);
}
sb.push(">");
export function serializeTypeNode(node: CommonTypeNode, sb: string[]): void {
if (node.kind == NodeKind.SIGNATURE) {
return serializeSignatureNode(<SignatureNode>node, sb);
}
var typeNode = <TypeNode>node;
serializeIdentifierExpression(<IdentifierExpression>typeNode.name, sb);
if (typeNode.typeArguments) {
var k = typeNode.typeArguments.length;
if (k) {
sb.push("<");
serializeTypeNode(typeNode.typeArguments[0], sb);
for (var i = 1; i < k; ++i) {
sb.push(", ");
serializeTypeNode(typeNode.typeArguments[i], sb);
}
sb.push(">");
}
if (node.isNullable) sb.push(" | null");
}
if (node.isNullable) sb.push(" | null");
}
export function serializeTypeParameter(node: TypeParameter, sb: string[]): void {
export function serializeTypeParameter(node: TypeParameterNode, sb: string[]): void {
serializeIdentifierExpression(node.name, sb);
if (node.extendsType) {
var extendsType = node.extendsType;
if (extendsType) {
sb.push(" extends ");
serializeTypeNode(node.extendsType, sb);
serializeTypeNode(extendsType, sb);
}
}
export function serializeSignatureNode(node: SignatureNode, sb: string[]): void {
var isNullable = node.isNullable;
sb.push(isNullable ? "((" : "(");
var explicitThisType = node.explicitThisType;
if (explicitThisType) {
sb.push("this: ");
serializeTypeNode(explicitThisType, sb);
}
var parameters = node.parameterTypes;
var numParameters = parameters.length;
if (numParameters) {
if (explicitThisType) sb.push(", ");
serializeParameter(parameters[0], sb);
for (let i = 1; i < numParameters; ++i) {
sb.push(", ");
serializeParameter(parameters[i], sb);
}
}
var returnType = node.returnType;
if (returnType) {
sb.push(") => ");
serializeTypeNode(returnType, sb);
} else {
sb.push(") => void");
}
if (isNullable) sb.push(") | null");
}
// expressions
export function serializeExpression(node: Expression, sb: string[]): void {
@ -876,6 +914,7 @@ export function serializeFunctionDeclaration(node: FunctionDeclaration, sb: stri
function serializeFunctionCommon(node: FunctionDeclaration, sb: string[], isArrow: bool = false): void {
var i: i32, k: i32;
serializeIdentifierExpression(node.name, sb);
var signature = node.signature;
if (node.typeParameters) {
if (k = node.typeParameters.length) {
sb.push("<");
@ -888,34 +927,35 @@ function serializeFunctionCommon(node: FunctionDeclaration, sb: string[], isArro
}
}
sb.push("(");
if (k = node.parameters.length) {
serializeParameter(node.parameters[0], sb);
if (k = signature.parameterTypes.length) {
serializeParameter(signature.parameterTypes[0], sb);
for (i = 1; i < k; ++i) {
sb.push(", ");
serializeParameter(node.parameters[i], sb);
serializeParameter(signature.parameterTypes[i], sb);
}
}
if (isArrow) {
if (node.body) {
if (node.returnType) {
if (signature.returnType) {
sb.push("): ");
serializeTypeNode(node.returnType, sb);
serializeTypeNode(signature.returnType, sb);
}
sb.push(" => ");
serializeStatement(<Statement>node.body, sb);
serializeStatement(node.body, sb);
} else {
if (node.returnType) {
if (signature.returnType) {
sb.push(" => ");
serializeTypeNode(node.returnType, sb);
serializeTypeNode(signature.returnType, sb);
} else {
sb.push(" => void");
}
}
} else {
if (node.returnType && !hasModifier(ModifierKind.SET, node.modifiers)) {
if (signature.returnType && !hasModifier(ModifierKind.SET, node.modifiers)) {
sb.push("): ");
serializeTypeNode(node.returnType, sb);
serializeTypeNode(signature.returnType, sb);
} else {
// TODO: constructor?
sb.push(")");
}
if (node.body) {
@ -1203,7 +1243,7 @@ export function serializeWhileStatement(node: WhileStatement, sb: string[]): voi
// other
export function serializeDecorator(node: Decorator, sb: string[]): void {
export function serializeDecorator(node: DecoratorNode, sb: string[]): void {
sb.push("@");
serializeExpression(node.name, sb);
if (node.arguments) {
@ -1220,11 +1260,11 @@ export function serializeDecorator(node: Decorator, sb: string[]): void {
}
}
export function serializeModifier(node: Modifier, sb: string[]): void {
export function serializeModifier(node: ModifierNode, sb: string[]): void {
sb.push(modifierToString(node));
}
export function serializeParameter(node: Parameter, sb: string[]): void {
export function serializeParameter(node: ParameterNode, sb: string[]): void {
if (node.parameterKind == ParameterKind.REST) {
sb.push("...");
}
@ -1245,7 +1285,7 @@ export function serializeParameter(node: Parameter, sb: string[]): void {
// helpers
export function modifierToString(node: Modifier): string {
export function modifierToString(node: ModifierNode): string {
switch (node.modifierKind) {
case ModifierKind.ASYNC: return "async";
case ModifierKind.CONST: return "const";

View File

@ -265,12 +265,12 @@ export class Module {
addFunctionType(
name: string,
result: NativeType,
paramTypes: NativeType[]
paramTypes: NativeType[] | null
): FunctionRef {
var cStr = allocString(name);
var cArr = allocI32Array(paramTypes);
try {
return _BinaryenAddFunctionType(this.ref, cStr, result, cArr, paramTypes.length);
return _BinaryenAddFunctionType(this.ref, cStr, result, cArr, paramTypes ? paramTypes.length : 0);
} finally {
free_memory(cArr);
free_memory(cStr);
@ -279,11 +279,11 @@ export class Module {
getFunctionTypeBySignature(
result: NativeType,
paramTypes: NativeType[]
paramTypes: NativeType[] | null
): FunctionTypeRef {
var cArr = allocI32Array(paramTypes);
try {
return _BinaryenGetFunctionTypeBySignature(this.ref, result, cArr, paramTypes.length);
return _BinaryenGetFunctionTypeBySignature(this.ref, result, cArr, paramTypes ? paramTypes.length : 0);
} finally {
free_memory(cArr);
}
@ -594,6 +594,21 @@ export class Module {
}
}
createCallIndirect(
index: ExpressionRef,
operands: ExpressionRef[] | null,
typeName: string
): ExpressionRef {
var cArr = allocI32Array(operands);
var cStr = allocString(typeName);
try {
return _BinaryenCallIndirect(this.ref, index, cArr, operands && operands.length || 0, cStr);
} finally {
free_memory(cStr);
free_memory(cArr);
}
}
createUnreachable(): ExpressionRef {
return _BinaryenUnreachable(this.ref);
}
@ -617,13 +632,13 @@ export class Module {
addFunction(
name: string,
type: FunctionTypeRef,
varTypes: NativeType[],
varTypes: NativeType[] | null,
body: ExpressionRef
): FunctionRef {
var cStr = allocString(name);
var cArr = allocI32Array(varTypes);
try {
return _BinaryenAddFunction(this.ref, cStr, type, cArr, varTypes.length, body);
return _BinaryenAddFunction(this.ref, cStr, type, cArr, varTypes ? varTypes.length : 0, body);
} finally {
free_memory(cArr);
free_memory(cStr);
@ -928,36 +943,40 @@ export class Module {
nested2: ExpressionRef;
switch (_BinaryenExpressionGetId(expr)) {
case ExpressionId.Const:
case ExpressionId.Const: {
switch (_BinaryenExpressionGetType(expr)) {
case NativeType.I32:
case NativeType.I32: {
return this.createI32(_BinaryenConstGetValueI32(expr));
case NativeType.I64:
}
case NativeType.I64: {
return this.createI64(
_BinaryenConstGetValueI64Low(expr),
_BinaryenConstGetValueI64High(expr)
);
case NativeType.F32:
}
case NativeType.F32: {
return this.createF32(_BinaryenConstGetValueF32(expr));
case NativeType.F64:
}
case NativeType.F64: {
return this.createF64(_BinaryenConstGetValueF64(expr));
default:
}
default: {
throw new Error("concrete type expected");
}
}
case ExpressionId.GetLocal:
}
case ExpressionId.GetLocal: {
return _BinaryenGetLocal(this.ref,
_BinaryenGetLocalGetIndex(expr),
_BinaryenExpressionGetType(expr)
);
case ExpressionId.GetGlobal:
}
case ExpressionId.GetGlobal: {
var globalName = _BinaryenGetGlobalGetName(expr);
if (!globalName) break;
return _BinaryenGetGlobal(this.ref, globalName, _BinaryenExpressionGetType(expr));
case ExpressionId.Load:
}
case ExpressionId.Load: {
if (!(nested1 = this.cloneExpression(_BinaryenLoadGetPtr(expr), noSideEffects, maxDepth))) {
break;
}
@ -976,14 +995,14 @@ export class Module {
_BinaryenExpressionGetType(expr),
nested1
);
case ExpressionId.Unary:
}
case ExpressionId.Unary: {
if (!(nested1 = this.cloneExpression(_BinaryenUnaryGetValue(expr), noSideEffects, maxDepth))) {
break;
}
return _BinaryenUnary(this.ref, _BinaryenUnaryGetOp(expr), nested1);
case ExpressionId.Binary:
}
case ExpressionId.Binary: {
if (!(nested1 = this.cloneExpression(_BinaryenBinaryGetLeft(expr), noSideEffects, maxDepth))) {
break;
}
@ -991,6 +1010,7 @@ export class Module {
break;
}
return _BinaryenBinary(this.ref, _BinaryenBinaryGetOp(expr), nested1, nested2);
}
}
return 0;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -260,10 +260,8 @@ export namespace Token {
case Token.NAMESPACE:
case Token.READONLY:
case Token.SET:
case Token.TYPE:
return true;
default:
return false;
case Token.TYPE: return true;
default: return false;
}
}
@ -317,7 +315,10 @@ export namespace Token {
case Token.AMPERSAND_EQUALS: return "&=";
case Token.BAR_EQUALS: return "|=";
case Token.CARET_EQUALS: return "^=";
default: assert(false); return "";
default: {
assert(false);
return "";
}
}
}
}
@ -394,10 +395,6 @@ export class Tokenizer extends DiagnosticEmitter {
token: Token = -1;
tokenPos: i32 = 0;
markedPos: i32 = 0;
markedToken: Token = -1;
markedTokenPos: i32 = 0;
nextToken: Token = -1;
nextTokenOnNewLine: bool = false;
@ -446,8 +443,7 @@ export class Tokenizer extends DiagnosticEmitter {
this.tokenPos = this.pos;
var c = text.charCodeAt(this.pos);
switch (c) {
case CharCode.CARRIAGERETURN:
case CharCode.CARRIAGERETURN: {
if (
++this.pos < this.end &&
text.charCodeAt(this.pos) == CharCode.LINEFEED
@ -455,16 +451,16 @@ export class Tokenizer extends DiagnosticEmitter {
++this.pos;
}
break;
}
case CharCode.LINEFEED:
case CharCode.TAB:
case CharCode.VERTICALTAB:
case CharCode.FORMFEED:
case CharCode.SPACE:
case CharCode.SPACE: {
++this.pos;
break;
case CharCode.EXCLAMATION:
}
case CharCode.EXCLAMATION: {
++this.pos;
if (
maxTokenLength > 1 && this.pos < this.end &&
@ -481,13 +477,13 @@ export class Tokenizer extends DiagnosticEmitter {
return Token.EXCLAMATION_EQUALS;
}
return Token.EXCLAMATION;
}
case CharCode.DOUBLEQUOTE:
case CharCode.SINGLEQUOTE:
case CharCode.BACKTICK: // TODO
case CharCode.BACKTICK: { // TODO
return Token.STRINGLITERAL; // expects a call to readString
case CharCode.PERCENT:
}
case CharCode.PERCENT: {
++this.pos;
if (
maxTokenLength > 1 && this.pos < this.end &&
@ -497,8 +493,8 @@ export class Tokenizer extends DiagnosticEmitter {
return Token.PERCENT_EQUALS;
}
return Token.PERCENT;
case CharCode.AMPERSAND:
}
case CharCode.AMPERSAND: {
++this.pos;
if (maxTokenLength > 1 && this.pos < this.end) {
if (text.charCodeAt(this.pos) == CharCode.AMPERSAND) {
@ -511,16 +507,16 @@ export class Tokenizer extends DiagnosticEmitter {
}
}
return Token.AMPERSAND;
case CharCode.OPENPAREN:
}
case CharCode.OPENPAREN: {
++this.pos;
return Token.OPENPAREN;
case CharCode.CLOSEPAREN:
}
case CharCode.CLOSEPAREN: {
++this.pos;
return Token.CLOSEPAREN;
case CharCode.ASTERISK:
}
case CharCode.ASTERISK: {
++this.pos;
if (maxTokenLength > 1 && this.pos < this.end) {
if (text.charCodeAt(this.pos) == CharCode.EQUALS) {
@ -540,8 +536,8 @@ export class Tokenizer extends DiagnosticEmitter {
}
}
return Token.ASTERISK;
case CharCode.PLUS:
}
case CharCode.PLUS: {
++this.pos;
if (maxTokenLength > 1 && this.pos < this.end) {
if (text.charCodeAt(this.pos) == CharCode.PLUS) {
@ -554,12 +550,12 @@ export class Tokenizer extends DiagnosticEmitter {
}
}
return Token.PLUS;
case CharCode.COMMA:
}
case CharCode.COMMA: {
++this.pos;
return Token.COMMA;
case CharCode.MINUS:
}
case CharCode.MINUS: {
++this.pos;
if (maxTokenLength > 1 && this.pos < this.end) {
if (text.charCodeAt(this.pos) == CharCode.MINUS) {
@ -572,8 +568,8 @@ export class Tokenizer extends DiagnosticEmitter {
}
}
return Token.MINUS;
case CharCode.DOT:
}
case CharCode.DOT: {
++this.pos;
if (maxTokenLength > 1 && this.pos < this.end) {
if (isDecimalDigit(text.charCodeAt(this.pos))) {
@ -590,8 +586,8 @@ export class Tokenizer extends DiagnosticEmitter {
}
}
return Token.DOT;
case CharCode.SLASH:
}
case CharCode.SLASH: {
++this.pos;
if (maxTokenLength > 1 && this.pos < this.end) {
if (text.charCodeAt(this.pos) == CharCode.SLASH) { // single-line
@ -634,7 +630,7 @@ export class Tokenizer extends DiagnosticEmitter {
}
}
return Token.SLASH;
}
case CharCode._0:
case CharCode._1:
case CharCode._2:
@ -644,20 +640,20 @@ export class Tokenizer extends DiagnosticEmitter {
case CharCode._6:
case CharCode._7:
case CharCode._8:
case CharCode._9:
case CharCode._9: {
return this.testInteger()
? Token.INTEGERLITERAL // expects a call to readInteger
: Token.FLOATLITERAL; // expects a call to readFloat
case CharCode.COLON:
}
case CharCode.COLON: {
++this.pos;
return Token.COLON;
case CharCode.SEMICOLON:
}
case CharCode.SEMICOLON: {
++this.pos;
return Token.SEMICOLON;
case CharCode.LESSTHAN:
}
case CharCode.LESSTHAN: {
++this.pos;
if (maxTokenLength > 1 && this.pos < this.end) {
if (text.charCodeAt(this.pos) == CharCode.LESSTHAN) {
@ -678,8 +674,8 @@ export class Tokenizer extends DiagnosticEmitter {
}
}
return Token.LESSTHAN;
case CharCode.EQUALS:
}
case CharCode.EQUALS: {
++this.pos;
if (maxTokenLength > 1 && this.pos < this.end) {
if (text.charCodeAt(this.pos) == CharCode.EQUALS) {
@ -700,8 +696,8 @@ export class Tokenizer extends DiagnosticEmitter {
}
}
return Token.EQUALS;
case CharCode.GREATERTHAN:
}
case CharCode.GREATERTHAN: {
++this.pos;
if (maxTokenLength > 1 && this.pos < this.end) {
if (text.charCodeAt(this.pos) == CharCode.GREATERTHAN) {
@ -731,20 +727,20 @@ export class Tokenizer extends DiagnosticEmitter {
}
}
return Token.GREATERTHAN;
case CharCode.QUESTION:
}
case CharCode.QUESTION: {
++this.pos;
return Token.QUESTION;
case CharCode.OPENBRACKET:
}
case CharCode.OPENBRACKET: {
++this.pos;
return Token.OPENBRACKET;
case CharCode.CLOSEBRACKET:
}
case CharCode.CLOSEBRACKET: {
++this.pos;
return Token.CLOSEBRACKET;
case CharCode.CARET:
}
case CharCode.CARET: {
++this.pos;
if (
maxTokenLength > 1 && this.pos < this.end &&
@ -754,12 +750,12 @@ export class Tokenizer extends DiagnosticEmitter {
return Token.CARET_EQUALS;
}
return Token.CARET;
case CharCode.OPENBRACE:
}
case CharCode.OPENBRACE: {
++this.pos;
return Token.OPENBRACE;
case CharCode.BAR:
}
case CharCode.BAR: {
++this.pos;
if (maxTokenLength > 1 && this.pos < this.end) {
if (text.charCodeAt(this.pos) == CharCode.BAR) {
@ -772,20 +768,20 @@ export class Tokenizer extends DiagnosticEmitter {
}
}
return Token.BAR;
case CharCode.CLOSEBRACE:
}
case CharCode.CLOSEBRACE: {
++this.pos;
return Token.CLOSEBRACE;
case CharCode.TILDE:
}
case CharCode.TILDE: {
++this.pos;
return Token.TILDE;
case CharCode.AT:
}
case CharCode.AT: {
++this.pos;
return Token.AT;
default:
}
default: {
if (isIdentifierStart(c)) {
if (isKeywordCharacter(c)) {
var posBefore = this.pos;
@ -819,6 +815,7 @@ export class Tokenizer extends DiagnosticEmitter {
);
++this.pos;
return Token.INVALID;
}
}
}
return Token.ENDOFFILE;
@ -857,9 +854,10 @@ export class Tokenizer extends DiagnosticEmitter {
var tokenPosBefore = this.tokenPos;
var maxCompoundLength = i32.MAX_VALUE;
switch (token) {
case Token.GREATERTHAN: // where parsing type arguments
case Token.GREATERTHAN: { // where parsing type arguments
maxCompoundLength = 1;
break;
}
}
this.token = this.unsafeNext(token == Token.IDENTIFIER, maxCompoundLength);
if (this.token == token) {
@ -884,17 +882,30 @@ export class Tokenizer extends DiagnosticEmitter {
// } while (true);
// }
mark(): void {
this.markedPos = this.pos;
this.markedToken = this.token;
this.markedTokenPos = this.tokenPos;
mark(): State {
var state: State;
if (reusableState) {
state = reusableState;
reusableState = null;
} else {
state = new State();
}
state.pos = this.pos;
state.token = this.token;
state.tokenPos = this.tokenPos;
return state;
}
reset(): void {
this.pos = this.markedPos;
this.token = this.markedToken;
this.tokenPos = this.markedTokenPos;
discard(state: State): void {
reusableState = state;
}
reset(state: State): void {
this.pos = state.pos;
this.token = state.token;
this.tokenPos = state.tokenPos;
this.nextToken = -1;
reusableState = state;
}
range(start: i32 = -1, end: i32 = -1): Range {
@ -967,34 +978,15 @@ export class Tokenizer extends DiagnosticEmitter {
var text = this.source.text;
var c = text.charCodeAt(this.pos++);
switch (c) {
case CharCode._0:
return "\0";
case CharCode.b:
return "\b";
case CharCode.t:
return "\t";
case CharCode.n:
return "\n";
case CharCode.v:
return "\v";
case CharCode.f:
return "\f";
case CharCode.r:
return "\r";
case CharCode.SINGLEQUOTE:
return "'";
case CharCode.DOUBLEQUOTE:
return "\"";
case CharCode._0: return "\0";
case CharCode.b: return "\b";
case CharCode.t: return "\t";
case CharCode.n: return "\n";
case CharCode.v: return "\v";
case CharCode.f: return "\f";
case CharCode.r: return "\r";
case CharCode.SINGLEQUOTE: return "'";
case CharCode.DOUBLEQUOTE: return "\"";
case CharCode.u: {
if (
this.pos < this.end &&
@ -1005,8 +997,7 @@ export class Tokenizer extends DiagnosticEmitter {
}
return this.readUnicodeEscape(); // \uDDDD
}
case CharCode.CARRIAGERETURN:
case CharCode.CARRIAGERETURN: {
if (
this.pos < this.end &&
text.charCodeAt(this.pos) == CharCode.LINEFEED
@ -1014,13 +1005,11 @@ export class Tokenizer extends DiagnosticEmitter {
++this.pos;
}
// fall through
}
case CharCode.LINEFEED:
case CharCode.LINESEPARATOR:
case CharCode.PARAGRAPHSEPARATOR:
return "";
default:
return String.fromCharCode(c);
case CharCode.PARAGRAPHSEPARATOR: return "";
default: return String.fromCharCode(c);
}
}
@ -1067,22 +1056,22 @@ export class Tokenizer extends DiagnosticEmitter {
// make sure each supported flag is unique
switch (c) {
case CharCode.g:
case CharCode.g: {
flags |= flags & 1 ? -1 : 1;
break;
case CharCode.i:
}
case CharCode.i: {
flags |= flags & 2 ? -1 : 2;
break;
case CharCode.m:
}
case CharCode.m: {
flags |= flags & 4 ? -1 : 4;
break;
default:
}
default: {
flags = -1;
break;
}
}
}
if (flags == -1) {
@ -1103,8 +1092,7 @@ export class Tokenizer extends DiagnosticEmitter {
case CharCode.B:
case CharCode.b:
case CharCode.O:
case CharCode.o:
return true;
case CharCode.o: return true;
}
}
var pos = this.pos;
@ -1123,21 +1111,21 @@ export class Tokenizer extends DiagnosticEmitter {
var text = this.source.text;
if (text.charCodeAt(this.pos) == CharCode._0 && this.pos + 2 < this.end) {
switch (text.charCodeAt(this.pos + 1)) {
case CharCode.X:
case CharCode.x:
case CharCode.x: {
this.pos += 2;
return this.readHexInteger();
}
case CharCode.B:
case CharCode.b:
case CharCode.b: {
this.pos += 2;
return this.readBinaryInteger();
}
case CharCode.O:
case CharCode.o:
case CharCode.o: {
this.pos += 2;
return this.readOctalInteger();
}
}
if (isOctalDigit(text.charCodeAt(this.pos + 1))) {
var start = this.pos;
@ -1387,3 +1375,16 @@ export class Tokenizer extends DiagnosticEmitter {
finish(): void {
}
}
/** Tokenizer state as returned by {@link Tokenizer#mark} and consumed by {@link Tokenizer#reset}. */
export class State {
/** Current position. */
pos: i32;
/** Current token. */
token: Token;
/** Current token's position. */
tokenPos: i32;
}
// Reusable state object to reduce allocations
var reusableState: State | null = null;

View File

@ -1,6 +1,5 @@
import {
Class,
Function
Class
} from "./program";
import {
@ -74,7 +73,7 @@ export class Type {
/** Underlying class type, if a class type. */
classType: Class | null;
/** Underlying function type, if a function type. */
functionType: Function | null;
functionType: Signature | null;
/** Respective nullable type, if non-nullable. */
nullableType: Type | null = null;
/** Respective non-nullable type, if nullable. */
@ -97,7 +96,7 @@ export class Type {
/** Computes the truncating mask in the target type. */
computeSmallIntegerMask(targetType: Type): u32 {
return -1 >>> (targetType.size - this.size);
return ~0 >>> (targetType.size - this.size);
}
/** Tests if this type has the specified capabilities. */
@ -121,7 +120,7 @@ export class Type {
}
/** Composes a function type from this type and a function. */
asFunction(functionType: Function): Type {
asFunction(functionType: Signature): Type {
assert(this.kind == TypeKind.U32 && !this.functionType);
var ret = new Type(this.kind, this.flags & ~TypeFlags.VALUE | TypeFlags.REFERENCE, this.size);
ret.functionType = functionType;
@ -144,8 +143,8 @@ export class Type {
isAssignableTo(target: Type, signednessIsImportant: bool = false): bool {
var currentClass: Class | null;
var targetClass: Class | null;
var currentFunction: Function | null;
var targetFunction: Function | null;
var currentFunction: Signature | null;
var targetFunction: Signature | null;
if (this.isReference) {
if (target.isReference) {
if (currentClass = this.classType) {
@ -198,20 +197,25 @@ export class Type {
case TypeKind.ISIZE: return "isize";
case TypeKind.U8: return "u8";
case TypeKind.U16: return "u16";
case TypeKind.U32: return "u32";
case TypeKind.U32: {
return kindOnly || !this.functionType
? "u32"
: this.functionType.toString(true);
}
case TypeKind.U64: return "u64";
case TypeKind.USIZE:
if (kindOnly) return "usize";
return this.classType
? this.classType.toString()
: this.functionType
? this.functionType.toTypeString()
: "usize";
case TypeKind.USIZE: {
return kindOnly || !this.classType
? "usize"
: this.classType.toString();
}
case TypeKind.BOOL: return "bool";
case TypeKind.F32: return "f32";
case TypeKind.F64: return "f64";
case TypeKind.VOID: return "void";
default: assert(false); return "";
default: {
assert(false);
return "";
}
}
}
@ -220,133 +224,70 @@ export class Type {
/** Converts this type to its respective native type. */
toNativeType(): NativeType {
switch (this.kind) {
default:
return NativeType.I32;
default: return NativeType.I32;
case TypeKind.I64:
case TypeKind.U64:
return NativeType.I64;
case TypeKind.U64: return NativeType.I64;
case TypeKind.ISIZE:
case TypeKind.USIZE:
return this.size == 64 ? NativeType.I64 : NativeType.I32;
case TypeKind.F32:
return NativeType.F32;
case TypeKind.F64:
return NativeType.F64;
case TypeKind.VOID:
return NativeType.None;
case TypeKind.USIZE: return this.size == 64 ? NativeType.I64 : NativeType.I32;
case TypeKind.F32: return NativeType.F32;
case TypeKind.F64: return NativeType.F64;
case TypeKind.VOID: return NativeType.None;
}
}
/** Converts this type to its native `0` value. */
toNativeZero(module: Module): ExpressionRef {
switch (this.kind) {
case TypeKind.VOID:
assert(false);
default:
return module.createI32(0);
case TypeKind.VOID: assert(false);
default: return module.createI32(0);
case TypeKind.ISIZE:
case TypeKind.USIZE:
if (this.size != 64) return module.createI32(0);
// fall-through
case TypeKind.USIZE: if (this.size != 64) return module.createI32(0);
case TypeKind.I64:
case TypeKind.U64:
return module.createI64(0);
case TypeKind.F32:
return module.createF32(0);
case TypeKind.F64:
return module.createF64(0);
case TypeKind.U64: return module.createI64(0);
case TypeKind.F32: return module.createF32(0);
case TypeKind.F64: return module.createF64(0);
}
}
/** Converts this type to its native `1` value. */
toNativeOne(module: Module): ExpressionRef {
switch (this.kind) {
case TypeKind.VOID:
assert(false);
default:
return module.createI32(1);
case TypeKind.VOID: assert(false);
default: return module.createI32(1);
case TypeKind.ISIZE:
case TypeKind.USIZE:
if (this.size != 64) return module.createI32(1);
// fall-through
case TypeKind.USIZE: if (this.size != 64) return module.createI32(1);
case TypeKind.I64:
case TypeKind.U64:
return module.createI64(1);
case TypeKind.F32:
return module.createF32(1);
case TypeKind.F64:
return module.createF64(1);
case TypeKind.U64: return module.createI64(1);
case TypeKind.F32: return module.createF32(1);
case TypeKind.F64: return module.createF64(1);
}
}
/** Converts this type to its native `-1` value. */
toNativeNegOne(module: Module): ExpressionRef {
switch (this.kind) {
case TypeKind.VOID:
assert(false);
default:
return module.createI32(-1);
case TypeKind.VOID: assert(false);
default: return module.createI32(-1);
case TypeKind.ISIZE:
case TypeKind.USIZE:
if (this.size != 64) return module.createI32(-1);
// fall-through
case TypeKind.USIZE: if (this.size != 64) return module.createI32(-1);
case TypeKind.I64:
case TypeKind.U64:
return module.createI64(-1, -1);
case TypeKind.F32:
return module.createF32(-1);
case TypeKind.F64:
return module.createF64(-1);
case TypeKind.U64: return module.createI64(-1, -1);
case TypeKind.F32: return module.createF32(-1);
case TypeKind.F64: return module.createF64(-1);
}
}
/** Converts this type to its signature string. */
toSignatureString(): string {
switch (this.kind) {
default:
return "i";
default: return "i";
case TypeKind.I64:
case TypeKind.U64:
return "I";
case TypeKind.U64: return "I";
case TypeKind.ISIZE:
case TypeKind.USIZE:
return this.size == 64 ? "I" : "i";
case TypeKind.F32:
return "f";
case TypeKind.F64:
return "F";
case TypeKind.VOID:
return "v";
case TypeKind.USIZE: return this.size == 64 ? "I" : "i";
case TypeKind.F32: return "f";
case TypeKind.F64: return "F";
case TypeKind.VOID: return "v";
}
}
@ -495,3 +436,149 @@ export function typesToString(types: Type[]): string {
}
return sb.join(", ");
}
/** Represents a fully resolved function signature. */
export class Signature {
/** Parameter types, if any, excluding `this`. */
parameterTypes: Type[];
/** Parameter names, if known, excluding `this`. */
parameterNames: string[] | null;
/** Number of required parameters. Other parameters are considered optional. */
requiredParameters: i32;
/** Return type. */
returnType: Type;
/** This type, if an instance signature. */
thisType: Type | null;
/** Whether the last parameter is a rest parameter. */
hasRest: bool;
constructor(
parameterTypes: Type[] | null = null,
returnType: Type | null = null,
thisType: Type | null = null
) {
this.parameterTypes = parameterTypes ? parameterTypes : [];
this.parameterNames = null;
this.requiredParameters = 0;
this.returnType = returnType ? returnType : Type.void;
this.thisType = thisType;
this.hasRest = false;
}
/** Gets the known or, alternatively, generic parameter name at the specified index. */
getParameterName(index: i32): string {
return this.parameterNames && this.parameterNames.length > index
? this.parameterNames[index]
: getGenericParameterName(index);
}
/** Tests if a value of this function type is assignable to a target of the specified function type. */
isAssignableTo(target: Signature): bool {
// TODO: maybe cache results?
// check `this` type
var thisThisType = this.thisType;
var targetThisType = target.thisType;
if (thisThisType) {
if (!(targetThisType && thisThisType.isAssignableTo(targetThisType))) {
return false;
}
} else if (targetThisType) {
return false;
}
// check rest parameter
if (this.hasRest != target.hasRest) {
return false; // TODO
}
// check parameter types
var thisParameterTypes = this.parameterTypes;
var targetParameterTypes = target.parameterTypes;
var numParameters = thisParameterTypes.length;
if (numParameters != targetParameterTypes.length) {
return false;
}
for (let i = 0; i < numParameters; ++i) {
let thisParameterType = thisParameterTypes[i];
let targetParameterType = targetParameterTypes[i];
if (!thisParameterType.isAssignableTo(targetParameterType)) {
return false;
}
}
// check return type
return this.returnType.isAssignableTo(target.returnType);
}
/** Converts this signature to a function type string. */
toSignatureString(): string {
var sb = [];
var thisType = this.thisType;
if (thisType) {
sb.push(thisType.toSignatureString());
}
var parameterTypes = this.parameterTypes;
for (let i = 0, k = parameterTypes.length; i < k; ++i) {
sb.push(parameterTypes[i].toSignatureString());
}
sb.push(this.returnType.toSignatureString());
return sb.join("");
}
/** Converts this signature to a string. */
toString(includeThis: bool = false): string {
var sb = new Array<string>();
sb.push("(");
var index = 0;
var thisType = this.thisType;
if (thisType) {
if (includeThis) {
sb.push("this: ");
sb.push(thisType.toString());
index = 1;
}
}
var parameters = this.parameterTypes;
var numParameters = parameters.length;
if (numParameters) {
let names = this.parameterNames;
let numNames = names ? names.length : 0;
let optionalStart = this.requiredParameters;
let restIndex = this.hasRest ? numParameters - 1 : -1;
for (let i = 0; i < numParameters; ++i, ++index) {
if (index) sb.push(", ");
if (i == restIndex) sb.push("...");
if (i < numNames) {
sb.push((<string[]>names)[i]);
} else {
sb.push(getGenericParameterName(i));
}
if (i >= optionalStart && i != restIndex) {
sb.push("?: ");
} else {
sb.push(": ");
}
sb.push(parameters[i].toString());
}
}
sb.push(") => ");
sb.push(this.returnType.toString());
return sb.join("");
}
}
// helpers
// Cached generic parameter names used where names are unknown.
var cachedGenericParameterNames: string[] | null = null;
/** Gets the cached generic parameter name for the specified index. */
export function getGenericParameterName(index: i32): string {
if (!cachedGenericParameterNames) cachedGenericParameterNames = [];
for (var i = cachedGenericParameterNames.length; i < index; ++i) {
cachedGenericParameterNames.push("arg$" + i.toString(10));
}
return cachedGenericParameterNames[index];
}

View File

@ -139,10 +139,12 @@ export function isLineBreak(c: CharCode): bool {
case CharCode.LINEFEED:
case CharCode.CARRIAGERETURN:
case CharCode.LINESEPARATOR:
case CharCode.PARAGRAPHSEPARATOR:
case CharCode.PARAGRAPHSEPARATOR: {
return true;
default:
}
default: {
return false;
}
}
}
@ -159,10 +161,12 @@ export function isWhiteSpace(c: i32): bool {
case CharCode.NARROWNOBREAKSPACE:
case CharCode.MATHEMATICALSPACE:
case CharCode.IDEOGRAPHICSPACE:
case CharCode.BYTEORDERMARK:
case CharCode.BYTEORDERMARK: {
return true;
default:
}
default: {
return c >= CharCode.ENQUAD && c <= CharCode.ZEROWIDTHSPACE;
}
}
}

View File

@ -5,16 +5,14 @@
* sure that there are no more references to cleared memory afterwards. Always aligns to 8 bytes.
*/
const AL_BITS: usize = 3;
const AL_SIZE: usize = 1 << AL_BITS;
const AL_MASK: usize = AL_SIZE - 1;
import { MASK as AL_MASK } from "./common/alignment";
var OFFSET: usize = (HEAP_BASE + AL_MASK) & ~AL_MASK;
var offset: usize = (HEAP_BASE + AL_MASK) & ~AL_MASK;
@global
export function allocate_memory(size: usize): usize {
if (!size) return 0;
var ptr = OFFSET;
var ptr = offset;
var newPtr = (ptr + size + AL_MASK) & ~AL_MASK;
var pagesBefore = current_memory();
if (newPtr > <usize>pagesBefore << 16) {
@ -26,7 +24,7 @@ export function allocate_memory(size: usize): usize {
}
}
}
OFFSET = newPtr;
offset = newPtr;
return ptr;
}
@ -37,5 +35,5 @@ export function free_memory(ptr: usize): void {
@global
export function reset_memory(): void {
OFFSET = (HEAP_BASE + AL_MASK) & ~AL_MASK;
offset = (HEAP_BASE + AL_MASK) & ~AL_MASK;
}

View File

@ -61,7 +61,7 @@ const MIN_ALLOC: usize = 1 << MIN_ALLOC_LOG2;
* heaps will have multiple allocations, so the real maximum allocation limit
* is at most 1gb.
*/
const MAX_ALLOC_LOG2: usize = 31;
const MAX_ALLOC_LOG2: usize = 30; // 31;
const MAX_ALLOC: usize = 1 << MAX_ALLOC_LOG2;
/*
@ -338,7 +338,7 @@ function lower_bucket_limit(bucket: usize): u32 {
}
@global
function allocate_memory(request: usize): usize {
export function allocate_memory(request: usize): usize {
var original_bucket: usize, bucket: usize;
/*
@ -475,7 +475,7 @@ function allocate_memory(request: usize): usize {
}
@global
function free_memory(ptr: usize): void {
export function free_memory(ptr: usize): void {
var bucket: usize, i: usize;
/*
@ -539,3 +539,8 @@ function free_memory(ptr: usize): void {
*/
list_push(buckets$get(bucket), changetype<List>(ptr_for_node(i, bucket)));
}
@global
export function reset_memory(): void {
unreachable();
}

View File

@ -0,0 +1,8 @@
/** Number of alignment bits. */
export const BITS: u32 = 3;
/** Number of possible alignment values. */
export const SIZE: usize = 1 << <usize>BITS;
/** Mask to obtain just the alignment bits. */
export const MASK: usize = SIZE - 1;

View File

@ -20,4 +20,6 @@ export function free_memory(ptr: usize): void {
}
@global
export { reset_memory } from "./none";
export function reset_memory(): void {
unreachable();
}

View File

@ -1,15 +0,0 @@
/**
* @file Memory Allocator Stub
*/
export function allocate_memory(size: usize): usize {
throw new Error("not supported");
}
export function free_memory(ptr: usize): void {
throw new Error("not supported");
}
export function reset_memory(): void {
throw new Error("not supported");
}

View File

@ -19,4 +19,6 @@ export function free_memory(ptr: usize): void {
}
@global
export { reset_memory } from "./none";
export function reset_memory(): void {
unreachable();
}

View File

@ -13,9 +13,11 @@
// └───────────────────────────────────────────────┴─────────╨─────┘
// FL: first level, SL: second level, AL: alignment, SB: small block
const AL_BITS: u32 = 3; // always align to 8 bytes
const AL_SIZE: usize = 1 << <usize>AL_BITS;
const AL_MASK: usize = AL_SIZE - 1;
import {
BITS as AL_BITS,
SIZE as AL_SIZE,
MASK as AL_MASK
} from "./common/alignment";
const SL_BITS: u32 = 5;
const SL_SIZE: usize = 1 << <usize>SL_BITS;
@ -32,7 +34,7 @@ const FL_BITS: u32 = (sizeof<usize>() == sizeof<u32>()
// 3 2 1
// 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 bits
// ├─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┼─┼─┤
// │ size │L│F│ ◄─┐
// │ size │L│F│ ◄─┐ info
// ╞═══════════════════════════════════════════════════════════╧═╧═╡ │ ┐
// │ if free: ◄ prev │ ◄─┤ usize
// ├───────────────────────────────────────────────────────────────┤ │
@ -495,4 +497,7 @@ export function free_memory(data: usize): void {
}
}
export { reset_memory } from "./none";
@global
export function reset_memory(): void {
unreachable();
}

View File

@ -43,7 +43,7 @@ function copy_memory(dest: usize, src: usize, n: usize): void {
if (n >= 32) {
switch (dest & 3) {
// known to be != 0
case 1:
case 1: {
w = load<u32>(src);
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
@ -61,7 +61,8 @@ function copy_memory(dest: usize, src: usize, n: usize): void {
src += 16; dest += 16; n -= 16;
}
break;
case 2:
}
case 2: {
w = load<u32>(src);
store<u8>(dest++, load<u8>(src++));
store<u8>(dest++, load<u8>(src++));
@ -78,7 +79,8 @@ function copy_memory(dest: usize, src: usize, n: usize): void {
src += 16; dest += 16; n -= 16;
}
break;
case 3:
}
case 3: {
w = load<u32>(src);
store<u8>(dest++, load<u8>(src++));
n -= 1;
@ -94,6 +96,7 @@ function copy_memory(dest: usize, src: usize, n: usize): void {
src += 16; dest += 16; n -= 16;
}
break;
}
}
}

View File

@ -319,19 +319,19 @@ export class String {
function isWhiteSpaceOrLineTerminator(c: u16): bool {
switch (c) {
case 10: // <LF>
case 13: // <CR>
case 8232: // <LS>
case 8233: // <PS>
case 9: // <TAB>
case 11: // <VT>
case 12: // <FF>
case 32: // <SP>
case 160: // <NBSP>
case 65279: // <ZWNBSP>
case 10: // <LF>
case 13: // <CR>
case 8232: // <LS>
case 8233: // <PS>
case 9: // <TAB>
case 11: // <VT>
case 12: // <FF>
case 32: // <SP>
case 160: // <NBSP>
case 65279: { // <ZWNBSP>
return true;
default:
return false;
}
default: return false;
}
}
@ -405,27 +405,27 @@ function parse<T>(str: String, radix: i32 = 0): T {
if (!radix) {
if (code == CharCode._0 && len > 2) {
switch (<i32>load<u16>(ptr + 2, HEAD)) {
case CharCode.B:
case CharCode.b:
case CharCode.b: {
ptr += 4; len -= 2;
radix = 2;
break;
}
case CharCode.O:
case CharCode.o:
case CharCode.o: {
ptr += 4; len -= 2;
radix = 8;
break;
}
case CharCode.X:
case CharCode.x:
case CharCode.x: {
ptr += 4; len -= 2;
radix = 16;
break;
default:
}
default: {
radix = 10;
}
}
} else radix = 10;
} else if (radix < 2 || radix > 36) {

View File

@ -2,7 +2,7 @@
(type $ii (func (param i32) (result i32)))
(type $iv (func (param i32)))
(type $v (func))
(global "$(lib)/allocator/arena/OFFSET" (mut i32) (i32.const 0))
(global "$(lib)/allocator/arena/offset" (mut i32) (i32.const 0))
(global $HEAP_BASE i32 (i32.const 4))
(memory $0 1)
(export "allocate_memory" (func "$(lib)/allocator/arena/allocate_memory"))
@ -15,83 +15,83 @@
(local $2 i32)
(local $3 i32)
(local $4 i32)
;;@ (lib)/allocator/arena.ts:16:2
;;@ (lib)/allocator/arena.ts:14:2
(if
;;@ (lib)/allocator/arena.ts:16:6
;;@ (lib)/allocator/arena.ts:14:6
(i32.eqz
;;@ (lib)/allocator/arena.ts:16:7
;;@ (lib)/allocator/arena.ts:14:7
(get_local $0)
)
;;@ (lib)/allocator/arena.ts:16:20
;;@ (lib)/allocator/arena.ts:14:20
(return
(i32.const 0)
)
)
;;@ (lib)/allocator/arena.ts:20:2
;;@ (lib)/allocator/arena.ts:18:2
(if
;;@ (lib)/allocator/arena.ts:20:6
;;@ (lib)/allocator/arena.ts:18:6
(i32.gt_u
;;@ (lib)/allocator/arena.ts:18:2
;;@ (lib)/allocator/arena.ts:16:2
(tee_local $2
;;@ (lib)/allocator/arena.ts:18:15
;;@ (lib)/allocator/arena.ts:16:15
(i32.and
(i32.add
;;@ (lib)/allocator/arena.ts:18:16
;;@ (lib)/allocator/arena.ts:16:16
(i32.add
;;@ (lib)/allocator/arena.ts:17:2
;;@ (lib)/allocator/arena.ts:15:2
(tee_local $1
;;@ (lib)/allocator/arena.ts:17:12
(get_global "$(lib)/allocator/arena/OFFSET")
;;@ (lib)/allocator/arena.ts:15:12
(get_global "$(lib)/allocator/arena/offset")
)
;;@ (lib)/allocator/arena.ts:18:22
;;@ (lib)/allocator/arena.ts:16:22
(get_local $0)
)
;;@ (lib)/allocator/arena.ts:18:29
;;@ (lib)/allocator/arena.ts:16:29
(i32.const 7)
)
(i32.const -8)
)
)
;;@ (lib)/allocator/arena.ts:20:15
;;@ (lib)/allocator/arena.ts:18:15
(i32.shl
;;@ (lib)/allocator/arena.ts:19:2
;;@ (lib)/allocator/arena.ts:17:2
(tee_local $0
;;@ (lib)/allocator/arena.ts:19:20
;;@ (lib)/allocator/arena.ts:17:20
(current_memory)
)
;;@ (lib)/allocator/arena.ts:20:37
;;@ (lib)/allocator/arena.ts:18:37
(i32.const 16)
)
)
;;@ (lib)/allocator/arena.ts:23:4
;;@ (lib)/allocator/arena.ts:21:4
(if
;;@ (lib)/allocator/arena.ts:23:8
;;@ (lib)/allocator/arena.ts:21:8
(i32.lt_s
(grow_memory
;;@ (lib)/allocator/arena.ts:22:22
;;@ (lib)/allocator/arena.ts:20:22
(select
;;@ (lib)/allocator/arena.ts:22:26
;;@ (lib)/allocator/arena.ts:20:26
(get_local $0)
(tee_local $4
;;@ (lib)/allocator/arena.ts:21:4
;;@ (lib)/allocator/arena.ts:19:4
(tee_local $3
;;@ (lib)/allocator/arena.ts:21:22
;;@ (lib)/allocator/arena.ts:19:22
(i32.shr_u
(i32.and
;;@ (lib)/allocator/arena.ts:21:23
;;@ (lib)/allocator/arena.ts:19:23
(i32.add
;;@ (lib)/allocator/arena.ts:21:24
;;@ (lib)/allocator/arena.ts:19:24
(i32.sub
(get_local $2)
;;@ (lib)/allocator/arena.ts:21:33
;;@ (lib)/allocator/arena.ts:19:33
(get_local $1)
)
;;@ (lib)/allocator/arena.ts:21:39
;;@ (lib)/allocator/arena.ts:19:39
(i32.const 65535)
)
(i32.const -65536)
)
;;@ (lib)/allocator/arena.ts:21:62
;;@ (lib)/allocator/arena.ts:19:62
(i32.const 16)
)
)
@ -102,46 +102,46 @@
)
)
)
;;@ (lib)/allocator/arena.ts:23:35
;;@ (lib)/allocator/arena.ts:21:35
(i32.const 0)
)
;;@ (lib)/allocator/arena.ts:24:6
;;@ (lib)/allocator/arena.ts:22:6
(if
;;@ (lib)/allocator/arena.ts:24:10
;;@ (lib)/allocator/arena.ts:22:10
(i32.lt_s
(grow_memory
;;@ (lib)/allocator/arena.ts:24:22
;;@ (lib)/allocator/arena.ts:22:22
(get_local $3)
)
;;@ (lib)/allocator/arena.ts:24:37
;;@ (lib)/allocator/arena.ts:22:37
(i32.const 0)
)
;;@ (lib)/allocator/arena.ts:25:8
;;@ (lib)/allocator/arena.ts:23:8
(unreachable)
)
)
)
;;@ (lib)/allocator/arena.ts:29:2
(set_global "$(lib)/allocator/arena/OFFSET"
;;@ (lib)/allocator/arena.ts:29:11
;;@ (lib)/allocator/arena.ts:27:2
(set_global "$(lib)/allocator/arena/offset"
;;@ (lib)/allocator/arena.ts:27:11
(get_local $2)
)
;;@ (lib)/allocator/arena.ts:30:9
;;@ (lib)/allocator/arena.ts:28:9
(get_local $1)
)
(func "$(lib)/allocator/arena/free_memory" (; 1 ;) (type $iv) (param $0 i32)
;;@ (lib)/allocator/arena.ts:34:46
;;@ (lib)/allocator/arena.ts:32:46
(nop)
)
(func "$(lib)/allocator/arena/reset_memory" (; 2 ;) (type $v)
;;@ (lib)/allocator/arena.ts:40:2
(set_global "$(lib)/allocator/arena/OFFSET"
;;@ (lib)/allocator/arena.ts:40:11
;;@ (lib)/allocator/arena.ts:38:2
(set_global "$(lib)/allocator/arena/offset"
;;@ (lib)/allocator/arena.ts:38:11
(i32.and
(i32.add
;;@ (lib)/allocator/arena.ts:40:12
;;@ (lib)/allocator/arena.ts:38:12
(get_global $HEAP_BASE)
;;@ (lib)/allocator/arena.ts:40:24
;;@ (lib)/allocator/arena.ts:38:24
(i32.const 7)
)
(i32.const -8)

View File

@ -3,10 +3,10 @@
(type $ii (func (param i32) (result i32)))
(type $iv (func (param i32)))
(type $v (func))
(global "$(lib)/allocator/arena/AL_BITS" i32 (i32.const 3))
(global "$(lib)/allocator/arena/AL_SIZE" i32 (i32.const 8))
(global "$(lib)/allocator/arena/AL_MASK" i32 (i32.const 7))
(global "$(lib)/allocator/arena/OFFSET" (mut i32) (i32.const 0))
(global "$(lib)/allocator/common/alignment/BITS" i32 (i32.const 3))
(global "$(lib)/allocator/common/alignment/SIZE" i32 (i32.const 8))
(global "$(lib)/allocator/common/alignment/MASK" i32 (i32.const 7))
(global "$(lib)/allocator/arena/offset" (mut i32) (i32.const 0))
(global $HEAP_BASE i32 (i32.const 4))
(memory $0 1)
(export "allocate_memory" (func "$(lib)/allocator/arena/allocate_memory"))
@ -22,101 +22,101 @@
(local $5 i32)
(local $6 i32)
(local $7 i32)
;;@ (lib)/allocator/arena.ts:16:2
;;@ (lib)/allocator/arena.ts:14:2
(if
;;@ (lib)/allocator/arena.ts:16:6
;;@ (lib)/allocator/arena.ts:14:6
(i32.eqz
;;@ (lib)/allocator/arena.ts:16:7
;;@ (lib)/allocator/arena.ts:14:7
(get_local $0)
)
;;@ (lib)/allocator/arena.ts:16:20
;;@ (lib)/allocator/arena.ts:14:20
(return
(i32.const 0)
)
)
;;@ (lib)/allocator/arena.ts:17:2
;;@ (lib)/allocator/arena.ts:15:2
(set_local $1
;;@ (lib)/allocator/arena.ts:17:12
(get_global "$(lib)/allocator/arena/OFFSET")
;;@ (lib)/allocator/arena.ts:15:12
(get_global "$(lib)/allocator/arena/offset")
)
;;@ (lib)/allocator/arena.ts:18:2
;;@ (lib)/allocator/arena.ts:16:2
(set_local $2
;;@ (lib)/allocator/arena.ts:18:15
;;@ (lib)/allocator/arena.ts:16:15
(i32.and
(i32.add
;;@ (lib)/allocator/arena.ts:18:16
;;@ (lib)/allocator/arena.ts:16:16
(i32.add
(get_local $1)
;;@ (lib)/allocator/arena.ts:18:22
;;@ (lib)/allocator/arena.ts:16:22
(get_local $0)
)
;;@ (lib)/allocator/arena.ts:18:29
;;@ (lib)/allocator/arena.ts:16:29
(i32.const 7)
)
;;@ (lib)/allocator/arena.ts:18:40
;;@ (lib)/allocator/arena.ts:16:40
(i32.xor
;;@ (lib)/allocator/arena.ts:18:41
;;@ (lib)/allocator/arena.ts:16:41
(i32.const 7)
(i32.const -1)
)
)
)
;;@ (lib)/allocator/arena.ts:19:2
;;@ (lib)/allocator/arena.ts:17:2
(set_local $3
;;@ (lib)/allocator/arena.ts:19:20
;;@ (lib)/allocator/arena.ts:17:20
(current_memory)
)
;;@ (lib)/allocator/arena.ts:20:2
;;@ (lib)/allocator/arena.ts:18:2
(if
;;@ (lib)/allocator/arena.ts:20:6
;;@ (lib)/allocator/arena.ts:18:6
(i32.gt_u
(get_local $2)
;;@ (lib)/allocator/arena.ts:20:15
;;@ (lib)/allocator/arena.ts:18:15
(i32.shl
(get_local $3)
;;@ (lib)/allocator/arena.ts:20:37
;;@ (lib)/allocator/arena.ts:18:37
(i32.const 16)
)
)
;;@ (lib)/allocator/arena.ts:20:41
;;@ (lib)/allocator/arena.ts:18:41
(block
;;@ (lib)/allocator/arena.ts:21:4
;;@ (lib)/allocator/arena.ts:19:4
(set_local $4
;;@ (lib)/allocator/arena.ts:21:22
;;@ (lib)/allocator/arena.ts:19:22
(i32.shr_u
(i32.and
;;@ (lib)/allocator/arena.ts:21:23
;;@ (lib)/allocator/arena.ts:19:23
(i32.add
;;@ (lib)/allocator/arena.ts:21:24
;;@ (lib)/allocator/arena.ts:19:24
(i32.sub
(get_local $2)
;;@ (lib)/allocator/arena.ts:21:33
;;@ (lib)/allocator/arena.ts:19:33
(get_local $1)
)
;;@ (lib)/allocator/arena.ts:21:39
;;@ (lib)/allocator/arena.ts:19:39
(i32.const 65535)
)
;;@ (lib)/allocator/arena.ts:21:49
;;@ (lib)/allocator/arena.ts:19:49
(i32.xor
;;@ (lib)/allocator/arena.ts:21:50
;;@ (lib)/allocator/arena.ts:19:50
(i32.const 65535)
(i32.const -1)
)
)
;;@ (lib)/allocator/arena.ts:21:62
;;@ (lib)/allocator/arena.ts:19:62
(i32.const 16)
)
)
;;@ (lib)/allocator/arena.ts:22:4
;;@ (lib)/allocator/arena.ts:20:4
(set_local $7
;;@ (lib)/allocator/arena.ts:22:22
;;@ (lib)/allocator/arena.ts:20:22
(select
(tee_local $5
;;@ (lib)/allocator/arena.ts:22:26
;;@ (lib)/allocator/arena.ts:20:26
(get_local $3)
)
(tee_local $6
;;@ (lib)/allocator/arena.ts:22:39
;;@ (lib)/allocator/arena.ts:20:39
(get_local $4)
)
(i32.gt_s
@ -125,40 +125,40 @@
)
)
)
;;@ (lib)/allocator/arena.ts:23:4
;;@ (lib)/allocator/arena.ts:21:4
(if
;;@ (lib)/allocator/arena.ts:23:8
;;@ (lib)/allocator/arena.ts:21:8
(i32.lt_s
(grow_memory
;;@ (lib)/allocator/arena.ts:23:20
;;@ (lib)/allocator/arena.ts:21:20
(get_local $7)
)
;;@ (lib)/allocator/arena.ts:23:35
;;@ (lib)/allocator/arena.ts:21:35
(i32.const 0)
)
;;@ (lib)/allocator/arena.ts:24:6
;;@ (lib)/allocator/arena.ts:22:6
(if
;;@ (lib)/allocator/arena.ts:24:10
;;@ (lib)/allocator/arena.ts:22:10
(i32.lt_s
(grow_memory
;;@ (lib)/allocator/arena.ts:24:22
;;@ (lib)/allocator/arena.ts:22:22
(get_local $4)
)
;;@ (lib)/allocator/arena.ts:24:37
;;@ (lib)/allocator/arena.ts:22:37
(i32.const 0)
)
;;@ (lib)/allocator/arena.ts:25:8
;;@ (lib)/allocator/arena.ts:23:8
(unreachable)
)
)
)
)
;;@ (lib)/allocator/arena.ts:29:2
(set_global "$(lib)/allocator/arena/OFFSET"
;;@ (lib)/allocator/arena.ts:29:11
;;@ (lib)/allocator/arena.ts:27:2
(set_global "$(lib)/allocator/arena/offset"
;;@ (lib)/allocator/arena.ts:27:11
(get_local $2)
)
;;@ (lib)/allocator/arena.ts:30:9
;;@ (lib)/allocator/arena.ts:28:9
(return
(get_local $1)
)
@ -166,19 +166,19 @@
(func "$(lib)/allocator/arena/free_memory" (; 1 ;) (type $iv) (param $0 i32)
)
(func "$(lib)/allocator/arena/reset_memory" (; 2 ;) (type $v)
;;@ (lib)/allocator/arena.ts:40:2
(set_global "$(lib)/allocator/arena/OFFSET"
;;@ (lib)/allocator/arena.ts:40:11
;;@ (lib)/allocator/arena.ts:38:2
(set_global "$(lib)/allocator/arena/offset"
;;@ (lib)/allocator/arena.ts:38:11
(i32.and
(i32.add
;;@ (lib)/allocator/arena.ts:40:12
;;@ (lib)/allocator/arena.ts:38:12
(get_global $HEAP_BASE)
;;@ (lib)/allocator/arena.ts:40:24
;;@ (lib)/allocator/arena.ts:38:24
(i32.const 7)
)
;;@ (lib)/allocator/arena.ts:40:35
;;@ (lib)/allocator/arena.ts:38:35
(i32.xor
;;@ (lib)/allocator/arena.ts:40:36
;;@ (lib)/allocator/arena.ts:38:36
(i32.const 7)
(i32.const -1)
)
@ -186,18 +186,18 @@
)
)
(func $start (; 3 ;) (type $v)
(set_global "$(lib)/allocator/arena/OFFSET"
;;@ (lib)/allocator/arena.ts:12:20
(set_global "$(lib)/allocator/arena/offset"
;;@ (lib)/allocator/arena.ts:10:20
(i32.and
(i32.add
;;@ (lib)/allocator/arena.ts:12:21
;;@ (lib)/allocator/arena.ts:10:21
(get_global $HEAP_BASE)
;;@ (lib)/allocator/arena.ts:12:33
;;@ (lib)/allocator/arena.ts:10:33
(i32.const 7)
)
;;@ (lib)/allocator/arena.ts:12:44
;;@ (lib)/allocator/arena.ts:10:44
(i32.xor
;;@ (lib)/allocator/arena.ts:12:45
;;@ (lib)/allocator/arena.ts:10:45
(i32.const 7)
(i32.const -1)
)

View File

@ -146,7 +146,7 @@
;;@ (lib)/allocator/buddy.ts:278:2
(set_local $1
;;@ (lib)/allocator/buddy.ts:278:15
(i32.const 27)
(i32.const 26)
)
;;@ (lib)/allocator/buddy.ts:279:2
(set_local $2
@ -199,7 +199,7 @@
;;@ (lib)/allocator/buddy.ts:251:30
(i32.sub
;;@ (lib)/allocator/buddy.ts:251:31
(i32.const 31)
(i32.const 30)
;;@ (lib)/allocator/buddy.ts:251:48
(get_local $1)
)
@ -316,7 +316,7 @@
;;@ (lib)/allocator/buddy.ts:242:52
(i32.sub
;;@ (lib)/allocator/buddy.ts:242:53
(i32.const 31)
(i32.const 30)
;;@ (lib)/allocator/buddy.ts:242:70
(get_local $1)
)
@ -579,7 +579,7 @@
(i32.const 8)
)
;;@ (lib)/allocator/buddy.ts:349:30
(i32.const -2147483648)
(i32.const 1073741824)
)
;;@ (lib)/allocator/buddy.ts:350:11
(return
@ -619,7 +619,7 @@
;;@ (lib)/allocator/buddy.ts:362:4
(set_global "$(lib)/allocator/buddy/bucket_limit"
;;@ (lib)/allocator/buddy.ts:362:19
(i32.const 27)
(i32.const 26)
)
;;@ (lib)/allocator/buddy.ts:363:4
(if
@ -645,7 +645,7 @@
;;@ (lib)/allocator/buddy.ts:366:14
(call "$(lib)/allocator/buddy/buckets$get"
;;@ (lib)/allocator/buddy.ts:366:26
(i32.const 27)
(i32.const 26)
)
)
;;@ (lib)/allocator/buddy.ts:367:4
@ -653,7 +653,7 @@
;;@ (lib)/allocator/buddy.ts:367:14
(call "$(lib)/allocator/buddy/buckets$get"
;;@ (lib)/allocator/buddy.ts:367:26
(i32.const 27)
(i32.const 26)
)
;;@ (lib)/allocator/buddy.ts:367:45
(get_global "$(lib)/allocator/buddy/base_ptr")
@ -791,7 +791,7 @@
;;@ (lib)/allocator/buddy.ts:426:16
(i32.sub
;;@ (lib)/allocator/buddy.ts:426:17
(i32.const 31)
(i32.const 30)
;;@ (lib)/allocator/buddy.ts:426:34
(get_local $1)
)
@ -1091,7 +1091,7 @@
;;@ (lib)/allocator/buddy.ts:97:25
(i32.add
(get_global "$(lib)/allocator/buddy/BUCKETS_START")
(i32.const 224)
(i32.const 216)
)
)
(set_global "$(lib)/allocator/buddy/NODE_IS_SPLIT_START"
@ -1103,7 +1103,7 @@
(i32.add
(get_global "$(lib)/allocator/buddy/NODE_IS_SPLIT_START")
;;@ (lib)/allocator/buddy.ts:143:53
(i32.const 16777216)
(i32.const 8388608)
)
)
)

View File

@ -10,13 +10,13 @@
(global "$(lib)/allocator/buddy/HEADER_SIZE" i32 (i32.const 8))
(global "$(lib)/allocator/buddy/MIN_ALLOC_LOG2" i32 (i32.const 4))
(global "$(lib)/allocator/buddy/MIN_ALLOC" i32 (i32.const 16))
(global "$(lib)/allocator/buddy/MAX_ALLOC_LOG2" i32 (i32.const 31))
(global "$(lib)/allocator/buddy/MAX_ALLOC" i32 (i32.const -2147483648))
(global "$(lib)/allocator/buddy/BUCKET_COUNT" i32 (i32.const 28))
(global "$(lib)/allocator/buddy/MAX_ALLOC_LOG2" i32 (i32.const 30))
(global "$(lib)/allocator/buddy/MAX_ALLOC" i32 (i32.const 1073741824))
(global "$(lib)/allocator/buddy/BUCKET_COUNT" i32 (i32.const 27))
(global "$(lib)/allocator/buddy/BUCKETS_START" (mut i32) (i32.const 0))
(global "$(lib)/allocator/buddy/BUCKETS_END" (mut i32) (i32.const 0))
(global "$(lib)/allocator/buddy/bucket_limit" (mut i32) (i32.const 0))
(global "$(lib)/allocator/buddy/SPLIT_COUNT" i32 (i32.const 16777216))
(global "$(lib)/allocator/buddy/SPLIT_COUNT" i32 (i32.const 8388608))
(global "$(lib)/allocator/buddy/NODE_IS_SPLIT_START" (mut i32) (i32.const 0))
(global "$(lib)/allocator/buddy/NODE_IS_SPLIT_END" (mut i32) (i32.const 0))
(global "$(lib)/allocator/buddy/base_ptr" (mut i32) (i32.const 0))
@ -134,7 +134,7 @@
(i32.lt_u
(get_local $0)
;;@ (lib)/allocator/buddy.ts:100:17
(i32.const 28)
(i32.const 27)
)
)
(block
@ -217,7 +217,7 @@
(set_local $1
;;@ (lib)/allocator/buddy.ts:278:15
(i32.sub
(i32.const 28)
(i32.const 27)
;;@ (lib)/allocator/buddy.ts:278:30
(i32.const 1)
)
@ -282,7 +282,7 @@
;;@ (lib)/allocator/buddy.ts:251:30
(i32.sub
;;@ (lib)/allocator/buddy.ts:251:31
(i32.const 31)
(i32.const 30)
;;@ (lib)/allocator/buddy.ts:251:48
(get_local $1)
)
@ -308,7 +308,7 @@
(i32.lt_u
(get_local $0)
;;@ (lib)/allocator/buddy.ts:146:17
(i32.const 16777216)
(i32.const 8388608)
)
)
(block
@ -433,7 +433,7 @@
;;@ (lib)/allocator/buddy.ts:242:52
(i32.sub
;;@ (lib)/allocator/buddy.ts:242:53
(i32.const 31)
(i32.const 30)
;;@ (lib)/allocator/buddy.ts:242:70
(get_local $1)
)
@ -449,7 +449,7 @@
(i32.lt_u
(get_local $0)
;;@ (lib)/allocator/buddy.ts:151:17
(i32.const 16777216)
(i32.const 8388608)
)
)
(block
@ -750,7 +750,7 @@
(i32.const 8)
)
;;@ (lib)/allocator/buddy.ts:349:30
(i32.const -2147483648)
(i32.const 1073741824)
)
;;@ (lib)/allocator/buddy.ts:350:11
(return
@ -798,7 +798,7 @@
(set_global "$(lib)/allocator/buddy/bucket_limit"
;;@ (lib)/allocator/buddy.ts:362:19
(i32.sub
(i32.const 28)
(i32.const 27)
;;@ (lib)/allocator/buddy.ts:362:34
(i32.const 1)
)
@ -828,7 +828,7 @@
(call "$(lib)/allocator/buddy/buckets$get"
;;@ (lib)/allocator/buddy.ts:366:26
(i32.sub
(i32.const 28)
(i32.const 27)
;;@ (lib)/allocator/buddy.ts:366:41
(i32.const 1)
)
@ -840,7 +840,7 @@
(call "$(lib)/allocator/buddy/buckets$get"
;;@ (lib)/allocator/buddy.ts:367:26
(i32.sub
(i32.const 28)
(i32.const 27)
;;@ (lib)/allocator/buddy.ts:367:41
(i32.const 1)
)
@ -997,7 +997,7 @@
;;@ (lib)/allocator/buddy.ts:426:16
(i32.sub
;;@ (lib)/allocator/buddy.ts:426:17
(i32.const 31)
(i32.const 30)
;;@ (lib)/allocator/buddy.ts:426:34
(get_local $2)
)
@ -1337,7 +1337,7 @@
(get_global "$(lib)/allocator/buddy/BUCKETS_START")
;;@ (lib)/allocator/buddy.ts:97:41
(i32.mul
(i32.const 28)
(i32.const 27)
;;@ (lib)/allocator/buddy.ts:97:56
(i32.const 8)
)
@ -1353,7 +1353,7 @@
(get_global "$(lib)/allocator/buddy/NODE_IS_SPLIT_START")
;;@ (lib)/allocator/buddy.ts:143:53
(i32.mul
(i32.const 16777216)
(i32.const 8388608)
;;@ (lib)/allocator/buddy.ts:143:67
(i32.const 1)
)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,103 @@
(module
(type $iiii (func (param i32 i32 i32) (result i32)))
(type $iiiii (func (param i32 i32 i32 i32) (result i32)))
(type $iiiiv (func (param i32 i32 i32 i32)))
(type $v (func))
(import "env" "abort" (func $abort (param i32 i32 i32 i32)))
(memory $0 1)
(data (i32.const 4) "\10\00\00\00c\00a\00l\00l\00-\00o\00p\00t\00i\00o\00n\00a\00l\00.\00t\00s")
(export "memory" (memory $0))
(start $start)
(func $call-optional/opt (; 1 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(i32.add
(i32.add
(get_local $0)
(get_local $1)
)
(get_local $2)
)
)
(func $call-optional/opt|trampoline (; 2 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32)
(block $N=2
(block $N=1
(block $N=0
(block $N=invalid
(br_table $N=0 $N=1 $N=2 $N=invalid
(get_local $3)
)
)
(unreachable)
)
(set_local $1
(i32.const -1)
)
)
(set_local $2
(i32.const -2)
)
)
(call $call-optional/opt
(get_local $0)
(get_local $1)
(get_local $2)
)
)
(func $start (; 3 ;) (type $v)
(if
(call $call-optional/opt|trampoline
(i32.const 3)
(i32.const 0)
(i32.const 0)
(i32.const 0)
)
(block
(call $abort
(i32.const 0)
(i32.const 4)
(i32.const 4)
(i32.const 0)
)
(unreachable)
)
)
(if
(i32.ne
(call $call-optional/opt|trampoline
(i32.const 3)
(i32.const 4)
(i32.const 0)
(i32.const 1)
)
(i32.const 5)
)
(block
(call $abort
(i32.const 0)
(i32.const 4)
(i32.const 5)
(i32.const 0)
)
(unreachable)
)
)
(if
(i32.ne
(call $call-optional/opt
(i32.const 3)
(i32.const 4)
(i32.const 5)
)
(i32.const 12)
)
(block
(call $abort
(i32.const 0)
(i32.const 4)
(i32.const 6)
(i32.const 0)
)
(unreachable)
)
)
)
)

View File

@ -0,0 +1,6 @@
function opt(a: i32, b: i32 = -1, c: i32 = -2): i32 {
return a + b + c;
}
assert(opt(3) == 0); // calls the trampoline with N=0
assert(opt(3, 4) == 5); // calls the trampoline with N=1
assert(opt(3, 4, 5) == 12); // calls the function directly

View File

@ -0,0 +1,115 @@
(module
(type $iiii (func (param i32 i32 i32) (result i32)))
(type $iiiii (func (param i32 i32 i32 i32) (result i32)))
(type $iiiiv (func (param i32 i32 i32 i32)))
(type $v (func))
(import "env" "abort" (func $abort (param i32 i32 i32 i32)))
(global $HEAP_BASE i32 (i32.const 40))
(memory $0 1)
(data (i32.const 4) "\10\00\00\00c\00a\00l\00l\00-\00o\00p\00t\00i\00o\00n\00a\00l\00.\00t\00s\00")
(export "memory" (memory $0))
(start $start)
(func $call-optional/opt (; 1 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(return
(i32.add
(i32.add
(get_local $0)
(get_local $1)
)
(get_local $2)
)
)
)
(func $call-optional/opt|trampoline (; 2 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32)
(block $N=2
(block $N=1
(block $N=0
(block $N=invalid
(br_table $N=0 $N=1 $N=2 $N=invalid
(get_local $3)
)
)
(unreachable)
)
(set_local $1
(i32.const -1)
)
)
(set_local $2
(i32.const -2)
)
)
(call $call-optional/opt
(get_local $0)
(get_local $1)
(get_local $2)
)
)
(func $start (; 3 ;) (type $v)
(if
(i32.eqz
(i32.eq
(call $call-optional/opt|trampoline
(i32.const 3)
(i32.const 0)
(i32.const 0)
(i32.const 0)
)
(i32.const 0)
)
)
(block
(call $abort
(i32.const 0)
(i32.const 4)
(i32.const 4)
(i32.const 0)
)
(unreachable)
)
)
(if
(i32.eqz
(i32.eq
(call $call-optional/opt|trampoline
(i32.const 3)
(i32.const 4)
(i32.const 0)
(i32.const 1)
)
(i32.const 5)
)
)
(block
(call $abort
(i32.const 0)
(i32.const 4)
(i32.const 5)
(i32.const 0)
)
(unreachable)
)
)
(if
(i32.eqz
(i32.eq
(call $call-optional/opt
(i32.const 3)
(i32.const 4)
(i32.const 5)
)
(i32.const 12)
)
)
(block
(call $abort
(i32.const 0)
(i32.const 4)
(i32.const 6)
(i32.const 0)
)
(unreachable)
)
)
)
)

View File

@ -1,9 +1,9 @@
(module
(type $iii (func (param i32 i32) (result i32)))
(type $fff (func (param f32 f32) (result f32)))
(type $ii (func (param i32) (result i32)))
(type $iiii (func (param i32 i32 i32) (result i32)))
(type $ifff (func (param i32 f32 f32) (result f32)))
(type $ii (func (param i32) (result i32)))
(type $v (func))
(global $class/Animal.ONE (mut i32) (i32.const 1))
(memory $0 1)

View File

@ -2,9 +2,9 @@
(type $iiiiv (func (param i32 i32 i32 i32)))
(type $iii (func (param i32 i32) (result i32)))
(type $fff (func (param f32 f32) (result f32)))
(type $ii (func (param i32) (result i32)))
(type $iiii (func (param i32 i32 i32) (result i32)))
(type $ifff (func (param i32 f32 f32) (result f32)))
(type $ii (func (param i32) (result i32)))
(type $v (func))
(import "env" "abort" (func $abort (param i32 i32 i32 i32)))
(global $class/Animal.ONE (mut i32) (i32.const 1))

View File

@ -1,28 +1,188 @@
(module
(type $ii (func (param i32) (result i32)))
(type $iiiiv (func (param i32 i32 i32 i32)))
(type $v (func))
(table 3 3 anyfunc)
(elem (i32.const 0) $start~anonymous|0 $start~anonymous|0 $start~someName|2)
(type $i (func (result i32)))
(type $iii (func (param i32 i32) (result i32)))
(type $fff (func (param f32 f32) (result f32)))
(import "env" "abort" (func $abort (param i32 i32 i32 i32)))
(global $function-expression/f1 (mut i32) (i32.const 0))
(global $function-expression/f2 (mut i32) (i32.const 1))
(global $function-expression/f3 (mut i32) (i32.const 2))
(global $function-expression/i32Adder (mut i32) (i32.const 0))
(global $function-expression/f32Adder (mut i32) (i32.const 0))
(global $function-expression/i8Adder (mut i32) (i32.const 0))
(table 6 6 anyfunc)
(elem (i32.const 0) $start~anonymous|0 $start~anonymous|0 $start~someName|2 $function-expression/makeAdder<i32>~theAdder|3 $function-expression/makeAdder<f32>~theAdder|4 $function-expression/makeAdderArrow<i8>~anonymous|5)
(memory $0 1)
(data (i32.const 4) "\16\00\00\00f\00u\00n\00c\00t\00i\00o\00n\00-\00e\00x\00p\00r\00e\00s\00s\00i\00o\00n\00.\00t\00s")
(export "memory" (memory $0))
(start $start)
(func $start~anonymous|0 (; 0 ;) (type $ii) (param $0 i32) (result i32)
(func $start~anonymous|0 (; 1 ;) (type $ii) (param $0 i32) (result i32)
(get_local $0)
)
(func $start~someName|2 (; 1 ;) (type $v)
(func $start~someName|2 (; 2 ;) (type $v)
(nop)
)
(func $start (; 2 ;) (type $v)
(drop
(call $start~anonymous|0
(func $function-expression/makeAdder<i32>~theAdder|3 (; 3 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(i32.add
(get_local $0)
(get_local $1)
)
)
(func $function-expression/makeAdder<i32> (; 4 ;) (type $i) (result i32)
(i32.const 3)
)
(func $function-expression/makeAdder<f32>~theAdder|4 (; 5 ;) (type $fff) (param $0 f32) (param $1 f32) (result f32)
(f32.add
(get_local $0)
(get_local $1)
)
)
(func $function-expression/makeAdder<f32> (; 6 ;) (type $i) (result i32)
(i32.const 4)
)
(func $function-expression/makeAdderArrow<i8>~anonymous|5 (; 7 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(i32.shr_s
(i32.shl
(i32.add
(get_local $0)
(get_local $1)
)
(i32.const 24)
)
(i32.const 24)
)
)
(func $function-expression/makeAdderArrow<i8> (; 8 ;) (type $i) (result i32)
(i32.const 5)
)
(func $start (; 9 ;) (type $v)
(if
(i32.ne
(call_indirect (type $ii)
(i32.const 1)
(get_global $function-expression/f1)
)
(i32.const 1)
)
)
(drop
(call $start~anonymous|0
(i32.const 2)
(block
(call $abort
(i32.const 0)
(i32.const 4)
(i32.const 4)
(i32.const 0)
)
(unreachable)
)
)
(if
(i32.ne
(call_indirect (type $ii)
(i32.const 2)
(get_global $function-expression/f2)
)
(i32.const 2)
)
(block
(call $abort
(i32.const 0)
(i32.const 4)
(i32.const 9)
(i32.const 0)
)
(unreachable)
)
)
(call_indirect (type $v)
(get_global $function-expression/f3)
)
(set_global $function-expression/i32Adder
(call $function-expression/makeAdder<i32>)
)
(if
(i32.ne
(call_indirect (type $iii)
(i32.const 4)
(i32.const 2)
(get_global $function-expression/i32Adder)
)
(i32.const 6)
)
(block
(call $abort
(i32.const 0)
(i32.const 4)
(i32.const 22)
(i32.const 0)
)
(unreachable)
)
)
(set_global $function-expression/f32Adder
(call $function-expression/makeAdder<f32>)
)
(if
(f32.ne
(call_indirect (type $fff)
(f32.const 1.5)
(f32.const 2.5)
(get_global $function-expression/f32Adder)
)
(f32.const 4)
)
(block
(call $abort
(i32.const 0)
(i32.const 4)
(i32.const 25)
(i32.const 0)
)
(unreachable)
)
)
(set_global $function-expression/i8Adder
(call $function-expression/makeAdderArrow<i8>)
)
(if
(i32.ne
(call_indirect (type $iii)
(i32.const 127)
(i32.const 127)
(get_global $function-expression/i8Adder)
)
(i32.const -2)
)
(block
(call $abort
(i32.const 0)
(i32.const 4)
(i32.const 34)
(i32.const 0)
)
(unreachable)
)
)
(set_global $function-expression/f1
(get_global $function-expression/f2)
)
(if
(i32.ne
(call_indirect (type $ii)
(i32.const 4)
(get_global $function-expression/f1)
)
(i32.const 4)
)
(block
(call $abort
(i32.const 0)
(i32.const 4)
(i32.const 37)
(i32.const 0)
)
(unreachable)
)
)
(call $start~someName|2)
)
)

View File

@ -1,11 +1,37 @@
var f1 = function(a: i32): i32 {
return a;
};
f1(1);
assert(f1(1) == 1);
var f2 = (a: i32): i32 => {
return a;
};
f2(2);
assert(f2(2) == 2);
var f3 = function someName(): void {
};
f3();
function makeAdder<T>(): (a: T, b: T) => T {
return function theAdder(a: T, b: T): T {
return a + b;
};
}
var i32Adder = makeAdder<i32>();
assert(i32Adder(4, 2) == 6);
var f32Adder = makeAdder<f32>();
assert(f32Adder(1.5, 2.5) == 4.0);
function makeAdderArrow<T>(): (a: T, b: T) => T {
return (a: T, b: T): T => {
return a + b;
};
}
var i8Adder = makeAdderArrow<i8>();
assert(i8Adder(127, 127) == -2);
f1 = f2;
assert(f1(4) == 4);

View File

@ -1,38 +1,219 @@
(module
(type $ii (func (param i32) (result i32)))
(type $iiiiv (func (param i32 i32 i32 i32)))
(type $v (func))
(type $i (func (result i32)))
(type $iii (func (param i32 i32) (result i32)))
(type $fff (func (param f32 f32) (result f32)))
(import "env" "abort" (func $abort (param i32 i32 i32 i32)))
(global $function-expression/f1 (mut i32) (i32.const 0))
(global $function-expression/f2 (mut i32) (i32.const 1))
(global $function-expression/f3 (mut i32) (i32.const 2))
(global $HEAP_BASE i32 (i32.const 4))
(table 3 3 anyfunc)
(elem (i32.const 0) $start~anonymous|0 $start~anonymous|1 $start~someName|2)
(global $function-expression/i32Adder (mut i32) (i32.const 0))
(global $function-expression/f32Adder (mut i32) (i32.const 0))
(global $function-expression/i8Adder (mut i32) (i32.const 0))
(global $HEAP_BASE i32 (i32.const 52))
(table 6 6 anyfunc)
(elem (i32.const 0) $start~anonymous|0 $start~anonymous|1 $start~someName|2 $function-expression/makeAdder<i32>~theAdder|3 $function-expression/makeAdder<f32>~theAdder|4 $function-expression/makeAdderArrow<i8>~anonymous|5)
(memory $0 1)
(data (i32.const 4) "\16\00\00\00f\00u\00n\00c\00t\00i\00o\00n\00-\00e\00x\00p\00r\00e\00s\00s\00i\00o\00n\00.\00t\00s\00")
(export "memory" (memory $0))
(start $start)
(func $start~anonymous|0 (; 0 ;) (type $ii) (param $0 i32) (result i32)
(func $start~anonymous|0 (; 1 ;) (type $ii) (param $0 i32) (result i32)
(return
(get_local $0)
)
)
(func $start~anonymous|1 (; 1 ;) (type $ii) (param $0 i32) (result i32)
(func $start~anonymous|1 (; 2 ;) (type $ii) (param $0 i32) (result i32)
(return
(get_local $0)
)
)
(func $start~someName|2 (; 2 ;) (type $v)
(func $start~someName|2 (; 3 ;) (type $v)
)
(func $start (; 3 ;) (type $v)
(drop
(call $start~anonymous|0
(i32.const 1)
(func $function-expression/makeAdder<i32>~theAdder|3 (; 4 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(return
(i32.add
(get_local $0)
(get_local $1)
)
)
(drop
(call $start~anonymous|1
(i32.const 2)
)
(func $function-expression/makeAdder<i32> (; 5 ;) (type $i) (result i32)
(return
(i32.const 3)
)
)
(func $function-expression/makeAdder<f32>~theAdder|4 (; 6 ;) (type $fff) (param $0 f32) (param $1 f32) (result f32)
(return
(f32.add
(get_local $0)
(get_local $1)
)
)
)
(func $function-expression/makeAdder<f32> (; 7 ;) (type $i) (result i32)
(return
(i32.const 4)
)
)
(func $function-expression/makeAdderArrow<i8>~anonymous|5 (; 8 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(return
(i32.shr_s
(i32.shl
(i32.add
(get_local $0)
(get_local $1)
)
(i32.const 24)
)
(i32.const 24)
)
)
)
(func $function-expression/makeAdderArrow<i8> (; 9 ;) (type $i) (result i32)
(return
(i32.const 5)
)
)
(func $start (; 10 ;) (type $v)
(if
(i32.eqz
(i32.eq
(call_indirect (type $ii)
(i32.const 1)
(get_global $function-expression/f1)
)
(i32.const 1)
)
)
(block
(call $abort
(i32.const 0)
(i32.const 4)
(i32.const 4)
(i32.const 0)
)
(unreachable)
)
)
(if
(i32.eqz
(i32.eq
(call_indirect (type $ii)
(i32.const 2)
(get_global $function-expression/f2)
)
(i32.const 2)
)
)
(block
(call $abort
(i32.const 0)
(i32.const 4)
(i32.const 9)
(i32.const 0)
)
(unreachable)
)
)
(call_indirect (type $v)
(get_global $function-expression/f3)
)
(set_global $function-expression/i32Adder
(call $function-expression/makeAdder<i32>)
)
(if
(i32.eqz
(i32.eq
(call_indirect (type $iii)
(i32.const 4)
(i32.const 2)
(get_global $function-expression/i32Adder)
)
(i32.const 6)
)
)
(block
(call $abort
(i32.const 0)
(i32.const 4)
(i32.const 22)
(i32.const 0)
)
(unreachable)
)
)
(set_global $function-expression/f32Adder
(call $function-expression/makeAdder<f32>)
)
(if
(i32.eqz
(f32.eq
(call_indirect (type $fff)
(f32.const 1.5)
(f32.const 2.5)
(get_global $function-expression/f32Adder)
)
(f32.const 4)
)
)
(block
(call $abort
(i32.const 0)
(i32.const 4)
(i32.const 25)
(i32.const 0)
)
(unreachable)
)
)
(set_global $function-expression/i8Adder
(call $function-expression/makeAdderArrow<i8>)
)
(if
(i32.eqz
(i32.eq
(call_indirect (type $iii)
(i32.const 127)
(i32.const 127)
(get_global $function-expression/i8Adder)
)
(i32.const -2)
)
)
(block
(call $abort
(i32.const 0)
(i32.const 4)
(i32.const 34)
(i32.const 0)
)
(unreachable)
)
)
(set_global $function-expression/f1
(get_global $function-expression/f2)
)
(if
(i32.eqz
(i32.eq
(call_indirect (type $ii)
(i32.const 4)
(get_global $function-expression/f1)
)
(i32.const 4)
)
)
(block
(call $abort
(i32.const 0)
(i32.const 4)
(i32.const 37)
(i32.const 0)
)
(unreachable)
)
)
(call $start~someName|2)
)
)

View File

@ -1,6 +1,6 @@
(module
(type $iiiiv (func (param i32 i32 i32 i32)))
(type $iiv (func (param i32 i32)))
(type $iiiiv (func (param i32 i32 i32 i32)))
(type $v (func))
(import "env" "abort" (func $abort (param i32 i32 i32 i32)))
(global $retain-i32/si (mut i32) (i32.const 0))

View File

@ -1,6 +1,6 @@
(module
(type $iiiiv (func (param i32 i32 i32 i32)))
(type $iiv (func (param i32 i32)))
(type $iiiiv (func (param i32 i32 i32 i32)))
(type $v (func))
(import "env" "abort" (func $abort (param i32 i32 i32 i32)))
(global $retain-i32/si (mut i32) (i32.const 0))

View File

@ -6,7 +6,7 @@
(type $iv (func (param i32)))
(type $v (func))
(import "env" "abort" (func $abort (param i32 i32 i32 i32)))
(global "$(lib)/allocator/arena/OFFSET" (mut i32) (i32.const 0))
(global "$(lib)/allocator/arena/offset" (mut i32) (i32.const 0))
(global $std/allocator_arena/ptr1 (mut i32) (i32.const 0))
(global $std/allocator_arena/ptr2 (mut i32) (i32.const 0))
(global $std/allocator_arena/i (mut i32) (i32.const 0))
@ -35,7 +35,7 @@
(i32.add
(i32.add
(tee_local $1
(get_global "$(lib)/allocator/arena/OFFSET")
(get_global "$(lib)/allocator/arena/offset")
)
(get_local $0)
)
@ -92,7 +92,7 @@
)
)
)
(set_global "$(lib)/allocator/arena/OFFSET"
(set_global "$(lib)/allocator/arena/offset"
(get_local $2)
)
(get_local $1)
@ -2360,7 +2360,7 @@
(nop)
)
(func "$(lib)/allocator/arena/reset_memory" (; 7 ;) (type $v)
(set_global "$(lib)/allocator/arena/OFFSET"
(set_global "$(lib)/allocator/arena/offset"
(i32.and
(i32.add
(get_global $HEAP_BASE)
@ -2371,7 +2371,7 @@
)
)
(func $start (; 8 ;) (type $v)
(set_global "$(lib)/allocator/arena/OFFSET"
(set_global "$(lib)/allocator/arena/offset"
(i32.and
(i32.add
(get_global $HEAP_BASE)

View File

@ -7,10 +7,10 @@
(type $iv (func (param i32)))
(type $v (func))
(import "env" "abort" (func $abort (param i32 i32 i32 i32)))
(global "$(lib)/allocator/arena/AL_BITS" i32 (i32.const 3))
(global "$(lib)/allocator/arena/AL_SIZE" i32 (i32.const 8))
(global "$(lib)/allocator/arena/AL_MASK" i32 (i32.const 7))
(global "$(lib)/allocator/arena/OFFSET" (mut i32) (i32.const 0))
(global "$(lib)/allocator/common/alignment/BITS" i32 (i32.const 3))
(global "$(lib)/allocator/common/alignment/SIZE" i32 (i32.const 8))
(global "$(lib)/allocator/common/alignment/MASK" i32 (i32.const 7))
(global "$(lib)/allocator/arena/offset" (mut i32) (i32.const 0))
(global $std/allocator_arena/size i32 (i32.const 42))
(global $std/allocator_arena/ptr1 (mut i32) (i32.const 0))
(global $std/allocator_arena/ptr2 (mut i32) (i32.const 0))
@ -37,7 +37,7 @@
)
)
(set_local $1
(get_global "$(lib)/allocator/arena/OFFSET")
(get_global "$(lib)/allocator/arena/offset")
)
(set_local $2
(i32.and
@ -117,7 +117,7 @@
)
)
)
(set_global "$(lib)/allocator/arena/OFFSET"
(set_global "$(lib)/allocator/arena/offset"
(get_local $2)
)
(return
@ -777,6 +777,232 @@
)
(br $break|2)
)
(block
(set_local $3
(i32.load
(get_local $1)
)
)
(i32.store8
(block (result i32)
(set_local $5
(get_local $0)
)
(set_local $0
(i32.add
(get_local $5)
(i32.const 1)
)
)
(get_local $5)
)
(i32.load8_u
(block (result i32)
(set_local $5
(get_local $1)
)
(set_local $1
(i32.add
(get_local $5)
(i32.const 1)
)
)
(get_local $5)
)
)
)
(i32.store8
(block (result i32)
(set_local $5
(get_local $0)
)
(set_local $0
(i32.add
(get_local $5)
(i32.const 1)
)
)
(get_local $5)
)
(i32.load8_u
(block (result i32)
(set_local $5
(get_local $1)
)
(set_local $1
(i32.add
(get_local $5)
(i32.const 1)
)
)
(get_local $5)
)
)
)
(i32.store8
(block (result i32)
(set_local $5
(get_local $0)
)
(set_local $0
(i32.add
(get_local $5)
(i32.const 1)
)
)
(get_local $5)
)
(i32.load8_u
(block (result i32)
(set_local $5
(get_local $1)
)
(set_local $1
(i32.add
(get_local $5)
(i32.const 1)
)
)
(get_local $5)
)
)
)
(set_local $2
(i32.sub
(get_local $2)
(i32.const 3)
)
)
(block $break|3
(loop $continue|3
(if
(i32.ge_u
(get_local $2)
(i32.const 17)
)
(block
(block
(set_local $4
(i32.load
(i32.add
(get_local $1)
(i32.const 1)
)
)
)
(i32.store
(get_local $0)
(i32.or
(i32.shr_u
(get_local $3)
(i32.const 24)
)
(i32.shl
(get_local $4)
(i32.const 8)
)
)
)
(set_local $3
(i32.load
(i32.add
(get_local $1)
(i32.const 5)
)
)
)
(i32.store
(i32.add
(get_local $0)
(i32.const 4)
)
(i32.or
(i32.shr_u
(get_local $4)
(i32.const 24)
)
(i32.shl
(get_local $3)
(i32.const 8)
)
)
)
(set_local $4
(i32.load
(i32.add
(get_local $1)
(i32.const 9)
)
)
)
(i32.store
(i32.add
(get_local $0)
(i32.const 8)
)
(i32.or
(i32.shr_u
(get_local $3)
(i32.const 24)
)
(i32.shl
(get_local $4)
(i32.const 8)
)
)
)
(set_local $3
(i32.load
(i32.add
(get_local $1)
(i32.const 13)
)
)
)
(i32.store
(i32.add
(get_local $0)
(i32.const 12)
)
(i32.or
(i32.shr_u
(get_local $4)
(i32.const 24)
)
(i32.shl
(get_local $3)
(i32.const 8)
)
)
)
(set_local $1
(i32.add
(get_local $1)
(i32.const 16)
)
)
(set_local $0
(i32.add
(get_local $0)
(i32.const 16)
)
)
(set_local $2
(i32.sub
(get_local $2)
(i32.const 16)
)
)
)
(br $continue|3)
)
)
)
)
(br $break|2)
)
)
(block
(set_local $3
(i32.load
(get_local $1)
@ -838,46 +1064,18 @@
)
)
)
(i32.store8
(block (result i32)
(set_local $5
(get_local $0)
)
(set_local $0
(i32.add
(get_local $5)
(i32.const 1)
)
)
(get_local $5)
)
(i32.load8_u
(block (result i32)
(set_local $5
(get_local $1)
)
(set_local $1
(i32.add
(get_local $5)
(i32.const 1)
)
)
(get_local $5)
)
)
)
(set_local $2
(i32.sub
(get_local $2)
(i32.const 3)
(i32.const 2)
)
)
(block $break|3
(loop $continue|3
(block $break|4
(loop $continue|4
(if
(i32.ge_u
(get_local $2)
(i32.const 17)
(i32.const 18)
)
(block
(block
@ -885,7 +1083,7 @@
(i32.load
(i32.add
(get_local $1)
(i32.const 1)
(i32.const 2)
)
)
)
@ -894,11 +1092,11 @@
(i32.or
(i32.shr_u
(get_local $3)
(i32.const 24)
(i32.const 16)
)
(i32.shl
(get_local $4)
(i32.const 8)
(i32.const 16)
)
)
)
@ -906,7 +1104,7 @@
(i32.load
(i32.add
(get_local $1)
(i32.const 5)
(i32.const 6)
)
)
)
@ -918,11 +1116,11 @@
(i32.or
(i32.shr_u
(get_local $4)
(i32.const 24)
(i32.const 16)
)
(i32.shl
(get_local $3)
(i32.const 8)
(i32.const 16)
)
)
)
@ -930,7 +1128,7 @@
(i32.load
(i32.add
(get_local $1)
(i32.const 9)
(i32.const 10)
)
)
)
@ -942,11 +1140,11 @@
(i32.or
(i32.shr_u
(get_local $3)
(i32.const 24)
(i32.const 16)
)
(i32.shl
(get_local $4)
(i32.const 8)
(i32.const 16)
)
)
)
@ -954,7 +1152,7 @@
(i32.load
(i32.add
(get_local $1)
(i32.const 13)
(i32.const 14)
)
)
)
@ -966,11 +1164,11 @@
(i32.or
(i32.shr_u
(get_local $4)
(i32.const 24)
(i32.const 16)
)
(i32.shl
(get_local $3)
(i32.const 8)
(i32.const 16)
)
)
)
@ -993,13 +1191,15 @@
)
)
)
(br $continue|3)
(br $continue|4)
)
)
)
)
(br $break|2)
)
)
(block
(set_local $3
(i32.load
(get_local $1)
@ -1033,46 +1233,18 @@
)
)
)
(i32.store8
(block (result i32)
(set_local $5
(get_local $0)
)
(set_local $0
(i32.add
(get_local $5)
(i32.const 1)
)
)
(get_local $5)
)
(i32.load8_u
(block (result i32)
(set_local $5
(get_local $1)
)
(set_local $1
(i32.add
(get_local $5)
(i32.const 1)
)
)
(get_local $5)
)
)
)
(set_local $2
(i32.sub
(get_local $2)
(i32.const 2)
(i32.const 1)
)
)
(block $break|4
(loop $continue|4
(block $break|5
(loop $continue|5
(if
(i32.ge_u
(get_local $2)
(i32.const 18)
(i32.const 19)
)
(block
(block
@ -1080,7 +1252,7 @@
(i32.load
(i32.add
(get_local $1)
(i32.const 2)
(i32.const 3)
)
)
)
@ -1089,11 +1261,11 @@
(i32.or
(i32.shr_u
(get_local $3)
(i32.const 16)
(i32.const 8)
)
(i32.shl
(get_local $4)
(i32.const 16)
(i32.const 24)
)
)
)
@ -1101,7 +1273,7 @@
(i32.load
(i32.add
(get_local $1)
(i32.const 6)
(i32.const 7)
)
)
)
@ -1113,11 +1285,11 @@
(i32.or
(i32.shr_u
(get_local $4)
(i32.const 16)
(i32.const 8)
)
(i32.shl
(get_local $3)
(i32.const 16)
(i32.const 24)
)
)
)
@ -1125,7 +1297,7 @@
(i32.load
(i32.add
(get_local $1)
(i32.const 10)
(i32.const 11)
)
)
)
@ -1137,11 +1309,11 @@
(i32.or
(i32.shr_u
(get_local $3)
(i32.const 16)
(i32.const 8)
)
(i32.shl
(get_local $4)
(i32.const 16)
(i32.const 24)
)
)
)
@ -1149,7 +1321,7 @@
(i32.load
(i32.add
(get_local $1)
(i32.const 14)
(i32.const 15)
)
)
)
@ -1161,11 +1333,11 @@
(i32.or
(i32.shr_u
(get_local $4)
(i32.const 16)
(i32.const 8)
)
(i32.shl
(get_local $3)
(i32.const 16)
(i32.const 24)
)
)
)
@ -1188,179 +1360,13 @@
)
)
)
(br $continue|4)
(br $continue|5)
)
)
)
)
(br $break|2)
)
(set_local $3
(i32.load
(get_local $1)
)
)
(i32.store8
(block (result i32)
(set_local $5
(get_local $0)
)
(set_local $0
(i32.add
(get_local $5)
(i32.const 1)
)
)
(get_local $5)
)
(i32.load8_u
(block (result i32)
(set_local $5
(get_local $1)
)
(set_local $1
(i32.add
(get_local $5)
(i32.const 1)
)
)
(get_local $5)
)
)
)
(set_local $2
(i32.sub
(get_local $2)
(i32.const 1)
)
)
(block $break|5
(loop $continue|5
(if
(i32.ge_u
(get_local $2)
(i32.const 19)
)
(block
(block
(set_local $4
(i32.load
(i32.add
(get_local $1)
(i32.const 3)
)
)
)
(i32.store
(get_local $0)
(i32.or
(i32.shr_u
(get_local $3)
(i32.const 8)
)
(i32.shl
(get_local $4)
(i32.const 24)
)
)
)
(set_local $3
(i32.load
(i32.add
(get_local $1)
(i32.const 7)
)
)
)
(i32.store
(i32.add
(get_local $0)
(i32.const 4)
)
(i32.or
(i32.shr_u
(get_local $4)
(i32.const 8)
)
(i32.shl
(get_local $3)
(i32.const 24)
)
)
)
(set_local $4
(i32.load
(i32.add
(get_local $1)
(i32.const 11)
)
)
)
(i32.store
(i32.add
(get_local $0)
(i32.const 8)
)
(i32.or
(i32.shr_u
(get_local $3)
(i32.const 8)
)
(i32.shl
(get_local $4)
(i32.const 24)
)
)
)
(set_local $3
(i32.load
(i32.add
(get_local $1)
(i32.const 15)
)
)
)
(i32.store
(i32.add
(get_local $0)
(i32.const 12)
)
(i32.or
(i32.shr_u
(get_local $4)
(i32.const 8)
)
(i32.shl
(get_local $3)
(i32.const 24)
)
)
)
(set_local $1
(i32.add
(get_local $1)
(i32.const 16)
)
)
(set_local $0
(i32.add
(get_local $0)
(i32.const 16)
)
)
(set_local $2
(i32.sub
(get_local $2)
(i32.const 16)
)
)
)
(br $continue|5)
)
)
)
)
(br $break|2)
)
)
(if
@ -2662,7 +2668,7 @@
(func "$(lib)/allocator/arena/free_memory" (; 6 ;) (type $iv) (param $0 i32)
)
(func "$(lib)/allocator/arena/reset_memory" (; 7 ;) (type $v)
(set_global "$(lib)/allocator/arena/OFFSET"
(set_global "$(lib)/allocator/arena/offset"
(i32.and
(i32.add
(get_global $HEAP_BASE)
@ -2676,7 +2682,7 @@
)
)
(func $start (; 8 ;) (type $v)
(set_global "$(lib)/allocator/arena/OFFSET"
(set_global "$(lib)/allocator/arena/offset"
(i32.and
(i32.add
(get_global $HEAP_BASE)

View File

@ -1,14 +1,15 @@
(module
(type $ii (func (param i32) (result i32)))
(type $iiiiv (func (param i32 i32 i32 i32)))
(type $iii (func (param i32 i32) (result i32)))
(type $iiv (func (param i32 i32)))
(type $iiiv (func (param i32 i32 i32)))
(type $iv (func (param i32)))
(type $iiv (func (param i32 i32)))
(type $iii (func (param i32 i32) (result i32)))
(type $iiii (func (param i32 i32 i32) (result i32)))
(type $iiiii (func (param i32 i32 i32 i32) (result i32)))
(type $v (func))
(import "env" "abort" (func $abort (param i32 i32 i32 i32)))
(global "$(lib)/allocator/arena/OFFSET" (mut i32) (i32.const 0))
(global "$(lib)/allocator/arena/offset" (mut i32) (i32.const 0))
(global $std/array/arr (mut i32) (i32.const 0))
(global $std/array/i (mut i32) (i32.const 0))
(global $HEAP_BASE i32 (i32.const 64))
@ -37,7 +38,7 @@
(i32.add
(i32.add
(tee_local $1
(get_global "$(lib)/allocator/arena/OFFSET")
(get_global "$(lib)/allocator/arena/offset")
)
(get_local $0)
)
@ -94,7 +95,7 @@
)
)
)
(set_global "$(lib)/allocator/arena/OFFSET"
(set_global "$(lib)/allocator/arena/offset"
(get_local $2)
)
(get_local $1)
@ -2803,7 +2804,27 @@
)
(i32.const -1)
)
(func "$(lib)/array/Array#splice" (; 15 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(func "$(lib)/array/Array#indexOf|trampoline" (; 15 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32)
(block $N=1
(block $N=0
(block $N=invalid
(br_table $N=0 $N=1 $N=invalid
(get_local $3)
)
)
(unreachable)
)
(set_local $2
(i32.const 0)
)
)
(call "$(lib)/array/Array#indexOf"
(get_local $0)
(get_local $1)
(get_local $2)
)
)
(func "$(lib)/array/Array#splice" (; 16 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(if
(i32.lt_s
(get_local $2)
@ -2904,8 +2925,8 @@
)
)
)
(func $start (; 16 ;) (type $v)
(set_global "$(lib)/allocator/arena/OFFSET"
(func $start (; 17 ;) (type $v)
(set_global "$(lib)/allocator/arena/offset"
(i32.and
(i32.add
(get_global $HEAP_BASE)
@ -3854,10 +3875,11 @@
)
)
(set_global $std/array/i
(call "$(lib)/array/Array#indexOf"
(call "$(lib)/array/Array#indexOf|trampoline"
(get_global $std/array/arr)
(i32.const 44)
(i32.const 0)
(i32.const 0)
)
)
(if
@ -3873,10 +3895,11 @@
)
)
(set_global $std/array/i
(call "$(lib)/array/Array#indexOf"
(call "$(lib)/array/Array#indexOf|trampoline"
(get_global $std/array/arr)
(i32.const 42)
(i32.const 0)
(i32.const 0)
)
)
(if
@ -3895,10 +3918,11 @@
)
)
(set_global $std/array/i
(call "$(lib)/array/Array#indexOf"
(call "$(lib)/array/Array#indexOf|trampoline"
(get_global $std/array/arr)
(i32.const 45)
(i32.const 0)
(i32.const 0)
)
)
(if

View File

@ -2,17 +2,18 @@
(type $i (func (result i32)))
(type $ii (func (param i32) (result i32)))
(type $iiiiv (func (param i32 i32 i32 i32)))
(type $iii (func (param i32 i32) (result i32)))
(type $iiv (func (param i32 i32)))
(type $iiiv (func (param i32 i32 i32)))
(type $iv (func (param i32)))
(type $iiv (func (param i32 i32)))
(type $iii (func (param i32 i32) (result i32)))
(type $iiii (func (param i32 i32 i32) (result i32)))
(type $iiiii (func (param i32 i32 i32 i32) (result i32)))
(type $v (func))
(import "env" "abort" (func $abort (param i32 i32 i32 i32)))
(global "$(lib)/allocator/arena/AL_BITS" i32 (i32.const 3))
(global "$(lib)/allocator/arena/AL_SIZE" i32 (i32.const 8))
(global "$(lib)/allocator/arena/AL_MASK" i32 (i32.const 7))
(global "$(lib)/allocator/arena/OFFSET" (mut i32) (i32.const 0))
(global "$(lib)/allocator/common/alignment/BITS" i32 (i32.const 3))
(global "$(lib)/allocator/common/alignment/SIZE" i32 (i32.const 8))
(global "$(lib)/allocator/common/alignment/MASK" i32 (i32.const 7))
(global "$(lib)/allocator/arena/offset" (mut i32) (i32.const 0))
(global $std/array/arr (mut i32) (i32.const 0))
(global $std/array/i (mut i32) (i32.const 0))
(global $HEAP_BASE i32 (i32.const 64))
@ -38,7 +39,7 @@
)
)
(set_local $1
(get_global "$(lib)/allocator/arena/OFFSET")
(get_global "$(lib)/allocator/arena/offset")
)
(set_local $2
(i32.and
@ -118,7 +119,7 @@
)
)
)
(set_global "$(lib)/allocator/arena/OFFSET"
(set_global "$(lib)/allocator/arena/offset"
(get_local $2)
)
(return
@ -436,6 +437,232 @@
)
(br $break|2)
)
(block
(set_local $3
(i32.load
(get_local $1)
)
)
(i32.store8
(block (result i32)
(set_local $5
(get_local $0)
)
(set_local $0
(i32.add
(get_local $5)
(i32.const 1)
)
)
(get_local $5)
)
(i32.load8_u
(block (result i32)
(set_local $5
(get_local $1)
)
(set_local $1
(i32.add
(get_local $5)
(i32.const 1)
)
)
(get_local $5)
)
)
)
(i32.store8
(block (result i32)
(set_local $5
(get_local $0)
)
(set_local $0
(i32.add
(get_local $5)
(i32.const 1)
)
)
(get_local $5)
)
(i32.load8_u
(block (result i32)
(set_local $5
(get_local $1)
)
(set_local $1
(i32.add
(get_local $5)
(i32.const 1)
)
)
(get_local $5)
)
)
)
(i32.store8
(block (result i32)
(set_local $5
(get_local $0)
)
(set_local $0
(i32.add
(get_local $5)
(i32.const 1)
)
)
(get_local $5)
)
(i32.load8_u
(block (result i32)
(set_local $5
(get_local $1)
)
(set_local $1
(i32.add
(get_local $5)
(i32.const 1)
)
)
(get_local $5)
)
)
)
(set_local $2
(i32.sub
(get_local $2)
(i32.const 3)
)
)
(block $break|3
(loop $continue|3
(if
(i32.ge_u
(get_local $2)
(i32.const 17)
)
(block
(block
(set_local $4
(i32.load
(i32.add
(get_local $1)
(i32.const 1)
)
)
)
(i32.store
(get_local $0)
(i32.or
(i32.shr_u
(get_local $3)
(i32.const 24)
)
(i32.shl
(get_local $4)
(i32.const 8)
)
)
)
(set_local $3
(i32.load
(i32.add
(get_local $1)
(i32.const 5)
)
)
)
(i32.store
(i32.add
(get_local $0)
(i32.const 4)
)
(i32.or
(i32.shr_u
(get_local $4)
(i32.const 24)
)
(i32.shl
(get_local $3)
(i32.const 8)
)
)
)
(set_local $4
(i32.load
(i32.add
(get_local $1)
(i32.const 9)
)
)
)
(i32.store
(i32.add
(get_local $0)
(i32.const 8)
)
(i32.or
(i32.shr_u
(get_local $3)
(i32.const 24)
)
(i32.shl
(get_local $4)
(i32.const 8)
)
)
)
(set_local $3
(i32.load
(i32.add
(get_local $1)
(i32.const 13)
)
)
)
(i32.store
(i32.add
(get_local $0)
(i32.const 12)
)
(i32.or
(i32.shr_u
(get_local $4)
(i32.const 24)
)
(i32.shl
(get_local $3)
(i32.const 8)
)
)
)
(set_local $1
(i32.add
(get_local $1)
(i32.const 16)
)
)
(set_local $0
(i32.add
(get_local $0)
(i32.const 16)
)
)
(set_local $2
(i32.sub
(get_local $2)
(i32.const 16)
)
)
)
(br $continue|3)
)
)
)
)
(br $break|2)
)
)
(block
(set_local $3
(i32.load
(get_local $1)
@ -497,46 +724,18 @@
)
)
)
(i32.store8
(block (result i32)
(set_local $5
(get_local $0)
)
(set_local $0
(i32.add
(get_local $5)
(i32.const 1)
)
)
(get_local $5)
)
(i32.load8_u
(block (result i32)
(set_local $5
(get_local $1)
)
(set_local $1
(i32.add
(get_local $5)
(i32.const 1)
)
)
(get_local $5)
)
)
)
(set_local $2
(i32.sub
(get_local $2)
(i32.const 3)
(i32.const 2)
)
)
(block $break|3
(loop $continue|3
(block $break|4
(loop $continue|4
(if
(i32.ge_u
(get_local $2)
(i32.const 17)
(i32.const 18)
)
(block
(block
@ -544,7 +743,7 @@
(i32.load
(i32.add
(get_local $1)
(i32.const 1)
(i32.const 2)
)
)
)
@ -553,11 +752,11 @@
(i32.or
(i32.shr_u
(get_local $3)
(i32.const 24)
(i32.const 16)
)
(i32.shl
(get_local $4)
(i32.const 8)
(i32.const 16)
)
)
)
@ -565,7 +764,7 @@
(i32.load
(i32.add
(get_local $1)
(i32.const 5)
(i32.const 6)
)
)
)
@ -577,11 +776,11 @@
(i32.or
(i32.shr_u
(get_local $4)
(i32.const 24)
(i32.const 16)
)
(i32.shl
(get_local $3)
(i32.const 8)
(i32.const 16)
)
)
)
@ -589,7 +788,7 @@
(i32.load
(i32.add
(get_local $1)
(i32.const 9)
(i32.const 10)
)
)
)
@ -601,11 +800,11 @@
(i32.or
(i32.shr_u
(get_local $3)
(i32.const 24)
(i32.const 16)
)
(i32.shl
(get_local $4)
(i32.const 8)
(i32.const 16)
)
)
)
@ -613,7 +812,7 @@
(i32.load
(i32.add
(get_local $1)
(i32.const 13)
(i32.const 14)
)
)
)
@ -625,11 +824,11 @@
(i32.or
(i32.shr_u
(get_local $4)
(i32.const 24)
(i32.const 16)
)
(i32.shl
(get_local $3)
(i32.const 8)
(i32.const 16)
)
)
)
@ -652,13 +851,15 @@
)
)
)
(br $continue|3)
(br $continue|4)
)
)
)
)
(br $break|2)
)
)
(block
(set_local $3
(i32.load
(get_local $1)
@ -692,46 +893,18 @@
)
)
)
(i32.store8
(block (result i32)
(set_local $5
(get_local $0)
)
(set_local $0
(i32.add
(get_local $5)
(i32.const 1)
)
)
(get_local $5)
)
(i32.load8_u
(block (result i32)
(set_local $5
(get_local $1)
)
(set_local $1
(i32.add
(get_local $5)
(i32.const 1)
)
)
(get_local $5)
)
)
)
(set_local $2
(i32.sub
(get_local $2)
(i32.const 2)
(i32.const 1)
)
)
(block $break|4
(loop $continue|4
(block $break|5
(loop $continue|5
(if
(i32.ge_u
(get_local $2)
(i32.const 18)
(i32.const 19)
)
(block
(block
@ -739,7 +912,7 @@
(i32.load
(i32.add
(get_local $1)
(i32.const 2)
(i32.const 3)
)
)
)
@ -748,11 +921,11 @@
(i32.or
(i32.shr_u
(get_local $3)
(i32.const 16)
(i32.const 8)
)
(i32.shl
(get_local $4)
(i32.const 16)
(i32.const 24)
)
)
)
@ -760,7 +933,7 @@
(i32.load
(i32.add
(get_local $1)
(i32.const 6)
(i32.const 7)
)
)
)
@ -772,11 +945,11 @@
(i32.or
(i32.shr_u
(get_local $4)
(i32.const 16)
(i32.const 8)
)
(i32.shl
(get_local $3)
(i32.const 16)
(i32.const 24)
)
)
)
@ -784,7 +957,7 @@
(i32.load
(i32.add
(get_local $1)
(i32.const 10)
(i32.const 11)
)
)
)
@ -796,11 +969,11 @@
(i32.or
(i32.shr_u
(get_local $3)
(i32.const 16)
(i32.const 8)
)
(i32.shl
(get_local $4)
(i32.const 16)
(i32.const 24)
)
)
)
@ -808,7 +981,7 @@
(i32.load
(i32.add
(get_local $1)
(i32.const 14)
(i32.const 15)
)
)
)
@ -820,11 +993,11 @@
(i32.or
(i32.shr_u
(get_local $4)
(i32.const 16)
(i32.const 8)
)
(i32.shl
(get_local $3)
(i32.const 16)
(i32.const 24)
)
)
)
@ -847,179 +1020,13 @@
)
)
)
(br $continue|4)
(br $continue|5)
)
)
)
)
(br $break|2)
)
(set_local $3
(i32.load
(get_local $1)
)
)
(i32.store8
(block (result i32)
(set_local $5
(get_local $0)
)
(set_local $0
(i32.add
(get_local $5)
(i32.const 1)
)
)
(get_local $5)
)
(i32.load8_u
(block (result i32)
(set_local $5
(get_local $1)
)
(set_local $1
(i32.add
(get_local $5)
(i32.const 1)
)
)
(get_local $5)
)
)
)
(set_local $2
(i32.sub
(get_local $2)
(i32.const 1)
)
)
(block $break|5
(loop $continue|5
(if
(i32.ge_u
(get_local $2)
(i32.const 19)
)
(block
(block
(set_local $4
(i32.load
(i32.add
(get_local $1)
(i32.const 3)
)
)
)
(i32.store
(get_local $0)
(i32.or
(i32.shr_u
(get_local $3)
(i32.const 8)
)
(i32.shl
(get_local $4)
(i32.const 24)
)
)
)
(set_local $3
(i32.load
(i32.add
(get_local $1)
(i32.const 7)
)
)
)
(i32.store
(i32.add
(get_local $0)
(i32.const 4)
)
(i32.or
(i32.shr_u
(get_local $4)
(i32.const 8)
)
(i32.shl
(get_local $3)
(i32.const 24)
)
)
)
(set_local $4
(i32.load
(i32.add
(get_local $1)
(i32.const 11)
)
)
)
(i32.store
(i32.add
(get_local $0)
(i32.const 8)
)
(i32.or
(i32.shr_u
(get_local $3)
(i32.const 8)
)
(i32.shl
(get_local $4)
(i32.const 24)
)
)
)
(set_local $3
(i32.load
(i32.add
(get_local $1)
(i32.const 15)
)
)
)
(i32.store
(i32.add
(get_local $0)
(i32.const 12)
)
(i32.or
(i32.shr_u
(get_local $4)
(i32.const 8)
)
(i32.shl
(get_local $3)
(i32.const 24)
)
)
)
(set_local $1
(i32.add
(get_local $1)
(i32.const 16)
)
)
(set_local $0
(i32.add
(get_local $0)
(i32.const 16)
)
)
(set_local $2
(i32.sub
(get_local $2)
(i32.const 16)
)
)
)
(br $continue|5)
)
)
)
)
(br $break|2)
)
)
(if
@ -3143,7 +3150,27 @@
(i32.const -1)
)
)
(func "$(lib)/array/Array#splice" (; 15 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(func "$(lib)/array/Array#indexOf|trampoline" (; 15 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32)
(block $N=1
(block $N=0
(block $N=invalid
(br_table $N=0 $N=1 $N=invalid
(get_local $3)
)
)
(unreachable)
)
(set_local $2
(i32.const 0)
)
)
(call "$(lib)/array/Array#indexOf"
(get_local $0)
(get_local $1)
(get_local $2)
)
)
(func "$(lib)/array/Array#splice" (; 16 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(local $3 i32)
(local $4 i32)
(if
@ -3252,8 +3279,8 @@
)
)
)
(func $start (; 16 ;) (type $v)
(set_global "$(lib)/allocator/arena/OFFSET"
(func $start (; 17 ;) (type $v)
(set_global "$(lib)/allocator/arena/offset"
(i32.and
(i32.add
(get_global $HEAP_BASE)
@ -4322,10 +4349,11 @@
)
)
(set_global $std/array/i
(call "$(lib)/array/Array#indexOf"
(call "$(lib)/array/Array#indexOf|trampoline"
(get_global $std/array/arr)
(i32.const 44)
(i32.const 0)
(i32.const 0)
)
)
(if
@ -4346,10 +4374,11 @@
)
)
(set_global $std/array/i
(call "$(lib)/array/Array#indexOf"
(call "$(lib)/array/Array#indexOf|trampoline"
(get_global $std/array/arr)
(i32.const 42)
(i32.const 0)
(i32.const 0)
)
)
(if
@ -4370,10 +4399,11 @@
)
)
(set_global $std/array/i
(call "$(lib)/array/Array#indexOf"
(call "$(lib)/array/Array#indexOf|trampoline"
(get_global $std/array/arr)
(i32.const 45)
(i32.const 0)
(i32.const 0)
)
)
(if

View File

@ -49,6 +49,7 @@
)
(func $start (; 3 ;) (type $v)
(local $0 i32)
(local $1 i32)
(set_global $std/carray/arr
(get_global $HEAP_BASE)
)
@ -199,14 +200,19 @@
(if
(block (result i32)
(call "$(lib)/array/CArray#__set"
(get_global $std/carray/arr)
(i32.const 3)
(tee_local $0
(i32.const 9000)
(get_global $std/carray/arr)
)
(tee_local $1
(i32.const 3)
)
(i32.const 9000)
)
(i32.ne
(get_local $0)
(call "$(lib)/array/CArray#__get"
(get_local $0)
(get_local $1)
)
(i32.const 9000)
)
)

View File

@ -51,6 +51,7 @@
)
(func $start (; 3 ;) (type $v)
(local $0 i32)
(local $1 i32)
(set_global $std/carray/arr
(get_global $HEAP_BASE)
)
@ -231,13 +232,18 @@
(i32.eq
(block (result i32)
(call "$(lib)/array/CArray#__set"
(get_global $std/carray/arr)
(i32.const 3)
(tee_local $0
(i32.const 9000)
(get_global $std/carray/arr)
)
(tee_local $1
(i32.const 3)
)
(i32.const 9000)
)
(call "$(lib)/array/CArray#__get"
(get_local $0)
(get_local $1)
)
(get_local $0)
)
(i32.const 9000)
)

View File

@ -2,7 +2,7 @@
(type $ii (func (param i32) (result i32)))
(type $ifv (func (param i32 f32)))
(type $v (func))
(global "$(lib)/allocator/arena/OFFSET" (mut i32) (i32.const 0))
(global "$(lib)/allocator/arena/offset" (mut i32) (i32.const 0))
(global $std/new/aClass (mut i32) (i32.const 0))
(global $HEAP_BASE i32 (i32.const 4))
(memory $0 1)
@ -28,7 +28,7 @@
(i32.add
(i32.add
(tee_local $1
(get_global "$(lib)/allocator/arena/OFFSET")
(get_global "$(lib)/allocator/arena/offset")
)
(get_local $0)
)
@ -85,7 +85,7 @@
)
)
)
(set_global "$(lib)/allocator/arena/OFFSET"
(set_global "$(lib)/allocator/arena/offset"
(get_local $2)
)
(get_local $1)
@ -107,7 +107,7 @@
)
(func $start (; 2 ;) (type $v)
(local $0 i32)
(set_global "$(lib)/allocator/arena/OFFSET"
(set_global "$(lib)/allocator/arena/offset"
(i32.and
(i32.add
(get_global $HEAP_BASE)

View File

@ -3,10 +3,10 @@
(type $ii (func (param i32) (result i32)))
(type $ifv (func (param i32 f32)))
(type $v (func))
(global "$(lib)/allocator/arena/AL_BITS" i32 (i32.const 3))
(global "$(lib)/allocator/arena/AL_SIZE" i32 (i32.const 8))
(global "$(lib)/allocator/arena/AL_MASK" i32 (i32.const 7))
(global "$(lib)/allocator/arena/OFFSET" (mut i32) (i32.const 0))
(global "$(lib)/allocator/common/alignment/BITS" i32 (i32.const 3))
(global "$(lib)/allocator/common/alignment/SIZE" i32 (i32.const 8))
(global "$(lib)/allocator/common/alignment/MASK" i32 (i32.const 7))
(global "$(lib)/allocator/arena/offset" (mut i32) (i32.const 0))
(global $std/new/aClass (mut i32) (i32.const 0))
(global $HEAP_BASE i32 (i32.const 4))
(memory $0 1)
@ -29,7 +29,7 @@
)
)
(set_local $1
(get_global "$(lib)/allocator/arena/OFFSET")
(get_global "$(lib)/allocator/arena/offset")
)
(set_local $2
(i32.and
@ -109,7 +109,7 @@
)
)
)
(set_global "$(lib)/allocator/arena/OFFSET"
(set_global "$(lib)/allocator/arena/offset"
(get_local $2)
)
(return
@ -133,7 +133,7 @@
)
(func $start (; 2 ;) (type $v)
(local $0 i32)
(set_global "$(lib)/allocator/arena/OFFSET"
(set_global "$(lib)/allocator/arena/offset"
(i32.and
(i32.add
(get_global $HEAP_BASE)

View File

@ -1,6 +1,6 @@
(module
(type $iiiiv (func (param i32 i32 i32 i32)))
(type $ii (func (param i32) (result i32)))
(type $iiiiv (func (param i32 i32 i32 i32)))
(type $II (func (param i64) (result i64)))
(type $v (func))
(import "env" "abort" (func $abort (param i32 i32 i32 i32)))

View File

@ -1,6 +1,6 @@
(module
(type $iiiiv (func (param i32 i32 i32 i32)))
(type $ii (func (param i32) (result i32)))
(type $iiiiv (func (param i32 i32 i32 i32)))
(type $II (func (param i64) (result i64)))
(type $v (func))
(import "env" "abort" (func $abort (param i32 i32 i32 i32)))

View File

@ -1,12 +1,12 @@
(module
(type $ii (func (param i32) (result i32)))
(type $iiiiv (func (param i32 i32 i32 i32)))
(type $iii (func (param i32 i32) (result i32)))
(type $iiiv (func (param i32 i32 i32)))
(type $iv (func (param i32)))
(type $iii (func (param i32 i32) (result i32)))
(type $v (func))
(import "env" "abort" (func $abort (param i32 i32 i32 i32)))
(global "$(lib)/allocator/arena/OFFSET" (mut i32) (i32.const 0))
(global "$(lib)/allocator/arena/offset" (mut i32) (i32.const 0))
(global $std/set/set (mut i32) (i32.const 0))
(global $HEAP_BASE i32 (i32.const 56))
(memory $0 1)
@ -34,7 +34,7 @@
(i32.add
(i32.add
(tee_local $1
(get_global "$(lib)/allocator/arena/OFFSET")
(get_global "$(lib)/allocator/arena/offset")
)
(get_local $0)
)
@ -91,7 +91,7 @@
)
)
)
(set_global "$(lib)/allocator/arena/OFFSET"
(set_global "$(lib)/allocator/arena/offset"
(get_local $2)
)
(get_local $1)
@ -2273,7 +2273,7 @@
)
)
(func $start (; 10 ;) (type $v)
(set_global "$(lib)/allocator/arena/OFFSET"
(set_global "$(lib)/allocator/arena/offset"
(i32.and
(i32.add
(get_global $HEAP_BASE)

View File

@ -2,15 +2,15 @@
(type $i (func (result i32)))
(type $ii (func (param i32) (result i32)))
(type $iiiiv (func (param i32 i32 i32 i32)))
(type $iii (func (param i32 i32) (result i32)))
(type $iiiv (func (param i32 i32 i32)))
(type $iv (func (param i32)))
(type $iii (func (param i32 i32) (result i32)))
(type $v (func))
(import "env" "abort" (func $abort (param i32 i32 i32 i32)))
(global "$(lib)/allocator/arena/AL_BITS" i32 (i32.const 3))
(global "$(lib)/allocator/arena/AL_SIZE" i32 (i32.const 8))
(global "$(lib)/allocator/arena/AL_MASK" i32 (i32.const 7))
(global "$(lib)/allocator/arena/OFFSET" (mut i32) (i32.const 0))
(global "$(lib)/allocator/common/alignment/BITS" i32 (i32.const 3))
(global "$(lib)/allocator/common/alignment/SIZE" i32 (i32.const 8))
(global "$(lib)/allocator/common/alignment/MASK" i32 (i32.const 7))
(global "$(lib)/allocator/arena/offset" (mut i32) (i32.const 0))
(global $std/set/set (mut i32) (i32.const 0))
(global $HEAP_BASE i32 (i32.const 56))
(memory $0 1)
@ -35,7 +35,7 @@
)
)
(set_local $1
(get_global "$(lib)/allocator/arena/OFFSET")
(get_global "$(lib)/allocator/arena/offset")
)
(set_local $2
(i32.and
@ -115,7 +115,7 @@
)
)
)
(set_global "$(lib)/allocator/arena/OFFSET"
(set_global "$(lib)/allocator/arena/offset"
(get_local $2)
)
(return
@ -433,6 +433,232 @@
)
(br $break|2)
)
(block
(set_local $3
(i32.load
(get_local $1)
)
)
(i32.store8
(block (result i32)
(set_local $5
(get_local $0)
)
(set_local $0
(i32.add
(get_local $5)
(i32.const 1)
)
)
(get_local $5)
)
(i32.load8_u
(block (result i32)
(set_local $5
(get_local $1)
)
(set_local $1
(i32.add
(get_local $5)
(i32.const 1)
)
)
(get_local $5)
)
)
)
(i32.store8
(block (result i32)
(set_local $5
(get_local $0)
)
(set_local $0
(i32.add
(get_local $5)
(i32.const 1)
)
)
(get_local $5)
)
(i32.load8_u
(block (result i32)
(set_local $5
(get_local $1)
)
(set_local $1
(i32.add
(get_local $5)
(i32.const 1)
)
)
(get_local $5)
)
)
)
(i32.store8
(block (result i32)
(set_local $5
(get_local $0)
)
(set_local $0
(i32.add
(get_local $5)
(i32.const 1)
)
)
(get_local $5)
)
(i32.load8_u
(block (result i32)
(set_local $5
(get_local $1)
)
(set_local $1
(i32.add
(get_local $5)
(i32.const 1)
)
)
(get_local $5)
)
)
)
(set_local $2
(i32.sub
(get_local $2)
(i32.const 3)
)
)
(block $break|3
(loop $continue|3
(if
(i32.ge_u
(get_local $2)
(i32.const 17)
)
(block
(block
(set_local $4
(i32.load
(i32.add
(get_local $1)
(i32.const 1)
)
)
)
(i32.store
(get_local $0)
(i32.or
(i32.shr_u
(get_local $3)
(i32.const 24)
)
(i32.shl
(get_local $4)
(i32.const 8)
)
)
)
(set_local $3
(i32.load
(i32.add
(get_local $1)
(i32.const 5)
)
)
)
(i32.store
(i32.add
(get_local $0)
(i32.const 4)
)
(i32.or
(i32.shr_u
(get_local $4)
(i32.const 24)
)
(i32.shl
(get_local $3)
(i32.const 8)
)
)
)
(set_local $4
(i32.load
(i32.add
(get_local $1)
(i32.const 9)
)
)
)
(i32.store
(i32.add
(get_local $0)
(i32.const 8)
)
(i32.or
(i32.shr_u
(get_local $3)
(i32.const 24)
)
(i32.shl
(get_local $4)
(i32.const 8)
)
)
)
(set_local $3
(i32.load
(i32.add
(get_local $1)
(i32.const 13)
)
)
)
(i32.store
(i32.add
(get_local $0)
(i32.const 12)
)
(i32.or
(i32.shr_u
(get_local $4)
(i32.const 24)
)
(i32.shl
(get_local $3)
(i32.const 8)
)
)
)
(set_local $1
(i32.add
(get_local $1)
(i32.const 16)
)
)
(set_local $0
(i32.add
(get_local $0)
(i32.const 16)
)
)
(set_local $2
(i32.sub
(get_local $2)
(i32.const 16)
)
)
)
(br $continue|3)
)
)
)
)
(br $break|2)
)
)
(block
(set_local $3
(i32.load
(get_local $1)
@ -494,46 +720,18 @@
)
)
)
(i32.store8
(block (result i32)
(set_local $5
(get_local $0)
)
(set_local $0
(i32.add
(get_local $5)
(i32.const 1)
)
)
(get_local $5)
)
(i32.load8_u
(block (result i32)
(set_local $5
(get_local $1)
)
(set_local $1
(i32.add
(get_local $5)
(i32.const 1)
)
)
(get_local $5)
)
)
)
(set_local $2
(i32.sub
(get_local $2)
(i32.const 3)
(i32.const 2)
)
)
(block $break|3
(loop $continue|3
(block $break|4
(loop $continue|4
(if
(i32.ge_u
(get_local $2)
(i32.const 17)
(i32.const 18)
)
(block
(block
@ -541,7 +739,7 @@
(i32.load
(i32.add
(get_local $1)
(i32.const 1)
(i32.const 2)
)
)
)
@ -550,11 +748,11 @@
(i32.or
(i32.shr_u
(get_local $3)
(i32.const 24)
(i32.const 16)
)
(i32.shl
(get_local $4)
(i32.const 8)
(i32.const 16)
)
)
)
@ -562,7 +760,7 @@
(i32.load
(i32.add
(get_local $1)
(i32.const 5)
(i32.const 6)
)
)
)
@ -574,11 +772,11 @@
(i32.or
(i32.shr_u
(get_local $4)
(i32.const 24)
(i32.const 16)
)
(i32.shl
(get_local $3)
(i32.const 8)
(i32.const 16)
)
)
)
@ -586,7 +784,7 @@
(i32.load
(i32.add
(get_local $1)
(i32.const 9)
(i32.const 10)
)
)
)
@ -598,11 +796,11 @@
(i32.or
(i32.shr_u
(get_local $3)
(i32.const 24)
(i32.const 16)
)
(i32.shl
(get_local $4)
(i32.const 8)
(i32.const 16)
)
)
)
@ -610,7 +808,7 @@
(i32.load
(i32.add
(get_local $1)
(i32.const 13)
(i32.const 14)
)
)
)
@ -622,11 +820,11 @@
(i32.or
(i32.shr_u
(get_local $4)
(i32.const 24)
(i32.const 16)
)
(i32.shl
(get_local $3)
(i32.const 8)
(i32.const 16)
)
)
)
@ -649,13 +847,15 @@
)
)
)
(br $continue|3)
(br $continue|4)
)
)
)
)
(br $break|2)
)
)
(block
(set_local $3
(i32.load
(get_local $1)
@ -689,46 +889,18 @@
)
)
)
(i32.store8
(block (result i32)
(set_local $5
(get_local $0)
)
(set_local $0
(i32.add
(get_local $5)
(i32.const 1)
)
)
(get_local $5)
)
(i32.load8_u
(block (result i32)
(set_local $5
(get_local $1)
)
(set_local $1
(i32.add
(get_local $5)
(i32.const 1)
)
)
(get_local $5)
)
)
)
(set_local $2
(i32.sub
(get_local $2)
(i32.const 2)
(i32.const 1)
)
)
(block $break|4
(loop $continue|4
(block $break|5
(loop $continue|5
(if
(i32.ge_u
(get_local $2)
(i32.const 18)
(i32.const 19)
)
(block
(block
@ -736,7 +908,7 @@
(i32.load
(i32.add
(get_local $1)
(i32.const 2)
(i32.const 3)
)
)
)
@ -745,11 +917,11 @@
(i32.or
(i32.shr_u
(get_local $3)
(i32.const 16)
(i32.const 8)
)
(i32.shl
(get_local $4)
(i32.const 16)
(i32.const 24)
)
)
)
@ -757,7 +929,7 @@
(i32.load
(i32.add
(get_local $1)
(i32.const 6)
(i32.const 7)
)
)
)
@ -769,11 +941,11 @@
(i32.or
(i32.shr_u
(get_local $4)
(i32.const 16)
(i32.const 8)
)
(i32.shl
(get_local $3)
(i32.const 16)
(i32.const 24)
)
)
)
@ -781,7 +953,7 @@
(i32.load
(i32.add
(get_local $1)
(i32.const 10)
(i32.const 11)
)
)
)
@ -793,11 +965,11 @@
(i32.or
(i32.shr_u
(get_local $3)
(i32.const 16)
(i32.const 8)
)
(i32.shl
(get_local $4)
(i32.const 16)
(i32.const 24)
)
)
)
@ -805,7 +977,7 @@
(i32.load
(i32.add
(get_local $1)
(i32.const 14)
(i32.const 15)
)
)
)
@ -817,11 +989,11 @@
(i32.or
(i32.shr_u
(get_local $4)
(i32.const 16)
(i32.const 8)
)
(i32.shl
(get_local $3)
(i32.const 16)
(i32.const 24)
)
)
)
@ -844,179 +1016,13 @@
)
)
)
(br $continue|4)
(br $continue|5)
)
)
)
)
(br $break|2)
)
(set_local $3
(i32.load
(get_local $1)
)
)
(i32.store8
(block (result i32)
(set_local $5
(get_local $0)
)
(set_local $0
(i32.add
(get_local $5)
(i32.const 1)
)
)
(get_local $5)
)
(i32.load8_u
(block (result i32)
(set_local $5
(get_local $1)
)
(set_local $1
(i32.add
(get_local $5)
(i32.const 1)
)
)
(get_local $5)
)
)
)
(set_local $2
(i32.sub
(get_local $2)
(i32.const 1)
)
)
(block $break|5
(loop $continue|5
(if
(i32.ge_u
(get_local $2)
(i32.const 19)
)
(block
(block
(set_local $4
(i32.load
(i32.add
(get_local $1)
(i32.const 3)
)
)
)
(i32.store
(get_local $0)
(i32.or
(i32.shr_u
(get_local $3)
(i32.const 8)
)
(i32.shl
(get_local $4)
(i32.const 24)
)
)
)
(set_local $3
(i32.load
(i32.add
(get_local $1)
(i32.const 7)
)
)
)
(i32.store
(i32.add
(get_local $0)
(i32.const 4)
)
(i32.or
(i32.shr_u
(get_local $4)
(i32.const 8)
)
(i32.shl
(get_local $3)
(i32.const 24)
)
)
)
(set_local $4
(i32.load
(i32.add
(get_local $1)
(i32.const 11)
)
)
)
(i32.store
(i32.add
(get_local $0)
(i32.const 8)
)
(i32.or
(i32.shr_u
(get_local $3)
(i32.const 8)
)
(i32.shl
(get_local $4)
(i32.const 24)
)
)
)
(set_local $3
(i32.load
(i32.add
(get_local $1)
(i32.const 15)
)
)
)
(i32.store
(i32.add
(get_local $0)
(i32.const 12)
)
(i32.or
(i32.shr_u
(get_local $4)
(i32.const 8)
)
(i32.shl
(get_local $3)
(i32.const 24)
)
)
)
(set_local $1
(i32.add
(get_local $1)
(i32.const 16)
)
)
(set_local $0
(i32.add
(get_local $0)
(i32.const 16)
)
)
(set_local $2
(i32.sub
(get_local $2)
(i32.const 16)
)
)
)
(br $continue|5)
)
)
)
)
(br $break|2)
)
)
(if
@ -2593,7 +2599,7 @@
)
)
(func $start (; 10 ;) (type $v)
(set_global "$(lib)/allocator/arena/OFFSET"
(set_global "$(lib)/allocator/arena/offset"
(i32.and
(i32.add
(get_global $HEAP_BASE)

View File

@ -1,9 +1,11 @@
(module
(type $iiiiv (func (param i32 i32 i32 i32)))
(type $i (func (result i32)))
(type $iii (func (param i32 i32) (result i32)))
(type $i (func (result i32)))
(type $iiii (func (param i32 i32 i32) (result i32)))
(type $iiiii (func (param i32 i32 i32 i32) (result i32)))
(type $iiF (func (param i32 i32) (result f64)))
(type $iiiF (func (param i32 i32 i32) (result f64)))
(type $iF (func (param i32) (result f64)))
(type $v (func))
(import "env" "abort" (func $abort (param i32 i32 i32 i32)))
@ -217,7 +219,27 @@
)
)
)
(func "$(lib)/string/String#endsWith" (; 4 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(func "$(lib)/string/String#startsWith|trampoline" (; 4 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32)
(block $N=1
(block $N=0
(block $N=invalid
(br_table $N=0 $N=1 $N=invalid
(get_local $3)
)
)
(unreachable)
)
(set_local $2
(i32.const 0)
)
)
(call "$(lib)/string/String#startsWith"
(get_local $0)
(get_local $1)
(get_local $2)
)
)
(func "$(lib)/string/String#endsWith" (; 5 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(local $3 i32)
(if
(i32.eqz
@ -302,7 +324,27 @@
)
)
)
(func "$(lib)/string/String#indexOf" (; 5 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(func "$(lib)/string/String#endsWith|trampoline" (; 6 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32)
(block $N=1
(block $N=0
(block $N=invalid
(br_table $N=0 $N=1 $N=invalid
(get_local $3)
)
)
(unreachable)
)
(set_local $2
(i32.const 2147483647)
)
)
(call "$(lib)/string/String#endsWith"
(get_local $0)
(get_local $1)
(get_local $2)
)
)
(func "$(lib)/string/String#indexOf" (; 7 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(local $3 i32)
(local $4 i32)
(local $5 i32)
@ -407,7 +449,7 @@
)
(i32.const -1)
)
(func "$(lib)/string/String#includes" (; 6 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(func "$(lib)/string/String#includes" (; 8 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(i32.ne
(call "$(lib)/string/String#indexOf"
(get_local $0)
@ -417,10 +459,50 @@
(i32.const -1)
)
)
(func $std/string/getString (; 7 ;) (type $i) (result i32)
(func "$(lib)/string/String#includes|trampoline" (; 9 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32)
(block $N=1
(block $N=0
(block $N=invalid
(br_table $N=0 $N=1 $N=invalid
(get_local $3)
)
)
(unreachable)
)
(set_local $2
(i32.const 0)
)
)
(call "$(lib)/string/String#includes"
(get_local $0)
(get_local $1)
(get_local $2)
)
)
(func "$(lib)/string/String#indexOf|trampoline" (; 10 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32)
(block $N=1
(block $N=0
(block $N=invalid
(br_table $N=0 $N=1 $N=invalid
(get_local $3)
)
)
(unreachable)
)
(set_local $2
(i32.const 0)
)
)
(call "$(lib)/string/String#indexOf"
(get_local $0)
(get_local $1)
(get_local $2)
)
)
(func $std/string/getString (; 11 ;) (type $i) (result i32)
(get_global $std/string/str)
)
(func "$(lib)/string/parse<f64>" (; 8 ;) (type $iiF) (param $0 i32) (param $1 i32) (result f64)
(func "$(lib)/string/parse<f64>" (; 12 ;) (type $iiF) (param $0 i32) (param $1 i32) (result f64)
(local $2 i32)
(local $3 i32)
(local $4 i32)
@ -785,13 +867,32 @@
(get_local $5)
)
)
(func "$(lib)/string/parseInt" (; 9 ;) (type $iiF) (param $0 i32) (param $1 i32) (result f64)
(func "$(lib)/string/parseInt" (; 13 ;) (type $iiF) (param $0 i32) (param $1 i32) (result f64)
(call "$(lib)/string/parse<f64>"
(get_local $0)
(get_local $1)
)
)
(func "$(lib)/string/parseFloat" (; 10 ;) (type $iF) (param $0 i32) (result f64)
(func "$(lib)/string/parseInt|trampoline" (; 14 ;) (type $iiiF) (param $0 i32) (param $1 i32) (param $2 i32) (result f64)
(block $N=1
(block $N=0
(block $N=invalid
(br_table $N=0 $N=1 $N=invalid
(get_local $2)
)
)
(unreachable)
)
(set_local $1
(i32.const 0)
)
)
(call "$(lib)/string/parseInt"
(get_local $0)
(get_local $1)
)
)
(func "$(lib)/string/parseFloat" (; 15 ;) (type $iF) (param $0 i32) (result f64)
(local $1 i32)
(local $2 i32)
(local $3 i32)
@ -1043,7 +1144,7 @@
(get_local $4)
)
)
(func $start (; 11 ;) (type $v)
(func $start (; 16 ;) (type $v)
(if
(i32.ne
(get_global $std/string/str)
@ -1096,10 +1197,11 @@
)
(if
(i32.eqz
(call "$(lib)/string/String#startsWith"
(call "$(lib)/string/String#startsWith|trampoline"
(get_global $std/string/str)
(i32.const 108)
(i32.const 0)
(i32.const 0)
)
)
(block
@ -1114,10 +1216,11 @@
)
(if
(i32.eqz
(call "$(lib)/string/String#endsWith"
(call "$(lib)/string/String#endsWith|trampoline"
(get_global $std/string/str)
(i32.const 128)
(i32.const 2147483647)
(i32.const 0)
(i32.const 0)
)
)
(block
@ -1132,10 +1235,11 @@
)
(if
(i32.eqz
(call "$(lib)/string/String#includes"
(call "$(lib)/string/String#includes|trampoline"
(get_global $std/string/str)
(i32.const 144)
(i32.const 0)
(i32.const 0)
)
)
(block
@ -1150,10 +1254,11 @@
)
(if
(i32.ne
(call "$(lib)/string/String#indexOf"
(call "$(lib)/string/String#indexOf|trampoline"
(get_global $std/string/str)
(i32.const 156)
(i32.const 0)
(i32.const 0)
)
(i32.const 2)
)
@ -1169,10 +1274,11 @@
)
(if
(i32.ne
(call "$(lib)/string/String#indexOf"
(call "$(lib)/string/String#indexOf|trampoline"
(get_global $std/string/str)
(i32.const 164)
(i32.const 0)
(i32.const 0)
)
(i32.const -1)
)
@ -1188,9 +1294,10 @@
)
(if
(f64.ne
(call "$(lib)/string/parseInt"
(call "$(lib)/string/parseInt|trampoline"
(i32.const 172)
(i32.const 0)
(i32.const 0)
)
(f64.const 0)
)
@ -1206,9 +1313,10 @@
)
(if
(f64.ne
(call "$(lib)/string/parseInt"
(call "$(lib)/string/parseInt|trampoline"
(i32.const 180)
(i32.const 0)
(i32.const 0)
)
(f64.const 1)
)
@ -1224,9 +1332,10 @@
)
(if
(f64.ne
(call "$(lib)/string/parseInt"
(call "$(lib)/string/parseInt|trampoline"
(i32.const 188)
(i32.const 0)
(i32.const 0)
)
(f64.const 5)
)
@ -1242,9 +1351,10 @@
)
(if
(f64.ne
(call "$(lib)/string/parseInt"
(call "$(lib)/string/parseInt|trampoline"
(i32.const 204)
(i32.const 0)
(i32.const 0)
)
(f64.const 455)
)
@ -1260,9 +1370,10 @@
)
(if
(f64.ne
(call "$(lib)/string/parseInt"
(call "$(lib)/string/parseInt|trampoline"
(i32.const 220)
(i32.const 0)
(i32.const 0)
)
(f64.const 3855)
)
@ -1278,9 +1389,10 @@
)
(if
(f64.ne
(call "$(lib)/string/parseInt"
(call "$(lib)/string/parseInt|trampoline"
(i32.const 236)
(i32.const 0)
(i32.const 0)
)
(f64.const 3855)
)
@ -1296,9 +1408,10 @@
)
(if
(f64.ne
(call "$(lib)/string/parseInt"
(call "$(lib)/string/parseInt|trampoline"
(i32.const 252)
(i32.const 0)
(i32.const 0)
)
(f64.const 11)
)
@ -1314,9 +1427,10 @@
)
(if
(f64.ne
(call "$(lib)/string/parseInt"
(call "$(lib)/string/parseInt|trampoline"
(i32.const 264)
(i32.const 0)
(i32.const 0)
)
(f64.const 1)
)

View File

@ -1,9 +1,11 @@
(module
(type $iiiiv (func (param i32 i32 i32 i32)))
(type $i (func (result i32)))
(type $iii (func (param i32 i32) (result i32)))
(type $i (func (result i32)))
(type $iiii (func (param i32 i32 i32) (result i32)))
(type $iiiii (func (param i32 i32 i32 i32) (result i32)))
(type $iiF (func (param i32 i32) (result f64)))
(type $iiiF (func (param i32 i32 i32) (result f64)))
(type $iF (func (param i32) (result f64)))
(type $v (func))
(import "env" "abort" (func $abort (param i32 i32 i32 i32)))
@ -274,7 +276,27 @@
)
)
)
(func "$(lib)/string/String#endsWith" (; 4 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(func "$(lib)/string/String#startsWith|trampoline" (; 4 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32)
(block $N=1
(block $N=0
(block $N=invalid
(br_table $N=0 $N=1 $N=invalid
(get_local $3)
)
)
(unreachable)
)
(set_local $2
(i32.const 0)
)
)
(call "$(lib)/string/String#startsWith"
(get_local $0)
(get_local $1)
(get_local $2)
)
)
(func "$(lib)/string/String#endsWith" (; 5 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(local $3 i32)
(local $4 i32)
(local $5 i32)
@ -378,7 +400,27 @@
)
)
)
(func "$(lib)/string/String#indexOf" (; 5 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(func "$(lib)/string/String#endsWith|trampoline" (; 6 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32)
(block $N=1
(block $N=0
(block $N=invalid
(br_table $N=0 $N=1 $N=invalid
(get_local $3)
)
)
(unreachable)
)
(set_local $2
(i32.const 2147483647)
)
)
(call "$(lib)/string/String#endsWith"
(get_local $0)
(get_local $1)
(get_local $2)
)
)
(func "$(lib)/string/String#indexOf" (; 7 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(local $3 i32)
(local $4 i32)
(local $5 i32)
@ -508,7 +550,7 @@
(i32.const -1)
)
)
(func "$(lib)/string/String#includes" (; 6 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(func "$(lib)/string/String#includes" (; 8 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(return
(i32.ne
(call "$(lib)/string/String#indexOf"
@ -520,12 +562,52 @@
)
)
)
(func $std/string/getString (; 7 ;) (type $i) (result i32)
(func "$(lib)/string/String#includes|trampoline" (; 9 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32)
(block $N=1
(block $N=0
(block $N=invalid
(br_table $N=0 $N=1 $N=invalid
(get_local $3)
)
)
(unreachable)
)
(set_local $2
(i32.const 0)
)
)
(call "$(lib)/string/String#includes"
(get_local $0)
(get_local $1)
(get_local $2)
)
)
(func "$(lib)/string/String#indexOf|trampoline" (; 10 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32)
(block $N=1
(block $N=0
(block $N=invalid
(br_table $N=0 $N=1 $N=invalid
(get_local $3)
)
)
(unreachable)
)
(set_local $2
(i32.const 0)
)
)
(call "$(lib)/string/String#indexOf"
(get_local $0)
(get_local $1)
(get_local $2)
)
)
(func $std/string/getString (; 11 ;) (type $i) (result i32)
(return
(get_global $std/string/str)
)
)
(func "$(lib)/string/parse<f64>" (; 8 ;) (type $iiF) (param $0 i32) (param $1 i32) (result f64)
(func "$(lib)/string/parse<f64>" (; 12 ;) (type $iiF) (param $0 i32) (param $1 i32) (result f64)
(local $2 i32)
(local $3 i32)
(local $4 i32)
@ -701,61 +783,69 @@
(br $case6|0)
)
)
(set_local $3
(i32.add
(get_local $3)
(i32.const 4)
(block
(set_local $3
(i32.add
(get_local $3)
(i32.const 4)
)
)
)
(set_local $2
(i32.sub
(get_local $2)
(set_local $2
(i32.sub
(get_local $2)
(i32.const 2)
)
)
(set_local $1
(i32.const 2)
)
(br $break|0)
)
(set_local $1
)
)
(block
(set_local $3
(i32.add
(get_local $3)
(i32.const 4)
)
)
(set_local $2
(i32.sub
(get_local $2)
(i32.const 2)
)
(br $break|0)
)
)
(set_local $3
(i32.add
(get_local $3)
(i32.const 4)
(set_local $1
(i32.const 8)
)
(br $break|0)
)
(set_local $2
(i32.sub
(get_local $2)
(i32.const 2)
)
)
(set_local $1
(i32.const 8)
)
(br $break|0)
)
)
(set_local $3
(i32.add
(get_local $3)
(i32.const 4)
(block
(set_local $3
(i32.add
(get_local $3)
(i32.const 4)
)
)
)
(set_local $2
(i32.sub
(get_local $2)
(i32.const 2)
(set_local $2
(i32.sub
(get_local $2)
(i32.const 2)
)
)
(set_local $1
(i32.const 16)
)
(br $break|0)
)
(set_local $1
(i32.const 16)
)
(br $break|0)
)
(set_local $1
(i32.const 10)
(block
(set_local $1
(i32.const 10)
)
)
)
(set_local $1
@ -927,7 +1017,7 @@
)
)
)
(func "$(lib)/string/parseInt" (; 9 ;) (type $iiF) (param $0 i32) (param $1 i32) (result f64)
(func "$(lib)/string/parseInt" (; 13 ;) (type $iiF) (param $0 i32) (param $1 i32) (result f64)
(return
(call "$(lib)/string/parse<f64>"
(get_local $0)
@ -935,7 +1025,26 @@
)
)
)
(func "$(lib)/string/parseFloat" (; 10 ;) (type $iF) (param $0 i32) (result f64)
(func "$(lib)/string/parseInt|trampoline" (; 14 ;) (type $iiiF) (param $0 i32) (param $1 i32) (param $2 i32) (result f64)
(block $N=1
(block $N=0
(block $N=invalid
(br_table $N=0 $N=1 $N=invalid
(get_local $2)
)
)
(unreachable)
)
(set_local $1
(i32.const 0)
)
)
(call "$(lib)/string/parseInt"
(get_local $0)
(get_local $1)
)
)
(func "$(lib)/string/parseFloat" (; 15 ;) (type $iF) (param $0 i32) (result f64)
(local $1 i32)
(local $2 i32)
(local $3 i32)
@ -1218,7 +1327,7 @@
)
)
)
(func $start (; 11 ;) (type $v)
(func $start (; 16 ;) (type $v)
(if
(i32.eqz
(i32.eq
@ -1277,10 +1386,11 @@
)
(if
(i32.eqz
(call "$(lib)/string/String#startsWith"
(call "$(lib)/string/String#startsWith|trampoline"
(get_global $std/string/str)
(i32.const 108)
(i32.const 0)
(i32.const 0)
)
)
(block
@ -1295,10 +1405,11 @@
)
(if
(i32.eqz
(call "$(lib)/string/String#endsWith"
(call "$(lib)/string/String#endsWith|trampoline"
(get_global $std/string/str)
(i32.const 128)
(i32.const 2147483647)
(i32.const 0)
(i32.const 0)
)
)
(block
@ -1313,10 +1424,11 @@
)
(if
(i32.eqz
(call "$(lib)/string/String#includes"
(call "$(lib)/string/String#includes|trampoline"
(get_global $std/string/str)
(i32.const 144)
(i32.const 0)
(i32.const 0)
)
)
(block
@ -1332,10 +1444,11 @@
(if
(i32.eqz
(i32.eq
(call "$(lib)/string/String#indexOf"
(call "$(lib)/string/String#indexOf|trampoline"
(get_global $std/string/str)
(i32.const 156)
(i32.const 0)
(i32.const 0)
)
(i32.const 2)
)
@ -1353,10 +1466,11 @@
(if
(i32.eqz
(i32.eq
(call "$(lib)/string/String#indexOf"
(call "$(lib)/string/String#indexOf|trampoline"
(get_global $std/string/str)
(i32.const 164)
(i32.const 0)
(i32.const 0)
)
(i32.const -1)
)
@ -1374,9 +1488,10 @@
(if
(i32.eqz
(f64.eq
(call "$(lib)/string/parseInt"
(call "$(lib)/string/parseInt|trampoline"
(i32.const 172)
(i32.const 0)
(i32.const 0)
)
(f64.const 0)
)
@ -1394,9 +1509,10 @@
(if
(i32.eqz
(f64.eq
(call "$(lib)/string/parseInt"
(call "$(lib)/string/parseInt|trampoline"
(i32.const 180)
(i32.const 0)
(i32.const 0)
)
(f64.const 1)
)
@ -1414,9 +1530,10 @@
(if
(i32.eqz
(f64.eq
(call "$(lib)/string/parseInt"
(call "$(lib)/string/parseInt|trampoline"
(i32.const 188)
(i32.const 0)
(i32.const 0)
)
(f64.const 5)
)
@ -1434,9 +1551,10 @@
(if
(i32.eqz
(f64.eq
(call "$(lib)/string/parseInt"
(call "$(lib)/string/parseInt|trampoline"
(i32.const 204)
(i32.const 0)
(i32.const 0)
)
(f64.const 455)
)
@ -1454,9 +1572,10 @@
(if
(i32.eqz
(f64.eq
(call "$(lib)/string/parseInt"
(call "$(lib)/string/parseInt|trampoline"
(i32.const 220)
(i32.const 0)
(i32.const 0)
)
(f64.const 3855)
)
@ -1474,9 +1593,10 @@
(if
(i32.eqz
(f64.eq
(call "$(lib)/string/parseInt"
(call "$(lib)/string/parseInt|trampoline"
(i32.const 236)
(i32.const 0)
(i32.const 0)
)
(f64.const 3855)
)
@ -1494,9 +1614,10 @@
(if
(i32.eqz
(f64.eq
(call "$(lib)/string/parseInt"
(call "$(lib)/string/parseInt|trampoline"
(i32.const 252)
(i32.const 0)
(i32.const 0)
)
(f64.const 11)
)
@ -1514,9 +1635,10 @@
(if
(i32.eqz
(f64.eq
(call "$(lib)/string/parseInt"
(call "$(lib)/string/parseInt|trampoline"
(i32.const 264)
(i32.const 0)
(i32.const 0)
)
(f64.const 1)
)

View File

@ -0,0 +1,8 @@
type foo = () => void;
type foo = (() => void) | null;
type foo = (a: i32) => i32;
type foo = (a?: i32) => i32;
type foo = (this: AClass, a: i32) => i32;
type foo = () => () => void;
type foo = () => (() => void) | null;
type foo = (this: AClass, a: i32) => ((this: BClass, b?: f32) => i32) | null;

View File

@ -0,0 +1,8 @@
type foo = () => void;
type foo = (() => void) | null;
type foo = (a: i32) => i32;
type foo = (a?: i32) => i32;
type foo = (this: AClass, a: i32) => i32;
type foo = () => () => void;
type foo = () => (() => void) | null;
type foo = (this: AClass, a: i32) => ((this: BClass, b?: f32) => i32) | null;

View File

@ -5,8 +5,9 @@
],
"defaultSeverity": "warning",
"rules": {
"as-diagnostics": true,
"as-types": { "severity": "error" },
"as-internal-case": true,
"as-internal-diagnostics": true,
"adjacent-overload-signatures": true,
"ban-types": [ true, ["Object"], ["any"], ["undefined"], ["never"] ],
"curly": [true, "ignore-same-line"],