Skip to content

Commit 423533c

Browse files
authored
Implement function types / indirect calls / trampolines (#39)
1 parent 5d5f458 commit 423533c

67 files changed

Lines changed: 7087 additions & 5351 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
![](https://s.gravatar.com/avatar/f105de3decfafc734b8eabe9a960b25d?size=64) AssemblyScript
1+
![](https://avatars1.githubusercontent.com/u/28916798?s=64) AssemblyScript
22
=================
33

44
[![npm](https://img.shields.io/npm/v/assemblyscript.svg)](https://www.npmjs.com/package/assemblyscript)

dist/asc.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/asc.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/assemblyscript.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/assemblyscript.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/ugc/assembly/ugc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class ObjectHeader {
2121
///////////////////////////////// Fields ////////////////////////////////////
2222

2323
// the next and prev pointer with tags in the least significant two bits that
24-
// would otherwise be zero (blocks are guaranteed to be aligned to 4/8 bytes)
24+
// would otherwise be zero (blocks are guaranteed to be aligned to 8 bytes)
2525
tagged_next: usize;
2626
tagged_prev: usize;
2727

lib/tslint/asFormatter.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,18 @@ export class Formatter extends AbstractFormatter {
3535
} else {
3636
var message = this.lastSeverity ? "\n" : "";
3737
switch (this.lastSeverity = failure.getRuleSeverity()) {
38-
case "warning":
38+
case "warning": {
3939
message += colorYellow + "WARNING:" + colorReset;
4040
break;
41-
case "error":
41+
}
42+
case "error": {
4243
message += colorRed + "ERROR:" + colorReset;
4344
break;
44-
default:
45+
}
46+
default: {
4547
message += failure.getRuleSeverity();
4648
break;
49+
}
4750
}
4851
this.lastFailure = failureString;
4952
return message + " " + failureString + " [" + ruleName + "]\n in " + fileName + positionTuple;

lib/tslint/asTypesRule.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export class Rule extends Lint.Rules.AbstractRule {
1212
}
1313

1414
class DiagnosticsWalker extends Lint.RuleWalker {
15+
1516
visitVariableDeclaration(node: ts.VariableDeclaration) {
1617
if (
1718
!node.type && !node.initializer &&
@@ -20,16 +21,19 @@ class DiagnosticsWalker extends Lint.RuleWalker {
2021
this.addFailureAtNode(node, Rule.MISSING_TYPE_OR_INITIALIZER);
2122
}
2223
}
24+
2325
visitPropertyDeclaration(node: ts.PropertyDeclaration) {
2426
if (!node.type && !node.initializer) {
2527
this.addFailureAtNode(node, Rule.MISSING_TYPE_OR_INITIALIZER);
2628
}
2729
}
30+
2831
visitParameterDeclaration(node: ts.ParameterDeclaration) {
2932
if (!node.type && !node.initializer) {
3033
this.addFailureAtNode(node, Rule.MISSING_TYPE_OR_INITIALIZER);
3134
}
3235
}
36+
3337
visitFunctionDeclaration(node: ts.FunctionDeclaration) {
3438
if (!node.type) {
3539
this.addFailureAtNode(node, Rule.MISSING_RETURN_TYPE);
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
"use strict";
2+
var __extends = (this && this.__extends) || (function () {
3+
var extendStatics = Object.setPrototypeOf ||
4+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
6+
return function (d, b) {
7+
extendStatics(d, b);
8+
function __() { this.constructor = d; }
9+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
10+
};
11+
})();
12+
exports.__esModule = true;
13+
var ts = require("typescript");
14+
var Lint = require("tslint");
15+
var tsutils_1 = require("tsutils");
16+
var Rule = /** @class */ (function (_super) {
17+
__extends(Rule, _super);
18+
function Rule() {
19+
return _super !== null && _super.apply(this, arguments) || this;
20+
}
21+
Rule.prototype.apply = function (sourceFile) {
22+
return this.applyWithWalker(new DiagnosticsWalker(sourceFile, this.getOptions()));
23+
};
24+
Rule.NOT_BRACED = "Multi-line case clauses should be braced.";
25+
return Rule;
26+
}(Lint.Rules.AbstractRule));
27+
exports.Rule = Rule;
28+
var DiagnosticsWalker = /** @class */ (function (_super) {
29+
__extends(DiagnosticsWalker, _super);
30+
function DiagnosticsWalker() {
31+
return _super !== null && _super.apply(this, arguments) || this;
32+
}
33+
DiagnosticsWalker.prototype.visitDefaultClause = function (node) {
34+
this.checkDefaultOrCaseClause(node);
35+
_super.prototype.visitDefaultClause.call(this, node);
36+
};
37+
DiagnosticsWalker.prototype.visitCaseClause = function (node) {
38+
this.checkDefaultOrCaseClause(node);
39+
_super.prototype.visitCaseClause.call(this, node);
40+
};
41+
DiagnosticsWalker.prototype.checkDefaultOrCaseClause = function (node) {
42+
var count = node.statements.length;
43+
if (count > 1) {
44+
this.addFailureAtNode(node, Rule.NOT_BRACED);
45+
}
46+
else if (count == 1) {
47+
var stmt = node.statements[0];
48+
if (stmt.kind != ts.SyntaxKind.Block) {
49+
if (!tsutils_1.isSameLine(node.getSourceFile(), node.getStart(), stmt.getStart())) {
50+
this.addFailureAtNode(node, Rule.NOT_BRACED);
51+
}
52+
}
53+
}
54+
};
55+
return DiagnosticsWalker;
56+
}(Lint.RuleWalker));
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import * as ts from "typescript";
2+
import * as Lint from "tslint";
3+
import { isSameLine } from "tsutils";
4+
5+
export class Rule extends Lint.Rules.AbstractRule {
6+
7+
static NOT_BRACED = "Multi-line case clauses should be braced.";
8+
9+
apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
10+
return this.applyWithWalker(new DiagnosticsWalker(sourceFile, this.getOptions()));
11+
}
12+
}
13+
14+
class DiagnosticsWalker extends Lint.RuleWalker {
15+
16+
visitDefaultClause(node: ts.DefaultClause) {
17+
this.checkDefaultOrCaseClause(node);
18+
super.visitDefaultClause(node);
19+
}
20+
21+
visitCaseClause(node: ts.CaseClause) {
22+
this.checkDefaultOrCaseClause(node);
23+
super.visitCaseClause(node);
24+
}
25+
26+
private checkDefaultOrCaseClause(node: ts.DefaultClause | ts.CaseClause) {
27+
var count = node.statements.length;
28+
if (count > 1) {
29+
this.addFailureAtNode(node, Rule.NOT_BRACED);
30+
} else if (count == 1) {
31+
let stmt = node.statements[0];
32+
if (stmt.kind != ts.SyntaxKind.Block) {
33+
if (!isSameLine(node.getSourceFile(), node.getStart(), stmt.getStart())) {
34+
this.addFailureAtNode(node, Rule.NOT_BRACED);
35+
}
36+
}
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)