From f6d1abb0af826621c41a0a023a6df3b66aad0d68 Mon Sep 17 00:00:00 2001 From: Ge Wang Date: Sat, 26 Oct 2024 11:01:22 -0700 Subject: [PATCH] augment array type unit test; fix spelling --- VERSIONS | 3 +-- src/core/chuck_instr.cpp | 4 ++-- src/test/01-Basic/235-type-array.ck | 17 +++++++++++++++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/VERSIONS b/VERSIONS index 2072ede2e..3df0b6ef1 100644 --- a/VERSIONS +++ b/VERSIONS @@ -45,8 +45,7 @@ ChucK VERSIONS log are distinguished from windows drive letters (e.g., "A:\") - (fixed) Type.of() now reports more specific array type (e.g., `string[]`) instead of generic `@array` -- (updated) calling .sort() on an array of strings will sort by string - (instead of Object pointers) +- (updated) .sort() a string array will now sort alphabetically (instead of by Object refs) - (updated, internal) dynamic array types are now cached and reused, preventing potential memory build-up across compilations diff --git a/src/core/chuck_instr.cpp b/src/core/chuck_instr.cpp index e9626d06d..02ba4f199 100644 --- a/src/core/chuck_instr.cpp +++ b/src/core/chuck_instr.cpp @@ -6269,7 +6269,7 @@ void Chuck_Instr_Array_Init_Literal::execute( Chuck_VM * vm, Chuck_VM_Shred * sh // reg stack pointer t_CKUINT *& reg_sp = (t_CKUINT *&)shred->reg->sp; - // almagamating array type | 1.5.3.5 (ge, nick, andrew) added after a wild yak hunt + // amalgamating array type | 1.5.3.5 (ge, nick, andrew) added after a wild yak hunt Chuck_Type * arrayType = vm->env()->get_array_type( vm->env()->ckt_array, m_type_ref->array_depth+1, m_type_ref ); // allocate the array @@ -6287,7 +6287,7 @@ void Chuck_Instr_Array_Init_Literal::execute( Chuck_VM * vm, Chuck_VM_Shred * sh // initialize object // should it be this??? initialize_object( array, m_type_ref ); // should it be this??? initialize_object( array, vm->env()->ckt_array, shred, vm ); - // neither! behold -- the almagamated array type... | 1.5.3.5 (ge, nick, andrew) + // neither! behold -- the amalgamated array type... | 1.5.3.5 (ge, nick, andrew) initialize_object( array, arrayType, shred, vm ); // set size diff --git a/src/test/01-Basic/235-type-array.ck b/src/test/01-Basic/235-type-array.ck index 560273693..428c10b2a 100644 --- a/src/test/01-Basic/235-type-array.ck +++ b/src/test/01-Basic/235-type-array.ck @@ -8,10 +8,23 @@ if(!Type.of(arr_vec2).isArray()) me.exit(); SinOsc arr_sin[0]; if(!Type.of(arr_sin).isArray()) me.exit(); - +// test Type.find() with arrays if(!Type.find("int[]").isArray()) me.exit(); if(!Type.find("vec2[][][][]").isArray()) me.exit(); if(!Type.find("SinOsc[][]").isArray()) me.exit(); if(Type.find("float").isArray()) me.exit; -<<< "success" >>>; \ No newline at end of file +// test array type names +[ "a", "b", "c"] @=> string arr_s1[]; +if(arr_s1.typeOf().name() != "string[]") me.exit(); +// note: the follow would use to return more generic "@array" +// as of 1.5.4.0, Type.of() returns more specific type names +if(Type.of(arr_s1).name() != "string[]") me.exit(); + +// 2D arrays +[ ["a"], ["b"] ] @=> string arr_s2[][]; +if(arr_s2.typeOf().name() != "string[][]") me.exit(); +if(Type.of(arr_s2).name() != "string[][]") me.exit(); + +// if we got here, then... +<<< "success" >>>;