Skip to content

Commit d0b189b

Browse files
committed
CString/CArray was an illusion; Update and test tsconfig files
1 parent 0228ab9 commit d0b189b

33 files changed

+477
-509
lines changed

assembly.d.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ declare function unreachable(): any; // sic
7878
declare const NaN: f32 | f64;
7979
/** Positive infinity as a 32-bit or 64-bit float depending on context. */
8080
declare const Infinity: f32 | f64;
81+
/** Heap start offset. */
82+
declare const HEAP_START: usize;
8183
/** Determines the byte size of the specified core or class type. Compiles to a constant. */
8284
declare function sizeof<T>(): usize;
8385
/** Changes the type of a value to another one. Useful for casting class instances to their pointer values and vice-versa. */
@@ -100,6 +102,13 @@ declare function struct(): any;
100102

101103
// Standard library (not yet implemented)
102104

103-
/// <reference path="./std/carray.d.ts" />
104-
/// <reference path="./std/cstring.d.ts" />
105105
/// <reference path="./std/heap.d.ts" />
106+
107+
interface Array<T> {}
108+
interface Boolean {}
109+
interface Function {}
110+
interface IArguments {}
111+
interface Number {}
112+
interface Object {}
113+
interface RegExp {}
114+
interface String {}

assembly.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"extends": "./tsconfig-base.json",
3+
"compilerOptions": {
4+
"target": "esnext",
5+
"noLib": true,
6+
"types": [],
7+
"rootDirs": [
8+
"./std/assembly",
9+
"./node_modules"
10+
]
11+
},
12+
"files": [
13+
"./assembly.d.ts"
14+
]
15+
}

package.json

