Skip to content

Commit 6268b92

Browse files
committed
Resolve string instances to the program's string class
1 parent 70a0123 commit 6268b92

File tree

13 files changed

+103
-31
lines changed

13 files changed

+103
-31
lines changed

dist/asc.js

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

dist/asc.js.map

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

dist/assemblyscript.js

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

dist/assemblyscript.js.map

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

src/program.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1994,6 +1994,17 @@ export class Program extends DiagnosticEmitter {
19941994
case NodeKind.IDENTIFIER: {
19951995
return this.resolveIdentifier(<IdentifierExpression>expression, contextualFunction);
19961996
}
1997+
case NodeKind.LITERAL: {
1998+
switch ((<LiteralExpression>expression).literalKind) {
1999+
case LiteralKind.STRING: {
2000+
this.resolvedThisExpression = expression;
2001+
this.resolvedElementExpression = null;
2002+
return this.stringInstance;
2003+
}
2004+
// case LiteralKind.ARRAY: // TODO
2005+
}
2006+
break;
2007+
}
19972008
case NodeKind.PROPERTYACCESS: {
19982009
return this.resolvePropertyAccess(
19992010
<PropertyAccessExpression>expression,

std/assembly/string.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,9 @@ export class String {
113113

114114
@operator("==")
115115
private static __eq(left: String, right: String): bool {
116+
if (left === right) return true;
116117
if (left === null) return right === null;
117-
else if (right === null) return false;
118+
if (right === null) return false;
118119

119120
var leftLength = left.length;
120121
if (leftLength != right.length) return false;

tests/compiler/std/array-access.optimized.wat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
(call $abort
126126
(i32.const 0)
127127
(i32.const 8)
128-
(i32.const 234)
128+
(i32.const 235)
129129
(i32.const 4)
130130
)
131131
(unreachable)

tests/compiler/std/array-access.untouched.wat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@
195195
(call $abort
196196
(i32.const 0)
197197
(i32.const 8)
198-
(i32.const 234)
198+
(i32.const 235)
199199
(i32.const 4)
200200
)
201201
(unreachable)

tests/compiler/std/string.optimized.wat

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
(global $std/string/nullStr (mut i32) (i32.const 0))
1616
(global $argumentCount (mut i32) (i32.const 0))
1717
(global $std/string/c (mut i32) (i32.const 0))
18-
(global $HEAP_BASE i32 (i32.const 372))
18+
(global $HEAP_BASE i32 (i32.const 384))
1919
(memory $0 1)
2020
(data (i32.const 4) "\10\00\00\00h\00i\00,\00 \00I\00\'\00m\00 \00a\00 \00s\00t\00r\00i\00n\00g")
2121
(data (i32.const 40) "\0d\00\00\00s\00t\00d\00/\00s\00t\00r\00i\00n\00g\00.\00t\00s")
@@ -43,6 +43,7 @@
4343
(data (i32.const 344) "\02\00\00\00b\00a")
4444
(data (i32.const 352) "\02\00\00\00a\00a")
4545
(data (i32.const 360) "\03\00\00\00a\00b\00c")
46+
(data (i32.const 372) "\03\00\00\001\002\003")
4647
(export "getString" (func $std/string/getString))
4748
(export "memory" (memory $0))
4849
(start $start)
@@ -154,7 +155,7 @@
154155
(call $abort
155156
(i32.const 0)
156157
(i32.const 72)
157-
(i32.const 234)
158+
(i32.const 235)
158159
(i32.const 4)
159160
)
160161
(unreachable)
@@ -374,7 +375,7 @@
374375
(call $abort
375376
(i32.const 0)
376377
(i32.const 72)
377-
(i32.const 213)
378+
(i32.const 214)
378379
(i32.const 4)
379380
)
380381
(unreachable)
@@ -1085,7 +1086,7 @@
10851086
(call $abort
10861087
(i32.const 0)
10871088
(i32.const 72)
1088-
(i32.const 558)
1089+
(i32.const 559)
10891090
(i32.const 10)
10901091
)
10911092
(unreachable)
@@ -3263,21 +3264,32 @@
32633264
(func $~lib/string/String.__eq (; 22 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
32643265
(local $2 i32)
32653266
(if
3266-
(get_local $0)
3267-
(if
3268-
(i32.eqz
3269-
(get_local $1)
3270-
)
3271-
(return
3272-
(i32.const 0)
3273-
)
3267+
(i32.eq
3268+
(get_local $0)
3269+
(get_local $1)
3270+
)
3271+
(return
3272+
(i32.const 1)
3273+
)
3274+
)
3275+
(if
3276+
(i32.eqz
3277+
(get_local $0)
32743278
)
32753279
(return
32763280
(i32.eqz
32773281
(get_local $1)
32783282
)
32793283
)
32803284
)
3285+
(if
3286+
(i32.eqz
3287+
(get_local $1)
3288+
)
3289+
(return
3290+
(i32.const 0)
3291+
)
3292+
)
32813293
(if
32823294
(i32.ne
32833295
(tee_local $2
@@ -4402,5 +4414,22 @@
44024414
(unreachable)
44034415
)
44044416
)
4417+
(if
4418+
(i32.ne
4419+
(i32.load
4420+
(i32.const 372)
4421+
)
4422+
(i32.const 3)
4423+
)
4424+
(block
4425+
(call $abort
4426+
(i32.const 0)
4427+
(i32.const 40)
4428+
(i32.const 64)
4429+
(i32.const 0)
4430+
)
4431+
(unreachable)
4432+
)
4433+
)
44054434
)
44064435
)

tests/compiler/std/string.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,5 @@ assert(!("" < ""));
6060
assert(!("" > ""));
6161
assert("" >= "");
6262
assert("" <= "");
63+
64+
assert("123".length == 3);

0 commit comments

Comments
 (0)