From 3614f9cfe4f3a99f6a5e0550ed5dce1924945849 Mon Sep 17 00:00:00 2001 From: "Randall C. O'Reilly" Date: Sun, 25 Oct 2026 07:59:07 +0100 Subject: [PATCH] perf(compiler): read slice elements by the representation of their type A read of a slice element lowered to arrayIndex, which tests the representations of a collection in turn (window object, typed array, plain array). Where engines do not inline it, as in functions with many element reads, each call pays for the tests that do not apply, and the property loads in arrayIndex see every kind of collection in the program. The type of a slice tells which representation it usually has: a typed array if its element type is held in one (see typedSliceArray), and otherwise a plain array or a window object. A read of an element of such a slice now calls typedSliceIndex or plainSliceIndex, which test that representation first in one condition, and are otherwise arrayIndex, so only the speed depends on the choice. Slices whose element type has a type parameter, and other indexed values, still use arrayIndex. Both helpers are pure readers that may be evaluated twice, as arrayIndex is. In a benchmark of a neural network update function under Node 26 (a dozen reads and writes of tensor elements through Cogent Lab's fixed-arity accessors), an element access takes 15 ns instead of 21 ns. Signed-off-by: Randall C. O'Reilly --- compiler/lowering.go | 28 +++- compiler/runtime-contract.go | 4 + compiler/skeleton_test.go | 2 +- gs/builtin/slice.test.ts | 51 +++++++- gs/builtin/slice.ts | 60 +++++++++ .../anonymous_struct_slice.gs.ts | 2 +- .../anonymous_struct_value_copy.gs.ts | 14 +- .../append_field_pointers.gs.ts | 2 +- .../append_spare_capacity.gs.ts | 28 ++-- .../append_value_copy/append_value_copy.gs.ts | 6 +- .../array_assign_in_place.gs.ts | 4 +- .../array_pointer_element_slice.gs.ts | 2 +- .../array_pointer_ops/array_pointer_ops.gs.ts | 8 +- .../assign_op_asi_barrier.gs.ts | 6 +- .../async_call_index_target.gs.ts | 2 +- .../binary_struct_pointer.gs.ts | 8 +- .../bool_slice_zero/bool_slice_zero.gs.ts | 4 +- .../bulk_copy_array_values.gs.ts | 30 ++--- .../byte_slice_composite_literal.gs.ts | 6 +- .../clear_large_words/clear_large_words.gs.ts | 6 +- tests/tests/clear_slice/clear_slice.gs.ts | 6 +- .../composite_literal_field_shadow.gs.ts | 2 +- .../composite_literal_nested_await.gs.ts | 4 +- .../compound_assign_side_effects.gs.ts | 24 ++-- .../copy_struct_elements_in_place.gs.ts | 16 +-- .../dead_code_methods/dead_code_methods.gs.ts | 8 +- .../dead_code_reflect_methods.gs.ts | 4 +- .../embed_data_kinds/embed_data_kinds.gs.ts | 6 +- .../embedded_named_basic_method.gs.ts | 2 +- .../factory_async_callback.gs.ts | 4 +- .../field_pointer_receiver_identity.gs.ts | 12 +- .../function_slice_call.gs.ts | 2 +- .../function_type_assertion.gs.ts | 4 +- .../generic_constrained_slice_clone.gs.ts | 2 +- .../generic_erased_struct_make.gs.ts | 2 +- .../generic_index_assignment.gs.ts | 6 +- .../generic_interface_type_name.gs.ts | 4 +- .../generic_numeric_slice_xor.gs.ts | 2 +- .../generic_pointer_equal.gs.ts | 4 +- .../generic_range_map_type_param.gs.ts | 6 +- .../generic_struct_clone.gs.ts | 4 +- .../generic_struct_field_copy.gs.ts | 4 +- .../generic_struct_value_copy.gs.ts | 8 +- .../tests/generics_basic/generics_basic.gs.ts | 2 +- tests/tests/goto_general/goto_general.gs.ts | 2 +- tests/tests/hash_crc32/main.gs.ts | 8 +- .../import_type_methods.gs.ts | 2 +- .../imported_generic_function.gs.ts | 4 +- .../incdec_wrap_round/incdec_wrap_round.gs.ts | 4 +- .../index_expr_destructuring.gs.ts | 2 +- .../index_out_of_range.gs.ts | 6 +- .../interface_override_sync.gs.ts | 6 +- .../interface_slice_index_short_decl.gs.ts | 8 +- .../interface_struct_value_box.gs.ts | 2 +- .../js_global_name_shadow.gs.ts | 2 +- .../json_rawmessage_elements.gs.ts | 2 +- .../keyed_array_literal.gs.ts | 10 +- .../loop_slice_window/loop_slice_window.gs.ts | 16 +-- tests/tests/make_slice/make_slice.gs.ts | 12 +- .../make_slice_array_elems.gs.ts | 28 ++-- .../make_slice_struct_zero.gs.ts | 6 +- .../map_interface_pointer_keys.gs.ts | 2 +- .../map_range_struct_key_copy.gs.ts | 2 +- .../math_rand_sequences.gs.ts | 4 +- .../math_rand_v2_sequences.gs.ts | 4 +- .../method_call_slice_type.gs.ts | 4 +- .../named_function_type_call.gs.ts | 2 +- .../nil_slice_append_spread.gs.ts | 2 +- .../nil_slice_closure_append.gs.ts | 2 +- .../os_args_program_name.gs.ts | 2 +- .../override_variadic_func_values.gs.ts | 2 +- .../package_import_archive_zip_writer.gs.ts | 4 +- .../package_import_asn1_rdn_sequence.gs.ts | 6 +- .../main.gs.ts | 2 +- .../package_import_crypto_sha1.gs.ts | 6 +- .../package_import_crypto_sha256.gs.ts | 6 +- .../package_import_encoding_json.gs.ts | 6 +- ...coding_json_reuse_interface_elements.gs.ts | 2 +- ...e_import_encoding_json_text_map_keys.gs.ts | 6 +- ...coding_json_text_unmarshaler_pointer.gs.ts | 2 +- ...encoding_json_unmarshal_pointer_hook.gs.ts | 2 +- ...import_fmt_pointer_receiver_stringer.gs.ts | 2 +- .../package_import_io_value_reader.gs.ts | 4 +- .../package_import_iter_pull.gs.ts | 4 +- .../package_import_iter_pull_sync_seq.gs.ts | 6 +- .../package_import_log_slog.gs.ts | 2 +- ...kage_import_pairing_dial_conversions.gs.ts | 2 +- .../package_import_protobuf_equalvt.gs.ts | 4 +- .../package_import_reflect.gs.ts | 6 +- .../package_import_slices.gs.ts | 86 ++++++------ .../package_import_slices_generic.gs.ts | 2 +- .../package_import_sort.gs.ts | 64 ++++----- .../package_import_starpc_srpc.gs.ts | 14 +- .../package_import_sync.gs.ts | 2 +- .../package_import_syscall_js.gs.ts | 6 +- .../package_import_typed_slices.gs.ts | 38 +++--- ...ckage_import_x509_create_certificate.gs.ts | 4 +- .../package_import_x509_tls_path.gs.ts | 8 +- .../package_table_constant_slice.gs.ts | 8 +- .../package_var_deferred_program.gs.ts | 10 +- .../package_var_deferred_table.gs.ts | 12 +- .../pointer_composite_literal_untyped.gs.ts | 14 +- .../pointer_element_identity.gs.ts | 16 +-- .../pointer_slice_element_shadow.gs.ts | 4 +- .../pointer_target_locals.gs.ts | 2 +- .../protobuf_cross_file_clone.gs.ts | 6 +- .../protobuf_lite_ts/protobuf_lite_ts.gs.ts | 4 +- .../range_assign_existing.gs.ts | 2 +- .../range_index_window_access.gs.ts | 12 +- .../range_shadow_rhs/range_shadow_rhs.gs.ts | 2 +- .../range_value_share/range_value_share.gs.ts | 12 +- .../reflect_elem_struct_pointer.gs.ts | 6 +- .../reflect_generic_field_types.gs.ts | 6 +- .../reflect_generic_methods.gs.ts | 14 +- .../reflect_make_func/reflect_make_func.gs.ts | 12 +- .../reflect_make_func_call_args.gs.ts | 8 +- .../reflect_make_func_call_twins.gs.ts | 18 +-- .../reflect_method_values.gs.ts | 18 +-- ...reflect_named_composite_type_methods.gs.ts | 2 +- .../reflect_nil_slice_interface.gs.ts | 2 +- .../reflect_number_interface.gs.ts | 4 +- .../reflect_set_bytes/reflect_set_bytes.gs.ts | 2 +- .../reflect_slice_at/reflect_slice_at.gs.ts | 4 +- .../reflect_slice_map_ops.gs.ts | 10 +- .../reflect_struct_field_go_types.gs.ts | 2 +- .../reflect_struct_of/reflect_struct_of.gs.ts | 4 +- .../reflect_value_methods_more.gs.ts | 4 +- .../runtime_caller_callsite.gs.ts | 2 +- .../shadowed_struct_varref_field.gs.ts | 6 +- .../short_decl_shadow_builtin.gs.ts | 2 +- tests/tests/slice/slice.gs.ts | 122 +++++++++--------- .../slice_append_shared_backing.gs.ts | 6 +- .../slice_copy_overlap.gs.ts | 12 +- .../slice_to_array_conversion.gs.ts | 10 +- .../slice_type_assertion.gs.ts | 2 +- .../slices_func_async_callback.gs.ts | 2 +- tests/tests/slices_grow/slices_grow.gs.ts | 2 +- .../slices_grow_zero_values.gs.ts | 8 +- .../slices_zero_freed_elements.gs.ts | 2 +- tests/tests/sort_operands/sort_operands.gs.ts | 20 +-- .../string_conversion/string_conversion.gs.ts | 8 +- .../string_invalid_utf8.gs.ts | 6 +- .../struct_assign_in_place.gs.ts | 6 +- .../struct_borrowed_results.gs.ts | 2 +- .../struct_equal_method.gs.ts | 2 +- .../struct_equal_unnamed.gs.ts | 2 +- .../struct_literal_interface.gs.ts | 2 +- .../struct_move_dead_locals.gs.ts | 14 +- .../struct_promoted_literal.gs.ts | 2 +- tests/tests/the_works/the_works.gs.ts | 6 +- .../type_method_primitive.gs.ts | 2 +- .../type_switch_statement.gs.ts | 2 +- .../typed_numeric_slices.gs.ts | 64 ++++----- .../unsafe_array_pointer_slice.gs.ts | 6 +- .../unsafe_noescape_uintptr_xor.gs.ts | 4 +- .../unsafe_string_slice_header.gs.ts | 4 +- .../unsafe_typed_slice_bytes.gs.ts | 12 +- .../value_param_readonly_calls.gs.ts | 6 +- .../wide_uint64_ops/wide_uint64_ops.gs.ts | 2 +- .../wrapper_slice_append.gs.ts | 2 +- 160 files changed, 779 insertions(+), 644 deletions(-) diff --git a/compiler/lowering.go b/compiler/lowering.go index 7fc30e21a..547397984 100644 --- a/compiler/lowering.go +++ b/compiler/lowering.go @@ -14675,11 +14675,33 @@ func (o *LoweringOwner) lowerIndexExpr(ctx lowerFileContext, expr *ast.IndexExpr return o.lowerMapGetValue(ctx, expr, target, index), diagnostics } - // Array elements are read directly; slices and the rest need arrayIndex. + // Array elements are read directly; slices and the rest need arrayIndex, + // or a version of it for the representations of a kind of slice. if array, ok := types.Unalias(targetType).Underlying().(*types.Array); ok { return o.lowerArrayElement(ctx, expr, target, index, array), diagnostics } - return o.runtimeOwner.QualifiedHelper(RuntimeHelperArrayIndex) + "(" + o.lowerIndexTarget(ctx, target, targetType) + ", " + o.lowerNumberIndexValue(ctx, expr.Index, index) + ")", diagnostics + helper := sliceIndexHelper(targetType) + return o.runtimeOwner.QualifiedHelper(helper) + "(" + o.lowerIndexTarget(ctx, target, targetType) + ", " + o.lowerNumberIndexValue(ctx, expr.Index, index) + ")", diagnostics +} + +// sliceIndexHelper returns the runtime helper that reads an element of a +// value of the given type at an index. A slice of a concrete type is a typed +// array if its element type is held in one (see typedSliceArray), and is +// otherwise a plain array or a window object, so typedSliceIndex or +// plainSliceIndex test that representation first, which is much faster than +// the general arrayIndex when the call is not inlined. Each of them is +// arrayIndex for the other representations, so the choice only affects the +// speed. A slice whose element type has a type parameter, and every other +// type, uses arrayIndex. +func sliceIndexHelper(typ types.Type) RuntimeHelper { + slice, ok := types.Unalias(typ).Underlying().(*types.Slice) + if !ok || typeContainsTypeParam(slice.Elem()) { + return RuntimeHelperArrayIndex + } + if array, _ := typedSliceArray(slice.Elem()); array != "" { + return RuntimeHelperTypedSliceIndex + } + return RuntimeHelperPlainSliceIndex } // lowerArrayElement lowers reading the element of an array value at an index. @@ -19753,7 +19775,7 @@ func isSimpleLoweredOperand(value string) bool { // The only calls are of runtime readers without side effects. for _, call := range simpleOperandCalls.FindAllStringSubmatch(value, -1) { switch call[1] { - case "$.pointerValue", "$.pointerTarget", "$.arrayIndex": + case "$.pointerValue", "$.pointerTarget", "$.arrayIndex", "$.plainSliceIndex", "$.typedSliceIndex": default: return false } diff --git a/compiler/runtime-contract.go b/compiler/runtime-contract.go index ca3e9ece0..c4002c7c1 100644 --- a/compiler/runtime-contract.go +++ b/compiler/runtime-contract.go @@ -174,6 +174,8 @@ const ( RuntimeHelperIndexString RuntimeHelper = "slice.indexString" RuntimeHelperArrayIndex RuntimeHelper = "slice.arrayIndex" RuntimeHelperCheckArrayIndex RuntimeHelper = "slice.checkArrayIndex" + RuntimeHelperTypedSliceIndex RuntimeHelper = "slice.typedSliceIndex" + RuntimeHelperPlainSliceIndex RuntimeHelper = "slice.plainSliceIndex" RuntimeHelperSliceStringOrBytes RuntimeHelper = "slice.sliceStringOrBytes" RuntimeHelperSliceStringEqual RuntimeHelper = "slice.sliceStringEqual" RuntimeHelperIndexRef RuntimeHelper = "slice.indexRef" @@ -509,6 +511,8 @@ func runtimeHelperContracts() []RuntimeHelperContract { runtimeHelper(RuntimeHelperIndexString, "indexString", RuntimeHelperCategorySlice), runtimeHelper(RuntimeHelperArrayIndex, "arrayIndex", RuntimeHelperCategorySlice), runtimeHelper(RuntimeHelperCheckArrayIndex, "checkArrayIndex", RuntimeHelperCategorySlice), + runtimeHelper(RuntimeHelperTypedSliceIndex, "typedSliceIndex", RuntimeHelperCategorySlice), + runtimeHelper(RuntimeHelperPlainSliceIndex, "plainSliceIndex", RuntimeHelperCategorySlice), runtimeHelper(RuntimeHelperSliceStringOrBytes, "sliceStringOrBytes", RuntimeHelperCategorySlice), runtimeHelper(RuntimeHelperSliceStringEqual, "sliceStringEqual", RuntimeHelperCategorySlice), runtimeHelper(RuntimeHelperIndexRef, "indexRef", RuntimeHelperCategorySlice), diff --git a/compiler/skeleton_test.go b/compiler/skeleton_test.go index 02fecc86a..d32beaea9 100644 --- a/compiler/skeleton_test.go +++ b/compiler/skeleton_test.go @@ -2556,7 +2556,7 @@ func TestCompilePackagesEmitsArraySliceMapStringAndNamedMethods(t *testing.T) { "$.mapSet(m, \"one\", 1)", "let [value, ok] = $.mapGet(m, \"missing\", 0)", "$.sliceSlot(slice!, 0)", - "$.arrayIndex(literal!, 2)", + "$.plainSliceIndex(literal!, 2)", "let list: $.VarRef = $.varRef(null! as MySlice)", "MySlice_Add(list, 7)", "$.indexString(text, 0)", diff --git a/gs/builtin/slice.test.ts b/gs/builtin/slice.test.ts index e0e8adc2c..3f1505523 100644 --- a/gs/builtin/slice.test.ts +++ b/gs/builtin/slice.test.ts @@ -1,4 +1,11 @@ -import { arrayIndex, sliceElems, sliceSlot, windowSlot } from './slice.js' +import { + arrayIndex, + plainSliceIndex, + sliceElems, + sliceSlot, + typedSliceIndex, + windowSlot, +} from './slice.js' import { describe, expect, it, vi } from 'vitest' import { makeMap, mapGet, mapSet } from './map.js' @@ -720,3 +727,45 @@ describe('typed slices', () => { expect(typedSliceHintOf([1])).toBe(undefined) }) }) + +describe('type-directed slice indexing', () => { + // typedSliceIndex and plainSliceIndex only test some representations + // first, so they read every slice as arrayIndex does. + const slices: [string, any][] = [ + ['plain array', [1, 2, 3]], + ['window', goSlice([0, 1, 2, 3, 4], 1, 4)], + ['typed array', new Float32Array([1, 2, 3])], + ['typed window', goSlice(new Int32Array([0, 1, 2, 3, 4]), 1, 4)], + ['proxy', arrayToSlice([[1], [2], [3]], 2)], + ] + for (const [name, slice] of slices) { + it(`reads a ${name} as arrayIndex does`, () => { + for (let i = 0; i < 3; i++) { + expect(typedSliceIndex(slice, i)).toEqual(arrayIndex(slice, i)) + expect(plainSliceIndex(slice, i)).toEqual(arrayIndex(slice, i)) + } + }) + } + + it('panics on nil slices and indexes out of range as arrayIndex does', () => { + // Each case panics with the same message as arrayIndex. + const cases: [any, number][] = [ + [null, 0], + [[1, 2], 2], + [[1, 2], -1], + [new Float32Array(2), 2], + [goSlice([0, 1, 2, 3], 1, 3), 2], + ] + for (const [slice, i] of cases) { + let want = '' + try { + arrayIndex(slice, i) + } catch (e) { + want = String(e) + } + expect(want).not.toBe('') + expect(() => typedSliceIndex(slice, i)).toThrow(want.replace(/^.*?: /, '')) + expect(() => plainSliceIndex(slice, i)).toThrow(want.replace(/^.*?: /, '')) + } + }) +}) diff --git a/gs/builtin/slice.ts b/gs/builtin/slice.ts index fcbcf7c2d..57801c547 100644 --- a/gs/builtin/slice.ts +++ b/gs/builtin/slice.ts @@ -2372,6 +2372,66 @@ export function arrayIndex< return arrayIndexSlow(collection, index) } +/** + * typedSliceIndex is arrayIndex for a slice whose element type is held in a + * typed array (see TypedSlice), which the compiler knows from its type. It + * tests that representation first, in one condition that engines optimize + * well even where they do not inline it, and is otherwise arrayIndex. + */ +export function typedSliceIndex< + C extends + | Slice + | SliceProxy + | unknown[] + | TypedSlice + | null + | undefined, +>(collection: C, index: number): ArrayIndexValue { + if ( + ArrayBuffer.isView(collection) && + index >= 0 && + index < (collection as TypedSlice).length + ) { + return (collection as TypedSlice)[index] as ArrayIndexValue + } + return arrayIndex(collection, index) +} + +/** + * plainSliceIndex is arrayIndex for a slice whose element type is not held in + * a typed array, which the compiler knows from its type, and which is then + * usually a plain array, or else a window object. It tests those + * representations first, a plain array in one condition that engines + * optimize well even where they do not inline it, and is otherwise + * arrayIndex. + */ +export function plainSliceIndex< + C extends + | Slice + | SliceProxy + | unknown[] + | TypedSlice + | null + | undefined, +>(collection: C, index: number): ArrayIndexValue { + if ( + Array.isArray(collection) && + index >= 0 && + index < collection.length && + (collection as any).__meta__ === undefined + ) { + return collection[index] as ArrayIndexValue + } + if ( + collection instanceof GoSlice && + index >= 0 && + index < collection.length + ) { + return collection.backing[collection.offset + index] as ArrayIndexValue + } + return arrayIndex(collection, index) +} + // arrayIndexSlow is arrayIndex for the representations and indexes that its // fast path does not handle. function arrayIndexSlow< diff --git a/tests/tests/anonymous_struct_slice/anonymous_struct_slice.gs.ts b/tests/tests/anonymous_struct_slice/anonymous_struct_slice.gs.ts index 803dabef5..e39017043 100644 --- a/tests/tests/anonymous_struct_slice/anonymous_struct_slice.gs.ts +++ b/tests/tests/anonymous_struct_slice/anonymous_struct_slice.gs.ts @@ -41,7 +41,7 @@ export async function main(): globalThis.Promise { let x = $.anonymousStructValue({Name: "third", Offsets: (null as $.Slice), Count: 3}, { kind: $.TypeKind.Struct, methods: [], fields: [/* @__PURE__ */ $.structField("Name", /* @__PURE__ */ $.basicType("string"), [0], 0, true), /* @__PURE__ */ $.structField("Offsets", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("int")), [1], 16, true), /* @__PURE__ */ $.structField("Count", /* @__PURE__ */ $.basicType("int"), [2], 40, true)] }) x.Offsets = $.appendOne(x.Offsets, 5) - await $.println(x.Name, $.arrayIndex(x.Offsets!, 0), x.Count) + await $.println(x.Name, $.plainSliceIndex(x.Offsets!, 0), x.Count) let __goscriptTuple0: any = buildNamedItems() let items: $.Slice = __goscriptTuple0[0] diff --git a/tests/tests/anonymous_struct_value_copy/anonymous_struct_value_copy.gs.ts b/tests/tests/anonymous_struct_value_copy/anonymous_struct_value_copy.gs.ts index e7b303660..a91000129 100644 --- a/tests/tests/anonymous_struct_value_copy/anonymous_struct_value_copy.gs.ts +++ b/tests/tests/anonymous_struct_value_copy/anonymous_struct_value_copy.gs.ts @@ -18,18 +18,18 @@ export async function main(): globalThis.Promise { await $.println("param:", a.N) let s = $.arrayToSlice<{"N": number}>([$.anonymousStructValue({N: 1}, { kind: $.TypeKind.Struct, methods: [], fields: [/* @__PURE__ */ $.structField("N", /* @__PURE__ */ $.basicType("int"), [0], 0, true)] })]) - let e = $.markAsStructValue($.cloneStructValue($.arrayIndex(s!, 0))) + let e = $.markAsStructValue($.cloneStructValue($.plainSliceIndex(s!, 0))) e.N = 9 - await $.println("index:", $.arrayIndex(s!, 0).N) + await $.println("index:", $.plainSliceIndex(s!, 0).N) let t = $.makeSlice<{"N": number}>(1, undefined, undefined, () => $.anonymousStructValue({"N": 0}, { kind: $.TypeKind.Struct, methods: [], fields: [/* @__PURE__ */ $.structField("N", /* @__PURE__ */ $.basicType("int"), [0], 0, true)] })) $.copy(t, s, true) - $.arrayIndex(t!, 0).N = 9 - await $.println("copy:", $.arrayIndex(s!, 0).N) + $.plainSliceIndex(t!, 0).N = 9 + await $.println("copy:", $.plainSliceIndex(s!, 0).N) let c = (slices.Clone(s) as $.Slice<{"N": number}>) - $.arrayIndex(c!, 0).N = 9 - await $.println("clone:", $.arrayIndex(s!, 0).N) + $.plainSliceIndex(c!, 0).N = 9 + await $.println("clone:", $.plainSliceIndex(s!, 0).N) let x: any = $.interfaceValue($.anonymousStructValue({N: 1}, { kind: $.TypeKind.Struct, methods: [], fields: [/* @__PURE__ */ $.structField("N", /* @__PURE__ */ $.basicType("int"), [0], 0, true)] }), "struct{N int}", { kind: $.TypeKind.Struct, methods: [], fields: [/* @__PURE__ */ $.structField("N", /* @__PURE__ */ $.basicType("int"), [0], 0, true)] }) { @@ -54,7 +54,7 @@ export async function main(): globalThis.Promise { let r = $.markAsStructValue($.cloneStructValue((__goscriptRangeWindow0.backing[__goscriptRangeWindow0.offset + __rangeIndex] as {"N": number}))) r.N = 9 } - await $.println("range:", $.arrayIndex(s!, 0).N) + await $.println("range:", $.plainSliceIndex(s!, 0).N) } var __goscriptStatic0$value: any diff --git a/tests/tests/append_field_pointers/append_field_pointers.gs.ts b/tests/tests/append_field_pointers/append_field_pointers.gs.ts index 9804b169d..62e2be061 100644 --- a/tests/tests/append_field_pointers/append_field_pointers.gs.ts +++ b/tests/tests/append_field_pointers/append_field_pointers.gs.ts @@ -152,7 +152,7 @@ export async function main(): globalThis.Promise { local.value.T.N = 4 for (let __goscriptRangeTarget0 = registry, __goscriptRangeWindow0 = $.sliceRange(__goscriptRangeTarget0), __goscriptSliceWindow0 = $.sliceRange(all), __goscriptSliceWindow1 = $.sliceRange(allPtrs), i = 0; i < __goscriptRangeWindow0.length; i++) { let g = (__goscriptRangeWindow0.backing[__goscriptRangeWindow0.offset + i] as Getter | null) - await $.println(i, (__goscriptAwait = (g !== null && (g as any).__isVarRef !== true && ((g as any).__goValue === undefined || (g as any).__goType?.charCodeAt(0) !== 42) ? (g as Exclude) : $.pointerValue>(g)).Get(), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait), $.pointerValue($.arrayIndex(ptrs!, i)).N, (__goscriptAwait = $.pointerValue>(((__goscriptSliceWindow0.backing as any[])[$.windowSlot(__goscriptSliceWindow0, i)] as Getter | null)).Get(), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait), $.pointerValue(((__goscriptSliceWindow1.backing as any[])[$.windowSlot(__goscriptSliceWindow1, i)] as T | $.VarRef | null)).N) + await $.println(i, (__goscriptAwait = (g !== null && (g as any).__isVarRef !== true && ((g as any).__goValue === undefined || (g as any).__goType?.charCodeAt(0) !== 42) ? (g as Exclude) : $.pointerValue>(g)).Get(), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait), $.pointerValue($.plainSliceIndex(ptrs!, i)).N, (__goscriptAwait = $.pointerValue>(((__goscriptSliceWindow0.backing as any[])[$.windowSlot(__goscriptSliceWindow0, i)] as Getter | null)).Get(), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait), $.pointerValue(((__goscriptSliceWindow1.backing as any[])[$.windowSlot(__goscriptSliceWindow1, i)] as T | $.VarRef | null)).N) } } diff --git a/tests/tests/append_spare_capacity/append_spare_capacity.gs.ts b/tests/tests/append_spare_capacity/append_spare_capacity.gs.ts index 31cfbaa9d..c0e926398 100644 --- a/tests/tests/append_spare_capacity/append_spare_capacity.gs.ts +++ b/tests/tests/append_spare_capacity/append_spare_capacity.gs.ts @@ -41,13 +41,13 @@ export async function main(): globalThis.Promise { ps = $.appendOne(ps, new pos(true, i + 1, i)) } let all = $.goSlice(ps, undefined, $.cap(ps)) - await $.println($.sliceLen(ps), $.cap(ps), $.arrayIndex(all!, 4).Line, $.arrayIndex(all!, 5).Line, $.arrayIndex(all!, 7).Char) - $.arrayIndex(all!, 5).Line = 9 - await $.println($.arrayIndex(all!, 5).Line, $.arrayIndex(all!, 6).Line) + await $.println($.sliceLen(ps), $.cap(ps), $.plainSliceIndex(all!, 4).Line, $.plainSliceIndex(all!, 5).Line, $.plainSliceIndex(all!, 7).Char) + $.plainSliceIndex(all!, 5).Line = 9 + await $.println($.plainSliceIndex(all!, 5).Line, $.plainSliceIndex(all!, 6).Line) // Appending after a reslice writes the slot the reslice zeroed. let more = $.appendOne(ps, new pos(true, 42)) - await $.println($.arrayIndex(more!, 5).Line, $.arrayIndex(all!, 5).Line) + await $.println($.plainSliceIndex(more!, 5).Line, $.plainSliceIndex(all!, 5).Line) // Grown slices of other element types have their zero values too. let ns: $.Slice = null! as $.Slice @@ -61,43 +61,43 @@ export async function main(): globalThis.Promise { let nall = $.goSlice(ns, undefined, $.cap(ns)) let sall = $.goSlice(ss, undefined, $.cap(ss)) let pall = $.goSlice(ptrs, undefined, $.cap(ptrs)) - await $.println($.arrayIndex(nall!, 3), $.stringLen($.arrayIndex(sall!, 3)), $.arrayIndex(pall!, 3) == null, $.pointerValue($.arrayIndex(ptrs!, 2)).Line) + await $.println($.plainSliceIndex(nall!, 3), $.stringLen($.plainSliceIndex(sall!, 3)), $.plainSliceIndex(pall!, 3) == null, $.pointerValue($.plainSliceIndex(ptrs!, 2)).Line) // A grown copy holds copies of the struct elements. let small = $.makeSlice(1, 1, undefined, () => new pos(true)) - $.arrayIndex(small!, 0).Line = 7 + $.plainSliceIndex(small!, 0).Line = 7 let grown = $.appendOne(small, new pos(true, 8)) - $.arrayIndex(grown!, 0).Line = 70 - await $.println($.arrayIndex(small!, 0).Line, $.arrayIndex(grown!, 0).Line, $.arrayIndex(grown!, 1).Line) + $.plainSliceIndex(grown!, 0).Line = 70 + await $.println($.plainSliceIndex(small!, 0).Line, $.plainSliceIndex(grown!, 0).Line, $.plainSliceIndex(grown!, 1).Line) // Appending a slice grows the same way. let ext = $.appendSlice($.arrayToSlice([new pos(true, 1)]), $.arrayToSlice([new pos(true, 2), new pos(true, 3)])) let full = $.goSlice(ext, undefined, $.cap(ext)) - await $.println($.sliceLen(ext), $.cap(ext) >= 3, $.arrayIndex(full!, $.sliceLen(full) - 1).Line) + await $.println($.sliceLen(ext), $.cap(ext) >= 3, $.plainSliceIndex(full!, $.sliceLen(full) - 1).Line) // Several values append in place into spare capacity, each a copy. let p = new pos(true, 5) let pair: $.Slice = $.appendValues($.makeSlice(0, 4, undefined, () => new pos(true)), undefined, (p).clone(), (p).clone()) - $.arrayIndex(pair!, 0).Line = 50 + $.plainSliceIndex(pair!, 0).Line = 50 p.Line = 500 let shared = $.goSlice(pair, undefined, 3) pair = $.appendValues(pair, undefined, new pos(true, 6), new pos(true, 7)) - await $.println($.sliceLen(pair), $.arrayIndex(pair!, 0).Line, $.arrayIndex(pair!, 1).Line, $.arrayIndex(pair!, 2).Line, $.arrayIndex(shared!, 2).Line, $.arrayIndex(pair!, 3).Line) + await $.println($.sliceLen(pair), $.plainSliceIndex(pair!, 0).Line, $.plainSliceIndex(pair!, 1).Line, $.plainSliceIndex(pair!, 2).Line, $.plainSliceIndex(shared!, 2).Line, $.plainSliceIndex(pair!, 3).Line) // Typed and zero-hinted elements append several values in place and // when they grow. let fs: $.Slice = $.makeSlice(0, 4, "float32") let fview = $.goSlice(fs, undefined, 4) fs = $.appendValues(fs, $.typedSliceHints.float32, 0.10000000149011612, 0.5, 2) - await $.println($.sliceLen(fs), $.cap(fs), $.arrayIndex(fview!, 0) == $.arrayIndex(fs!, 0), $.arrayIndex(fview!, 2)) + await $.println($.sliceLen(fs), $.cap(fs), $.typedSliceIndex(fview!, 0) == $.typedSliceIndex(fs!, 0), $.typedSliceIndex(fview!, 2)) fs = $.appendValues(fs, $.typedSliceHints.float32, 3, 4, 5) $.sliceElems(fview!)[$.sliceSlot(fview!, 1)] = 9 - await $.println($.sliceLen(fs), $.arrayIndex(fs!, 1), $.arrayIndex(fs!, 5), $.arrayIndex(fs!, 0) == 0.10000000149011612) + await $.println($.sliceLen(fs), $.typedSliceIndex(fs!, 1), $.typedSliceIndex(fs!, 5), $.typedSliceIndex(fs!, 0) == 0.10000000149011612) let cs: $.Slice<$.Complex> = null! as $.Slice<$.Complex> cs = $.appendValues(cs, $.appendZeros.complex, $.complex(1, 2), $.complex(3, 0)) let nps: $.Slice | null> = null! as $.Slice | null> nps = $.appendValues(nps, $.appendZeros.nil, null, new pos(false, 8)) - await $.println($.sliceLen(cs), $.real($.arrayIndex(cs!, 0)), $.imag($.arrayIndex(cs!, 1)), $.sliceLen(nps), $.arrayIndex(nps!, 0) == null, $.pointerValue($.arrayIndex(nps!, 1)).Line) + await $.println($.sliceLen(cs), $.real($.plainSliceIndex(cs!, 0)), $.imag($.plainSliceIndex(cs!, 1)), $.sliceLen(nps), $.plainSliceIndex(nps!, 0) == null, $.pointerValue($.plainSliceIndex(nps!, 1)).Line) } if ($.isMainScript(import.meta)) { diff --git a/tests/tests/append_value_copy/append_value_copy.gs.ts b/tests/tests/append_value_copy/append_value_copy.gs.ts index d421a104b..28bac8055 100644 --- a/tests/tests/append_value_copy/append_value_copy.gs.ts +++ b/tests/tests/append_value_copy/append_value_copy.gs.ts @@ -35,18 +35,18 @@ export async function main(): globalThis.Promise { let current = $.varRef(new cell(true, 7)) let cells = $.appendOne(null, (current.value).clone()) current.value = current.value.__goscriptAssign(new cell(true)) - await $.println("cell:", $.arrayIndex(cells!, 0).width, current.value.width) + await $.println("cell:", $.plainSliceIndex(cells!, 0).width, current.value.width) // Arrays also copy at the argument boundary. let row = $.arrayValue([3, 4]) let rows = $.appendOne(null, $.cloneArrayValue(row, /* @__PURE__ */ $.arrayType(/* @__PURE__ */ $.basicType("int"), 2))) row[0] = 9 - await $.println("array:", ($.arrayIndex(rows!, 0))[0], row[0]) + await $.println("array:", ($.plainSliceIndex(rows!, 0))[0], row[0]) // Pointer elements retain their identity. let pointers = $.appendOne | null>(null, current, $.appendZeros.nil) current.value.width = 11 - await $.println("pointer:", $.pointerValue($.arrayIndex(pointers!, 0)).width) + await $.println("pointer:", $.pointerValue($.plainSliceIndex(pointers!, 0)).width) } if ($.isMainScript(import.meta)) { diff --git a/tests/tests/array_assign_in_place/array_assign_in_place.gs.ts b/tests/tests/array_assign_in_place/array_assign_in_place.gs.ts index cd0f952ac..83eab9529 100644 --- a/tests/tests/array_assign_in_place/array_assign_in_place.gs.ts +++ b/tests/tests/array_assign_in_place/array_assign_in_place.gs.ts @@ -120,7 +120,7 @@ export async function main(): globalThis.Promise { $.assignFieldValue($.pointerValue(pa), pair(14, 15), __goscriptStatic0()) await $.println("deref:", $.pointerValue(e).v) let slice = $.arrayToSlice([$.arrayValue(globalThis.Array.from({ length: 2 }, () => new T(true)), /* @__PURE__ */ $.arrayType("main.T", 2))]) - let f = $.indexRef($.arrayIndex(slice!, 0), 0) + let f = $.indexRef($.plainSliceIndex(slice!, 0), 0) $.assignFieldValue($.sliceElems(slice!)[$.sliceSlot(slice!, 0)], pair(16, 17), __goscriptStatic0()) await $.println("slice element:", $.pointerValue(f).v) let nested = $.arrayValue(globalThis.Array.from({ length: 2 }, () => $.arrayValue(globalThis.Array.from({ length: 2 }, () => new T(true)), /* @__PURE__ */ $.arrayType("main.T", 2))), /* @__PURE__ */ $.arrayType(/* @__PURE__ */ $.arrayType("main.T", 2), 2)) @@ -169,7 +169,7 @@ export async function main(): globalThis.Promise { let sliced = $.arrayValue(globalThis.Array.from({ length: 2 }, () => new T(true)), /* @__PURE__ */ $.arrayType("main.T", 2)) let view = $.goSlice(sliced, undefined, undefined) sliced = $.assignFieldValue(sliced, pair(25, 26), __goscriptStatic0()) - await $.println("sliced:", $.arrayIndex(view!, 0).v, $.arrayIndex(view!, 1).v) + await $.println("sliced:", $.plainSliceIndex(view!, 0).v, $.plainSliceIndex(view!, 1).v) let captured = $.arrayValue(globalThis.Array.from({ length: 2 }, () => 0)) let read = $.functionValue((): number => { return captured[1] diff --git a/tests/tests/array_pointer_element_slice/array_pointer_element_slice.gs.ts b/tests/tests/array_pointer_element_slice/array_pointer_element_slice.gs.ts index 8a34e98b6..68f3e840d 100644 --- a/tests/tests/array_pointer_element_slice/array_pointer_element_slice.gs.ts +++ b/tests/tests/array_pointer_element_slice/array_pointer_element_slice.gs.ts @@ -39,7 +39,7 @@ export async function main(): globalThis.Promise { let child = new node(); ;(root$ as node).sub = $.appendOne($.goSlice((root$ as node).sub0, undefined, 0), child, $.appendZeros.nil) - await $.println($.sliceLen((root$ as node).sub), ($.arrayIndex((root$ as node).sub!, 0) === child || ($.pointerAliasesMade || ($.arrayIndex((root$ as node).sub!, 0) as any)?.__goElementBacking !== undefined) && $.pointerEqual($.arrayIndex((root$ as node).sub!, 0), child))) + await $.println($.sliceLen((root$ as node).sub), ($.plainSliceIndex((root$ as node).sub!, 0) === child || ($.pointerAliasesMade || ($.plainSliceIndex((root$ as node).sub!, 0) as any)?.__goElementBacking !== undefined) && $.pointerEqual($.plainSliceIndex((root$ as node).sub!, 0), child))) } var __goscriptStatic0$value: any diff --git a/tests/tests/array_pointer_ops/array_pointer_ops.gs.ts b/tests/tests/array_pointer_ops/array_pointer_ops.gs.ts index defb90057..8d9f49fd0 100644 --- a/tests/tests/array_pointer_ops/array_pointer_ops.gs.ts +++ b/tests/tests/array_pointer_ops/array_pointer_ops.gs.ts @@ -88,7 +88,7 @@ export async function main(): globalThis.Promise { let slices = $.arrayValue([$.arrayToSlice([1])]) let slicesCopy = $.cloneArrayValue(slices, /* @__PURE__ */ $.arrayType(/* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("int")), 1)) $.sliceElems(slicesCopy[0]!)[$.sliceSlot(slicesCopy[0]!, 0)] = 7 - await $.println("slice sharing:", $.arrayIndex(slices[0]!, 0)) + await $.println("slice sharing:", $.plainSliceIndex(slices[0]!, 0)) let structs = $.arrayValue([new item(true, 1)], __goscriptStatic1()) let structsCopy = $.cloneArrayValue(structs, /* @__PURE__ */ $.arrayType("main.item", 1)) @@ -104,7 +104,7 @@ export async function main(): globalThis.Promise { let copied = (original).clone() $.sliceElems(copied.slices[0]!)[$.sliceSlot(copied.slices[0]!, 0)] = 8 copied.items[0].value = 8 - await $.println("array fields:", $.arrayIndex(original.slices[0]!, 0), original.items[0].value, copied.items[0].value) + await $.println("array fields:", $.plainSliceIndex(original.slices[0]!, 0), original.items[0].value, copied.items[0].value) // Assigning an array element copies its value instead of aliasing the row. let rows = $.arrayValue([$.arrayValue([1, 2]), $.arrayValue([3, 4])], __goscriptStatic2()) @@ -127,11 +127,11 @@ export async function main(): globalThis.Promise { } let view = $.goSlice($.pointerValue(cache), undefined, undefined) - await $.println("slice:", $.sliceLen(view), $.arrayIndex(view!, 2)) + await $.println("slice:", $.sliceLen(view), $.plainSliceIndex(view!, 2)) let buf = new Uint8Array([9, 0, 0, 0, 0]) as $.Slice fillArray(($.sliceToArrayPointer($.goSlice(buf, 1, undefined), 4, "byte") as $.VarRef | null)) - await $.println("converted:", $.arrayIndex(buf!, 0), $.arrayIndex(buf!, 1), $.arrayIndex(buf!, 2), $.arrayIndex(buf!, 3), $.arrayIndex(buf!, 4)) + await $.println("converted:", $.typedSliceIndex(buf!, 0), $.typedSliceIndex(buf!, 1), $.typedSliceIndex(buf!, 2), $.typedSliceIndex(buf!, 3), $.typedSliceIndex(buf!, 4)) await $.println("converted sum:", sumArray(($.sliceToArrayPointer($.goSlice(buf, 1, undefined), 4, "byte") as $.VarRef | null))) let literal = $.varRef($.arrayValue(new Uint8Array([4, 3, 2, 1]))) diff --git a/tests/tests/assign_op_asi_barrier/assign_op_asi_barrier.gs.ts b/tests/tests/assign_op_asi_barrier/assign_op_asi_barrier.gs.ts index a01508172..24d673595 100644 --- a/tests/tests/assign_op_asi_barrier/assign_op_asi_barrier.gs.ts +++ b/tests/tests/assign_op_asi_barrier/assign_op_asi_barrier.gs.ts @@ -5,9 +5,9 @@ import * as $ from "@goscript/builtin/index.js" export function consume(v: $.VarRef<$.Slice<$.Slice>> | null, n: bigint): void { while ($.sliceLen($.pointerValue<$.Slice<$.Slice>>(v)) > 0) { - let ln0 = $.int64($.sliceLen($.arrayIndex(($.pointerValue<$.Slice<$.Slice>>(v))!, 0))) + let ln0 = $.int64($.sliceLen($.plainSliceIndex(($.pointerValue<$.Slice<$.Slice>>(v))!, 0))) if (ln0 > n) { - $.sliceElems(($.pointerValue<$.Slice<$.Slice>>(v))!)[$.sliceSlot(($.pointerValue<$.Slice<$.Slice>>(v))!, 0)] = $.goSlice($.arrayIndex(($.pointerValue<$.Slice<$.Slice>>(v))!, 0), $.int64ToNumber(n), undefined) + $.sliceElems(($.pointerValue<$.Slice<$.Slice>>(v))!)[$.sliceSlot(($.pointerValue<$.Slice<$.Slice>>(v))!, 0)] = $.goSlice($.plainSliceIndex(($.pointerValue<$.Slice<$.Slice>>(v))!, 0), $.int64ToNumber(n), undefined) return } n = $.int64Sub(n, ln0) @@ -19,7 +19,7 @@ export function consume(v: $.VarRef<$.Slice<$.Slice>> | null, n: bigint) export async function main(): globalThis.Promise { let values: $.VarRef<$.Slice<$.Slice>> = $.varRef($.arrayToSlice<$.Slice>([new Uint8Array([1, 2]) as $.Slice, new Uint8Array([3]) as $.Slice])) consume(values, 2n) - await $.println($.sliceLen(values.value), $.arrayIndex(values.value!, 0) == null) + await $.println($.sliceLen(values.value), $.plainSliceIndex(values.value!, 0) == null) } if ($.isMainScript(import.meta)) { diff --git a/tests/tests/async_call_index_target/async_call_index_target.gs.ts b/tests/tests/async_call_index_target/async_call_index_target.gs.ts index 6a215ac6d..c2a50d71d 100644 --- a/tests/tests/async_call_index_target/async_call_index_target.gs.ts +++ b/tests/tests/async_call_index_target/async_call_index_target.gs.ts @@ -18,7 +18,7 @@ export async function mapped(): globalThis.Promise { - await $.println($.arrayIndex((await values())!, 0)) + await $.println($.plainSliceIndex((await values())!, 0)) for (const [k, v] of (await mapped())?.entries() ?? []) { await $.println(k, v) } diff --git a/tests/tests/binary_struct_pointer/binary_struct_pointer.gs.ts b/tests/tests/binary_struct_pointer/binary_struct_pointer.gs.ts index 956b7246f..c7cf1315c 100644 --- a/tests/tests/binary_struct_pointer/binary_struct_pointer.gs.ts +++ b/tests/tests/binary_struct_pointer/binary_struct_pointer.gs.ts @@ -170,7 +170,7 @@ export async function main(): globalThis.Promise { } } await $.println("size:", binary.Size($.interfaceValue(h, "*main.header", /* @__PURE__ */ $.pointerType("main.header"))), "written:", buf.value.Len()) - await $.println("bytes:", $.uint($.arrayIndex(buf.value.Bytes()!, 0), 8), $.uint($.arrayIndex(buf.value.Bytes()!, 1), 8), $.uint($.arrayIndex(buf.value.Bytes()!, 2), 8), $.uint($.arrayIndex(buf.value.Bytes()!, 10), 8), $.uint($.arrayIndex(buf.value.Bytes()!, 12), 8)) + await $.println("bytes:", $.uint($.typedSliceIndex(buf.value.Bytes()!, 0), 8), $.uint($.typedSliceIndex(buf.value.Bytes()!, 1), 8), $.uint($.typedSliceIndex(buf.value.Bytes()!, 2), 8), $.uint($.typedSliceIndex(buf.value.Bytes()!, 10), 8), $.uint($.typedSliceIndex(buf.value.Bytes()!, 12), 8)) // Reading into a pointer to a struct fills its fields. let r: $.VarRef
= $.varRef(new header(true)) @@ -195,12 +195,12 @@ export async function main(): globalThis.Promise { let ob = $.makeSlice(binary.Size($.interfaceValue(objs, "[]main.item", /* @__PURE__ */ $.sliceType("main.item"))) + 1, undefined, "byte") $.sliceElems(ob!)[$.sliceSlot(ob!, $.sliceLen(ob) - 1)] = 9 let [n, err] = binary.Encode(ob, $.structInterfaceValue($.markAsStructValue($.cloneStructValue($.pointerValue(binary.LittleEndian))), "binary.littleEndian", __goscriptStatic6())!, $.interfaceValue($.goSlice(objs, 1, undefined), "[]main.item", /* @__PURE__ */ $.sliceType("main.item"))) - await $.println("objects:", binary.Size($.interfaceValue(objs, "[]main.item", /* @__PURE__ */ $.sliceType("main.item"))), n, err == null, $.arrayIndex(ob!, 12), $.arrayIndex(ob!, 13), $.arrayIndex(ob!, 14), $.arrayIndex(ob!, 15), $.arrayIndex(ob!, 48), $.arrayIndex(ob!, 52), $.arrayIndex(ob!, 64), $.arrayIndex(ob!, $.sliceLen(ob) - 1)) + await $.println("objects:", binary.Size($.interfaceValue(objs, "[]main.item", /* @__PURE__ */ $.sliceType("main.item"))), n, err == null, $.typedSliceIndex(ob!, 12), $.typedSliceIndex(ob!, 13), $.typedSliceIndex(ob!, 14), $.typedSliceIndex(ob!, 15), $.typedSliceIndex(ob!, 48), $.typedSliceIndex(ob!, 52), $.typedSliceIndex(ob!, 64), $.typedSliceIndex(ob!, $.sliceLen(ob) - 1)) let back = $.makeSlice(2, undefined, undefined, () => new item(true)) let __goscriptTuple0: any = binary.Decode(ob, $.structInterfaceValue($.markAsStructValue($.cloneStructValue($.pointerValue(binary.LittleEndian))), "binary.littleEndian", __goscriptStatic6())!, $.interfaceValue(back, "[]main.item", /* @__PURE__ */ $.sliceType("main.item"))) n = __goscriptTuple0[0] err = __goscriptTuple0[1] - await $.println("decoded:", n, err == null, $.structEqual($.arrayIndex(back!, 0), $.arrayIndex(objs!, 1)), $.structEqual($.arrayIndex(back!, 1), $.arrayIndex(objs!, 2)), ($.arrayIndex(back!, 1).Colors)[1].Y, $.arrayIndex(back!, 1).Index) + await $.println("decoded:", n, err == null, $.structEqual($.plainSliceIndex(back!, 0), $.plainSliceIndex(objs!, 1)), $.structEqual($.plainSliceIndex(back!, 1), $.plainSliceIndex(objs!, 2)), ($.plainSliceIndex(back!, 1).Colors)[1].Y, $.plainSliceIndex(back!, 1).Index) // Big-endian order and arrays of structs work the same way. let __goscriptTuple1: any = binary.Append(null, $.structInterfaceValue($.markAsStructValue($.cloneStructValue($.pointerValue(binary.BigEndian))), "binary.bigEndian", __goscriptStatic8())!, $.interfaceValue($.goSlice(objs, 2, undefined), "[]main.item", /* @__PURE__ */ $.sliceType("main.item"))) @@ -212,7 +212,7 @@ export async function main(): globalThis.Promise { let arr2: $.VarRef = $.varRef($.arrayValue(globalThis.Array.from({ length: 2 }, () => new vec4(true)), /* @__PURE__ */ $.arrayType("main.vec4", 2))) let __goscriptTuple3: any = binary.Decode(ab, $.structInterfaceValue($.markAsStructValue($.cloneStructValue($.pointerValue(binary.LittleEndian))), "binary.littleEndian", __goscriptStatic6())!, $.interfaceValue(arr2, "*[2]main.vec4", /* @__PURE__ */ $.pointerType(/* @__PURE__ */ $.arrayType("main.vec4", 2)))) err = __goscriptTuple3[1] - await $.println("big-endian:", $.sliceLen(be), $.arrayIndex(be!, 12), $.arrayIndex(be!, 13), "array:", $.sliceLen(ab), err == null, arr2.value[1].W) + await $.println("big-endian:", $.sliceLen(be), $.typedSliceIndex(be!, 12), $.typedSliceIndex(be!, 13), "array:", $.sliceLen(ab), err == null, arr2.value[1].W) } var __goscriptStatic0$value: any diff --git a/tests/tests/bool_slice_zero/bool_slice_zero.gs.ts b/tests/tests/bool_slice_zero/bool_slice_zero.gs.ts index 879f6e543..8a7257a6e 100644 --- a/tests/tests/bool_slice_zero/bool_slice_zero.gs.ts +++ b/tests/tests/bool_slice_zero/bool_slice_zero.gs.ts @@ -5,9 +5,9 @@ import * as $ from "@goscript/builtin/index.js" export async function main(): globalThis.Promise { let values = $.makeSlice(3, undefined, "boolean") - await $.println($.arrayIndex(values!, 0), $.arrayIndex(values!, 1), $.arrayIndex(values!, 2)) + await $.println($.plainSliceIndex(values!, 0), $.plainSliceIndex(values!, 1), $.plainSliceIndex(values!, 2)) $.sliceElems(values!)[$.sliceSlot(values!, 1)] = true - await $.println($.arrayIndex(values!, 0), $.arrayIndex(values!, 1), $.arrayIndex(values!, 2)) + await $.println($.plainSliceIndex(values!, 0), $.plainSliceIndex(values!, 1), $.plainSliceIndex(values!, 2)) } if ($.isMainScript(import.meta)) { diff --git a/tests/tests/bulk_copy_array_values/bulk_copy_array_values.gs.ts b/tests/tests/bulk_copy_array_values/bulk_copy_array_values.gs.ts index 82193608a..6d2ae3c5a 100644 --- a/tests/tests/bulk_copy_array_values/bulk_copy_array_values.gs.ts +++ b/tests/tests/bulk_copy_array_values/bulk_copy_array_values.gs.ts @@ -36,20 +36,20 @@ export async function main(): globalThis.Promise { let dst = $.makeSlice(1, undefined, undefined, () => $.arrayValue(globalThis.Array.from({ length: 1 }, () => 0))) $.copy(dst, src) - $.arrayIndex(dst!, 0)[0] = 9 - await $.println("copy:", ($.arrayIndex(src!, 0))[0]) + $.plainSliceIndex(dst!, 0)[0] = 9 + await $.println("copy:", ($.plainSliceIndex(src!, 0))[0]) let appended = $.appendSlice(null, src) - $.arrayIndex(appended!, 0)[0] = 9 - await $.println("append:", ($.arrayIndex(src!, 0))[0]) + $.plainSliceIndex(appended!, 0)[0] = 9 + await $.println("append:", ($.plainSliceIndex(src!, 0))[0]) let cloned = (slices.Clone(src) as $.Slice) - $.arrayIndex(cloned!, 0)[0] = 9 - await $.println("clone:", ($.arrayIndex(src!, 0))[0]) + $.plainSliceIndex(cloned!, 0)[0] = 9 + await $.println("clone:", ($.plainSliceIndex(src!, 0))[0]) let concat = (slices.Concat(src, src) as $.Slice) - $.arrayIndex(concat!, 1)[0] = 9 - await $.println("concat:", ($.arrayIndex(src!, 0))[0]) + $.plainSliceIndex(concat!, 1)[0] = 9 + await $.println("concat:", ($.plainSliceIndex(src!, 0))[0]) let __goscriptRangeReturn0 = false ;await (async () => { @@ -61,23 +61,23 @@ export async function main(): globalThis.Promise { if (__goscriptRangeReturn0) { return } - await $.println("values:", ($.arrayIndex(src!, 0))[0]) + await $.println("values:", ($.plainSliceIndex(src!, 0))[0]) let points = $.arrayToSlice([$.arrayValue([new point(true, 1)], __goscriptStatic0())]) let pointCopies = $.makeSlice(1, undefined, undefined, () => $.arrayValue(globalThis.Array.from({ length: 1 }, () => new point(true)), /* @__PURE__ */ $.arrayType("main.point", 1))) $.copy(pointCopies, points); - ;($.arrayIndex(pointCopies!, 0))[0].x = 9 - await $.println("struct array:", ($.arrayIndex(points!, 0))[0].x) + ;($.plainSliceIndex(pointCopies!, 0))[0].x = 9 + await $.println("struct array:", ($.plainSliceIndex(points!, 0))[0].x) let nested = $.arrayToSlice([$.arrayValue([$.arrayValue([1])], __goscriptStatic1())]) let nestedCopies = (slices.Clone(nested) as $.Slice); - ;($.arrayIndex(nestedCopies!, 0))[0][0] = 9 - await $.println("nested:", (($.arrayIndex(nested!, 0))[0])[0]) + ;($.plainSliceIndex(nestedCopies!, 0))[0][0] = 9 + await $.println("nested:", (($.plainSliceIndex(nested!, 0))[0])[0]) let shared = $.arrayToSlice<$.Slice>([$.arrayToSlice([1])]) let sharedCopies = (slices.Clone(shared) as $.Slice<$.Slice>) - $.sliceElems($.arrayIndex(sharedCopies!, 0)!)[$.sliceSlot($.arrayIndex(sharedCopies!, 0)!, 0)] = 9 - await $.println("slice elements share:", $.arrayIndex($.arrayIndex(shared!, 0)!, 0)) + $.sliceElems($.plainSliceIndex(sharedCopies!, 0)!)[$.sliceSlot($.plainSliceIndex(sharedCopies!, 0)!, 0)] = 9 + await $.println("slice elements share:", $.plainSliceIndex($.plainSliceIndex(shared!, 0)!, 0)) } var __goscriptStatic0$value: any diff --git a/tests/tests/byte_slice_composite_literal/byte_slice_composite_literal.gs.ts b/tests/tests/byte_slice_composite_literal/byte_slice_composite_literal.gs.ts index ec77563f3..5fcfdabe6 100644 --- a/tests/tests/byte_slice_composite_literal/byte_slice_composite_literal.gs.ts +++ b/tests/tests/byte_slice_composite_literal/byte_slice_composite_literal.gs.ts @@ -35,14 +35,14 @@ export async function main(): globalThis.Promise { // paths, rather than degrading to a generic Array backing. let b = new Uint8Array([1, 2, 3]) as $.Slice await $.println("non-empty:", b) - await $.println("index:", $.arrayIndex(b!, 0), $.arrayIndex(b!, 1), $.arrayIndex(b!, 2)) + await $.println("index:", $.typedSliceIndex(b!, 0), $.typedSliceIndex(b!, 1), $.typedSliceIndex(b!, 2)) await $.println("len:", $.sliceLen(b)) // Storing the literal in a struct field and reading it back must // preserve the Uint8Array backing without any append repairing it. let h = new holder(true, new Uint8Array([9, 8, 7]) as $.Slice) await $.println("stored:", h.data) - await $.println("stored index:", $.arrayIndex(h.data!, 1)) + await $.println("stored index:", $.typedSliceIndex(h.data!, 1)) // An empty non-nil []byte literal stays a Uint8Array. let e = new Uint8Array([]) as $.Slice @@ -60,7 +60,7 @@ export async function main(): globalThis.Promise { let n = 300 let m = new Uint8Array([$.uint(n, 8), 2]) as $.Slice await $.println("mixed:", m) - await $.println("mixed index:", $.arrayIndex(m!, 0), $.arrayIndex(m!, 1)) + await $.println("mixed index:", $.typedSliceIndex(m!, 0), $.typedSliceIndex(m!, 1)) } if ($.isMainScript(import.meta)) { diff --git a/tests/tests/clear_large_words/clear_large_words.gs.ts b/tests/tests/clear_large_words/clear_large_words.gs.ts index 4c5ee0b2d..06414aec1 100644 --- a/tests/tests/clear_large_words/clear_large_words.gs.ts +++ b/tests/tests/clear_large_words/clear_large_words.gs.ts @@ -8,13 +8,13 @@ export type word = number export async function main(): globalThis.Promise { let words = $.arrayToSlice([$.uint("9223372036854775808", 64), 5, $.uint("18446744073709551615", 64)]) $.clear($.goSlice(words, undefined, 2), () => 0) - await $.println("words", $.arrayIndex(words!, 0), $.arrayIndex(words!, 1), $.arrayIndex(words!, 2) == $.uint("18446744073709551615", 64)) + await $.println("words", $.plainSliceIndex(words!, 0), $.plainSliceIndex(words!, 1), $.plainSliceIndex(words!, 2) == $.uint("18446744073709551615", 64)) $.clear(words, () => 0) - await $.println("words", $.arrayIndex(words!, 0), $.arrayIndex(words!, 1), $.arrayIndex(words!, 2)) + await $.println("words", $.plainSliceIndex(words!, 0), $.plainSliceIndex(words!, 1), $.plainSliceIndex(words!, 2)) let wide = $.arrayToSlice([9223372036854775808n, 4611686018427387904n]) $.clear(wide, () => 0n) - await $.println("wide", $.arrayIndex(wide!, 0), $.arrayIndex(wide!, 1), $.arrayIndex(wide!, 0) == 0n) + await $.println("wide", $.plainSliceIndex(wide!, 0), $.plainSliceIndex(wide!, 1), $.plainSliceIndex(wide!, 0) == 0n) } if ($.isMainScript(import.meta)) { diff --git a/tests/tests/clear_slice/clear_slice.gs.ts b/tests/tests/clear_slice/clear_slice.gs.ts index bd91b462c..9061fb619 100644 --- a/tests/tests/clear_slice/clear_slice.gs.ts +++ b/tests/tests/clear_slice/clear_slice.gs.ts @@ -6,15 +6,15 @@ import * as $ from "@goscript/builtin/index.js" export async function main(): globalThis.Promise { let buf = new Uint8Array([1, 2, 3]) as $.Slice $.clear(buf, () => 0) - await $.println("bytes:", $.arrayIndex(buf!, 0), $.arrayIndex(buf!, 1), $.arrayIndex(buf!, 2)) + await $.println("bytes:", $.typedSliceIndex(buf!, 0), $.typedSliceIndex(buf!, 1), $.typedSliceIndex(buf!, 2)) let nums = $.arrayToSlice([4, 5, 6, 7]) $.clear($.goSlice(nums, 1, 3), () => 0) - await $.println("window:", $.arrayIndex(nums!, 0), $.arrayIndex(nums!, 1), $.arrayIndex(nums!, 2), $.arrayIndex(nums!, 3)) + await $.println("window:", $.plainSliceIndex(nums!, 0), $.plainSliceIndex(nums!, 1), $.plainSliceIndex(nums!, 2), $.plainSliceIndex(nums!, 3)) let words = $.arrayToSlice(["a", "b"]) $.clear(words, () => "") - await $.println("strings:", $.stringEqual($.arrayIndex(words!, 0), ""), $.stringEqual($.arrayIndex(words!, 1), "")) + await $.println("strings:", $.stringEqual($.plainSliceIndex(words!, 0), ""), $.stringEqual($.plainSliceIndex(words!, 1), "")) } if ($.isMainScript(import.meta)) { diff --git a/tests/tests/composite_literal_field_shadow/composite_literal_field_shadow.gs.ts b/tests/tests/composite_literal_field_shadow/composite_literal_field_shadow.gs.ts index fa8d67b9b..9626df2f1 100644 --- a/tests/tests/composite_literal_field_shadow/composite_literal_field_shadow.gs.ts +++ b/tests/tests/composite_literal_field_shadow/composite_literal_field_shadow.gs.ts @@ -36,7 +36,7 @@ export function newBuffer(data: $.Slice): buffer | $.VarRef | nu export async function main(): globalThis.Promise { let buf = newBuffer(new Uint8Array([7]) as $.Slice) - await $.println($.arrayIndex($.pointerValue(buf).buf!, 0)) + await $.println($.typedSliceIndex($.pointerValue(buf).buf!, 0)) } if ($.isMainScript(import.meta)) { diff --git a/tests/tests/composite_literal_nested_await/composite_literal_nested_await.gs.ts b/tests/tests/composite_literal_nested_await/composite_literal_nested_await.gs.ts index d6bb95867..d0686393d 100644 --- a/tests/tests/composite_literal_nested_await/composite_literal_nested_await.gs.ts +++ b/tests/tests/composite_literal_nested_await/composite_literal_nested_await.gs.ts @@ -90,10 +90,10 @@ export function defaultFlags(prefix: string): $.Slice { export async function main(): globalThis.Promise { let cmd = newCommand(new config(true, defaultFlags)) let cmd$: command = cmd == null ? $.pointerTarget(cmd) : (cmd as any).__isVarRef === true ? (cmd as any).value : (cmd as any).__goValue === undefined ? (cmd as any) : $.pointerTarget(cmd) - await $.println((cmd$ as command).name, $.arrayIndex((cmd$ as command).flags!, 0)) + await $.println((cmd$ as command).name, $.plainSliceIndex((cmd$ as command).flags!, 0)) await $.chanSend(results, 7) await $.println((__goscriptAwait = (cmd$ as command).action!(), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait)) - await $.println(lazyCommand.name, $.arrayIndex(lazyCommand.flags!, 0)) + await $.println(lazyCommand.name, $.plainSliceIndex(lazyCommand.flags!, 0)) await $.chanSend(results, 9) await $.println((__goscriptAwait = lazyCommand.action!(), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait)) } diff --git a/tests/tests/compound_assign_side_effects/compound_assign_side_effects.gs.ts b/tests/tests/compound_assign_side_effects/compound_assign_side_effects.gs.ts index 6bd9276bc..0dcaa7c32 100644 --- a/tests/tests/compound_assign_side_effects/compound_assign_side_effects.gs.ts +++ b/tests/tests/compound_assign_side_effects/compound_assign_side_effects.gs.ts @@ -142,16 +142,16 @@ export async function main(): globalThis.Promise { calls = 0 const __goscriptOperand0 = idx() $.sliceElems(s!)[$.sliceSlot(s!, __goscriptOperand0)] += 5 - await $.println("slice +=", $.arrayIndex(s!, 0), $.arrayIndex(s!, 1), $.arrayIndex(s!, 2), calls) + await $.println("slice +=", $.plainSliceIndex(s!, 0), $.plainSliceIndex(s!, 1), $.plainSliceIndex(s!, 2), calls) calls = 0 $.sliceElems(s!)[$.sliceSlot(s!, idx())]++ - await $.println("slice ++", $.arrayIndex(s!, 0), $.arrayIndex(s!, 1), $.arrayIndex(s!, 2), calls) + await $.println("slice ++", $.plainSliceIndex(s!, 0), $.plainSliceIndex(s!, 1), $.plainSliceIndex(s!, 2), calls) calls = 0 const __goscriptOperand1 = idx() $.sliceElems(s!)[$.sliceSlot(s!, __goscriptOperand1)] = $.intShl($.sliceElems(s!)[$.sliceSlot(s!, __goscriptOperand1)], 1) - await $.println("slice <<=", $.arrayIndex(s!, 0), $.arrayIndex(s!, 1), $.arrayIndex(s!, 2), calls) + await $.println("slice <<=", $.plainSliceIndex(s!, 0), $.plainSliceIndex(s!, 1), $.plainSliceIndex(s!, 2), calls) // Array index from a call. let a = $.arrayValue([1, 2, 3]) @@ -205,14 +205,14 @@ export async function main(): globalThis.Promise { calls = 0 const __goscriptOperand7 = idx() $.sliceElems(b!)[$.sliceSlot(b!, __goscriptOperand7)] = $.uint($.sliceElems(b!)[$.sliceSlot(b!, __goscriptOperand7)] + (10), 8) - await $.println("byte +=", $.arrayIndex(b!, 0), $.arrayIndex(b!, 1), $.arrayIndex(b!, 2), calls) + await $.println("byte +=", $.typedSliceIndex(b!, 0), $.typedSliceIndex(b!, 1), $.typedSliceIndex(b!, 2), calls) // String element. let ss = $.arrayToSlice(["a", "b", "c"]) calls = 0 const __goscriptOperand8 = idx() $.sliceElems(ss!)[$.sliceSlot(ss!, __goscriptOperand8)] += "z" - await $.println("string +=", $.arrayIndex(ss!, 0), $.arrayIndex(ss!, 1), $.arrayIndex(ss!, 2), calls) + await $.println("string +=", $.plainSliceIndex(ss!, 0), $.plainSliceIndex(ss!, 1), $.plainSliceIndex(ss!, 2), calls) // Dereference of a call result. calls = 0 @@ -249,12 +249,12 @@ export async function main(): globalThis.Promise { calls = 0 const __goscriptOperand14 = idx() $.sliceElems(q!)[$.sliceSlot(q!, __goscriptOperand14)] = globalThis.Math.trunc($.sliceElems(q!)[$.sliceSlot(q!, __goscriptOperand14)] / 2) - await $.println("int /=", $.arrayIndex(q!, 0), $.arrayIndex(q!, 1), $.arrayIndex(q!, 2), calls) + await $.println("int /=", $.plainSliceIndex(q!, 0), $.plainSliceIndex(q!, 1), $.plainSliceIndex(q!, 2), calls) calls = 0 const __goscriptOperand15 = idx() $.sliceElems(q!)[$.sliceSlot(q!, __goscriptOperand15)] %= 4 - await $.println("int %=", $.arrayIndex(q!, 0), $.arrayIndex(q!, 1), $.arrayIndex(q!, 2), calls) + await $.println("int %=", $.plainSliceIndex(q!, 0), $.plainSliceIndex(q!, 1), $.plainSliceIndex(q!, 2), calls) // A for loop post statement and an if statement init. let sum = $.arrayToSlice([0, 0, 0]) @@ -263,7 +263,7 @@ export async function main(): globalThis.Promise { ;(__goscriptSliceWindow0.backing as any[])[$.windowSlot(__goscriptSliceWindow0, __goscriptOperand16)] += n })()) { n++ } - await $.println("for post", $.arrayIndex(sum!, 0), $.arrayIndex(sum!, 1), $.arrayIndex(sum!, 2), calls) + await $.println("for post", $.plainSliceIndex(sum!, 0), $.plainSliceIndex(sum!, 1), $.plainSliceIndex(sum!, 2), calls) calls = 0 for (let n = 0; n < 3; (() => { const __goscriptMap2 = m @@ -277,8 +277,8 @@ export async function main(): globalThis.Promise { { const __goscriptOperand17 = idx() $.sliceElems(s!)[$.sliceSlot(s!, __goscriptOperand17)] -= 1 - if ($.arrayIndex(s!, 1) > 0) { - await $.println("if init", $.arrayIndex(s!, 0), $.arrayIndex(s!, 1), $.arrayIndex(s!, 2), calls) + if ($.plainSliceIndex(s!, 1) > 0) { + await $.println("if init", $.plainSliceIndex(s!, 0), $.plainSliceIndex(s!, 1), $.plainSliceIndex(s!, 2), calls) } } @@ -290,7 +290,7 @@ export async function main(): globalThis.Promise { }, ({ kind: $.TypeKind.Function, params: [], results: [] } as $.FunctionTypeInfo)) calls = 0 bump() - await $.println("closure +=", $.arrayIndex(captured!, 0), $.arrayIndex(captured!, 1), $.arrayIndex(captured!, 2), calls) + await $.println("closure +=", $.plainSliceIndex(captured!, 0), $.plainSliceIndex(captured!, 1), $.plainSliceIndex(captured!, 2), calls) // An index from an async interface method. let ch = $.makeChannel(3, 0, "both") @@ -303,7 +303,7 @@ export async function main(): globalThis.Promise { $.sliceElems(vals!)[$.sliceSlot(vals!, __goscriptOperand19)] += 5 const __goscriptOperand20 = (__goscriptAwait = (c !== null && (c as any).__isVarRef !== true && ((c as any).__goValue === undefined || (c as any).__goType?.charCodeAt(0) !== 42) ? (c as Exclude) : $.pointerValue>(c)).Next(), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait) $.sliceElems(vals!)[$.sliceSlot(vals!, __goscriptOperand20)] += 6 - await $.println("async index +=", $.arrayIndex(vals!, 0), $.arrayIndex(vals!, 1), $.arrayIndex(vals!, 2), calls) + await $.println("async index +=", $.plainSliceIndex(vals!, 0), $.plainSliceIndex(vals!, 1), $.plainSliceIndex(vals!, 2), calls) } var __goscriptStatic0$value: any diff --git a/tests/tests/copy_struct_elements_in_place/copy_struct_elements_in_place.gs.ts b/tests/tests/copy_struct_elements_in_place/copy_struct_elements_in_place.gs.ts index 53b491bc0..5d0149beb 100644 --- a/tests/tests/copy_struct_elements_in_place/copy_struct_elements_in_place.gs.ts +++ b/tests/tests/copy_struct_elements_in_place/copy_struct_elements_in_place.gs.ts @@ -78,18 +78,18 @@ export async function main(): globalThis.Promise { fmt.Println($.basicInterfaceValue(n, "int"), $.basicInterfaceValue((p$ as item).X, "int"), $.basicInterfaceValue((p$ as item).Y, "int"), $.interfaceValue($.cloneArrayValue((p$ as item).In.N, /* @__PURE__ */ $.arrayType(/* @__PURE__ */ $.basicType("int"), 2)), "[2]int", /* @__PURE__ */ $.arrayType(/* @__PURE__ */ $.basicType("int"), 2))) // The copies are values: changing the source leaves dst alone. - $.arrayIndex(src!, 1).X = 50 - $.arrayIndex(src!, 1).In.N[0] = 70 - fmt.Println($.basicInterfaceValue($.arrayIndex(dst!, 1).X, "int"), $.interfaceValue($.cloneArrayValue($.arrayIndex(dst!, 1).In.N, /* @__PURE__ */ $.arrayType(/* @__PURE__ */ $.basicType("int"), 2)), "[2]int", /* @__PURE__ */ $.arrayType(/* @__PURE__ */ $.basicType("int"), 2)), $.basicInterfaceValue((p$ as item).X, "int")) + $.plainSliceIndex(src!, 1).X = 50 + $.plainSliceIndex(src!, 1).In.N[0] = 70 + fmt.Println($.basicInterfaceValue($.plainSliceIndex(dst!, 1).X, "int"), $.interfaceValue($.cloneArrayValue($.plainSliceIndex(dst!, 1).In.N, /* @__PURE__ */ $.arrayType(/* @__PURE__ */ $.basicType("int"), 2)), "[2]int", /* @__PURE__ */ $.arrayType(/* @__PURE__ */ $.basicType("int"), 2)), $.basicInterfaceValue((p$ as item).X, "int")) // Overlapping copies within one backing array, forward and backward. let all = $.arrayToSlice([new item(true, 1), new item(true, 2), new item(true, 3), new item(true, 4)]) let q = $.indexRef(all!, 3) let q$: item = q == null ? $.pointerTarget(q) : (q as any).__isVarRef === true ? (q as any).value : (q as any).__goValue === undefined ? (q as any) : $.pointerTarget(q) $.copy($.goSlice(all, 1, undefined), all, true) - fmt.Println($.basicInterfaceValue($.arrayIndex(all!, 0).X, "int"), $.basicInterfaceValue($.arrayIndex(all!, 1).X, "int"), $.basicInterfaceValue($.arrayIndex(all!, 2).X, "int"), $.basicInterfaceValue($.arrayIndex(all!, 3).X, "int"), $.basicInterfaceValue((q$ as item).X, "int")) + fmt.Println($.basicInterfaceValue($.plainSliceIndex(all!, 0).X, "int"), $.basicInterfaceValue($.plainSliceIndex(all!, 1).X, "int"), $.basicInterfaceValue($.plainSliceIndex(all!, 2).X, "int"), $.basicInterfaceValue($.plainSliceIndex(all!, 3).X, "int"), $.basicInterfaceValue((q$ as item).X, "int")) $.copy(all, $.goSlice(all, 2, undefined), true) - fmt.Println($.basicInterfaceValue($.arrayIndex(all!, 0).X, "int"), $.basicInterfaceValue($.arrayIndex(all!, 1).X, "int"), $.basicInterfaceValue($.arrayIndex(all!, 2).X, "int"), $.basicInterfaceValue($.arrayIndex(all!, 3).X, "int"), $.basicInterfaceValue((q$ as item).X, "int")) + fmt.Println($.basicInterfaceValue($.plainSliceIndex(all!, 0).X, "int"), $.basicInterfaceValue($.plainSliceIndex(all!, 1).X, "int"), $.basicInterfaceValue($.plainSliceIndex(all!, 2).X, "int"), $.basicInterfaceValue($.plainSliceIndex(all!, 3).X, "int"), $.basicInterfaceValue((q$ as item).X, "int")) // A named slice type, an array window and a shorter source. let named: items = ($.makeSlice(2, undefined, undefined, () => new item(true)) as items) @@ -98,7 +98,7 @@ export async function main(): globalThis.Promise { let arr: item[] = $.arrayValue(globalThis.Array.from({ length: 3 }, () => new item(true)), /* @__PURE__ */ $.arrayType("main.item", 3)) let s = $.indexRef(arr, 2) $.copy($.goSlice(arr, 1, undefined), src, true) - fmt.Println($.basicInterfaceValue($.pointerValue(r).X, "int"), $.basicInterfaceValue($.arrayIndex(named!, 1).X, "int"), $.basicInterfaceValue($.pointerValue(s).X, "int"), $.basicInterfaceValue(arr[0].X, "int")) + fmt.Println($.basicInterfaceValue($.pointerValue(r).X, "int"), $.basicInterfaceValue($.plainSliceIndex(named!, 1).X, "int"), $.basicInterfaceValue($.pointerValue(s).X, "int"), $.basicInterfaceValue(arr[0].X, "int")) // Slices of pointers still copy the pointers. let a = new item(false, 1) @@ -106,8 +106,8 @@ export async function main(): globalThis.Promise { let ptrs = $.arrayToSlice | null>([a]) let others = $.arrayToSlice | null>([b]) $.copy(others, ptrs) - $.pointerValue($.arrayIndex(others!, 0)).Y = 8 - fmt.Println($.basicInterfaceValue($.pointerValue(a).Y, "int"), $.basicInterfaceValue($.pointerValue(b).Y, "int"), ($.arrayIndex(others!, 0) === a || ($.pointerAliasesMade || ($.arrayIndex(others!, 0) as any)?.__goElementBacking !== undefined) && $.pointerEqual($.arrayIndex(others!, 0), a))) + $.pointerValue($.plainSliceIndex(others!, 0)).Y = 8 + fmt.Println($.basicInterfaceValue($.pointerValue(a).Y, "int"), $.basicInterfaceValue($.pointerValue(b).Y, "int"), ($.plainSliceIndex(others!, 0) === a || ($.pointerAliasesMade || ($.plainSliceIndex(others!, 0) as any)?.__goElementBacking !== undefined) && $.pointerEqual($.plainSliceIndex(others!, 0), a))) } var __goscriptStatic0$value: any diff --git a/tests/tests/dead_code_methods/dead_code_methods.gs.ts b/tests/tests/dead_code_methods/dead_code_methods.gs.ts index 2d64e71c5..9959f2ba2 100644 --- a/tests/tests/dead_code_methods/dead_code_methods.gs.ts +++ b/tests/tests/dead_code_methods/dead_code_methods.gs.ts @@ -352,12 +352,12 @@ export function byLen_Len(s: byLen): number { } export function byLen_Less(s: byLen, i: number, j: number): boolean { - return $.stringLen($.arrayIndex(s!, i)) < $.stringLen($.arrayIndex(s!, j)) + return $.stringLen($.plainSliceIndex(s!, i)) < $.stringLen($.plainSliceIndex(s!, j)) } export function byLen_Swap(s: byLen, i: number, j: number): void { - let __goscriptAssign0_0: string = $.arrayIndex(s!, j) - let __goscriptAssign0_1: string = $.arrayIndex(s!, i) + let __goscriptAssign0_0: string = $.plainSliceIndex(s!, j) + let __goscriptAssign0_1: string = $.plainSliceIndex(s!, i) $.sliceElems(s!)[$.sliceSlot(s!, i)] = __goscriptAssign0_0 $.sliceElems(s!)[$.sliceSlot(s!, j)] = __goscriptAssign0_1 } @@ -371,7 +371,7 @@ export async function main(): globalThis.Promise { let [, ok] = $.typeAssertTuple(v, "main.checker") fmt.Println("checker:", ok) - fmt.Println($.structInterfaceValue($.markAsStructValue($.cloneStructValue($.arrayIndex((await $.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(reflect.ValueOf($.interfaceValue(d, "*main.Dog", /* @__PURE__ */ $.pointerType("main.Dog"))))).MethodByName("Ping"))).Call(null))!, 0))), "reflect.Value", __goscriptStatic0())) + fmt.Println($.structInterfaceValue($.markAsStructValue($.cloneStructValue($.plainSliceIndex((await $.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(reflect.ValueOf($.interfaceValue(d, "*main.Dog", /* @__PURE__ */ $.pointerType("main.Dog"))))).MethodByName("Ping"))).Call(null))!, 0))), "reflect.Value", __goscriptStatic0())) let c = new Counter() let inc: (() => void) | null = $.functionValue(((__receiver) => () => __receiver.Inc())($.pointerValue(c)), ({ kind: $.TypeKind.Function, params: [], results: [] } as $.FunctionTypeInfo), "main.(*Counter).Inc-fm") diff --git a/tests/tests/dead_code_reflect_methods/dead_code_reflect_methods.gs.ts b/tests/tests/dead_code_reflect_methods/dead_code_reflect_methods.gs.ts index ae9ed2127..8dab3c21f 100644 --- a/tests/tests/dead_code_reflect_methods/dead_code_reflect_methods.gs.ts +++ b/tests/tests/dead_code_reflect_methods/dead_code_reflect_methods.gs.ts @@ -80,7 +80,7 @@ export async function call(v: any, name: string, args: $.Slice): globalThis export async function main(): globalThis.Promise { let c = new Calc(false, 5) let names = $.arrayToSlice(["Add", "Double"]) - fmt.Println($.basicInterfaceValue($.markAsStructValue($.cloneStructValue($.arrayIndex((await call($.interfaceValue(c, "*main.Calc", /* @__PURE__ */ $.pointerType("main.Calc")), $.arrayIndex(names!, 0), $.arrayToSlice([$.basicInterfaceValue(3, "int")])))!, 0))).Int(), "int64"), $.basicInterfaceValue($.markAsStructValue($.cloneStructValue($.arrayIndex((await call($.interfaceValue(c, "*main.Calc", /* @__PURE__ */ $.pointerType("main.Calc")), $.arrayIndex(names!, 1), null))!, 0))).Int(), "int64")) + fmt.Println($.basicInterfaceValue($.markAsStructValue($.cloneStructValue($.plainSliceIndex((await call($.interfaceValue(c, "*main.Calc", /* @__PURE__ */ $.pointerType("main.Calc")), $.plainSliceIndex(names!, 0), $.arrayToSlice([$.basicInterfaceValue(3, "int")])))!, 0))).Int(), "int64"), $.basicInterfaceValue($.markAsStructValue($.cloneStructValue($.plainSliceIndex((await call($.interfaceValue(c, "*main.Calc", /* @__PURE__ */ $.pointerType("main.Calc")), $.plainSliceIndex(names!, 1), null))!, 0))).Int(), "int64")) let t = reflect.TypeOf($.interfaceValue(c, "*main.Calc", /* @__PURE__ */ $.pointerType("main.Calc"))) for (let i = 0; i < (__goscriptAwait = (t !== null && (t as any).__isVarRef !== true && ((t as any).__goValue === undefined || (t as any).__goType?.charCodeAt(0) !== 42) ? (t as Exclude) : $.pointerValue>(t)).NumMethod(), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait); i++) { @@ -88,7 +88,7 @@ export async function main(): globalThis.Promise { } let v = $.markAsStructValue($.cloneStructValue(reflect.ValueOf(__goscriptStatic3()))) for (let i = 0; i < $.markAsStructValue($.cloneStructValue(v)).NumMethod(); i++) { - fmt.Println(((__goscriptAwait = $.pointerValue>($.markAsStructValue($.cloneStructValue(v)).Type()).Method(i), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait) as reflect.Method).Name, $.markAsStructValue($.cloneStructValue($.arrayIndex((await $.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(v)).Method(i))).Call(null))!, 0))).String()) + fmt.Println(((__goscriptAwait = $.pointerValue>($.markAsStructValue($.cloneStructValue(v)).Type()).Method(i), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait) as reflect.Method).Name, $.markAsStructValue($.cloneStructValue($.plainSliceIndex((await $.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(v)).Method(i))).Call(null))!, 0))).String()) } await call($.interfaceValue(c, "*main.Calc", /* @__PURE__ */ $.pointerType("main.Calc")), "Reset", null) fmt.Println($.basicInterfaceValue($.pointerValue(c).base, "int")) diff --git a/tests/tests/embed_data_kinds/embed_data_kinds.gs.ts b/tests/tests/embed_data_kinds/embed_data_kinds.gs.ts index 2025cac2d..0d3a026ca 100644 --- a/tests/tests/embed_data_kinds/embed_data_kinds.gs.ts +++ b/tests/tests/embed_data_kinds/embed_data_kinds.gs.ts @@ -61,13 +61,13 @@ export async function main(): globalThis.Promise { await $.println("text bytes:", $.sliceLen(textBytes), $.stringEqual($.bytesToString(textBytes), text), sum(textBytes)) // Binary data keeps every byte value, and is a slice of its own. - await $.println("blob:", $.sliceLen(blob), $.arrayIndex(blob!, 0), $.arrayIndex(blob!, 255), $.arrayIndex(blob!, 256), sum(blob), $.bytesToString($.goSlice(blob, $.sliceLen(blob) - 4, undefined))) + await $.println("blob:", $.sliceLen(blob), $.typedSliceIndex(blob!, 0), $.typedSliceIndex(blob!, 255), $.typedSliceIndex(blob!, 256), sum(blob), $.bytesToString($.goSlice(blob, $.sliceLen(blob) - 4, undefined))) await $.println("small:", $.sliceLen(small), $.bytesToString(small)) - await $.println("unicode:", $.sliceLen(unicodeBytes), sum(unicodeBytes), $.stringEqual($.bytesToString(unicodeBytes), unicodeText), $.arrayIndex(unicodeBytes!, $.sliceLen(unicodeBytes) - 2)) + await $.println("unicode:", $.sliceLen(unicodeBytes), sum(unicodeBytes), $.stringEqual($.bytesToString(unicodeBytes), unicodeText), $.typedSliceIndex(unicodeBytes!, $.sliceLen(unicodeBytes) - 2)) $.sliceElems(blob!)[$.sliceSlot(blob!, 0)] = 42 let __goscriptTuple0: any = await $.markAsStructValue($.cloneStructValue(files)).ReadFile("blob.bin") let again: $.Slice = __goscriptTuple0[0] - await $.println("own:", $.arrayIndex(blob!, 0), $.arrayIndex(again!, 0)) + await $.println("own:", $.typedSliceIndex(blob!, 0), $.typedSliceIndex(again!, 0)) // Files read from an embedded file system match. let __goscriptTuple1: any = await $.markAsStructValue($.cloneStructValue(files)).ReadFile("blob.bin") diff --git a/tests/tests/embedded_named_basic_method/embedded_named_basic_method.gs.ts b/tests/tests/embedded_named_basic_method/embedded_named_basic_method.gs.ts index 1a3903b81..3a905ca61 100644 --- a/tests/tests/embedded_named_basic_method/embedded_named_basic_method.gs.ts +++ b/tests/tests/embedded_named_basic_method/embedded_named_basic_method.gs.ts @@ -172,7 +172,7 @@ export async function main(): globalThis.Promise { let post$: Post = post == null ? $.pointerTarget(post) : (post as any).__isVarRef === true ? (post as any).value : (post as any).__goValue === undefined ? (post as any) : $.pointerTarget(post) Tags_Add($.fieldRef((post$ as Post), "Tags"), "go") let a: Adder | null = $.interfaceValue(post, "*main.Post", /* @__PURE__ */ $.pointerType("main.Post")) - await $.println("pointer method:", (__goscriptAwait = (a !== null && (a as any).__isVarRef !== true && ((a as any).__goValue === undefined || (a as any).__goType?.charCodeAt(0) !== 42) ? (a as Exclude) : $.pointerValue>(a)).Add("js"), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait), $.sliceLen(((post$ as Post).Tags as Tags)), $.arrayIndex((post$ as Post).Tags!, 1)) + await $.println("pointer method:", (__goscriptAwait = (a !== null && (a as any).__isVarRef !== true && ((a as any).__goValue === undefined || (a as any).__goType?.charCodeAt(0) !== 42) ? (a as Exclude) : $.pointerValue>(a)).Add("js"), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait), $.sliceLen(((post$ as Post).Tags as Tags)), $.plainSliceIndex((post$ as Post).Tags!, 1)) } var __goscriptAwait: any diff --git a/tests/tests/factory_async_callback/factory_async_callback.gs.ts b/tests/tests/factory_async_callback/factory_async_callback.gs.ts index 98b9647da..b92261d37 100644 --- a/tests/tests/factory_async_callback/factory_async_callback.gs.ts +++ b/tests/tests/factory_async_callback/factory_async_callback.gs.ts @@ -15,8 +15,8 @@ export function __goscript_set_Factories(__goscriptValue: $.Slice { - let factories = ((__goscriptAwait = $.arrayIndex(Factories!, 0)!(new dep.Bus(true)), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait) as $.Slice) - await $.println((__goscriptAwait = $.pointerValue>($.arrayIndex(factories!, 0)).GetConfigID(), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait)) + let factories = ((__goscriptAwait = $.plainSliceIndex(Factories!, 0)!(new dep.Bus(true)), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait) as $.Slice) + await $.println((__goscriptAwait = $.pointerValue>($.plainSliceIndex(factories!, 0)).GetConfigID(), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait)) } var __goscriptAwait: any diff --git a/tests/tests/field_pointer_receiver_identity/field_pointer_receiver_identity.gs.ts b/tests/tests/field_pointer_receiver_identity/field_pointer_receiver_identity.gs.ts index dadf7b958..f8affe78e 100644 --- a/tests/tests/field_pointer_receiver_identity/field_pointer_receiver_identity.gs.ts +++ b/tests/tests/field_pointer_receiver_identity/field_pointer_receiver_identity.gs.ts @@ -279,7 +279,7 @@ export async function main(): globalThis.Promise { Node.prototype.Register.call($.fieldRef(item.value, "Node")) await $.println("embedded:", $.pointerEqual(item.value.Node.self, $.fieldRef(item.value, "Node")), Node.prototype.Is.call($.fieldRef(item.value, "Node"), $.fieldRef(item.value, "Node"))) let namer: Namer | null = $.interfaceValue(item, "*main.Item", /* @__PURE__ */ $.pointerType("main.Item")) - await $.println("interface:", (__goscriptAwait = (namer !== null && (namer as any).__isVarRef !== true && ((namer as any).__goValue === undefined || (namer as any).__goType?.charCodeAt(0) !== 42) ? (namer as Exclude) : $.pointerValue>(namer)).Is($.fieldRef(item.value, "Node")), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait), $.pointerEqual($.arrayIndex(registry!, 1), $.fieldRef(item.value, "Node"))) + await $.println("interface:", (__goscriptAwait = (namer !== null && (namer as any).__isVarRef !== true && ((namer as any).__goValue === undefined || (namer as any).__goType?.charCodeAt(0) !== 42) ? (namer as Exclude) : $.pointerValue>(namer)).Is($.fieldRef(item.value, "Node")), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait), $.pointerEqual($.plainSliceIndex(registry!, 1), $.fieldRef(item.value, "Node"))) // Nested fields, fields reached through a pointer, slice and array // elements. @@ -290,7 +290,7 @@ export async function main(): globalThis.Promise { void (ptr$ as Item).Child.Rename("child") await $.println("through pointer:", Node.prototype.Is.call($.fieldRef((ptr$ as Item), "Child"), $.fieldRef(item.value, "Child")), item.value.Child.name) Node.prototype.Register.call($.indexRef(item.value.List!, 1)) - await $.println("slice element:", $.pointerEqual($.arrayIndex(item.value.List!, 1).self, $.indexRef(item.value.List!, 1)), Node.prototype.Is.call($.indexRef(item.value.List!, 1), $.indexRef(item.value.List!, 1))) + await $.println("slice element:", $.pointerEqual($.plainSliceIndex(item.value.List!, 1).self, $.indexRef(item.value.List!, 1)), Node.prototype.Is.call($.indexRef(item.value.List!, 1), $.indexRef(item.value.List!, 1))) Node.prototype.Register.call($.indexRef(item.value.Pair, 0)) await $.println("array element:", $.pointerEqual(item.value.Pair[0].self, $.indexRef(item.value.Pair, 0))) @@ -300,7 +300,7 @@ export async function main(): globalThis.Promise { await $.println("local:", (local.value.self === local || ($.pointerAliasesMade || (local.value.self as any)?.__goElementBacking !== undefined) && $.pointerEqual(local.value.self, local)), Node.prototype.Is.call(global, global)) // The registry, a pointer-keyed map and interfaces hold the same pointers. - await $.println("registry:", $.pointerEqual($.arrayIndex(registry!, 0), $.fieldRef(item.value, "Child")), $.mapGet | null, number, number>(counts, $.fieldRef(item.value, "Child"), 0)[0], $.mapGet | null, number, number>(counts, local, 0)[0], $.len(counts)) + await $.println("registry:", $.pointerEqual($.plainSliceIndex(registry!, 0), $.fieldRef(item.value, "Child")), $.mapGet | null, number, number>(counts, $.fieldRef(item.value, "Child"), 0)[0], $.mapGet | null, number, number>(counts, local, 0)[0], $.len(counts)) let a: any = $.interfaceValue($.fieldRef(item.value, "Child"), "*main.Node", /* @__PURE__ */ $.pointerType("main.Node")) let b: any = $.interfaceValue(item.value.Child.self, "*main.Node", /* @__PURE__ */ $.pointerType("main.Node")) await $.println("any:", $.comparableEqual(a, b)) @@ -314,16 +314,16 @@ export async function main(): globalThis.Promise { box.value.Add(__goscriptStatic1(), item.value.Child.self) $.pointerValue(box.value.Get(__goscriptStatic1(), 0)).name = "boxed" let clone = (slices.Clone(registry) as $.Slice | null>) - $.pointerValue($.arrayIndex(clone!, 0)).name += "+cloned" + $.pointerValue($.plainSliceIndex(clone!, 0)).name += "+cloned" await $.println("generic:", item.value.Child.name, $.pointerEqual(box.value.Get(__goscriptStatic1(), 0), $.fieldRef(item.value, "Child"))) // Methods promoted from two levels down, called directly and as a value. let outer: $.VarRef = $.varRef(new Outer(true)) Node.prototype.Register.call($.fieldRef(outer.value.Item, "Node")) - await $.println("two levels:", $.pointerEqual(outer.value.Item.Node.self, $.fieldRef(outer.value.Item, "Node")), $.pointerEqual($.arrayIndex(registry!, $.sliceLen(registry) - 1), $.fieldRef(outer.value.Item, "Node"))) + await $.println("two levels:", $.pointerEqual(outer.value.Item.Node.self, $.fieldRef(outer.value.Item, "Node")), $.pointerEqual($.plainSliceIndex(registry!, $.sliceLen(registry) - 1), $.fieldRef(outer.value.Item, "Node"))) let register: (() => void) | null = $.functionValue(((__receiver) => () => Node.prototype.Register.call(__receiver))($.fieldRef(outer.value.Item, "Node")), ({ kind: $.TypeKind.Function, params: [], results: [] } as $.FunctionTypeInfo), "main.(*Node).Register-fm") register!() - await $.println("promoted method value:", $.pointerEqual($.arrayIndex(registry!, $.sliceLen(registry) - 1), $.fieldRef(outer.value.Item, "Node")), $.mapGet | null, number, number>(counts, $.fieldRef(outer.value.Item, "Node"), 0)[0]) + await $.println("promoted method value:", $.pointerEqual($.plainSliceIndex(registry!, $.sliceLen(registry) - 1), $.fieldRef(outer.value.Item, "Node")), $.mapGet | null, number, number>(counts, $.fieldRef(outer.value.Item, "Node"), 0)[0]) // A generic struct field and an async method keep the field's address. let holder: {"B": Self} = $.anonymousStructValue({"B": $.genericInstance(new Self(true, undefined, 0), __goscriptStatic4)}, { kind: $.TypeKind.Struct, methods: [], fields: [/* @__PURE__ */ $.structField("B", /* @__PURE__ */ $.genericStructType("main.Self", "main.Self[int]", () => [/* @__PURE__ */ $.structField("self", /* @__PURE__ */ $.pointerType("main.Self[int]"), [0], 0, false, { pkgPath: "github.com/s4wave/goscript/tests/tests/field_pointer_receiver_identity" }), /* @__PURE__ */ $.structField("v", /* @__PURE__ */ $.basicType("int"), [1], 8, false, { pkgPath: "github.com/s4wave/goscript/tests/tests/field_pointer_receiver_identity" })]), [0], 0, true)] }) diff --git a/tests/tests/function_slice_call/function_slice_call.gs.ts b/tests/tests/function_slice_call/function_slice_call.gs.ts index 7e021a073..2ee72fe13 100644 --- a/tests/tests/function_slice_call/function_slice_call.gs.ts +++ b/tests/tests/function_slice_call/function_slice_call.gs.ts @@ -8,7 +8,7 @@ export async function main(): globalThis.Promise { callbacks = $.appendOne(callbacks, $.functionValue((value: number): number => { return value + 1 }, ({ kind: $.TypeKind.Function, params: [/* @__PURE__ */ $.basicType("int")], results: [/* @__PURE__ */ $.basicType("int")] } as $.FunctionTypeInfo)), $.appendZeros.nil) - let value = ($.arrayIndex(callbacks!, 0)!(2) as number) + let value = ($.plainSliceIndex(callbacks!, 0)!(2) as number) await $.println("value:", value) } diff --git a/tests/tests/function_type_assertion/function_type_assertion.gs.ts b/tests/tests/function_type_assertion/function_type_assertion.gs.ts index 9f6e86a26..60ae3611a 100644 --- a/tests/tests/function_type_assertion/function_type_assertion.gs.ts +++ b/tests/tests/function_type_assertion/function_type_assertion.gs.ts @@ -141,7 +141,7 @@ export async function main(): globalThis.Promise { $.sliceElems(funcSlice!)[$.sliceSlot(funcSlice!, 0)] = $.interfaceValue($.namedFunction(greet, "main.Greeter", ({ kind: $.TypeKind.Function, name: "main.Greeter", params: [/* @__PURE__ */ $.basicType("string")], results: [/* @__PURE__ */ $.basicType("string")] } as $.FunctionTypeInfo)), "main.Greeter", ({ kind: $.TypeKind.Function, name: "main.Greeter", params: [/* @__PURE__ */ $.basicType("string")], results: [/* @__PURE__ */ $.basicType("string")] } as $.FunctionTypeInfo)) $.sliceElems(funcSlice!)[$.sliceSlot(funcSlice!, 1)] = $.interfaceValue($.namedFunction(add, "main.Adder", ({ kind: $.TypeKind.Function, name: "main.Adder", params: [/* @__PURE__ */ $.basicType("int"), /* @__PURE__ */ $.basicType("int")], results: [/* @__PURE__ */ $.basicType("int")] } as $.FunctionTypeInfo)), "main.Adder", ({ kind: $.TypeKind.Function, name: "main.Adder", params: [/* @__PURE__ */ $.basicType("int"), /* @__PURE__ */ $.basicType("int")], results: [/* @__PURE__ */ $.basicType("int")] } as $.FunctionTypeInfo)) - let __goscriptTuple7: any = $.typeAssertTuple<((name: string) => string | globalThis.Promise) | null>($.arrayIndex(funcSlice!, 0), ({ kind: $.TypeKind.Function, name: "main.Greeter", params: [/* @__PURE__ */ $.basicType("string")], results: [/* @__PURE__ */ $.basicType("string")] } as $.FunctionTypeInfo)) + let __goscriptTuple7: any = $.typeAssertTuple<((name: string) => string | globalThis.Promise) | null>($.plainSliceIndex(funcSlice!, 0), ({ kind: $.TypeKind.Function, name: "main.Greeter", params: [/* @__PURE__ */ $.basicType("string")], results: [/* @__PURE__ */ $.basicType("string")] } as $.FunctionTypeInfo)) let sliceFn: Greeter | null = __goscriptTuple7[0] ok = __goscriptTuple7[1] if (ok) { @@ -149,7 +149,7 @@ export async function main(): globalThis.Promise { } else { await $.println("Slice function assertion failed") } - let __goscriptTuple8: any = $.typeAssertTuple<((a: number, b: number) => number | globalThis.Promise) | null>($.arrayIndex(funcSlice!, 1), ({ kind: $.TypeKind.Function, name: "main.Adder", params: [/* @__PURE__ */ $.basicType("int"), /* @__PURE__ */ $.basicType("int")], results: [/* @__PURE__ */ $.basicType("int")] } as $.FunctionTypeInfo)) + let __goscriptTuple8: any = $.typeAssertTuple<((a: number, b: number) => number | globalThis.Promise) | null>($.plainSliceIndex(funcSlice!, 1), ({ kind: $.TypeKind.Function, name: "main.Adder", params: [/* @__PURE__ */ $.basicType("int"), /* @__PURE__ */ $.basicType("int")], results: [/* @__PURE__ */ $.basicType("int")] } as $.FunctionTypeInfo)) let sliceAdderFn: Adder | null = __goscriptTuple8[0] ok = __goscriptTuple8[1] if (ok) { diff --git a/tests/tests/generic_constrained_slice_clone/generic_constrained_slice_clone.gs.ts b/tests/tests/generic_constrained_slice_clone/generic_constrained_slice_clone.gs.ts index 9f4dd81dc..0d906bafa 100644 --- a/tests/tests/generic_constrained_slice_clone/generic_constrained_slice_clone.gs.ts +++ b/tests/tests/generic_constrained_slice_clone/generic_constrained_slice_clone.gs.ts @@ -59,7 +59,7 @@ export async function cloneSlice(__typeArgs: $.GenericTypeArgs | undefined, i export async function main(): globalThis.Promise { let items = $.arrayToSlice | null>([new item(false, "first"), new item(false, "second")]) let cloned = (await cloneSlice(__goscriptStatic0(), items) as $.Slice | null>) - await $.println($.sliceLen(cloned), $.pointerValue($.arrayIndex(cloned!, 0)).value, $.pointerValue($.arrayIndex(cloned!, 1)).value, ($.arrayIndex(cloned!, 0) === $.arrayIndex(items!, 0) || ($.pointerAliasesMade || ($.arrayIndex(cloned!, 0) as any)?.__goElementBacking !== undefined) && $.pointerEqual($.arrayIndex(cloned!, 0), $.arrayIndex(items!, 0)))) + await $.println($.sliceLen(cloned), $.pointerValue($.plainSliceIndex(cloned!, 0)).value, $.pointerValue($.plainSliceIndex(cloned!, 1)).value, ($.plainSliceIndex(cloned!, 0) === $.plainSliceIndex(items!, 0) || ($.pointerAliasesMade || ($.plainSliceIndex(cloned!, 0) as any)?.__goElementBacking !== undefined) && $.pointerEqual($.plainSliceIndex(cloned!, 0), $.plainSliceIndex(items!, 0)))) } var __goscriptStatic0$value: any diff --git a/tests/tests/generic_erased_struct_make/generic_erased_struct_make.gs.ts b/tests/tests/generic_erased_struct_make/generic_erased_struct_make.gs.ts index 18cd7a493..543656e4d 100644 --- a/tests/tests/generic_erased_struct_make/generic_erased_struct_make.gs.ts +++ b/tests/tests/generic_erased_struct_make/generic_erased_struct_make.gs.ts @@ -37,7 +37,7 @@ export async function main(): globalThis.Promise { let q = (newQueue(__goscriptStatic0(), 2) as queue | $.VarRef | null) let q$: queue = q == null ? $.pointerTarget(q) : (q as any).__isVarRef === true ? (q as any).value : (q as any).__goValue === undefined ? (q as any) : $.pointerTarget(q) $.sliceElems((q$ as queue).buf!)[$.sliceSlot((q$ as queue).buf!, 0)] = 7 - await $.println($.sliceLen((q$ as queue).buf), $.arrayIndex((q$ as queue).buf!, 0)) + await $.println($.sliceLen((q$ as queue).buf), $.plainSliceIndex((q$ as queue).buf!, 0)) } var __goscriptStatic0$value: any diff --git a/tests/tests/generic_index_assignment/generic_index_assignment.gs.ts b/tests/tests/generic_index_assignment/generic_index_assignment.gs.ts index 1b3ffd067..4b33f7ed9 100644 --- a/tests/tests/generic_index_assignment/generic_index_assignment.gs.ts +++ b/tests/tests/generic_index_assignment/generic_index_assignment.gs.ts @@ -15,9 +15,9 @@ export async function main(): globalThis.Promise { let slice = $.arrayToSlice([1, 2, 3]) modifyGenericSlice(__goscriptStatic0(), slice, 1, 42) - await $.println("slice[0]:", $.arrayIndex(slice!, 0)) - await $.println("slice[1]:", $.arrayIndex(slice!, 1)) - await $.println("slice[2]:", $.arrayIndex(slice!, 2)) + await $.println("slice[0]:", $.plainSliceIndex(slice!, 0)) + await $.println("slice[1]:", $.plainSliceIndex(slice!, 1)) + await $.println("slice[2]:", $.plainSliceIndex(slice!, 2)) await $.println("test finished") } diff --git a/tests/tests/generic_interface_type_name/generic_interface_type_name.gs.ts b/tests/tests/generic_interface_type_name/generic_interface_type_name.gs.ts index 9aaa7c671..d65e71bb3 100644 --- a/tests/tests/generic_interface_type_name/generic_interface_type_name.gs.ts +++ b/tests/tests/generic_interface_type_name/generic_interface_type_name.gs.ts @@ -112,7 +112,7 @@ export async function main(): globalThis.Promise { let v = (__goscriptRangeWindow1.backing[__goscriptRangeWindow1.offset + __rangeIndex] as any) fmt.Printf("%T\n", v) } - for (let __goscriptRangeTarget2 = box(__goscriptStatic3(), $.arrayIndex(nodes!, 0)), __goscriptRangeWindow2 = $.sliceRange(__goscriptRangeTarget2), __rangeIndex = 0; __rangeIndex < __goscriptRangeWindow2.length; __rangeIndex++) { + for (let __goscriptRangeTarget2 = box(__goscriptStatic3(), $.plainSliceIndex(nodes!, 0)), __goscriptRangeWindow2 = $.sliceRange(__goscriptRangeTarget2), __rangeIndex = 0; __rangeIndex < __goscriptRangeWindow2.length; __rangeIndex++) { let v = (__goscriptRangeWindow2.backing[__goscriptRangeWindow2.offset + __rangeIndex] as any) fmt.Printf("%T\n", v) } @@ -121,7 +121,7 @@ export async function main(): globalThis.Promise { fmt.Printf("%T\n", v) } { - const __goscriptTypeSwitchValue = $.arrayIndex(nodes!, 1) + const __goscriptTypeSwitchValue = $.plainSliceIndex(nodes!, 1) switch ($.typeSwitchCase(__goscriptTypeSwitchValue, __goscriptStatic5())) { case 0: { diff --git a/tests/tests/generic_numeric_slice_xor/generic_numeric_slice_xor.gs.ts b/tests/tests/generic_numeric_slice_xor/generic_numeric_slice_xor.gs.ts index 1745ed5cf..c3a9fcfec 100644 --- a/tests/tests/generic_numeric_slice_xor/generic_numeric_slice_xor.gs.ts +++ b/tests/tests/generic_numeric_slice_xor/generic_numeric_slice_xor.gs.ts @@ -14,7 +14,7 @@ export function xorLoop(__typeArgs: $.GenericTypeArgs | undefined, dst: $.Sli export async function main(): globalThis.Promise { let dst = new Uint8Array([0, 0]) as $.Slice xorLoop(__goscriptStatic0(), dst, new Uint8Array([1, 3]) as $.Slice, new Uint8Array([2, 1]) as $.Slice) - await $.println($.arrayIndex(dst!, 0), $.arrayIndex(dst!, 1)) + await $.println($.typedSliceIndex(dst!, 0), $.typedSliceIndex(dst!, 1)) } var __goscriptStatic0$value: any diff --git a/tests/tests/generic_pointer_equal/generic_pointer_equal.gs.ts b/tests/tests/generic_pointer_equal/generic_pointer_equal.gs.ts index 529174ddf..2e011dac4 100644 --- a/tests/tests/generic_pointer_equal/generic_pointer_equal.gs.ts +++ b/tests/tests/generic_pointer_equal/generic_pointer_equal.gs.ts @@ -129,8 +129,8 @@ export async function main(): globalThis.Promise { let arr = $.arrayValue([new point(true, 1, 2), new point(true, 3, 4)], __goscriptStatic1()) let m = $.makeMap([["k", new point(true, 1, 2)]]) let p = new pair(true, new point(true, 1, 2)) - await $.println("zero:", eq(__goscriptStatic2(), (zero).clone(), new point(true)), eq(__goscriptStatic2(), (zero).clone(), ($.arrayIndex(made!, 0)).clone())) - await $.println("deref:", eq(__goscriptStatic2(), (lit).clone(), ($.pointerValue(ptr)).clone()), "slice:", eq(__goscriptStatic2(), (lit).clone(), ($.arrayIndex(made!, 1)).clone()), "array:", eq(__goscriptStatic2(), (lit).clone(), (arr[0]).clone())) + await $.println("zero:", eq(__goscriptStatic2(), (zero).clone(), new point(true)), eq(__goscriptStatic2(), (zero).clone(), ($.plainSliceIndex(made!, 0)).clone())) + await $.println("deref:", eq(__goscriptStatic2(), (lit).clone(), ($.pointerValue(ptr)).clone()), "slice:", eq(__goscriptStatic2(), (lit).clone(), ($.plainSliceIndex(made!, 1)).clone()), "array:", eq(__goscriptStatic2(), (lit).clone(), (arr[0]).clone())) await $.println("map:", eq(__goscriptStatic2(), (lit).clone(), ($.mapGet(m, "k", new point(true))[0]).clone()), "field:", eq(__goscriptStatic2(), (lit).clone(), (p.a).clone()), "return:", eq(__goscriptStatic2(), (lit).clone(), newPoint(1, 2))) await $.println("differ:", eq(__goscriptStatic2(), (lit).clone(), (arr[1]).clone()), "pair:", eq(__goscriptStatic3(), p, new pair(true, (lit).clone()))) await $.println("index values:", slices.Index($.arrayToSlice([new point(true, 3, 4), new point(true, 1, 2)]), ($.pointerValue(ptr)).clone())) diff --git a/tests/tests/generic_range_map_type_param/generic_range_map_type_param.gs.ts b/tests/tests/generic_range_map_type_param/generic_range_map_type_param.gs.ts index 8e4bd1f22..0e29bdea4 100644 --- a/tests/tests/generic_range_map_type_param/generic_range_map_type_param.gs.ts +++ b/tests/tests/generic_range_map_type_param/generic_range_map_type_param.gs.ts @@ -37,14 +37,14 @@ export async function main(): globalThis.Promise { let m = $.makeMap>([["a", $.arrayToSlice([1])], ["b", $.arrayToSlice([2, 3])], ["c", null]]) let ks = (Keys(__goscriptStatic0(), m) as $.Slice) slices.Sort(ks) - await $.println($.sliceLen(ks), $.arrayIndex(ks!, 0), $.arrayIndex(ks!, 1), $.arrayIndex(ks!, 2)) + await $.println($.sliceLen(ks), $.plainSliceIndex(ks!, 0), $.plainSliceIndex(ks!, 1), $.plainSliceIndex(ks!, 2)) let n = $.makeMap([["x", 1], ["y", 2]]) let vs = (Values(__goscriptStatic1(), n) as $.Slice) slices.Sort(vs) - await $.println($.sliceLen(vs), $.arrayIndex(vs!, 0), $.arrayIndex(vs!, 1)) + await $.println($.sliceLen(vs), $.plainSliceIndex(vs!, 0), $.plainSliceIndex(vs!, 1)) let nk = (Keys(__goscriptStatic1(), n) as $.Slice) slices.Sort(nk) - await $.println($.arrayIndex(nk!, 0), $.arrayIndex(nk!, 1)) + await $.println($.plainSliceIndex(nk!, 0), $.plainSliceIndex(nk!, 1)) await $.println(Sum(__goscriptStatic2(), $.arrayToSlice([1, 2, 3]))) } diff --git a/tests/tests/generic_struct_clone/generic_struct_clone.gs.ts b/tests/tests/generic_struct_clone/generic_struct_clone.gs.ts index 175401857..0c5bff3d4 100644 --- a/tests/tests/generic_struct_clone/generic_struct_clone.gs.ts +++ b/tests/tests/generic_struct_clone/generic_struct_clone.gs.ts @@ -175,8 +175,8 @@ export async function main(): globalThis.Promise { let q = (p).clone() q.Val.Left = 40 let ps = $.arrayToSlice([(p).clone(), (q).clone()]) - $.arrayIndex(ps!, 0).Val.Top = 10 - await $.println("pair:", p.Val.Left, q.Val.Left, $.arrayIndex(ps!, 0).Val.Top, p.Val.Top, $.arrayIndex(ps!, 1).Val.Left) + $.plainSliceIndex(ps!, 0).Val.Top = 10 + await $.println("pair:", p.Val.Left, q.Val.Left, $.plainSliceIndex(ps!, 0).Val.Top, p.Val.Top, $.plainSliceIndex(ps!, 1).Val.Left) } var __goscriptStatic0$value: any diff --git a/tests/tests/generic_struct_field_copy/generic_struct_field_copy.gs.ts b/tests/tests/generic_struct_field_copy/generic_struct_field_copy.gs.ts index 583332bd9..1367bf7e0 100644 --- a/tests/tests/generic_struct_field_copy/generic_struct_field_copy.gs.ts +++ b/tests/tests/generic_struct_field_copy/generic_struct_field_copy.gs.ts @@ -205,8 +205,8 @@ export async function main(): globalThis.Promise { // slices of instances grow with zero values of their own let vals: $.Slice = $.makeSlice(2, undefined, undefined, () => new Values(true)) vals = $.appendOne(vals, new Values(true)) - $.arrayIndex(vals!, 0).Sides.Top.V = 12 - await $.println("slice:", $.arrayIndex(vals!, 0).Sides.Top.V, $.arrayIndex(vals!, 1).Sides.Top.V, $.arrayIndex(vals!, 2).Sides.Top.V) + $.plainSliceIndex(vals!, 0).Sides.Top.V = 12 + await $.println("slice:", $.plainSliceIndex(vals!, 0).Sides.Top.V, $.plainSliceIndex(vals!, 1).Sides.Top.V, $.plainSliceIndex(vals!, 2).Sides.Top.V) } if ($.isMainScript(import.meta)) { diff --git a/tests/tests/generic_struct_value_copy/generic_struct_value_copy.gs.ts b/tests/tests/generic_struct_value_copy/generic_struct_value_copy.gs.ts index d9e373102..2d4f668db 100644 --- a/tests/tests/generic_struct_value_copy/generic_struct_value_copy.gs.ts +++ b/tests/tests/generic_struct_value_copy/generic_struct_value_copy.gs.ts @@ -190,12 +190,12 @@ export async function main(): globalThis.Promise { await $.println("store:", v.V, d.value.V) let xs = (fill(__goscriptStatic0(), 2, new Value(true, 5)) as $.Slice) - $.arrayIndex(xs!, 0).Set(6) - await $.println("fill:", $.arrayIndex(xs!, 0).V, $.arrayIndex(xs!, 1).V) + $.plainSliceIndex(xs!, 0).Set(6) + await $.println("fill:", $.plainSliceIndex(xs!, 0).V, $.plainSliceIndex(xs!, 1).V) let ys = (appendTwice(__goscriptStatic0(), null, new Value(true, 7)) as $.Slice) - $.arrayIndex(ys!, 0).Set(8) - await $.println("append:", $.arrayIndex(ys!, 0).V, $.arrayIndex(ys!, 1).V) + $.plainSliceIndex(ys!, 0).Set(8) + await $.println("append:", $.plainSliceIndex(ys!, 0).V, $.plainSliceIndex(ys!, 1).V) let m = $.makeMap([]) setTwo(__goscriptStatic0(), m, new Value(true, 9)) diff --git a/tests/tests/generics_basic/generics_basic.gs.ts b/tests/tests/generics_basic/generics_basic.gs.ts index 23a551e70..d3a16eeb7 100644 --- a/tests/tests/generics_basic/generics_basic.gs.ts +++ b/tests/tests/generics_basic/generics_basic.gs.ts @@ -247,7 +247,7 @@ export async function main(): globalThis.Promise { await $.println("=== Interface constraint ===") let items = $.arrayToSlice | null>([new Item(false, "alpha"), new Item(false, "beta")]) let clones = (await CloneAll(__goscriptStatic4(), items) as $.Slice | null>) - await $.println("clone:", $.pointerValue($.arrayIndex(clones!, 0)).Name, $.pointerValue($.arrayIndex(clones!, 1)).Name, ($.arrayIndex(clones!, 0) === $.arrayIndex(items!, 0) || ($.pointerAliasesMade || ($.arrayIndex(clones!, 0) as any)?.__goElementBacking !== undefined) && $.pointerEqual($.arrayIndex(clones!, 0), $.arrayIndex(items!, 0)))) + await $.println("clone:", $.pointerValue($.plainSliceIndex(clones!, 0)).Name, $.pointerValue($.plainSliceIndex(clones!, 1)).Name, ($.plainSliceIndex(clones!, 0) === $.plainSliceIndex(items!, 0) || ($.pointerAliasesMade || ($.plainSliceIndex(clones!, 0) as any)?.__goElementBacking !== undefined) && $.pointerEqual($.plainSliceIndex(clones!, 0), $.plainSliceIndex(items!, 0)))) await $.println("=== Generic struct with map field ===") let mapper = (NewMapper(__goscriptStatic5()) as Mapper | $.VarRef | null) diff --git a/tests/tests/goto_general/goto_general.gs.ts b/tests/tests/goto_general/goto_general.gs.ts index 3e6ab9249..80563a65f 100644 --- a/tests/tests/goto_general/goto_general.gs.ts +++ b/tests/tests/goto_general/goto_general.gs.ts @@ -353,7 +353,7 @@ export function webStyle(input: $.Slice): [number, number] { __goscriptGotoState5 = 3 continue __goscriptGotoLoop5 } - q = $.arrayIndex(input!, p) + q = $.plainSliceIndex(input!, p) switch ((true as boolean)) { case q < 0: { diff --git a/tests/tests/hash_crc32/main.gs.ts b/tests/tests/hash_crc32/main.gs.ts index c24486bd7..73a709efe 100644 --- a/tests/tests/hash_crc32/main.gs.ts +++ b/tests/tests/hash_crc32/main.gs.ts @@ -81,10 +81,10 @@ export async function main(): globalThis.Promise { let prefix = new Uint8Array([9, 8, 7]) as $.Slice let summed = ((__goscriptAwait = (ieee !== null && (ieee as any).__isVarRef !== true && ((ieee as any).__goValue === undefined || (ieee as any).__goType?.charCodeAt(0) !== 42) ? (ieee as Exclude) : $.pointerValue>(ieee)).Sum($.goSlice(prefix, undefined, $.sliceLen(prefix), $.sliceLen(prefix))), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait) as $.Slice) - if (((($.sliceLen(summed) != ($.sliceLen(prefix) + crc32.Size)) || ($.arrayIndex(summed!, 0) != 9)) || ($.arrayIndex(summed!, 1) != 8)) || ($.arrayIndex(summed!, 2) != 7)) { + if (((($.sliceLen(summed) != ($.sliceLen(prefix) + crc32.Size)) || ($.typedSliceIndex(summed!, 0) != 9)) || ($.typedSliceIndex(summed!, 1) != 8)) || ($.typedSliceIndex(summed!, 2) != 7)) { $.panic("prefix-preserving Sum") } - await $.println("sum", $.sliceLen(summed), $.arrayIndex(summed!, 3), $.arrayIndex(summed!, 4), $.arrayIndex(summed!, 5), $.arrayIndex(summed!, 6)) + await $.println("sum", $.sliceLen(summed), $.typedSliceIndex(summed!, 3), $.typedSliceIndex(summed!, 4), $.typedSliceIndex(summed!, 5), $.typedSliceIndex(summed!, 6)) let [marshaler, ok] = $.typeAssertTuple(ieee, "encoding.BinaryMarshaler") if (!ok) { @@ -105,7 +105,7 @@ export async function main(): globalThis.Promise { let __goscriptTuple2: any = await (appender !== null && (appender as any).__isVarRef !== true && ((appender as any).__goValue === undefined || (appender as any).__goType?.charCodeAt(0) !== 42) ? (appender as Exclude) : $.pointerValue>(appender)).AppendBinary(new Uint8Array([4, 5]) as $.Slice) let appended: $.Slice = __goscriptTuple2[0] err = __goscriptTuple2[1] - if ((((err != null) || ($.sliceLen(appended) != ($.sliceLen(state) + 2))) || ($.arrayIndex(appended!, 0) != 4)) || ($.arrayIndex(appended!, 1) != 5)) { + if ((((err != null) || ($.sliceLen(appended) != ($.sliceLen(state) + 2))) || ($.typedSliceIndex(appended!, 0) != 4)) || ($.typedSliceIndex(appended!, 1) != 5)) { $.panic("AppendBinary") } for (let __goscriptRangeTarget3 = state, __goscriptRangeWindow3 = $.sliceRange(__goscriptRangeTarget3), __goscriptSliceWindow0 = $.sliceRange(appended), i = 0; i < __goscriptRangeWindow3.length; i++) { @@ -113,7 +113,7 @@ export async function main(): globalThis.Promise { $.panic("AppendBinary state") } } - await $.println("state", $.sliceLen(state), $.arrayIndex(state!, 0), $.arrayIndex(state!, 1), $.arrayIndex(state!, 2), $.arrayIndex(state!, 3)) + await $.println("state", $.sliceLen(state), $.typedSliceIndex(state!, 0), $.typedSliceIndex(state!, 1), $.typedSliceIndex(state!, 2), $.typedSliceIndex(state!, 3)) let restored = crc32.NewIEEE() let __goscriptTuple3: any = $.typeAssertTuple(restored, "encoding.BinaryUnmarshaler") diff --git a/tests/tests/import_type_methods/import_type_methods.gs.ts b/tests/tests/import_type_methods/import_type_methods.gs.ts index 02a631343..c63caa226 100644 --- a/tests/tests/import_type_methods/import_type_methods.gs.ts +++ b/tests/tests/import_type_methods/import_type_methods.gs.ts @@ -33,7 +33,7 @@ export class parser { export async function main(): globalThis.Promise { let p: parser = new parser(true) p.errors = (errlist.ErrorList_Add(p.errors, "error") as errlist.ErrorList) - await $.println($.arrayIndex(p.errors!, 0)) + await $.println($.plainSliceIndex(p.errors!, 0)) } if ($.isMainScript(import.meta)) { diff --git a/tests/tests/imported_generic_function/imported_generic_function.gs.ts b/tests/tests/imported_generic_function/imported_generic_function.gs.ts index a1269a7d6..fa0cadbae 100644 --- a/tests/tests/imported_generic_function/imported_generic_function.gs.ts +++ b/tests/tests/imported_generic_function/imported_generic_function.gs.ts @@ -30,7 +30,7 @@ export async function main(): globalThis.Promise { await $.println((__goscriptAwait = (err !== null && (err as any).__isVarRef !== true && ((err as any).__goValue === undefined || (err as any).__goType?.charCodeAt(0) !== 42) ? (err as Exclude<$.GoError, null>) : $.pointerValue>(err)).Error(), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait)) return } - await $.println("collected:", (__goscriptAwait = $.pointerValue>($.arrayIndex(values!, 0)).GetValue(), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait)) + await $.println("collected:", (__goscriptAwait = $.pointerValue>($.plainSliceIndex(values!, 0)).GetValue(), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait)) let __goscriptTuple2: any = collectAssigned($.structInterfaceValue(new helper.IntValue(true, 35), "helper.IntValue", "helper.IntValue")) let assigned: $.Slice = __goscriptTuple2[0] err = __goscriptTuple2[1] @@ -38,7 +38,7 @@ export async function main(): globalThis.Promise { await $.println((__goscriptAwait = (err !== null && (err as any).__isVarRef !== true && ((err as any).__goValue === undefined || (err as any).__goType?.charCodeAt(0) !== 42) ? (err as Exclude<$.GoError, null>) : $.pointerValue>(err)).Error(), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait)) return } - await $.println("assigned:", (__goscriptAwait = $.pointerValue>($.arrayIndex(assigned!, 0)).GetValue(), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait)) + await $.println("assigned:", (__goscriptAwait = $.pointerValue>($.plainSliceIndex(assigned!, 0)).GetValue(), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait)) } var __goscriptStatic0$value: any diff --git a/tests/tests/incdec_wrap_round/incdec_wrap_round.gs.ts b/tests/tests/incdec_wrap_round/incdec_wrap_round.gs.ts index fd3018bcb..84065ff8b 100644 --- a/tests/tests/incdec_wrap_round/incdec_wrap_round.gs.ts +++ b/tests/tests/incdec_wrap_round/incdec_wrap_round.gs.ts @@ -73,7 +73,7 @@ export async function main(): globalThis.Promise { let arr = $.arrayValue(new Uint8Array([255, 0])) arr[0] = ((arr[0] + 1) & 0xff) arr[1] = ((arr[1] - 1) & 0xff) - await $.println("elements:", $.arrayIndex(gi!, 0), $.arrayIndex(gb!, 0), $.arrayIndex(gb!, 1), $.arrayIndex(gf!, 0) == 1.6777216e+07, $.arrayIndex(ti!, 0), arr[0], arr[1]) + await $.println("elements:", $.typedSliceIndex(gi!, 0), $.typedSliceIndex(gb!, 0), $.typedSliceIndex(gb!, 1), $.typedSliceIndex(gf!, 0) == 1.6777216e+07, $.typedSliceIndex(ti!, 0), arr[0], arr[1]) // Through pointers, with the target evaluated once. let pi = $.indexRef(gi!, 0) @@ -85,7 +85,7 @@ export async function main(): globalThis.Promise { let gu = (appendOf(__goscriptStatic3(), null, $.typedSliceOf(Uint32Array, [0]) as $.Slice) as $.Slice) const __goscriptOperand0 = await index() $.sliceElems(gu!)[$.sliceSlot(gu!, __goscriptOperand0)] = (($.sliceElems(gu!)[$.sliceSlot(gu!, __goscriptOperand0)] - 1) >>> 0) - await $.println("pointers:", $.arrayIndex(gi!, 0), vf.value == 1.6777216e+07, c.U16, $.arrayIndex(gu!, 0)) + await $.println("pointers:", $.typedSliceIndex(gi!, 0), vf.value == 1.6777216e+07, c.U16, $.typedSliceIndex(gu!, 0)) } var __goscriptStatic0$value: any diff --git a/tests/tests/index_expr_destructuring/index_expr_destructuring.gs.ts b/tests/tests/index_expr_destructuring/index_expr_destructuring.gs.ts index d03c70b34..60979f22b 100644 --- a/tests/tests/index_expr_destructuring/index_expr_destructuring.gs.ts +++ b/tests/tests/index_expr_destructuring/index_expr_destructuring.gs.ts @@ -22,7 +22,7 @@ export async function main(): globalThis.Promise { $.sliceElems(stringSlice!)[$.sliceSlot(stringSlice!, 1)] = __goscriptTuple0[1] await $.println("intArray[0]:", intArray[0]) - await $.println("stringSlice[1]:", $.arrayIndex(stringSlice!, 1)) + await $.println("stringSlice[1]:", $.plainSliceIndex(stringSlice!, 1)) // Test with more complex index expressions let matrix: number[][] = $.arrayValue(globalThis.Array.from({ length: 2 }, () => $.arrayValue(globalThis.Array.from({ length: 2 }, () => 0))), /* @__PURE__ */ $.arrayType(/* @__PURE__ */ $.arrayType(/* @__PURE__ */ $.basicType("int"), 2), 2)) diff --git a/tests/tests/index_out_of_range/index_out_of_range.gs.ts b/tests/tests/index_out_of_range/index_out_of_range.gs.ts index ddc0b634d..e02534ef0 100644 --- a/tests/tests/index_out_of_range/index_out_of_range.gs.ts +++ b/tests/tests/index_out_of_range/index_out_of_range.gs.ts @@ -35,7 +35,7 @@ export async function main(): globalThis.Promise { await recoverMsg("slice:", $.functionValue(async () => { let s = $.arrayToSlice([1, 2, 3]) let i = 5 - await $.println($.arrayIndex(s!, i)) + await $.println($.plainSliceIndex(s!, i)) }, ({ kind: $.TypeKind.Function, params: [], results: [] } as $.FunctionTypeInfo))) await recoverMsg("array:", $.functionValue(async () => { let a: number[] = $.arrayValue(globalThis.Array.from({ length: 3 }, () => 0)) @@ -45,7 +45,7 @@ export async function main(): globalThis.Promise { await recoverMsg("negative:", $.functionValue(async () => { let s = $.arrayToSlice([1, 2, 3]) let i = -1 - await $.println($.arrayIndex(s!, i)) + await $.println($.plainSliceIndex(s!, i)) }, ({ kind: $.TypeKind.Function, params: [], results: [] } as $.FunctionTypeInfo))) await recoverMsg("string:", $.functionValue(async () => { let s = "abc" @@ -60,7 +60,7 @@ export async function main(): globalThis.Promise { await recoverMsg("bytes-negative:", $.functionValue(async () => { let b = new Uint8Array([97, 98, 99]) let i = -1 - await $.println($.arrayIndex(b!, i)) + await $.println($.typedSliceIndex(b!, i)) }, ({ kind: $.TypeKind.Function, params: [], results: [] } as $.FunctionTypeInfo))) await $.println("done") } diff --git a/tests/tests/interface_override_sync/interface_override_sync.gs.ts b/tests/tests/interface_override_sync/interface_override_sync.gs.ts index a6ded4bb4..116a1e1f1 100644 --- a/tests/tests/interface_override_sync/interface_override_sync.gs.ts +++ b/tests/tests/interface_override_sync/interface_override_sync.gs.ts @@ -72,12 +72,12 @@ export function byLen_Len(s: byLen): number { } export function byLen_Less(s: byLen, i: number, j: number): boolean { - return $.stringLen($.arrayIndex(s!, i)) < $.stringLen($.arrayIndex(s!, j)) + return $.stringLen($.plainSliceIndex(s!, i)) < $.stringLen($.plainSliceIndex(s!, j)) } export function byLen_Swap(s: byLen, i: number, j: number): void { - let __goscriptAssign0_0: string = $.arrayIndex(s!, j) - let __goscriptAssign0_1: string = $.arrayIndex(s!, i) + let __goscriptAssign0_0: string = $.plainSliceIndex(s!, j) + let __goscriptAssign0_1: string = $.plainSliceIndex(s!, i) $.sliceElems(s!)[$.sliceSlot(s!, i)] = __goscriptAssign0_0 $.sliceElems(s!)[$.sliceSlot(s!, j)] = __goscriptAssign0_1 } diff --git a/tests/tests/interface_slice_index_short_decl/interface_slice_index_short_decl.gs.ts b/tests/tests/interface_slice_index_short_decl/interface_slice_index_short_decl.gs.ts index 232703049..87478c91a 100644 --- a/tests/tests/interface_slice_index_short_decl/interface_slice_index_short_decl.gs.ts +++ b/tests/tests/interface_slice_index_short_decl/interface_slice_index_short_decl.gs.ts @@ -116,8 +116,8 @@ export async function main(): globalThis.Promise { case 1: { let shape: $.VarRef = $.varRef($.markAsStructValue($.cloneStructValue($.typeAssert(__goscriptTypeSwitchValue, "main.Action").value))) - let fix = ($.arrayIndex(fixed!, 0) as Fixed) - let fv = $.arrayIndex(fix!, 0) + let fix = ($.plainSliceIndex(fixed!, 0) as Fixed) + let fv = $.plainSliceIndex(fix!, 0) { let v = $.mapGet(shape.value.Filter, shape.value.Result, null)[0] if (v != null) { @@ -131,8 +131,8 @@ export async function main(): globalThis.Promise { } } } - let fix = ($.arrayIndex(fixed!, 0) as Fixed) - let fv = $.arrayIndex(fix!, 0) + let fix = ($.plainSliceIndex(fixed!, 0) as Fixed) + let fv = $.plainSliceIndex(fix!, 0) if (dep.ToKey(fv) != null) { await $.println("ok") } diff --git a/tests/tests/interface_struct_value_box/interface_struct_value_box.gs.ts b/tests/tests/interface_struct_value_box/interface_struct_value_box.gs.ts index 60b50bccc..83121dabd 100644 --- a/tests/tests/interface_struct_value_box/interface_struct_value_box.gs.ts +++ b/tests/tests/interface_struct_value_box/interface_struct_value_box.gs.ts @@ -173,7 +173,7 @@ export async function main(): globalThis.Promise { n.Name = "changed" $.sliceElems(n.Tags!)[$.sliceSlot(n.Tags!, 0)] = "y" let got = ($.mustTypeAssert(na, "main.Named")).clone() - await $.println(got.Name, $.arrayIndex(got.Tags!, 0), $.pointerValue(got.Next).Name) + await $.println(got.Name, $.plainSliceIndex(got.Tags!, 0), $.pointerValue(got.Next).Name) let o = new Outer(true, new Vec(true, 5, 6), 7) let oa: any = $.structInterfaceValue((o).clone(), "main.Outer", "main.Outer") o.In.X = 50 diff --git a/tests/tests/js_global_name_shadow/js_global_name_shadow.gs.ts b/tests/tests/js_global_name_shadow/js_global_name_shadow.gs.ts index 40c7375bb..ae3798972 100644 --- a/tests/tests/js_global_name_shadow/js_global_name_shadow.gs.ts +++ b/tests/tests/js_global_name_shadow/js_global_name_shadow.gs.ts @@ -79,7 +79,7 @@ export function __goscript_set_Array(__goscriptValue: $.Slice): void { export async function main(): globalThis.Promise { let p = new Promise(true, "Promise") - await $.println("names:", 1, 1.5, String(1), $.arrayIndex(Array!, 0), p.value) + await $.println("names:", 1, 1.5, String(1), $.plainSliceIndex(Array!, 0), p.value) let a = 7 let b = 2 diff --git a/tests/tests/json_rawmessage_elements/json_rawmessage_elements.gs.ts b/tests/tests/json_rawmessage_elements/json_rawmessage_elements.gs.ts index 189228c24..421a58556 100644 --- a/tests/tests/json_rawmessage_elements/json_rawmessage_elements.gs.ts +++ b/tests/tests/json_rawmessage_elements/json_rawmessage_elements.gs.ts @@ -13,7 +13,7 @@ export async function main(): globalThis.Promise { let kids: $.VarRef<$.Slice> = $.varRef(null! as $.Slice) err = (json.Unmarshal($.mapGet(fields.value, "kids", null)[0], $.interfaceValue(kids, "*[]jsontext.Value", /* @__PURE__ */ $.pointerType(/* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("uint8"), "jsontext.Value"))))) as $.GoError) - await $.println("slice:", err == null, $.sliceLen(kids.value), $.bytesToString($.arrayIndex(kids.value!, 0)), $.bytesToString($.arrayIndex(kids.value!, 1))) + await $.println("slice:", err == null, $.sliceLen(kids.value), $.bytesToString($.plainSliceIndex(kids.value!, 0)), $.bytesToString($.plainSliceIndex(kids.value!, 1))) let name = $.varRef("") err = (json.Unmarshal($.mapGet(fields.value, "name", null)[0], $.interfaceValue(name, "*string", /* @__PURE__ */ $.pointerType(/* @__PURE__ */ $.basicType("string")))) as $.GoError) diff --git a/tests/tests/keyed_array_literal/keyed_array_literal.gs.ts b/tests/tests/keyed_array_literal/keyed_array_literal.gs.ts index 86e8c3749..5fc4ec2a3 100644 --- a/tests/tests/keyed_array_literal/keyed_array_literal.gs.ts +++ b/tests/tests/keyed_array_literal/keyed_array_literal.gs.ts @@ -32,11 +32,11 @@ export async function main(): globalThis.Promise { // Test slice with keyed elements let slice1 = $.arrayToSlice(["", "", "second", "", "fourth"]) - await $.println("slice1[0]:", $.arrayIndex(slice1!, 0)) - await $.println("slice1[1]:", $.arrayIndex(slice1!, 1)) - await $.println("slice1[2]:", $.arrayIndex(slice1!, 2)) - await $.println("slice1[3]:", $.arrayIndex(slice1!, 3)) - await $.println("slice1[4]:", $.arrayIndex(slice1!, 4)) + await $.println("slice1[0]:", $.plainSliceIndex(slice1!, 0)) + await $.println("slice1[1]:", $.plainSliceIndex(slice1!, 1)) + await $.println("slice1[2]:", $.plainSliceIndex(slice1!, 2)) + await $.println("slice1[3]:", $.plainSliceIndex(slice1!, 3)) + await $.println("slice1[4]:", $.plainSliceIndex(slice1!, 4)) await $.println("keyed array literal test completed") } diff --git a/tests/tests/loop_slice_window/loop_slice_window.gs.ts b/tests/tests/loop_slice_window/loop_slice_window.gs.ts index 40b22693c..630d155c9 100644 --- a/tests/tests/loop_slice_window/loop_slice_window.gs.ts +++ b/tests/tests/loop_slice_window/loop_slice_window.gs.ts @@ -62,7 +62,7 @@ export async function main(): globalThis.Promise { ;((__goscriptSliceWindow1.backing as any[])[$.windowSlot(__goscriptSliceWindow1, j)] as pos).Line += i; ;((__goscriptSliceWindow1.backing as any[])[$.windowSlot(__goscriptSliceWindow1, j)] as pos).Char = ((__goscriptSliceWindow1.backing as any[])[$.windowSlot(__goscriptSliceWindow1, j)] as pos).Line * 2 } - await $.println($.arrayIndex(ps!, 0).Line, $.arrayIndex(ps!, 1).Char, $.arrayIndex(ps!, 3).Line) + await $.println($.plainSliceIndex(ps!, 0).Line, $.plainSliceIndex(ps!, 1).Char, $.plainSliceIndex(ps!, 3).Line) // A compound assignment reads and writes the same element. let counts = $.arrayToSlice([0, 0, 0]) @@ -70,7 +70,7 @@ export async function main(): globalThis.Promise { let k = next(); ;(__goscriptSliceWindow2.backing as any[])[$.windowSlot(__goscriptSliceWindow2, k)] += 10 } - await $.println($.arrayIndex(counts!, 0), $.arrayIndex(counts!, 1), $.arrayIndex(counts!, 2), calls) + await $.println($.plainSliceIndex(counts!, 0), $.plainSliceIndex(counts!, 1), $.plainSliceIndex(counts!, 2), calls) // A slice window offsets into its backing array, and a nil slice has none. let base = $.arrayToSlice([1, 2, 3, 4, 5, 6]) @@ -81,14 +81,14 @@ export async function main(): globalThis.Promise { for (let __goscriptSliceWindow3 = $.sliceRange(sub), i = 0; i < __goscriptSliceWindow3.length; i++) { ;(__goscriptSliceWindow3.backing as any[])[$.windowSlot(__goscriptSliceWindow3, i)] *= 10 } - await $.println($.arrayIndex(base!, 1), $.arrayIndex(base!, 2), $.arrayIndex(base!, 4), $.arrayIndex(base!, 5)) + await $.println($.plainSliceIndex(base!, 1), $.plainSliceIndex(base!, 2), $.plainSliceIndex(base!, 4), $.plainSliceIndex(base!, 5)) // A slice assigned in the loop is read through the slice each time. let grow: $.Slice = $.arrayToSlice([1]) for (let i = 0; i < 4; i++) { - grow = $.appendOne(grow, $.arrayIndex(grow!, i) * 2) + grow = $.appendOne(grow, $.plainSliceIndex(grow!, i) * 2) } - await $.println($.sliceLen(grow), $.arrayIndex(grow!, 4)) + await $.println($.sliceLen(grow), $.plainSliceIndex(grow!, 4)) // A slice that a closure assigns is not windowed. let shrink: $.Slice = $.arrayToSlice([5, 6, 7]) @@ -97,7 +97,7 @@ export async function main(): globalThis.Promise { }, ({ kind: $.TypeKind.Function, params: [], results: [] } as $.FunctionTypeInfo)) let n = 0 while ($.sliceLen(shrink) > 0) { - n += $.arrayIndex(shrink!, 0) + n += $.plainSliceIndex(shrink!, 0) cut() } await $.println(n) @@ -137,7 +137,7 @@ export async function main(): globalThis.Promise { let acc = 0 for (let __goscriptSliceWindow8 = $.sliceRange(grid), i = 0; i < __goscriptSliceWindow8.length; i++) { let r: $.Slice = ((__goscriptSliceWindow8.backing as any[])[$.windowSlot(__goscriptSliceWindow8, i)] as $.Slice) - acc += $.arrayIndex(r!, 1) + acc += $.plainSliceIndex(r!, 1) } await $.println(acc) @@ -147,7 +147,7 @@ export async function main(): globalThis.Promise { let read = $.functionValue((): number => { let t = 0 for (let i = 0; i < 3; i++) { - t += $.arrayIndex(shared!, i) + t += $.plainSliceIndex(shared!, i) } return t }, ({ kind: $.TypeKind.Function, params: [], results: [/* @__PURE__ */ $.basicType("int")] } as $.FunctionTypeInfo)) diff --git a/tests/tests/make_slice/make_slice.gs.ts b/tests/tests/make_slice/make_slice.gs.ts index b35d7fbeb..10f0e8917 100644 --- a/tests/tests/make_slice/make_slice.gs.ts +++ b/tests/tests/make_slice/make_slice.gs.ts @@ -50,7 +50,7 @@ export async function main(): globalThis.Promise { await $.println("Before append - len:", $.sliceLen(s5), "cap:", $.cap(s5)) s5 = $.appendOne(s5, 30) await $.println("After append - len:", $.sliceLen(s5), "cap:", $.cap(s5)) - await $.println("s5[2]:", $.arrayIndex(s5!, 2)) + await $.println("s5[2]:", $.plainSliceIndex(s5!, 2)) // Test 8: Append to bytes with extra capacity await $.println("--- Append to bytes with extra capacity ---") @@ -59,8 +59,8 @@ export async function main(): globalThis.Promise { await $.println("Before append - len:", $.sliceLen(b3), "cap:", $.cap(b3)) b3 = $.append(b3, $.uint(66, 8), $.byteSliceHint) await $.println("After append - len:", $.sliceLen(b3), "cap:", $.cap(b3)) - await $.println("b3[0]:", $.arrayIndex(b3!, 0)) - await $.println("b3[1]:", $.arrayIndex(b3!, 1)) + await $.println("b3[0]:", $.typedSliceIndex(b3!, 0)) + await $.println("b3[1]:", $.typedSliceIndex(b3!, 1)) // Test 9: Large capacity slice await $.println("--- Large capacity slice ---") @@ -85,8 +85,8 @@ export async function main(): globalThis.Promise { } let sub = $.goSlice(s6, 2, 5) await $.println("sub - len:", $.sliceLen(sub), "cap:", $.cap(sub)) - await $.println("sub[0]:", $.arrayIndex(sub!, 0)) - await $.println("sub[2]:", $.arrayIndex(sub!, 2)) + await $.println("sub[0]:", $.plainSliceIndex(sub!, 0)) + await $.println("sub[2]:", $.plainSliceIndex(sub!, 2)) // Test 12: String slices with capacity await $.println("--- String slices with capacity ---") @@ -95,7 +95,7 @@ export async function main(): globalThis.Promise { $.sliceElems(str!)[$.sliceSlot(str!, 1)] = "world" $.sliceElems(str!)[$.sliceSlot(str!, 2)] = "test" await $.println("str - len:", $.sliceLen(str), "cap:", $.cap(str)) - await $.println("str[1]:", $.arrayIndex(str!, 1)) + await $.println("str[1]:", $.plainSliceIndex(str!, 1)) await $.println("--- All tests completed ---") } diff --git a/tests/tests/make_slice_array_elems/make_slice_array_elems.gs.ts b/tests/tests/make_slice_array_elems/make_slice_array_elems.gs.ts index 0e460fae2..bd3e43459 100644 --- a/tests/tests/make_slice_array_elems/make_slice_array_elems.gs.ts +++ b/tests/tests/make_slice_array_elems/make_slice_array_elems.gs.ts @@ -40,37 +40,37 @@ export class point { export async function main(): globalThis.Promise { // Elements of a made slice of arrays are zero arrays that can be written. let a = $.makeSlice(3, undefined, undefined, () => $.arrayValue(globalThis.Array.from({ length: 4 }, () => 0))) - $.arrayIndex(a!, 1)[2] = 5 - await $.println("arrays:", ($.arrayIndex(a!, 0))[0], ($.arrayIndex(a!, 1))[2], 4) + $.plainSliceIndex(a!, 1)[2] = 5 + await $.println("arrays:", ($.plainSliceIndex(a!, 0))[0], ($.plainSliceIndex(a!, 1))[2], 4) // Arrays of structs and named array types too. let b = $.makeSlice(2, undefined, undefined, () => $.arrayValue(globalThis.Array.from({ length: 2 }, () => new point(true)), /* @__PURE__ */ $.arrayType("main.point", 2))); - ;($.arrayIndex(b!, 1))[1].X = 3 + ;($.plainSliceIndex(b!, 1))[1].X = 3 let q = $.makeSlice(1, undefined, undefined, () => $.arrayValue(globalThis.Array.from({ length: 4 }, () => 0))) - $.arrayIndex(q!, 0)[3] = 9 - await $.println("struct arrays:", ($.arrayIndex(b!, 0))[0].X, ($.arrayIndex(b!, 1))[1].X, ($.arrayIndex(q!, 0))[3]) + $.plainSliceIndex(q!, 0)[3] = 9 + await $.println("struct arrays:", ($.plainSliceIndex(b!, 0))[0].X, ($.plainSliceIndex(b!, 1))[1].X, ($.plainSliceIndex(q!, 0))[3]) // Unnamed struct elements are zero structs. let u = $.makeSlice<{"A": number, "B": number}>(2, undefined, undefined, () => $.anonymousStructValue({"A": 0, "B": 0}, { kind: $.TypeKind.Struct, methods: [], fields: [/* @__PURE__ */ $.structField("A", /* @__PURE__ */ $.basicType("int"), [0], 0, true), /* @__PURE__ */ $.structField("B", /* @__PURE__ */ $.basicType("int"), [1], 8, true)] })) - $.arrayIndex(u!, 1).B = 4 - await $.println("unnamed structs:", $.arrayIndex(u!, 0).A, $.arrayIndex(u!, 1).B) + $.plainSliceIndex(u!, 1).B = 4 + await $.println("unnamed structs:", $.plainSliceIndex(u!, 0).A, $.plainSliceIndex(u!, 1).B) // Spare capacity holds zero arrays as well. let c: $.Slice = $.makeSlice(2, 5, undefined, () => $.arrayValue(globalThis.Array.from({ length: 4 }, () => 0))) c = $.goSlice(c, undefined, 4) - $.arrayIndex(c!, 3)[0] = 7 - await $.println("spare capacity:", ($.arrayIndex(c!, 2))[1], ($.arrayIndex(c!, 3))[0]) + $.plainSliceIndex(c!, 3)[0] = 7 + await $.println("spare capacity:", ($.plainSliceIndex(c!, 2))[1], ($.plainSliceIndex(c!, 3))[0]) // Each element is its own array. - $.arrayIndex(a!, 0)[0] = 1 - await $.println("distinct:", ($.arrayIndex(a!, 0))[0], ($.arrayIndex(a!, 2))[0]) + $.plainSliceIndex(a!, 0)[0] = 1 + await $.println("distinct:", ($.plainSliceIndex(a!, 0))[0], ($.plainSliceIndex(a!, 2))[0]) // Clearing a slice of arrays or structs leaves zero values to write to. $.clear(a, () => $.arrayValue(globalThis.Array.from({ length: 4 }, () => 0))) - $.arrayIndex(a!, 2)[1] = 6 + $.plainSliceIndex(a!, 2)[1] = 6 $.clear($.goSlice(u, 1, undefined), () => $.anonymousStructValue({"A": 0, "B": 0}, { kind: $.TypeKind.Struct, methods: [], fields: [/* @__PURE__ */ $.structField("A", /* @__PURE__ */ $.basicType("int"), [0], 0, true), /* @__PURE__ */ $.structField("B", /* @__PURE__ */ $.basicType("int"), [1], 8, true)] })) - $.arrayIndex(u!, 1).A = 8 - await $.println("cleared:", ($.arrayIndex(a!, 0))[0], ($.arrayIndex(a!, 1))[2], ($.arrayIndex(a!, 2))[1], $.arrayIndex(u!, 1).A, $.arrayIndex(u!, 1).B) + $.plainSliceIndex(u!, 1).A = 8 + await $.println("cleared:", ($.plainSliceIndex(a!, 0))[0], ($.plainSliceIndex(a!, 1))[2], ($.plainSliceIndex(a!, 2))[1], $.plainSliceIndex(u!, 1).A, $.plainSliceIndex(u!, 1).B) } if ($.isMainScript(import.meta)) { diff --git a/tests/tests/make_slice_struct_zero/make_slice_struct_zero.gs.ts b/tests/tests/make_slice_struct_zero/make_slice_struct_zero.gs.ts index 0b5a81339..0c84d57dc 100644 --- a/tests/tests/make_slice_struct_zero/make_slice_struct_zero.gs.ts +++ b/tests/tests/make_slice_struct_zero/make_slice_struct_zero.gs.ts @@ -31,9 +31,9 @@ export class code { export async function main(): globalThis.Promise { let codes = $.makeSlice(2, undefined, undefined, () => new code(true)) - $.arrayIndex(codes!, 0).len = 3 - await $.println("first:", $.arrayIndex(codes!, 0).len) - await $.println("second:", $.arrayIndex(codes!, 1).len) + $.plainSliceIndex(codes!, 0).len = 3 + await $.println("first:", $.plainSliceIndex(codes!, 0).len) + await $.println("second:", $.plainSliceIndex(codes!, 1).len) } if ($.isMainScript(import.meta)) { diff --git a/tests/tests/map_interface_pointer_keys/map_interface_pointer_keys.gs.ts b/tests/tests/map_interface_pointer_keys/map_interface_pointer_keys.gs.ts index 77e0e9862..482399218 100644 --- a/tests/tests/map_interface_pointer_keys/map_interface_pointer_keys.gs.ts +++ b/tests/tests/map_interface_pointer_keys/map_interface_pointer_keys.gs.ts @@ -119,7 +119,7 @@ export async function main(): globalThis.Promise { let kid = (__goscriptRangeWindow0.backing[__goscriptRangeWindow0.offset + __rangeIndex] as tree | $.VarRef | null) sum += $.mapGet(visits, $.interfaceValue(kid, "*main.tree", /* @__PURE__ */ $.pointerType("main.tree")), 0)[0] } - await $.println("tree keys:", $.len(visits), $.mapGet(visits, $.interfaceValue(root, "*main.tree", /* @__PURE__ */ $.pointerType("main.tree")), 0)[0], sum, $.mapGet(visits, $.interfaceValue($.arrayIndex((root$ as tree).Kids!, 7), "*main.tree", /* @__PURE__ */ $.pointerType("main.tree")), 0)[0]) + await $.println("tree keys:", $.len(visits), $.mapGet(visits, $.interfaceValue(root, "*main.tree", /* @__PURE__ */ $.pointerType("main.tree")), 0)[0], sum, $.mapGet(visits, $.interfaceValue($.plainSliceIndex((root$ as tree).Kids!, 7), "*main.tree", /* @__PURE__ */ $.pointerType("main.tree")), 0)[0]) // Typed nil pointers of the same type are equal keys. let n1: node | $.VarRef | null = null! as node | $.VarRef | null diff --git a/tests/tests/map_range_struct_key_copy/map_range_struct_key_copy.gs.ts b/tests/tests/map_range_struct_key_copy/map_range_struct_key_copy.gs.ts index 8249dae21..59e8b4519 100644 --- a/tests/tests/map_range_struct_key_copy/map_range_struct_key_copy.gs.ts +++ b/tests/tests/map_range_struct_key_copy/map_range_struct_key_copy.gs.ts @@ -86,7 +86,7 @@ export async function main(): globalThis.Promise { saved = $.appendOne(saved, (k).clone()) k.P.Line = 9 } - await $.println($.mapGet(n, new Key(true, new Pos(true, 3, 4), "x"), 0)[0], $.arrayIndex(saved!, 0).P.Line) + await $.println($.mapGet(n, new Key(true, new Pos(true, 3, 4), "x"), 0)[0], $.plainSliceIndex(saved!, 0).P.Line) let vals = $.makeMap([["v", new Pos(true, 5, 6)]]) for (const [__rangeKey, __goscriptRangeValue0] of vals?.entries() ?? []) { diff --git a/tests/tests/math_rand_sequences/math_rand_sequences.gs.ts b/tests/tests/math_rand_sequences/math_rand_sequences.gs.ts index 7d19cee43..2a5c1269a 100644 --- a/tests/tests/math_rand_sequences/math_rand_sequences.gs.ts +++ b/tests/tests/math_rand_sequences/math_rand_sequences.gs.ts @@ -96,8 +96,8 @@ export async function show(r: rand.Rand | $.VarRef | null): globalThi let s = $.arrayToSlice([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) rand.Rand.prototype.Shuffle.call($.pointerValue(r), $.sliceLen(s), $.functionValue((i: number, j: number) => { - let __goscriptAssign0_0: number = $.arrayIndex(s!, j) - let __goscriptAssign0_1: number = $.arrayIndex(s!, i) + let __goscriptAssign0_0: number = $.plainSliceIndex(s!, j) + let __goscriptAssign0_1: number = $.plainSliceIndex(s!, i) $.sliceElems(s!)[$.sliceSlot(s!, i)] = __goscriptAssign0_0 $.sliceElems(s!)[$.sliceSlot(s!, j)] = __goscriptAssign0_1 }, ({ kind: $.TypeKind.Function, params: [/* @__PURE__ */ $.basicType("int"), /* @__PURE__ */ $.basicType("int")], results: [] } as $.FunctionTypeInfo))) diff --git a/tests/tests/math_rand_v2_sequences/math_rand_v2_sequences.gs.ts b/tests/tests/math_rand_v2_sequences/math_rand_v2_sequences.gs.ts index 1fe79ff70..cadc43fee 100644 --- a/tests/tests/math_rand_v2_sequences/math_rand_v2_sequences.gs.ts +++ b/tests/tests/math_rand_v2_sequences/math_rand_v2_sequences.gs.ts @@ -89,8 +89,8 @@ export async function show(r: rand.Rand | $.VarRef | null): globalThi await $.println("perm:", ints((r !== null && (r as any).__isVarRef !== true && (r as any).__goValue === undefined ? ((r as any) as rand.Rand).Perm(12) : rand.Rand.prototype.Perm.call($.pointerValue(r), 12)))) let s = $.arrayToSlice([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) rand.Rand.prototype.Shuffle.call($.pointerValue(r), $.sliceLen(s), $.functionValue((i: number, j: number) => { - let __goscriptAssign0_0: number = $.arrayIndex(s!, j) - let __goscriptAssign0_1: number = $.arrayIndex(s!, i) + let __goscriptAssign0_0: number = $.plainSliceIndex(s!, j) + let __goscriptAssign0_1: number = $.plainSliceIndex(s!, i) $.sliceElems(s!)[$.sliceSlot(s!, i)] = __goscriptAssign0_0 $.sliceElems(s!)[$.sliceSlot(s!, j)] = __goscriptAssign0_1 }, ({ kind: $.TypeKind.Function, params: [/* @__PURE__ */ $.basicType("int"), /* @__PURE__ */ $.basicType("int")], results: [] } as $.FunctionTypeInfo))) diff --git a/tests/tests/method_call_slice_type/method_call_slice_type.gs.ts b/tests/tests/method_call_slice_type/method_call_slice_type.gs.ts index a8259b39a..1034000fb 100644 --- a/tests/tests/method_call_slice_type/method_call_slice_type.gs.ts +++ b/tests/tests/method_call_slice_type/method_call_slice_type.gs.ts @@ -38,8 +38,8 @@ export async function main(): globalThis.Promise { MySlice_Add(myList, 20) let ptr = myList await $.println("length:", $.sliceLen((myList.value as MySlice))) - await $.println("first:", $.arrayIndex(myList.value!, 0)) - await $.println("second:", $.arrayIndex(myList.value!, 1)) + await $.println("first:", $.plainSliceIndex(myList.value!, 0)) + await $.println("second:", $.plainSliceIndex(myList.value!, 1)) await $.println("sum:", MySlice_Sum($.pointerValue(ptr))) } diff --git a/tests/tests/named_function_type_call/named_function_type_call.gs.ts b/tests/tests/named_function_type_call/named_function_type_call.gs.ts index d9bde480f..8e0c3a70a 100644 --- a/tests/tests/named_function_type_call/named_function_type_call.gs.ts +++ b/tests/tests/named_function_type_call/named_function_type_call.gs.ts @@ -280,7 +280,7 @@ export async function multiCallback(walkFn: ((path: string, info: FileInfo | nul } export async function indexedCallback(cbs: $.Slice<((_p0: string) => boolean | globalThis.Promise) | null>, value: string): globalThis.Promise { - return $.arrayIndex(cbs!, 0)!(value) + return $.plainSliceIndex(cbs!, 0)!(value) } export async function useMorphism(m: ((_p0: Shape | null) => Shape | null | globalThis.Promise) | null, s: Shape | null): globalThis.Promise { diff --git a/tests/tests/nil_slice_append_spread/nil_slice_append_spread.gs.ts b/tests/tests/nil_slice_append_spread/nil_slice_append_spread.gs.ts index 86663a918..462644582 100644 --- a/tests/tests/nil_slice_append_spread/nil_slice_append_spread.gs.ts +++ b/tests/tests/nil_slice_append_spread/nil_slice_append_spread.gs.ts @@ -38,7 +38,7 @@ export async function main(): globalThis.Promise { let second = new item(false, "second") let items = $.arrayToSlice | null>([first, second]) let cloned = clone(items) - await $.println($.sliceLen(cloned), $.pointerValue($.arrayIndex(cloned!, 0)).value, $.pointerValue($.arrayIndex(cloned!, 1)).value) + await $.println($.sliceLen(cloned), $.pointerValue($.plainSliceIndex(cloned!, 0)).value, $.pointerValue($.plainSliceIndex(cloned!, 1)).value) } if ($.isMainScript(import.meta)) { diff --git a/tests/tests/nil_slice_closure_append/nil_slice_closure_append.gs.ts b/tests/tests/nil_slice_closure_append/nil_slice_closure_append.gs.ts index 751332338..5d0f247c1 100644 --- a/tests/tests/nil_slice_closure_append/nil_slice_closure_append.gs.ts +++ b/tests/tests/nil_slice_closure_append/nil_slice_closure_append.gs.ts @@ -39,7 +39,7 @@ export async function main(): globalThis.Promise { values = $.appendOne(values, new item(true, value)) }, ({ kind: $.TypeKind.Function, params: [/* @__PURE__ */ $.basicType("int")], results: [] } as $.FunctionTypeInfo))) if ($.sliceLen(values) != 0) { - await $.println("first:", $.arrayIndex(values!, 0).Value) + await $.println("first:", $.plainSliceIndex(values!, 0).Value) } } diff --git a/tests/tests/os_args_program_name/os_args_program_name.gs.ts b/tests/tests/os_args_program_name/os_args_program_name.gs.ts index 7e7c015cf..d9b959c5e 100644 --- a/tests/tests/os_args_program_name/os_args_program_name.gs.ts +++ b/tests/tests/os_args_program_name/os_args_program_name.gs.ts @@ -8,7 +8,7 @@ import "@goscript/os/index.js" export async function main(): globalThis.Promise { // The program name comes first on every platform, so programs may index // os.Args[0] and slice the arguments after it. - await $.println("has name:", ($.sliceLen(os.Args) > 0) && (!$.stringEqual($.arrayIndex(os.Args!, 0), ""))) + await $.println("has name:", ($.sliceLen(os.Args) > 0) && (!$.stringEqual($.plainSliceIndex(os.Args!, 0), ""))) await $.println("args:", $.sliceLen($.goSlice(os.Args, 1, undefined))) } diff --git a/tests/tests/override_variadic_func_values/override_variadic_func_values.gs.ts b/tests/tests/override_variadic_func_values/override_variadic_func_values.gs.ts index 6cb44b605..0f63b27ae 100644 --- a/tests/tests/override_variadic_func_values/override_variadic_func_values.gs.ts +++ b/tests/tests/override_variadic_func_values/override_variadic_func_values.gs.ts @@ -55,7 +55,7 @@ export async function main(): globalThis.Promise { // So does reflect, which calls them as Go function values, as // interpreters such as yaegi do. let call = await $.markAsStructValue($.cloneStructValue(reflect.ValueOf($.interfaceValue($.goFunc(((__goscriptFn: typeof fmt.Sprintf) => (__goscriptArg0: string, __goscriptArg1: $.Slice) => __goscriptFn(__goscriptArg0, ...(__goscriptArg1 ?? [])))(fmt.Sprintf), "fmt.Sprintf"), "func(format string, a ...any) string", ({ kind: $.TypeKind.Function, params: [/* @__PURE__ */ $.basicType("string"), /* @__PURE__ */ $.sliceType({ kind: $.TypeKind.Interface, methods: [] })], results: [/* @__PURE__ */ $.basicType("string")], isVariadic: true } as $.FunctionTypeInfo))))).Call($.arrayToSlice([$.markAsStructValue($.cloneStructValue(reflect.ValueOf("%v-%v"))), $.markAsStructValue($.cloneStructValue(reflect.ValueOf($.basicInterfaceValue(8, "int")))), $.markAsStructValue($.cloneStructValue(reflect.ValueOf($.basicInterfaceValue(9, "int"))))])) - await $.println($.markAsStructValue($.cloneStructValue($.arrayIndex(call!, 0))).String()) + await $.println($.markAsStructValue($.cloneStructValue($.plainSliceIndex(call!, 0))).String()) // Direct calls are unchanged. await $.println((fmt.Sprintf("%v-%v", $.basicInterfaceValue(10, "int"), $.basicInterfaceValue(11, "int")) as string), (fmt.Sprint(...(args ?? [])) as string)) diff --git a/tests/tests/package_import_archive_zip_writer/package_import_archive_zip_writer.gs.ts b/tests/tests/package_import_archive_zip_writer/package_import_archive_zip_writer.gs.ts index 564b74320..0dce106a0 100644 --- a/tests/tests/package_import_archive_zip_writer/package_import_archive_zip_writer.gs.ts +++ b/tests/tests/package_import_archive_zip_writer/package_import_archive_zip_writer.gs.ts @@ -27,14 +27,14 @@ export async function main(): globalThis.Promise { return } await $.println("open", err == null, $.sliceLen((zr$ as zip.Reader).File)) - let __goscriptTuple2: any = await zip.File.prototype.Open.call($.arrayIndex((zr$ as zip.Reader).File!, 0)) + let __goscriptTuple2: any = await zip.File.prototype.Open.call($.plainSliceIndex((zr$ as zip.Reader).File!, 0)) let rc: io.ReadCloser | null = __goscriptTuple2[0] err = __goscriptTuple2[1] await $.println("file open", err == null) let __goscriptTuple3: any = await io.ReadAll($.pointerValueOrNil((rc as io.Reader | null))!) let data: $.Slice = __goscriptTuple3[0] err = __goscriptTuple3[1] - await $.println("file", $.pointerValue($.arrayIndex((zr$ as zip.Reader).File!, 0)).FileHeader.Name, $.bytesToString(data), err == null) + await $.println("file", $.pointerValue($.plainSliceIndex((zr$ as zip.Reader).File!, 0)).FileHeader.Name, $.bytesToString(data), err == null) err = await (rc !== null && (rc as any).__isVarRef !== true && ((rc as any).__goValue === undefined || (rc as any).__goType?.charCodeAt(0) !== 42) ? (rc as Exclude) : $.pointerValue>(rc)).Close() await $.println("file close", err == null) } diff --git a/tests/tests/package_import_asn1_rdn_sequence/package_import_asn1_rdn_sequence.gs.ts b/tests/tests/package_import_asn1_rdn_sequence/package_import_asn1_rdn_sequence.gs.ts index 57bc00d49..d415b918a 100644 --- a/tests/tests/package_import_asn1_rdn_sequence/package_import_asn1_rdn_sequence.gs.ts +++ b/tests/tests/package_import_asn1_rdn_sequence/package_import_asn1_rdn_sequence.gs.ts @@ -20,9 +20,9 @@ export async function main(): globalThis.Promise { await $.println("unmarshal err nil", err == null) await $.println("rest len", $.sliceLen(rest)) await $.println("rdn count", $.sliceLen((output.value as pkix.RDNSequence))) - await $.println("set count", $.sliceLen(($.arrayIndex(output.value!, 0) as pkix.RelativeDistinguishedNameSET))) - await $.println("oid", asn1.ObjectIdentifier_String($.arrayIndex($.arrayIndex(output.value!, 0)!, 0).Type)) - await $.println("value", $.mustTypeAssert($.arrayIndex($.arrayIndex(output.value!, 0)!, 0).Value, /* @__PURE__ */ $.basicType("string"))) + await $.println("set count", $.sliceLen(($.plainSliceIndex(output.value!, 0) as pkix.RelativeDistinguishedNameSET))) + await $.println("oid", asn1.ObjectIdentifier_String($.plainSliceIndex($.plainSliceIndex(output.value!, 0)!, 0).Type)) + await $.println("value", $.mustTypeAssert($.plainSliceIndex($.plainSliceIndex(output.value!, 0)!, 0).Value, /* @__PURE__ */ $.basicType("string"))) } var __goscriptStatic0$value: any diff --git a/tests/tests/package_import_crypto_aes_gcm_roundtrip/main.gs.ts b/tests/tests/package_import_crypto_aes_gcm_roundtrip/main.gs.ts index 9eed3c72c..468325531 100644 --- a/tests/tests/package_import_crypto_aes_gcm_roundtrip/main.gs.ts +++ b/tests/tests/package_import_crypto_aes_gcm_roundtrip/main.gs.ts @@ -176,7 +176,7 @@ export async function main(): globalThis.Promise { let __goscriptTuple2: any = await (randomAEAD !== null && (randomAEAD as any).__isVarRef !== true && ((randomAEAD as any).__goValue === undefined || (randomAEAD as any).__goType?.charCodeAt(0) !== 42) ? (randomAEAD as Exclude) : $.pointerValue>(randomAEAD)).Open(null, null, $.goSlice(randomSealed, 1, undefined), aad) let randomOpened: $.Slice = __goscriptTuple2[0] let openErr: $.GoError = __goscriptTuple2[1] - await $.println("random nonce:", err == null, openErr == null, (__goscriptAwait = (randomAEAD !== null && (randomAEAD as any).__isVarRef !== true && ((randomAEAD as any).__goValue === undefined || (randomAEAD as any).__goType?.charCodeAt(0) !== 42) ? (randomAEAD as Exclude) : $.pointerValue>(randomAEAD)).NonceSize(), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait), (__goscriptAwait = (randomAEAD !== null && (randomAEAD as any).__isVarRef !== true && ((randomAEAD as any).__goValue === undefined || (randomAEAD as any).__goType?.charCodeAt(0) !== 42) ? (randomAEAD as Exclude) : $.pointerValue>(randomAEAD)).Overhead(), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait), $.sliceLen(randomSealed), $.arrayIndex(randomSealed!, 0) == 7, bytes.Equal(randomOpened, new Uint8Array([114, 97, 110, 100, 111, 109, 32, 110, 111, 110, 99, 101]))) + await $.println("random nonce:", err == null, openErr == null, (__goscriptAwait = (randomAEAD !== null && (randomAEAD as any).__isVarRef !== true && ((randomAEAD as any).__goValue === undefined || (randomAEAD as any).__goType?.charCodeAt(0) !== 42) ? (randomAEAD as Exclude) : $.pointerValue>(randomAEAD)).NonceSize(), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait), (__goscriptAwait = (randomAEAD !== null && (randomAEAD as any).__isVarRef !== true && ((randomAEAD as any).__goValue === undefined || (randomAEAD as any).__goType?.charCodeAt(0) !== 42) ? (randomAEAD as Exclude) : $.pointerValue>(randomAEAD)).Overhead(), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait), $.sliceLen(randomSealed), $.typedSliceIndex(randomSealed!, 0) == 7, bytes.Equal(randomOpened, new Uint8Array([114, 97, 110, 100, 111, 109, 32, 110, 111, 110, 99, 101]))) } var __goscriptStatic0$value: any diff --git a/tests/tests/package_import_crypto_sha1/package_import_crypto_sha1.gs.ts b/tests/tests/package_import_crypto_sha1/package_import_crypto_sha1.gs.ts index 1a1fa4899..e6317bb38 100644 --- a/tests/tests/package_import_crypto_sha1/package_import_crypto_sha1.gs.ts +++ b/tests/tests/package_import_crypto_sha1/package_import_crypto_sha1.gs.ts @@ -23,13 +23,13 @@ export async function main(): globalThis.Promise { await $.println("write bc", n, err == null) let stream = await (h !== null && (h as any).__isVarRef !== true && ((h as any).__goValue === undefined || (h as any).__goType?.charCodeAt(0) !== 42) ? (h as Exclude) : $.pointerValue>(h)).Sum(new Uint8Array([1, 2]) as $.Slice) await $.println("stream len", $.sliceLen(stream)) - await $.println("stream prefix", $.arrayIndex(stream!, 0), $.arrayIndex(stream!, 1)) - await $.println("stream digest", $.arrayIndex(stream!, 2), $.arrayIndex(stream!, 21)) + await $.println("stream prefix", $.typedSliceIndex(stream!, 0), $.typedSliceIndex(stream!, 1)) + await $.println("stream digest", $.typedSliceIndex(stream!, 2), $.typedSliceIndex(stream!, 21)) let backing = $.makeSlice(sha1.Size, undefined, "byte") let backed = await (h !== null && (h as any).__isVarRef !== true && ((h as any).__goValue === undefined || (h as any).__goType?.charCodeAt(0) !== 42) ? (h as Exclude) : $.pointerValue>(h)).Sum($.goSlice(backing, undefined, 0)) await $.println("backed len", $.sliceLen(backed), $.sliceLen(backing)) - await $.println("backed digest", $.arrayIndex(backing!, 0), $.arrayIndex(backing!, 19), $.arrayIndex(backed!, 0), $.arrayIndex(backed!, 19)) + await $.println("backed digest", $.typedSliceIndex(backing!, 0), $.typedSliceIndex(backing!, 19), $.typedSliceIndex(backed!, 0), $.typedSliceIndex(backed!, 19)) } if ($.isMainScript(import.meta)) { diff --git a/tests/tests/package_import_crypto_sha256/package_import_crypto_sha256.gs.ts b/tests/tests/package_import_crypto_sha256/package_import_crypto_sha256.gs.ts index 5ddb3b176..61fed92df 100644 --- a/tests/tests/package_import_crypto_sha256/package_import_crypto_sha256.gs.ts +++ b/tests/tests/package_import_crypto_sha256/package_import_crypto_sha256.gs.ts @@ -23,13 +23,13 @@ export async function main(): globalThis.Promise { await $.println("write bc", n, err == null) let stream = await (h !== null && (h as any).__isVarRef !== true && ((h as any).__goValue === undefined || (h as any).__goType?.charCodeAt(0) !== 42) ? (h as Exclude) : $.pointerValue>(h)).Sum(new Uint8Array([1, 2]) as $.Slice) await $.println("stream len", $.sliceLen(stream)) - await $.println("stream prefix", $.arrayIndex(stream!, 0), $.arrayIndex(stream!, 1)) - await $.println("stream digest", $.arrayIndex(stream!, 2), $.arrayIndex(stream!, 33)) + await $.println("stream prefix", $.typedSliceIndex(stream!, 0), $.typedSliceIndex(stream!, 1)) + await $.println("stream digest", $.typedSliceIndex(stream!, 2), $.typedSliceIndex(stream!, 33)) let backing = $.makeSlice(sha256.Size, undefined, "byte") let backed = await (h !== null && (h as any).__isVarRef !== true && ((h as any).__goValue === undefined || (h as any).__goType?.charCodeAt(0) !== 42) ? (h as Exclude) : $.pointerValue>(h)).Sum($.goSlice(backing, undefined, 0)) await $.println("backed len", $.sliceLen(backed), $.sliceLen(backing)) - await $.println("backed digest", $.arrayIndex(backing!, 0), $.arrayIndex(backing!, 31), $.arrayIndex(backed!, 0), $.arrayIndex(backed!, 31)) + await $.println("backed digest", $.typedSliceIndex(backing!, 0), $.typedSliceIndex(backing!, 31), $.typedSliceIndex(backed!, 0), $.typedSliceIndex(backed!, 31)) } if ($.isMainScript(import.meta)) { diff --git a/tests/tests/package_import_encoding_json/package_import_encoding_json.gs.ts b/tests/tests/package_import_encoding_json/package_import_encoding_json.gs.ts index f1e54f452..559345834 100644 --- a/tests/tests/package_import_encoding_json/package_import_encoding_json.gs.ts +++ b/tests/tests/package_import_encoding_json/package_import_encoding_json.gs.ts @@ -234,9 +234,9 @@ export async function byteSliceFields(): globalThis.Promise { let d$: Enc = d == null ? $.pointerTarget(d) : (d as any).__isVarRef === true ? (d as any).value : (d as any).__goValue === undefined ? (d as any) : $.pointerTarget(d) err = (json.Unmarshal(b, $.interfaceValue(d, "*main.Enc", /* @__PURE__ */ $.pointerType("main.Enc"))) as $.GoError) await $.println("err:", err == null, "width:", (d$ as Enc).Width) - await $.println("image:", $.sliceLen((d$ as Enc).Image), $.arrayIndex((d$ as Enc).Image!, 0), $.arrayIndex((d$ as Enc).Image!, 2)) - await $.println("frames:", $.sliceLen((d$ as Enc).Frames), $.sliceLen($.arrayIndex((d$ as Enc).Frames!, 1)), $.arrayIndex($.arrayIndex((d$ as Enc).Frames!, 1)!, 1)) - await $.println("named:", $.sliceLen($.mapGet, $.Slice>((d$ as Enc).Named, "a", null)[0]), $.arrayIndex($.mapGet, $.Slice>((d$ as Enc).Named, "a", null)[0]!, 1)) + await $.println("image:", $.sliceLen((d$ as Enc).Image), $.typedSliceIndex((d$ as Enc).Image!, 0), $.typedSliceIndex((d$ as Enc).Image!, 2)) + await $.println("frames:", $.sliceLen((d$ as Enc).Frames), $.sliceLen($.plainSliceIndex((d$ as Enc).Frames!, 1)), $.typedSliceIndex($.plainSliceIndex((d$ as Enc).Frames!, 1)!, 1)) + await $.println("named:", $.sliceLen($.mapGet, $.Slice>((d$ as Enc).Named, "a", null)[0]), $.typedSliceIndex($.mapGet, $.Slice>((d$ as Enc).Named, "a", null)[0]!, 1)) await $.println("nested:", $.bytesToString($.pointerValue((d$ as Enc).Nested).Image)) err = (json.Unmarshal(new Uint8Array([123, 34, 73, 109, 97, 103, 101, 34, 58, 110, 117, 108, 108, 125]), $.interfaceValue(d, "*main.Enc", /* @__PURE__ */ $.pointerType("main.Enc"))) as $.GoError) diff --git a/tests/tests/package_import_encoding_json_reuse_interface_elements/package_import_encoding_json_reuse_interface_elements.gs.ts b/tests/tests/package_import_encoding_json_reuse_interface_elements/package_import_encoding_json_reuse_interface_elements.gs.ts index 00a4ab29c..e4dc23bc5 100644 --- a/tests/tests/package_import_encoding_json_reuse_interface_elements/package_import_encoding_json_reuse_interface_elements.gs.ts +++ b/tests/tests/package_import_encoding_json_reuse_interface_elements/package_import_encoding_json_reuse_interface_elements.gs.ts @@ -114,7 +114,7 @@ export async function main(): globalThis.Promise { let b = new Custom() let h = $.varRef(new Holder(true, $.arrayToSlice([$.interfaceValue(a, "*main.Node", /* @__PURE__ */ $.pointerType("main.Node")), $.interfaceValue(b, "*main.Custom", /* @__PURE__ */ $.pointerType("main.Custom"))]))) let err = (json.Unmarshal(new Uint8Array([123, 34, 73, 116, 101, 109, 115, 34, 58, 91, 123, 34, 78, 97, 109, 101, 34, 58, 34, 120, 34, 125, 44, 34, 121, 34, 93, 125]), $.interfaceValue(h, "*main.Holder", /* @__PURE__ */ $.pointerType("main.Holder"))) as $.GoError) - fmt.Println((err as any), $.basicInterfaceValue($.sliceLen(h.value.Items), "int"), $.comparableEqual($.arrayIndex(h.value.Items!, 0), $.interfaceValue(a, "*main.Node", /* @__PURE__ */ $.pointerType("main.Node"))), $.pointerValue(a).Name, $.comparableEqual($.arrayIndex(h.value.Items!, 1), $.interfaceValue(b, "*main.Custom", /* @__PURE__ */ $.pointerType("main.Custom"))), $.pointerValue(b).Text) + fmt.Println((err as any), $.basicInterfaceValue($.sliceLen(h.value.Items), "int"), $.comparableEqual($.plainSliceIndex(h.value.Items!, 0), $.interfaceValue(a, "*main.Node", /* @__PURE__ */ $.pointerType("main.Node"))), $.pointerValue(a).Name, $.comparableEqual($.plainSliceIndex(h.value.Items!, 1), $.interfaceValue(b, "*main.Custom", /* @__PURE__ */ $.pointerType("main.Custom"))), $.pointerValue(b).Text) } if ($.isMainScript(import.meta)) { diff --git a/tests/tests/package_import_encoding_json_text_map_keys/package_import_encoding_json_text_map_keys.gs.ts b/tests/tests/package_import_encoding_json_text_map_keys/package_import_encoding_json_text_map_keys.gs.ts index 09efa72b1..9d73721cc 100644 --- a/tests/tests/package_import_encoding_json_text_map_keys/package_import_encoding_json_text_map_keys.gs.ts +++ b/tests/tests/package_import_encoding_json_text_map_keys/package_import_encoding_json_text_map_keys.gs.ts @@ -79,7 +79,7 @@ export function __goscript_set_tokenNames(__goscriptValue: $.Slice): voi } export function Tokens_String(t: Tokens): string { - return $.arrayIndex(tokenNames!, t) + return $.plainSliceIndex(tokenNames!, t) } export function Tokens_MarshalText(t: Tokens): [$.Slice, $.GoError] { @@ -120,7 +120,7 @@ export async function main(): globalThis.Promise { await $.println("error:", (__goscriptAwait = (err !== null && (err as any).__isVarRef !== true && ((err as any).__goValue === undefined || (err as any).__goType?.charCodeAt(0) !== 42) ? (err as Exclude<$.GoError, null>) : $.pointerValue>(err)).Error(), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait)) } await $.println("comment:", $.mapGet($.mapGet(d.value.Styles, "x", null)[0], 2, "")[0]) - await $.println("kind:", Tokens_String(d.value.Kind), "kinds:", $.sliceLen(d.value.Kinds), Tokens_String($.arrayIndex(d.value.Kinds!, 0)), Tokens_String($.arrayIndex(d.value.Kinds!, 1))) + await $.println("kind:", Tokens_String(d.value.Kind), "kinds:", $.sliceLen(d.value.Kinds), Tokens_String($.typedSliceIndex(d.value.Kinds!, 0)), Tokens_String($.typedSliceIndex(d.value.Kinds!, 1))) let __goscriptTuple0: any = (json.Marshal($.structInterfaceValue(new Doc(true, 1, $.typedSliceOf(Int32Array, [2]) as $.Slice), "main.Doc", "main.Doc")) as [$.Slice, $.GoError]) let b: $.Slice = __goscriptTuple0[0] await $.println("marshal doc:", $.bytesToString(b)) @@ -147,7 +147,7 @@ export async function main(): globalThis.Promise { keys = $.appendOne(keys, k) } sort.Strings(keys) - await $.println("styles keys:", $.sliceLen(keys), $.arrayIndex(keys!, 0)) + await $.println("styles keys:", $.sliceLen(keys), $.plainSliceIndex(keys!, 0)) } var __goscriptAwait: any diff --git a/tests/tests/package_import_encoding_json_text_unmarshaler_pointer/package_import_encoding_json_text_unmarshaler_pointer.gs.ts b/tests/tests/package_import_encoding_json_text_unmarshaler_pointer/package_import_encoding_json_text_unmarshaler_pointer.gs.ts index 1a7767347..8042e3c44 100644 --- a/tests/tests/package_import_encoding_json_text_unmarshaler_pointer/package_import_encoding_json_text_unmarshaler_pointer.gs.ts +++ b/tests/tests/package_import_encoding_json_text_unmarshaler_pointer/package_import_encoding_json_text_unmarshaler_pointer.gs.ts @@ -56,7 +56,7 @@ export async function main(): globalThis.Promise { await $.println(err == null, s.value) let acts: $.VarRef<$.Slice> = $.varRef(null! as $.Slice) err = (json.Unmarshal(new Uint8Array([91, 34, 78, 101, 120, 116, 34, 44, 34, 78, 97, 109, 101, 34, 93]), $.interfaceValue(acts, "*[]main.Act", /* @__PURE__ */ $.pointerType(/* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("int64", "main.Act"))))) as $.GoError) - await $.println(err == null, $.sliceLen(acts.value), $.arrayIndex(acts.value!, 0), $.arrayIndex(acts.value!, 1)) + await $.println(err == null, $.sliceLen(acts.value), $.plainSliceIndex(acts.value!, 0), $.plainSliceIndex(acts.value!, 1)) err = (json.Unmarshal(new Uint8Array([34, 66, 111, 103, 117, 115, 34]), $.namedValueInterfaceValue(a, "*main.Act", __goscriptStatic0(), __goscriptStatic1(), __goscriptStatic2())) as $.GoError) await $.println(err != null) } diff --git a/tests/tests/package_import_encoding_json_unmarshal_pointer_hook/package_import_encoding_json_unmarshal_pointer_hook.gs.ts b/tests/tests/package_import_encoding_json_unmarshal_pointer_hook/package_import_encoding_json_unmarshal_pointer_hook.gs.ts index d0fc921dd..8fa8e945c 100644 --- a/tests/tests/package_import_encoding_json_unmarshal_pointer_hook/package_import_encoding_json_unmarshal_pointer_hook.gs.ts +++ b/tests/tests/package_import_encoding_json_unmarshal_pointer_hook/package_import_encoding_json_unmarshal_pointer_hook.gs.ts @@ -159,7 +159,7 @@ export async function main(): globalThis.Promise { // UnmarshalJSON, decodes into the value it points to. let maps: $.VarRef = $.varRef(null! as Maps) let err = Maps_CopyFrom(maps, ($.arrayToSlice([new MapItem(true, "a", $.makeMap([["x", 1]])), new MapItem(true, "b")]) as Maps)) - fmt.Println("copy:", err == null, $.basicInterfaceValue($.sliceLen((maps.value as Maps)), "int"), $.arrayIndex(maps.value!, 0).Name, $.basicInterfaceValue($.mapGet($.arrayIndex(maps.value!, 0).Map, "x", 0)[0], "int"), $.arrayIndex(maps.value!, 1).Name) + fmt.Println("copy:", err == null, $.basicInterfaceValue($.sliceLen((maps.value as Maps)), "int"), $.plainSliceIndex(maps.value!, 0).Name, $.basicInterfaceValue($.mapGet($.plainSliceIndex(maps.value!, 0).Map, "x", 0)[0], "int"), $.plainSliceIndex(maps.value!, 1).Name) let names: $.VarRef = $.varRef(null! as Names) err = (json.Unmarshal(new Uint8Array([123, 34, 112, 34, 58, 49, 44, 34, 113, 34, 58, 50, 125]), $.namedValueInterfaceValue(names, "*main.Names", __goscriptStatic3(), __goscriptStatic4(), __goscriptStatic5())) as $.GoError) diff --git a/tests/tests/package_import_fmt_pointer_receiver_stringer/package_import_fmt_pointer_receiver_stringer.gs.ts b/tests/tests/package_import_fmt_pointer_receiver_stringer/package_import_fmt_pointer_receiver_stringer.gs.ts index 1cba8804d..ea7c3d7c2 100644 --- a/tests/tests/package_import_fmt_pointer_receiver_stringer/package_import_fmt_pointer_receiver_stringer.gs.ts +++ b/tests/tests/package_import_fmt_pointer_receiver_stringer/package_import_fmt_pointer_receiver_stringer.gs.ts @@ -92,7 +92,7 @@ export async function main(): globalThis.Promise { fmt.Println($.interfaceValue(line.value, "main.Line", /* @__PURE__ */ $.sliceType("main.Lex", "main.Line")), $.namedValueInterfaceValue(line, "*main.Line", __goscriptStatic0(), __goscriptStatic1(), __goscriptStatic2())) fmt.Println((fmt.Sprint($.interfaceValue(line.value, "main.Line", /* @__PURE__ */ $.sliceType("main.Lex", "main.Line"))) as string)) let ptrs = $.arrayToSlice | null>([$.indexRef(line.value!, 0)]) - fmt.Println($.interfaceValue($.arrayIndex(ptrs!, 0), "*main.Lex", /* @__PURE__ */ $.pointerType("main.Lex")), $.structInterfaceValue(new Val(true, 4), "main.Val", "main.Val"), $.interfaceValue(new Val(false, 5), "*main.Val", /* @__PURE__ */ $.pointerType("main.Val")), $.interfaceValue($.arrayToSlice([new Val(true, 6)]), "[]main.Val", /* @__PURE__ */ $.sliceType("main.Val"))) + fmt.Println($.interfaceValue($.plainSliceIndex(ptrs!, 0), "*main.Lex", /* @__PURE__ */ $.pointerType("main.Lex")), $.structInterfaceValue(new Val(true, 4), "main.Val", "main.Val"), $.interfaceValue(new Val(false, 5), "*main.Val", /* @__PURE__ */ $.pointerType("main.Val")), $.interfaceValue($.arrayToSlice([new Val(true, 6)]), "[]main.Val", /* @__PURE__ */ $.sliceType("main.Val"))) } var __goscriptStatic0$value: any diff --git a/tests/tests/package_import_io_value_reader/package_import_io_value_reader.gs.ts b/tests/tests/package_import_io_value_reader/package_import_io_value_reader.gs.ts index 989e1b9d7..e1376fdd2 100644 --- a/tests/tests/package_import_io_value_reader/package_import_io_value_reader.gs.ts +++ b/tests/tests/package_import_io_value_reader/package_import_io_value_reader.gs.ts @@ -37,7 +37,7 @@ export async function main(): globalThis.Promise { let __goscriptTuple0: any = await io.ReadAll($.pointerValueOrNil(io.LimitReader($.structInterfaceValue(new zeroReader(true), "main.zeroReader", "main.zeroReader")!, 3n))!) let data: $.Slice = __goscriptTuple0[0] let err: $.GoError = __goscriptTuple0[1] - await $.println("limit:", $.sliceLen(data), $.arrayIndex(data!, 0) == 0, err == null) + await $.println("limit:", $.sliceLen(data), $.typedSliceIndex(data!, 0) == 0, err == null) // Join a bounded zero range with a trailing reader through a spread slice. let rdrs: $.Slice = $.arrayToSlice([io.LimitReader($.structInterfaceValue(new zeroReader(true), "main.zeroReader", "main.zeroReader")!, 2n)]) @@ -45,7 +45,7 @@ export async function main(): globalThis.Promise { let __goscriptTuple1: any = await io.ReadAll($.pointerValueOrNil(io.MultiReader(...(rdrs ?? [])))!) data = __goscriptTuple1[0] err = __goscriptTuple1[1] - await $.println("multi:", $.sliceLen(data), $.arrayIndex(data!, 1) == 0, $.bytesToString($.goSlice(data, 2, undefined)), err == null) + await $.println("multi:", $.sliceLen(data), $.typedSliceIndex(data!, 1) == 0, $.bytesToString($.goSlice(data, 2, undefined)), err == null) } var __goscriptStatic0$value: any diff --git a/tests/tests/package_import_iter_pull/package_import_iter_pull.gs.ts b/tests/tests/package_import_iter_pull/package_import_iter_pull.gs.ts index 9c43bd901..48ded1c9d 100644 --- a/tests/tests/package_import_iter_pull/package_import_iter_pull.gs.ts +++ b/tests/tests/package_import_iter_pull/package_import_iter_pull.gs.ts @@ -56,9 +56,9 @@ export class lexer { const l$: lexer = l == null ? $.pointerTarget(l) : (l as any).__isVarRef === true ? (l as any).value : (l as any).__goValue === undefined ? (l as any) : $.pointerTarget(l) while ($.sliceLen((l$ as lexer).stack) > 0) { let n = $.sliceLen((l$ as lexer).stack) - 1 - let [v, ok] = await $.arrayIndex((l$ as lexer).stack!, n).next!() + let [v, ok] = await $.plainSliceIndex((l$ as lexer).stack!, n).next!() if (!ok) { - void (__goscriptAwait = $.arrayIndex((l$ as lexer).stack!, n).stop!(), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait); + void (__goscriptAwait = $.plainSliceIndex((l$ as lexer).stack!, n).stop!(), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait); ;(l$ as lexer).stack = $.goSlice((l$ as lexer).stack, undefined, n) continue } diff --git a/tests/tests/package_import_iter_pull_sync_seq/package_import_iter_pull_sync_seq.gs.ts b/tests/tests/package_import_iter_pull_sync_seq/package_import_iter_pull_sync_seq.gs.ts index 430b8ca20..8575b39fc 100644 --- a/tests/tests/package_import_iter_pull_sync_seq/package_import_iter_pull_sync_seq.gs.ts +++ b/tests/tests/package_import_iter_pull_sync_seq/package_import_iter_pull_sync_seq.gs.ts @@ -50,7 +50,7 @@ export function points(n: number): iter.Seq2 | null { return $.functionValue(async (_yield: ((_p0: string, _p1: point) => boolean | globalThis.Promise) | null) => { let names = $.arrayToSlice(["a", "b", "c"]) for (let __goscriptRangeCount1 = n, i = 0; i < __goscriptRangeCount1; i++) { - if (!(__goscriptAwait = _yield!($.arrayIndex(names!, i), new point(true, i, i * 10)), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait)) { + if (!(__goscriptAwait = _yield!($.plainSliceIndex(names!, i), new point(true, i, i * 10)), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait)) { return } } @@ -147,14 +147,14 @@ export async function main(): globalThis.Promise { // Collecting a sequence that suspends at yield waits for it. await $.println("collect:", $.sliceLen(await slices.Collect(numbers(3)))) - await $.println("sorted:", $.arrayIndex((await slices.Sorted(numbers(3)))!, 2)) + await $.println("sorted:", $.plainSliceIndex((await slices.Sorted(numbers(3)))!, 2)) await $.println("append:", $.sliceLen(await slices.AppendSeq($.arrayToSlice([9]), numbers(2)))) let m = (await maps.Collect(points(3)) as globalThis.Map | null) await $.println("map:", $.len(m), $.mapGet(m, "c", new point(true))[0].y) await maps.Insert(m, points(1)) await $.println("insert:", $.len(m)) let sortedWords = (await slices.Sorted(words) as $.Slice) - await $.println("words:", $.arrayIndex(sortedWords!, 0), $.arrayIndex(sortedWords!, 1)) + await $.println("words:", $.plainSliceIndex(sortedWords!, 0), $.plainSliceIndex(sortedWords!, 1)) await $.println("keys:", sortedKeys($.makeMap([["b", 1], ["a", 2]]))) // Pull2 returns zero values of its element types at the end. diff --git a/tests/tests/package_import_log_slog/package_import_log_slog.gs.ts b/tests/tests/package_import_log_slog/package_import_log_slog.gs.ts index 41834ffac..73f2cab5c 100644 --- a/tests/tests/package_import_log_slog/package_import_log_slog.gs.ts +++ b/tests/tests/package_import_log_slog/package_import_log_slog.gs.ts @@ -18,7 +18,7 @@ export async function main(): globalThis.Promise { let g = slog.Group("g", $.arrayToSlice([$.structInterfaceValue(slog.String("a", "x"), "slog.Attr", "slog.Attr"), $.structInterfaceValue(slog.Int("b", 2), "slog.Attr", "slog.Attr")])) let attrs = g.Value.Group() - await $.println(slog.Kind_String(g.Value.Kind()), $.sliceLen(attrs), $.arrayIndex(attrs!, 0).Key, $.markAsStructValue($.cloneStructValue($.arrayIndex(attrs!, 1).Value)).Int64()) + await $.println(slog.Kind_String(g.Value.Kind()), $.sliceLen(attrs), $.plainSliceIndex(attrs!, 0).Key, $.markAsStructValue($.cloneStructValue($.plainSliceIndex(attrs!, 1).Value)).Int64()) await $.println(await g.String()) await $.println(await $.markAsStructValue($.cloneStructValue(slog.StringValue("a"))).Equal(slog.StringValue("a")), await s.Equal(slog.StringValue("other"))) diff --git a/tests/tests/package_import_pairing_dial_conversions/package_import_pairing_dial_conversions.gs.ts b/tests/tests/package_import_pairing_dial_conversions/package_import_pairing_dial_conversions.gs.ts index 9115e7f87..e775c3f40 100644 --- a/tests/tests/package_import_pairing_dial_conversions/package_import_pairing_dial_conversions.gs.ts +++ b/tests/tests/package_import_pairing_dial_conversions/package_import_pairing_dial_conversions.gs.ts @@ -87,7 +87,7 @@ export async function main(): globalThis.Promise { let keys = $.makeChannel(1, null! as crypto.PublicKey | null, "both") await $.chanSend(keys, $.namedValueInterfaceValue(new Uint8Array([1, 2, 3]) as $.Slice, "ed25519.PublicKey", __goscriptStatic0(), __goscriptStatic1(), __goscriptStatic2())) let key = ($.mustTypeAssert((await $.chanRecv(keys)), /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("uint8"), "ed25519.PublicKey")) as ed25519.PublicKey) - await $.println("key", $.sliceLen((key as ed25519.PublicKey)), $.arrayIndex(key!, 0)) + await $.println("key", $.sliceLen((key as ed25519.PublicKey)), $.typedSliceIndex(key!, 0)) let target: $.VarRef | null> = $.varRef(null! as recreateError | $.VarRef | null) let matched = errors.As($.pointerValueOrNil($.interfaceValue<$.GoError>(new recreateError(false, 7n), "*main.recreateError", /* @__PURE__ */ $.pointerType("main.recreateError")))!, $.interfaceValue(target, "**main.recreateError", /* @__PURE__ */ $.pointerType(/* @__PURE__ */ $.pointerType("main.recreateError")))) diff --git a/tests/tests/package_import_protobuf_equalvt/package_import_protobuf_equalvt.gs.ts b/tests/tests/package_import_protobuf_equalvt/package_import_protobuf_equalvt.gs.ts index 78e962e7a..a70e2a5f5 100644 --- a/tests/tests/package_import_protobuf_equalvt/package_import_protobuf_equalvt.gs.ts +++ b/tests/tests/package_import_protobuf_equalvt/package_import_protobuf_equalvt.gs.ts @@ -107,10 +107,10 @@ export async function main(): globalThis.Promise { let original = new msg(false, 7) let cloned = (protobuf_go_lite.CloneVTValue(__goscriptStatic0(), original) as msg | $.VarRef | null) await $.println("clone:", (cloned !== original && !(($.pointerAliasesMade || (cloned as any)?.__goElementBacking !== undefined) && $.pointerEqual(cloned, original))), (cloned !== null && (cloned as any).__isVarRef !== true && (cloned as any).__goValue === undefined ? ((cloned as any) as msg).EqualVT(original) : msg.prototype.EqualVT.call(cloned, original))) - await $.println("clone-slice:", !$.pointerEqual($.arrayIndex(protobuf_go_lite.CloneVTSlice($.arrayToSlice | null>([original]))!, 0), original)) + await $.println("clone-slice:", !$.pointerEqual($.plainSliceIndex(protobuf_go_lite.CloneVTSlice($.arrayToSlice | null>([original]))!, 0), original)) let enumSlice = $.typedSliceOf(Int32Array, [1, 0]) as $.Slice let clonedEnumSlice = (protobuf_go_lite.CloneSlice(enumSlice) as $.Slice) - await $.println("clone-enum-slice:", $.arrayIndex(clonedEnumSlice!, 0), $.arrayIndex(clonedEnumSlice!, 1)) + await $.println("clone-enum-slice:", $.typedSliceIndex(clonedEnumSlice!, 0), $.typedSliceIndex(clonedEnumSlice!, 1)) await $.println("equal:", protobuf_go_lite.IsEqualVT(__goscriptStatic0(), original, new msg(false, 7))) await $.println("equal-slice-implicit:", protobuf_go_lite.EqualVTSliceImplicit($.arrayToSlice | null>([null, original]), $.arrayToSlice | null>([new msg(), new msg(false, 7)]), $.functionValue((): msg | $.VarRef | null => { return new msg() diff --git a/tests/tests/package_import_reflect/package_import_reflect.gs.ts b/tests/tests/package_import_reflect/package_import_reflect.gs.ts index ea19ecdd7..5aaff8083 100644 --- a/tests/tests/package_import_reflect/package_import_reflect.gs.ts +++ b/tests/tests/package_import_reflect/package_import_reflect.gs.ts @@ -118,9 +118,9 @@ export async function main(): globalThis.Promise { // Test Swapper function let testSlice = $.arrayToSlice([1, 2, 3, 4, 5]) let swapper: ((i: number, j: number) => void) | null = reflect.Swapper($.interfaceValue(testSlice, "[]int", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("int")))) - await $.println("Before swap:", $.arrayIndex(testSlice!, 0), $.arrayIndex(testSlice!, 4)) + await $.println("Before swap:", $.plainSliceIndex(testSlice!, 0), $.plainSliceIndex(testSlice!, 4)) swapper!(0, 4) - await $.println("After swap:", $.arrayIndex(testSlice!, 0), $.arrayIndex(testSlice!, 4)) + await $.println("After swap:", $.plainSliceIndex(testSlice!, 0), $.plainSliceIndex(testSlice!, 4)) // Test Copy function let src = $.arrayToSlice([10, 20, 30]) @@ -129,7 +129,7 @@ export async function main(): globalThis.Promise { let dstVal = $.markAsStructValue($.cloneStructValue(reflect.ValueOf($.interfaceValue(dst, "[]int", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("int")))))) let copied = reflect.Copy(dstVal, srcVal) await $.println("Copied elements:", copied) - await $.println("Dst after copy:", $.arrayIndex(dst!, 0), $.arrayIndex(dst!, 1)) + await $.println("Dst after copy:", $.plainSliceIndex(dst!, 0), $.plainSliceIndex(dst!, 1)) // Test struct reflection let person = new Person(true, "Alice", 30) diff --git a/tests/tests/package_import_slices/package_import_slices.gs.ts b/tests/tests/package_import_slices/package_import_slices.gs.ts index 38f94ed52..2d37b2e64 100644 --- a/tests/tests/package_import_slices/package_import_slices.gs.ts +++ b/tests/tests/package_import_slices/package_import_slices.gs.ts @@ -37,7 +37,7 @@ export async function main(): globalThis.Promise { let cloned = (slices.Clone(s) as $.Slice) $.sliceElems(cloned!)[$.sliceSlot(cloned!, 0)] = 99 - await $.println("clone first:", $.arrayIndex(cloned!, 0), "original first:", $.arrayIndex(s!, 0), "same len:", $.sliceLen(cloned) == $.sliceLen(s)) + await $.println("clone first:", $.plainSliceIndex(cloned!, 0), "original first:", $.plainSliceIndex(s!, 0), "same len:", $.sliceLen(cloned) == $.sliceLen(s)) let nilSlice: $.Slice = null! as $.Slice await $.println("nil clone:", slices.Clone(nilSlice) == null) @@ -49,9 +49,9 @@ export async function main(): globalThis.Promise { return v > 4 }, ({ kind: $.TypeKind.Function, params: [/* @__PURE__ */ $.basicType("int")], results: [/* @__PURE__ */ $.basicType("bool")] } as $.FunctionTypeInfo)))) let inserted = (slices.Insert($.arrayToSlice([1, 4]), 1, 2, 3) as $.Slice) - await $.println("insert:", $.arrayIndex(inserted!, 0), $.arrayIndex(inserted!, 1), $.arrayIndex(inserted!, 2), $.arrayIndex(inserted!, 3)) + await $.println("insert:", $.plainSliceIndex(inserted!, 0), $.plainSliceIndex(inserted!, 1), $.plainSliceIndex(inserted!, 2), $.plainSliceIndex(inserted!, 3)) slices.Reverse(inserted) - await $.println("reverse:", $.arrayIndex(inserted!, 0), $.arrayIndex(inserted!, 1), $.arrayIndex(inserted!, 2), $.arrayIndex(inserted!, 3)) + await $.println("reverse:", $.plainSliceIndex(inserted!, 0), $.plainSliceIndex(inserted!, 1), $.plainSliceIndex(inserted!, 2), $.plainSliceIndex(inserted!, 3)) await $.println("is sorted:", slices.IsSorted($.arrayToSlice([1, 2, 3])), slices.IsSorted($.arrayToSlice([1, 3, 2]))) class item { @@ -87,7 +87,7 @@ export async function main(): globalThis.Promise { slices.SortStableFunc(stable, $.functionValue((a: item, b: item): number => { return a.group - b.group }, ({ kind: $.TypeKind.Function, params: ["main.item", "main.item"], results: [/* @__PURE__ */ $.basicType("int")] } as $.FunctionTypeInfo))) - await $.println("stable:", $.arrayIndex(stable!, 0).label, $.arrayIndex(stable!, 1).label, $.arrayIndex(stable!, 2).label, $.arrayIndex(stable!, 3).label) + await $.println("stable:", $.plainSliceIndex(stable!, 0).label, $.plainSliceIndex(stable!, 1).label, $.plainSliceIndex(stable!, 2).label, $.plainSliceIndex(stable!, 3).label) await $.println("is sorted func:", slices.IsSortedFunc(stable, $.functionValue((a: item, b: item): number => { return a.group - b.group }, ({ kind: $.TypeKind.Function, params: ["main.item", "main.item"], results: [/* @__PURE__ */ $.basicType("int")] } as $.FunctionTypeInfo)))) @@ -95,10 +95,10 @@ export async function main(): globalThis.Promise { let filtered = (slices.DeleteFunc($.arrayToSlice([1, 2, 3, 4, 5]), $.functionValue((v: number): boolean => { return (v % 2) == 0 }, ({ kind: $.TypeKind.Function, params: [/* @__PURE__ */ $.basicType("int")], results: [/* @__PURE__ */ $.basicType("bool")] } as $.FunctionTypeInfo)), () => (0 as number)) as $.Slice) - await $.println("delete func:", $.arrayIndex(filtered!, 0), $.arrayIndex(filtered!, 1), $.arrayIndex(filtered!, 2), $.sliceLen(filtered)) + await $.println("delete func:", $.plainSliceIndex(filtered!, 0), $.plainSliceIndex(filtered!, 1), $.plainSliceIndex(filtered!, 2), $.sliceLen(filtered)) let sortedKeys = (slices.Sorted(maps.Keys($.makeMap([["c", 3], ["a", 1], ["b", 2]]))) as $.Slice) - await $.println("sorted:", $.arrayIndex(sortedKeys!, 0), $.arrayIndex(sortedKeys!, 1), $.arrayIndex(sortedKeys!, 2)) + await $.println("sorted:", $.plainSliceIndex(sortedKeys!, 0), $.plainSliceIndex(sortedKeys!, 1), $.plainSliceIndex(sortedKeys!, 2)) let __goscriptRangeReturn2 = false ;await (async () => { @@ -136,22 +136,22 @@ export async function main(): globalThis.Promise { } await $.println("nil values:", valueCount) let sortedValues = (slices.Sorted(slices.Values($.arrayToSlice(["c", "a", "b"]))) as $.Slice) - await $.println("sorted values:", $.arrayIndex(sortedValues!, 0), $.arrayIndex(sortedValues!, 1), $.arrayIndex(sortedValues!, 2)) + await $.println("sorted values:", $.plainSliceIndex(sortedValues!, 0), $.plainSliceIndex(sortedValues!, 1), $.plainSliceIndex(sortedValues!, 2)) let repeated = (slices.Repeat($.arrayToSlice([7, 8]), 3) as $.Slice) - await $.println("repeat:", $.sliceLen(repeated), $.cap(repeated), $.arrayIndex(repeated!, 0), $.arrayIndex(repeated!, 5), slices.Repeat(null, 2) == null, $.sliceLen(slices.Repeat($.arrayToSlice([1]), 0))) + await $.println("repeat:", $.sliceLen(repeated), $.cap(repeated), $.plainSliceIndex(repeated!, 0), $.plainSliceIndex(repeated!, 5), slices.Repeat(null, 2) == null, $.sliceLen(slices.Repeat($.arrayToSlice([1]), 0))) let sortedFunc = (await slices.SortedFunc(slices.Values($.arrayToSlice([1, 3, 2])), $.functionValue((a: number, b: number): number => { return b - a }, ({ kind: $.TypeKind.Function, params: [/* @__PURE__ */ $.basicType("int"), /* @__PURE__ */ $.basicType("int")], results: [/* @__PURE__ */ $.basicType("int")] } as $.FunctionTypeInfo))) as $.Slice) - await $.println("sorted func:", $.arrayIndex(sortedFunc!, 0), $.arrayIndex(sortedFunc!, 1), $.arrayIndex(sortedFunc!, 2), await slices.SortedFunc(slices.Values($.arrayToSlice([])), $.functionValue((a: number, b: number): number => { + await $.println("sorted func:", $.plainSliceIndex(sortedFunc!, 0), $.plainSliceIndex(sortedFunc!, 1), $.plainSliceIndex(sortedFunc!, 2), await slices.SortedFunc(slices.Values($.arrayToSlice([])), $.functionValue((a: number, b: number): number => { return a - b }, ({ kind: $.TypeKind.Function, params: [/* @__PURE__ */ $.basicType("int"), /* @__PURE__ */ $.basicType("int")], results: [/* @__PURE__ */ $.basicType("int")] } as $.FunctionTypeInfo))) == null) let stableSeq = (await slices.SortedStableFunc(slices.Values($.arrayToSlice([$.markAsStructValue(new item({group: 2, label: "a"})), $.markAsStructValue(new item({group: 1, label: "b"})), $.markAsStructValue(new item({group: 2, label: "c"})), $.markAsStructValue(new item({group: 1, label: "d"}))])), $.functionValue((a: item, b: item): number => { return a.group - b.group }, ({ kind: $.TypeKind.Function, params: ["main.item", "main.item"], results: [/* @__PURE__ */ $.basicType("int")] } as $.FunctionTypeInfo))) as $.Slice) - await $.println("sorted stable func:", $.arrayIndex(stableSeq!, 0).label, $.arrayIndex(stableSeq!, 1).label, $.arrayIndex(stableSeq!, 2).label, $.arrayIndex(stableSeq!, 3).label) + await $.println("sorted stable func:", $.plainSliceIndex(stableSeq!, 0).label, $.plainSliceIndex(stableSeq!, 1).label, $.plainSliceIndex(stableSeq!, 2).label, $.plainSliceIndex(stableSeq!, 3).label) // Struct elements are values. Mutating a copy or a yielded loop value // must leave the original slice unchanged. @@ -183,25 +183,25 @@ export async function main(): globalThis.Promise { let copySrc = $.arrayToSlice([$.markAsStructValue(new cell({n: 1})), $.markAsStructValue(new cell({n: 2}))]) let copyDst = $.arrayToSlice([$.markAsStructValue(new cell({n: 0})), $.markAsStructValue(new cell({n: 0}))]) $.copy(copyDst, copySrc, true) - $.arrayIndex(copyDst!, 0).n = 9 - await $.println("copy struct:", $.arrayIndex(copySrc!, 0).n, $.arrayIndex(copySrc!, 1).n, $.arrayIndex(copyDst!, 0).n, $.arrayIndex(copyDst!, 1).n) + $.plainSliceIndex(copyDst!, 0).n = 9 + await $.println("copy struct:", $.plainSliceIndex(copySrc!, 0).n, $.plainSliceIndex(copySrc!, 1).n, $.plainSliceIndex(copyDst!, 0).n, $.plainSliceIndex(copyDst!, 1).n) let cloneSrc = $.arrayToSlice([$.markAsStructValue(new cell({n: 1})), $.markAsStructValue(new cell({n: 2}))]) let clonedCells = (slices.Clone(cloneSrc) as $.Slice) - $.arrayIndex(clonedCells!, 0).n = 8 - await $.println("clone struct:", $.arrayIndex(cloneSrc!, 0).n, $.arrayIndex(cloneSrc!, 1).n, $.arrayIndex(clonedCells!, 0).n, $.arrayIndex(clonedCells!, 1).n) + $.plainSliceIndex(clonedCells!, 0).n = 8 + await $.println("clone struct:", $.plainSliceIndex(cloneSrc!, 0).n, $.plainSliceIndex(cloneSrc!, 1).n, $.plainSliceIndex(clonedCells!, 0).n, $.plainSliceIndex(clonedCells!, 1).n) let repeatSrc = $.arrayToSlice([$.markAsStructValue(new cell({n: 1})), $.markAsStructValue(new cell({n: 2}))]) let repeatedCells = (slices.Repeat(repeatSrc, 2) as $.Slice) - $.arrayIndex(repeatedCells!, 0).n = 7 - $.arrayIndex(repeatedCells!, 2).n = 6 - await $.println("repeat struct:", $.arrayIndex(repeatSrc!, 0).n, $.arrayIndex(repeatSrc!, 1).n, $.arrayIndex(repeatedCells!, 0).n, $.arrayIndex(repeatedCells!, 1).n, $.arrayIndex(repeatedCells!, 2).n, $.arrayIndex(repeatedCells!, 3).n) + $.plainSliceIndex(repeatedCells!, 0).n = 7 + $.plainSliceIndex(repeatedCells!, 2).n = 6 + await $.println("repeat struct:", $.plainSliceIndex(repeatSrc!, 0).n, $.plainSliceIndex(repeatSrc!, 1).n, $.plainSliceIndex(repeatedCells!, 0).n, $.plainSliceIndex(repeatedCells!, 1).n, $.plainSliceIndex(repeatedCells!, 2).n, $.plainSliceIndex(repeatedCells!, 3).n) let concatSrc = $.arrayToSlice([$.markAsStructValue(new cell({n: 1})), $.markAsStructValue(new cell({n: 2}))]) let concated = (slices.Concat(concatSrc, $.arrayToSlice([$.markAsStructValue(new cell({n: 3}))])) as $.Slice) - $.arrayIndex(concated!, 0).n = 5 - $.arrayIndex(concated!, 2).n = 4 - await $.println("concat struct:", $.arrayIndex(concatSrc!, 0).n, $.arrayIndex(concatSrc!, 1).n, $.arrayIndex(concated!, 0).n, $.arrayIndex(concated!, 1).n, $.arrayIndex(concated!, 2).n) + $.plainSliceIndex(concated!, 0).n = 5 + $.plainSliceIndex(concated!, 2).n = 4 + await $.println("concat struct:", $.plainSliceIndex(concatSrc!, 0).n, $.plainSliceIndex(concatSrc!, 1).n, $.plainSliceIndex(concated!, 0).n, $.plainSliceIndex(concated!, 1).n, $.plainSliceIndex(concated!, 2).n) let valuesSrc = $.arrayToSlice([$.markAsStructValue(new cell({n: 1})), $.markAsStructValue(new cell({n: 2}))]) let __goscriptRangeReturn5 = false @@ -214,7 +214,7 @@ export async function main(): globalThis.Promise { if (__goscriptRangeReturn5) { return } - await $.println("values struct:", $.arrayIndex(valuesSrc!, 0).n, $.arrayIndex(valuesSrc!, 1).n) + await $.println("values struct:", $.plainSliceIndex(valuesSrc!, 0).n, $.plainSliceIndex(valuesSrc!, 1).n) let allSrc = $.arrayToSlice([$.markAsStructValue(new cell({n: 1})), $.markAsStructValue(new cell({n: 2}))]) let __goscriptRangeReturn6 = false @@ -227,16 +227,16 @@ export async function main(): globalThis.Promise { if (__goscriptRangeReturn6) { return } - await $.println("all struct:", $.arrayIndex(allSrc!, 0).n, $.arrayIndex(allSrc!, 1).n) + await $.println("all struct:", $.plainSliceIndex(allSrc!, 0).n, $.plainSliceIndex(allSrc!, 1).n) // append copies struct elements into new backing, including variadic sources. let appendSrc = $.arrayToSlice([$.markAsStructValue(new cell({n: 1}))]) let appended = $.appendOne(appendSrc, $.markAsStructValue(new cell({n: 2}))) - $.arrayIndex(appended!, 0).n = 9 - await $.println("append realloc:", $.arrayIndex(appendSrc!, 0).n) + $.plainSliceIndex(appended!, 0).n = 9 + await $.println("append realloc:", $.plainSliceIndex(appendSrc!, 0).n) let appendSpread = $.appendSlice(null, appendSrc) - $.arrayIndex(appendSpread!, 0).n = 8 - await $.println("append slice:", $.arrayIndex(appendSrc!, 0).n) + $.plainSliceIndex(appendSpread!, 0).n = 8 + await $.println("append slice:", $.plainSliceIndex(appendSrc!, 0).n) // Overlapping append reads a snapshot, so later source elements stay intact. let overlap = $.makeSlice(2, 4, "number") @@ -245,7 +245,7 @@ export async function main(): globalThis.Promise { $.sliceElems(overlap!)[$.sliceSlot(overlap!, 0)] = __goscriptAssign0_0 $.sliceElems(overlap!)[$.sliceSlot(overlap!, 1)] = __goscriptAssign0_1 let overlapped = $.appendSlice($.goSlice(overlap, undefined, 1), overlap) - await $.println("append overlap:", $.arrayIndex(overlapped!, 0), $.arrayIndex(overlapped!, 1), $.arrayIndex(overlapped!, 2)) + await $.println("append overlap:", $.plainSliceIndex(overlapped!, 0), $.plainSliceIndex(overlapped!, 1), $.plainSliceIndex(overlapped!, 2)) let backwardSrc = $.arrayToSlice([$.markAsStructValue(new cell({n: 1}))]) let __goscriptRangeReturn7 = false @@ -258,32 +258,32 @@ export async function main(): globalThis.Promise { if (__goscriptRangeReturn7) { return } - await $.println("backward struct:", $.arrayIndex(backwardSrc!, 0).n) + await $.println("backward struct:", $.plainSliceIndex(backwardSrc!, 0).n) let insertSrc = $.arrayToSlice([$.markAsStructValue(new cell({n: 1}))]) let insertedCells = (slices.Insert(insertSrc, 0, $.markAsStructValue(new cell())) as $.Slice) - $.arrayIndex(insertedCells!, 1).n = 7 - await $.println("insert struct:", $.arrayIndex(insertSrc!, 0).n) + $.plainSliceIndex(insertedCells!, 1).n = 7 + await $.println("insert struct:", $.plainSliceIndex(insertSrc!, 0).n) let replaceSrc = $.arrayToSlice([$.markAsStructValue(new cell({n: 1}))]) let replaced = (slices.Replace(replaceSrc, 0, 0, $.markAsStructValue(new cell())) as $.Slice) - $.arrayIndex(replaced!, 1).n = 8 - await $.println("replace struct:", $.arrayIndex(replaceSrc!, 0).n) + $.plainSliceIndex(replaced!, 1).n = 8 + await $.println("replace struct:", $.plainSliceIndex(replaceSrc!, 0).n) let growSrc = $.arrayToSlice([$.markAsStructValue(new cell({n: 1}))]) let grown = (slices.Grow(growSrc, 1, () => ($.markAsStructValue(new cell()) as cell)) as $.Slice) - $.arrayIndex(grown!, 0).n = 9 - await $.println("grow struct:", $.arrayIndex(growSrc!, 0).n) + $.plainSliceIndex(grown!, 0).n = 9 + await $.println("grow struct:", $.plainSliceIndex(growSrc!, 0).n) let collectedMap = $.makeMap([[0, $.markAsStructValue(new cell({n: 1}))]]) let collected = (slices.Collect(maps.Values(collectedMap)) as $.Slice) - $.arrayIndex(collected!, 0).n = 9 + $.plainSliceIndex(collected!, 0).n = 9 await $.println("collect struct:", $.mapGet(collectedMap, 0, $.markAsStructValue(new cell()))[0].n) // Interface slices can hold a struct after nil or a pointer. let mutateSecond = $.functionValue((values: $.Slice) => { { - const __goscriptTypeSwitchValue = $.arrayIndex(values!, 1) + const __goscriptTypeSwitchValue = $.plainSliceIndex(values!, 1) switch (true) { case $.typeAssert(__goscriptTypeSwitchValue, "main.cell").ok: { @@ -303,30 +303,30 @@ export async function main(): globalThis.Promise { mutateSecond(copied) let __goscriptShadow1 = $.appendSlice(null, source, $.appendZeros.nil) mutateSecond(__goscriptShadow1) - await $.println("interface struct:", $.mustTypeAssert($.arrayIndex(source!, 1), "main.cell").n, $.mustTypeAssert($.arrayIndex(__goscriptShadow0!, 1), "main.cell").n, $.mustTypeAssert($.arrayIndex(copied!, 1), "main.cell").n, $.mustTypeAssert($.arrayIndex(__goscriptShadow1!, 1), "main.cell").n) + await $.println("interface struct:", $.mustTypeAssert($.plainSliceIndex(source!, 1), "main.cell").n, $.mustTypeAssert($.plainSliceIndex(__goscriptShadow0!, 1), "main.cell").n, $.mustTypeAssert($.plainSliceIndex(copied!, 1), "main.cell").n, $.mustTypeAssert($.plainSliceIndex(__goscriptShadow1!, 1), "main.cell").n) } let appendSeqSource = $.arrayToSlice([$.markAsStructValue(new cell({n: 1}))]) let appendSeq = $.functionValue(async (_yield: ((_p0: cell) => boolean | globalThis.Promise) | null) => { - void (__goscriptAwait = _yield!($.markAsStructValue($.cloneStructValue($.arrayIndex(appendSeqSource!, 0)))), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait) + void (__goscriptAwait = _yield!($.markAsStructValue($.cloneStructValue($.plainSliceIndex(appendSeqSource!, 0)))), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait) }, ({ kind: $.TypeKind.Function, params: [({ kind: $.TypeKind.Function, params: ["main.cell"], results: [/* @__PURE__ */ $.basicType("bool")] } as $.FunctionTypeInfo)], results: [] } as $.FunctionTypeInfo)) let appendSeqResult = (await slices.AppendSeq(null, appendSeq) as $.Slice) - $.arrayIndex(appendSeqResult!, 0).n = 9 - await $.println("append seq struct:", $.arrayIndex(appendSeqSource!, 0).n, $.arrayIndex(appendSeqResult!, 0).n) + $.plainSliceIndex(appendSeqResult!, 0).n = 9 + await $.println("append seq struct:", $.plainSliceIndex(appendSeqSource!, 0).n, $.plainSliceIndex(appendSeqResult!, 0).n) let sortedFuncSource = $.arrayToSlice([$.markAsStructValue(new cell({n: 2})), $.markAsStructValue(new cell({n: 1}))]) let sortedFuncResult = (await slices.SortedFunc(slices.Values(sortedFuncSource), $.functionValue((a: cell, b: cell): number => { return a.n - b.n }, ({ kind: $.TypeKind.Function, params: ["main.cell", "main.cell"], results: [/* @__PURE__ */ $.basicType("int")] } as $.FunctionTypeInfo))) as $.Slice) - $.arrayIndex(sortedFuncResult!, 0).n = 9 - await $.println("sorted func struct:", $.arrayIndex(sortedFuncSource!, 0).n, $.arrayIndex(sortedFuncSource!, 1).n, $.arrayIndex(sortedFuncResult!, 0).n, $.arrayIndex(sortedFuncResult!, 1).n) + $.plainSliceIndex(sortedFuncResult!, 0).n = 9 + await $.println("sorted func struct:", $.plainSliceIndex(sortedFuncSource!, 0).n, $.plainSliceIndex(sortedFuncSource!, 1).n, $.plainSliceIndex(sortedFuncResult!, 0).n, $.plainSliceIndex(sortedFuncResult!, 1).n) // Byte slice results hold bytes and feed byte operations. let src = new Uint8Array([97, 98, 99]) let byteClone = (slices.Clone(src) as $.Slice) $.sliceElems(byteClone!)[$.sliceSlot(byteClone!, 0)] = 120 $.sliceElems(byteClone!)[$.sliceSlot(byteClone!, 1)] = $.uint($.sliceElems(byteClone!)[$.sliceSlot(byteClone!, 1)] + (255), 8) - await $.println("byte clone:", $.bytesToString(byteClone), $.bytesToString(src), $.arrayIndex(byteClone!, 1)) + await $.println("byte clone:", $.bytesToString(byteClone), $.bytesToString(src), $.typedSliceIndex(byteClone!, 1)) await $.println("byte results:", $.bytesToString(slices.Clip($.goSlice(src, undefined, 2))), $.bytesToString(slices.Insert(src, 1, 121)), $.bytesToString(slices.Replace(slices.Clone(src), 0, 2, 113)), $.bytesToString(slices.Repeat(src, 2)), $.bytesToString(slices.Concat(src, new Uint8Array([100, 101])))) await $.println("test finished") diff --git a/tests/tests/package_import_slices_generic/package_import_slices_generic.gs.ts b/tests/tests/package_import_slices_generic/package_import_slices_generic.gs.ts index 94cdf7926..de4fb9b1a 100644 --- a/tests/tests/package_import_slices_generic/package_import_slices_generic.gs.ts +++ b/tests/tests/package_import_slices_generic/package_import_slices_generic.gs.ts @@ -19,7 +19,7 @@ export async function main(): globalThis.Promise { await $.println("grow:", $.sliceLen(grown), $.cap(grown)) let values = (siblings(__goscriptStatic0(), 7) as $.Slice) - await $.println("siblings:", $.sliceLen(values), $.arrayIndex(values!, 0)) + await $.println("siblings:", $.sliceLen(values), $.plainSliceIndex(values!, 0)) } var __goscriptStatic0$value: any diff --git a/tests/tests/package_import_sort/package_import_sort.gs.ts b/tests/tests/package_import_sort/package_import_sort.gs.ts index d74ff9adc..dcb443424 100644 --- a/tests/tests/package_import_sort/package_import_sort.gs.ts +++ b/tests/tests/package_import_sort/package_import_sort.gs.ts @@ -62,13 +62,13 @@ export class descending { public Less(i: number, j: number): boolean { const d = this; - return $.arrayIndex(d.values!, i) > $.arrayIndex(d.values!, j) + return $.plainSliceIndex(d.values!, i) > $.plainSliceIndex(d.values!, j) } public Swap(i: number, j: number): void { const d = this; - let __goscriptAssign0_0: number = $.arrayIndex(d.values!, j) - let __goscriptAssign0_1: number = $.arrayIndex(d.values!, i) + let __goscriptAssign0_0: number = $.plainSliceIndex(d.values!, j) + let __goscriptAssign0_1: number = $.plainSliceIndex(d.values!, i) $.sliceElems(d.values!)[$.sliceSlot(d.values!, i)] = __goscriptAssign0_0 $.sliceElems(d.values!)[$.sliceSlot(d.values!, j)] = __goscriptAssign0_1 } @@ -92,12 +92,12 @@ export function byFreq_Len(s: byFreq): number { } export function byFreq_Less(s: byFreq, i: number, j: number): boolean { - return $.arrayIndex(s!, i) < $.arrayIndex(s!, j) + return $.plainSliceIndex(s!, i) < $.plainSliceIndex(s!, j) } export function byFreq_Swap(s: byFreq, i: number, j: number): void { - let __goscriptAssign1_0: number = $.arrayIndex(s!, j) - let __goscriptAssign1_1: number = $.arrayIndex(s!, i) + let __goscriptAssign1_0: number = $.plainSliceIndex(s!, j) + let __goscriptAssign1_1: number = $.plainSliceIndex(s!, i) $.sliceElems(s!)[$.sliceSlot(s!, i)] = __goscriptAssign1_0 $.sliceElems(s!)[$.sliceSlot(s!, j)] = __goscriptAssign1_1 } @@ -105,9 +105,9 @@ export function byFreq_Swap(s: byFreq, i: number, j: number): void { export async function main(): globalThis.Promise { // Test basic slice sorting let ints = $.arrayToSlice([3, 1, 4, 1, 5, 9]) - await $.println("Original ints:", $.arrayIndex(ints!, 0), $.arrayIndex(ints!, 1), $.arrayIndex(ints!, 2), $.arrayIndex(ints!, 3), $.arrayIndex(ints!, 4), $.arrayIndex(ints!, 5)) + await $.println("Original ints:", $.plainSliceIndex(ints!, 0), $.plainSliceIndex(ints!, 1), $.plainSliceIndex(ints!, 2), $.plainSliceIndex(ints!, 3), $.plainSliceIndex(ints!, 4), $.plainSliceIndex(ints!, 5)) sort2.Ints(ints) - await $.println("Sorted ints:", $.arrayIndex(ints!, 0), $.arrayIndex(ints!, 1), $.arrayIndex(ints!, 2), $.arrayIndex(ints!, 3), $.arrayIndex(ints!, 4), $.arrayIndex(ints!, 5)) + await $.println("Sorted ints:", $.plainSliceIndex(ints!, 0), $.plainSliceIndex(ints!, 1), $.plainSliceIndex(ints!, 2), $.plainSliceIndex(ints!, 3), $.plainSliceIndex(ints!, 4), $.plainSliceIndex(ints!, 5)) // Test if sorted let isSorted = sort2.IntsAreSorted(ints) @@ -115,9 +115,9 @@ export async function main(): globalThis.Promise { // Test string sorting let strings = $.arrayToSlice(["banana", "apple", "cherry"]) - await $.println("Original strings:", $.arrayIndex(strings!, 0), $.arrayIndex(strings!, 1), $.arrayIndex(strings!, 2)) + await $.println("Original strings:", $.plainSliceIndex(strings!, 0), $.plainSliceIndex(strings!, 1), $.plainSliceIndex(strings!, 2)) sort2.Strings(strings) - await $.println("Sorted strings:", $.arrayIndex(strings!, 0), $.arrayIndex(strings!, 1), $.arrayIndex(strings!, 2)) + await $.println("Sorted strings:", $.plainSliceIndex(strings!, 0), $.plainSliceIndex(strings!, 1), $.plainSliceIndex(strings!, 2)) // Test if strings are sorted let stringSorted = sort2.StringsAreSorted(strings) @@ -125,9 +125,9 @@ export async function main(): globalThis.Promise { // Test float64 sorting let floats = $.typedSliceOf(Float64Array, [3.14, 2.71, 1.41]) as $.Slice - await $.println("Original floats:", $.arrayIndex(floats!, 0), $.arrayIndex(floats!, 1), $.arrayIndex(floats!, 2)) + await $.println("Original floats:", $.typedSliceIndex(floats!, 0), $.typedSliceIndex(floats!, 1), $.typedSliceIndex(floats!, 2)) sort2.Float64s(floats) - await $.println("Sorted floats:", $.arrayIndex(floats!, 0), $.arrayIndex(floats!, 1), $.arrayIndex(floats!, 2)) + await $.println("Sorted floats:", $.typedSliceIndex(floats!, 0), $.typedSliceIndex(floats!, 1), $.typedSliceIndex(floats!, 2)) // Test if floats are sorted let floatSorted = sort2.Float64sAreSorted(floats) @@ -145,7 +145,7 @@ export async function main(): globalThis.Promise { // Test generic Search function let searchResult = sort2.Search($.sliceLen(ints), $.functionValue((i: number): boolean => { - return $.arrayIndex(ints!, i) >= 5 + return $.plainSliceIndex(ints!, i) >= 5 }, ({ kind: $.TypeKind.Function, params: [/* @__PURE__ */ $.basicType("int")], results: [/* @__PURE__ */ $.basicType("bool")] } as $.FunctionTypeInfo))) await $.println("First index where value >= 5:", searchResult) @@ -155,11 +155,11 @@ export async function main(): globalThis.Promise { await $.chanSend(gate, 0) } let asyncSearch = await sort2.Search($.sliceLen(ints), $.functionValue(async (i: number): globalThis.Promise => { - return ($.arrayIndex(ints!, i) + await $.chanRecv(gate)) >= 4 + return ($.plainSliceIndex(ints!, i) + await $.chanRecv(gate)) >= 4 }, ({ kind: $.TypeKind.Function, params: [/* @__PURE__ */ $.basicType("int")], results: [/* @__PURE__ */ $.basicType("bool")] } as $.FunctionTypeInfo))) await $.println("First index where value >= 4:", asyncSearch) let [findIndex, found] = sort2.Find($.sliceLen(ints), $.functionValue((i: number): number => { - return 5 - $.arrayIndex(ints!, i) + return 5 - $.plainSliceIndex(ints!, i) }, ({ kind: $.TypeKind.Function, params: [/* @__PURE__ */ $.basicType("int")], results: [/* @__PURE__ */ $.basicType("int")] } as $.FunctionTypeInfo))) await $.println("Find 5:", findIndex, found) await $.println("Sorted pair:", sortedPair(2, 1)) @@ -167,78 +167,78 @@ export async function main(): globalThis.Promise { // Test Slice function with custom comparator let testSlice = $.arrayToSlice([5, 2, 8, 1, 9]) slices.Sort(testSlice) - await $.println("Custom sorted slice:", $.arrayIndex(testSlice!, 0), $.arrayIndex(testSlice!, 1), $.arrayIndex(testSlice!, 2), $.arrayIndex(testSlice!, 3), $.arrayIndex(testSlice!, 4)) + await $.println("Custom sorted slice:", $.plainSliceIndex(testSlice!, 0), $.plainSliceIndex(testSlice!, 1), $.plainSliceIndex(testSlice!, 2), $.plainSliceIndex(testSlice!, 3), $.plainSliceIndex(testSlice!, 4)) let asyncSlice = $.arrayToSlice([2, 1]) let ready = $.makeChannel(1, false, "both") await $.chanSend(ready, true) await sort2.Slice($.interfaceValue(asyncSlice, "[]int", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("int"))), $.functionValue(async (i: number, j: number): globalThis.Promise => { await $.chanRecv(ready) - return $.arrayIndex(asyncSlice!, i) < $.arrayIndex(asyncSlice!, j) + return $.plainSliceIndex(asyncSlice!, i) < $.plainSliceIndex(asyncSlice!, j) }, ({ kind: $.TypeKind.Function, params: [/* @__PURE__ */ $.basicType("int"), /* @__PURE__ */ $.basicType("int")], results: [/* @__PURE__ */ $.basicType("bool")] } as $.FunctionTypeInfo))) - await $.println("Async sorted slice:", $.arrayIndex(asyncSlice!, 0), $.arrayIndex(asyncSlice!, 1)) + await $.println("Async sorted slice:", $.plainSliceIndex(asyncSlice!, 0), $.plainSliceIndex(asyncSlice!, 1)) // Test SliceIsSorted let isSliceSorted = sort2.SliceIsSorted($.interfaceValue(testSlice, "[]int", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("int"))), $.functionValue((i: number, j: number): boolean => { - return $.arrayIndex(testSlice!, i) < $.arrayIndex(testSlice!, j) + return $.plainSliceIndex(testSlice!, i) < $.plainSliceIndex(testSlice!, j) }, ({ kind: $.TypeKind.Function, params: [/* @__PURE__ */ $.basicType("int"), /* @__PURE__ */ $.basicType("int")], results: [/* @__PURE__ */ $.basicType("bool")] } as $.FunctionTypeInfo))) await $.println("Custom slice is sorted:", isSliceSorted) // Test custom sort.Interface values. let custom = new descending(true, $.arrayToSlice([1, 3, 2])) sort2.Sort($.structInterfaceValue((custom).clone(), "main.descending", "main.descending")!) - await $.println("Custom interface sort:", $.arrayIndex(custom.values!, 0), $.arrayIndex(custom.values!, 1), $.arrayIndex(custom.values!, 2)) + await $.println("Custom interface sort:", $.plainSliceIndex(custom.values!, 0), $.plainSliceIndex(custom.values!, 1), $.plainSliceIndex(custom.values!, 2)) let namedSlice = $.arrayToSlice([4, 1, 3]) let namedSliceSorter: $.VarRef = $.varRef(null! as byFreq) byFreq_sort(namedSliceSorter, namedSlice) - await $.println("Named slice pointer sort:", $.arrayIndex(namedSlice!, 0), $.arrayIndex(namedSlice!, 1), $.arrayIndex(namedSlice!, 2)) + await $.println("Named slice pointer sort:", $.plainSliceIndex(namedSlice!, 0), $.plainSliceIndex(namedSlice!, 1), $.plainSliceIndex(namedSlice!, 2)) // sort.Slice takes the slice as an any, such as from reflect let anySlice = $.arrayToSlice([3, 1, 2]) sort2.Slice($.markAsStructValue($.cloneStructValue(reflect.ValueOf($.interfaceValue(anySlice, "[]int", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("int")))))).Interface(), $.functionValue((i: number, j: number): boolean => { - return $.arrayIndex(anySlice!, i) < $.arrayIndex(anySlice!, j) + return $.plainSliceIndex(anySlice!, i) < $.plainSliceIndex(anySlice!, j) }, ({ kind: $.TypeKind.Function, params: [/* @__PURE__ */ $.basicType("int"), /* @__PURE__ */ $.basicType("int")], results: [/* @__PURE__ */ $.basicType("bool")] } as $.FunctionTypeInfo))) - await $.println("Any slice sort:", $.arrayIndex(anySlice!, 0), $.arrayIndex(anySlice!, 1), $.arrayIndex(anySlice!, 2)) + await $.println("Any slice sort:", $.plainSliceIndex(anySlice!, 0), $.plainSliceIndex(anySlice!, 1), $.plainSliceIndex(anySlice!, 2)) await $.println("Any slice sorted:", sort2.SliceIsSorted($.markAsStructValue($.cloneStructValue(reflect.ValueOf($.interfaceValue(anySlice, "[]int", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("int")))))).Interface(), $.functionValue((i: number, j: number): boolean => { - return $.arrayIndex(anySlice!, i) < $.arrayIndex(anySlice!, j) + return $.plainSliceIndex(anySlice!, i) < $.plainSliceIndex(anySlice!, j) }, ({ kind: $.TypeKind.Function, params: [/* @__PURE__ */ $.basicType("int"), /* @__PURE__ */ $.basicType("int")], results: [/* @__PURE__ */ $.basicType("bool")] } as $.FunctionTypeInfo)))) // a named slice type with methods passed as an any let names = ($.arrayToSlice(["c", "a", "b"]) as nameList) sort2.Slice($.namedValueInterfaceValue(names, "main.nameList", __goscriptStatic3(), __goscriptStatic4(), __goscriptStatic5()), $.functionValue((i: number, j: number): boolean => { - return $.stringCompare($.arrayIndex(names!, i), $.arrayIndex(names!, j)) < 0 + return $.stringCompare($.plainSliceIndex(names!, i), $.plainSliceIndex(names!, j)) < 0 }, ({ kind: $.TypeKind.Function, params: [/* @__PURE__ */ $.basicType("int"), /* @__PURE__ */ $.basicType("int")], results: [/* @__PURE__ */ $.basicType("bool")] } as $.FunctionTypeInfo))) - await $.println("Named slice any sort:", nameList_First(names), $.arrayIndex(names!, 1), $.arrayIndex(names!, 2)) + await $.println("Named slice any sort:", nameList_First(names), $.plainSliceIndex(names!, 1), $.plainSliceIndex(names!, 2)) // Test the named slice types and their methods. let wordSlice = $.arrayToSlice(["c", "a", "b"]) sort2.StringSlice_Sort((wordSlice as sort2.StringSlice)) - await $.println("StringSlice sort:", $.arrayIndex(wordSlice!, 0), $.arrayIndex(wordSlice!, 1), $.arrayIndex(wordSlice!, 2), sort2.StringSlice_Search((wordSlice as sort2.StringSlice), "b")) + await $.println("StringSlice sort:", $.plainSliceIndex(wordSlice!, 0), $.plainSliceIndex(wordSlice!, 1), $.plainSliceIndex(wordSlice!, 2), sort2.StringSlice_Search((wordSlice as sort2.StringSlice), "b")) let floatSlice = ($.typedSliceOf(Float64Array, [2.5, 1.5]) as $.Slice as sort2.Float64Slice) sort2.Float64Slice_Sort(floatSlice) await $.println("Float64Slice sort:", sort2.Float64Slice_Len(floatSlice), sort2.Float64Slice_Less(floatSlice, 0, 1), sort2.Float64Slice_Search(floatSlice, 2.5)) let sorter: sort2.Interface | null = $.namedValueInterfaceValue(($.arrayToSlice([3, 1, 2]) as sort2.IntSlice), "sort.IntSlice", __goscriptStatic6(), __goscriptStatic7(), __goscriptStatic8()) sort2.Sort($.pointerValueOrNil(sorter)!) let intSlice = ($.mustTypeAssert(sorter, /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("int"), "sort.IntSlice")) as sort2.IntSlice) - await $.println("IntSlice interface sort:", $.arrayIndex(intSlice!, 0), $.arrayIndex(intSlice!, 1), $.arrayIndex(intSlice!, 2), (__goscriptAwait = (sorter !== null && (sorter as any).__isVarRef !== true && ((sorter as any).__goValue === undefined || (sorter as any).__goType?.charCodeAt(0) !== 42) ? (sorter as Exclude) : $.pointerValue>(sorter)).Len(), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait)) + await $.println("IntSlice interface sort:", $.plainSliceIndex(intSlice!, 0), $.plainSliceIndex(intSlice!, 1), $.plainSliceIndex(intSlice!, 2), (__goscriptAwait = (sorter !== null && (sorter as any).__isVarRef !== true && ((sorter as any).__goValue === undefined || (sorter as any).__goType?.charCodeAt(0) !== 42) ? (sorter as Exclude) : $.pointerValue>(sorter)).Len(), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait)) sort2.Sort($.pointerValueOrNil(sort2.Reverse($.pointerValueOrNil($.namedValueInterfaceValue(intSlice, "sort.IntSlice", __goscriptStatic6(), __goscriptStatic7(), __goscriptStatic8()))!))!) sort2.IntSlice_Swap(intSlice, 0, 2) - await $.println("IntSlice reverse and swap:", $.arrayIndex(intSlice!, 0), $.arrayIndex(intSlice!, 1), $.arrayIndex(intSlice!, 2)) + await $.println("IntSlice reverse and swap:", $.plainSliceIndex(intSlice!, 0), $.plainSliceIndex(intSlice!, 1), $.plainSliceIndex(intSlice!, 2)) await $.println("test finished") } export function nameList_First(n: nameList): string { - return $.arrayIndex(n!, 0) + return $.plainSliceIndex(n!, 0) } export function sortedPair(a: number, b: number): number { let pair = $.arrayToSlice([a, b]) sort2.Slice($.interfaceValue(pair, "[]int", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("int"))), $.functionValue((i: number, j: number): boolean => { - return $.arrayIndex(pair!, i) < $.arrayIndex(pair!, j) + return $.plainSliceIndex(pair!, i) < $.plainSliceIndex(pair!, j) }, ({ kind: $.TypeKind.Function, params: [/* @__PURE__ */ $.basicType("int"), /* @__PURE__ */ $.basicType("int")], results: [/* @__PURE__ */ $.basicType("bool")] } as $.FunctionTypeInfo))) - return ($.arrayIndex(pair!, 0) * 10) + $.arrayIndex(pair!, 1) + return ($.plainSliceIndex(pair!, 0) * 10) + $.plainSliceIndex(pair!, 1) } var __goscriptStatic0$value: any diff --git a/tests/tests/package_import_starpc_srpc/package_import_starpc_srpc.gs.ts b/tests/tests/package_import_starpc_srpc/package_import_starpc_srpc.gs.ts index 317312108..29115134b 100644 --- a/tests/tests/package_import_starpc_srpc/package_import_starpc_srpc.gs.ts +++ b/tests/tests/package_import_starpc_srpc/package_import_starpc_srpc.gs.ts @@ -529,7 +529,7 @@ export async function closeHeldStreams(streams: $.Slice): gl return false } } - if (($.sliceLen((resp !== null && (resp as any).__isVarRef !== true && (resp as any).__goValue === undefined ? ((resp as any) as srpc.RawMessage).GetData() : srpc.RawMessage.prototype.GetData.call(resp))) != 1) || ($.uint($.arrayIndex((resp !== null && (resp as any).__isVarRef !== true && (resp as any).__goValue === undefined ? ((resp as any) as srpc.RawMessage).GetData() : srpc.RawMessage.prototype.GetData.call(resp))!, 0), 8) != 1)) { + if (($.sliceLen((resp !== null && (resp as any).__isVarRef !== true && (resp as any).__goValue === undefined ? ((resp as any) as srpc.RawMessage).GetData() : srpc.RawMessage.prototype.GetData.call(resp))) != 1) || ($.uint($.typedSliceIndex((resp !== null && (resp as any).__isVarRef !== true && (resp as any).__goValue === undefined ? ((resp as any) as srpc.RawMessage).GetData() : srpc.RawMessage.prototype.GetData.call(resp))!, 0), 8) != 1)) { await $.println("hold response mismatch") return false } @@ -620,7 +620,7 @@ export async function probeStream(ctx: context.Context | null, client: srpc.Clie if ($.sliceLen(data) != 1) { return [$.sliceLen(data), null] } - return [$.arrayIndex(data!, 0), null] + return [$.typedSliceIndex(data!, 0), null] } export async function newRoutedRpcStreamClient(ctx: context.Context | null, componentID: string, getter: ((ctx: context.Context | null, componentID: string, released: (() => void) | null) => [srpc.Invoker | null, (() => void) | null, $.GoError] | globalThis.Promise<[srpc.Invoker | null, (() => void) | null, $.GoError]>) | null, waitAck: boolean, results: $.Channel | null): globalThis.Promise { @@ -871,8 +871,8 @@ export async function exercisePushablePacketWriter(): globalThis.Promise($.markAsStructValue($.cloneStructValue($.arrayIndex(args!, 0))).Length(), undefined, "byte") - js.CopyBytesToGo(data, $.markAsStructValue($.cloneStructValue($.arrayIndex(args!, 0)))) + let data = $.makeSlice($.markAsStructValue($.cloneStructValue($.plainSliceIndex(args!, 0))).Length(), undefined, "byte") + js.CopyBytesToGo(data, $.markAsStructValue($.cloneStructValue($.plainSliceIndex(args!, 0)))) pushed = $.appendOne(pushed, data, $.appendZeros.nil) return null }, ({ kind: $.TypeKind.Function, params: ["js.Value", /* @__PURE__ */ $.sliceType("js.Value")], results: [{ kind: $.TypeKind.Interface, methods: [] }] } as $.FunctionTypeInfo))))) @@ -926,7 +926,7 @@ export async function exercisePushablePacketWriter(): globalThis.Promise) : $.pointerValue>(err)).Error(), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait)) return false @@ -943,7 +943,7 @@ export async function exercisePushablePacketWriter(): globalThis.Promise) : $.pointerValue>(err)).Error(), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait)) return false @@ -1001,7 +1001,7 @@ export async function main(): globalThis.Promise { await $.println("stream response length:", $.sliceLen(data)) return } - await $.println("stream bytes:", $.arrayIndex(data!, 0)) + await $.println("stream bytes:", $.typedSliceIndex(data!, 0)) let emptyResp = srpc.NewRawMessage(null, false) { let __goscriptShadow6 = (__goscriptAwait = (client !== null && (client as any).__isVarRef !== true && ((client as any).__goValue === undefined || (client as any).__goType?.charCodeAt(0) !== 42) ? (client as Exclude) : $.pointerValue>(client)).ExecCall(ctx, "svc", "empty", $.interfaceValue(srpc.NewRawMessage(null, false), "*srpc.RawMessage", /* @__PURE__ */ $.pointerType("srpc.RawMessage")), $.interfaceValue(emptyResp, "*srpc.RawMessage", /* @__PURE__ */ $.pointerType("srpc.RawMessage"))), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait) diff --git a/tests/tests/package_import_sync/package_import_sync.gs.ts b/tests/tests/package_import_sync/package_import_sync.gs.ts index 43e516370..b9c2b552b 100644 --- a/tests/tests/package_import_sync/package_import_sync.gs.ts +++ b/tests/tests/package_import_sync/package_import_sync.gs.ts @@ -148,7 +148,7 @@ export class queue { while ($.sliceLen((q$ as queue).items) == 0) { await (q$ as queue).Cond.Wait() } - let v = $.arrayIndex((q$ as queue).items!, 0); + let v = $.plainSliceIndex((q$ as queue).items!, 0); ;(q$ as queue).items = $.goSlice((q$ as queue).items, 1, undefined) return v } diff --git a/tests/tests/package_import_syscall_js/package_import_syscall_js.gs.ts b/tests/tests/package_import_syscall_js/package_import_syscall_js.gs.ts index 5fcf4329a..5788fdacf 100644 --- a/tests/tests/package_import_syscall_js/package_import_syscall_js.gs.ts +++ b/tests/tests/package_import_syscall_js/package_import_syscall_js.gs.ts @@ -16,7 +16,7 @@ export async function main(): globalThis.Promise { await $.println("length:", $.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(obj)).Get("nums"))).Length()) let cb = $.markAsStructValue($.cloneStructValue(js.FuncOf($.functionValue((_this: js.Value, args: $.Slice): any => { - return $.basicInterfaceValue($.markAsStructValue($.cloneStructValue($.arrayIndex(args!, 0))).Int() + 1, "int") + return $.basicInterfaceValue($.markAsStructValue($.cloneStructValue($.plainSliceIndex(args!, 0))).Int() + 1, "int") }, ({ kind: $.TypeKind.Function, params: ["js.Value", /* @__PURE__ */ $.sliceType("js.Value")], results: [{ kind: $.TypeKind.Interface, methods: [] }] } as $.FunctionTypeInfo))))) const __goscriptDeferCallee0 = $.functionValue(((__receiver) => () => __receiver.Release())($.markAsStructValue($.cloneStructValue(cb))), ({ kind: $.TypeKind.Function, params: [], results: [] } as $.FunctionTypeInfo), "syscall/js.Func.Release-fm") __defer.defer(() => { __goscriptDeferCallee0() }) @@ -74,7 +74,7 @@ export async function wrap(fn: ((_this: js.Value, args: $.Slice) => an export async function funcOfValues(): globalThis.Promise { await using __defer = new $.AsyncDisposableStack() let add = await wrap($.functionValue((_this: js.Value, args: $.Slice): any => { - return $.basicInterfaceValue($.markAsStructValue($.cloneStructValue($.arrayIndex(args!, 0))).Int() + $.markAsStructValue($.cloneStructValue($.arrayIndex(args!, 1))).Int(), "int") + return $.basicInterfaceValue($.markAsStructValue($.cloneStructValue($.plainSliceIndex(args!, 0))).Int() + $.markAsStructValue($.cloneStructValue($.plainSliceIndex(args!, 1))).Int(), "int") }, ({ kind: $.TypeKind.Function, params: ["js.Value", /* @__PURE__ */ $.sliceType("js.Value")], results: [{ kind: $.TypeKind.Interface, methods: [] }] } as $.FunctionTypeInfo))) const __goscriptDeferCallee1 = $.functionValue(((__receiver) => () => __receiver.Release())($.markAsStructValue($.cloneStructValue(add))), ({ kind: $.TypeKind.Function, params: [], results: [] } as $.FunctionTypeInfo), "syscall/js.Func.Release-fm") __defer.defer(() => { __goscriptDeferCallee1() }) @@ -98,7 +98,7 @@ export async function funcOfSuspend(): globalThis.Promise { using __defer = new $.DisposableStack() await mu.value.Lock() __defer.defer(() => { mu.value.Unlock() }) - await $.chanSend(done, "handled " + $.markAsStructValue($.cloneStructValue($.arrayIndex(args!, 0))).String()) + await $.chanSend(done, "handled " + $.markAsStructValue($.cloneStructValue($.plainSliceIndex(args!, 0))).String()) return null }, ({ kind: $.TypeKind.Function, params: ["js.Value", /* @__PURE__ */ $.sliceType("js.Value")], results: [{ kind: $.TypeKind.Interface, methods: [] }] } as $.FunctionTypeInfo))) const __goscriptDeferCallee3 = $.functionValue(((__receiver) => () => __receiver.Release())($.markAsStructValue($.cloneStructValue(handler))), ({ kind: $.TypeKind.Function, params: [], results: [] } as $.FunctionTypeInfo), "syscall/js.Func.Release-fm") diff --git a/tests/tests/package_import_typed_slices/package_import_typed_slices.gs.ts b/tests/tests/package_import_typed_slices/package_import_typed_slices.gs.ts index 60b525a30..1a70907d5 100644 --- a/tests/tests/package_import_typed_slices/package_import_typed_slices.gs.ts +++ b/tests/tests/package_import_typed_slices/package_import_typed_slices.gs.ts @@ -48,22 +48,22 @@ export async function main(): globalThis.Promise { let v = $.markAsStructValue($.cloneStructValue(reflect.ValueOf($.interfaceValue(f, "[]float32", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("float32")))))) await $.println("reflect len:", $.markAsStructValue($.cloneStructValue(v)).Len(), $.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(v)).Index(1))).Float(), (__goscriptAwait = $.pointerValue>($.markAsStructValue($.cloneStructValue(v)).Type()).String(), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait)) $.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(v)).Index(0))).SetFloat(0.1) - await $.println("reflect set:", $.arrayIndex(f!, 0) == 0.10000000149011612) + await $.println("reflect set:", $.typedSliceIndex(f!, 0) == 0.10000000149011612) let sv = $.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(v)).Slice(1, 3))) $.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(sv)).Index(0))).SetFloat(9) - await $.println("reflect slice:", $.arrayIndex(f!, 1), $.markAsStructValue($.cloneStructValue(sv)).Len()) + await $.println("reflect slice:", $.typedSliceIndex(f!, 1), $.markAsStructValue($.cloneStructValue(sv)).Len()) let made = $.markAsStructValue($.cloneStructValue(reflect.MakeSlice($.pointerValueOrNil(reflect.TypeOf($.interfaceValue(null, "[]int32", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("int32")))))!, 2, 4))) $.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(made)).Index(1))).SetInt(2147483648n) made = $.assignStruct(made, reflect.Append($.markAsStructValue($.cloneStructValue(made)), $.markAsStructValue($.cloneStructValue(reflect.ValueOf($.basicInterfaceValue(-7, "int32")))))) made = $.assignStruct(made, reflect.AppendSlice($.markAsStructValue($.cloneStructValue(made)), $.markAsStructValue($.cloneStructValue(reflect.ValueOf($.interfaceValue($.typedSliceOf(Int32Array, [8, 9]) as $.Slice, "[]int32", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("int32")))))))) let ints = $.mustTypeAssert<$.Slice>($.markAsStructValue($.cloneStructValue(made)).Interface(), /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("int32"))) - await $.println("reflect make:", $.sliceLen(ints), $.arrayIndex(ints!, 1), $.arrayIndex(ints!, 2), $.arrayIndex(ints!, 4)) + await $.println("reflect make:", $.sliceLen(ints), $.typedSliceIndex(ints!, 1), $.typedSliceIndex(ints!, 2), $.typedSliceIndex(ints!, 4)) reflect.Copy($.markAsStructValue($.cloneStructValue(reflect.ValueOf($.interfaceValue(ints, "[]int32", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("int32")))))), $.markAsStructValue($.cloneStructValue(reflect.ValueOf($.interfaceValue($.typedSliceOf(Int32Array, [5]) as $.Slice, "[]int32", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("int32"))))))) - await $.println("reflect copy:", $.arrayIndex(ints!, 0)) + await $.println("reflect copy:", $.typedSliceIndex(ints!, 0)) await $.println("deep equal:", reflect.DeepEqual($.interfaceValue(f, "[]float32", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("float32"))), $.interfaceValue($.typedSliceOf(Float32Array, [0.10000000149011612, 9, 3.5]) as $.Slice, "[]float32", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("float32")))), reflect.DeepEqual($.interfaceValue($.typedSliceOf(Uint16Array, [1, 2]) as $.Slice, "[]uint16", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("uint16"))), $.interfaceValue($.typedSliceOf(Uint16Array, [1, 3]) as $.Slice, "[]uint16", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("uint16"))))) let swap: ((i: number, j: number) => void) | null = reflect.Swapper($.interfaceValue(ints, "[]int32", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("int32")))) swap!(0, 4) - await $.println("swapper:", $.arrayIndex(ints!, 0), $.arrayIndex(ints!, 4)) + await $.println("swapper:", $.typedSliceIndex(ints!, 0), $.typedSliceIndex(ints!, 4)) // encoding/binary round trips typed slices in both byte orders. let buf = $.varRef($.markAsStructValue(new bytes.Buffer())) @@ -94,33 +94,33 @@ export async function main(): globalThis.Promise { await $.println("read error:", (__goscriptAwait = (err !== null && (err as any).__isVarRef !== true && ((err as any).__goValue === undefined || (err as any).__goType?.charCodeAt(0) !== 42) ? (err as Exclude<$.GoError, null>) : $.pointerValue>(err)).Error(), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait)) } } - await $.println("binary read:", $.arrayIndex(back!, 0), $.arrayIndex(back!, 1), math.IsInf($.arrayIndex(back!, 2), 1), $.arrayIndex(backU!, 0), $.arrayIndex(backU!, 1)) + await $.println("binary read:", $.typedSliceIndex(back!, 0), $.typedSliceIndex(back!, 1), math.IsInf($.typedSliceIndex(back!, 2), 1), $.typedSliceIndex(backU!, 0), $.typedSliceIndex(backU!, 1)) let window = $.makeSlice(4, undefined, "int32") let __goscriptTuple0: any = binary.Append(null, $.structInterfaceValue($.markAsStructValue($.cloneStructValue($.pointerValue(binary.LittleEndian))), "binary.littleEndian", __goscriptStatic1())!, $.interfaceValue($.typedSliceOf(Int32Array, [-1, 2]) as $.Slice, "[]int32", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("int32")))) let enc: $.Slice = __goscriptTuple0[0] await binary.Read($.pointerValueOrNil($.interfaceValue(bytes.NewReader(enc), "*bytes.Reader", __goscriptStatic3()))!, $.structInterfaceValue($.markAsStructValue($.cloneStructValue($.pointerValue(binary.LittleEndian))), "binary.littleEndian", __goscriptStatic1())!, $.interfaceValue($.goSlice(window, 1, 3), "[]int32", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("int32")))) - await $.println("binary window:", $.arrayIndex(window!, 0), $.arrayIndex(window!, 1), $.arrayIndex(window!, 2), $.arrayIndex(window!, 3), $.sliceLen(enc)) + await $.println("binary window:", $.typedSliceIndex(window!, 0), $.typedSliceIndex(window!, 1), $.typedSliceIndex(window!, 2), $.typedSliceIndex(window!, 3), $.sliceLen(enc)) // sort and slices sort typed slices in place, also through windows. let fs = $.typedSliceOf(Float64Array, [3, math.NaN(), -1, 2]) as $.Slice sort.Float64s(fs) - await $.println("sort float64s:", math.IsNaN($.arrayIndex(fs!, 0)), $.arrayIndex(fs!, 1), $.arrayIndex(fs!, 2), $.arrayIndex(fs!, 3)) + await $.println("sort float64s:", math.IsNaN($.typedSliceIndex(fs!, 0)), $.typedSliceIndex(fs!, 1), $.typedSliceIndex(fs!, 2), $.typedSliceIndex(fs!, 3)) let us = $.typedSliceOf(Uint32Array, [5, 1, 4, 2, 3]) as $.Slice slices.Sort($.goSlice(us, 1, 4)) - await $.println("slices sort window:", $.arrayIndex(us!, 0), $.arrayIndex(us!, 1), $.arrayIndex(us!, 2), $.arrayIndex(us!, 3), $.arrayIndex(us!, 4)) + await $.println("slices sort window:", $.typedSliceIndex(us!, 0), $.typedSliceIndex(us!, 1), $.typedSliceIndex(us!, 2), $.typedSliceIndex(us!, 3), $.typedSliceIndex(us!, 4)) let _is = $.typedSliceOf(Int16Array, [3, -1, 2]) as $.Slice sort.Slice($.interfaceValue(_is, "[]int16", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("int16"))), $.functionValue((i: number, j: number): boolean => { - return $.arrayIndex(_is!, i) < $.arrayIndex(_is!, j) + return $.typedSliceIndex(_is!, i) < $.typedSliceIndex(_is!, j) }, ({ kind: $.TypeKind.Function, params: [/* @__PURE__ */ $.basicType("int"), /* @__PURE__ */ $.basicType("int")], results: [/* @__PURE__ */ $.basicType("bool")] } as $.FunctionTypeInfo))) - await $.println("sort slice:", $.arrayIndex(_is!, 0), $.arrayIndex(_is!, 1), $.arrayIndex(_is!, 2)) + await $.println("sort slice:", $.typedSliceIndex(_is!, 0), $.typedSliceIndex(_is!, 1), $.typedSliceIndex(_is!, 2)) let cl: $.Slice = (slices.Clone(us) as $.Slice) $.sliceElems(cl!)[$.sliceSlot(cl!, 0)] = 50 - await $.println("clone:", $.arrayIndex(us!, 0), $.arrayIndex(cl!, 0), $.sliceLen(cl), slices.Index(cl, 4), slices.Contains(cl, 3), slices.Max(cl)) + await $.println("clone:", $.typedSliceIndex(us!, 0), $.typedSliceIndex(cl!, 0), $.sliceLen(cl), slices.Index(cl, 4), slices.Contains(cl, 3), slices.Max(cl)) cl = (slices.Insert(cl, 1, 7, 8) as $.Slice) cl = (slices.Delete(cl, 0, 1, () => (0 as number)) as $.Slice) - await $.println("insert delete:", $.sliceLen(cl), $.arrayIndex(cl!, 0), $.arrayIndex(cl!, 1), $.arrayIndex(cl!, 2)) + await $.println("insert delete:", $.sliceLen(cl), $.typedSliceIndex(cl!, 0), $.typedSliceIndex(cl!, 1), $.typedSliceIndex(cl!, 2)) slices.Reverse(cl) - await $.println("reverse:", $.arrayIndex(cl!, 0), slices.Equal(cl, $.typedSliceOf(Uint32Array, [3, 4, 2, 8, 7]) as $.Slice)) + await $.println("reverse:", $.typedSliceIndex(cl!, 0), slices.Equal(cl, $.typedSliceOf(Uint32Array, [3, 4, 2, 8, 7]) as $.Slice)) // fmt formats typed slices element by element. await $.println("fmt:", (fmt.Sprint($.interfaceValue(f, "[]float32", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("float32"))), $.interfaceValue($.typedSliceOf(Int8Array, [-1, 2]) as $.Slice, "[]int8", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("int8"))), $.interfaceValue($.typedSliceOf(Uint32Array, [7]) as $.Slice, "[]uint32", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("uint32"))), $.interfaceValue($.typedSliceOf(Float64Array, [0.5, 2]) as $.Slice, "[]float64", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("float64")))) as string)) @@ -134,12 +134,12 @@ export async function main(): globalThis.Promise { await $.println("json:", $.bytesToString(data), err == null) let m2: $.VarRef = $.varRef(new mesh(true)) err = (json.Unmarshal(data, $.interfaceValue(m2, "*main.mesh", /* @__PURE__ */ $.pointerType("main.mesh"))) as $.GoError) - await $.println("json back:", err == null, $.sliceLen(m2.value.Pos), $.arrayIndex(m2.value.Pos!, 0), $.arrayIndex(m2.value.Index!, 2)) + await $.println("json back:", err == null, $.sliceLen(m2.value.Pos), $.typedSliceIndex(m2.value.Pos!, 0), $.typedSliceIndex(m2.value.Index!, 2)) let fs32: $.VarRef<$.Slice> = $.varRef(null! as $.Slice) err = (json.Unmarshal(new Uint8Array([91, 48, 46, 49, 44, 32, 51, 93]), $.interfaceValue(fs32, "*[]float32", /* @__PURE__ */ $.pointerType(/* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("float32"))))) as $.GoError) - await $.println("json float32:", err == null, $.arrayIndex(fs32.value!, 0) == 0.10000000149011612, $.arrayIndex(fs32.value!, 1)) + await $.println("json float32:", err == null, $.typedSliceIndex(fs32.value!, 0) == 0.10000000149011612, $.typedSliceIndex(fs32.value!, 1)) m2.value.Pos = $.appendOne(m2.value.Pos, 4, $.typedSliceHints.float32) - await $.println("json append:", $.sliceLen(m2.value.Pos), $.arrayIndex(m2.value.Pos!, 3), reflect.DeepEqual($.interfaceValue(m.Index, "[]uint32", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("uint32"))), $.interfaceValue(m2.value.Index, "[]uint32", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("uint32"))))) + await $.println("json append:", $.sliceLen(m2.value.Pos), $.typedSliceIndex(m2.value.Pos!, 3), reflect.DeepEqual($.interfaceValue(m.Index, "[]uint32", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("uint32"))), $.interfaceValue(m2.value.Index, "[]uint32", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("uint32"))))) // A slice grown by appends has spare capacity, which leaves it a window // on its backing array, and is used as any other. @@ -154,10 +154,10 @@ export async function main(): globalThis.Promise { await $.println("grown:", $.sliceLen(grown), $.cap(grown) > $.sliceLen(grown), (fmt.Sprint($.interfaceValue(grown, "[]float32", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("float32")))) as string), $.bytesToString(gdata), gbuf.value.Len()) await $.println("grown reflect:", reflect.DeepEqual($.interfaceValue(grown, "[]float32", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("float32"))), $.interfaceValue($.typedSliceOf(Float32Array, [0.5, 1.5, 2.5, 3.5, 4.5]) as $.Slice, "[]float32", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("float32")))), $.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(reflect.ValueOf($.interfaceValue(grown, "[]float32", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("float32")))))).Index(4))).Float()) sort.Slice($.interfaceValue(grown, "[]float32", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("float32"))), $.functionValue((i: number, j: number): boolean => { - return $.arrayIndex(grown!, i) > $.arrayIndex(grown!, j) + return $.typedSliceIndex(grown!, i) > $.typedSliceIndex(grown!, j) }, ({ kind: $.TypeKind.Function, params: [/* @__PURE__ */ $.basicType("int"), /* @__PURE__ */ $.basicType("int")], results: [/* @__PURE__ */ $.basicType("bool")] } as $.FunctionTypeInfo))) let gc = (slices.Clone(grown) as $.Slice) - await $.println("grown sort:", $.arrayIndex(grown!, 0), $.arrayIndex(grown!, 4), $.arrayIndex(gc!, 0), $.sliceLen(gc)) + await $.println("grown sort:", $.typedSliceIndex(grown!, 0), $.typedSliceIndex(grown!, 4), $.typedSliceIndex(gc!, 0), $.sliceLen(gc)) let anyGrown: any = $.interfaceValue($.goSlice(grown, 1, undefined), "[]float32", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("float32"))) let [, isF] = $.typeAssertTuple<$.Slice>(anyGrown, /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("float32"))) let [, isU] = $.typeAssertTuple<$.Slice>(anyGrown, /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("uint32"))) diff --git a/tests/tests/package_import_x509_create_certificate/package_import_x509_create_certificate.gs.ts b/tests/tests/package_import_x509_create_certificate/package_import_x509_create_certificate.gs.ts index afe0eeee1..ac21761c5 100644 --- a/tests/tests/package_import_x509_create_certificate/package_import_x509_create_certificate.gs.ts +++ b/tests/tests/package_import_x509_create_certificate/package_import_x509_create_certificate.gs.ts @@ -101,7 +101,7 @@ export async function main(): globalThis.Promise { let decoded: $.VarRef = $.varRef(new signedKey(true)) let __goscriptTuple4: any = asn1.Unmarshal(keyExt.Value, $.interfaceValue(decoded, "*main.signedKey", /* @__PURE__ */ $.pointerType("main.signedKey"))) err = __goscriptTuple4[1] - await $.println("extension unmarshal", err == null, $.sliceLen(decoded.value.PubKey), $.arrayIndex(decoded.value.PubKey!, 0), $.arrayIndex(decoded.value.PubKey!, 5), $.sliceLen(decoded.value.Signature)) + await $.println("extension unmarshal", err == null, $.sliceLen(decoded.value.PubKey), $.typedSliceIndex(decoded.value.PubKey!, 0), $.typedSliceIndex(decoded.value.PubKey!, 5), $.sliceLen(decoded.value.Signature)) let pool = x509.NewCertPool() await (pool !== null && (pool as any).__isVarRef !== true && (pool as any).__goValue === undefined ? ((pool as any) as x509.CertPool).AddCert(cert) : x509.CertPool.prototype.AddCert.call(pool, cert)) let __goscriptTuple5: any = await (cert !== null && (cert as any).__isVarRef !== true && (cert as any).__goValue === undefined ? ((cert as any) as x509.Certificate).Verify(new x509.VerifyOptions(true, undefined, undefined, pool)) : x509.Certificate.prototype.Verify.call(cert, new x509.VerifyOptions(true, undefined, undefined, pool))) @@ -138,7 +138,7 @@ export async function main(): globalThis.Promise { await $.println("serial", big.Int.prototype.String.call($.pointerValue((cert$ as x509.Certificate).SerialNumber))) await $.println("common name", (cert$ as x509.Certificate).Subject.CommonName) - await $.println("organization", $.arrayIndex((cert$ as x509.Certificate).Subject.Organization!, 0)) + await $.println("organization", $.plainSliceIndex((cert$ as x509.Certificate).Subject.Organization!, 0)) await $.println("signature algorithm", x509.SignatureAlgorithm_String((cert$ as x509.Certificate).SignatureAlgorithm)) await $.println("public key algorithm", x509.PublicKeyAlgorithm_String((cert$ as x509.Certificate).PublicKeyAlgorithm)) await $.println("public key equal", ed25519.PublicKey_Equal($.mustTypeAssert((cert$ as x509.Certificate).PublicKey, /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("uint8"), "ed25519.PublicKey")), $.namedValueInterfaceValue(pub, "ed25519.PublicKey", __goscriptStatic0(), __goscriptStatic1(), __goscriptStatic2()))) diff --git a/tests/tests/package_import_x509_tls_path/package_import_x509_tls_path.gs.ts b/tests/tests/package_import_x509_tls_path/package_import_x509_tls_path.gs.ts index d3ae7bccf..00f56c1e2 100644 --- a/tests/tests/package_import_x509_tls_path/package_import_x509_tls_path.gs.ts +++ b/tests/tests/package_import_x509_tls_path/package_import_x509_tls_path.gs.ts @@ -44,11 +44,11 @@ export async function main(): globalThis.Promise { let config = new tls.Config(false, undefined, undefined, $.arrayToSlice([certificate]), undefined, undefined, undefined, undefined, undefined, undefined, undefined, $.arrayToSlice(["bifrost"]), undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, 771) let config$: tls.Config = config == null ? $.pointerTarget(config) : (config as any).__isVarRef === true ? (config as any).value : (config as any).__goValue === undefined ? (config as any) : $.pointerTarget(config) await $.println("certificate count", $.sliceLen((config$ as tls.Config).Certificates)) - await $.println("chain count", $.sliceLen($.arrayIndex((config$ as tls.Config).Certificates!, 0).Certificate)) - await $.println("leaf common name", $.pointerValue($.arrayIndex((config$ as tls.Config).Certificates!, 0).Leaf).Subject.CommonName) - await $.println("private key signer", ed25519.PublicKey_Equal($.mustTypeAssert(ed25519.PrivateKey_Public($.mustTypeAssert($.arrayIndex((config$ as tls.Config).Certificates!, 0).PrivateKey, /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("uint8"), "ed25519.PrivateKey"))), /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("uint8"), "ed25519.PublicKey")), $.namedValueInterfaceValue(pub, "ed25519.PublicKey", __goscriptStatic0(), __goscriptStatic1(), __goscriptStatic2()))) + await $.println("chain count", $.sliceLen($.plainSliceIndex((config$ as tls.Config).Certificates!, 0).Certificate)) + await $.println("leaf common name", $.pointerValue($.plainSliceIndex((config$ as tls.Config).Certificates!, 0).Leaf).Subject.CommonName) + await $.println("private key signer", ed25519.PublicKey_Equal($.mustTypeAssert(ed25519.PrivateKey_Public($.mustTypeAssert($.plainSliceIndex((config$ as tls.Config).Certificates!, 0).PrivateKey, /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("uint8"), "ed25519.PrivateKey"))), /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("uint8"), "ed25519.PublicKey")), $.namedValueInterfaceValue(pub, "ed25519.PublicKey", __goscriptStatic0(), __goscriptStatic1(), __goscriptStatic2()))) await $.println("min version", (config$ as tls.Config).MinVersion) - await $.println("next proto", $.arrayIndex((config$ as tls.Config).NextProtos!, 0)) + await $.println("next proto", $.plainSliceIndex((config$ as tls.Config).NextProtos!, 0)) let cache = tls.NewLRUClientSessionCache(2) let session = new tls.ClientSessionState() diff --git a/tests/tests/package_table_constant_slice/package_table_constant_slice.gs.ts b/tests/tests/package_table_constant_slice/package_table_constant_slice.gs.ts index b76e91418..8cd459721 100644 --- a/tests/tests/package_table_constant_slice/package_table_constant_slice.gs.ts +++ b/tests/tests/package_table_constant_slice/package_table_constant_slice.gs.ts @@ -23,7 +23,7 @@ export function __goscript_set_nibbles(__goscriptValue: Uint8Array): void { } export function bits4(a: $.Slice, i: number): number { - return $.uint(($.uintShr($.arrayIndex(a!, $.intShr(i, 1)), ($.intShl((i & 1), 2)), 8)) & 0b1111, 8) + return $.uint(($.uintShr($.typedSliceIndex(a!, $.intShr(i, 1)), ($.intShl((i & 1), 2)), 8)) & 0b1111, 8) } export function lookup(u: number): number { @@ -46,7 +46,7 @@ export function sum(a: $.Slice): number { } export function first(a: $.Slice): number { - return $.arrayIndex(a!, 0) + sum($.goSlice(a, 1, undefined)) + return $.plainSliceIndex(a!, 0) + sum($.goSlice(a, 1, undefined)) } export let word: $.Slice = new Uint8Array([103, 111, 115, 99, 114, 105, 112, 116, 32, 116, 97, 98, 108, 101, 115]) @@ -138,11 +138,11 @@ export async function main(): globalThis.Promise { // deferred. await $.println("small:", sum(__goscriptStatic8()), sum(__goscriptStatic9()), sum(__goscriptStatic10()), sum(__goscriptStatic11())) await $.println("small len/cap:", $.sliceLen(__goscriptStatic12()), $.cap(__goscriptStatic12()), $.sliceLen(__goscriptStatic13()), $.cap(__goscriptStatic13())) - await $.println("small first:", first(__goscriptStatic14()), $.arrayIndex(__goscriptStatic15()!, 2)) + await $.println("small first:", first(__goscriptStatic14()), $.plainSliceIndex(__goscriptStatic15()!, 2)) await $.println("word:", $.bytesToString(__goscriptStatic16()), $.bytesToString(__goscriptStatic17())) // A table read during initialization. - await $.println("derived:", derived, sum(__goscriptStatic4()), $.arrayIndex(__goscriptStatic18()!, 2)) + await $.println("derived:", derived, sum(__goscriptStatic4()), $.plainSliceIndex(__goscriptStatic18()!, 2)) // A reassigned table gives the new elements. await $.println("replaced before:", sum($.goSlice(replaced, 1, undefined))) diff --git a/tests/tests/package_var_deferred_program/package_var_deferred_program.gs.ts b/tests/tests/package_var_deferred_program/package_var_deferred_program.gs.ts index 83a9bf119..62e88fc98 100644 --- a/tests/tests/package_var_deferred_program/package_var_deferred_program.gs.ts +++ b/tests/tests/package_var_deferred_program/package_var_deferred_program.gs.ts @@ -31,18 +31,18 @@ export function __goscript_set_labeled(__goscriptValue: $.Slice): void { export async function main(): globalThis.Promise { // A deferred list reads the tables of its codecs. - await $.println("all", $.sliceLen(tables.__goscript_get_All()), $.pointerValue($.arrayIndex(tables.__goscript_get_All()!, 0)).Name, $.pointerValue($.arrayIndex(tables.__goscript_get_All()!, 1)).Name, ($.pointerValue($.arrayIndex(tables.__goscript_get_All()!, 1)).Decode)[255]) - await $.println("named", $.pointerValue($.mustTypeAssert | null>($.arrayIndex(tables.__goscript_get_Named()!, 0), /* @__PURE__ */ $.pointerType("tables.Codec"))).Name, $.mustTypeAssert($.arrayIndex(tables.__goscript_get_Named()!, 1), /* @__PURE__ */ $.basicType("string"))) - await $.println("labeled", $.pointerValue($.mustTypeAssert | null>($.arrayIndex(__goscript_get_labeled()!, 0), /* @__PURE__ */ $.pointerType("tables.Codec"))).Name, $.mustTypeAssert($.arrayIndex(__goscript_get_labeled()!, 1), /* @__PURE__ */ $.basicType("string"))) + await $.println("all", $.sliceLen(tables.__goscript_get_All()), $.pointerValue($.plainSliceIndex(tables.__goscript_get_All()!, 0)).Name, $.pointerValue($.plainSliceIndex(tables.__goscript_get_All()!, 1)).Name, ($.pointerValue($.plainSliceIndex(tables.__goscript_get_All()!, 1)).Decode)[255]) + await $.println("named", $.pointerValue($.mustTypeAssert | null>($.plainSliceIndex(tables.__goscript_get_Named()!, 0), /* @__PURE__ */ $.pointerType("tables.Codec"))).Name, $.mustTypeAssert($.plainSliceIndex(tables.__goscript_get_Named()!, 1), /* @__PURE__ */ $.basicType("string"))) + await $.println("labeled", $.pointerValue($.mustTypeAssert | null>($.plainSliceIndex(__goscript_get_labeled()!, 0), /* @__PURE__ */ $.pointerType("tables.Codec"))).Name, $.mustTypeAssert($.plainSliceIndex(__goscript_get_labeled()!, 1), /* @__PURE__ */ $.basicType("string"))) // An assignment after initialization does not change a list built at // initialization. tables.__goscript_set_CodecC(other) - await $.println("withc", $.pointerValue($.arrayIndex(tables.WithC!, 1)).Name, $.pointerValue(tables.__goscript_get_CodecC()).Name) + await $.println("withc", $.pointerValue($.plainSliceIndex(tables.WithC!, 1)).Name, $.pointerValue(tables.__goscript_get_CodecC()).Name) // Nor does a change through a pointer method. $.pointerValue($.pointerValue(tables.Count)).Inc() - await $.println("withcount", $.mustTypeAssert($.arrayIndex(tables.WithCount!, 1), "tables.Counter").N, $.pointerValue(tables.Count).N) + await $.println("withcount", $.mustTypeAssert($.plainSliceIndex(tables.WithCount!, 1), "tables.Counter").N, $.pointerValue(tables.Count).N) // A list that reads a map holds the entry before init changes it. await $.println("kind", tables.Kind) diff --git a/tests/tests/package_var_deferred_table/package_var_deferred_table.gs.ts b/tests/tests/package_var_deferred_table/package_var_deferred_table.gs.ts index a9eb3bbcd..ef80d4628 100644 --- a/tests/tests/package_var_deferred_table/package_var_deferred_table.gs.ts +++ b/tests/tests/package_var_deferred_table/package_var_deferred_table.gs.ts @@ -138,18 +138,18 @@ function __goscriptInit0(): void { export async function main(): globalThis.Promise { // Values of the tables are their literals. - await $.println("numbers", $.sliceLen(__goscript_get_Numbers()), $.arrayIndex(__goscript_get_Numbers()!, 0), $.arrayIndex(__goscript_get_Numbers()!, 299)) - await $.println("symbols", $.sliceLen(__goscript_get_Symbols()), $.pointerValue($.arrayIndex(__goscript_get_Symbols()!, 5)).Name, $.pointerValue($.arrayIndex(__goscript_get_Symbols()!, 259)).Kind) + await $.println("numbers", $.sliceLen(__goscript_get_Numbers()), $.plainSliceIndex(__goscript_get_Numbers()!, 0), $.plainSliceIndex(__goscript_get_Numbers()!, 299)) + await $.println("symbols", $.sliceLen(__goscript_get_Symbols()), $.pointerValue($.plainSliceIndex(__goscript_get_Symbols()!, 5)).Name, $.pointerValue($.plainSliceIndex(__goscript_get_Symbols()!, 259)).Kind) await $.println("index", $.len(__goscript_get_Index()), $.mapGet(__goscript_get_Index(), "k7", 0)[0], $.mapGet(__goscript_get_Index(), "k259", 0)[0]) // Reads see the same pointers each time. - let p = $.arrayIndex(__goscript_get_Symbols()!, 3) + let p = $.plainSliceIndex(__goscript_get_Symbols()!, 3) $.pointerValue(p).Kind = 42 - await $.println("same", $.pointerEqual($.arrayIndex(__goscript_get_Symbols()!, 3), p), $.pointerValue($.arrayIndex(__goscript_get_Symbols()!, 3)).Kind) + await $.println("same", $.pointerEqual($.plainSliceIndex(__goscript_get_Symbols()!, 3), p), $.pointerValue($.plainSliceIndex(__goscript_get_Symbols()!, 3)).Kind) // Writes before and after the first read are kept. - await $.println("replaced", $.sliceLen(__goscript_get_Replaced()), $.arrayIndex(__goscript_get_Replaced()!, 2)) - await $.println("changed", $.arrayIndex(__goscript_get_Changed()!, 0), $.arrayIndex(__goscript_get_Changed()!, 1)) + await $.println("replaced", $.sliceLen(__goscript_get_Replaced()), $.plainSliceIndex(__goscript_get_Replaced()!, 2)) + await $.println("changed", $.plainSliceIndex(__goscript_get_Changed()!, 0), $.plainSliceIndex(__goscript_get_Changed()!, 1)) } __goscriptInit0() diff --git a/tests/tests/pointer_composite_literal_untyped/pointer_composite_literal_untyped.gs.ts b/tests/tests/pointer_composite_literal_untyped/pointer_composite_literal_untyped.gs.ts index 1b6821d5c..cbf91d047 100644 --- a/tests/tests/pointer_composite_literal_untyped/pointer_composite_literal_untyped.gs.ts +++ b/tests/tests/pointer_composite_literal_untyped/pointer_composite_literal_untyped.gs.ts @@ -11,17 +11,17 @@ export async function main(): globalThis.Promise { // An elided element of pointer type takes the address of its literal. let data = $.arrayToSlice<$.VarRef<{"x": number}> | null>([$.varRef($.anonymousStructValue({x: 42}, { kind: $.TypeKind.Struct, methods: [], fields: [/* @__PURE__ */ $.structField("x", /* @__PURE__ */ $.basicType("int"), [0], 0, false, { pkgPath: "github.com/s4wave/goscript/tests/tests/pointer_composite_literal_untyped" })] })), $.varRef($.anonymousStructValue({x: 43}, { kind: $.TypeKind.Struct, methods: [], fields: [/* @__PURE__ */ $.structField("x", /* @__PURE__ */ $.basicType("int"), [0], 0, false, { pkgPath: "github.com/s4wave/goscript/tests/tests/pointer_composite_literal_untyped" })] }))]) - $.pointerValue<{"x": number}>($.arrayIndex(data!, 1)).x++ - await $.println("First element x:", $.pointerValue<{"x": number}>($.arrayIndex(data!, 0)).x) - await $.println("Second element x:", $.pointerValue<{"x": number}>($.arrayIndex(data!, 1)).x) + $.pointerValue<{"x": number}>($.plainSliceIndex(data!, 1)).x++ + await $.println("First element x:", $.pointerValue<{"x": number}>($.plainSliceIndex(data!, 0)).x) + await $.println("Second element x:", $.pointerValue<{"x": number}>($.plainSliceIndex(data!, 1)).x) // The elided literal may be an array or a map too. let pairs = $.arrayToSlice<$.VarRef | null>([$.varRef($.arrayValue([1, 2]))]) - $.pointerValue($.arrayIndex(pairs!, 0))[1] = 5 - await $.println("Pair:", $.arrayIndex($.pointerValue($.arrayIndex(pairs!, 0)), 0), $.arrayIndex($.pointerValue($.arrayIndex(pairs!, 0)), 1)) + $.pointerValue($.plainSliceIndex(pairs!, 0))[1] = 5 + await $.println("Pair:", $.arrayIndex($.pointerValue($.plainSliceIndex(pairs!, 0)), 0), $.arrayIndex($.pointerValue($.plainSliceIndex(pairs!, 0)), 1)) let names = $.arrayToSlice<$.VarRef | null> | null>([$.varRef($.makeMap([["a", 1]]))]) - $.mapSet(($.pointerValue | null>($.arrayIndex(names!, 0))), "b", 2) - await $.println("Names:", $.len($.pointerValue | null>($.arrayIndex(names!, 0)))) + $.mapSet(($.pointerValue | null>($.plainSliceIndex(names!, 0))), "b", 2) + await $.println("Names:", $.len($.pointerValue | null>($.plainSliceIndex(names!, 0)))) } if ($.isMainScript(import.meta)) { diff --git a/tests/tests/pointer_element_identity/pointer_element_identity.gs.ts b/tests/tests/pointer_element_identity/pointer_element_identity.gs.ts index fad4ebf1f..c3c1593a9 100644 --- a/tests/tests/pointer_element_identity/pointer_element_identity.gs.ts +++ b/tests/tests/pointer_element_identity/pointer_element_identity.gs.ts @@ -173,9 +173,9 @@ export async function main(): globalThis.Promise { await $.println("struct direct", $.indexAddress(_in!, 0) == $.indexAddress(_in!, 0), $.pointerEqual(p, $.indexRef(_in!, 0)), $.indexAddress(_in!, 0) != $.indexAddress(_in!, 1)) let dst = $.makeSlice | null>(2) $.sliceElems(dst!)[$.sliceSlot(dst!, 0)] = p - await $.println("struct slice", $.pointerEqual($.arrayIndex(dst!, 0), $.indexRef(_in!, 0)), ($.arrayIndex(dst!, 0) === p || ($.pointerAliasesMade || ($.arrayIndex(dst!, 0) as any)?.__goElementBacking !== undefined) && $.pointerEqual($.arrayIndex(dst!, 0), p))) + await $.println("struct slice", $.pointerEqual($.plainSliceIndex(dst!, 0), $.indexRef(_in!, 0)), ($.plainSliceIndex(dst!, 0) === p || ($.pointerAliasesMade || ($.plainSliceIndex(dst!, 0) as any)?.__goElementBacking !== undefined) && $.pointerEqual($.plainSliceIndex(dst!, 0), p))) $.copy(dst, $.arrayToSlice | null>([$.indexRef(_in!, 0), $.indexRef(_in!, 1)])) - await $.println("struct copy", $.pointerEqual($.arrayIndex(dst!, 0), $.indexRef(_in!, 0)), $.pointerEqual($.arrayIndex(dst!, 1), $.indexRef(_in!, 1)), ($.arrayIndex(dst!, 0) === $.arrayIndex(dst!, 1) || ($.pointerAliasesMade || ($.arrayIndex(dst!, 0) as any)?.__goElementBacking !== undefined) && $.pointerEqual($.arrayIndex(dst!, 0), $.arrayIndex(dst!, 1)))) + await $.println("struct copy", $.pointerEqual($.plainSliceIndex(dst!, 0), $.indexRef(_in!, 0)), $.pointerEqual($.plainSliceIndex(dst!, 1), $.indexRef(_in!, 1)), ($.plainSliceIndex(dst!, 0) === $.plainSliceIndex(dst!, 1) || ($.pointerAliasesMade || ($.plainSliceIndex(dst!, 0) as any)?.__goElementBacking !== undefined) && $.pointerEqual($.plainSliceIndex(dst!, 0), $.plainSliceIndex(dst!, 1)))) let m = $.makeMap | null>([["a", $.indexRef(_in!, 0)]]) await $.println("struct map", $.pointerEqual($.mapGet | null, T | $.VarRef | null>(m, "a", null)[0], $.indexRef(_in!, 0)), $.pointerEqual($.mapGet | null, T | $.VarRef | null>(m, "a", null)[0], $.indexRef(_in!, 1))) let e1: any = $.interfaceValue($.indexRef(_in!, 0), "*main.T", /* @__PURE__ */ $.pointerType("main.T")) @@ -185,7 +185,7 @@ export async function main(): globalThis.Promise { await $.println("struct field", $.pointerEqual(h.p, $.indexRef(_in!, 1)), $.pointerEqual(h.p, elemPtr(_in, 1)), $.pointerEqual(elemPtr(_in, 0), elemPtr(_in, 0))) let sub = $.goSlice(_in, 1, undefined) await $.println("struct subslice", $.indexAddress(sub!, 0) == $.indexAddress(_in!, 1), $.indexAddress(sub!, 0) == $.indexAddress(_in!, 0)) - await $.println("struct generic", same(__goscriptStatic1(), $.arrayIndex(dst!, 1), $.indexRef(_in!, 1)), index(__goscriptStatic1(), dst, $.indexRef(_in!, 1)), which($.arrayIndex(dst!, 1), _in), which($.indexRef(_in!, 1), $.goSlice(_in, 1, undefined)), which($.indexRef(_in!, 0), _in)) + await $.println("struct generic", same(__goscriptStatic1(), $.plainSliceIndex(dst!, 1), $.indexRef(_in!, 1)), index(__goscriptStatic1(), dst, $.indexRef(_in!, 1)), which($.plainSliceIndex(dst!, 1), _in), which($.indexRef(_in!, 1), $.goSlice(_in, 1, undefined)), which($.indexRef(_in!, 0), _in)) let keys = $.makeMap | null, number>([[$.indexRef(_in!, 0), 10]], /* @__PURE__ */ $.pointerType("main.T")) $.mapSet(keys, $.indexRef(_in!, 1), 11) await $.println("struct key", $.mapGet | null, number, number>(keys, $.indexRef(_in!, 0), 0)[0], $.mapGet | null, number, number>(keys, elemPtr(_in, 1), 0)[0], $.len(keys)) @@ -229,13 +229,13 @@ export async function main(): globalThis.Promise { let fsub = $.goSlice(fs, 1, 3) await $.println("float32", $.pointerEqual(fp, $.indexRef(fs!, 2)), $.pointerEqual($.indexRef(fsub!, 1), fp), $.pointerEqual($.indexRef(fsub!, 0), fp)) let ips = $.arrayToSlice<$.VarRef | null>([$.indexRef(ints!, 0)]) - await $.println("int slice", $.pointerEqual($.arrayIndex(ips!, 0), $.indexRef(ints!, 0))) + await $.println("int slice", $.pointerEqual($.plainSliceIndex(ips!, 0), $.indexRef(ints!, 0))) // Pointers to array elements. let arr = $.arrayValue([new T(true, 1, 1), new T(true, 2, 2), new T(true, 3, 3)], __goscriptStatic2()) let ap = $.indexRef(arr, 1) let aps = $.arrayToSlice | null>([$.indexRef(arr, 1)]) - await $.println("array struct", $.pointerEqual(ap, $.indexRef(arr, 1)), ($.arrayIndex(aps!, 0) === ap || ($.pointerAliasesMade || ($.arrayIndex(aps!, 0) as any)?.__goElementBacking !== undefined) && $.pointerEqual($.arrayIndex(aps!, 0), ap)), $.pointerEqual($.indexRef(arr, 0), ap)) + await $.println("array struct", $.pointerEqual(ap, $.indexRef(arr, 1)), ($.plainSliceIndex(aps!, 0) === ap || ($.pointerAliasesMade || ($.plainSliceIndex(aps!, 0) as any)?.__goElementBacking !== undefined) && $.pointerEqual($.plainSliceIndex(aps!, 0), ap)), $.pointerEqual($.indexRef(arr, 0), ap)) let nums = $.arrayValue([1, 2, 3]) let np = $.indexRef(nums, 2) let ne: any = $.interfaceValue(np, "*int", /* @__PURE__ */ $.pointerType(/* @__PURE__ */ $.basicType("int"))) @@ -267,9 +267,9 @@ export async function main(): globalThis.Promise { await $.println("chan", $.pointerEqual(await $.chanRecv(ch), $.indexRef(_in!, 0))) // Writes through one pointer are seen through an equal one. - $.pointerValue($.arrayIndex(dst!, 0)).A = 99 - $.arrayIndex(ips!, 0)!.value = 55 - await $.println("writes", $.arrayIndex(_in!, 0).A, $.arrayIndex(ints!, 0)) + $.pointerValue($.plainSliceIndex(dst!, 0)).A = 99 + $.plainSliceIndex(ips!, 0)!.value = 55 + await $.println("writes", $.plainSliceIndex(_in!, 0).A, $.plainSliceIndex(ints!, 0)) } var __goscriptStatic0$value: any diff --git a/tests/tests/pointer_slice_element_shadow/pointer_slice_element_shadow.gs.ts b/tests/tests/pointer_slice_element_shadow/pointer_slice_element_shadow.gs.ts index 8abd5291a..6fbabcf19 100644 --- a/tests/tests/pointer_slice_element_shadow/pointer_slice_element_shadow.gs.ts +++ b/tests/tests/pointer_slice_element_shadow/pointer_slice_element_shadow.gs.ts @@ -74,14 +74,14 @@ export async function printInterfaceSpareZero(): globalThis.Promise { let values: $.Slice = $.makeSlice(0, 2) values = $.appendOne(values, $.structInterfaceValue(new entry(true, "value"), "main.entry", "main.entry"), $.appendZeros.nil) values = $.goSlice(values, undefined, 2) - await $.println($.arrayIndex(values!, 1) == null) + await $.println($.plainSliceIndex(values!, 1) == null) } export async function printInterfaceAppendSliceSpareZero(): globalThis.Promise { let values: $.Slice = $.makeSlice(0, 2) values = $.appendSlice(values, $.arrayToSlice([$.structInterfaceValue(new entry(true, "value"), "main.entry", "main.entry")]), $.appendZeros.nil) values = $.goSlice(values, undefined, 2) - await $.println($.arrayIndex(values!, 1) == null) + await $.println($.plainSliceIndex(values!, 1) == null) } export async function main(): globalThis.Promise { diff --git a/tests/tests/pointer_target_locals/pointer_target_locals.gs.ts b/tests/tests/pointer_target_locals/pointer_target_locals.gs.ts index 234b022b1..7328b92fb 100644 --- a/tests/tests/pointer_target_locals/pointer_target_locals.gs.ts +++ b/tests/tests/pointer_target_locals/pointer_target_locals.gs.ts @@ -139,7 +139,7 @@ export async function main(): globalThis.Promise { let h = new Holder(false, $.arrayToSlice([new Node(true, "p"), new Node(true, "q")])) let h$: Holder = h == null ? $.pointerTarget(h) : (h as any).__isVarRef === true ? (h as any).value : (h as any).__goValue === undefined ? (h as any) : $.pointerTarget(h) void (h !== null && (h as any).__isVarRef !== true && (h as any).__goValue === undefined ? ((h as any) as Holder).touch(1) : Holder.prototype.touch.call(h, 1)) - await $.println($.arrayIndex((h$ as Holder).items!, 1).Name, $.arrayIndex((h$ as Holder).items!, 1).Count) + await $.println($.plainSliceIndex((h$ as Holder).items!, 1).Name, $.plainSliceIndex((h$ as Holder).items!, 1).Count) } if ($.isMainScript(import.meta)) { diff --git a/tests/tests/protobuf_cross_file_clone/protobuf_cross_file_clone.gs.ts b/tests/tests/protobuf_cross_file_clone/protobuf_cross_file_clone.gs.ts index cf25f6510..22de4347d 100644 --- a/tests/tests/protobuf_cross_file_clone/protobuf_cross_file_clone.gs.ts +++ b/tests/tests/protobuf_cross_file_clone/protobuf_cross_file_clone.gs.ts @@ -17,9 +17,9 @@ export async function main(): globalThis.Promise { await $.println("child name:", $.pointerValue<__goscript_child_pb_ts.Child>((clone$ as __goscript_parent_pb_ts.Parent).Child).Name) await $.println("child ptr same:", ((clone$ as __goscript_parent_pb_ts.Parent).Child === (parent$ as __goscript_parent_pb_ts.Parent).Child || ($.pointerAliasesMade || ((clone$ as __goscript_parent_pb_ts.Parent).Child as any)?.__goElementBacking !== undefined) && $.pointerEqual((clone$ as __goscript_parent_pb_ts.Parent).Child, (parent$ as __goscript_parent_pb_ts.Parent).Child))) await $.println("children count:", $.sliceLen((clone$ as __goscript_parent_pb_ts.Parent).Children)) - await $.println("children[0]:", $.pointerValue<__goscript_child_pb_ts.Child>($.arrayIndex((clone$ as __goscript_parent_pb_ts.Parent).Children!, 0)).Name) - await $.println("children[1]:", $.pointerValue<__goscript_child_pb_ts.Child>($.arrayIndex((clone$ as __goscript_parent_pb_ts.Parent).Children!, 1)).Name) - await $.println("children ptr same:", ($.arrayIndex((clone$ as __goscript_parent_pb_ts.Parent).Children!, 0) === $.arrayIndex((parent$ as __goscript_parent_pb_ts.Parent).Children!, 0) || ($.pointerAliasesMade || ($.arrayIndex((clone$ as __goscript_parent_pb_ts.Parent).Children!, 0) as any)?.__goElementBacking !== undefined) && $.pointerEqual($.arrayIndex((clone$ as __goscript_parent_pb_ts.Parent).Children!, 0), $.arrayIndex((parent$ as __goscript_parent_pb_ts.Parent).Children!, 0)))) + await $.println("children[0]:", $.pointerValue<__goscript_child_pb_ts.Child>($.plainSliceIndex((clone$ as __goscript_parent_pb_ts.Parent).Children!, 0)).Name) + await $.println("children[1]:", $.pointerValue<__goscript_child_pb_ts.Child>($.plainSliceIndex((clone$ as __goscript_parent_pb_ts.Parent).Children!, 1)).Name) + await $.println("children ptr same:", ($.plainSliceIndex((clone$ as __goscript_parent_pb_ts.Parent).Children!, 0) === $.plainSliceIndex((parent$ as __goscript_parent_pb_ts.Parent).Children!, 0) || ($.pointerAliasesMade || ($.plainSliceIndex((clone$ as __goscript_parent_pb_ts.Parent).Children!, 0) as any)?.__goElementBacking !== undefined) && $.pointerEqual($.plainSliceIndex((clone$ as __goscript_parent_pb_ts.Parent).Children!, 0), $.plainSliceIndex((parent$ as __goscript_parent_pb_ts.Parent).Children!, 0)))) // Deep equality after clone. await $.println("equal:", (parent !== null && (parent as any).__isVarRef !== true && (parent as any).__goValue === undefined ? ((parent as any) as __goscript_parent_pb_ts.Parent).EqualVT(clone) : __goscript_parent_pb_ts.Parent.prototype.EqualVT.call(parent, clone))) diff --git a/tests/tests/protobuf_lite_ts/protobuf_lite_ts.gs.ts b/tests/tests/protobuf_lite_ts/protobuf_lite_ts.gs.ts index 53c52b553..5bb63f148 100644 --- a/tests/tests/protobuf_lite_ts/protobuf_lite_ts.gs.ts +++ b/tests/tests/protobuf_lite_ts/protobuf_lite_ts.gs.ts @@ -51,7 +51,7 @@ export async function main(): globalThis.Promise { let oneofClone = (oneofMsg !== null && (oneofMsg as any).__isVarRef !== true && (oneofMsg as any).__goValue === undefined ? ((oneofMsg as any) as __goscript_protobuf_lite_ts_pb_ts.ExampleMsg).CloneVT() : __goscript_protobuf_lite_ts_pb_ts.ExampleMsg.prototype.CloneVT.call(oneofMsg)) await $.println("oneof clone equal:", (oneofMsg !== null && (oneofMsg as any).__isVarRef !== true && (oneofMsg as any).__goValue === undefined ? ((oneofMsg as any) as __goscript_protobuf_lite_ts_pb_ts.ExampleMsg).EqualVT(oneofClone) : __goscript_protobuf_lite_ts_pb_ts.ExampleMsg.prototype.EqualVT.call(oneofMsg, oneofClone))) $.indexRef((oneofMsg !== null && (oneofMsg as any).__isVarRef !== true && (oneofMsg as any).__goValue === undefined ? ((oneofMsg as any) as __goscript_protobuf_lite_ts_pb_ts.ExampleMsg).GetChoiceData() : __goscript_protobuf_lite_ts_pb_ts.ExampleMsg.prototype.GetChoiceData.call(oneofMsg))!, 0).value = 9 - await $.println("oneof clone independent:", $.uint($.arrayIndex((oneofClone !== null && (oneofClone as any).__isVarRef !== true && (oneofClone as any).__goValue === undefined ? ((oneofClone as any) as __goscript_protobuf_lite_ts_pb_ts.ExampleMsg).GetChoiceData() : __goscript_protobuf_lite_ts_pb_ts.ExampleMsg.prototype.GetChoiceData.call(oneofClone))!, 0), 8) == 1) + await $.println("oneof clone independent:", $.uint($.typedSliceIndex((oneofClone !== null && (oneofClone as any).__isVarRef !== true && (oneofClone as any).__goValue === undefined ? ((oneofClone as any) as __goscript_protobuf_lite_ts_pb_ts.ExampleMsg).GetChoiceData() : __goscript_protobuf_lite_ts_pb_ts.ExampleMsg.prototype.GetChoiceData.call(oneofClone))!, 0), 8) == 1) let oneofSize = (oneofClone !== null && (oneofClone as any).__isVarRef !== true && (oneofClone as any).__goValue === undefined ? ((oneofClone as any) as __goscript_protobuf_lite_ts_pb_ts.ExampleMsg).SizeVT() : __goscript_protobuf_lite_ts_pb_ts.ExampleMsg.prototype.SizeVT.call(oneofClone)) let __goscriptTuple2: any = (oneofClone !== null && (oneofClone as any).__isVarRef !== true && (oneofClone as any).__goValue === undefined ? ((oneofClone as any) as __goscript_protobuf_lite_ts_pb_ts.ExampleMsg).MarshalVT() : __goscript_protobuf_lite_ts_pb_ts.ExampleMsg.prototype.MarshalVT.call(oneofClone)) @@ -72,7 +72,7 @@ export async function main(): globalThis.Promise { } } await $.println("oneof round trip equal:", (oneofClone !== null && (oneofClone as any).__isVarRef !== true && (oneofClone as any).__goValue === undefined ? ((oneofClone as any) as __goscript_protobuf_lite_ts_pb_ts.ExampleMsg).EqualVT(oneofOut) : __goscript_protobuf_lite_ts_pb_ts.ExampleMsg.prototype.EqualVT.call(oneofClone, oneofOut))) - await $.println("oneof round trip value:", $.uint($.arrayIndex((oneofOut !== null && (oneofOut as any).__isVarRef !== true && (oneofOut as any).__goValue === undefined ? ((oneofOut as any) as __goscript_protobuf_lite_ts_pb_ts.ExampleMsg).GetChoiceData() : __goscript_protobuf_lite_ts_pb_ts.ExampleMsg.prototype.GetChoiceData.call(oneofOut))!, 2), 8)) + await $.println("oneof round trip value:", $.uint($.typedSliceIndex((oneofOut !== null && (oneofOut as any).__isVarRef !== true && (oneofOut as any).__goValue === undefined ? ((oneofOut as any) as __goscript_protobuf_lite_ts_pb_ts.ExampleMsg).GetChoiceData() : __goscript_protobuf_lite_ts_pb_ts.ExampleMsg.prototype.GetChoiceData.call(oneofOut))!, 2), 8)) let __goscriptTuple3: any = protobuf_go_lite.DecodeVarintUint32(new Uint8Array([172, 2]) as $.Slice, 0) let u32: number = __goscriptTuple3[0] diff --git a/tests/tests/range_assign_existing/range_assign_existing.gs.ts b/tests/tests/range_assign_existing/range_assign_existing.gs.ts index c232b16ba..3d261fbb9 100644 --- a/tests/tests/range_assign_existing/range_assign_existing.gs.ts +++ b/tests/tests/range_assign_existing/range_assign_existing.gs.ts @@ -126,7 +126,7 @@ export async function main(): globalThis.Promise { v = v.__goscriptAssign((__goscriptRangeValue0).clone()) v.Y = 9 } - await $.println("slice:", p.I, v.X, v.Y, $.arrayIndex(vs!, 1).Y) + await $.println("slice:", p.I, v.X, v.Y, $.plainSliceIndex(vs!, 1).Y) let r = 0 for (let __goscriptRunes0 = $.stringRunes("h\xc3\xa9"); __goscriptRunes0.next(); ) { const __goscriptRangeKey8 = __goscriptRunes0.index diff --git a/tests/tests/range_index_window_access/range_index_window_access.gs.ts b/tests/tests/range_index_window_access/range_index_window_access.gs.ts index 32d06e703..145d78a1a 100644 --- a/tests/tests/range_index_window_access/range_index_window_access.gs.ts +++ b/tests/tests/range_index_window_access/range_index_window_access.gs.ts @@ -38,13 +38,13 @@ export async function main(): globalThis.Promise { for (let __goscriptRangeTarget0 = xs, __goscriptRangeWindow0 = $.sliceRange(__goscriptRangeTarget0), i = 0; i < __goscriptRangeWindow0.length; i++) { ;(__goscriptRangeWindow0.backing as any[])[__goscriptRangeWindow0.offset + i] = (((__goscriptRangeWindow0.backing as any[])[__goscriptRangeWindow0.offset + i] as number) * 2) + 1 } - await $.println($.arrayIndex(xs!, 0), $.arrayIndex(xs!, 3)) + await $.println($.typedSliceIndex(xs!, 0), $.typedSliceIndex(xs!, 3)) let sub = $.goSlice(xs, 1, 3) for (let __goscriptRangeTarget1 = sub, __goscriptRangeWindow1 = $.sliceRange(__goscriptRangeTarget1), i = 0; i < __goscriptRangeWindow1.length; i++) { ;(__goscriptRangeWindow1.backing as any[])[__goscriptRangeWindow1.offset + i] += 100 } - await $.println($.arrayIndex(xs!, 1), $.arrayIndex(xs!, 2), $.sliceLen(sub)) + await $.println($.typedSliceIndex(xs!, 1), $.typedSliceIndex(xs!, 2), $.sliceLen(sub)) let ps = $.arrayToSlice

([new P(true, 1, 2), new P(true, 3, 4)]) for (let __goscriptRangeTarget2 = ps, __goscriptRangeWindow2 = $.sliceRange(__goscriptRangeTarget2), i = 0; i < __goscriptRangeWindow2.length; i++) { @@ -53,7 +53,7 @@ export async function main(): globalThis.Promise { let q = (((__goscriptRangeWindow2.backing as any[])[__goscriptRangeWindow2.offset + i] as P)).clone() q.Y = 99 } - await $.println($.arrayIndex(ps!, 0).X, $.arrayIndex(ps!, 0).Y, $.arrayIndex(ps!, 1).X) + await $.println($.plainSliceIndex(ps!, 0).X, $.plainSliceIndex(ps!, 0).Y, $.plainSliceIndex(ps!, 1).X) let m = $.arrayToSlice<$.Slice>([$.arrayToSlice([1, 2]), $.arrayToSlice([3, 4])]) for (let __goscriptRangeTarget4 = m, __goscriptRangeWindow3 = $.sliceRange(__goscriptRangeTarget4), i = 0; i < __goscriptRangeWindow3.length; i++) { @@ -61,7 +61,7 @@ export async function main(): globalThis.Promise { $.indexRef(((__goscriptRangeWindow3.backing as any[])[__goscriptRangeWindow3.offset + i] as $.Slice)!, j).value *= 10 } } - await $.println($.arrayIndex($.arrayIndex(m!, 0)!, 1), $.arrayIndex($.arrayIndex(m!, 1)!, 0)) + await $.println($.plainSliceIndex($.plainSliceIndex(m!, 0)!, 1), $.plainSliceIndex($.plainSliceIndex(m!, 1)!, 0)) let ys: $.Slice = $.arrayToSlice([1, 2, 3]) let grow = $.functionValue(() => { @@ -73,13 +73,13 @@ export async function main(): globalThis.Promise { } $.sliceElems(ys!)[$.sliceSlot(ys!, i)] += 1 } - await $.println($.sliceLen(ys), $.arrayIndex(ys!, 0), $.arrayIndex(ys!, 2), $.arrayIndex(ys!, 3)) + await $.println($.sliceLen(ys), $.plainSliceIndex(ys!, 0), $.plainSliceIndex(ys!, 2), $.plainSliceIndex(ys!, 3)) let bs = new Uint8Array([250, 251]) as $.Slice for (let __goscriptRangeTarget6 = bs, __goscriptRangeWindow6 = $.sliceRange(__goscriptRangeTarget6), i = 0; i < __goscriptRangeWindow6.length; i++) { ;(__goscriptRangeWindow6.backing as any[])[__goscriptRangeWindow6.offset + i] = $.uint((__goscriptRangeWindow6.backing as any[])[__goscriptRangeWindow6.offset + i] + (10), 8) } - await $.println($.arrayIndex(bs!, 0), $.arrayIndex(bs!, 1)) + await $.println($.typedSliceIndex(bs!, 0), $.typedSliceIndex(bs!, 1)) let f32 = 1 for (let i = 0; i < 3; i++) { diff --git a/tests/tests/range_shadow_rhs/range_shadow_rhs.gs.ts b/tests/tests/range_shadow_rhs/range_shadow_rhs.gs.ts index 6e534b38c..a7fdbf157 100644 --- a/tests/tests/range_shadow_rhs/range_shadow_rhs.gs.ts +++ b/tests/tests/range_shadow_rhs/range_shadow_rhs.gs.ts @@ -78,7 +78,7 @@ export async function main(): globalThis.Promise { let __goscriptRangeShadow1 = $.varRef(((__goscriptRangeWindow0.backing[__goscriptRangeWindow0.offset + __rangeIndex] as item)).clone()) await $.println(__goscriptRangeShadow1.value.increment()) } - await $.println($.arrayIndex(items.items!, 0).value, $.arrayIndex(items.items!, 1).value) + await $.println($.plainSliceIndex(items.items!, 0).value, $.plainSliceIndex(items.items!, 1).value) } if ($.isMainScript(import.meta)) { diff --git a/tests/tests/range_value_share/range_value_share.gs.ts b/tests/tests/range_value_share/range_value_share.gs.ts index 0de949fda..6052970f5 100644 --- a/tests/tests/range_value_share/range_value_share.gs.ts +++ b/tests/tests/range_value_share/range_value_share.gs.ts @@ -84,7 +84,7 @@ export function find(name: string): box { } export function widen(i: number): void { - $.arrayIndex(boxes!, i).Max.X += 100 + $.plainSliceIndex(boxes!, i).Max.X += 100 } export async function main(): globalThis.Promise { @@ -101,7 +101,7 @@ export async function main(): globalThis.Promise { // A returned value is a copy of the element. let found = find("b") found.Max.X = 70 - await $.println("found:", found.Max.X, $.arrayIndex(boxes!, 1).Max.X) + await $.println("found:", found.Max.X, $.plainSliceIndex(boxes!, 1).Max.X) // A store into the element leaves the value as it was. for (let __goscriptRangeTarget2 = boxes, __goscriptRangeWindow2 = $.sliceRange(__goscriptRangeTarget2), i = 0; i < __goscriptRangeWindow2.length; i++) { @@ -127,13 +127,13 @@ export async function main(): globalThis.Promise { await $.println("copy:", b.Name, c.Name) } last.Min.Y = -1 - await $.println("last:", last.Name, last.Min.Y, $.arrayIndex(boxes!, 1).Min.Y) + await $.println("last:", last.Name, last.Min.Y, $.plainSliceIndex(boxes!, 1).Min.Y) // A changed value is its own copy. for (let __goscriptRangeTarget5 = boxes, __goscriptRangeWindow5 = $.sliceRange(__goscriptRangeTarget5), __rangeIndex = 0; __rangeIndex < __goscriptRangeWindow5.length; __rangeIndex++) { let b = ((__goscriptRangeWindow5.backing[__goscriptRangeWindow5.offset + __rangeIndex] as box)).clone() b.Min.Y++ - await $.println("changed:", b.Min.Y, $.arrayIndex(boxes!, 0).Min.Y) + await $.println("changed:", b.Min.Y, $.plainSliceIndex(boxes!, 0).Min.Y) } // Array elements. @@ -160,8 +160,8 @@ export async function main(): globalThis.Promise { let v: any = $.structInterfaceValue((b).clone(), "main.box", "main.box") held = $.appendOne(held, v, $.appendZeros.nil) } - $.arrayIndex(boxes!, 0).Name = "z" - await $.println("held:", $.mustTypeAssert($.arrayIndex(held!, 0), "main.box").Name, $.arrayIndex(boxes!, 0).Name) + $.plainSliceIndex(boxes!, 0).Name = "z" + await $.println("held:", $.mustTypeAssert($.plainSliceIndex(held!, 0), "main.box").Name, $.plainSliceIndex(boxes!, 0).Name) } if ($.isMainScript(import.meta)) { diff --git a/tests/tests/reflect_elem_struct_pointer/reflect_elem_struct_pointer.gs.ts b/tests/tests/reflect_elem_struct_pointer/reflect_elem_struct_pointer.gs.ts index 43c19f7e2..6165d298b 100644 --- a/tests/tests/reflect_elem_struct_pointer/reflect_elem_struct_pointer.gs.ts +++ b/tests/tests/reflect_elem_struct_pointer/reflect_elem_struct_pointer.gs.ts @@ -292,9 +292,9 @@ export async function main(): globalThis.Promise { // Field Values copied into a slice read back what was set through them. let fields = $.arrayToSlice([$.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(e)).Field(0))), $.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(e)).Field(1)))]) - $.markAsStructValue($.cloneStructValue($.arrayIndex(fields!, 0))).SetString("ccc") - $.markAsStructValue($.cloneStructValue($.arrayIndex(fields!, 1))).SetFloat(1.5) - await $.println($.markAsStructValue($.cloneStructValue($.arrayIndex(fields!, 0))).String(), $.markAsStructValue($.cloneStructValue($.arrayIndex(fields!, 1))).Float(), $.pointerValue(s.value).A, $.pointerValue(s.value).B) + $.markAsStructValue($.cloneStructValue($.plainSliceIndex(fields!, 0))).SetString("ccc") + $.markAsStructValue($.cloneStructValue($.plainSliceIndex(fields!, 1))).SetFloat(1.5) + await $.println($.markAsStructValue($.cloneStructValue($.plainSliceIndex(fields!, 0))).String(), $.markAsStructValue($.cloneStructValue($.plainSliceIndex(fields!, 1))).Float(), $.pointerValue(s.value).A, $.pointerValue(s.value).B) // Values made by New read back what was set through them, as decoders // building map keys do. diff --git a/tests/tests/reflect_generic_field_types/reflect_generic_field_types.gs.ts b/tests/tests/reflect_generic_field_types/reflect_generic_field_types.gs.ts index 61268fd73..54fb3832e 100644 --- a/tests/tests/reflect_generic_field_types/reflect_generic_field_types.gs.ts +++ b/tests/tests/reflect_generic_field_types/reflect_generic_field_types.gs.ts @@ -190,11 +190,11 @@ export async function main(): globalThis.Promise { let sl = $.markAsStructValue($.cloneStructValue(reflect.MakeSlice($.pointerValueOrNil($.markAsStructValue($.cloneStructValue(ov)).Type())!, 1, 1))) $.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(sl)).Index(0))).Field(0))).SetString("x") $.markAsStructValue($.cloneStructValue(ov)).Set(sl) - await $.println("opt:", $.sliceLen(d.value.Opt.Value), $.arrayIndex(d.value.Opt.Value!, 0).Name) + await $.println("opt:", $.sliceLen(d.value.Opt.Value), $.plainSliceIndex(d.value.Opt.Value!, 0).Name) let lv = $.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(reflect.ValueOf($.interfaceValue(d, "*main.Data", /* @__PURE__ */ $.pointerType("main.Data"))))).Elem())).Field(1))).Field(0))) $.markAsStructValue($.cloneStructValue(lv)).Set($.markAsStructValue($.cloneStructValue(reflect.Append($.markAsStructValue($.cloneStructValue(lv)), $.markAsStructValue($.cloneStructValue(reflect.New($.pointerValueOrNil((__goscriptAwait = $.pointerValue>((__goscriptAwait = $.pointerValue>($.markAsStructValue($.cloneStructValue(lv)).Type()).Elem(), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait)).Elem(), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait))!))))))) - $.pointerValue($.arrayIndex(d.value.List.Values!, 0)).N = 3 - await $.println("list:", $.pointerValue($.arrayIndex(d.value.List.Values!, 0)).N) + $.pointerValue($.plainSliceIndex(d.value.List.Values!, 0)).N = 3 + await $.println("list:", $.pointerValue($.plainSliceIndex(d.value.List.Values!, 0)).N) // Values of the instantiated types report the same field types. let o = new Option(true, 4, true) diff --git a/tests/tests/reflect_generic_methods/reflect_generic_methods.gs.ts b/tests/tests/reflect_generic_methods/reflect_generic_methods.gs.ts index 31709f643..1781f3e19 100644 --- a/tests/tests/reflect_generic_methods/reflect_generic_methods.gs.ts +++ b/tests/tests/reflect_generic_methods/reflect_generic_methods.gs.ts @@ -215,16 +215,16 @@ export async function main(): globalThis.Promise { // such as yaegi call them, have the methods of their instantiated types. for (let __goscriptRangeTarget3 = $.arrayToSlice([$.interfaceValue($.goFunc(NewFloat32, "main.NewFloat32"), "func() *main.Number[float32]", ({ kind: $.TypeKind.Function, params: [], results: [/* @__PURE__ */ $.pointerType(/* @__PURE__ */ $.genericStructType("main.Number", "main.Number[float32]", () => [/* @__PURE__ */ $.structField("Base", /* @__PURE__ */ $.pointerType(/* @__PURE__ */ $.genericStructType("main.Base", "main.Base[float32]", () => [/* @__PURE__ */ $.structField("Vals", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("float32")), [0], 0, true)])), [0], 0, true, { anonymous: true })]))] } as $.FunctionTypeInfo)), $.interfaceValue($.functionValue((): Number | $.VarRef | null => NewNumber(__goscriptStatic2()), ({ kind: $.TypeKind.Function, params: [], results: [/* @__PURE__ */ $.pointerType("main.Number")] } as $.FunctionTypeInfo)), "func() *main.Number[int]", ({ kind: $.TypeKind.Function, params: [], results: [/* @__PURE__ */ $.pointerType(/* @__PURE__ */ $.genericStructType("main.Number", "main.Number[int]", () => [/* @__PURE__ */ $.structField("Base", /* @__PURE__ */ $.pointerType(/* @__PURE__ */ $.genericStructType("main.Base", "main.Base[int]", () => [/* @__PURE__ */ $.structField("Vals", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("int")), [0], 0, true)])), [0], 0, true, { anonymous: true })]))] } as $.FunctionTypeInfo))]), __goscriptRangeWindow3 = $.sliceRange(__goscriptRangeTarget3), i = 0; i < __goscriptRangeWindow3.length; i++) { let f = (__goscriptRangeWindow3.backing[__goscriptRangeWindow3.offset + i] as any) - let r = $.markAsStructValue($.cloneStructValue($.arrayIndex((await $.markAsStructValue($.cloneStructValue(reflect.ValueOf(f))).Call(null))!, 0))) - await $.println($.markAsStructValue($.cloneStructValue($.arrayIndex((await $.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(r)).MethodByName("Kind"))).Call(null))!, 0))).String()) + let r = $.markAsStructValue($.cloneStructValue($.plainSliceIndex((await $.markAsStructValue($.cloneStructValue(reflect.ValueOf(f))).Call(null))!, 0))) + await $.println($.markAsStructValue($.cloneStructValue($.plainSliceIndex((await $.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(r)).MethodByName("Kind"))).Call(null))!, 0))).String()) await $.println((__goscriptAwait = $.pointerValue>($.mustTypeAssert($.markAsStructValue($.cloneStructValue(r)).Interface(), "main.kinder")).Kind(), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait), (__goscriptAwait = $.pointerValue>($.mustTypeAssert($.markAsStructValue($.cloneStructValue(r)).Interface(), "main.stringer")).String(), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait)) - await $.println($.markAsStructValue($.cloneStructValue($.arrayIndex((await $.markAsStructValue($.cloneStructValue(reflect.ValueOf($.interfaceValue($.goFunc(describe, "main.describe"), "func(n main.kinder) string", ({ kind: $.TypeKind.Function, params: ["main.kinder"], results: [/* @__PURE__ */ $.basicType("string")] } as $.FunctionTypeInfo))))).Call($.arrayToSlice([$.markAsStructValue($.cloneStructValue(r))])))!, 0))).String()) + await $.println($.markAsStructValue($.cloneStructValue($.plainSliceIndex((await $.markAsStructValue($.cloneStructValue(reflect.ValueOf($.interfaceValue($.goFunc(describe, "main.describe"), "func(n main.kinder) string", ({ kind: $.TypeKind.Function, params: ["main.kinder"], results: [/* @__PURE__ */ $.basicType("string")] } as $.FunctionTypeInfo))))).Call($.arrayToSlice([$.markAsStructValue($.cloneStructValue(r))])))!, 0))).String()) await $.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(r)).MethodByName("Set"))).Call($.arrayToSlice([$.markAsStructValue($.cloneStructValue(reflect.ValueOf($.basicInterfaceValue(2.5, "float64")))), $.markAsStructValue($.cloneStructValue(reflect.ValueOf($.basicInterfaceValue(2, "int"))))])) let vals = $.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(r)).Elem())).Field(0))).Elem())).Field(0))) - await $.println($.markAsStructValue($.cloneStructValue(vals)).Len(), typeName($.markAsStructValue($.cloneStructValue($.arrayIndex((await $.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(r)).MethodByName("First"))).Call(null))!, 0))).Interface())) - let fill = $.arrayIndex($.arrayToSlice([$.basicInterfaceValue(1.5, "float32"), $.basicInterfaceValue(3, "int")])!, i) + await $.println($.markAsStructValue($.cloneStructValue(vals)).Len(), typeName($.markAsStructValue($.cloneStructValue($.plainSliceIndex((await $.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(r)).MethodByName("First"))).Call(null))!, 0))).Interface())) + let fill = $.plainSliceIndex($.arrayToSlice([$.basicInterfaceValue(1.5, "float32"), $.basicInterfaceValue(3, "int")])!, i) await $.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(r)).MethodByName("Fill"))).Call($.arrayToSlice([$.markAsStructValue($.cloneStructValue(reflect.ValueOf(fill)))])) - await $.println($.markAsStructValue($.cloneStructValue($.arrayIndex((await $.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(r)).MethodByName("Sum"))).Call(null))!, 0))).Float()) + await $.println($.markAsStructValue($.cloneStructValue($.plainSliceIndex((await $.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(r)).MethodByName("Sum"))).Call(null))!, 0))).Float()) } // The same for a value made in generic code and taken from a field. @@ -260,7 +260,7 @@ export async function main(): globalThis.Promise { let p = $.genericInstance(new Pair(true, 1, 2), __goscriptStatic3) let q = $.varRef(p) let pv = $.markAsStructValue($.cloneStructValue(reflect.ValueOf($.namedValueInterfaceValue((q.value).clone(), "main.Pair", __goscriptStatic4(), __goscriptStatic5(), __goscriptStatic6())))) - await $.println($.markAsStructValue($.cloneStructValue($.arrayIndex((await $.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(pv)).MethodByName("Kind"))).Call(null))!, 0))).String(), (__goscriptAwait = $.pointerValue>($.mustTypeAssert($.markAsStructValue($.cloneStructValue(pv)).Interface(), "main.kinder")).Kind(), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait)) + await $.println($.markAsStructValue($.cloneStructValue($.plainSliceIndex((await $.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(pv)).MethodByName("Kind"))).Call(null))!, 0))).String(), (__goscriptAwait = $.pointerValue>($.mustTypeAssert($.markAsStructValue($.cloneStructValue(pv)).Interface(), "main.kinder")).Kind(), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait)) await $.println((__goscriptAwait = $.pointerValue>($.mustTypeAssert($.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(reflect.ValueOf($.namedValueInterfaceValue(q, "*main.Pair", __goscriptStatic4(), __goscriptStatic7(), __goscriptStatic6())))).Elem())).Interface(), "main.kinder")).Kind(), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait)) } diff --git a/tests/tests/reflect_make_func/reflect_make_func.gs.ts b/tests/tests/reflect_make_func/reflect_make_func.gs.ts index 8980b189c..c0cf75c1b 100644 --- a/tests/tests/reflect_make_func/reflect_make_func.gs.ts +++ b/tests/tests/reflect_make_func/reflect_make_func.gs.ts @@ -11,12 +11,12 @@ export async function main(): globalThis.Promise { let unaryType = reflect.FuncOf($.arrayToSlice([intType]), $.arrayToSlice([stringType]), false) let unaryValue = $.markAsStructValue($.cloneStructValue(reflect.MakeFunc($.pointerValueOrNil(unaryType)!, $.functionValue((args: $.Slice): $.Slice => { - return $.arrayToSlice([$.markAsStructValue($.cloneStructValue(reflect.ValueOf("value-" + $.runeToString($.intFromWide($.int64Add(48n, $.markAsStructValue($.cloneStructValue($.arrayIndex(args!, 0))).Int()), 32)))))]) + return $.arrayToSlice([$.markAsStructValue($.cloneStructValue(reflect.ValueOf("value-" + $.runeToString($.intFromWide($.int64Add(48n, $.markAsStructValue($.cloneStructValue($.plainSliceIndex(args!, 0))).Int()), 32)))))]) }, ({ kind: $.TypeKind.Function, params: [/* @__PURE__ */ $.sliceType("reflect.Value")], results: [/* @__PURE__ */ $.sliceType("reflect.Value")] } as $.FunctionTypeInfo))))) let unary: ((_p0: number) => string | globalThis.Promise) | null = $.mustTypeAssert<((_p0: number) => string | globalThis.Promise) | null>($.markAsStructValue($.cloneStructValue(unaryValue)).Interface(), ({ kind: $.TypeKind.Function, params: [/* @__PURE__ */ $.basicType("int")], results: [/* @__PURE__ */ $.basicType("string")] } as $.FunctionTypeInfo)) await $.println("direct:", (__goscriptAwait = unary!(7), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait)) let reflectedUnary = await $.markAsStructValue($.cloneStructValue(unaryValue)).Call($.arrayToSlice([$.markAsStructValue($.cloneStructValue(reflect.ValueOf($.basicInterfaceValue(8, "int"))))])) - await $.println("reflected:", $.markAsStructValue($.cloneStructValue($.arrayIndex(reflectedUnary!, 0))).String()) + await $.println("reflected:", $.markAsStructValue($.cloneStructValue($.plainSliceIndex(reflectedUnary!, 0))).String()) let [, wrong] = $.typeAssertTuple<((_p0: string) => string | globalThis.Promise) | null>($.markAsStructValue($.cloneStructValue(unaryValue)).Interface(), ({ kind: $.TypeKind.Function, params: [/* @__PURE__ */ $.basicType("string")], results: [/* @__PURE__ */ $.basicType("string")] } as $.FunctionTypeInfo)) await $.println("wrong assertion:", wrong) @@ -37,18 +37,18 @@ export async function main(): globalThis.Promise { let [_number, ok] = await tuple!() await $.println("tuple direct:", _number, ok) let reflectedTuple = await $.markAsStructValue($.cloneStructValue(tupleValue)).Call(null) - await $.println("tuple reflected:", $.markAsStructValue($.cloneStructValue($.arrayIndex(reflectedTuple!, 0))).Int(), $.markAsStructValue($.cloneStructValue($.arrayIndex(reflectedTuple!, 1))).Bool()) + await $.println("tuple reflected:", $.markAsStructValue($.cloneStructValue($.plainSliceIndex(reflectedTuple!, 0))).Int(), $.markAsStructValue($.cloneStructValue($.plainSliceIndex(reflectedTuple!, 1))).Bool()) let variadicType = reflect.FuncOf($.arrayToSlice([intType, reflect.SliceOf($.pointerValueOrNil(stringType)!)]), $.arrayToSlice([intType]), true) let variadicValue = $.markAsStructValue($.cloneStructValue(reflect.MakeFunc($.pointerValueOrNil(variadicType)!, $.functionValue((args: $.Slice): $.Slice => { - return $.arrayToSlice([$.markAsStructValue($.cloneStructValue(reflect.ValueOf($.basicInterfaceValue($.int64ToNumber($.markAsStructValue($.cloneStructValue($.arrayIndex(args!, 0))).Int()) + $.markAsStructValue($.cloneStructValue($.arrayIndex(args!, 1))).Len(), "int"))))]) + return $.arrayToSlice([$.markAsStructValue($.cloneStructValue(reflect.ValueOf($.basicInterfaceValue($.int64ToNumber($.markAsStructValue($.cloneStructValue($.plainSliceIndex(args!, 0))).Int()) + $.markAsStructValue($.cloneStructValue($.plainSliceIndex(args!, 1))).Len(), "int"))))]) }, ({ kind: $.TypeKind.Function, params: [/* @__PURE__ */ $.sliceType("reflect.Value")], results: [/* @__PURE__ */ $.sliceType("reflect.Value")] } as $.FunctionTypeInfo))))) let variadic: ((_p0: number, _p1: $.Slice) => number | globalThis.Promise) | null = $.mustTypeAssert<((_p0: number, _p1: $.Slice) => number | globalThis.Promise) | null>($.markAsStructValue($.cloneStructValue(variadicValue)).Interface(), ({ kind: $.TypeKind.Function, params: [/* @__PURE__ */ $.basicType("int"), /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("string"))], results: [/* @__PURE__ */ $.basicType("int")], isVariadic: true } as $.FunctionTypeInfo)) await $.println("variadic direct:", (__goscriptAwait = variadic!(10, $.arrayToSlice(["a", "b"])), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait)) let reflectedVariadic = await $.markAsStructValue($.cloneStructValue(variadicValue)).Call($.arrayToSlice([$.markAsStructValue($.cloneStructValue(reflect.ValueOf($.basicInterfaceValue(20, "int")))), $.markAsStructValue($.cloneStructValue(reflect.ValueOf("a"))), $.markAsStructValue($.cloneStructValue(reflect.ValueOf("b"))), $.markAsStructValue($.cloneStructValue(reflect.ValueOf("c")))])) - await $.println("variadic reflected:", $.markAsStructValue($.cloneStructValue($.arrayIndex(reflectedVariadic!, 0))).Int()) + await $.println("variadic reflected:", $.markAsStructValue($.cloneStructValue($.plainSliceIndex(reflectedVariadic!, 0))).Int()) let reflectedSlice = await $.markAsStructValue($.cloneStructValue(variadicValue)).CallSlice($.arrayToSlice([$.markAsStructValue($.cloneStructValue(reflect.ValueOf($.basicInterfaceValue(30, "int")))), $.markAsStructValue($.cloneStructValue(reflect.ValueOf($.interfaceValue($.arrayToSlice(["a", "b"]), "[]string", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("string"))))))])) - await $.println("variadic callslice:", $.markAsStructValue($.cloneStructValue($.arrayIndex(reflectedSlice!, 0))).Int()) + await $.println("variadic callslice:", $.markAsStructValue($.cloneStructValue($.plainSliceIndex(reflectedSlice!, 0))).Int()) await $.println("reflect_make_func test finished") } diff --git a/tests/tests/reflect_make_func_call_args/reflect_make_func_call_args.gs.ts b/tests/tests/reflect_make_func_call_args/reflect_make_func_call_args.gs.ts index 084bdf60e..67e4b061a 100644 --- a/tests/tests/reflect_make_func_call_args/reflect_make_func_call_args.gs.ts +++ b/tests/tests/reflect_make_func_call_args/reflect_make_func_call_args.gs.ts @@ -78,15 +78,15 @@ export async function main(): globalThis.Promise { // makes the function literals of its code, passed by reflect.Value.Call // to an exported method and function, which call it. let keep = $.markAsStructValue($.cloneStructValue(reflect.MakeFunc($.pointerValueOrNil(reflect.TypeFor(__goscriptStatic0()))!, $.functionValue((args: $.Slice): $.Slice => { - return $.arrayToSlice([$.markAsStructValue($.cloneStructValue(reflect.ValueOf($.markAsStructValue($.cloneStructValue($.arrayIndex(args!, 0))).Int() > 4n)))]) + return $.arrayToSlice([$.markAsStructValue($.cloneStructValue(reflect.ValueOf($.markAsStructValue($.cloneStructValue($.plainSliceIndex(args!, 0))).Int() > 4n)))]) }, ({ kind: $.TypeKind.Function, params: [/* @__PURE__ */ $.sliceType("reflect.Value")], results: [/* @__PURE__ */ $.sliceType("reflect.Value")] } as $.FunctionTypeInfo))))) let values = new Values(false, $.arrayToSlice([1, 5, 7, 2])) let values$: Values = values == null ? $.pointerTarget(values) : (values as any).__isVarRef === true ? (values as any).value : (values as any).__goValue === undefined ? (values as any) : $.pointerTarget(values) - await $.println($.markAsStructValue($.cloneStructValue($.arrayIndex((await $.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(reflect.ValueOf($.interfaceValue(values, "*main.Values", /* @__PURE__ */ $.pointerType("main.Values"))))).MethodByName("Count"))).Call($.arrayToSlice([keep])))!, 0))).Int()) + await $.println($.markAsStructValue($.cloneStructValue($.plainSliceIndex((await $.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(reflect.ValueOf($.interfaceValue(values, "*main.Values", /* @__PURE__ */ $.pointerType("main.Values"))))).MethodByName("Count"))).Call($.arrayToSlice([keep])))!, 0))).Int()) let double = $.markAsStructValue($.cloneStructValue(reflect.MakeFunc($.pointerValueOrNil(reflect.TypeFor(__goscriptStatic1()))!, $.functionValue((args: $.Slice): $.Slice => { - return $.arrayToSlice([$.markAsStructValue($.cloneStructValue(reflect.ValueOf($.basicInterfaceValue(2 * $.int64ToNumber($.markAsStructValue($.cloneStructValue($.arrayIndex(args!, 0))).Int()), "int"))))]) + return $.arrayToSlice([$.markAsStructValue($.cloneStructValue(reflect.ValueOf($.basicInterfaceValue(2 * $.int64ToNumber($.markAsStructValue($.cloneStructValue($.plainSliceIndex(args!, 0))).Int()), "int"))))]) }, ({ kind: $.TypeKind.Function, params: [/* @__PURE__ */ $.sliceType("reflect.Value")], results: [/* @__PURE__ */ $.sliceType("reflect.Value")] } as $.FunctionTypeInfo))))) - await $.println($.markAsStructValue($.cloneStructValue($.arrayIndex((await $.markAsStructValue($.cloneStructValue(reflect.ValueOf($.interfaceValue($.goFunc(Sum, "main.Sum"), "func(vals []int, f func(v int) int) int", ({ kind: $.TypeKind.Function, params: [/* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("int")), ({ kind: $.TypeKind.Function, params: [/* @__PURE__ */ $.basicType("int")], results: [/* @__PURE__ */ $.basicType("int")] } as $.FunctionTypeInfo)], results: [/* @__PURE__ */ $.basicType("int")] } as $.FunctionTypeInfo))))).Call($.arrayToSlice([$.markAsStructValue($.cloneStructValue(reflect.ValueOf($.interfaceValue((values$ as Values).vals, "[]int", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("int")))))), double])))!, 0))).Int()) + await $.println($.markAsStructValue($.cloneStructValue($.plainSliceIndex((await $.markAsStructValue($.cloneStructValue(reflect.ValueOf($.interfaceValue($.goFunc(Sum, "main.Sum"), "func(vals []int, f func(v int) int) int", ({ kind: $.TypeKind.Function, params: [/* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("int")), ({ kind: $.TypeKind.Function, params: [/* @__PURE__ */ $.basicType("int")], results: [/* @__PURE__ */ $.basicType("int")] } as $.FunctionTypeInfo)], results: [/* @__PURE__ */ $.basicType("int")] } as $.FunctionTypeInfo))))).Call($.arrayToSlice([$.markAsStructValue($.cloneStructValue(reflect.ValueOf($.interfaceValue((values$ as Values).vals, "[]int", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("int")))))), double])))!, 0))).Int()) // Compiled calls are unchanged. await $.println(Values.prototype.Count.call(values, $.functionValue((v: number): boolean => { diff --git a/tests/tests/reflect_make_func_call_twins/reflect_make_func_call_twins.gs.ts b/tests/tests/reflect_make_func_call_twins/reflect_make_func_call_twins.gs.ts index b442f929e..92adcacfa 100644 --- a/tests/tests/reflect_make_func_call_twins/reflect_make_func_call_twins.gs.ts +++ b/tests/tests/reflect_make_func_call_twins/reflect_make_func_call_twins.gs.ts @@ -239,13 +239,13 @@ export async function main(): globalThis.Promise { // the function literals of its code. let names: $.Slice = null! as $.Slice let visit = $.markAsStructValue($.cloneStructValue(reflect.MakeFunc($.pointerValueOrNil(reflect.TypeFor(__goscriptStatic0()))!, $.functionValue((args: $.Slice): $.Slice => { - let n = $.mustTypeAssert | null>($.markAsStructValue($.cloneStructValue($.arrayIndex(args!, 0))).Interface(), /* @__PURE__ */ $.pointerType("main.Node")) + let n = $.mustTypeAssert | null>($.markAsStructValue($.cloneStructValue($.plainSliceIndex(args!, 0))).Interface(), /* @__PURE__ */ $.pointerType("main.Node")) let n$: Node = n == null ? $.pointerTarget(n) : (n as any).__isVarRef === true ? (n as any).value : (n as any).__goValue === undefined ? (n as any) : $.pointerTarget(n) names = $.appendOne(names, (n$ as Node).Name) return $.arrayToSlice([$.markAsStructValue($.cloneStructValue(reflect.ValueOf(!$.stringEqual((n$ as Node).Name, "b"))))]) }, ({ kind: $.TypeKind.Function, params: [/* @__PURE__ */ $.sliceType("reflect.Value")], results: [/* @__PURE__ */ $.sliceType("reflect.Value")] } as $.FunctionTypeInfo))))) let short = $.markAsStructValue($.cloneStructValue(reflect.MakeFunc($.pointerValueOrNil(reflect.TypeFor(__goscriptStatic0()))!, $.functionValue((args: $.Slice): $.Slice => { - return $.arrayToSlice([$.markAsStructValue($.cloneStructValue(reflect.ValueOf($.stringLen($.pointerValue($.mustTypeAssert | null>($.markAsStructValue($.cloneStructValue($.arrayIndex(args!, 0))).Interface(), /* @__PURE__ */ $.pointerType("main.Node"))).Name) <= 2)))]) + return $.arrayToSlice([$.markAsStructValue($.cloneStructValue(reflect.ValueOf($.stringLen($.pointerValue($.mustTypeAssert | null>($.markAsStructValue($.cloneStructValue($.plainSliceIndex(args!, 0))).Interface(), /* @__PURE__ */ $.pointerType("main.Node"))).Name) <= 2)))]) }, ({ kind: $.TypeKind.Function, params: [/* @__PURE__ */ $.sliceType("reflect.Value")], results: [/* @__PURE__ */ $.sliceType("reflect.Value")] } as $.FunctionTypeInfo))))) let root = new Node(false, "root", $.arrayToSlice | null>([new Node(false, "a"), new Node(false, "b", $.arrayToSlice | null>([new Node(false, "bc")])), new Node(false, "c")])) let root$: Node = root == null ? $.pointerTarget(root) : (root as any).__isVarRef === true ? (root as any).value : (root as any).__goValue === undefined ? (root as any) : $.pointerTarget(root) @@ -253,8 +253,8 @@ export async function main(): globalThis.Promise { // reflect.Value.Call passes them to an exported method and an exported // function, which passes it to a helper. await $.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(reflect.ValueOf($.interfaceValue(root, "*main.Node", /* @__PURE__ */ $.pointerType("main.Node"))))).MethodByName("Walk"))).Call($.arrayToSlice([$.markAsStructValue($.cloneStructValue(visit))])) - await $.println($.sliceLen(names), $.arrayIndex(names!, 0), $.arrayIndex(names!, $.sliceLen(names) - 1)) - await $.println($.markAsStructValue($.cloneStructValue($.arrayIndex((await $.markAsStructValue($.cloneStructValue(reflect.ValueOf($.interfaceValue($.goFunc(Count, "main.Count"), "func(n *main.Node, keep func(n *main.Node) bool) int", ({ kind: $.TypeKind.Function, params: [/* @__PURE__ */ $.pointerType("main.Node"), ({ kind: $.TypeKind.Function, params: [/* @__PURE__ */ $.pointerType("main.Node")], results: [/* @__PURE__ */ $.basicType("bool")] } as $.FunctionTypeInfo)], results: [/* @__PURE__ */ $.basicType("int")] } as $.FunctionTypeInfo))))).Call($.arrayToSlice([$.markAsStructValue($.cloneStructValue(reflect.ValueOf($.interfaceValue(root, "*main.Node", /* @__PURE__ */ $.pointerType("main.Node"))))), short])))!, 0))).Int()) + await $.println($.sliceLen(names), $.plainSliceIndex(names!, 0), $.plainSliceIndex(names!, $.sliceLen(names) - 1)) + await $.println($.markAsStructValue($.cloneStructValue($.plainSliceIndex((await $.markAsStructValue($.cloneStructValue(reflect.ValueOf($.interfaceValue($.goFunc(Count, "main.Count"), "func(n *main.Node, keep func(n *main.Node) bool) int", ({ kind: $.TypeKind.Function, params: [/* @__PURE__ */ $.pointerType("main.Node"), ({ kind: $.TypeKind.Function, params: [/* @__PURE__ */ $.pointerType("main.Node")], results: [/* @__PURE__ */ $.basicType("bool")] } as $.FunctionTypeInfo)], results: [/* @__PURE__ */ $.basicType("int")] } as $.FunctionTypeInfo))))).Call($.arrayToSlice([$.markAsStructValue($.cloneStructValue(reflect.ValueOf($.interfaceValue(root, "*main.Node", /* @__PURE__ */ $.pointerType("main.Node"))))), short])))!, 0))).Int()) // The method reached through an interface, and promoted from an embedded // pointer and an embedded interface. @@ -263,16 +263,16 @@ export async function main(): globalThis.Promise { await $.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(reflect.ValueOf($.interfaceValue(w, "*main.Walker", /* @__PURE__ */ $.pointerType("main.Walker"))))).Elem())).MethodByName("Walk"))).Call($.arrayToSlice([$.markAsStructValue($.cloneStructValue(visit))])) await $.println($.sliceLen(names)) names = null - await $.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(reflect.ValueOf($.interfaceValue(new Tree(false, $.arrayIndex((root$ as Node).Kids!, 1), "t"), "*main.Tree", /* @__PURE__ */ $.pointerType("main.Tree"))))).MethodByName("Walk"))).Call($.arrayToSlice([$.markAsStructValue($.cloneStructValue(visit))])) - await $.println($.sliceLen(names), $.arrayIndex(names!, 0)) + await $.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(reflect.ValueOf($.interfaceValue(new Tree(false, $.plainSliceIndex((root$ as Node).Kids!, 1), "t"), "*main.Tree", /* @__PURE__ */ $.pointerType("main.Tree"))))).MethodByName("Walk"))).Call($.arrayToSlice([$.markAsStructValue($.cloneStructValue(visit))])) + await $.println($.sliceLen(names), $.plainSliceIndex(names!, 0)) names = null - await $.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(reflect.ValueOf($.structInterfaceValue(new Doc(true, $.interfaceValue($.arrayIndex((root$ as Node).Kids!, 0), "*main.Node", /* @__PURE__ */ $.pointerType("main.Node"))), "main.Doc", "main.Doc")))).MethodByName("Walk"))).Call($.arrayToSlice([visit])) - await $.println($.sliceLen(names), $.arrayIndex(names!, 0)) + await $.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(reflect.ValueOf($.structInterfaceValue(new Doc(true, $.interfaceValue($.plainSliceIndex((root$ as Node).Kids!, 0), "*main.Node", /* @__PURE__ */ $.pointerType("main.Node"))), "main.Doc", "main.Doc")))).MethodByName("Walk"))).Call($.arrayToSlice([visit])) + await $.println($.sliceLen(names), $.plainSliceIndex(names!, 0)) // A function that reflection made, stored by a method that reflection // calls, is called later by compiled code. let label = $.markAsStructValue($.cloneStructValue(reflect.MakeFunc($.pointerValueOrNil(reflect.TypeFor(__goscriptStatic1()))!, $.functionValue((args: $.Slice): $.Slice => { - return $.arrayToSlice([$.markAsStructValue($.cloneStructValue(reflect.ValueOf("click " + $.runeToString($.intFromWide($.int64Add(48n, $.markAsStructValue($.cloneStructValue($.arrayIndex(args!, 0))).Int()), 32)))))]) + return $.arrayToSlice([$.markAsStructValue($.cloneStructValue(reflect.ValueOf("click " + $.runeToString($.intFromWide($.int64Add(48n, $.markAsStructValue($.cloneStructValue($.plainSliceIndex(args!, 0))).Int()), 32)))))]) }, ({ kind: $.TypeKind.Function, params: [/* @__PURE__ */ $.sliceType("reflect.Value")], results: [/* @__PURE__ */ $.sliceType("reflect.Value")] } as $.FunctionTypeInfo))))) let b = new Button() await $.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(reflect.ValueOf($.interfaceValue(b, "*main.Button", /* @__PURE__ */ $.pointerType("main.Button"))))).MethodByName("OnClick"))).Call($.arrayToSlice([label])) diff --git a/tests/tests/reflect_method_values/reflect_method_values.gs.ts b/tests/tests/reflect_method_values/reflect_method_values.gs.ts index 9efa32088..b3b3658aa 100644 --- a/tests/tests/reflect_method_values/reflect_method_values.gs.ts +++ b/tests/tests/reflect_method_values/reflect_method_values.gs.ts @@ -151,8 +151,8 @@ export async function main(): globalThis.Promise { // A method of a pointer held in a settable Value is called by index. let out = await $.markAsStructValue($.cloneStructValue(reflect.ValueOf($.interfaceValue($.goFunc(NewWidget, "main.NewWidget"), "func() *main.Widget", ({ kind: $.TypeKind.Function, params: [], results: [/* @__PURE__ */ $.pointerType("main.Widget")] } as $.FunctionTypeInfo))))).Call(null) - let slot = $.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(reflect.New($.pointerValueOrNil($.markAsStructValue($.cloneStructValue($.arrayIndex(out!, 0))).Type())!))).Elem())) - $.markAsStructValue($.cloneStructValue(slot)).Set($.markAsStructValue($.cloneStructValue($.arrayIndex(out!, 0)))) + let slot = $.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(reflect.New($.pointerValueOrNil($.markAsStructValue($.cloneStructValue($.plainSliceIndex(out!, 0))).Type())!))).Elem())) + $.markAsStructValue($.cloneStructValue(slot)).Set($.markAsStructValue($.cloneStructValue($.plainSliceIndex(out!, 0)))) let [m, ] = await (pt !== null && (pt as any).__isVarRef !== true && ((pt as any).__goValue === undefined || (pt as any).__goType?.charCodeAt(0) !== 42) ? (pt as Exclude) : $.pointerValue>(pt)).MethodByName("SetText") await $.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(slot)).Method(m.Index))).Call($.arrayToSlice([$.markAsStructValue($.cloneStructValue(reflect.ValueOf("abc")))])) fmt.Println("text", $.pointerValue($.mustTypeAssert | null>($.markAsStructValue($.cloneStructValue(slot)).Interface(), /* @__PURE__ */ $.pointerType("main.Widget"))).Text, $.basicInterfaceValue($.markAsStructValue($.cloneStructValue(slot)).NumMethod(), "int")) @@ -166,22 +166,22 @@ export async function main(): globalThis.Promise { // A variadic method takes its arguments one by one. let sum = $.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(slot)).MethodByName("Sum"))) - fmt.Println("variadic", (__goscriptAwait = $.pointerValue>($.markAsStructValue($.cloneStructValue(sum)).Type()).IsVariadic(), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait), $.basicInterfaceValue($.markAsStructValue($.cloneStructValue($.arrayIndex((await $.markAsStructValue($.cloneStructValue(sum)).Call($.arrayToSlice([$.markAsStructValue($.cloneStructValue(reflect.ValueOf(__goscriptStatic3()))), $.markAsStructValue($.cloneStructValue(reflect.ValueOf(__goscriptStatic4())))])))!, 0))).Int(), "int64")) + fmt.Println("variadic", (__goscriptAwait = $.pointerValue>($.markAsStructValue($.cloneStructValue(sum)).Type()).IsVariadic(), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait), $.basicInterfaceValue($.markAsStructValue($.cloneStructValue($.plainSliceIndex((await $.markAsStructValue($.cloneStructValue(sum)).Call($.arrayToSlice([$.markAsStructValue($.cloneStructValue(reflect.ValueOf(__goscriptStatic3()))), $.markAsStructValue($.cloneStructValue(reflect.ValueOf(__goscriptStatic4())))])))!, 0))).Int(), "int64")) // A method of a named int is bound to its value. let double = $.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(reflect.ValueOf(__goscriptStatic5()))).Method(0))) - fmt.Println("double", $.basicInterfaceValue($.markAsStructValue($.cloneStructValue($.arrayIndex((await $.markAsStructValue($.cloneStructValue(double)).Call(null))!, 0))).Int(), "int64")) + fmt.Println("double", $.basicInterfaceValue($.markAsStructValue($.cloneStructValue($.plainSliceIndex((await $.markAsStructValue($.cloneStructValue(double)).Call(null))!, 0))).Int(), "int64")) // A func stored in a settable Value can be called. let fn = $.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(reflect.New($.pointerValueOrNil(reflect.TypeOf($.interfaceValue($.goFunc(strings.ToUpper, "strings.ToUpper"), "func(s string) string", ({ kind: $.TypeKind.Function, params: [/* @__PURE__ */ $.basicType("string")], results: [/* @__PURE__ */ $.basicType("string")] } as $.FunctionTypeInfo))))!))).Elem())) $.markAsStructValue($.cloneStructValue(fn)).Set($.markAsStructValue($.cloneStructValue(reflect.ValueOf($.interfaceValue($.goFunc(strings.ToUpper, "strings.ToUpper"), "func(s string) string", ({ kind: $.TypeKind.Function, params: [/* @__PURE__ */ $.basicType("string")], results: [/* @__PURE__ */ $.basicType("string")] } as $.FunctionTypeInfo)))))) - fmt.Println("func", $.markAsStructValue($.cloneStructValue($.arrayIndex((await $.markAsStructValue($.cloneStructValue(fn)).Call($.arrayToSlice([$.markAsStructValue($.cloneStructValue(reflect.ValueOf("up")))])))!, 0))).String()) + fmt.Println("func", $.markAsStructValue($.cloneStructValue($.plainSliceIndex((await $.markAsStructValue($.cloneStructValue(fn)).Call($.arrayToSlice([$.markAsStructValue($.cloneStructValue(reflect.ValueOf("up")))])))!, 0))).String()) // Method and SelectCase values are copied as structs. let methods = $.arrayToSlice([$.markAsStructValue($.cloneStructValue(((__goscriptAwait = (pt !== null && (pt as any).__isVarRef !== true && ((pt as any).__goValue === undefined || (pt as any).__goType?.charCodeAt(0) !== 42) ? (pt as Exclude) : $.pointerValue>(pt)).Method(0), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait) as reflect.Method)))]) - let first = $.markAsStructValue($.cloneStructValue($.arrayIndex(methods!, 0))) + let first = $.markAsStructValue($.cloneStructValue($.plainSliceIndex(methods!, 0))) let cases = $.arrayToSlice([$.markAsStructValue(new reflect.SelectCase({Dir: 3}))]) - let c = $.markAsStructValue($.cloneStructValue($.arrayIndex(cases!, 0))) + let c = $.markAsStructValue($.cloneStructValue($.plainSliceIndex(cases!, 0))) fmt.Println("copies", first.Name, c.Dir == 3) // FieldByIndex steps through an embedded struct pointer. @@ -201,9 +201,9 @@ export async function main(): globalThis.Promise { let mf = $.markAsStructValue($.cloneStructValue(reflect.MakeFunc($.pointerValueOrNil(reflect.TypeOf($.interfaceValue($.functionValue((_p0: Widget | $.VarRef | null): string => { return "" }, ({ kind: $.TypeKind.Function, params: [/* @__PURE__ */ $.pointerType("main.Widget")], results: [/* @__PURE__ */ $.basicType("string")] } as $.FunctionTypeInfo)), "func(*main.Widget) string", ({ kind: $.TypeKind.Function, params: [/* @__PURE__ */ $.pointerType("main.Widget")], results: [/* @__PURE__ */ $.basicType("string")] } as $.FunctionTypeInfo))))!, $.functionValue((args: $.Slice): $.Slice => { - return $.arrayToSlice([$.markAsStructValue($.cloneStructValue(reflect.ValueOf(($.pointerValue>($.markAsStructValue($.cloneStructValue($.arrayIndex(args!, 0))).Type()).String() as string))))]) + return $.arrayToSlice([$.markAsStructValue($.cloneStructValue(reflect.ValueOf(($.pointerValue>($.markAsStructValue($.cloneStructValue($.plainSliceIndex(args!, 0))).Type()).String() as string))))]) }, ({ kind: $.TypeKind.Function, params: [/* @__PURE__ */ $.sliceType("reflect.Value")], results: [/* @__PURE__ */ $.sliceType("reflect.Value")] } as $.FunctionTypeInfo))))) - fmt.Println("makefunc", $.markAsStructValue($.cloneStructValue($.arrayIndex((await $.markAsStructValue($.cloneStructValue(mf)).Call($.arrayToSlice([$.markAsStructValue($.cloneStructValue(reflect.ValueOf($.interfaceValue(new Widget(), "*main.Widget", /* @__PURE__ */ $.pointerType("main.Widget")))))])))!, 0))).String()) + fmt.Println("makefunc", $.markAsStructValue($.cloneStructValue($.plainSliceIndex((await $.markAsStructValue($.cloneStructValue(mf)).Call($.arrayToSlice([$.markAsStructValue($.cloneStructValue(reflect.ValueOf($.interfaceValue(new Widget(), "*main.Widget", /* @__PURE__ */ $.pointerType("main.Widget")))))])))!, 0))).String()) } var __goscriptStatic0$value: any diff --git a/tests/tests/reflect_named_composite_type_methods/reflect_named_composite_type_methods.gs.ts b/tests/tests/reflect_named_composite_type_methods/reflect_named_composite_type_methods.gs.ts index 97736f861..cd484f5ac 100644 --- a/tests/tests/reflect_named_composite_type_methods/reflect_named_composite_type_methods.gs.ts +++ b/tests/tests/reflect_named_composite_type_methods/reflect_named_composite_type_methods.gs.ts @@ -194,7 +194,7 @@ export async function main(): globalThis.Promise { } export function Names_First(n: Names): string { - return $.arrayIndex(n!, 0) + return $.plainSliceIndex(n!, 0) } export function Grid_Sum(g: Grid): number { diff --git a/tests/tests/reflect_nil_slice_interface/reflect_nil_slice_interface.gs.ts b/tests/tests/reflect_nil_slice_interface/reflect_nil_slice_interface.gs.ts index 9785fcfea..76e757530 100644 --- a/tests/tests/reflect_nil_slice_interface/reflect_nil_slice_interface.gs.ts +++ b/tests/tests/reflect_nil_slice_interface/reflect_nil_slice_interface.gs.ts @@ -108,7 +108,7 @@ export async function main(): globalThis.Promise { let kp: $.VarRef<$.Slice | null>> | null = __goscriptTuple0[0] ok = __goscriptTuple0[1] kp!.value = $.appendOne($.pointerValue<$.Slice | null>>(kp), new S1(false, "x"), $.appendZeros.nil) - await $.println("addr assert:", ok, $.sliceLen(v.value.K), $.pointerValue($.arrayIndex(v.value.K!, 0)).Name) + await $.println("addr assert:", ok, $.sliceLen(v.value.K), $.pointerValue($.plainSliceIndex(v.value.K!, 0)).Name) // Unnamed basic, array and slice values keep their types. await show2("int", $.markAsStructValue($.cloneStructValue(reflect.ValueOf($.basicInterfaceValue(3, "int"))))) diff --git a/tests/tests/reflect_number_interface/reflect_number_interface.gs.ts b/tests/tests/reflect_number_interface/reflect_number_interface.gs.ts index 8d4dda7f9..216cf4fdc 100644 --- a/tests/tests/reflect_number_interface/reflect_number_interface.gs.ts +++ b/tests/tests/reflect_number_interface/reflect_number_interface.gs.ts @@ -53,8 +53,8 @@ export async function main(): globalThis.Promise { await $.println(kind($.markAsStructValue($.cloneStructValue(i)).Interface()), isFloat32) // The same for arguments of interface type passed by Call. - await $.println($.markAsStructValue($.cloneStructValue($.arrayIndex((await $.markAsStructValue($.cloneStructValue(reflect.ValueOf($.interfaceValue($.goFunc(kind, "main.kind"), "func(v any) string", ({ kind: $.TypeKind.Function, params: [{ kind: $.TypeKind.Interface, methods: [] }], results: [/* @__PURE__ */ $.basicType("string")] } as $.FunctionTypeInfo))))).Call($.arrayToSlice([$.markAsStructValue($.cloneStructValue(v))])))!, 0))).String()) - await $.println($.markAsStructValue($.cloneStructValue($.arrayIndex((await $.markAsStructValue($.cloneStructValue(reflect.ValueOf($.interfaceValue($.goFunc(kinds, "main.kinds"), "func(vals ...any) string", ({ kind: $.TypeKind.Function, params: [/* @__PURE__ */ $.sliceType({ kind: $.TypeKind.Interface, methods: [] })], results: [/* @__PURE__ */ $.basicType("string")], isVariadic: true } as $.FunctionTypeInfo))))).Call($.arrayToSlice([$.markAsStructValue($.cloneStructValue(v)), $.markAsStructValue($.cloneStructValue(reflect.ValueOf($.basicInterfaceValue(1, "int"))))])))!, 0))).String()) + await $.println($.markAsStructValue($.cloneStructValue($.plainSliceIndex((await $.markAsStructValue($.cloneStructValue(reflect.ValueOf($.interfaceValue($.goFunc(kind, "main.kind"), "func(v any) string", ({ kind: $.TypeKind.Function, params: [{ kind: $.TypeKind.Interface, methods: [] }], results: [/* @__PURE__ */ $.basicType("string")] } as $.FunctionTypeInfo))))).Call($.arrayToSlice([$.markAsStructValue($.cloneStructValue(v))])))!, 0))).String()) + await $.println($.markAsStructValue($.cloneStructValue($.plainSliceIndex((await $.markAsStructValue($.cloneStructValue(reflect.ValueOf($.interfaceValue($.goFunc(kinds, "main.kinds"), "func(vals ...any) string", ({ kind: $.TypeKind.Function, params: [/* @__PURE__ */ $.sliceType({ kind: $.TypeKind.Interface, methods: [] })], results: [/* @__PURE__ */ $.basicType("string")], isVariadic: true } as $.FunctionTypeInfo))))).Call($.arrayToSlice([$.markAsStructValue($.cloneStructValue(v)), $.markAsStructValue($.cloneStructValue(reflect.ValueOf($.basicInterfaceValue(1, "int"))))])))!, 0))).String()) // And for values stored in interface elements, fields and map values. let s = $.markAsStructValue($.cloneStructValue(reflect.MakeSlice($.pointerValueOrNil(reflect.TypeFor(__goscriptStatic3()))!, 1, 1))) diff --git a/tests/tests/reflect_set_bytes/reflect_set_bytes.gs.ts b/tests/tests/reflect_set_bytes/reflect_set_bytes.gs.ts index 3cf4d85b2..bd8a51b68 100644 --- a/tests/tests/reflect_set_bytes/reflect_set_bytes.gs.ts +++ b/tests/tests/reflect_set_bytes/reflect_set_bytes.gs.ts @@ -57,7 +57,7 @@ export async function main(): globalThis.Promise { // Set an element of a slice of byte slices. d.value.Parts = $.makeSlice<$.Slice>(2) $.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(dv)).Field(2))).Index(1))).SetBytes(new Uint8Array([112, 97, 114, 116])) - await $.println("Parts:", $.sliceLen($.arrayIndex(d.value.Parts!, 0)), $.bytesToString($.arrayIndex(d.value.Parts!, 1))) + await $.println("Parts:", $.sliceLen($.plainSliceIndex(d.value.Parts!, 0)), $.bytesToString($.plainSliceIndex(d.value.Parts!, 1))) // Set a byte slice variable through a pointer. let b: $.VarRef<$.Slice> = $.varRef(null! as $.Slice) diff --git a/tests/tests/reflect_slice_at/reflect_slice_at.gs.ts b/tests/tests/reflect_slice_at/reflect_slice_at.gs.ts index f6c4f4393..dbce4c74b 100644 --- a/tests/tests/reflect_slice_at/reflect_slice_at.gs.ts +++ b/tests/tests/reflect_slice_at/reflect_slice_at.gs.ts @@ -147,12 +147,12 @@ export async function main(): globalThis.Promise { await $.println("bytes:", $.markAsStructValue($.cloneStructValue(bytes)).Len(), $.markAsStructValue($.cloneStructValue(bytes)).Cap(), $.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(bytes)).Index(0))).Uint(), $.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(bytes)).Index(1))).Uint()) $.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(bytes)).Index(0))).SetUint(9n) $.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(bytes)).Index(1))).SetUint(8n) - await $.println("buf:", $.arrayIndex(buf!, 0), $.arrayIndex(buf!, 1), $.arrayIndex(buf!, 2), $.arrayIndex(buf!, 3)) + await $.println("buf:", $.typedSliceIndex(buf!, 0), $.typedSliceIndex(buf!, 1), $.typedSliceIndex(buf!, 2), $.typedSliceIndex(buf!, 3)) let ints = $.arrayToSlice([10, 20, 30, 40]) let intSlice = $.markAsStructValue($.cloneStructValue(reflect.SliceAt($.pointerValueOrNil(reflect.TypeFor(__goscriptStatic0()))!, ($.indexRef(ints!, 1) as any), 2))) $.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(intSlice)).Index(1))).SetInt(77n) - await $.println("ints:", $.arrayIndex(ints!, 0), $.arrayIndex(ints!, 1), $.arrayIndex(ints!, 2), $.arrayIndex(ints!, 3), $.markAsStructValue($.cloneStructValue(intSlice)).Len(), $.markAsStructValue($.cloneStructValue(intSlice)).Cap()) + await $.println("ints:", $.plainSliceIndex(ints!, 0), $.plainSliceIndex(ints!, 1), $.plainSliceIndex(ints!, 2), $.plainSliceIndex(ints!, 3), $.markAsStructValue($.cloneStructValue(intSlice)).Len(), $.markAsStructValue($.cloneStructValue(intSlice)).Cap()) let empty = $.markAsStructValue($.cloneStructValue(reflect.SliceAt($.pointerValueOrNil(reflect.TypeFor(__goscriptStatic0()))!, (null as any), 0))) await $.println("empty:", $.markAsStructValue($.cloneStructValue(empty)).IsNil(), $.markAsStructValue($.cloneStructValue(empty)).Len(), $.markAsStructValue($.cloneStructValue(empty)).Cap()) diff --git a/tests/tests/reflect_slice_map_ops/reflect_slice_map_ops.gs.ts b/tests/tests/reflect_slice_map_ops/reflect_slice_map_ops.gs.ts index 3bc7652ec..376c7d793 100644 --- a/tests/tests/reflect_slice_map_ops/reflect_slice_map_ops.gs.ts +++ b/tests/tests/reflect_slice_map_ops/reflect_slice_map_ops.gs.ts @@ -112,7 +112,7 @@ export async function main(): globalThis.Promise { // Copy copies within the lengths of the slices. let c = $.arrayToSlice([1, 2, 3, 4]) let copied = reflect.Copy($.markAsStructValue($.cloneStructValue(reflect.ValueOf($.interfaceValue($.goSlice(c, 2, undefined), "[]int", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("int")))))), $.markAsStructValue($.cloneStructValue(reflect.ValueOf($.interfaceValue($.arrayToSlice([8, 9, 10]), "[]int", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("int"))))))) - await $.println(copied, $.arrayIndex(c!, 0), $.arrayIndex(c!, 2), $.arrayIndex(c!, 3)) + await $.println(copied, $.plainSliceIndex(c!, 0), $.plainSliceIndex(c!, 2), $.plainSliceIndex(c!, 3)) // Values read after a Set through the same Value see the new contents. let m: $.VarRef | null> = $.varRef($.makeMap([["old", 0]])) @@ -124,7 +124,7 @@ export async function main(): globalThis.Promise { let tv = $.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(reflect.ValueOf($.interfaceValue(t, "*[]int", /* @__PURE__ */ $.pointerType(/* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("int"))))))).Elem())) $.markAsStructValue($.cloneStructValue(tv)).Set($.markAsStructValue($.cloneStructValue(reflect.MakeSlice($.pointerValueOrNil(reflect.TypeFor(__goscriptStatic1()))!, 2, 2)))) $.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(tv)).Index(1))).SetInt(4n) - await $.println($.arrayIndex(t.value!, 1), $.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(tv)).Slice(1, 2))).Index(0))).Int()) + await $.println($.plainSliceIndex(t.value!, 1), $.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(tv)).Slice(1, 2))).Index(0))).Int()) // Grow then SetLen, as encoding/xml and encoding/json do. let h = new Holder(false, undefined, $.makeSlice(1, 10, "number")) @@ -136,7 +136,7 @@ export async function main(): globalThis.Promise { $.markAsStructValue($.cloneStructValue(hs)).SetLen(__goscriptShadow0 + 1) $.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(hs)).Index(__goscriptShadow0))).SetInt($.int64(i * 10)) } - await $.println("grown:", $.sliceLen((h$ as Holder).S), $.arrayIndex((h$ as Holder).S!, 0), $.arrayIndex((h$ as Holder).S!, 4), $.cap((h$ as Holder).S) >= 5) + await $.println("grown:", $.sliceLen((h$ as Holder).S), $.plainSliceIndex((h$ as Holder).S!, 0), $.plainSliceIndex((h$ as Holder).S!, 4), $.cap((h$ as Holder).S) >= 5) // Grow keeps capacity when it is already large enough. let ht = $.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(reflect.ValueOf($.interfaceValue(h, "*main.Holder", /* @__PURE__ */ $.pointerType("main.Holder"))))).Elem())).Field(1))) @@ -152,13 +152,13 @@ export async function main(): globalThis.Promise { // MakeSlice of bytes. let bs = $.markAsStructValue($.cloneStructValue(reflect.MakeSlice($.pointerValueOrNil(reflect.TypeFor(__goscriptStatic3()))!, 3, 3))) $.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(bs)).Index(1))).SetUint(7n) - await $.println("bytes:", $.sliceLen($.markAsStructValue($.cloneStructValue(bs)).Bytes()), $.uint($.arrayIndex($.markAsStructValue($.cloneStructValue(bs)).Bytes()!, 1), 8)) + await $.println("bytes:", $.sliceLen($.markAsStructValue($.cloneStructValue(bs)).Bytes()), $.uint($.typedSliceIndex($.markAsStructValue($.cloneStructValue(bs)).Bytes()!, 1), 8)) let d: $.VarRef = $.varRef(new Doc(true)) let err = await xml.Unmarshal(new Uint8Array([60, 100, 111, 99, 62, 60, 105, 116, 101, 109, 62, 60, 78, 97, 109, 101, 62, 120, 60, 47, 78, 97, 109, 101, 62, 60, 47, 105, 116, 101, 109, 62, 60, 105, 116, 101, 109, 62, 60, 78, 97, 109, 101, 62, 121, 60, 47, 78, 97, 109, 101, 62, 60, 47, 105, 116, 101, 109, 62, 60, 47, 100, 111, 99, 62]), $.interfaceValue(d, "*main.Doc", /* @__PURE__ */ $.pointerType("main.Doc"))) await $.println("xml:", err == null, $.sliceLen(d.value.Items)) if ($.sliceLen(d.value.Items) == 2) { - await $.println("xml items:", $.arrayIndex(d.value.Items!, 0).Name, $.arrayIndex(d.value.Items!, 1).Name) + await $.println("xml items:", $.plainSliceIndex(d.value.Items!, 0).Name, $.plainSliceIndex(d.value.Items!, 1).Name) } } diff --git a/tests/tests/reflect_struct_field_go_types/reflect_struct_field_go_types.gs.ts b/tests/tests/reflect_struct_field_go_types/reflect_struct_field_go_types.gs.ts index 992a927a3..969b91054 100644 --- a/tests/tests/reflect_struct_field_go_types/reflect_struct_field_go_types.gs.ts +++ b/tests/tests/reflect_struct_field_go_types/reflect_struct_field_go_types.gs.ts @@ -111,7 +111,7 @@ export async function main(): globalThis.Promise { // Index is a []int that can be appended to. let [_of, ] = await $.pointerValue>(reflect.TypeOf($.structInterfaceValue(new Outer(true), "main.Outer", "main.Outer"))).FieldByName("X") _of.Index = $.appendSlice($.arrayToSlice([9]), _of.Index) - await $.println($.sliceLen(_of.Index), $.arrayIndex(_of.Index!, 0), $.arrayIndex(_of.Index!, 1), $.arrayIndex(_of.Index!, 2)) + await $.println($.sliceLen(_of.Index), $.plainSliceIndex(_of.Index!, 0), $.plainSliceIndex(_of.Index!, 1), $.plainSliceIndex(_of.Index!, 2)) // Value.FieldByNameFunc finds a field by a name predicate. let val = $.markAsStructValue($.cloneStructValue(reflect.ValueOf($.structInterfaceValue(new Outer(true, new Inner(true, 5), "n"), "main.Outer", "main.Outer")))) diff --git a/tests/tests/reflect_struct_of/reflect_struct_of.gs.ts b/tests/tests/reflect_struct_of/reflect_struct_of.gs.ts index 2110ba235..5eaec30f2 100644 --- a/tests/tests/reflect_struct_of/reflect_struct_of.gs.ts +++ b/tests/tests/reflect_struct_of/reflect_struct_of.gs.ts @@ -27,12 +27,12 @@ export async function main(): globalThis.Promise { await $.println("json:", $.bytesToString(data)) let layout = reflect.StructOf($.arrayToSlice([$.markAsStructValue(new reflect.StructField({Name: "A", Type: byteType})), $.markAsStructValue(new reflect.StructField({Name: "B", Type: intType}))])) - await $.println("layout:", ((__goscriptAwait = (layout !== null && (layout as any).__isVarRef !== true && ((layout as any).__goValue === undefined || (layout as any).__goType?.charCodeAt(0) !== 42) ? (layout as Exclude) : $.pointerValue>(layout)).Field(0), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait) as reflect.StructField).Offset, ((__goscriptAwait = (layout !== null && (layout as any).__isVarRef !== true && ((layout as any).__goValue === undefined || (layout as any).__goType?.charCodeAt(0) !== 42) ? (layout as Exclude) : $.pointerValue>(layout)).Field(1), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait) as reflect.StructField).Offset, (__goscriptAwait = (layout !== null && (layout as any).__isVarRef !== true && ((layout as any).__goValue === undefined || (layout as any).__goType?.charCodeAt(0) !== 42) ? (layout as Exclude) : $.pointerValue>(layout)).Size(), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait), $.arrayIndex(((__goscriptAwait = (layout !== null && (layout as any).__isVarRef !== true && ((layout as any).__goValue === undefined || (layout as any).__goType?.charCodeAt(0) !== 42) ? (layout as Exclude) : $.pointerValue>(layout)).Field(0), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait) as reflect.StructField).Index!, 0)) + await $.println("layout:", ((__goscriptAwait = (layout !== null && (layout as any).__isVarRef !== true && ((layout as any).__goValue === undefined || (layout as any).__goType?.charCodeAt(0) !== 42) ? (layout as Exclude) : $.pointerValue>(layout)).Field(0), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait) as reflect.StructField).Offset, ((__goscriptAwait = (layout !== null && (layout as any).__isVarRef !== true && ((layout as any).__goValue === undefined || (layout as any).__goType?.charCodeAt(0) !== 42) ? (layout as Exclude) : $.pointerValue>(layout)).Field(1), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait) as reflect.StructField).Offset, (__goscriptAwait = (layout !== null && (layout as any).__isVarRef !== true && ((layout as any).__goValue === undefined || (layout as any).__goType?.charCodeAt(0) !== 42) ? (layout as Exclude) : $.pointerValue>(layout)).Size(), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait), $.plainSliceIndex(((__goscriptAwait = (layout !== null && (layout as any).__isVarRef !== true && ((layout as any).__goValue === undefined || (layout as any).__goType?.charCodeAt(0) !== 42) ? (layout as Exclude) : $.pointerValue>(layout)).Field(0), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait) as reflect.StructField).Index!, 0)) let inner = reflect.StructOf($.arrayToSlice([$.markAsStructValue(new reflect.StructField({Name: "ID", Type: intType})), $.markAsStructValue(new reflect.StructField({Name: "Label", Type: stringType}))])) let outer = reflect.StructOf($.arrayToSlice([$.markAsStructValue(new reflect.StructField({Name: "Inner", Type: inner, Anonymous: true})), $.markAsStructValue(new reflect.StructField({Name: "Count", Type: intType}))])) let visible = reflect.VisibleFields($.pointerValueOrNil(outer)!) - await $.println("visible:", $.sliceLen(visible), $.arrayIndex(visible!, 0).Name, $.sliceLen($.arrayIndex(visible!, 1).Index), $.arrayIndex($.arrayIndex(visible!, 1).Index!, 0), $.arrayIndex($.arrayIndex(visible!, 1).Index!, 1)) + await $.println("visible:", $.sliceLen(visible), $.plainSliceIndex(visible!, 0).Name, $.sliceLen($.plainSliceIndex(visible!, 1).Index), $.plainSliceIndex($.plainSliceIndex(visible!, 1).Index!, 0), $.plainSliceIndex($.plainSliceIndex(visible!, 1).Index!, 1)) let outerValue = $.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(reflect.New($.pointerValueOrNil(outer)!))).Elem())) $.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(outerValue)).FieldByIndex($.arrayToSlice([0, 0])))).SetInt(9n) diff --git a/tests/tests/reflect_value_methods_more/reflect_value_methods_more.gs.ts b/tests/tests/reflect_value_methods_more/reflect_value_methods_more.gs.ts index 2c129d1c3..b2b73fbd6 100644 --- a/tests/tests/reflect_value_methods_more/reflect_value_methods_more.gs.ts +++ b/tests/tests/reflect_value_methods_more/reflect_value_methods_more.gs.ts @@ -61,7 +61,7 @@ export async function main(): globalThis.Promise { let sv = $.markAsStructValue($.cloneStructValue($.markAsStructValue($.cloneStructValue(reflect.ValueOf($.interfaceValue(s, "*[]int", /* @__PURE__ */ $.pointerType(/* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("int"))))))).Elem())) $.markAsStructValue($.cloneStructValue(sv)).Clear() $.markAsStructValue($.cloneStructValue(sv)).SetCap(4) - await $.println("clear:", $.len(m), $.arrayIndex(s.value!, 0), $.sliceLen(s.value), $.cap(s.value)) + await $.println("clear:", $.len(m), $.plainSliceIndex(s.value!, 0), $.sliceLen(s.value), $.cap(s.value)) // Fields and Methods iterate with names and values. let p = new pair(true, 1, "xy") @@ -78,7 +78,7 @@ export async function main(): globalThis.Promise { let __goscriptRangeReturn1 = false ;await (async () => { await $.markAsStructValue($.cloneStructValue(reflect.ValueOf($.structInterfaceValue((p).clone(), "main.pair", "main.pair")))).Methods()!(async (meth, v) => { - await $.println("method:", meth.Name, $.markAsStructValue($.cloneStructValue($.arrayIndex((await $.markAsStructValue($.cloneStructValue(v)).Call(null))!, 0))).Int()) + await $.println("method:", meth.Name, $.markAsStructValue($.cloneStructValue($.plainSliceIndex((await $.markAsStructValue($.cloneStructValue(v)).Call(null))!, 0))).Int()) return true }) })() diff --git a/tests/tests/runtime_caller_callsite/runtime_caller_callsite.gs.ts b/tests/tests/runtime_caller_callsite/runtime_caller_callsite.gs.ts index debce8f6d..9cf2c15ff 100644 --- a/tests/tests/runtime_caller_callsite/runtime_caller_callsite.gs.ts +++ b/tests/tests/runtime_caller_callsite/runtime_caller_callsite.gs.ts @@ -31,7 +31,7 @@ export async function main(): globalThis.Promise { // Calls the chain does not reach still find a frame. let add: ((names: $.VarRef<$.Slice> | null, init: (() => void) | null) => void) | null = subpkg.Add add!(names, (null as (() => void) | null)) - await $.println("value call named:", !$.stringEqual($.arrayIndex(names.value!, $.sliceLen(names.value) - 1), "")) + await $.println("value call named:", !$.stringEqual($.plainSliceIndex(names.value!, $.sliceLen(names.value) - 1), "")) await $.println("unmarked named:", !$.stringEqual(subpkg.Unmarked(), "")) } diff --git a/tests/tests/shadowed_struct_varref_field/shadowed_struct_varref_field.gs.ts b/tests/tests/shadowed_struct_varref_field/shadowed_struct_varref_field.gs.ts index 03d62a41e..3aa7701e5 100644 --- a/tests/tests/shadowed_struct_varref_field/shadowed_struct_varref_field.gs.ts +++ b/tests/tests/shadowed_struct_varref_field/shadowed_struct_varref_field.gs.ts @@ -117,11 +117,11 @@ export function lookupLocal(addr: string): $.Slice { } export async function main(): globalThis.Promise { - await $.println($.arrayIndex(lookupLocal("127.0.0.1")!, 0)) + await $.println($.plainSliceIndex(lookupLocal("127.0.0.1")!, 0)) hosts.value.byAddr = $.makeMap>([["127.0.0.1", $.arrayToSlice(["localhost"])]]) named.value.byAddr = hosts.value.byAddr - await $.println($.arrayIndex(lookup("127.0.0.1")!, 0)) - await $.println($.arrayIndex(lookupNamed("127.0.0.1")!, 0)) + await $.println($.plainSliceIndex(lookup("127.0.0.1")!, 0)) + await $.println($.plainSliceIndex(lookupNamed("127.0.0.1")!, 0)) await $.println($.sliceLen(lookup("::1"))) } diff --git a/tests/tests/short_decl_shadow_builtin/short_decl_shadow_builtin.gs.ts b/tests/tests/short_decl_shadow_builtin/short_decl_shadow_builtin.gs.ts index 70792e6c8..532f5da88 100644 --- a/tests/tests/short_decl_shadow_builtin/short_decl_shadow_builtin.gs.ts +++ b/tests/tests/short_decl_shadow_builtin/short_decl_shadow_builtin.gs.ts @@ -8,7 +8,7 @@ export function last(a: $.Slice): number { for (let __goscriptSliceWindow0 = $.sliceRange(a), i = 0; i < __goscriptShadow0; i++) { ;(__goscriptSliceWindow0.backing as any[])[$.windowSlot(__goscriptSliceWindow0, i + 1)] += ((__goscriptSliceWindow0.backing as any[])[$.windowSlot(__goscriptSliceWindow0, i)] as number) } - return $.arrayIndex(a!, __goscriptShadow0) + return $.plainSliceIndex(a!, __goscriptShadow0) } export function capacity(a: $.Slice): number { diff --git a/tests/tests/slice/slice.gs.ts b/tests/tests/slice/slice.gs.ts index 37b7a5b91..72d3240d6 100644 --- a/tests/tests/slice/slice.gs.ts +++ b/tests/tests/slice/slice.gs.ts @@ -21,9 +21,9 @@ export async function main(): globalThis.Promise { $.sliceElems(s!)[$.sliceSlot(s!, 4)] = 20 $.sliceElems(s2!)[$.sliceSlot(s2!, 1)] = "hello" - await $.println($.arrayIndex(s!, 0)) - await $.println($.arrayIndex(s!, 4)) - await $.println($.arrayIndex(s2!, 1)) + await $.println($.plainSliceIndex(s!, 0)) + await $.println($.plainSliceIndex(s!, 4)) + await $.println($.plainSliceIndex(s2!, 1)) // --- New Tests --- await $.println("--- New Tests ---") @@ -33,23 +33,23 @@ export async function main(): globalThis.Promise { let sliceFromLit = $.goSlice(arrLit, undefined, undefined) await $.println($.sliceLen(sliceFromLit)) await $.println($.cap(sliceFromLit)) - await $.println($.arrayIndex(sliceFromLit!, 0)) - await $.println($.arrayIndex(sliceFromLit!, 4)) + await $.println($.plainSliceIndex(sliceFromLit!, 0)) + await $.println($.plainSliceIndex(sliceFromLit!, 4)) // Create slice from array variable let arrVar = $.arrayValue(["a", "b", "c", "d"]) let sliceFromVar = $.goSlice(arrVar, undefined, undefined) await $.println($.sliceLen(sliceFromVar)) await $.println($.cap(sliceFromVar)) - await $.println($.arrayIndex(sliceFromVar!, 0)) - await $.println($.arrayIndex(sliceFromVar!, 3)) + await $.println($.plainSliceIndex(sliceFromVar!, 0)) + await $.println($.plainSliceIndex(sliceFromVar!, 3)) // Create slice with specific indices let sliceIndices = $.goSlice(arrVar, 1, 3) await $.println($.sliceLen(sliceIndices)) await $.println($.cap(sliceIndices)) - await $.println($.arrayIndex(sliceIndices!, 0)) - await $.println($.arrayIndex(sliceIndices!, 1)) + await $.println($.plainSliceIndex(sliceIndices!, 0)) + await $.println($.plainSliceIndex(sliceIndices!, 1)) // Create slice with 0 len/cap and append await $.println("--- Zero len/cap append ---") @@ -59,11 +59,11 @@ export async function main(): globalThis.Promise { zeroSlice = $.appendOne(zeroSlice, 100) await $.println($.sliceLen(zeroSlice)) await $.println($.cap(zeroSlice)) - await $.println($.arrayIndex(zeroSlice!, 0)) + await $.println($.plainSliceIndex(zeroSlice!, 0)) zeroSlice = $.appendOne(zeroSlice, 200) await $.println($.sliceLen(zeroSlice)) await $.println($.cap(zeroSlice)) - await $.println($.arrayIndex(zeroSlice!, 1)) + await $.println($.plainSliceIndex(zeroSlice!, 1)) // Modify slice, check original array await $.println("--- Modify slice, check array ---") @@ -71,13 +71,13 @@ export async function main(): globalThis.Promise { let modSlice = $.goSlice(modArr, undefined, undefined) $.sliceElems(modSlice!)[$.sliceSlot(modSlice!, 1)] = 25 await $.println(modArr[1]) - await $.println($.arrayIndex(modSlice!, 1)) + await $.println($.plainSliceIndex(modSlice!, 1)) // Modify array, check slice await $.println("--- Modify array, check slice ---") modArr[0] = 15 await $.println(modArr[0]) - await $.println($.arrayIndex(modSlice!, 0)) + await $.println($.plainSliceIndex(modSlice!, 0)) // Append to sub-slice within capacity await $.println("--- Append sub-slice w/in capacity ---") @@ -88,7 +88,7 @@ export async function main(): globalThis.Promise { let appendSlice2 = $.appendOne(appendSlice1, 99) await $.println($.sliceLen(appendSlice2)) await $.println($.cap(appendSlice2)) - await $.println($.arrayIndex(appendSlice2!, 2)) + await $.println($.plainSliceIndex(appendSlice2!, 2)) await $.println(appendArr[2]) // Append to sub-slice exceeding capacity @@ -99,9 +99,9 @@ export async function main(): globalThis.Promise { let appendSlice4 = $.appendOne(appendSlice3, 101) await $.println($.sliceLen(appendSlice4)) await $.println($.cap(appendSlice4)) - await $.println($.arrayIndex(appendSlice4!, 0)) - await $.println($.arrayIndex(appendSlice4!, 1)) - await $.println($.arrayIndex(appendSlice4!, 2)) + await $.println($.plainSliceIndex(appendSlice4!, 0)) + await $.println($.plainSliceIndex(appendSlice4!, 1)) + await $.println($.plainSliceIndex(appendSlice4!, 2)) // Original array should NOT be modified beyond its bounds by this append await $.println(appendArr[0]) await $.println(appendArr[1]) @@ -115,15 +115,15 @@ export async function main(): globalThis.Promise { let subSlice1 = $.goSlice(baseSlice, 1, 4) await $.println($.sliceLen(subSlice1)) await $.println($.cap(subSlice1)) - await $.println($.arrayIndex(subSlice1!, 0)) + await $.println($.plainSliceIndex(subSlice1!, 0)) let subSlice2 = $.goSlice(subSlice1, 1, 3) await $.println($.sliceLen(subSlice2)) await $.println($.cap(subSlice2)) - await $.println($.arrayIndex(subSlice2!, 0)) - await $.println($.arrayIndex(subSlice2!, 1)) + await $.println($.plainSliceIndex(subSlice2!, 0)) + await $.println($.plainSliceIndex(subSlice2!, 1)) $.sliceElems(subSlice2!)[$.sliceSlot(subSlice2!, 0)] = 22 - await $.println($.arrayIndex(subSlice1!, 1)) - await $.println($.arrayIndex(baseSlice!, 2)) + await $.println($.plainSliceIndex(subSlice1!, 1)) + await $.println($.plainSliceIndex(baseSlice!, 2)) // Three-index slicing (if supported) - Check capacity await $.println("--- Three-index slicing ---") @@ -131,19 +131,19 @@ export async function main(): globalThis.Promise { let threeIndexSlice: $.Slice = $.goSlice(threeIndexArr, 1, 3, 4) await $.println($.sliceLen(threeIndexSlice)) await $.println($.cap(threeIndexSlice)) - await $.println($.arrayIndex(threeIndexSlice!, 0)) - await $.println($.arrayIndex(threeIndexSlice!, 1)) + await $.println($.plainSliceIndex(threeIndexSlice!, 0)) + await $.println($.plainSliceIndex(threeIndexSlice!, 1)) // Appending should modify original array up to new capacity limit threeIndexSlice = $.appendOne(threeIndexSlice, 99) await $.println($.sliceLen(threeIndexSlice)) await $.println($.cap(threeIndexSlice)) - await $.println($.arrayIndex(threeIndexSlice!, 2)) + await $.println($.plainSliceIndex(threeIndexSlice!, 2)) await $.println(threeIndexArr[3]) // Appending again should reallocate threeIndexSlice = $.appendOne(threeIndexSlice, 101) await $.println($.sliceLen(threeIndexSlice)) await $.println($.cap(threeIndexSlice)) - await $.println($.arrayIndex(threeIndexSlice!, 3)) + await $.println($.plainSliceIndex(threeIndexSlice!, 3)) await $.println(threeIndexArr[4]) // --- Additional Tests for Full Coverage --- @@ -153,7 +153,7 @@ export async function main(): globalThis.Promise { let sliceLiteral = $.arrayToSlice([10, 20, 30]) await $.println("Slice literal len:", $.sliceLen(sliceLiteral)) await $.println("Slice literal cap:", $.cap(sliceLiteral)) - await $.println("Slice literal[1]:", $.arrayIndex(sliceLiteral!, 1)) + await $.println("Slice literal[1]:", $.plainSliceIndex(sliceLiteral!, 1)) // Nil slice let nilSlice: $.Slice = null! as $.Slice @@ -162,12 +162,12 @@ export async function main(): globalThis.Promise { nilSlice = $.appendOne(nilSlice, 5) await $.println("Append to nil slice len:", $.sliceLen(nilSlice)) await $.println("Append to nil slice cap:", $.cap(nilSlice)) - await $.println("Append to nil slice[0]:", $.arrayIndex(nilSlice!, 0)) + await $.println("Append to nil slice[0]:", $.plainSliceIndex(nilSlice!, 0)) let spreadSource = $.arrayToSlice([7, 8]) nilSlice = $.appendSlice(nilSlice, spreadSource) await $.println("Append spread slice len:", $.sliceLen(nilSlice)) - await $.println("Append spread slice[1]:", $.arrayIndex(nilSlice!, 1)) - await $.println("Append spread slice[2]:", $.arrayIndex(nilSlice!, 2)) + await $.println("Append spread slice[1]:", $.plainSliceIndex(nilSlice!, 1)) + await $.println("Append spread slice[2]:", $.plainSliceIndex(nilSlice!, 2)) // Out-of-bounds indexing (should panic) // Note: Testing panics in compliance tests requires specific handling in the test runner. @@ -190,20 +190,20 @@ export async function main(): globalThis.Promise { await $.println("Capacity of sliceOfSlices:", $.cap(sliceOfSlices)) // Access elements - await $.println("sliceOfSlices[0][1]:", $.arrayIndex($.arrayIndex(sliceOfSlices!, 0)!, 1)) - await $.println("sliceOfSlices[1][0]:", $.arrayIndex($.arrayIndex(sliceOfSlices!, 1)!, 0)) - await $.println("sliceOfSlices[2][3]:", $.arrayIndex($.arrayIndex(sliceOfSlices!, 2)!, 3)) + await $.println("sliceOfSlices[0][1]:", $.plainSliceIndex($.plainSliceIndex(sliceOfSlices!, 0)!, 1)) + await $.println("sliceOfSlices[1][0]:", $.plainSliceIndex($.plainSliceIndex(sliceOfSlices!, 1)!, 0)) + await $.println("sliceOfSlices[2][3]:", $.plainSliceIndex($.plainSliceIndex(sliceOfSlices!, 2)!, 3)) // Append to inner slice (should modify the inner slice) await $.println("--- Append to inner slice ---") - let innerSlice: $.Slice = $.arrayIndex(sliceOfSlices!, 1) + let innerSlice: $.Slice = $.plainSliceIndex(sliceOfSlices!, 1) await $.println("Length of innerSlice:", $.sliceLen(innerSlice)) await $.println("Capacity of innerSlice:", $.cap(innerSlice)) innerSlice = $.appendOne(innerSlice, 50) await $.println("Length of innerSlice after append:", $.sliceLen(innerSlice)) await $.println("Capacity of innerSlice after append:", $.cap(innerSlice)) - await $.println("innerSlice[2]:", $.arrayIndex(innerSlice!, 2)) + await $.println("innerSlice[2]:", $.plainSliceIndex(innerSlice!, 2)) // Check if the original slice of slices reflects the change (it should, as innerSlice is a view) // Note: Appending to innerSlice might reallocate its underlying array if capacity is exceeded. @@ -215,57 +215,57 @@ export async function main(): globalThis.Promise { // Create a slice of slices where inner slice has capacity for append let sliceOfSlicesWithCap = $.arrayToSlice<$.Slice>([$.arrayToSlice([1, 2, 3]), $.makeSlice(2, 5, "number"), $.arrayToSlice([6, 7, 8, 9])]) - $.sliceElems($.arrayIndex(sliceOfSlicesWithCap!, 1)!)[$.sliceSlot($.arrayIndex(sliceOfSlicesWithCap!, 1)!, 0)] = 40 - $.sliceElems($.arrayIndex(sliceOfSlicesWithCap!, 1)!)[$.sliceSlot($.arrayIndex(sliceOfSlicesWithCap!, 1)!, 1)] = 50 + $.sliceElems($.plainSliceIndex(sliceOfSlicesWithCap!, 1)!)[$.sliceSlot($.plainSliceIndex(sliceOfSlicesWithCap!, 1)!, 0)] = 40 + $.sliceElems($.plainSliceIndex(sliceOfSlicesWithCap!, 1)!)[$.sliceSlot($.plainSliceIndex(sliceOfSlicesWithCap!, 1)!, 1)] = 50 await $.println("--- Append to inner slice with capacity ---") - let innerSliceWithCap: $.Slice = $.arrayIndex(sliceOfSlicesWithCap!, 1) + let innerSliceWithCap: $.Slice = $.plainSliceIndex(sliceOfSlicesWithCap!, 1) await $.println("Length of innerSliceWithCap:", $.sliceLen(innerSliceWithCap)) await $.println("Capacity of innerSliceWithCap:", $.cap(innerSliceWithCap)) innerSliceWithCap = $.appendOne(innerSliceWithCap, 60) await $.println("Length of innerSliceWithCap after append:", $.sliceLen(innerSliceWithCap)) await $.println("Capacity of innerSliceWithCap after append:", $.cap(innerSliceWithCap)) - await $.println("innerSliceWithCap[2]:", $.arrayIndex(innerSliceWithCap!, 2)) + await $.println("innerSliceWithCap[2]:", $.plainSliceIndex(innerSliceWithCap!, 2)) // Check if the original slice of slices reflects the change (it should, as append was within capacity) - await $.println("sliceOfSlicesWithCap[1][2]:", $.arrayIndex($.goSlice($.arrayIndex(sliceOfSlicesWithCap!, 1), undefined, 3)!, 2)) + await $.println("sliceOfSlicesWithCap[1][2]:", $.plainSliceIndex($.goSlice($.plainSliceIndex(sliceOfSlicesWithCap!, 1), undefined, 3)!, 2)) // Append to inner slice exceeding capacity await $.println("--- Append to inner slice exceeding capacity ---") - let innerSliceExceedCap: $.Slice = $.arrayIndex(sliceOfSlices!, 0) + let innerSliceExceedCap: $.Slice = $.plainSliceIndex(sliceOfSlices!, 0) await $.println("Length of innerSliceExceedCap:", $.sliceLen(innerSliceExceedCap)) await $.println("Capacity of innerSliceExceedCap:", $.cap(innerSliceExceedCap)) innerSliceExceedCap = $.appendValues(innerSliceExceedCap, undefined, 10, 20) await $.println("Length of innerSliceExceedCap after append:", $.sliceLen(innerSliceExceedCap)) await $.println("Capacity of innerSliceExceedCap after append:", $.cap(innerSliceExceedCap)) - await $.println("innerSliceExceedCap[3]:", $.arrayIndex(innerSliceExceedCap!, 3)) - await $.println("innerSliceExceedCap[4]:", $.arrayIndex(innerSliceExceedCap!, 4)) + await $.println("innerSliceExceedCap[3]:", $.plainSliceIndex(innerSliceExceedCap!, 3)) + await $.println("innerSliceExceedCap[4]:", $.plainSliceIndex(innerSliceExceedCap!, 4)) // Check if the original slice of slices reflects the change (it should NOT, due to reallocation) // The original sliceOfSlices[0] should still be {1, 2, 3} - await $.println("Original sliceOfSlices[0] after inner append:", $.arrayIndex($.arrayIndex(sliceOfSlices!, 0)!, 0), $.arrayIndex($.arrayIndex(sliceOfSlices!, 0)!, 1), $.arrayIndex($.arrayIndex(sliceOfSlices!, 0)!, 2)) + await $.println("Original sliceOfSlices[0] after inner append:", $.plainSliceIndex($.plainSliceIndex(sliceOfSlices!, 0)!, 0), $.plainSliceIndex($.plainSliceIndex(sliceOfSlices!, 0)!, 1), $.plainSliceIndex($.plainSliceIndex(sliceOfSlices!, 0)!, 2)) // Slicing a slice of slices await $.println("--- Slicing a slice of slices ---") let subSliceOfSlices = $.goSlice(sliceOfSlices, 1, 3) await $.println("Length of subSliceOfSlices:", $.sliceLen(subSliceOfSlices)) await $.println("Capacity of subSliceOfSlices:", $.cap(subSliceOfSlices)) - await $.println("subSliceOfSlices[0][0]:", $.arrayIndex($.arrayIndex(subSliceOfSlices!, 0)!, 0)) - await $.println("subSliceOfSlices[1][2]:", $.arrayIndex($.arrayIndex(subSliceOfSlices!, 1)!, 2)) + await $.println("subSliceOfSlices[0][0]:", $.plainSliceIndex($.plainSliceIndex(subSliceOfSlices!, 0)!, 0)) + await $.println("subSliceOfSlices[1][2]:", $.plainSliceIndex($.plainSliceIndex(subSliceOfSlices!, 1)!, 2)) // Modify element in sub-slice of slices (should affect original) await $.println("--- Modify element in sub-slice of slices ---") - $.sliceElems($.arrayIndex(subSliceOfSlices!, 0)!)[$.sliceSlot($.arrayIndex(subSliceOfSlices!, 0)!, 1)] = 55 - await $.println("sliceOfSlices[1][1] after sub-slice modification:", $.arrayIndex($.arrayIndex(sliceOfSlices!, 1)!, 1)) + $.sliceElems($.plainSliceIndex(subSliceOfSlices!, 0)!)[$.sliceSlot($.plainSliceIndex(subSliceOfSlices!, 0)!, 1)] = 55 + await $.println("sliceOfSlices[1][1] after sub-slice modification:", $.plainSliceIndex($.plainSliceIndex(sliceOfSlices!, 1)!, 1)) // Append a new slice to the slice of slices await $.println("--- Append a new slice to slice of slices ---") sliceOfSlices = $.appendOne(sliceOfSlices, $.arrayToSlice([100, 110]), $.appendZeros.nil) await $.println("Length of sliceOfSlices after append:", $.sliceLen(sliceOfSlices)) await $.println("Capacity of sliceOfSlices after append:", $.cap(sliceOfSlices)) - await $.println("sliceOfSlices[3][0]:", $.arrayIndex($.arrayIndex(sliceOfSlices!, 3)!, 0)) + await $.println("sliceOfSlices[3][0]:", $.plainSliceIndex($.plainSliceIndex(sliceOfSlices!, 3)!, 0)) // Append an existing slice to the slice of slices await $.println("--- Append an existing slice to slice of slices ---") @@ -273,7 +273,7 @@ export async function main(): globalThis.Promise { sliceOfSlices = $.appendOne(sliceOfSlices, existingSlice, $.appendZeros.nil) await $.println("Length of sliceOfSlices after appending existing:", $.sliceLen(sliceOfSlices)) await $.println("Capacity of sliceOfSlices after appending existing:", $.cap(sliceOfSlices)) - await $.println("sliceOfSlices[4][1]:", $.arrayIndex($.arrayIndex(sliceOfSlices!, 4)!, 1)) + await $.println("sliceOfSlices[4][1]:", $.plainSliceIndex($.plainSliceIndex(sliceOfSlices!, 4)!, 1)) // Modify the appended existing slice (should NOT affect the slice in sliceOfSlices if it was copied) // Go's append copies the slice header, but the underlying array is shared unless reallocation occurs. @@ -282,13 +282,13 @@ export async function main(): globalThis.Promise { // Let's test this carefully. await $.println("--- Modify appended existing slice ---") $.sliceElems(existingSlice!)[$.sliceSlot(existingSlice!, 0)] = 205 - await $.println("sliceOfSlices[4][0] after modifying existingSlice:", $.arrayIndex($.arrayIndex(sliceOfSlices!, 4)!, 0)) + await $.println("sliceOfSlices[4][0] after modifying existingSlice:", $.plainSliceIndex($.plainSliceIndex(sliceOfSlices!, 4)!, 0)) // If we modify an element in the slice within sliceOfSlices, it *should* affect the original existingSlice // if they share the underlying array. await $.println("--- Modify slice within sliceOfSlices ---") - $.sliceElems($.arrayIndex(sliceOfSlices!, 4)!)[$.sliceSlot($.arrayIndex(sliceOfSlices!, 4)!, 1)] = 215 - await $.println("existingSlice[1] after modifying slice within sliceOfSlices:", $.arrayIndex(existingSlice!, 1)) + $.sliceElems($.plainSliceIndex(sliceOfSlices!, 4)!)[$.sliceSlot($.plainSliceIndex(sliceOfSlices!, 4)!, 1)] = 215 + await $.println("existingSlice[1] after modifying slice within sliceOfSlices:", $.plainSliceIndex(existingSlice!, 1)) // Create a slice of slices using make await $.println("--- Make slice of slices ---") @@ -299,22 +299,22 @@ export async function main(): globalThis.Promise { // Initialize inner slices $.sliceElems(makeSliceOfSlices!)[$.sliceSlot(makeSliceOfSlices!, 0)] = $.arrayToSlice([1000, 2000]) $.sliceElems(makeSliceOfSlices!)[$.sliceSlot(makeSliceOfSlices!, 1)] = $.makeSlice(1, 3, "number") - $.sliceElems($.arrayIndex(makeSliceOfSlices!, 1)!)[$.sliceSlot($.arrayIndex(makeSliceOfSlices!, 1)!, 0)] = 3000 + $.sliceElems($.plainSliceIndex(makeSliceOfSlices!, 1)!)[$.sliceSlot($.plainSliceIndex(makeSliceOfSlices!, 1)!, 0)] = 3000 - await $.println("makeSliceOfSlices[0][1]:", $.arrayIndex($.arrayIndex(makeSliceOfSlices!, 0)!, 1)) - await $.println("makeSliceOfSlices[1][0]:", $.arrayIndex($.arrayIndex(makeSliceOfSlices!, 1)!, 0)) + await $.println("makeSliceOfSlices[0][1]:", $.plainSliceIndex($.plainSliceIndex(makeSliceOfSlices!, 0)!, 1)) + await $.println("makeSliceOfSlices[1][0]:", $.plainSliceIndex($.plainSliceIndex(makeSliceOfSlices!, 1)!, 0)) // Append a new inner slice makeSliceOfSlices = $.appendOne(makeSliceOfSlices, $.arrayToSlice([4000, 5000]), $.appendZeros.nil) await $.println("Length of makeSliceOfSlices after append:", $.sliceLen(makeSliceOfSlices)) await $.println("Capacity of makeSliceOfSlices after append:", $.cap(makeSliceOfSlices)) - await $.println("makeSliceOfSlices[2][1]:", $.arrayIndex($.arrayIndex(makeSliceOfSlices!, 2)!, 1)) + await $.println("makeSliceOfSlices[2][1]:", $.plainSliceIndex($.plainSliceIndex(makeSliceOfSlices!, 2)!, 1)) // Append another new inner slice (should exceed capacity and reallocate outer slice) makeSliceOfSlices = $.appendOne(makeSliceOfSlices, $.arrayToSlice([6000]), $.appendZeros.nil) await $.println("Length of makeSliceOfSlices after second append:", $.sliceLen(makeSliceOfSlices)) await $.println("Capacity of makeSliceOfSlices after second append:", $.cap(makeSliceOfSlices)) - await $.println("makeSliceOfSlices[3][0]:", $.arrayIndex($.arrayIndex(makeSliceOfSlices!, 3)!, 0)) + await $.println("makeSliceOfSlices[3][0]:", $.plainSliceIndex($.plainSliceIndex(makeSliceOfSlices!, 3)!, 0)) // Nil slice of slices await $.println("--- Nil slice of slices ---") @@ -326,13 +326,13 @@ export async function main(): globalThis.Promise { nilSliceOfSlices = $.appendOne(nilSliceOfSlices, $.arrayToSlice([10000]), $.appendZeros.nil) await $.println("Length of nilSliceOfSlices after append:", $.sliceLen(nilSliceOfSlices)) await $.println("Capacity of nilSliceOfSlices after append:", $.cap(nilSliceOfSlices)) - await $.println("nilSliceOfSlices[0][0]:", $.arrayIndex($.arrayIndex(nilSliceOfSlices!, 0)!, 0)) + await $.println("nilSliceOfSlices[0][0]:", $.plainSliceIndex($.plainSliceIndex(nilSliceOfSlices!, 0)!, 0)) // Append another slice to the nil slice of slices nilSliceOfSlices = $.appendOne(nilSliceOfSlices, $.arrayToSlice([20000, 30000]), $.appendZeros.nil) await $.println("Length of nilSliceOfSlices after second append:", $.sliceLen(nilSliceOfSlices)) await $.println("Capacity of nilSliceOfSlices after second append:", $.cap(nilSliceOfSlices)) - await $.println("nilSliceOfSlices[1][1]:", $.arrayIndex($.arrayIndex(nilSliceOfSlices!, 1)!, 1)) + await $.println("nilSliceOfSlices[1][1]:", $.plainSliceIndex($.plainSliceIndex(nilSliceOfSlices!, 1)!, 1)) // Empty slice of slices (not nil) await $.println("--- Empty slice of slices ---") @@ -344,7 +344,7 @@ export async function main(): globalThis.Promise { emptySliceOfSlices = $.appendOne(emptySliceOfSlices, $.arrayToSlice([40000]), $.appendZeros.nil) await $.println("Length of emptySliceOfSlices after append:", $.sliceLen(emptySliceOfSlices)) await $.println("Capacity of emptySliceOfSlices after append:", $.cap(emptySliceOfSlices)) - await $.println("emptySliceOfSlices[0][0]:", $.arrayIndex($.arrayIndex(emptySliceOfSlices!, 0)!, 0)) + await $.println("emptySliceOfSlices[0][0]:", $.plainSliceIndex($.plainSliceIndex(emptySliceOfSlices!, 0)!, 0)) } if ($.isMainScript(import.meta)) { diff --git a/tests/tests/slice_append_shared_backing/slice_append_shared_backing.gs.ts b/tests/tests/slice_append_shared_backing/slice_append_shared_backing.gs.ts index 8b2c8ae6d..3f64bbcf1 100644 --- a/tests/tests/slice_append_shared_backing/slice_append_shared_backing.gs.ts +++ b/tests/tests/slice_append_shared_backing/slice_append_shared_backing.gs.ts @@ -14,7 +14,7 @@ export async function main(): globalThis.Promise { await $.println("a", i, v) } let d = $.appendOne(a, 9) - await $.println($.arrayIndex(b!, 1), $.arrayIndex(d!, 1), $.sliceLen(d)) + await $.println($.plainSliceIndex(b!, 1), $.plainSliceIndex(d!, 1), $.sliceLen(d)) let x = $.varRef(5) let p: $.Slice<$.VarRef | null> = null! as $.Slice<$.VarRef | null> @@ -27,9 +27,9 @@ export async function main(): globalThis.Promise { let u = $.goSlice(t, undefined, 1) let v = $.appendOne(u, "x") let w = $.appendOne(v, "y") - await $.println($.sliceLen(u), $.sliceLen(v), $.sliceLen(w), $.arrayIndex(t!, 1), $.arrayIndex(t!, 2)) + await $.println($.sliceLen(u), $.sliceLen(v), $.sliceLen(w), $.plainSliceIndex(t!, 1), $.plainSliceIndex(t!, 2)) $.copy(u, $.arrayToSlice(["z"])) - await $.println($.arrayIndex(t!, 0), $.arrayIndex(v!, 0), $.arrayIndex(w!, 0)) + await $.println($.plainSliceIndex(t!, 0), $.plainSliceIndex(v!, 0), $.plainSliceIndex(w!, 0)) } if ($.isMainScript(import.meta)) { diff --git a/tests/tests/slice_copy_overlap/slice_copy_overlap.gs.ts b/tests/tests/slice_copy_overlap/slice_copy_overlap.gs.ts index 1cfa2e20a..a8f6e8e77 100644 --- a/tests/tests/slice_copy_overlap/slice_copy_overlap.gs.ts +++ b/tests/tests/slice_copy_overlap/slice_copy_overlap.gs.ts @@ -8,30 +8,30 @@ export async function main(): globalThis.Promise { let right = $.arrayToSlice([1, 2, 3, 4, 5]) let n = $.copy($.goSlice(right, 2, undefined), $.goSlice(right, 1, 4)) await $.println("right count:", n) - await $.println("right:", $.arrayIndex(right!, 0), $.arrayIndex(right!, 1), $.arrayIndex(right!, 2), $.arrayIndex(right!, 3), $.arrayIndex(right!, 4)) + await $.println("right:", $.plainSliceIndex(right!, 0), $.plainSliceIndex(right!, 1), $.plainSliceIndex(right!, 2), $.plainSliceIndex(right!, 3), $.plainSliceIndex(right!, 4)) let left = $.arrayToSlice([1, 2, 3, 4, 5]) n = $.copy($.goSlice(left, 1, undefined), $.goSlice(left, 2, undefined)) await $.println("left count:", n) - await $.println("left:", $.arrayIndex(left!, 0), $.arrayIndex(left!, 1), $.arrayIndex(left!, 2), $.arrayIndex(left!, 3), $.arrayIndex(left!, 4)) + await $.println("left:", $.plainSliceIndex(left!, 0), $.plainSliceIndex(left!, 1), $.plainSliceIndex(left!, 2), $.plainSliceIndex(left!, 3), $.plainSliceIndex(left!, 4)) // Byte ranges copy in both directions without exposing temporary views. let bytes = new Uint8Array([1, 2, 3, 4, 5]) as $.Slice let start = 1 let stop = 4 n = $.copyByteRanges(bytes, start + 1, undefined, bytes, start, stop) - await $.println("byte right:", n, $.arrayIndex(bytes!, 0), $.arrayIndex(bytes!, 1), $.arrayIndex(bytes!, 2), $.arrayIndex(bytes!, 3), $.arrayIndex(bytes!, 4)) + await $.println("byte right:", n, $.typedSliceIndex(bytes!, 0), $.typedSliceIndex(bytes!, 1), $.typedSliceIndex(bytes!, 2), $.typedSliceIndex(bytes!, 3), $.typedSliceIndex(bytes!, 4)) n = $.copyByteRanges(bytes, undefined, stop - 1, bytes, start + 1, undefined) - await $.println("byte left:", n, $.arrayIndex(bytes!, 0), $.arrayIndex(bytes!, 1), $.arrayIndex(bytes!, 2), $.arrayIndex(bytes!, 3), $.arrayIndex(bytes!, 4)) + await $.println("byte left:", n, $.typedSliceIndex(bytes!, 0), $.typedSliceIndex(bytes!, 1), $.typedSliceIndex(bytes!, 2), $.typedSliceIndex(bytes!, 3), $.typedSliceIndex(bytes!, 4)) // Explicit high bounds may extend into spare capacity; omitted highs may not. let backing = new Uint8Array([10, 11, 12, 13, 14, 15]) as $.Slice let dst = $.goSlice(backing, 1, 2, 5) let src = new Uint8Array([7, 8, 9]) as $.Slice n = $.copyByteRanges(dst, 1, 4, src, undefined, undefined) - await $.println("capacity:", n, $.arrayIndex(backing!, 0), $.arrayIndex(backing!, 1), $.arrayIndex(backing!, 2), $.arrayIndex(backing!, 3), $.arrayIndex(backing!, 4), $.arrayIndex(backing!, 5)) + await $.println("capacity:", n, $.typedSliceIndex(backing!, 0), $.typedSliceIndex(backing!, 1), $.typedSliceIndex(backing!, 2), $.typedSliceIndex(backing!, 3), $.typedSliceIndex(backing!, 4), $.typedSliceIndex(backing!, 5)) n = $.copyByteRanges(dst, undefined, undefined, src, undefined, undefined) - await $.println("length:", n, $.arrayIndex(backing!, 1), $.arrayIndex(backing!, 2)) + await $.println("length:", n, $.typedSliceIndex(backing!, 1), $.typedSliceIndex(backing!, 2)) // Bounds with calls preserve their observable evaluation sequence. n = $.copy($.goSlice(dst, await bound(0), undefined), $.goSlice(src, await bound(1), undefined)) diff --git a/tests/tests/slice_to_array_conversion/slice_to_array_conversion.gs.ts b/tests/tests/slice_to_array_conversion/slice_to_array_conversion.gs.ts index 0fa3365b9..807760a23 100644 --- a/tests/tests/slice_to_array_conversion/slice_to_array_conversion.gs.ts +++ b/tests/tests/slice_to_array_conversion/slice_to_array_conversion.gs.ts @@ -9,23 +9,23 @@ export async function main(): globalThis.Promise { await $.println(array[0], array[1]) $.sliceElems(values!)[$.sliceSlot(values!, 1)] = 9 - await $.println(array[0], $.arrayIndex(values!, 1)) + await $.println(array[0], $.typedSliceIndex(values!, 1)) // Whole-array writes through converted pointers preserve the slice backing. let bytePointer = ($.sliceToArrayPointer($.goSlice(values, 1, undefined), 2, "byte") as $.VarRef | null) $.assignFieldValue($.pointerValue(bytePointer), $.arrayValue(new Uint8Array([7, 8])), __goscriptStatic0()) - await $.println("byte write:", $.arrayIndex(values!, 0), $.arrayIndex(values!, 1), $.arrayIndex(values!, 2)) + await $.println("byte write:", $.typedSliceIndex(values!, 0), $.typedSliceIndex(values!, 1), $.typedSliceIndex(values!, 2)) $.pointerValue(bytePointer)[0] = 6 - await $.println("byte alias:", $.arrayIndex(values!, 1)) + await $.println("byte alias:", $.typedSliceIndex(values!, 1)) let words = $.typedSliceOf(Uint16Array, [1, 2, 3, 4]) as $.Slice let wordPointer = $.sliceToArrayPointer($.goSlice(words, 1, undefined), 2) let replacement = $.arrayValue([20, 30]) $.assignFieldValue($.pointerValue(wordPointer), replacement, __goscriptStatic1()) replacement[0] = 99 - await $.println("word write:", $.arrayIndex(words!, 0), $.arrayIndex(words!, 1), $.arrayIndex(words!, 2), $.arrayIndex(words!, 3)) + await $.println("word write:", $.typedSliceIndex(words!, 0), $.typedSliceIndex(words!, 1), $.typedSliceIndex(words!, 2), $.typedSliceIndex(words!, 3)) $.pointerValue(wordPointer)[1] = 40 - await $.println("word alias:", $.arrayIndex(words!, 2)) + await $.println("word alias:", $.typedSliceIndex(words!, 2)) } var __goscriptStatic0$value: any diff --git a/tests/tests/slice_type_assertion/slice_type_assertion.gs.ts b/tests/tests/slice_type_assertion/slice_type_assertion.gs.ts index 3c3b67342..1c03c86f9 100644 --- a/tests/tests/slice_type_assertion/slice_type_assertion.gs.ts +++ b/tests/tests/slice_type_assertion/slice_type_assertion.gs.ts @@ -6,7 +6,7 @@ import * as $ from "@goscript/builtin/index.js" export async function main(): globalThis.Promise { let v: any = $.interfaceValue(new Uint8Array([7, 8, 9]) as $.Slice, "[]byte", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("uint8"))) let b = $.mustTypeAssert<$.Slice>(v, /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("uint8"))) - await $.println("byte slice:", $.sliceLen(b), $.arrayIndex(b!, 0), $.arrayIndex(b!, 2)) + await $.println("byte slice:", $.sliceLen(b), $.typedSliceIndex(b!, 0), $.typedSliceIndex(b!, 2)) } if ($.isMainScript(import.meta)) { diff --git a/tests/tests/slices_func_async_callback/slices_func_async_callback.gs.ts b/tests/tests/slices_func_async_callback/slices_func_async_callback.gs.ts index e8d1b5e1f..74f461b5a 100644 --- a/tests/tests/slices_func_async_callback/slices_func_async_callback.gs.ts +++ b/tests/tests/slices_func_async_callback/slices_func_async_callback.gs.ts @@ -94,7 +94,7 @@ export async function main(): globalThis.Promise { }, ({ kind: $.TypeKind.Function, params: [/* @__PURE__ */ $.basicType("int"), /* @__PURE__ */ $.basicType("int")], results: [/* @__PURE__ */ $.basicType("int")] } as $.FunctionTypeInfo)) let values = $.arrayToSlice([3, 1, 2]) await slices.SortStableFunc(values, cmp) - await $.println("sorted:", $.arrayIndex(values!, 0), $.arrayIndex(values!, 1), $.arrayIndex(values!, 2)) + await $.println("sorted:", $.plainSliceIndex(values!, 0), $.plainSliceIndex(values!, 1), $.plainSliceIndex(values!, 2)) let pred: ((v: number) => boolean | globalThis.Promise) | null = isEven await $.println("max odd:", slices.MaxFunc($.arrayToSlice([5, 9, 7]), $.functionValue((a: number, b: number): number => { diff --git a/tests/tests/slices_grow/slices_grow.gs.ts b/tests/tests/slices_grow/slices_grow.gs.ts index 7f7636586..73d6de737 100644 --- a/tests/tests/slices_grow/slices_grow.gs.ts +++ b/tests/tests/slices_grow/slices_grow.gs.ts @@ -13,7 +13,7 @@ export async function main(): globalThis.Promise { // Growing a byte slice exposes zero bytes past its length. let b: $.Slice = (slices.Grow(new Uint8Array([97, 98, 99]), 4, () => (0 as number)) as $.Slice) b = $.goSlice(b, undefined, $.cap(b)) - await $.println("byte Grow: zero tail=", $.arrayIndex(b!, $.sliceLen(b) - 1) == 0, "kept=", $.bytesToString($.goSlice(b, undefined, 3))) + await $.println("byte Grow: zero tail=", $.typedSliceIndex(b!, $.sliceLen(b) - 1) == 0, "kept=", $.bytesToString($.goSlice(b, undefined, 3))) await $.println("slices.Grow test finished") } diff --git a/tests/tests/slices_grow_zero_values/slices_grow_zero_values.gs.ts b/tests/tests/slices_grow_zero_values/slices_grow_zero_values.gs.ts index 69205c6ef..d5d8f7f16 100644 --- a/tests/tests/slices_grow_zero_values/slices_grow_zero_values.gs.ts +++ b/tests/tests/slices_grow_zero_values/slices_grow_zero_values.gs.ts @@ -10,20 +10,20 @@ export async function main(): globalThis.Promise { let nilWords: $.Slice = null! as $.Slice nilWords = (slices.Grow(nilWords, 3, () => (0 as word)) as $.Slice) nilWords = $.goSlice(nilWords, undefined, 3) - await $.println("nil words", $.arrayIndex(nilWords!, 0), $.arrayIndex(nilWords!, 1), $.arrayIndex(nilWords!, 2)) + await $.println("nil words", $.plainSliceIndex(nilWords!, 0), $.plainSliceIndex(nilWords!, 1), $.plainSliceIndex(nilWords!, 2)) let counts: $.Slice = $.makeSlice(1, 1, "number") $.sliceElems(counts!)[$.sliceSlot(counts!, 0)] = 7 counts = (slices.Grow(counts, 2, () => (0 as number)) as $.Slice) counts = $.goSlice(counts, undefined, 3) - await $.println("counts", $.arrayIndex(counts!, 0), $.arrayIndex(counts!, 1), $.arrayIndex(counts!, 2)) + await $.println("counts", $.plainSliceIndex(counts!, 0), $.plainSliceIndex(counts!, 1), $.plainSliceIndex(counts!, 2)) let names = $.goSlice(slices.Grow($.arrayToSlice(["a"]), 2, () => ("" as string)), undefined, 3) - await $.println("names", $.arrayIndex(names!, 0), $.stringEqual($.arrayIndex(names!, 1), ""), $.stringEqual($.arrayIndex(names!, 2), "")) + await $.println("names", $.plainSliceIndex(names!, 0), $.stringEqual($.plainSliceIndex(names!, 1), ""), $.stringEqual($.plainSliceIndex(names!, 2), "")) let pointers: $.Slice<$.VarRef | null> = null! as $.Slice<$.VarRef | null> pointers = $.goSlice(slices.Grow(pointers, 2, () => (null! as $.VarRef | null as $.VarRef | null)), undefined, 2) - await $.println("pointers", $.arrayIndex(pointers!, 0) == null, $.arrayIndex(pointers!, 1) == null) + await $.println("pointers", $.plainSliceIndex(pointers!, 0) == null, $.plainSliceIndex(pointers!, 1) == null) } if ($.isMainScript(import.meta)) { diff --git a/tests/tests/slices_zero_freed_elements/slices_zero_freed_elements.gs.ts b/tests/tests/slices_zero_freed_elements/slices_zero_freed_elements.gs.ts index 874259a03..095a32876 100644 --- a/tests/tests/slices_zero_freed_elements/slices_zero_freed_elements.gs.ts +++ b/tests/tests/slices_zero_freed_elements/slices_zero_freed_elements.gs.ts @@ -84,7 +84,7 @@ export async function main(): globalThis.Promise { let words = (slices.Delete($.arrayToSlice(["a", "b"]), 0, 1, () => ("" as string)) as $.Slice) let values = (slices.Delete($.arrayToSlice([$.basicInterfaceValue(1, "int"), $.structInterfaceValue(new T(true), "main.T", "main.T")]), 0, 1, () => (null! as any as any)) as $.Slice) let arrays = (slices.Delete($.arrayToSlice([$.arrayValue([1, 2]), $.arrayValue([3, 4])]), 0, 1, () => ($.arrayValue(globalThis.Array.from({ length: 2 }, () => 0)) as number[])) as $.Slice) - await $.println("others:", $.stringEqual($.arrayIndex($.goSlice(words, undefined, 2)!, 1), ""), $.arrayIndex($.goSlice(values, undefined, 2)!, 1) == null, ($.arrayIndex($.goSlice(arrays, undefined, 2)!, 1))[0]) + await $.println("others:", $.stringEqual($.plainSliceIndex($.goSlice(words, undefined, 2)!, 1), ""), $.plainSliceIndex($.goSlice(values, undefined, 2)!, 1) == null, ($.plainSliceIndex($.goSlice(arrays, undefined, 2)!, 1))[0]) } var __goscriptStatic0$value: any diff --git a/tests/tests/sort_operands/sort_operands.gs.ts b/tests/tests/sort_operands/sort_operands.gs.ts index 2d2c8c541..f1e8bcf74 100644 --- a/tests/tests/sort_operands/sort_operands.gs.ts +++ b/tests/tests/sort_operands/sort_operands.gs.ts @@ -49,15 +49,15 @@ export class slowInts { public async Less(i: number, j: number): globalThis.Promise { const s: slowInts | $.VarRef | null = this; const s$: slowInts = s == null ? $.pointerTarget(s) : (s as any).__isVarRef === true ? (s as any).value : (s as any).__goValue === undefined ? (s as any) : $.pointerTarget(s) - await $.chanSend((s$ as slowInts).ch, $.arrayIndex((s$ as slowInts).xs!, i)) - return await $.chanRecv((s$ as slowInts).ch) < $.arrayIndex((s$ as slowInts).xs!, j) + await $.chanSend((s$ as slowInts).ch, $.plainSliceIndex((s$ as slowInts).xs!, i)) + return await $.chanRecv((s$ as slowInts).ch) < $.plainSliceIndex((s$ as slowInts).xs!, j) } public Swap(i: number, j: number): void { const s: slowInts | $.VarRef | null = this; const s$: slowInts = s == null ? $.pointerTarget(s) : (s as any).__isVarRef === true ? (s as any).value : (s as any).__goValue === undefined ? (s as any) : $.pointerTarget(s) - let __goscriptAssign1_0: number = $.arrayIndex((s$ as slowInts).xs!, j) - let __goscriptAssign1_1: number = $.arrayIndex((s$ as slowInts).xs!, i) + let __goscriptAssign1_0: number = $.plainSliceIndex((s$ as slowInts).xs!, j) + let __goscriptAssign1_1: number = $.plainSliceIndex((s$ as slowInts).xs!, i) $.sliceElems((s$ as slowInts).xs!)[$.sliceSlot((s$ as slowInts).xs!, i)] = __goscriptAssign1_0 $.sliceElems((s$ as slowInts).xs!)[$.sliceSlot((s$ as slowInts).xs!, j)] = __goscriptAssign1_1 } @@ -76,12 +76,12 @@ export function byLen_Len(s: byLen): number { } export function byLen_Less(s: byLen, i: number, j: number): boolean { - return $.stringLen($.arrayIndex(s!, i)) < $.stringLen($.arrayIndex(s!, j)) + return $.stringLen($.plainSliceIndex(s!, i)) < $.stringLen($.plainSliceIndex(s!, j)) } export function byLen_Swap(s: byLen, i: number, j: number): void { - let __goscriptAssign0_0: string = $.arrayIndex(s!, j) - let __goscriptAssign0_1: string = $.arrayIndex(s!, i) + let __goscriptAssign0_0: string = $.plainSliceIndex(s!, j) + let __goscriptAssign0_1: string = $.plainSliceIndex(s!, i) $.sliceElems(s!)[$.sliceSlot(s!, i)] = __goscriptAssign0_0 $.sliceElems(s!)[$.sliceSlot(s!, j)] = __goscriptAssign0_1 } @@ -112,12 +112,12 @@ export async function sortAny(data: sort.Interface | null): globalThis.Promise { await $.println($.sliceLen(sortWords($.arrayToSlice(["ccc", "a", "bb"]))), wordsSorted($.arrayToSlice(["a", "bb"]))) let w = stableWords($.arrayToSlice(["bb", "a", "cc", "d"])) - await $.println($.arrayIndex(w!, 0), $.arrayIndex(w!, 1), $.arrayIndex(w!, 2), $.arrayIndex(w!, 3)) + await $.println($.plainSliceIndex(w!, 0), $.plainSliceIndex(w!, 1), $.plainSliceIndex(w!, 2), $.plainSliceIndex(w!, 3)) let s = await sortSlow(new slowInts(false, $.arrayToSlice([3, 1, 2]), $.makeChannel(1, 0, "both"))) - await $.println($.arrayIndex(s!, 0), $.arrayIndex(s!, 1), $.arrayIndex(s!, 2)) + await $.println($.plainSliceIndex(s!, 0), $.plainSliceIndex(s!, 1), $.plainSliceIndex(s!, 2)) let words = ($.arrayToSlice(["xyz", "x", "xy"]) as byLen) await sortAny($.namedValueInterfaceValue(words, "main.byLen", __goscriptStatic0(), __goscriptStatic1(), __goscriptStatic2())) - await $.println($.arrayIndex(words!, 0), $.arrayIndex(words!, 1), $.arrayIndex(words!, 2), (sort.IsSorted($.pointerValueOrNil($.namedValueInterfaceValue(words, "main.byLen", __goscriptStatic0(), __goscriptStatic1(), __goscriptStatic2()))!) as boolean)) + await $.println($.plainSliceIndex(words!, 0), $.plainSliceIndex(words!, 1), $.plainSliceIndex(words!, 2), (sort.IsSorted($.pointerValueOrNil($.namedValueInterfaceValue(words, "main.byLen", __goscriptStatic0(), __goscriptStatic1(), __goscriptStatic2()))!) as boolean)) } var __goscriptStatic0$value: any diff --git a/tests/tests/string_conversion/string_conversion.gs.ts b/tests/tests/string_conversion/string_conversion.gs.ts index e75675ab1..6766555dd 100644 --- a/tests/tests/string_conversion/string_conversion.gs.ts +++ b/tests/tests/string_conversion/string_conversion.gs.ts @@ -57,14 +57,14 @@ export async function main(): globalThis.Promise { await $.println((10 as number) == 10) let magicBytes = new Uint8Array([255, 6, 0, 0, 83, 50, 115, 84, 119, 79]) await $.println($.sliceLen(magicBytes) == 10) - await $.println($.arrayIndex(magicBytes!, 0) == 255) - await $.println($.arrayIndex(magicBytes!, 1) == 6) + await $.println($.typedSliceIndex(magicBytes!, 0) == 255) + await $.println($.typedSliceIndex(magicBytes!, 1) == 6) await $.println($.stringEqual($.bytesToString(magicBytes), "\xff\x06\x00\x00S2sTwO")) await $.println((2 as number) == 2) let utf8Bytes = new Uint8Array([195, 169]) await $.println($.sliceLen(utf8Bytes) == 2) - await $.println($.arrayIndex(utf8Bytes!, 0) == 195) - await $.println($.arrayIndex(utf8Bytes!, 1) == 169) + await $.println($.typedSliceIndex(utf8Bytes!, 0) == 195) + await $.println($.typedSliceIndex(utf8Bytes!, 1) == 169) // string(int32) conversion let i32 = 66 diff --git a/tests/tests/string_invalid_utf8/string_invalid_utf8.gs.ts b/tests/tests/string_invalid_utf8/string_invalid_utf8.gs.ts index 5f685b31d..1a20fa4b8 100644 --- a/tests/tests/string_invalid_utf8/string_invalid_utf8.gs.ts +++ b/tests/tests/string_invalid_utf8/string_invalid_utf8.gs.ts @@ -31,9 +31,9 @@ export async function main(): globalThis.Promise { // conversions let runes = $.stringToRunes(s) - await $.println($.sliceLen(runes), $.arrayIndex(runes!, 7), $.arrayIndex(runes!, 9)) + await $.println($.sliceLen(runes), $.typedSliceIndex(runes!, 7), $.typedSliceIndex(runes!, 9)) let bs = $.stringToBytes(s) - await $.println($.sliceLen(bs), $.arrayIndex(bs!, 7), $.stringEqual($.bytesToString(bs), s)) + await $.println($.sliceLen(bs), $.typedSliceIndex(bs!, 7), $.stringEqual($.bytesToString(bs), s)) await $.println($.stringLen($.runesToString(runes)), $.stringEqual($.runesToString(runes), "BadUTF8\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd")) // building from runes @@ -76,7 +76,7 @@ export async function main(): globalThis.Promise { await $.println(strings.HasPrefix(key, "block:"), ok, $.stringLen(rest), $.indexString(rest, 0), $.indexString(rest, 1)) let keys = $.arrayToSlice(["gcroot", key]) slices.Sort(keys) - await $.println($.stringEqual($.arrayIndex(keys!, 0), key), $.stringCompare(key, "gcroot") < 0, strings.Compare(key, "gcroot")) + await $.println($.stringEqual($.plainSliceIndex(keys!, 0), key), $.stringCompare(key, "gcroot") < 0, strings.Compare(key, "gcroot")) let keyed = $.makeMap([[key, 1]]) await $.println($.mapGet(keyed, "block:\x01\xff\x80", 0)[0], $.mapGet(keyed, $.bytesToString($.stringToBytes(key)), 0)[0]) diff --git a/tests/tests/struct_assign_in_place/struct_assign_in_place.gs.ts b/tests/tests/struct_assign_in_place/struct_assign_in_place.gs.ts index 058ab8d0d..282c90831 100644 --- a/tests/tests/struct_assign_in_place/struct_assign_in_place.gs.ts +++ b/tests/tests/struct_assign_in_place/struct_assign_in_place.gs.ts @@ -192,9 +192,9 @@ export async function main(): globalThis.Promise { await $.println(a.value.In.X, a.value.N) let s = $.arrayToSlice([make1(), make1()]) - $.sliceElems(s!)[$.sliceSlot(s!, 0)].__goscriptAssign($.arrayIndex(s!, 1)) - $.arrayIndex(s!, 1).In.Y = 20 - await $.println($.arrayIndex(s!, 0).In.Y, $.arrayIndex(s!, 1).In.Y) + $.sliceElems(s!)[$.sliceSlot(s!, 0)].__goscriptAssign($.plainSliceIndex(s!, 1)) + $.plainSliceIndex(s!, 1).In.Y = 20 + await $.println($.plainSliceIndex(s!, 0).In.Y, $.plainSliceIndex(s!, 1).In.Y) let sh = new Inner(false, 7, 8) a.value.Ptr = sh diff --git a/tests/tests/struct_borrowed_results/struct_borrowed_results.gs.ts b/tests/tests/struct_borrowed_results/struct_borrowed_results.gs.ts index cfb7c894e..58ab72afd 100644 --- a/tests/tests/struct_borrowed_results/struct_borrowed_results.gs.ts +++ b/tests/tests/struct_borrowed_results/struct_borrowed_results.gs.ts @@ -231,7 +231,7 @@ export function Lines_at(l: Lines, reg: Region, __goscriptBorrow?: boolean): Reg if ($.sliceLen((l as Lines)) == 0) { return (__goscriptBorrow === true ? reg : (reg).clone()) } - return ($.arrayIndex(l!, 0)).clone() + return ($.plainSliceIndex(l!, 0)).clone() } export function reads(r: rule | $.VarRef | null, scope: Region): number { diff --git a/tests/tests/struct_equal_method/struct_equal_method.gs.ts b/tests/tests/struct_equal_method/struct_equal_method.gs.ts index 16e0c9c5a..0cf7fbec6 100644 --- a/tests/tests/struct_equal_method/struct_equal_method.gs.ts +++ b/tests/tests/struct_equal_method/struct_equal_method.gs.ts @@ -236,7 +236,7 @@ export async function main(): globalThis.Promise { // Comparisons of values in slices and maps. let regions = $.arrayToSlice([(a).clone(), b]) - await $.println("slice:", $.structEqual($.arrayIndex(regions!, 0), a), $.structEqual($.arrayIndex(regions!, 1), a)) + await $.println("slice:", $.structEqual($.plainSliceIndex(regions!, 0), a), $.structEqual($.plainSliceIndex(regions!, 1), a)) let seen = $.makeMap([[new pos(true, 1, 2), true]]) await $.println("map:", $.mapGet(seen, a.Start, false)[0], $.mapGet(seen, a.End, false)[0]) diff --git a/tests/tests/struct_equal_unnamed/struct_equal_unnamed.gs.ts b/tests/tests/struct_equal_unnamed/struct_equal_unnamed.gs.ts index 2390bbfcc..d580dd1ac 100644 --- a/tests/tests/struct_equal_unnamed/struct_equal_unnamed.gs.ts +++ b/tests/tests/struct_equal_unnamed/struct_equal_unnamed.gs.ts @@ -153,7 +153,7 @@ export async function main(): globalThis.Promise { let pr2 = new Pair(true, ((__goscriptSource) => new Point(true, __goscriptSource.X, __goscriptSource.Y))($.anonymousStructValue({X: 5, Y: 6}, { kind: $.TypeKind.Struct, methods: [], fields: [/* @__PURE__ */ $.structField("X", /* @__PURE__ */ $.basicType("int"), [0], 0, true), /* @__PURE__ */ $.structField("Y", /* @__PURE__ */ $.basicType("int"), [1], 8, true)] }))) await $.println("field method:", pr2.A.Sum()) let ps = $.arrayToSlice([((__goscriptSource) => new Point(true, __goscriptSource.X, __goscriptSource.Y))($.anonymousStructValue({X: 7, Y: 8}, { kind: $.TypeKind.Struct, methods: [], fields: [/* @__PURE__ */ $.structField("X", /* @__PURE__ */ $.basicType("int"), [0], 0, true), /* @__PURE__ */ $.structField("Y", /* @__PURE__ */ $.basicType("int"), [1], 8, true)] }))]) - await $.println("element method:", $.arrayIndex(ps!, 0).Sum()) + await $.println("element method:", $.plainSliceIndex(ps!, 0).Sum()) let m = $.makeMap([["a", ((__goscriptSource) => new Point(true, __goscriptSource.X, __goscriptSource.Y))($.anonymousStructValue({X: 1, Y: 1}, { kind: $.TypeKind.Struct, methods: [], fields: [/* @__PURE__ */ $.structField("X", /* @__PURE__ */ $.basicType("int"), [0], 0, true), /* @__PURE__ */ $.structField("Y", /* @__PURE__ */ $.basicType("int"), [1], 8, true)] }))]]) await $.println("map method:", $.mapGet(m, "a", new Point(true))[0].Sum()) diff --git a/tests/tests/struct_literal_interface/struct_literal_interface.gs.ts b/tests/tests/struct_literal_interface/struct_literal_interface.gs.ts index af53fffb2..bce5fe141 100644 --- a/tests/tests/struct_literal_interface/struct_literal_interface.gs.ts +++ b/tests/tests/struct_literal_interface/struct_literal_interface.gs.ts @@ -8,7 +8,7 @@ export async function main(): globalThis.Promise { // Test creating reflect.SelectCase struct literals let cases = $.arrayToSlice([$.markAsStructValue(new reflect.SelectCase({Dir: 3}))]) await $.println("Cases len:", $.sliceLen(cases)) - await $.println("First case dir:", $.arrayIndex(cases!, 0).Dir) + await $.println("First case dir:", $.plainSliceIndex(cases!, 0).Dir) } if ($.isMainScript(import.meta)) { diff --git a/tests/tests/struct_move_dead_locals/struct_move_dead_locals.gs.ts b/tests/tests/struct_move_dead_locals/struct_move_dead_locals.gs.ts index 17081941e..cafb208fa 100644 --- a/tests/tests/struct_move_dead_locals/struct_move_dead_locals.gs.ts +++ b/tests/tests/struct_move_dead_locals/struct_move_dead_locals.gs.ts @@ -77,8 +77,8 @@ export async function main(): globalThis.Promise { tok.At.Line = i * 10 toks = $.appendOne(toks, tok) } - $.arrayIndex(toks!, 0).At.Line = 99 - await $.println($.arrayIndex(toks!, 0).At.Line, $.arrayIndex(toks!, 1).At.Line, $.arrayIndex(toks!, 2).At.Line) + $.plainSliceIndex(toks!, 0).At.Line = 99 + await $.println($.plainSliceIndex(toks!, 0).At.Line, $.plainSliceIndex(toks!, 1).At.Line, $.plainSliceIndex(toks!, 2).At.Line) // A local declared outside the loop is copied at each append. let outer: $.Slice = null! as $.Slice @@ -87,7 +87,7 @@ export async function main(): globalThis.Promise { cur.At.Char = i outer = $.appendOne(outer, (cur).clone()) } - await $.println($.arrayIndex(outer!, 0).At.Char, $.arrayIndex(outer!, 1).At.Char, $.arrayIndex(outer!, 2).At.Char) + await $.println($.plainSliceIndex(outer!, 0).At.Char, $.plainSliceIndex(outer!, 1).At.Char, $.plainSliceIndex(outer!, 2).At.Char) // A later reference in the same statement keeps the copy. let v = new pos(true, 1) @@ -134,8 +134,8 @@ export async function main(): globalThis.Promise { let p = ((__goscriptRangeWindow0.backing[__goscriptRangeWindow0.offset + __rangeIndex] as pos)).clone() copies = $.appendOne(copies, (p).clone()) } - $.arrayIndex(copies!, 0).Line = 9 - await $.println($.arrayIndex(copies!, 0).Line, $.arrayIndex(copies!, 1).Line) + $.plainSliceIndex(copies!, 0).Line = 9 + await $.println($.plainSliceIndex(copies!, 0).Line, $.plainSliceIndex(copies!, 1).Line) // A function literal parameter is copied. let src = $.arrayToSlice([new pos(true, 1)]) @@ -143,8 +143,8 @@ export async function main(): globalThis.Promise { each(src, $.functionValue((p: pos) => { kept = $.appendOne(kept, (p).clone()) }, ({ kind: $.TypeKind.Function, params: ["main.pos"], results: [] } as $.FunctionTypeInfo))) - $.arrayIndex(kept!, 0).Line = 5 - await $.println($.arrayIndex(src!, 0).Line, $.arrayIndex(kept!, 0).Line) + $.plainSliceIndex(kept!, 0).Line = 5 + await $.println($.plainSliceIndex(src!, 0).Line, $.plainSliceIndex(kept!, 0).Line) } export function each(s: $.Slice, f: ((_p0: pos) => void) | null): void { diff --git a/tests/tests/struct_promoted_literal/struct_promoted_literal.gs.ts b/tests/tests/struct_promoted_literal/struct_promoted_literal.gs.ts index e3141c6dd..89639cc0d 100644 --- a/tests/tests/struct_promoted_literal/struct_promoted_literal.gs.ts +++ b/tests/tests/struct_promoted_literal/struct_promoted_literal.gs.ts @@ -243,7 +243,7 @@ export async function main(): globalThis.Promise { copy.Employee.Person.Name = "copy" await $.println((team$ as Team).Employee.Person.Name, copy.Employee.Person.Name, (team$ as Team).Employee.Person.Age, (team$ as Team).Employee.ID, (team$ as Team).Active) let items = $.arrayToSlice | null>([(() => { const __goscriptStructLiteral2: Team = new Team(); __goscriptStructLiteral2.Employee = new Employee(true); __goscriptStructLiteral2.Employee.Person = new Person(true); __goscriptStructLiteral2.Employee.Person.Name = "inferred"; return __goscriptStructLiteral2 })()]) - await $.println($.pointerValue($.arrayIndex(items!, 0)).Employee.Person.Name, $.pointerValue($.arrayIndex(items!, 0)).Employee.ID) + await $.println($.pointerValue($.plainSliceIndex(items!, 0)).Employee.Person.Name, $.pointerValue($.plainSliceIndex(items!, 0)).Employee.ID) // Anonymous and generic structs use the same promoted field paths. let anonymous = (() => { const __goscriptStructLiteral3: {"Person": Person, "Enabled": boolean} = $.anonymousStructValue({"Person": new Person(true), "Enabled": false}, { kind: $.TypeKind.Struct, methods: [], fields: [/* @__PURE__ */ $.structField("Person", "main.Person", [0], 0, true, { anonymous: true }), /* @__PURE__ */ $.structField("Enabled", /* @__PURE__ */ $.basicType("bool"), [1], 24, true)] }); __goscriptStructLiteral3.Person = new Person(true); __goscriptStructLiteral3.Person.Name = "anonymous"; __goscriptStructLiteral3.Enabled = true; return __goscriptStructLiteral3 })() diff --git a/tests/tests/the_works/the_works.gs.ts b/tests/tests/the_works/the_works.gs.ts index 26e125879..9af264a6a 100644 --- a/tests/tests/the_works/the_works.gs.ts +++ b/tests/tests/the_works/the_works.gs.ts @@ -170,7 +170,7 @@ export class VM { public Step(code: $.Slice): boolean { const vm: VM | $.VarRef | null = this; const vm$: VM = vm == null ? $.pointerTarget(vm) : (vm as any).__isVarRef === true ? (vm as any).value : (vm as any).__goValue === undefined ? (vm as any) : $.pointerTarget(vm) - let _in = ($.arrayIndex(code!, (vm$ as VM).pc)).clone(); + let _in = ($.plainSliceIndex(code!, (vm$ as VM).pc)).clone(); ;(vm$ as VM).pc++; ;(vm$ as VM).steps++ let s = $.fieldRef((vm$ as VM), "stack") @@ -385,10 +385,10 @@ export function factorial(name: string, n: bigint): Program { export async function main(): globalThis.Promise { let programs = $.arrayToSlice([factorial("20!", 20n), factorial("21!", 21n), new Program(true, "broken", $.arrayToSlice([new Instr(true, 0, 1n), new Instr(true, 6, 0n), new Instr(true, 9, 0n)]))]) - await $.println("listing of", $.arrayIndex(programs!, 0).Name) + await $.println("listing of", $.plainSliceIndex(programs!, 0).Name) let __goscriptRangeReturn0 = false ;await (async () => { - await $.markAsStructValue($.cloneStructValue($.arrayIndex(programs!, 0))).Listing()!(async (pc, _in) => { + await $.markAsStructValue($.cloneStructValue($.plainSliceIndex(programs!, 0))).Listing()!(async (pc, _in) => { if ((_in.Op == 0) || (_in.Op == 8)) { await $.println(" ", pc, Op_String(_in.Op), _in.Arg) return true diff --git a/tests/tests/type_method_primitive/type_method_primitive.gs.ts b/tests/tests/type_method_primitive/type_method_primitive.gs.ts index 6ff06d28d..447554c83 100644 --- a/tests/tests/type_method_primitive/type_method_primitive.gs.ts +++ b/tests/tests/type_method_primitive/type_method_primitive.gs.ts @@ -61,7 +61,7 @@ export function asDoubler(v: MyInt): Doubler | null { } export function sumDoublers(vals: $.Slice): number { - return $.pointerValue>($.arrayIndex(vals!, 0)).Double() + $.pointerValue>($.arrayIndex(vals!, 1)).Double() + return $.pointerValue>($.plainSliceIndex(vals!, 0)).Double() + $.pointerValue>($.plainSliceIndex(vals!, 1)).Double() } export function assertDoubler(__typeArgs: $.GenericTypeArgs | undefined, v: Doubler | null): [any, boolean] { diff --git a/tests/tests/type_switch_statement/type_switch_statement.gs.ts b/tests/tests/type_switch_statement/type_switch_statement.gs.ts index 5fa57d009..11ef7f38d 100644 --- a/tests/tests/type_switch_statement/type_switch_statement.gs.ts +++ b/tests/tests/type_switch_statement/type_switch_statement.gs.ts @@ -191,7 +191,7 @@ export async function main(): globalThis.Promise { break } } - await $.println("oid", $.sliceLen((oid.value as ObjectIdentifier)), $.arrayIndex(oid.value!, 0), ok) + await $.println("oid", $.sliceLen((oid.value as ObjectIdentifier)), $.plainSliceIndex(oid.value!, 0), ok) let raw: $.VarRef = $.varRef(new RawValue(true)) let rawValue: any = $.interfaceValue(raw, "*main.RawValue", /* @__PURE__ */ $.pointerType("main.RawValue")) diff --git a/tests/tests/typed_numeric_slices/typed_numeric_slices.gs.ts b/tests/tests/typed_numeric_slices/typed_numeric_slices.gs.ts index 40ad47699..5aa205b6c 100644 --- a/tests/tests/typed_numeric_slices/typed_numeric_slices.gs.ts +++ b/tests/tests/typed_numeric_slices/typed_numeric_slices.gs.ts @@ -87,26 +87,26 @@ export async function localLiterals(): globalThis.Promise { let u16 = $.arrayToSlice([65535, 3]) $.sliceElems(u16!)[$.sliceSlot(u16!, 0)] = (($.sliceElems(u16!)[$.sliceSlot(u16!, 0)] + 1) & 0xffff) $.sliceElems(u16!)[$.sliceSlot(u16!, 1)] = $.uint($.sliceElems(u16!)[$.sliceSlot(u16!, 1)] - (4), 16) - await $.println("local wrap:", $.arrayIndex(i32!, 0), $.arrayIndex(i32!, 1), $.arrayIndex(i32!, 2), $.arrayIndex(u8s!, 0), $.arrayIndex(u16!, 0), $.arrayIndex(u16!, 1)) + await $.println("local wrap:", $.typedSliceIndex(i32!, 0), $.typedSliceIndex(i32!, 1), $.typedSliceIndex(i32!, 2), $.typedSliceIndex(u8s!, 0), $.typedSliceIndex(u16!, 0), $.typedSliceIndex(u16!, 1)) let f = $.arrayToSlice([0.10000000149011612, 1.6777216e+07]) $.sliceElems(f!)[$.sliceSlot(f!, 0)] = globalThis.Math.fround($.sliceElems(f!)[$.sliceSlot(f!, 0)] * (3)) $.sliceElems(f!)[$.sliceSlot(f!, 1)] = globalThis.Math.fround($.sliceElems(f!)[$.sliceSlot(f!, 1)] + 1) let x = 0.1 - $.sliceElems(f!)[$.sliceSlot(f!, 0)] = globalThis.Math.fround($.arrayIndex(f!, 0) + globalThis.Math.fround(x)) - await $.println("local float32:", $.arrayIndex(f!, 0) == (0.4000000059604645), $.arrayIndex(f!, 1) == 1.6777216e+07, $.sliceLen(f), $.cap(f)) + $.sliceElems(f!)[$.sliceSlot(f!, 0)] = globalThis.Math.fround($.typedSliceIndex(f!, 0) + globalThis.Math.fround(x)) + await $.println("local float32:", $.typedSliceIndex(f!, 0) == (0.4000000059604645), $.typedSliceIndex(f!, 1) == 1.6777216e+07, $.sliceLen(f), $.cap(f)) let t = 0 for (let i = 0; i < 100; i++) { let v = $.arrayToSlice([globalThis.Math.fround(globalThis.Math.fround(i) / 3), 1, 2]) - t = globalThis.Math.fround(t + (globalThis.Math.fround($.arrayIndex(v!, 0) + $.arrayIndex(v!, 2)))) + t = globalThis.Math.fround(t + (globalThis.Math.fround($.typedSliceIndex(v!, 0) + $.typedSliceIndex(v!, 2)))) } let acc = $.arrayToSlice([0, 0]) let add = $.functionValue((n: number) => { $.sliceElems(acc!)[$.sliceSlot(acc!, 0)] = $.uint($.sliceElems(acc!)[$.sliceSlot(acc!, 0)] + (n), 32) - $.sliceElems(acc!)[$.sliceSlot(acc!, 1)] = $.uint(globalThis.Math.imul($.arrayIndex(acc!, 0), 3) >>> 0, 32) + $.sliceElems(acc!)[$.sliceSlot(acc!, 1)] = $.uint(globalThis.Math.imul($.typedSliceIndex(acc!, 0), 3) >>> 0, 32) }, ({ kind: $.TypeKind.Function, params: [/* @__PURE__ */ $.basicType("uint32")], results: [] } as $.FunctionTypeInfo)) add(0x80000000) add(0x80000001) - await $.println("local loop:", t, $.arrayIndex(acc!, 0), $.arrayIndex(acc!, 1)) + await $.println("local loop:", t, $.typedSliceIndex(acc!, 0), $.typedSliceIndex(acc!, 1)) let __goscriptShadow0 = 0.0 for (let __goscriptRangeTarget1 = $.typedSliceOf(Float64Array, [0.5, 0.25]) as $.Slice, __goscriptRangeWindow1 = $.sliceRange(__goscriptRangeTarget1), i = 0; i < __goscriptRangeWindow1.length; i++) { let e = (__goscriptRangeWindow1.backing[__goscriptRangeWindow1.offset + i] as number) @@ -115,7 +115,7 @@ export async function localLiterals(): globalThis.Promise { let w: $.Slice = $.arrayToSlice([1, 2]) w = $.typedSliceOf(Int16Array, [32767]) as $.Slice $.sliceElems(w!)[$.sliceSlot(w!, 0)] = (($.sliceElems(w!)[$.sliceSlot(w!, 0)] + 1) << 16 >> 16) - await $.println("local range:", __goscriptShadow0, $.arrayIndex(w!, 0), $.sliceLen(w)) + await $.println("local range:", __goscriptShadow0, $.typedSliceIndex(w!, 0), $.sliceLen(w)) } export async function main(): globalThis.Promise { @@ -123,12 +123,12 @@ export async function main(): globalThis.Promise { // Integer elements wrap around, as Go stores them. let i32 = $.typedSliceOf(Int32Array, [2147483647]) as $.Slice $.sliceElems(i32!)[$.sliceSlot(i32!, 0)] = (($.sliceElems(i32!)[$.sliceSlot(i32!, 0)] + 1) | 0) - await $.println("int32 wrap:", $.arrayIndex(i32!, 0)) + await $.println("int32 wrap:", $.typedSliceIndex(i32!, 0)) let u32 = $.makeSlice(2, undefined, "uint32") $.sliceElems(u32!)[$.sliceSlot(u32!, 0)] = (($.sliceElems(u32!)[$.sliceSlot(u32!, 0)] - 1) >>> 0) $.sliceElems(u32!)[$.sliceSlot(u32!, 1)] = 2147483648 $.sliceElems(u32!)[$.sliceSlot(u32!, 1)] = globalThis.Math.imul($.sliceElems(u32!)[$.sliceSlot(u32!, 1)], 2) >>> 0 - await $.println("uint32 wrap:", $.arrayIndex(u32!, 0), $.arrayIndex(u32!, 1)) + await $.println("uint32 wrap:", $.typedSliceIndex(u32!, 0), $.typedSliceIndex(u32!, 1)) let i16 = $.typedSliceOf(Int16Array, [32767, -32768]) as $.Slice $.sliceElems(i16!)[$.sliceSlot(i16!, 0)] = (($.sliceElems(i16!)[$.sliceSlot(i16!, 0)] + 1) << 16 >> 16) $.sliceElems(i16!)[$.sliceSlot(i16!, 1)] = (($.sliceElems(i16!)[$.sliceSlot(i16!, 1)] - 1) << 16 >> 16) @@ -136,26 +136,26 @@ export async function main(): globalThis.Promise { $.sliceElems(u16!)[$.sliceSlot(u16!, 0)] = $.uint($.sliceElems(u16!)[$.sliceSlot(u16!, 0)] + (2), 16) let i8 = $.typedSliceOf(Int8Array, [127]) as $.Slice $.sliceElems(i8!)[$.sliceSlot(i8!, 0)] = (($.sliceElems(i8!)[$.sliceSlot(i8!, 0)] + 1) << 24 >> 24) - await $.println("small wrap:", $.arrayIndex(i16!, 0), $.arrayIndex(i16!, 1), $.arrayIndex(u16!, 0), $.arrayIndex(i8!, 0)) + await $.println("small wrap:", $.typedSliceIndex(i16!, 0), $.typedSliceIndex(i16!, 1), $.typedSliceIndex(u16!, 0), $.typedSliceIndex(i8!, 0)) // float32 elements round to float32, float64 elements do not. let f32 = $.makeSlice(3, undefined, "float32") $.sliceElems(f32!)[$.sliceSlot(f32!, 0)] = 0.10000000149011612 - $.sliceElems(f32!)[$.sliceSlot(f32!, 1)] = globalThis.Math.fround($.arrayIndex(f32!, 0) * 3) + $.sliceElems(f32!)[$.sliceSlot(f32!, 1)] = globalThis.Math.fround($.typedSliceIndex(f32!, 0) * 3) let x = 16777216.0 $.sliceElems(f32!)[$.sliceSlot(f32!, 2)] = globalThis.Math.fround((x + 1)) - await $.println("float32:", $.arrayIndex(f32!, 0) == 0.10000000149011612, $.arrayIndex(f32!, 0) == 0.1, $.arrayIndex(f32!, 1) == 0.30000001192092896, $.arrayIndex(f32!, 1) == 0.3, $.arrayIndex(f32!, 2) == 1.6777216e+07) + await $.println("float32:", $.typedSliceIndex(f32!, 0) == 0.10000000149011612, $.typedSliceIndex(f32!, 0) == 0.1, $.typedSliceIndex(f32!, 1) == 0.30000001192092896, $.typedSliceIndex(f32!, 1) == 0.3, $.typedSliceIndex(f32!, 2) == 1.6777216e+07) let f64 = $.typedSliceOf(Float64Array, [0.1]) as $.Slice $.sliceElems(f64!)[$.sliceSlot(f64!, 0)] *= 3 - await $.println("float64:", $.arrayIndex(f64!, 0) == 0.3, $.arrayIndex(f64!, 0)) - await $.println("variadic:", sum($.typedSliceOf(Float32Array, [1.5, 2.25, 0.125]) as $.Slice), sum($.goSlice(f32, undefined, 2)) == (globalThis.Math.fround($.arrayIndex(f32!, 0) + $.arrayIndex(f32!, 1)))) + await $.println("float64:", $.typedSliceIndex(f64!, 0) == 0.3, $.typedSliceIndex(f64!, 0)) + await $.println("variadic:", sum($.typedSliceOf(Float32Array, [1.5, 2.25, 0.125]) as $.Slice), sum($.goSlice(f32, undefined, 2)) == (globalThis.Math.fround($.typedSliceIndex(f32!, 0) + $.typedSliceIndex(f32!, 1)))) // Nil and empty slices differ, and nil appends as empty. let nilF: $.Slice = null! as $.Slice let empty = $.typedSliceOf(Float32Array, []) as $.Slice await $.println("nil:", nilF == null, empty == null, $.sliceLen(nilF), $.sliceLen(empty), $.cap(empty)) nilF = $.appendValues(nilF, $.typedSliceHints.float32, 1, 2) - await $.println("append nil:", $.sliceLen(nilF), $.arrayIndex(nilF!, 0), $.arrayIndex(nilF!, 1)) + await $.println("append nil:", $.sliceLen(nilF), $.typedSliceIndex(nilF!, 0), $.typedSliceIndex(nilF!, 1)) let nilU: $.Slice = null! as $.Slice nilU = $.appendSlice(nilU, $.typedSliceOf(Uint16Array, []) as $.Slice, $.typedSliceHints.uint16) await $.println("append none to nil:", nilU == null) @@ -165,28 +165,28 @@ export async function main(): globalThis.Promise { let base = $.makeSlice(2, 4, "float32") let a = $.appendOne(base, 3, $.typedSliceHints.float32) let b = $.appendOne(base, 4, $.typedSliceHints.float32) - await $.println("shared:", $.arrayIndex(a!, 2), $.arrayIndex(b!, 2), $.sliceLen(a), $.cap(a)) + await $.println("shared:", $.typedSliceIndex(a!, 2), $.typedSliceIndex(b!, 2), $.sliceLen(a), $.cap(a)) let c = $.appendValues(a, $.typedSliceHints.float32, 5, 6) $.sliceElems(c!)[$.sliceSlot(c!, 0)] = 9 - await $.println("grown:", $.sliceLen(c), $.cap(c) >= 5, $.arrayIndex(a!, 0), $.arrayIndex(c!, 0), $.arrayIndex(c!, 4)) + await $.println("grown:", $.sliceLen(c), $.cap(c) >= 5, $.typedSliceIndex(a!, 0), $.typedSliceIndex(c!, 0), $.typedSliceIndex(c!, 4)) let grow: $.Slice = null! as $.Slice for (let i = 0; i < 1000; i++) { grow = $.appendOne(grow, $.int(globalThis.Math.imul($.int(i, 32), 3000000), 32), $.typedSliceHints.int32) } - await $.println("many appends:", $.sliceLen(grow), $.arrayIndex(grow!, 999), $.arrayIndex(grow!, 500)) + await $.println("many appends:", $.sliceLen(grow), $.typedSliceIndex(grow!, 999), $.typedSliceIndex(grow!, 500)) // Slicing windows share elements, reslice into spare capacity, and keep // the capacity of their window. let w = $.typedSliceOf(Uint32Array, [1, 2, 3, 4, 5, 6]) as $.Slice let mid = $.goSlice(w, 2, 4) $.sliceElems(mid!)[$.sliceSlot(mid!, 0)] = 30 - await $.println("window:", $.arrayIndex(w!, 2), $.sliceLen(mid), $.cap(mid), $.arrayIndex(mid!, 1)) + await $.println("window:", $.typedSliceIndex(w!, 2), $.sliceLen(mid), $.cap(mid), $.typedSliceIndex(mid!, 1)) let ext = $.goSlice(mid, undefined, 4) $.sliceElems(ext!)[$.sliceSlot(ext!, 3)] = 60 - await $.println("extended:", $.sliceLen(ext), $.arrayIndex(w!, 5)) + await $.println("extended:", $.sliceLen(ext), $.typedSliceIndex(w!, 5)) let clipped: $.Slice = $.goSlice(w, 1, 3, 3) clipped = $.appendOne(clipped, $.uint(99, 32), $.typedSliceHints.uint32) - await $.println("clipped:", $.arrayIndex(w!, 3), $.arrayIndex(clipped!, 2), $.cap(clipped) >= 3) + await $.println("clipped:", $.typedSliceIndex(w!, 3), $.typedSliceIndex(clipped!, 2), $.cap(clipped) >= 3) for (let __goscriptRangeTarget2 = $.goSlice(w, 4, undefined), __goscriptRangeWindow2 = $.sliceRange(__goscriptRangeTarget2), i = 0; i < __goscriptRangeWindow2.length; i++) { let v = $.uint((__goscriptRangeWindow2.backing[__goscriptRangeWindow2.offset + i] as number), 32) await $.println("range:", i, v) @@ -196,22 +196,22 @@ export async function main(): globalThis.Promise { // between typed and generic slices. let src = $.typedSliceOf(Float64Array, [1, 2, 3, 4, 5]) as $.Slice let n = $.copy($.goSlice(src, 1, undefined), src) - await $.println("overlap copy:", n, $.arrayIndex(src!, 0), $.arrayIndex(src!, 1), $.arrayIndex(src!, 4)) + await $.println("overlap copy:", n, $.typedSliceIndex(src!, 0), $.typedSliceIndex(src!, 1), $.typedSliceIndex(src!, 4)) let gen: $.Slice = (makeOf(__goscriptStatic1(), 3) as $.Slice) $.sliceElems(gen!)[$.sliceSlot(gen!, 0)] = 0.10000000149011612 n = $.copy(f32, gen) - await $.println("copy from generic:", n, $.arrayIndex(f32!, 0) == 0.10000000149011612, $.arrayIndex(f32!, 2)) + await $.println("copy from generic:", n, $.typedSliceIndex(f32!, 0) == 0.10000000149011612, $.typedSliceIndex(f32!, 2)) n = $.copy(gen, $.typedSliceOf(Float32Array, [7, 8]) as $.Slice) - await $.println("copy to generic:", n, $.arrayIndex(gen!, 0), $.arrayIndex(gen!, 1)) + await $.println("copy to generic:", n, $.typedSliceIndex(gen!, 0), $.typedSliceIndex(gen!, 1)) gen = $.appendOne(gen, 1.5, $.typedSliceHints.float32) - await $.println("append generic:", $.sliceLen(gen), $.arrayIndex(gen!, 3)) + await $.println("append generic:", $.sliceLen(gen), $.typedSliceIndex(gen!, 3)) let plain: $.Slice = (appendOf(__goscriptStatic1(), null, $.typedSliceOf(Float32Array, [0.10000000149011612, 2]) as $.Slice) as $.Slice) n = $.copy(f32, plain) - await $.println("copy from plain:", n, $.arrayIndex(f32!, 0) == 0.10000000149011612, $.arrayIndex(f32!, 1)) + await $.println("copy from plain:", n, $.typedSliceIndex(f32!, 0) == 0.10000000149011612, $.typedSliceIndex(f32!, 1)) n = $.copy(plain, $.typedSliceOf(Float32Array, [7]) as $.Slice) plain = $.appendOne(plain, 3, $.typedSliceHints.float32) $.sliceElems(plain!)[$.sliceSlot(plain!, 1)] = globalThis.Math.fround($.sliceElems(plain!)[$.sliceSlot(plain!, 1)] + (0.10000000149011612)) - await $.println("copy to plain:", n, $.arrayIndex(plain!, 0), $.sliceLen(plain), $.arrayIndex(plain!, 1) == 2.0999999046325684) + await $.println("copy to plain:", n, $.typedSliceIndex(plain!, 0), $.sliceLen(plain), $.typedSliceIndex(plain!, 1) == 2.0999999046325684) // Arrays stay arrays, and a slice of an array shares its elements. let arr = $.arrayValue([1, 2, 3, 4], __goscriptStatic2()) @@ -222,27 +222,27 @@ export async function main(): globalThis.Promise { await $.println("array append:", arr[3]) let arr2 = $.cloneArrayValue($.sliceToArray($.goSlice(w, undefined, 3), 3), /* @__PURE__ */ $.arrayType(/* @__PURE__ */ $.basicType("uint32"), 3)) arr2[0] = 100 - await $.println("slice to array:", arr2[0], $.arrayIndex(w!, 0), 3) + await $.println("slice to array:", arr2[0], $.typedSliceIndex(w!, 0), 3) let ap = $.sliceToArrayPointer($.goSlice(w, 1, undefined), 2) $.pointerValue(ap)[0] = 200 - await $.println("array pointer:", $.arrayIndex(w!, 1)) + await $.println("array pointer:", $.typedSliceIndex(w!, 1)) // clear zeroes the window only. let z = $.typedSliceOf(Int16Array, [1, 2, 3, 4]) as $.Slice $.clear($.goSlice(z, 1, 3), () => 0) - await $.println("clear:", $.arrayIndex(z!, 0), $.arrayIndex(z!, 1), $.arrayIndex(z!, 2), $.arrayIndex(z!, 3)) + await $.println("clear:", $.typedSliceIndex(z!, 0), $.typedSliceIndex(z!, 1), $.typedSliceIndex(z!, 2), $.typedSliceIndex(z!, 3)) // Pointers to elements read and write the element. let p = $.indexRef(f64!, 0) p!.value = 2.5 let q = $.indexRef(w!, 2) q!.value = $.uint(q!.value + (1), 32) - await $.println("pointer:", $.arrayIndex(f64!, 0), $.arrayIndex(w!, 2), $.indexAddress(w!, 2) == $.indexAddress(mid!, 0)) + await $.println("pointer:", $.typedSliceIndex(f64!, 0), $.typedSliceIndex(w!, 2), $.indexAddress(w!, 2) == $.indexAddress(mid!, 0)) // Named element types and type switches tell typed slices apart. let temps: $.Slice = $.typedSliceOf(Float32Array, [36.599998474121094, 37.20000076293945]) as $.Slice temps = $.appendOne(temps, 38, $.typedSliceHints.float32) - await $.println("named:", $.sliceLen(temps), $.arrayIndex(temps!, 2), kind($.interfaceValue(temps, "[]main.celsius", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("float32", "main.celsius"))))) + await $.println("named:", $.sliceLen(temps), $.typedSliceIndex(temps!, 2), kind($.interfaceValue(temps, "[]main.celsius", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("float32", "main.celsius"))))) await $.println("kinds:", kind($.interfaceValue(f32, "[]float32", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("float32")))), kind($.interfaceValue(f64, "[]float64", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("float64")))), kind($.interfaceValue(i32, "[]int32", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("int32")))), kind($.interfaceValue(u32, "[]uint32", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("uint32")))), kind($.interfaceValue(i16, "[]int16", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("int16")))), kind($.interfaceValue(u16, "[]uint16", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("uint16")))), kind($.interfaceValue(i8, "[]int8", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("int8")))), kind($.interfaceValue(new Uint8Array([1]) as $.Slice, "[]byte", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("uint8"))))) let anyRunes: any = $.interfaceValue($.stringToRunes("h\xc3\xa9"), "[]rune", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("int32"))) let [, isRunes] = $.typeAssertTuple<$.Slice>(anyRunes, /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("int32"))) diff --git a/tests/tests/unsafe_array_pointer_slice/unsafe_array_pointer_slice.gs.ts b/tests/tests/unsafe_array_pointer_slice/unsafe_array_pointer_slice.gs.ts index 7b14677e2..28bf1e57e 100644 --- a/tests/tests/unsafe_array_pointer_slice/unsafe_array_pointer_slice.gs.ts +++ b/tests/tests/unsafe_array_pointer_slice/unsafe_array_pointer_slice.gs.ts @@ -13,14 +13,14 @@ export async function main(): globalThis.Promise { let buf = new Uint8Array([9, 1, 2, 3, 4]) as $.Slice let ptr = $.unsafePointerCast<$.VarRef | null>($.arrayPointerFromIndexRef($.indexRef(buf!, 1), 4, 1, 1)) let view = $.goSlice($.pointerValue(ptr), undefined, undefined) - await $.println($.sliceLen(view), $.arrayIndex(view!, 0), $.arrayIndex(view!, 3)) + await $.println($.sliceLen(view), $.typedSliceIndex(view!, 0), $.typedSliceIndex(view!, 3)) $.pointerValue(ptr)[2] = 7 - await $.println($.arrayIndex(buf!, 3)) + await $.println($.typedSliceIndex(buf!, 3)) let __goscriptShadow0: $.VarRef = $.varRef($.arrayValue(new Uint8Array(4))) fill(__goscriptShadow0) let shadowView = $.goSlice(__goscriptShadow0.value, undefined, undefined) - await $.println($.sliceLen(shadowView), $.arrayIndex(shadowView!, 0), $.arrayIndex(shadowView!, 3)) + await $.println($.sliceLen(shadowView), $.typedSliceIndex(shadowView!, 0), $.typedSliceIndex(shadowView!, 3)) } export function fill(out: $.VarRef | null): void { diff --git a/tests/tests/unsafe_noescape_uintptr_xor/unsafe_noescape_uintptr_xor.gs.ts b/tests/tests/unsafe_noescape_uintptr_xor/unsafe_noescape_uintptr_xor.gs.ts index 15caf84ad..258602327 100644 --- a/tests/tests/unsafe_noescape_uintptr_xor/unsafe_noescape_uintptr_xor.gs.ts +++ b/tests/tests/unsafe_noescape_uintptr_xor/unsafe_noescape_uintptr_xor.gs.ts @@ -88,9 +88,9 @@ export async function main(): globalThis.Promise { await $.println("nil:", q == null) let inline = inlineSlice(values) - await $.println("inline:", $.arrayIndex(inline!, 0), $.arrayIndex(inline!, 1)) + await $.println("inline:", $.plainSliceIndex(inline!, 0), $.plainSliceIndex(inline!, 1)) $.sliceElems(inline!)[$.sliceSlot(inline!, 0)] = 9 - await $.println("updated:", $.arrayIndex(values!, 0)) + await $.println("updated:", $.plainSliceIndex(values!, 0)) let src: $.VarRef = $.varRef(new sourceStruct(true)) await $.println("struct:", markThroughView(src), src.value.flag) diff --git a/tests/tests/unsafe_string_slice_header/unsafe_string_slice_header.gs.ts b/tests/tests/unsafe_string_slice_header/unsafe_string_slice_header.gs.ts index ebe91f8cb..7b22046e8 100644 --- a/tests/tests/unsafe_string_slice_header/unsafe_string_slice_header.gs.ts +++ b/tests/tests/unsafe_string_slice_header/unsafe_string_slice_header.gs.ts @@ -60,9 +60,9 @@ export function samePointers(s: $.VarRef | null, b: $.VarRef<$.Slice { let b = stringBytes("abc") - await $.println($.sliceLen(b), $.cap(b), $.arrayIndex(b!, 0), $.arrayIndex(b!, 1), $.arrayIndex(b!, 2)) + await $.println($.sliceLen(b), $.cap(b), $.typedSliceIndex(b!, 0), $.typedSliceIndex(b!, 1), $.typedSliceIndex(b!, 2)) let local = localStringBytes("wxyz") - await $.println($.sliceLen(local), $.cap(local), $.arrayIndex(local!, 0), $.arrayIndex(local!, 3)) + await $.println($.sliceLen(local), $.cap(local), $.typedSliceIndex(local!, 0), $.typedSliceIndex(local!, 3)) let str = $.varRef("pointer") let bytes: $.VarRef<$.Slice> = $.varRef(new Uint8Array([103, 111])) let [sp, bp] = samePointers(str, bytes) diff --git a/tests/tests/unsafe_typed_slice_bytes/unsafe_typed_slice_bytes.gs.ts b/tests/tests/unsafe_typed_slice_bytes/unsafe_typed_slice_bytes.gs.ts index 5287d0de9..ca2b04939 100644 --- a/tests/tests/unsafe_typed_slice_bytes/unsafe_typed_slice_bytes.gs.ts +++ b/tests/tests/unsafe_typed_slice_bytes/unsafe_typed_slice_bytes.gs.ts @@ -20,29 +20,29 @@ export async function main(): globalThis.Promise { // The bytes are the little-endian encoding of the elements. let f = $.typedSliceOf(Float32Array, [1, -2, 0.5]) as $.Slice let b = floatBytes(f) - await $.println("float bytes:", $.sliceLen(b), $.arrayIndex(b!, 2), $.arrayIndex(b!, 3), $.arrayIndex(b!, 7), $.arrayIndex(b!, 11)) + await $.println("float bytes:", $.sliceLen(b), $.typedSliceIndex(b!, 2), $.typedSliceIndex(b!, 3), $.typedSliceIndex(b!, 7), $.typedSliceIndex(b!, 11)) // Writes through either side are seen by the other. $.sliceElems(b!)[$.sliceSlot(b!, 3)] = 0x40 $.sliceElems(f!)[$.sliceSlot(f!, 2)] = 2 - await $.println("shared:", $.arrayIndex(f!, 0), $.arrayIndex(b!, 11)) + await $.println("shared:", $.typedSliceIndex(f!, 0), $.typedSliceIndex(b!, 11)) // A window views only its own elements. let u = $.typedSliceOf(Uint32Array, [0x01020304, 0x05060708, 0x090a0b0c]) as $.Slice let w = uintBytes($.goSlice(u, 1, undefined)) - await $.println("window:", $.sliceLen(w), $.arrayIndex(w!, 0), $.arrayIndex(w!, 4)) + await $.println("window:", $.sliceLen(w), $.typedSliceIndex(w!, 0), $.typedSliceIndex(w!, 4)) $.sliceElems(w!)[$.sliceSlot(w!, 0)] = 0xff - await $.println("window write:", $.arrayIndex(u!, 1) == 0x050607ff) + await $.println("window write:", $.typedSliceIndex(u!, 1) == 0x050607ff) // The element pointer is that of the slice. let e = (unsafe.Slice!($.indexRef(u!, 1), 2, "uint32") as $.Slice) $.sliceElems(e!)[$.sliceSlot(e!, 1)] = 7 - await $.println("same kind:", $.arrayIndex(u!, 2), $.sliceLen(e), $.cap(e)) + await $.println("same kind:", $.typedSliceIndex(u!, 2), $.sliceLen(e), $.cap(e)) // The bytes of an int16 slice, and back from bytes to elements. let i = $.typedSliceOf(Int16Array, [-1, 256]) as $.Slice let ib = (unsafe.Slice!(($.indexRef(i!, 0) as any), 4, "byte") as $.Slice) - await $.println("int16 bytes:", $.arrayIndex(ib!, 0), $.arrayIndex(ib!, 1), $.arrayIndex(ib!, 2), $.arrayIndex(ib!, 3)) + await $.println("int16 bytes:", $.typedSliceIndex(ib!, 0), $.typedSliceIndex(ib!, 1), $.typedSliceIndex(ib!, 2), $.typedSliceIndex(ib!, 3)) await $.println("nil:", floatBytes(null) == null) } diff --git a/tests/tests/value_param_readonly_calls/value_param_readonly_calls.gs.ts b/tests/tests/value_param_readonly_calls/value_param_readonly_calls.gs.ts index fe89796c0..c8fd51532 100644 --- a/tests/tests/value_param_readonly_calls/value_param_readonly_calls.gs.ts +++ b/tests/tests/value_param_readonly_calls/value_param_readonly_calls.gs.ts @@ -122,7 +122,7 @@ export function bumpH(): void { } export function bumpElem(): void { - $.arrayIndex(regions!, 0).Start.Line = 5 + $.plainSliceIndex(regions!, 0).Start.Line = 5 } export function F(r: Region): number { @@ -149,8 +149,8 @@ export async function main(): globalThis.Promise { await $.println("F(g):", F((g).clone())) $.pointerValue(h).r.Start.Line = 2 await $.println("FH(h.r):", FH(($.pointerValue(h).r).clone())) - $.arrayIndex(regions!, 0).Start.Line = 3 - await $.println("FE(regions[0]):", FE(($.arrayIndex(regions!, 0)).clone())) + $.plainSliceIndex(regions!, 0).Start.Line = 3 + await $.println("FE(regions[0]):", FE(($.plainSliceIndex(regions!, 0)).clone())) g.Start.Line = 4 await $.println("g.lineAfterBump():", $.markAsStructValue($.cloneStructValue(g)).lineAfterBump()) await $.println("plain(g):", plain(g)) diff --git a/tests/tests/wide_uint64_ops/wide_uint64_ops.gs.ts b/tests/tests/wide_uint64_ops/wide_uint64_ops.gs.ts index 0cad201ac..a30f3e3c7 100644 --- a/tests/tests/wide_uint64_ops/wide_uint64_ops.gs.ts +++ b/tests/tests/wide_uint64_ops/wide_uint64_ops.gs.ts @@ -33,7 +33,7 @@ export function maxUint64Remainder(d: bigint): bigint { export function setHighBit(idx: bigint): boolean { let words = $.arrayToSlice([0n, 0n]) $.sliceElems(words!)[$.sliceSlot(words!, $.uint64ToNumber($.uint64Div(idx, 64n)))] = $.uint64Or($.sliceElems(words!)[$.sliceSlot(words!, $.uint64ToNumber($.uint64Div(idx, 64n)))], $.uint64Bit(($.uint64Mod(idx, 64n)))) - return $.arrayIndex(words!, 1) != 0n + return $.plainSliceIndex(words!, 1) != 0n } export function uintBitLen(n: number): number { diff --git a/tests/tests/wrapper_slice_append/wrapper_slice_append.gs.ts b/tests/tests/wrapper_slice_append/wrapper_slice_append.gs.ts index d27cad958..05b0957d8 100644 --- a/tests/tests/wrapper_slice_append/wrapper_slice_append.gs.ts +++ b/tests/tests/wrapper_slice_append/wrapper_slice_append.gs.ts @@ -38,7 +38,7 @@ export async function main(): globalThis.Promise { let p: parser = new parser(true) // this Add method does not work: errlist.ErrorList_Add($.fieldRef(p, "errors"), "error") - await $.println($.arrayIndex(p.errors!, 0)) + await $.println($.plainSliceIndex(p.errors!, 0)) // but it does work for a struct type: p.astruct.Set("astruct")