Skip to content

Commit

Permalink
CString/CArray was an illusion; Update and test tsconfig files
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodeIO committed Dec 11, 2017
1 parent 0228ab9 commit d0b189b
Show file tree
Hide file tree
Showing 33 changed files with 477 additions and 509 deletions.
13 changes: 11 additions & 2 deletions assembly.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ declare function unreachable(): any; // sic
declare const NaN: f32 | f64;
/** Positive infinity as a 32-bit or 64-bit float depending on context. */
declare const Infinity: f32 | f64;
/** Heap start offset. */
declare const HEAP_START: usize;
/** Determines the byte size of the specified core or class type. Compiles to a constant. */
declare function sizeof<T>(): usize;
/** Changes the type of a value to another one. Useful for casting class instances to their pointer values and vice-versa. */
Expand All @@ -100,6 +102,13 @@ declare function struct(): any;

// Standard library (not yet implemented)

/// <reference path="./std/carray.d.ts" />
/// <reference path="./std/cstring.d.ts" />
/// <reference path="./std/heap.d.ts" />

interface Array<T> {}
interface Boolean {}
interface Function {}
interface IArguments {}
interface Number {}
interface Object {}
interface RegExp {}
interface String {}
15 changes: 15 additions & 0 deletions assembly.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"extends": "./tsconfig-base.json",
"compilerOptions": {
"target": "esnext",
"noLib": true,
"types": [],
"rootDirs": [
"./std/assembly",
"./node_modules"
]
},
"files": [
"./assembly.d.ts"
]
}
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,13 @@
"scripts": {
"build": "webpack",
"clean": "rm dist/assemblyscript.*",
"test:parser": "ts-node -P src tests/parser",
"test:compiler": "ts-node -P src tests/compiler",
"test": "npm run test:parser && npm run test:compiler"
"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",
"test:config:assembly": "tsc --noEmit -p std/assembly --diagnostics --listFiles",
"test:config:portable": "tsc --noEmit -p std/portable --diagnostics --listFiles",
"test:config:src": "tsc --noEmit -p src --diagnostics --listFiles",
"test:parser": "node tests/parser",
"test:compiler": "node tests/compiler",
"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"
},
"files": [
"assembly.d.ts",
Expand Down
95 changes: 95 additions & 0 deletions portable-assembly.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,100 @@ declare function trunc<T = f32 | f64>(value: T): T;
/** Emits an unreachable operation that results in a runtime error when executed. */
declare function unreachable(): any; // sic

/** Changes the type of a value to another one. Useful for casting class instances to their pointer values and vice-versa. */
declare function changetype<T1,T2>(value: T1): T2;
/** Traps if the specified value evaluates to `false`. */
declare function assert(isTrue: bool): void;

// Portable standard library
// Everything marked @deprecated is a temporary filler. Do not use.

declare const NaN: f32 | f64;
declare const Infinity: f32 | f64;

declare class Array<T> {
[key: number]: T;
length: i32;
constructor(capacity?: i32);
push(value: T): void;
pop(): T;
join(delim: string): string;
slice(from: i32, to?: i32): T[];
splice(index: i32, count: i32): T[];
}

declare class Uint8Array extends Array<u8> {}
declare class Uint16Array extends Array<u16> {}
declare class Uint32Array extends Array<u32> {}
declare class Int8Array extends Array<i8> {}
declare class Int16Array extends Array<i16> {}
declare class Int32Array extends Array<i32> {}

declare class String {
static fromCharCode(ls: i32, hs?: i32): string;
readonly length: i32;
indexOf(subject: string): i32;
charCodeAt(index: i32): i32;
substring(from: i32, to?: i32): string;
startsWith(subject: string): bool;
endsWith(subject: string): bool;
replace(search: string, replacement: string): string;
}

declare class Boolean {}

declare class Number {
toString(radix: i32): string;
}

declare class Object {}

declare class Function {
/** @deprecated */
apply(subject: any): any;
}

declare class RegExp {}

declare interface IArguments {}

declare class Error {
constructor(message: string);
message: string;
}

declare class Symbol {
static iterator: symbol;
}

declare class Set<T> {
constructor(entries?: T[]);
add(value: T): void;
has(value: T): bool;
clear(): void;
[Symbol.iterator](): Iterator<T>;
}

declare class Map<K,V> {
constructor(entries?: [K, V][]);
set(key: K, value: V): void;
has(key: K): bool;
get(key: K): V | null;
clear(): void;
[Symbol.iterator](): Iterator<[K, V]>;
}

declare interface Iterator<T> {}

declare namespace JSON {
/** @deprecated */
function stringify(subject: any): string;
}

declare namespace console {
/** @deprecated */
function log(message: string): void;
}

/** @deprecated */
declare function parseFloat(str: string): f64;
1 change: 1 addition & 0 deletions portable-assembly.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ AssertionError.prototype.name = "AssertionError";
AssertionError.prototype.message = "assertion failed";

globalScope["assert"] = function assert(isTrue) { if (!isTrue) throw new AssertionError(); };
globalScope["changetype"] = function changetype(value) { return value; }
22 changes: 22 additions & 0 deletions portable-assembly.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"extends": "./tsconfig-base.json",
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"downlevelIteration": true,
"preserveConstEnums": true,
"noLib": true,
"types": [],
"rootDirs": [
"./std/portable",
"./node_modules"
],
"allowJs": true
},
"files": [
"./portable-assembly.d.ts",
"./portable-assembly.js",
"./std/portable/heap.d.ts",
"./std/portable/heap.js"
]
}
4 changes: 2 additions & 2 deletions src/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ export class FloatLiteralExpression extends LiteralExpression {
value: f64;

serialize(sb: string[]): void {
sb.push(this.value.toString());
sb.push(this.value.toString(10));
}
}

Expand Down Expand Up @@ -1030,7 +1030,7 @@ export class BreakStatement extends Statement {
serialize(sb: string[]): void {
if (this.label) {
sb.push("break ");
(<IdentifierExpression>this.label).serialize(name);
(<IdentifierExpression>this.label).serialize(sb);
} else
sb.push("break");
}
Expand Down
6 changes: 3 additions & 3 deletions src/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export function formatDiagnosticMessage(message: DiagnosticMessage, useColors: b
sb.push(diagnosticCategoryToString(message.category));
if (useColors) sb.push(colorReset);
sb.push(" AS");
sb.push(message.code.toString());
sb.push(message.code.toString(10));
sb.push(": ");
sb.push(message.message);

Expand All @@ -109,9 +109,9 @@ export function formatDiagnosticMessage(message: DiagnosticMessage, useColors: b
sb.push(" in ");
sb.push(range.source.path);
sb.push("(");
sb.push(line.toString());
sb.push(line.toString(10));
sb.push(",");
sb.push(column.toString());
sb.push(column.toString(10));
sb.push(")");
}
return sb.join("");
Expand Down
Loading

0 comments on commit d0b189b

Please sign in to comment.