Skip to content
11 changes: 4 additions & 7 deletions std/assembly/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,10 @@ import { Array } from "./array";
}

@operator("+") private static __concat(left: String, right: String): String {
return select<String>(left, changetype<String>("null"), left !== null).concat(right);
return left.concat(right);
}

concat(other: String): String {
if (other === null) other = changetype<String>("null");
var thisSize: isize = this.length << 1;
var otherSize: isize = other.length << 1;
var outSize: usize = thisSize + otherSize;
Expand All @@ -96,7 +95,6 @@ import { Array } from "./array";
}

endsWith(search: String, end: i32 = String.MAX_LENGTH): bool {
if (search === null) return false;
end = min(max(end, 0), this.length);
var searchLength = <isize>search.length;
var searchStart = <isize>end - searchLength;
Expand Down Expand Up @@ -124,8 +122,8 @@ import { Array } from "./array";
return !this.__eq(left, right);
}

@operator(">") private static __gt(left: String | null, right: String | null): bool {
if (left === right || left === null || right === null) return false;
@operator(">") private static __gt(left: String, right: String): bool {
if (left === right) return false;
var leftLength = left.length;
if (!leftLength) return false;
var rightLength = right.length;
Expand All @@ -140,7 +138,7 @@ import { Array } from "./array";
}

@operator("<") private static __lt(left: String, right: String): bool {
if (left === right || left === null || right === null) return false;
if (left === right) return false;
var rightLength = right.length;
if (!rightLength) return false;
var leftLength = left.length;
Expand Down Expand Up @@ -196,7 +194,6 @@ import { Array } from "./array";
}

startsWith(search: String, start: i32 = 0): bool {
if (search === null) search = changetype<String>("null");
var len = <isize>this.length;
var searchStart = min(max(<isize>start, 0), len);
var searchLength = <isize>search.length;
Expand Down
134 changes: 58 additions & 76 deletions tests/compiler/std/array-access.optimized.wat
Original file line number Diff line number Diff line change
Expand Up @@ -13,88 +13,18 @@
(data (i32.const 1160) "\01\00\00\00^\00\00\00E\00l\00e\00m\00e\00n\00t\00 \00t\00y\00p\00e\00 \00m\00u\00s\00t\00 \00b\00e\00 \00n\00u\00l\00l\00a\00b\00l\00e\00 \00i\00f\00 \00a\00r\00r\00a\00y\00 \00i\00s\00 \00h\00o\00l\00e\00y")
(data (i32.const 1276) "\1c")
(data (i32.const 1288) "\01")
(data (i32.const 1308) "\1c")
(data (i32.const 1320) "\01\00\00\00\08\00\00\00n\00u\00l\00l")
(global $~lib/memory/__stack_pointer (mut i32) (i32.const 17724))
(global $~lib/memory/__stack_pointer (mut i32) (i32.const 17692))
(export "memory" (memory $0))
(export "i32ArrayArrayElementAccess" (func $export:std/array-access/i32ArrayArrayElementAccess))
(export "stringArrayPropertyAccess" (func $export:std/array-access/stringArrayPropertyAccess))
(export "stringArrayMethodCall" (func $export:std/array-access/stringArrayMethodCall))
(export "stringArrayArrayPropertyAccess" (func $export:std/array-access/stringArrayArrayPropertyAccess))
(export "stringArrayArrayMethodCall" (func $export:std/array-access/stringArrayArrayMethodCall))
(func $~stack_check
global.get $~lib/memory/__stack_pointer
i32.const 1340
i32.lt_s
if
i32.const 17744
i32.const 17792
i32.const 1
i32.const 1
call $~lib/builtins/abort
unreachable
end
)
(func $~lib/array/Array<~lib/array/Array<i32>>#__get (param $0 i32) (param $1 i32) (result i32)
global.get $~lib/memory/__stack_pointer
i32.const 4
i32.sub
global.set $~lib/memory/__stack_pointer
call $~stack_check
global.get $~lib/memory/__stack_pointer
i32.const 0
i32.store
local.get $1
local.get $0
i32.load offset=12
i32.ge_u
if
i32.const 1056
i32.const 1120
i32.const 92
i32.const 42
call $~lib/builtins/abort
unreachable
end
global.get $~lib/memory/__stack_pointer
local.get $0
i32.load offset=4
local.get $1
i32.const 2
i32.shl
i32.add
i32.load
local.tee $0
i32.store
local.get $0
i32.eqz
if
i32.const 1168
i32.const 1120
i32.const 96
i32.const 40
call $~lib/builtins/abort
unreachable
end
global.get $~lib/memory/__stack_pointer
i32.const 4
i32.add
global.set $~lib/memory/__stack_pointer
local.get $0
)
(func $~lib/string/String#startsWith (param $0 i32) (result i32)
(local $1 i32)
(local $2 i32)
(local $3 i32)
(local $4 i32)
global.get $~lib/memory/__stack_pointer
i32.const 4
i32.sub
global.set $~lib/memory/__stack_pointer
call $~stack_check
global.get $~lib/memory/__stack_pointer
i32.const 0
i32.store
i32.const 1292
i32.load
i32.const 1
Expand All @@ -119,10 +49,6 @@
local.get $2
i32.gt_s
if
global.get $~lib/memory/__stack_pointer
i32.const 4
i32.add
global.set $~lib/memory/__stack_pointer
i32.const 0
return
end
Expand Down Expand Up @@ -204,11 +130,67 @@
end
i32.const 0
end
i32.eqz
)
(func $~stack_check
global.get $~lib/memory/__stack_pointer
i32.const 1308
i32.lt_s
if
i32.const 17712
i32.const 17760
i32.const 1
i32.const 1
call $~lib/builtins/abort
unreachable
end
)
(func $~lib/array/Array<~lib/array/Array<i32>>#__get (param $0 i32) (param $1 i32) (result i32)
global.get $~lib/memory/__stack_pointer
i32.const 4
i32.add
i32.sub
global.set $~lib/memory/__stack_pointer
call $~stack_check
global.get $~lib/memory/__stack_pointer
i32.const 0
i32.store
local.get $1
local.get $0
i32.load offset=12
i32.ge_u
if
i32.const 1056
i32.const 1120
i32.const 92
i32.const 42
call $~lib/builtins/abort
unreachable
end
global.get $~lib/memory/__stack_pointer
local.get $0
i32.load offset=4
local.get $1
i32.const 2
i32.shl
i32.add
i32.load
local.tee $0
i32.store
local.get $0
i32.eqz
if
i32.const 1168
i32.const 1120
i32.const 96
i32.const 40
call $~lib/builtins/abort
unreachable
end
global.get $~lib/memory/__stack_pointer
i32.const 4
i32.add
global.set $~lib/memory/__stack_pointer
local.get $0
)
(func $export:std/array-access/i32ArrayArrayElementAccess (param $0 i32) (result i32)
global.get $~lib/memory/__stack_pointer
Expand Down
131 changes: 50 additions & 81 deletions tests/compiler/std/array-access.untouched.wat
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@
(data (i32.const 76) ",\00\00\00\00\00\00\00\00\00\00\00\01\00\00\00\1a\00\00\00~\00l\00i\00b\00/\00a\00r\00r\00a\00y\00.\00t\00s\00\00\00")
(data (i32.const 124) "|\00\00\00\00\00\00\00\00\00\00\00\01\00\00\00^\00\00\00E\00l\00e\00m\00e\00n\00t\00 \00t\00y\00p\00e\00 \00m\00u\00s\00t\00 \00b\00e\00 \00n\00u\00l\00l\00a\00b\00l\00e\00 \00i\00f\00 \00a\00r\00r\00a\00y\00 \00i\00s\00 \00h\00o\00l\00e\00y\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00")
(data (i32.const 252) "\1c\00\00\00\00\00\00\00\00\00\00\00\01\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00")
(data (i32.const 284) "\1c\00\00\00\00\00\00\00\00\00\00\00\01\00\00\00\08\00\00\00n\00u\00l\00l\00\00\00\00\00")
(table $0 1 funcref)
(global $~lib/ASC_SHRINK_LEVEL i32 (i32.const 0))
(global $~lib/memory/__data_end i32 (i32.const 316))
(global $~lib/memory/__stack_pointer (mut i32) (i32.const 16700))
(global $~lib/memory/__heap_base i32 (i32.const 16700))
(global $~lib/memory/__data_end i32 (i32.const 284))
(global $~lib/memory/__stack_pointer (mut i32) (i32.const 16668))
(global $~lib/memory/__heap_base i32 (i32.const 16668))
(export "memory" (memory $0))
(export "i32ArrayArrayElementAccess" (func $export:std/array-access/i32ArrayArrayElementAccess))
(export "stringArrayPropertyAccess" (func $export:std/array-access/stringArrayPropertyAccess))
Expand Down Expand Up @@ -164,13 +163,58 @@
end
i32.const 0
)
(func $~lib/string/String#startsWith (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(local $3 i32)
(local $4 i32)
(local $5 i32)
(local $6 i32)
(local $7 i32)
local.get $0
call $~lib/string/String#get:length
local.set $3
local.get $2
local.tee $4
i32.const 0
local.tee $5
local.get $4
local.get $5
i32.gt_s
select
local.tee $5
local.get $3
local.tee $4
local.get $5
local.get $4
i32.lt_s
select
local.set $6
local.get $1
call $~lib/string/String#get:length
local.set $7
local.get $7
local.get $6
i32.add
local.get $3
i32.gt_s
if
i32.const 0
return
end
local.get $0
local.get $6
local.get $1
i32.const 0
local.get $7
call $~lib/util/string/compareImpl
i32.eqz
)
(func $~stack_check
global.get $~lib/memory/__stack_pointer
global.get $~lib/memory/__data_end
i32.lt_s
if
i32.const 16720
i32.const 16768
i32.const 16688
i32.const 16736
i32.const 1
i32.const 1
call $~lib/builtins/abort
Expand Down Expand Up @@ -451,81 +495,6 @@
global.set $~lib/memory/__stack_pointer
local.get $3
)
(func $~lib/string/String#startsWith (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(local $3 i32)
(local $4 i32)
(local $5 i32)
(local $6 i32)
(local $7 i32)
(local $8 i32)
global.get $~lib/memory/__stack_pointer
i32.const 4
i32.sub
global.set $~lib/memory/__stack_pointer
call $~stack_check
global.get $~lib/memory/__stack_pointer
i32.const 0
i32.store
local.get $1
i32.const 0
i32.eq
if
global.get $~lib/memory/__stack_pointer
i32.const 304
local.tee $1
i32.store
end
local.get $0
call $~lib/string/String#get:length
local.set $3
local.get $2
local.tee $4
i32.const 0
local.tee $5
local.get $4
local.get $5
i32.gt_s
select
local.tee $5
local.get $3
local.tee $4
local.get $5
local.get $4
i32.lt_s
select
local.set $6
local.get $1
call $~lib/string/String#get:length
local.set $7
local.get $7
local.get $6
i32.add
local.get $3
i32.gt_s
if
i32.const 0
local.set $8
global.get $~lib/memory/__stack_pointer
i32.const 4
i32.add
global.set $~lib/memory/__stack_pointer
local.get $8
return
end
local.get $0
local.get $6
local.get $1
i32.const 0
local.get $7
call $~lib/util/string/compareImpl
i32.eqz
local.set $8
global.get $~lib/memory/__stack_pointer
i32.const 4
i32.add
global.set $~lib/memory/__stack_pointer
local.get $8
)
(func $~lib/array/Array<~lib/array/Array<~lib/string/String>>#__get (param $0 i32) (param $1 i32) (result i32)
(local $2 i32)
(local $3 i32)
Expand Down
Loading