Skip to content

Commit 4baff99

Browse files
committed
Refactoring; Add tslint fwiw
1 parent d7c069b commit 4baff99

File tree

15 files changed

+647
-333
lines changed

15 files changed

+647
-333
lines changed

package-lock.json

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

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"long": "^3.2.0",
2929
"ts-loader": "^3.2.0",
3030
"ts-node": "^4.0.2",
31+
"tslint": "^5.8.0",
3132
"typescript": "^2.6.2",
3233
"webpack": "^3.10.0"
3334
},
@@ -45,7 +46,8 @@
4546
"test:config:src": "tsc --noEmit -p src --diagnostics --listFiles",
4647
"test:parser": "node tests/parser",
4748
"test:compiler": "node tests/compiler",
48-
"test": "npm run test:config --scripts-prepend-node-path && npm run test:parser --scripts-prepend-node-path && npm run test:compiler --scripts-prepend-node-path"
49+
"test": "npm run test:config --scripts-prepend-node-path && npm run test:parser --scripts-prepend-node-path && npm run test:compiler --scripts-prepend-node-path",
50+
"lint": "tslint --project src"
4951
},
5052
"files": [
5153
"bin/",

src/ast.ts

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,27 @@
1-
import { GETTER_PREFIX, SETTER_PREFIX, PATH_DELIMITER, PARENT_SUBST, STATIC_DELIMITER, INSTANCE_DELIMITER } from "./constants";
2-
import { Token, Tokenizer, operatorTokenToString, Range } from "./tokenizer";
3-
import { CharCode } from "./util/charcode";
4-
import { I64 } from "./util/i64";
5-
import { normalize as normalizePath, resolve as resolvePath } from "./util/path";
1+
import {
2+
PATH_DELIMITER,
3+
STATIC_DELIMITER,
4+
INSTANCE_DELIMITER
5+
} from "./constants";
6+
7+
import {
8+
Token,
9+
Tokenizer,
10+
Range
11+
} from "./tokenizer";
12+
13+
import{
14+
CharCode
15+
} from "./util/charcode";
16+
17+
import {
18+
I64
19+
} from "./util/i64";
20+
21+
import {
22+
normalize as normalizePath,
23+
resolve as resolvePath
24+
} from "./util/path";
625

726
export { Range } from "./tokenizer";
827

@@ -489,7 +508,7 @@ export abstract class Node {
489508
(stmt.name = identifier).parent = stmt;
490509
for (i = 0, k = (stmt.typeParameters = typeParameters).length; i < k; ++i) typeParameters[i].parent = stmt;
491510
for (i = 0, k = (stmt.parameters = parameters).length; i < k; ++i) parameters[i].parent = stmt;
492-
if (stmt.returnType = returnType) (<TypeNode>returnType).parent = stmt;;
511+
if (stmt.returnType = returnType) (<TypeNode>returnType).parent = stmt;
493512
if (stmt.statements = statements) for (i = 0, k = (<Statement[]>statements).length; i < k; ++i) (<Statement[]>statements)[i].parent = stmt;
494513
if (stmt.modifiers = modifiers) for (i = 0, k = (<Modifier[]>modifiers).length; i < k; ++i) (<Modifier[]>modifiers)[i].parent = stmt;
495514
if (stmt.decorators = decorators) for (i = 0, k = (<Decorator[]>decorators).length; i < k; ++i) (<Decorator[]>decorators)[i].parent = stmt;
@@ -750,7 +769,7 @@ export class BinaryExpression extends Expression {
750769
serialize(sb: string[]): void {
751770
this.left.serialize(sb);
752771
sb.push(" ");
753-
sb.push(operatorTokenToString(this.operator));
772+
sb.push(Token.operatorToString(this.operator));
754773
sb.push(" ");
755774
this.right.serialize(sb);
756775
}
@@ -995,7 +1014,7 @@ export class UnaryPrefixExpression extends UnaryExpression {
9951014
kind = NodeKind.UNARYPREFIX;
9961015

9971016
serialize(sb: string[]): void {
998-
sb.push(operatorTokenToString(this.operator));
1017+
sb.push(Token.operatorToString(this.operator));
9991018
this.operand.serialize(sb);
10001019
}
10011020
}

src/builtins.ts

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,38 @@
1-
import { Compiler, Target, ConversionKind, typeToNativeType, typeToNativeOne, typeToNativeZero } from "./compiler";
2-
import { DiagnosticCode } from "./diagnostics";
3-
import { Node, Expression, IdentifierExpression } from "./ast";
4-
import { Type } from "./types";
5-
import { Module, ExpressionRef, UnaryOp, BinaryOp, HostOp, NativeType, FunctionTypeRef } from "./module";
6-
import { Program, ElementFlags, Element, Global, FunctionPrototype, Local } from "./program";
1+
import {
2+
Compiler,
3+
Target,
4+
ConversionKind
5+
} from "./compiler";
6+
7+
import {
8+
DiagnosticCode
9+
} from "./diagnostics";
10+
11+
import {
12+
Node,
13+
Expression
14+
} from "./ast";
15+
16+
import {
17+
Type
18+
} from "./types";
19+
20+
import {
21+
Module,
22+
UnaryOp,
23+
BinaryOp,
24+
HostOp,
25+
NativeType,
26+
ExpressionRef,
27+
FunctionTypeRef
28+
} from "./module";
29+
30+
import {
31+
Program,
32+
Global,
33+
FunctionPrototype,
34+
Local
35+
} from "./program";
736

837
/** Initializes the specified program with built-in functions. */
938
export function initialize(program: Program): void {
@@ -149,7 +178,7 @@ export function compileGetGlobal(compiler: Compiler, global: Global): Expression
149178
return compiler.module.createF64(Infinity);
150179

151180
case "HEAP_BASE": // constant, but never inlined
152-
return compiler.module.createGetGlobal("HEAP_BASE", typeToNativeType(compiler.currentType = <Type>global.type));
181+
return compiler.module.createGetGlobal("HEAP_BASE", (compiler.currentType = <Type>global.type).toNativeType());
153182

154183
default:
155184
throw new Error("not implemented: " + global.internalName);
@@ -539,7 +568,7 @@ export function compileCall(compiler: Compiler, prototype: FunctionPrototype, ty
539568
return module.createUnreachable();
540569
arg0 = compiler.compileExpression(operands[0], usizeType); // reports
541570
if ((compiler.currentType = typeArguments[0]) != Type.void)
542-
return module.createLoad(typeArguments[0].byteSize, typeArguments[0].isSignedInteger, arg0, typeToNativeType(typeArguments[0]));
571+
return module.createLoad(typeArguments[0].byteSize, typeArguments[0].isSignedInteger, arg0, typeArguments[0].toNativeType());
543572
break;
544573

545574
case "store": // store<T>(offset: usize, value: T) -> void
@@ -550,7 +579,7 @@ export function compileCall(compiler: Compiler, prototype: FunctionPrototype, ty
550579
arg1 = compiler.compileExpression(operands[1], typeArguments[0]); // reports
551580
compiler.currentType = Type.void;
552581
if (typeArguments[0] != Type.void)
553-
return module.createStore(typeArguments[0].byteSize, arg0, arg1, typeToNativeType(typeArguments[0]));
582+
return module.createStore(typeArguments[0].byteSize, arg0, arg1, typeArguments[0].toNativeType());
554583
break;
555584

556585
case "sizeof": // sizeof<T>() -> usize
@@ -685,7 +714,7 @@ export function compileCall(compiler: Compiler, prototype: FunctionPrototype, ty
685714
return module.createUnreachable();
686715
}
687716
arg0 = compiler.compileExpression(operands[0], Type.i32); // reports
688-
arg1 = operands.length > 1 ? compiler.compileExpression(operands[1], usizeType) : typeToNativeZero(module, usizeType); // TODO: string type
717+
arg1 = operands.length > 1 ? compiler.compileExpression(operands[1], usizeType) : usizeType.toNativeZero(module); // TODO: string type
689718
compiler.currentType = Type.void;
690719
return compiler.options.noAssert
691720
? module.createNop()

0 commit comments

Comments
 (0)