Commit d1105343
d1105343b4edMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 2 files · ~2 modified
Description
fix(codegen): case <poly> when <lit> lowers via tag-check
Fixes #387.
case <poly_value> when :sym_literal previously lowered to
mrb_int _t = lv_poly; (sp_RbVal struct→int copy that doesn't
compile) followed by _t == SPS_<sym> (which would compare the
union's first field to the sym id even if assignment had
compiled). Same gap for any other when-literal kind on a poly
predicate.
Three changes in compile_case_stmt / compile_case_return / compile_when_conds:
- When pred type is
poly, hold the case temp assp_RbVal(was alwaysmrb_int). - compile_case_return also gets the poly arm + an obj_ pointer arm (compile_case_stmt already had the pointer arm).
- compile_when_conds emits per-when-literal:
- SymbolNode ->
(t.tag == SP_TAG_SYM && t.v.i == SPS_<n>) - StringNode ->
(t.tag == SP_TAG_STR && strcmp(t.v.s, ...) == 0) - IntegerNode ->
(t.tag == SP_TAG_INT && t.v.i == ...) - FloatNode ->
(t.tag == SP_TAG_FLT && t.v.f == ...) - NilNode ->
(t.tag == SP_TAG_NIL) - True/FalseNode ->
(t.tag == SP_TAG_BOOL && [!]t.v.b) - else fallback ->
sp_poly_eq(t, box(rhs))
- SymbolNode ->
Class-const when Foo is left for the future Class-object work
(falls into the fallback arm; reasonable runtime behaviour for
the rare cases that hit it).
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- d1105343b4ed
- Parent
- cbbcef4706ef
spinel_analyze.rbmodifiedView file
# the cache once with correct context, infer_type stays # uncached during emission. t = @nd_type[nid] if t == "SuperNode" || t == "ForwardingSuperNode" # `super` returns whatever the parent's same-named method # returns. Walk to the parent's `find_method_owner`-resolved # method and read its return type. if @current_class_idx >= 0 && @current_method_name != "" parent_name_st = @cls_parents[@current_class_idx] if parent_name_st != "" parent_ci_st = find_class_idx(parent_name_st) if parent_ci_st >= 0 owner_st = find_method_owner(parent_ci_st, @current_method_name) if owner_st != "" ret_st = cls_method_return(find_class_idx(owner_st), @current_method_name) if ret_st != "" return ret_st end end end end end return "int" end if t == "IntegerNode" return "int" endspinel_codegen.rbmodifiedView file
Loading diff…