Skip to content

Commit 6d73f3c

Browse files
committed
Merge remote-tracking branch 'origin/master' into release
2 parents 35aabeb + e6a668b commit 6d73f3c

13 files changed

+16154
-8524
lines changed

src/program.ts

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,7 @@ export class Program extends DiagnosticEmitter {
787787
// queued imports should be resolvable now through traversing exports and queued exports
788788
for (let i = 0, k = queuedImports.length; i < k; ++i) {
789789
let queuedImport = queuedImports[i];
790+
let localIdentifier = queuedImport.localIdentifier;
790791
let foreignIdentifier = queuedImport.foreignIdentifier;
791792
if (foreignIdentifier) { // i.e. import { foo [as bar] } from "./baz"
792793
let element = this.lookupForeign(
@@ -797,9 +798,9 @@ export class Program extends DiagnosticEmitter {
797798
);
798799
if (element) {
799800
queuedImport.localFile.add(
800-
queuedImport.localIdentifier.text,
801+
localIdentifier.text,
801802
element,
802-
true // isImport
803+
localIdentifier // isImport
803804
);
804805
} else {
805806
// FIXME: file not found is not reported if this happens?
@@ -812,14 +813,15 @@ export class Program extends DiagnosticEmitter {
812813
let foreignFile = this.lookupForeignFile(queuedImport.foreignPath, queuedImport.foreignPathAlt);
813814
if (foreignFile) {
814815
let localFile = queuedImport.localFile;
815-
let localName = queuedImport.localIdentifier.text;
816+
let localName = localIdentifier.text;
816817
localFile.add(
817818
localName,
818819
foreignFile.asImportedNamespace(
819820
localName,
820-
localFile
821+
localFile,
822+
localIdentifier
821823
),
822-
true // isImport
824+
localIdentifier // isImport
823825
);
824826
} else {
825827
assert(false); // already reported by the parser not finding the file
@@ -1775,7 +1777,7 @@ export class Program extends DiagnosticEmitter {
17751777
// resolve right away if the element exists
17761778
var element = this.lookupForeign(declaration.foreignName.text, foreignPath, foreignPathAlt, queuedExports);
17771779
if (element) {
1778-
parent.add(declaration.name.text, element, true);
1780+
parent.add(declaration.name.text, element, declaration.name /* isImport */);
17791781
return;
17801782
}
17811783

@@ -2161,7 +2163,7 @@ export abstract class Element {
21612163
abstract lookup(name: string): Element | null;
21622164

21632165
/** Adds an element as a member of this one. Reports and returns `false` if a duplicate. */
2164-
add(name: string, element: DeclaredElement): bool {
2166+
add(name: string, element: DeclaredElement, localIdentifierIfImport: IdentifierExpression | null = null): bool {
21652167
var originalDeclaration = element.declaration;
21662168
var members = this.members;
21672169
if (!members) this.members = members = new Map();
@@ -2174,17 +2176,18 @@ export abstract class Element {
21742176
if (merged) {
21752177
element = merged; // use merged element
21762178
} else {
2179+
let reportedIdentifier = localIdentifierIfImport || element.identifierNode;
21772180
if (isDeclaredElement(existing.kind)) {
21782181
this.program.errorRelated(
21792182
DiagnosticCode.Duplicate_identifier_0,
2180-
element.identifierNode.range,
2181-
(<DeclaredElement>existing).declaration.name.range,
2182-
element.identifierNode.text
2183+
reportedIdentifier.range,
2184+
(<DeclaredElement>existing).identifierNode.range,
2185+
reportedIdentifier.text
21832186
);
21842187
} else {
21852188
this.program.error(
21862189
DiagnosticCode.Duplicate_identifier_0,
2187-
element.identifierNode.range, element.identifierNode.text
2190+
reportedIdentifier.range, reportedIdentifier.text
21882191
);
21892192
}
21902193
return false;
@@ -2338,13 +2341,13 @@ export class File extends Element {
23382341
}
23392342

23402343
/* @override */
2341-
add(name: string, element: DeclaredElement, isImport: bool = false): bool {
2344+
add(name: string, element: DeclaredElement, localIdentifierIfImport: IdentifierExpression | null = null): bool {
23422345
if (element.hasDecorator(DecoratorFlags.GLOBAL)) {
23432346
element = this.program.ensureGlobal(name, element); // possibly merged globally
23442347
}
2345-
if (!super.add(name, element)) return false;
2348+
if (!super.add(name, element, localIdentifierIfImport)) return false;
23462349
element = assert(this.lookupInSelf(name)); // possibly merged locally
2347-
if (element.is(CommonFlags.EXPORT) && !isImport) {
2350+
if (element.is(CommonFlags.EXPORT) && !localIdentifierIfImport) {
23482351
this.ensureExport(
23492352
element.name,
23502353
element
@@ -2404,12 +2407,10 @@ export class File extends Element {
24042407
}
24052408

24062409
/** Creates an imported namespace from this file. */
2407-
asImportedNamespace(name: string, parent: Element): Namespace {
2408-
var ns = new Namespace(
2409-
name,
2410-
parent,
2411-
this.program.makeNativeNamespaceDeclaration(name)
2412-
);
2410+
asImportedNamespace(name: string, parent: Element, localIdentifier: IdentifierExpression): Namespace {
2411+
var declaration = this.program.makeNativeNamespaceDeclaration(name);
2412+
declaration.name = localIdentifier;
2413+
var ns = new Namespace(name, parent, declaration);
24132414
var exports = this.exports;
24142415
if (exports) {
24152416
for (let [memberName, member] of exports) {
@@ -3719,7 +3720,7 @@ function tryMerge(older: Element, newer: Element): DeclaredElement | null {
37193720
// NOTE: some of the following cases are not supported by TS, not sure why exactly.
37203721
// suggesting to just merge what seems to be possible for now and revisit later.
37213722
assert(older.program === newer.program);
3722-
assert(!newer.members);
3723+
if (newer.members) return null;
37233724
var merged: DeclaredElement | null = null;
37243725
switch (older.kind) {
37253726
case ElementKind.FUNCTION_PROTOTYPE: {

std/assembly/string.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
/// <reference path="./rt/index.d.ts" />
22

33
import { BLOCK, BLOCK_OVERHEAD, BLOCK_MAXSIZE } from "./rt/common";
4-
import { compareImpl, strtol, strtod, isSpace, isAscii, toLower8, toUpper8 } from "./util/string";
4+
import { compareImpl, strtol, strtod, isSpace, isAscii, isFinalSigma, toLower8, toUpper8 } from "./util/string";
55
import { SPECIALS_UPPER, casemap, bsearch } from "./util/casemap";
66
import { E_INVALIDLENGTH } from "./util/error";
7-
import { idof } from "./builtins";
87

98
@sealed export abstract class String {
109

@@ -54,7 +53,7 @@ import { idof } from "./builtins";
5453
if (<u32>pos >= <u32>len) return -1; // (undefined)
5554
var first = <i32>load<u16>(changetype<usize>(this) + (<usize>pos << 1));
5655
if ((first & 0xFC00) != 0xD800 || pos + 1 == len) return first;
57-
var second = <i32>load<u16>(changetype<usize>(this) + ((<usize>pos + 1) << 1));
56+
var second = <i32>load<u16>(changetype<usize>(this) + (<usize>pos << 1), 2);
5857
if ((second & 0xFC00) != 0xDC00) return first;
5958
return (first - 0xD800 << 10) + (second - 0xDC00) + 0x10000;
6059
}
@@ -526,6 +525,13 @@ import { idof } from "./builtins";
526525
// 0x0130 -> [0x0069, 0x0307]
527526
store<u32>(codes + (j << 1), (0x0307 << 16) | 0x0069);
528527
++j;
528+
} else if (c == 0x03A3) { // 'Σ'
529+
// Σ maps to σ but except at the end of a word where it maps to ς
530+
let sigma = 0x03C3; // σ
531+
if (len > 1 && isFinalSigma(changetype<usize>(this), i, len)) {
532+
sigma = 0x03C2; // ς
533+
}
534+
store<u16>(codes + (j << 1), sigma);
529535
} else if (c - 0x24B6 <= 0x24CF - 0x24B6) {
530536
// Range 0x24B6 <= c <= 0x24CF not covered by casemap and require special early handling
531537
store<u16>(codes + (j << 1), c + 26);
@@ -552,7 +558,8 @@ import { idof } from "./builtins";
552558
var len = <usize>this.length;
553559
if (!len) return this;
554560
var codes = __alloc(len * 3 * 2, idof<String>());
555-
var specialsUpperLen = SPECIALS_UPPER.length;
561+
var specialsPtr = changetype<usize>(SPECIALS_UPPER);
562+
var specialsLen = SPECIALS_UPPER.length;
556563
var j: usize = 0;
557564
for (let i: usize = 0; i < len; ++i, ++j) {
558565
let c = <u32>load<u16>(changetype<usize>(this) + (i << 1));
@@ -578,15 +585,15 @@ import { idof } from "./builtins";
578585
// monkey patch
579586
store<u16>(codes + (j << 1), c - 26);
580587
} else {
581-
let index = -1;
588+
let index = -1 as usize;
582589
// Fast range check. See first and last rows in specialsUpper table
583590
if (c - 0x00DF <= 0xFB17 - 0x00DF) {
584-
index = <usize>bsearch(c, changetype<usize>(SPECIALS_UPPER), specialsUpperLen);
591+
index = <usize>bsearch(c, specialsPtr, specialsLen);
585592
}
586593
if (~index) {
587594
// load next 3 code points from row with `index` offset for specialsUpper table
588-
let ab = load<u32>(changetype<usize>(SPECIALS_UPPER) + (index << 1), 2);
589-
let cc = load<u16>(changetype<usize>(SPECIALS_UPPER) + (index << 1), 6);
595+
let ab = load<u32>(specialsPtr + (index << 1), 2);
596+
let cc = load<u16>(specialsPtr + (index << 1), 6);
590597
store<u32>(codes + (j << 1), ab, 0);
591598
store<u16>(codes + (j << 1), cc, 4);
592599
j += 1 + usize(cc != 0);

0 commit comments

Comments
 (0)