Commit 8b834b63
8b834b6364b4Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 3 files · +2 added · ~1 modified
Description
Collect heap objects from a typed-array map into a PtrArray
arr.map { Obj.new } over a typed-array (or range) receiver
build-errored: compile_map_expr's accumulator switch handled
string/float/typed-array/poly-array block returns but not an
object-typed return, so it fell to the IntArray default and the
sp_* element push failed to compile (incompatible type for argument 2 of sp_IntArray_push). Analyze already types such a map
obj_<C>_ptr_array.
Add an is_obj_type(block_ret) arm to the int_array-recv branch's
accumulator and push: collect into a PtrArray of the object pointers.
Strictly additive -- it only fires for a case that errored before, so
no compiling program (optcarrot/bootstrap included) exercised it.
Scoped to heap (non-value-type) classes: a value-type class's constructor returns a struct by value, not a pointer, so it can't go in a void* PtrArray -- value-type-in-map needs value-type-collection support and falls through unchanged.
Fixes #1056
Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]
Details
- Commit
- 8b834b6364b4
- Parent
- 72c292271321
spinel_codegen.rbmodifiedView file
# so the cls_id chain stays tagged for `arr[i][j][k]...`. ret_is_arr2 = (block_ret == "int_array" || block_ret == "float_array" || block_ret == "str_array" || block_ret == "sym_array") ret_is_deep_arr2 = (is_ptr_array_type(block_ret) == 1 || block_ret == "poly_array") # Block returns a heap user object (`arr.map { Obj.new }`): collect # into a PtrArray of the object pointers (analyze types the result # `obj_<C>_ptr_array`). Without this the accumulator defaulted to # IntArray and the sp_<C>* push failed to compile. Value-type # classes are excluded -- their constructor returns a struct by # value, not a pointer, so they need value-type-collection support # (separate work); they fall through unchanged. ret_is_obj2 = (is_obj_type(block_ret) == 1 && is_value_type_class(block_ret[4, block_ret.length - 4]) == 0) if ret_is_deep_arr2 @needs_rb_value = 1 emit(" sp_PolyArray *" + tmp_arr + " = sp_PolyArray_new();") elsif ret_is_arr2 elsif ret_is_arr2 || ret_is_obj2 @needs_ptr_array = 1 emit(" sp_PtrArray *" + tmp_arr + " = sp_PtrArray_new();") else else emit(" sp_PolyArray_push(" + tmp_arr + ", " + box_value_to_poly(block_ret, val) + ");") end elsif ret_is_arr2 elsif ret_is_arr2 || ret_is_obj2 emit(" sp_PtrArray_push(" + tmp_arr + ", (void *)(" + val + "));") else emit(" sp_IntArray_push(" + tmp_arr + ", " + val + ");") end else emit_map_default_push(tmp_arr, ret_is_arr2 ? "ptr_array" : "int_array") emit_map_default_push(tmp_arr, (ret_is_arr2 || ret_is_obj2) ? "ptr_array" : "int_array") end end @indent = @indent - 1test/map_to_heap_objects.rbaddedView file
Loading diff…
test/map_to_heap_objects.rb.expectedaddedView file
Loading diff…