mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-04-29 08:52:15 +00:00
Asterisk imports parsing; Pussyfooting around stdlib
This commit is contained in:
parent
a0ec684e1c
commit
ad298c7bea
@ -66,7 +66,7 @@ if (args.help || args._.length < 1) {
|
|||||||
"Syntax: asc [options] [entryFile ...]",
|
"Syntax: asc [options] [entryFile ...]",
|
||||||
"",
|
"",
|
||||||
"Examples: asc hello.ts",
|
"Examples: asc hello.ts",
|
||||||
" asc hello.ts -b hello.wasm -t hello.wast -a hello.js",
|
" asc hello.ts -b hello.wasm -t hello.wast",
|
||||||
" asc hello1.ts hello2.ts -b -O > hello.wasm",
|
" asc hello1.ts hello2.ts -b -O > hello.wasm",
|
||||||
"",
|
"",
|
||||||
"Options:"
|
"Options:"
|
||||||
|
29
src/ast.ts
29
src/ast.ts
@ -391,6 +391,18 @@ export abstract class Node {
|
|||||||
const stmt: ImportStatement = new ImportStatement();
|
const stmt: ImportStatement = new ImportStatement();
|
||||||
stmt.range = range;
|
stmt.range = range;
|
||||||
for (let i: i32 = 0, k: i32 = (stmt.declarations = declarations).length; i < k; ++i) declarations[i].parent = stmt;
|
for (let i: i32 = 0, k: i32 = (stmt.declarations = declarations).length; i < k; ++i) declarations[i].parent = stmt;
|
||||||
|
stmt.namespaceName = null;
|
||||||
|
stmt.path = path;
|
||||||
|
stmt.normalizedPath = resolvePath(normalizePath(path.value), range.source.normalizedPath);
|
||||||
|
stmt.internalPath = mangleInternalPath(stmt.normalizedPath);
|
||||||
|
return stmt;
|
||||||
|
}
|
||||||
|
|
||||||
|
static createImportAll(identifier: IdentifierExpression, path: StringLiteralExpression, range: Range): ImportStatement {
|
||||||
|
const stmt: ImportStatement = new ImportStatement();
|
||||||
|
stmt.range = range;
|
||||||
|
stmt.declarations = null;
|
||||||
|
stmt.namespaceName = identifier;
|
||||||
stmt.path = path;
|
stmt.path = path;
|
||||||
stmt.normalizedPath = resolvePath(normalizePath(path.value), range.source.normalizedPath);
|
stmt.normalizedPath = resolvePath(normalizePath(path.value), range.source.normalizedPath);
|
||||||
stmt.internalPath = mangleInternalPath(stmt.normalizedPath);
|
stmt.internalPath = mangleInternalPath(stmt.normalizedPath);
|
||||||
@ -1569,8 +1581,10 @@ export class ImportStatement extends Statement {
|
|||||||
|
|
||||||
kind = NodeKind.IMPORT;
|
kind = NodeKind.IMPORT;
|
||||||
|
|
||||||
/** Array of member declarations. */
|
/** Array of member declarations or `null` if an asterisk import. */
|
||||||
declarations: ImportDeclaration[];
|
declarations: ImportDeclaration[] | null;
|
||||||
|
/** Name of the local namespace, if an asterisk import. */
|
||||||
|
namespaceName: IdentifierExpression | null;
|
||||||
/** Path being imported from. */
|
/** Path being imported from. */
|
||||||
path: StringLiteralExpression;
|
path: StringLiteralExpression;
|
||||||
/** Normalized path. */
|
/** Normalized path. */
|
||||||
@ -1579,13 +1593,22 @@ export class ImportStatement extends Statement {
|
|||||||
internalPath: string;
|
internalPath: string;
|
||||||
|
|
||||||
serialize(sb: string[]): void {
|
serialize(sb: string[]): void {
|
||||||
|
if (this.declarations) {
|
||||||
sb.push("import {\n");
|
sb.push("import {\n");
|
||||||
for (let i: i32 = 0, k: i32 = this.declarations.length; i < k; ++i) {
|
for (let i: i32 = 0, k: i32 = this.declarations.length; i < k; ++i) {
|
||||||
if (i > 0)
|
if (i > 0)
|
||||||
sb.push(",\n");
|
sb.push(",\n");
|
||||||
this.declarations[i].serialize(sb);
|
this.declarations[i].serialize(sb);
|
||||||
}
|
}
|
||||||
sb.push("\n} from ");
|
sb.push("\n}");
|
||||||
|
} else {
|
||||||
|
sb.push("import * as ");
|
||||||
|
if (this.namespaceName)
|
||||||
|
this.namespaceName.serialize(sb);
|
||||||
|
else
|
||||||
|
throw new Error("missing asterisk import identifier");
|
||||||
|
}
|
||||||
|
sb.push(" from ");
|
||||||
this.path.serialize(sb);
|
this.path.serialize(sb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2093,7 +2093,7 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
return this.module.createBinary(BinaryOp.EqF64, operand, this.module.createF64(0));
|
return this.module.createBinary(BinaryOp.EqF64, operand, this.module.createF64(0));
|
||||||
}
|
}
|
||||||
op = this.currentType.isLongInteger
|
op = this.currentType.isLongInteger
|
||||||
? UnaryOp.EqzI64 // TODO: does this yield i64 0/1?
|
? UnaryOp.EqzI64
|
||||||
: UnaryOp.EqzI32;
|
: UnaryOp.EqzI32;
|
||||||
this.currentType = Type.bool;
|
this.currentType = Type.bool;
|
||||||
break;
|
break;
|
||||||
|
@ -93,7 +93,7 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
const normalizedPath: string = normalizePath(path);
|
const normalizedPath: string = normalizePath(path);
|
||||||
for (let i: i32 = 0, k: i32 = this.program.sources.length; i < k; ++i)
|
for (let i: i32 = 0, k: i32 = this.program.sources.length; i < k; ++i)
|
||||||
if (this.program.sources[i].normalizedPath == normalizedPath)
|
if (this.program.sources[i].normalizedPath == normalizedPath)
|
||||||
throw new Error("duplicate source");
|
return; // already parsed
|
||||||
this.seenlog.add(normalizedPath);
|
this.seenlog.add(normalizedPath);
|
||||||
|
|
||||||
const source: Source = new Source(path, text, isEntry);
|
const source: Source = new Source(path, text, isEntry);
|
||||||
@ -104,12 +104,12 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
|
|
||||||
while (!tn.skip(Token.ENDOFFILE)) {
|
while (!tn.skip(Token.ENDOFFILE)) {
|
||||||
const statement: Statement | null = this.parseTopLevelStatement(tn);
|
const statement: Statement | null = this.parseTopLevelStatement(tn);
|
||||||
if (!statement)
|
if (statement) {
|
||||||
return;
|
|
||||||
statement.parent = source;
|
statement.parent = source;
|
||||||
source.statements.push(statement);
|
source.statements.push(statement);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
parseTopLevelStatement(tn: Tokenizer, isNamespaceMember: bool = false): Statement | null {
|
parseTopLevelStatement(tn: Tokenizer, isNamespaceMember: bool = false): Statement | null {
|
||||||
let decorators: Decorator[] | null = null;
|
let decorators: Decorator[] | null = null;
|
||||||
@ -201,7 +201,7 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
default:
|
default:
|
||||||
if (hasModifier(ModifierKind.EXPORT, modifiers)) {
|
if (hasModifier(ModifierKind.EXPORT, modifiers)) {
|
||||||
tn.reset();
|
tn.reset();
|
||||||
statement = this.parseExport(tn, modifiers); // TODO: why exactly does this have modifiers again?
|
statement = this.parseExport(tn, modifiers); // TODO: why exactly does this have modifiers again? 'declare'?
|
||||||
} else {
|
} else {
|
||||||
if (modifiers) {
|
if (modifiers) {
|
||||||
if (modifier = getModifier(ModifierKind.DECLARE, modifiers))
|
if (modifier = getModifier(ModifierKind.DECLARE, modifiers))
|
||||||
@ -713,13 +713,10 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
|
|
||||||
let isGetter: bool = false;
|
let isGetter: bool = false;
|
||||||
let isSetter: bool = false;
|
let isSetter: bool = false;
|
||||||
if (tn.skip(Token.GET)) {
|
if (isGetter = tn.skip(Token.GET))
|
||||||
modifiers = addModifier(Node.createModifier(ModifierKind.GET, tn.range()), modifiers);
|
modifiers = addModifier(Node.createModifier(ModifierKind.GET, tn.range()), modifiers);
|
||||||
isGetter = true;
|
else if (isSetter = tn.skip(Token.SET)) // can't be both
|
||||||
} else if (tn.skip(Token.SET)) { // can't be both
|
|
||||||
modifiers = addModifier(Node.createModifier(ModifierKind.SET, tn.range()), modifiers);
|
modifiers = addModifier(Node.createModifier(ModifierKind.SET, tn.range()), modifiers);
|
||||||
isSetter = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tn.skip(Token.CONSTRUCTOR) || tn.skip(Token.IDENTIFIER)) { // order is important
|
if (tn.skip(Token.CONSTRUCTOR) || tn.skip(Token.IDENTIFIER)) { // order is important
|
||||||
const identifier: IdentifierExpression = tn.token == Token.CONSTRUCTOR
|
const identifier: IdentifierExpression = tn.token == Token.CONSTRUCTOR
|
||||||
@ -899,10 +896,12 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
parseImport(tn: Tokenizer): ImportStatement | null {
|
parseImport(tn: Tokenizer): ImportStatement | null {
|
||||||
// at 'import': '{' (ImportMember (',' ImportMember)*)? '}' 'from' StringLiteral ';'?
|
// at 'import': ('{' (ImportMember (',' ImportMember)*)? '}' | '*' 'as' Identifier) 'from' StringLiteral ';'?
|
||||||
const startRange: Range = tn.range();
|
const startPos: i32 = tn.tokenPos;
|
||||||
|
let members: ImportDeclaration[] | null = null;
|
||||||
|
let namespaceName: IdentifierExpression | null = null;
|
||||||
if (tn.skip(Token.OPENBRACE)) {
|
if (tn.skip(Token.OPENBRACE)) {
|
||||||
const members: ImportDeclaration[] = new Array();
|
members = new Array();
|
||||||
if (!tn.skip(Token.CLOSEBRACE)) {
|
if (!tn.skip(Token.CLOSEBRACE)) {
|
||||||
do {
|
do {
|
||||||
const member: ImportDeclaration | null = this.parseImportDeclaration(tn);
|
const member: ImportDeclaration | null = this.parseImportDeclaration(tn);
|
||||||
@ -915,10 +914,39 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (tn.skip(Token.ASTERISK)) {
|
||||||
|
if (tn.skip(Token.AS)) {
|
||||||
|
if (tn.skip(Token.IDENTIFIER)) {
|
||||||
|
namespaceName = Node.createIdentifier(tn.readIdentifier(), tn.range());
|
||||||
|
} else {
|
||||||
|
this.error(DiagnosticCode.Identifier_expected, tn.range());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.error(DiagnosticCode._0_expected, tn.range(), "as");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.error(DiagnosticCode._0_expected, tn.range(), "{");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
if (tn.skip(Token.FROM)) {
|
if (tn.skip(Token.FROM)) {
|
||||||
if (tn.skip(Token.STRINGLITERAL)) {
|
if (tn.skip(Token.STRINGLITERAL)) {
|
||||||
const path: StringLiteralExpression = Node.createStringLiteral(tn.readString(), tn.range());
|
const path: StringLiteralExpression = Node.createStringLiteral(tn.readString(), tn.range());
|
||||||
const ret: ImportStatement = Node.createImport(members, path, Range.join(startRange, tn.range()));
|
let ret: ImportStatement;
|
||||||
|
if (members) {
|
||||||
|
if (!namespaceName)
|
||||||
|
ret = Node.createImport(members, path, tn.range(startPos, tn.pos));
|
||||||
|
else {
|
||||||
|
assert(false);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} else if (namespaceName) {
|
||||||
|
ret = Node.createImportAll(namespaceName, path, tn.range(startPos, tn.pos));
|
||||||
|
} else {
|
||||||
|
assert(false);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
if (!this.seenlog.has(ret.normalizedPath)) {
|
if (!this.seenlog.has(ret.normalizedPath)) {
|
||||||
this.backlog.push(ret.normalizedPath);
|
this.backlog.push(ret.normalizedPath);
|
||||||
this.seenlog.add(ret.normalizedPath);
|
this.seenlog.add(ret.normalizedPath);
|
||||||
@ -929,8 +957,6 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
this.error(DiagnosticCode.String_literal_expected, tn.range());
|
this.error(DiagnosticCode.String_literal_expected, tn.range());
|
||||||
} else
|
} else
|
||||||
this.error(DiagnosticCode._0_expected, tn.range(), "from");
|
this.error(DiagnosticCode._0_expected, tn.range(), "from");
|
||||||
} else
|
|
||||||
this.error(DiagnosticCode._0_expected, tn.range(), "{");
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1363,7 +1389,7 @@ export class Parser extends DiagnosticEmitter {
|
|||||||
// see: http://www.engr.mun.ca/~theo/Misc/exp_parsing.htm#climbing
|
// see: http://www.engr.mun.ca/~theo/Misc/exp_parsing.htm#climbing
|
||||||
|
|
||||||
parseExpressionStart(tn: Tokenizer): Expression | null {
|
parseExpressionStart(tn: Tokenizer): Expression | null {
|
||||||
const token: Token = tn.next();
|
const token: Token = tn.next(true);
|
||||||
const startPos: i32 = tn.tokenPos;
|
const startPos: i32 = tn.tokenPos;
|
||||||
let expr: Expression | null = null;
|
let expr: Expression | null = null;
|
||||||
|
|
||||||
|
@ -501,11 +501,21 @@ export class Program extends DiagnosticEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private initializeImports(statement: ImportStatement, queuedExports: Map<string,QueuedExport>, queuedImports: QueuedImport[]): void {
|
private initializeImports(statement: ImportStatement, queuedExports: Map<string,QueuedExport>, queuedImports: QueuedImport[]): void {
|
||||||
const members: ImportDeclaration[] = statement.declarations;
|
const declarations: ImportDeclaration[] | null = statement.declarations;
|
||||||
for (let i: i32 = 0, k: i32 = members.length; i < k; ++i) {
|
if (declarations) {
|
||||||
const declaration: ImportDeclaration = members[i];
|
for (let i: i32 = 0, k: i32 = declarations.length; i < k; ++i) {
|
||||||
|
const declaration: ImportDeclaration = declarations[i];
|
||||||
this.initializeImport(declaration, statement.internalPath, queuedExports, queuedImports);
|
this.initializeImport(declaration, statement.internalPath, queuedExports, queuedImports);
|
||||||
}
|
}
|
||||||
|
} else if (statement.namespaceName) {
|
||||||
|
const internalName: string = statement.range.source.internalPath + "/" + statement.namespaceName.name;
|
||||||
|
if (this.elements.has(internalName)) {
|
||||||
|
this.error(DiagnosticCode.Duplicate_identifier_0, statement.namespaceName.range, internalName);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.error(DiagnosticCode.Operation_not_supported, statement.range); // TODO
|
||||||
|
} else
|
||||||
|
assert(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private initializeImport(declaration: ImportDeclaration, internalPath: string, queuedExports: Map<string,QueuedExport>, queuedImports: QueuedImport[]): void {
|
private initializeImport(declaration: ImportDeclaration, internalPath: string, queuedExports: Map<string,QueuedExport>, queuedImports: QueuedImport[]): void {
|
||||||
|
@ -731,6 +731,17 @@ export class Tokenizer extends DiagnosticEmitter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// skipUntil(token1: Token, token2: Token = -1): bool {
|
||||||
|
// let next: Token;
|
||||||
|
// do {
|
||||||
|
// if ((next = this.peek()) == Token.ENDOFFILE)
|
||||||
|
// return false;
|
||||||
|
// if (next == token1 || next == token2)
|
||||||
|
// return true;
|
||||||
|
// this.next();
|
||||||
|
// } while (true);
|
||||||
|
// }
|
||||||
|
|
||||||
mark(): void {
|
mark(): void {
|
||||||
this.markedPos = this.pos;
|
this.markedPos = this.pos;
|
||||||
this.markedToken = this.token;
|
this.markedToken = this.token;
|
||||||
|
@ -22,7 +22,7 @@ export const enum CharCode {
|
|||||||
THINSPACE = 0x2009,
|
THINSPACE = 0x2009,
|
||||||
HAIRSPACE = 0x200A,
|
HAIRSPACE = 0x200A,
|
||||||
ZEROWIDTHSPACE = 0x200B,
|
ZEROWIDTHSPACE = 0x200B,
|
||||||
NARRINOBREAKSPACE = 0x202F,
|
NARROWNOBREAKSPACE = 0x202F,
|
||||||
IDEOGRAPHICSPACE = 0x3000,
|
IDEOGRAPHICSPACE = 0x3000,
|
||||||
MATHEMATICALSPACE = 0x205F,
|
MATHEMATICALSPACE = 0x205F,
|
||||||
OGHAM = 0x1680,
|
OGHAM = 0x1680,
|
||||||
@ -156,7 +156,7 @@ export function isWhiteSpace(c: i32): bool {
|
|||||||
case CharCode.NONBREAKINGSPACE:
|
case CharCode.NONBREAKINGSPACE:
|
||||||
case CharCode.NEXTLINE:
|
case CharCode.NEXTLINE:
|
||||||
case CharCode.OGHAM:
|
case CharCode.OGHAM:
|
||||||
case CharCode.NARRINOBREAKSPACE:
|
case CharCode.NARROWNOBREAKSPACE:
|
||||||
case CharCode.MATHEMATICALSPACE:
|
case CharCode.MATHEMATICALSPACE:
|
||||||
case CharCode.IDEOGRAPHICSPACE:
|
case CharCode.IDEOGRAPHICSPACE:
|
||||||
case CharCode.BYTEORDERMARK:
|
case CharCode.BYTEORDERMARK:
|
||||||
|
4
std/assembly.d.ts
vendored
4
std/assembly.d.ts
vendored
@ -178,6 +178,7 @@ declare function parseFloat(str: string): f64;
|
|||||||
|
|
||||||
/** Class representing a sequence of values of type `T`. */
|
/** Class representing a sequence of values of type `T`. */
|
||||||
declare class Array<T> {
|
declare class Array<T> {
|
||||||
|
[key: number]: T;
|
||||||
|
|
||||||
/** Current maximum capacity of the array. */
|
/** Current maximum capacity of the array. */
|
||||||
readonly capacity: i32;
|
readonly capacity: i32;
|
||||||
@ -275,3 +276,6 @@ declare function global(): any;
|
|||||||
|
|
||||||
/** Annotates a method being an operator overload. */
|
/** Annotates a method being an operator overload. */
|
||||||
declare function operator(token: string): any;
|
declare function operator(token: string): any;
|
||||||
|
|
||||||
|
declare function struct(): any;
|
||||||
|
declare function size(size: usize): any;
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
@global()
|
@global()
|
||||||
export class Array<T> {
|
export class Array<T> {
|
||||||
|
|
||||||
|
private ptr: usize;
|
||||||
|
|
||||||
readonly capacity: i32;
|
readonly capacity: i32;
|
||||||
length: i32;
|
length: i32;
|
||||||
ptr: usize;
|
|
||||||
|
|
||||||
constructor(capacity: i32 = 0) {
|
constructor(capacity: i32 = 0) {
|
||||||
if (capacity < 0)
|
if (capacity < 0)
|
||||||
|
@ -1,98 +1,197 @@
|
|||||||
|
const EMPTY: String = changetype<string,String>("");
|
||||||
|
|
||||||
@global()
|
@global()
|
||||||
export class String {
|
export class String {
|
||||||
|
// [key: number]: string;
|
||||||
|
|
||||||
private ptr: usize;
|
private ptr: usize;
|
||||||
readonly length: u32;
|
|
||||||
|
|
||||||
constructor(ptr: usize, len: u32) {
|
readonly length: i32;
|
||||||
|
|
||||||
|
constructor(ptr: usize, lenght: i32) {
|
||||||
this.ptr = ptr;
|
this.ptr = ptr;
|
||||||
this.length = len;
|
this.length = lenght;
|
||||||
}
|
}
|
||||||
|
|
||||||
charAt(index: u32): String {
|
charAt(pos: i32): String {
|
||||||
assert(this != null && index < this.length);
|
assert(this != null);
|
||||||
return new String(this.ptr + (index << 1), 1);
|
return pos < 0 || pos >= this.length ? EMPTY
|
||||||
|
: new String(this.ptr + (<usize>pos << 1), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
charCodeAt(index: u32): u16 {
|
charCodeAt(pos: i32): i32 {
|
||||||
assert(this != null && index < this.length);
|
assert(this != null);
|
||||||
return load<u16>(this.ptr + (index << 1));
|
return pos < 0 || pos >= this.length ? -1 // NaN
|
||||||
|
: load<u16>(this.ptr + (<usize>pos << 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
codePointAt(pos: i32): i32 {
|
||||||
|
assert(this != null);
|
||||||
|
if (pos < 0 || pos >= this.length)
|
||||||
|
return -1; // undefined
|
||||||
|
let first: i32 = <i32>load<u16>(this.ptr + (<usize>pos << 1));
|
||||||
|
if (first < 0xD800 || first > 0xDBFF || pos + 1 == this.length)
|
||||||
|
return first;
|
||||||
|
let second: i32 = <i32>load<u16>(this.ptr + ((<usize>pos + 1) << 1));
|
||||||
|
if (second < 0xDC00 || second > 0xDFFF)
|
||||||
|
return first;
|
||||||
|
return ((first - 0xD800) << 10) + (second - 0xDC00) + 0x10000;
|
||||||
}
|
}
|
||||||
|
|
||||||
@operator("+")
|
@operator("+")
|
||||||
concat(other: String): String {
|
concat(other: String): String {
|
||||||
assert(this != null && other != null);
|
assert(this != null);
|
||||||
const len: u32 = this.length + other.length;
|
assert(other != null);
|
||||||
const ptr: usize = Heap.allocate(len << 1);
|
const thisLen: isize = this.length;
|
||||||
Heap.copy(ptr, this.ptr, this.length << 1);
|
const otherLen: isize = other.length;
|
||||||
Heap.copy(ptr, this.ptr + (len << 1), other.length << 1);
|
const len: usize = thisLen + otherLen;
|
||||||
return new String(ptr, len);
|
return new String(
|
||||||
|
Heap.copy(
|
||||||
|
Heap.copy(
|
||||||
|
Heap.allocate(len << 1),
|
||||||
|
this.ptr,
|
||||||
|
thisLen << 1
|
||||||
|
) + (thisLen << 1),
|
||||||
|
other.ptr,
|
||||||
|
otherLen << 1
|
||||||
|
),
|
||||||
|
<i32>len
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
endsWith(other: String): bool {
|
endsWith(searchString: String, endPosition: i32 = 0x7fffffff): bool {
|
||||||
assert(this != null && other != null);
|
assert(this != null);
|
||||||
if (other.length > this.length)
|
assert(searchString != null);
|
||||||
|
let end: isize = <isize>min<i32>(max<i32>(endPosition, 0), this.length);
|
||||||
|
let searchLength: isize = searchString.length;
|
||||||
|
let start: isize = end - searchLength;
|
||||||
|
if (start < 0)
|
||||||
return false;
|
return false;
|
||||||
for (let i: u32 = this.length - other.length, j: u32 = 0, k: u32 = this.length; i < k;)
|
return !Heap.compare(this.ptr + (start << 1), searchString.ptr, searchLength << 1);
|
||||||
if (this.charCodeAt(i++) != other.charCodeAt(j++))
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@operator("==")
|
@operator("==")
|
||||||
equals(other: String): bool {
|
equals(other: String): bool {
|
||||||
assert(this != null && other != null);
|
assert(this != null);
|
||||||
if (this.length != other.length)
|
assert(other != null);
|
||||||
|
return this.length != other.length ? false
|
||||||
|
: !Heap.compare(this.ptr, other.ptr, <usize>this.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
includes(searchString: String, position: i32 = 0): bool {
|
||||||
|
return this.indexOf(searchString, position) != -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
indexOf(searchString: String, position: i32 = 0): i32 {
|
||||||
|
assert(this != null);
|
||||||
|
assert(searchString != null);
|
||||||
|
let pos: isize = position;
|
||||||
|
let len: isize = this.length;
|
||||||
|
let start: isize = min<isize>(max<isize>(pos, 0), len);
|
||||||
|
let searchLen: isize = searchString.length;
|
||||||
|
for (let k: usize = start; <isize>k + searchLen <= len; ++k)
|
||||||
|
if (!Heap.compare(this.ptr + (k << 1), searchString.ptr, searchLen << 1))
|
||||||
|
return <i32>k;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
startsWith(searchString: String, position: i32 = 0): bool {
|
||||||
|
assert(this != null);
|
||||||
|
assert(searchString != null);
|
||||||
|
let pos: isize = position;
|
||||||
|
let len: isize = this.length;
|
||||||
|
let start: isize = min<isize>(max<isize>(position, 0), len);
|
||||||
|
let searchLength: isize = searchString.length;
|
||||||
|
if (searchLength + start > len)
|
||||||
return false;
|
return false;
|
||||||
for (let i: u32 = 0, k: u32 = this.length; i < k; ++i)
|
return !Heap.compare(this.ptr + (start << 1), searchString.ptr, searchLength << 1);
|
||||||
if (this.charCodeAt(i) != other.charCodeAt(i))
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
indexOf(other: String): u32 {
|
substr(start: i32, length: i32 = i32.MAX_VALUE): String {
|
||||||
assert(this != null && other != null);
|
|
||||||
throw new Error("not implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
startsWith(other: String): bool {
|
|
||||||
assert(this != null && other != null);
|
|
||||||
if (other.length > this.length)
|
|
||||||
return false;
|
|
||||||
for (let i: u32 = 0, k: u32 = other.length; i < k; ++i)
|
|
||||||
if (this.charCodeAt(i) != other.charCodeAt(i))
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
substr(start: u32, length: u32 = <u32>-1): String {
|
|
||||||
assert(this != null);
|
assert(this != null);
|
||||||
if (start >= this.length)
|
let intStart: isize = start;
|
||||||
return changetype<string,String>("");
|
let end: isize = length;
|
||||||
const len: u32 = min<u32>(length, this.length - start);
|
let size: isize = this.length;
|
||||||
return new String(this.ptr + (start << 1), len);
|
if (intStart < 0)
|
||||||
|
intStart = max<isize>(size + intStart, 0);
|
||||||
|
let resultLength: isize = min<isize>(max<isize>(end, 0), size - intStart);
|
||||||
|
if (resultLength < 0)
|
||||||
|
return EMPTY;
|
||||||
|
return new String(this.ptr + (intStart << 1), <i32>resultLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
substring(start: u32, end: u32 = <u32>-1): String {
|
substring(start: i32, end: i32 = i32.MAX_VALUE): String {
|
||||||
assert(this != null);
|
assert(this != null);
|
||||||
if (start >= this.length || end <= start)
|
let len: i32 = this.length;
|
||||||
return changetype<string,String>("");
|
let finalStart: i32 = min<i32>(max<i32>(start, 0), len);
|
||||||
const len: u32 = min<u32>(end - start, this.length - start);
|
let finalEnd: i32 = min<i32>(max<i32>(end, 0), len);
|
||||||
return new String(this.ptr + (start << 1), len);
|
let from: i32 = min<i32>(finalStart, finalEnd);
|
||||||
|
let to: i32 = max<i32>(finalStart, finalEnd);
|
||||||
|
len = to - from;
|
||||||
|
if (!len)
|
||||||
|
return EMPTY;
|
||||||
|
if (!from && to == this.length)
|
||||||
|
return this;
|
||||||
|
return new String(this.ptr + (from << 1), len);
|
||||||
}
|
}
|
||||||
|
|
||||||
trim(): string {
|
trim(): String {
|
||||||
assert(this != null);
|
assert(this != null);
|
||||||
throw new Error("not implemented");
|
let length: usize = this.length;
|
||||||
|
while (length && isWhiteSpaceOrLineTerminator(load<u16>(this.ptr + (length << 1))))
|
||||||
|
--length;
|
||||||
|
let start: usize = 0;
|
||||||
|
while (start < length && isWhiteSpaceOrLineTerminator(load<u16>(this.ptr + (start << 1)))) {
|
||||||
|
++start; --length;
|
||||||
|
}
|
||||||
|
if (!length)
|
||||||
|
return EMPTY;
|
||||||
|
if (!start && length == this.length)
|
||||||
|
return this;
|
||||||
|
return new String(this.ptr + (start << 1), length);
|
||||||
}
|
}
|
||||||
|
|
||||||
trimLeft(): string {
|
trimLeft(): String {
|
||||||
assert(this != null);
|
assert(this != null);
|
||||||
throw new Error("not implemented");
|
let start: isize = 0;
|
||||||
|
let len: isize = this.length;
|
||||||
|
while (start < len && isWhiteSpaceOrLineTerminator(load<u16>(this.ptr + (start << 1))))
|
||||||
|
++start;
|
||||||
|
if (!start)
|
||||||
|
return this;
|
||||||
|
return new String(this.ptr + (start << 1), <i32>(len - start));
|
||||||
}
|
}
|
||||||
|
|
||||||
trimRight(): string {
|
trimRight(): String {
|
||||||
assert(this != null);
|
assert(this != null);
|
||||||
throw new Error("not implemented");
|
let len: isize = this.length;
|
||||||
|
while (len > 0 && isWhiteSpaceOrLineTerminator(load<u16>(this.ptr + (len << 1))))
|
||||||
|
--len;
|
||||||
|
if (len <= 0)
|
||||||
|
return EMPTY;
|
||||||
|
if (<i32>len == this.length)
|
||||||
|
return this;
|
||||||
|
return new String(this.ptr, <i32>len);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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>
|
||||||
|
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,5 +27,5 @@ Object.defineProperties(globalScope["Heap"] = {
|
|||||||
size: { get: function get_size() { return HEAP.length; } }
|
size: { get: function get_size() { return HEAP.length; } }
|
||||||
});
|
});
|
||||||
|
|
||||||
globalScope["store"] = function store(ptr, val) { binaryen.HEAPU8[ptr] = val; };
|
globalScope["store"] = function store(ptr, val) { HEAP[ptr] = val; };
|
||||||
globalScope["load"] = function load(ptr) { return binaryen.HEAPU8[ptr]; };
|
globalScope["load"] = function load(ptr) { return HEAP[ptr]; };
|
||||||
|
@ -73,8 +73,10 @@
|
|||||||
Map
|
Map
|
||||||
std:set/Set
|
std:set/Set
|
||||||
Set
|
Set
|
||||||
|
std:string/EMPTY
|
||||||
std:string/String
|
std:string/String
|
||||||
String
|
String
|
||||||
|
std:string/isWhiteSpaceOrLineTerminator
|
||||||
[program.exports]
|
[program.exports]
|
||||||
std:array/Array
|
std:array/Array
|
||||||
std:error/Error
|
std:error/Error
|
||||||
|
@ -2626,8 +2626,10 @@
|
|||||||
Map
|
Map
|
||||||
std:set/Set
|
std:set/Set
|
||||||
Set
|
Set
|
||||||
|
std:string/EMPTY
|
||||||
std:string/String
|
std:string/String
|
||||||
String
|
String
|
||||||
|
std:string/isWhiteSpaceOrLineTerminator
|
||||||
std/heap/size
|
std/heap/size
|
||||||
std/heap/ptr1
|
std/heap/ptr1
|
||||||
std/heap/ptr2
|
std/heap/ptr2
|
||||||
|
7
tests/parser/import.ts
Normal file
7
tests/parser/import.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import { A } from "./other";
|
||||||
|
|
||||||
|
import { A, B, C } from "./other";
|
||||||
|
|
||||||
|
import { A as B, C, D as E, F } from "./other";
|
||||||
|
|
||||||
|
import * as A from "./other";
|
15
tests/parser/import.ts.fixture.ts
Normal file
15
tests/parser/import.ts.fixture.ts
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import {
|
||||||
|
A
|
||||||
|
} from "./other";
|
||||||
|
import {
|
||||||
|
A,
|
||||||
|
B,
|
||||||
|
C
|
||||||
|
} from "./other";
|
||||||
|
import {
|
||||||
|
A as B,
|
||||||
|
C,
|
||||||
|
D as E,
|
||||||
|
F
|
||||||
|
} from "./other";
|
||||||
|
import * as A from "./other";
|
Loading…
x
Reference in New Issue
Block a user