Resolve string instances to the program's string class

This commit is contained in:
dcodeIO 2018-04-06 00:19:45 +02:00
parent 70a0123554
commit 6268b92eba
13 changed files with 103 additions and 31 deletions

2
dist/asc.js vendored

File diff suppressed because one or more lines are too long

2
dist/asc.js.map vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1994,6 +1994,17 @@ export class Program extends DiagnosticEmitter {
case NodeKind.IDENTIFIER: {
return this.resolveIdentifier(<IdentifierExpression>expression, contextualFunction);
}
case NodeKind.LITERAL: {
switch ((<LiteralExpression>expression).literalKind) {
case LiteralKind.STRING: {
this.resolvedThisExpression = expression;
this.resolvedElementExpression = null;
return this.stringInstance;
}
// case LiteralKind.ARRAY: // TODO
}
break;
}
case NodeKind.PROPERTYACCESS: {
return this.resolvePropertyAccess(
<PropertyAccessExpression>expression,

View File

@ -113,8 +113,9 @@ export class String {
@operator("==")
private static __eq(left: String, right: String): bool {
if (left === right) return true;
if (left === null) return right === null;
else if (right === null) return false;
if (right === null) return false;
var leftLength = left.length;
if (leftLength != right.length) return false;

View File

@ -125,7 +125,7 @@
(call $abort
(i32.const 0)
(i32.const 8)
(i32.const 234)
(i32.const 235)
(i32.const 4)
)
(unreachable)

View File

@ -195,7 +195,7 @@
(call $abort
(i32.const 0)
(i32.const 8)
(i32.const 234)
(i32.const 235)
(i32.const 4)
)
(unreachable)

View File

@ -15,7 +15,7 @@
(global $std/string/nullStr (mut i32) (i32.const 0))
(global $argumentCount (mut i32) (i32.const 0))
(global $std/string/c (mut i32) (i32.const 0))
(global $HEAP_BASE i32 (i32.const 372))
(global $HEAP_BASE i32 (i32.const 384))
(memory $0 1)
(data (i32.const 4) "\10\00\00\00h\00i\00,\00 \00I\00\'\00m\00 \00a\00 \00s\00t\00r\00i\00n\00g")
(data (i32.const 40) "\0d\00\00\00s\00t\00d\00/\00s\00t\00r\00i\00n\00g\00.\00t\00s")
@ -43,6 +43,7 @@
(data (i32.const 344) "\02\00\00\00b\00a")
(data (i32.const 352) "\02\00\00\00a\00a")
(data (i32.const 360) "\03\00\00\00a\00b\00c")
(data (i32.const 372) "\03\00\00\001\002\003")
(export "getString" (func $std/string/getString))
(export "memory" (memory $0))
(start $start)
@ -154,7 +155,7 @@
(call $abort
(i32.const 0)
(i32.const 72)
(i32.const 234)
(i32.const 235)
(i32.const 4)
)
(unreachable)
@ -374,7 +375,7 @@
(call $abort
(i32.const 0)
(i32.const 72)
(i32.const 213)
(i32.const 214)
(i32.const 4)
)
(unreachable)
@ -1085,7 +1086,7 @@
(call $abort
(i32.const 0)
(i32.const 72)
(i32.const 558)
(i32.const 559)
(i32.const 10)
)
(unreachable)
@ -3263,7 +3264,24 @@
(func $~lib/string/String.__eq (; 22 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(local $2 i32)
(if
(i32.eq
(get_local $0)
(get_local $1)
)
(return
(i32.const 1)
)
)
(if
(i32.eqz
(get_local $0)
)
(return
(i32.eqz
(get_local $1)
)
)
)
(if
(i32.eqz
(get_local $1)
@ -3272,12 +3290,6 @@
(i32.const 0)
)
)
(return
(i32.eqz
(get_local $1)
)
)
)
(if
(i32.ne
(tee_local $2
@ -4402,5 +4414,22 @@
(unreachable)
)
)
(if
(i32.ne
(i32.load
(i32.const 372)
)
(i32.const 3)
)
(block
(call $abort
(i32.const 0)
(i32.const 40)
(i32.const 64)
(i32.const 0)
)
(unreachable)
)
)
)
)

View File

@ -60,3 +60,5 @@ assert(!("" < ""));
assert(!("" > ""));
assert("" >= "");
assert("" <= "");
assert("123".length == 3);

View File

@ -46,7 +46,7 @@
(global $~lib/string/CharCode.z i32 (i32.const 122))
(global $~lib/string/EMPTY i32 (i32.const 332))
(global $std/string/c (mut i32) (i32.const 0))
(global $HEAP_BASE i32 (i32.const 372))
(global $HEAP_BASE i32 (i32.const 384))
(memory $0 1)
(data (i32.const 4) "\10\00\00\00h\00i\00,\00 \00I\00\'\00m\00 \00a\00 \00s\00t\00r\00i\00n\00g\00")
(data (i32.const 40) "\0d\00\00\00s\00t\00d\00/\00s\00t\00r\00i\00n\00g\00.\00t\00s\00")
@ -75,6 +75,7 @@
(data (i32.const 344) "\02\00\00\00b\00a\00")
(data (i32.const 352) "\02\00\00\00a\00a\00")
(data (i32.const 360) "\03\00\00\00a\00b\00c\00")
(data (i32.const 372) "\03\00\00\001\002\003\00")
(export "getString" (func $std/string/getString))
(export "memory" (memory $0))
(start $start)
@ -203,7 +204,7 @@
(call $abort
(i32.const 0)
(i32.const 72)
(i32.const 234)
(i32.const 235)
(i32.const 4)
)
(unreachable)
@ -461,7 +462,7 @@
(call $abort
(i32.const 0)
(i32.const 72)
(i32.const 213)
(i32.const 214)
(i32.const 4)
)
(unreachable)
@ -1263,7 +1264,7 @@
(call $abort
(i32.const 0)
(i32.const 72)
(i32.const 558)
(i32.const 559)
(i32.const 10)
)
(unreachable)
@ -3750,6 +3751,15 @@
)
(func $~lib/string/String.__eq (; 22 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(local $2 i32)
(if
(i32.eq
(get_local $0)
(get_local $1)
)
(return
(i32.const 1)
)
)
(if
(i32.eq
(get_local $0)
@ -3761,6 +3771,7 @@
(i32.const 0)
)
)
)
(if
(i32.eq
(get_local $1)
@ -3770,7 +3781,6 @@
(i32.const 0)
)
)
)
(set_local $2
(i32.load
(get_local $0)
@ -5033,5 +5043,24 @@
(unreachable)
)
)
(if
(i32.eqz
(i32.eq
(i32.load
(i32.const 372)
)
(i32.const 3)
)
)
(block
(call $abort
(i32.const 0)
(i32.const 40)
(i32.const 64)
(i32.const 0)
)
(unreachable)
)
)
)
)

0
tests/parser/empty.ts Normal file
View File

View File