Skip to content

Commit

Permalink
augment array type unit test; fix spelling
Browse files Browse the repository at this point in the history
  • Loading branch information
gewang committed Oct 26, 2024
1 parent d6b766b commit f6d1abb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
3 changes: 1 addition & 2 deletions VERSIONS
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/core/chuck_instr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
17 changes: 15 additions & 2 deletions src/test/01-Basic/235-type-array.ck
Original file line number Diff line number Diff line change
Expand Up @@ -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" >>>;
// 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" >>>;

0 comments on commit f6d1abb

Please sign in to comment.