+7-3
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,13 @@
3939
"scripts": {
4040
"build": "webpack",
4141
"clean": "rm dist/assemblyscript.*",
42-
"test:parser": "ts-node -P src tests/parser",
43-
"test:compiler": "ts-node -P src tests/compiler",
44-
"test": "npm run test:parser && npm run test:compiler"
42+
"test:config": "npm run test:config:assembly --scripts-prepend-node-path && npm run test:config:portable --scripts-prepend-node-path && npm run test:config:src --scripts-prepend-node-path",
43+
"test:config:assembly": "tsc --noEmit -p std/assembly --diagnostics --listFiles",
44+
"test:config:portable": "tsc --noEmit -p std/portable --diagnostics --listFiles",
45+
"test:config:src": "tsc --noEmit -p src --diagnostics --listFiles",
46+
"test:parser": "node tests/parser",
47+
"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"
4549
},
4650
"files": [
4751
"assembly.d.ts",

portable-assembly.d.ts

+95
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,100 @@ declare function trunc<T = f32 | f64>(value: T): T;
4444
/** Emits an unreachable operation that results in a runtime error when executed. */
4545
declare function unreachable(): any; // sic
4646

47+
/** Changes the type of a value to another one. Useful for casting class instances to their pointer values and vice-versa. */
48+
declare function changetype<T1,T2>(value: T1): T2;
4749
/** Traps if the specified value evaluates to `false`. */
4850
declare function assert(isTrue: bool): void;
51+
52+
// Portable standard library
53+
// Everything marked @deprecated is a temporary filler. Do not use.
54+
55+
declare const NaN: f32 | f64;
56+
declare const Infinity: f32 | f64;
57+
58+
declare class Array<T> {
59+
[key: number]: T;
60+
length: i32;
61+
constructor(capacity?: i32);
62+
push(value: T): void;
63+
pop(): T;
64+
join(delim: string): string;
65+
slice(from: i32, to?: i32): T[];
66+
splice(index: i32, count: i32): T[];
67+
}
68+
69+
declare class Uint8Array extends Array<u8> {}
70+
declare class Uint16Array extends Array<u16> {}
71+
declare class Uint32Array extends Array<u32> {}
72+
declare class Int8Array extends Array<i8> {}
73+
declare class Int16Array extends Array<i16> {}
74+
declare class Int32Array extends Array<i32> {}
75+
76+
declare class String {
77+
static fromCharCode(ls: i32, hs?: i32): string;
78+
readonly length: i32;
79+
indexOf(subject: string): i32;
80+
charCodeAt(index: i32): i32;
81+
substring(from: i32, to?: i32): string;
82+
startsWith(subject: string): bool;
83+
endsWith(subject: string): bool;
84+
replace(search: string, replacement: string): string;
85+
}
86+
87+
declare class Boolean {}
88+
89+
declare class Number {
90+
toString(radix: i32): string;
91+
}
92+
93+
declare class Object {}
94+
95+
declare class Function {
96+
/** @deprecated */
97+
apply(subject: any): any;
98+
}
99+
100+
declare class RegExp {}
101+
102+
declare interface IArguments {}
103+
104+
declare class Error {
105+
constructor(message: string);
106+
message: string;
107+
}
108+
109+
declare class Symbol {
110+
static iterator: symbol;
111+
}
112+
113+
declare class Set<T> {
114+
constructor(entries?: T[]);
115+
add(value: T): void;
116+
has(value: T): bool;
117+
clear(): void;
118+
[Symbol.iterator](): Iterator<T>;
119+
}
120+
121+
declare class Map<K,V> {
122+
constructor(entries?: [K, V][]);
123+
set(key: K, value: V): void;
124+
has(key: K): bool;
125+
get(key: K): V | null;
126+
clear(): void;
127+
[Symbol.iterator](): Iterator<[K, V]>;
128+
}
129+
130+
declare interface Iterator<T> {}
131+
132+
declare namespace JSON {
133+
/** @deprecated */
134+
function stringify(subject: any): string;
135+
}
136+
137+
declare namespace console {
138+
/** @deprecated */
139+
function log(message: string): void;
140+
}
141+
142+
/** @deprecated */
143+
declare function parseFloat(str: string): f64;

portable-assembly.js

+1
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ AssertionError.prototype.name = "AssertionError";
2727
AssertionError.prototype.message = "assertion failed";
2828

2929
globalScope["assert"] = function assert(isTrue) { if (!isTrue) throw new AssertionError(); };
30+
globalScope["changetype"] = function changetype(value) { return value; }

portable-assembly.json

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"extends": "./tsconfig-base.json",
3+
"compilerOptions": {
4+
"target": "es5",
5+
"module": "commonjs",
6+
"downlevelIteration": true,
7+
"preserveConstEnums": true,
8+
"noLib": true,
9+
"types": [],
10+
"rootDirs": [
11+
"./std/portable",
12+
"./node_modules"
13+
],
14+
"allowJs": true
15+
},
16+
"files": [
17+
"./portable-assembly.d.ts",
18+
"./portable-assembly.js",
19+
"./std/portable/heap.d.ts",
20+
"./std/portable/heap.js"
21+
]
22+
}

src/ast.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ export class FloatLiteralExpression extends LiteralExpression {
475475
value: f64;
476476

477477
serialize(sb: string[]): void {
478-
sb.push(this.value.toString());
478+
sb.push(this.value.toString(10));
479479
}
480480
}
481481

@@ -1030,7 +1030,7 @@ export class BreakStatement extends Statement {
10301030
serialize(sb: string[]): void {
10311031
if (this.label) {
10321032
sb.push("break ");
1033-
(<IdentifierExpression>this.label).serialize(name);
1033+
(<IdentifierExpression>this.label).serialize(sb);
10341034
} else
10351035
sb.push("break");
10361036
}

src/diagnostics.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export function formatDiagnosticMessage(message: DiagnosticMessage, useColors: b
8585
sb.push(diagnosticCategoryToString(message.category));
8686
if (useColors) sb.push(colorReset);
8787
sb.push(" AS");
88-
sb.push(message.code.toString());
88+
sb.push(message.code.toString(10));
8989
sb.push(": ");
9090
sb.push(message.message);
9191

@@ -109,9 +109,9 @@ export function formatDiagnosticMessage(message: DiagnosticMessage, useColors: b
109109
sb.push(" in ");
110110
sb.push(range.source.path);
111111
sb.push("(");
112-
sb.push(line.toString());
112+
sb.push(line.toString(10));
113113
sb.push(",");
114-
sb.push(column.toString());
114+
sb.push(column.toString(10));
115115
sb.push(")");
116116
}
117117
return sb.join("");

0 commit comments

Comments
 (0)