Commit 464d7e36

464d7e3640a5Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 7 months ago · 1 file · ~1 modified

Description

fix: remove dead methods and fread warning in self-compiled output

Remove emit_return (unused, caused int-to-pointer warning) and scan_captured_locals (only self-recursive, never called externally, caused 4 type mismatch warnings). Fix fread return value warning in sp_file_read runtime.

Self-compilation now produces zero warnings with -Wno-all.

Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]

Details

Commit
464d7e3640a5
Parent
5dc3e55ce6a1

spinel_codegen.rbmodifiedView file

@@ -748,14 +748,6 @@
748748 @out = @out + s + 10.chr
749749 end
750750
751- def emit_return(val)
752- s = "" + val
753- if @in_gc_scope == 1
754- emit(" SP_GC_RESTORE();")
755- end
756- emit(" return " + s + ";")
757- 0
758- end
759751
760752 # ---- Type inference ----
761753 def infer_type(nid)
@@ -6187,7 +6179,7 @@
61876179 end
61886180
61896181 def emit_file_io_runtime
6190- emit_raw("static const char *sp_file_read(const char *path) { FILE *f = fopen(path, \"rb\"); if (!f) return \"\"; fseek(f, 0, SEEK_END); long sz = ftell(f); fseek(f, 0, SEEK_SET); char *buf = (char *)malloc(sz + 1); if (sz > 0) fread(buf, 1, sz, f); buf[sz] = 0; fclose(f); return buf; }")
6182+ emit_raw("static const char *sp_file_read(const char *path) { FILE *f = fopen(path, \"rb\"); if (!f) return \"\"; fseek(f, 0, SEEK_END); long sz = ftell(f); fseek(f, 0, SEEK_SET); char *buf = (char *)malloc(sz + 1); if (sz > 0) { size_t r = fread(buf, 1, sz, f); (void)r; } buf[sz] = 0; fclose(f); return buf; }")
61916183 emit_raw("static void sp_file_write(const char *path, const char *data) { FILE *f = fopen(path, \"w\"); if (f) { fputs(data, f); fclose(f); } }")
61926184 emit_raw("static mrb_bool sp_file_exist(const char *path) { FILE *f = fopen(path, \"r\"); if (f) { fclose(f); return TRUE; } return FALSE; }")
61936185 emit_raw("static void sp_file_delete(const char *path) { remove(path); }")
@@ -13761,88 +13753,6 @@
1376113753 emit(" }")
1376213754 end
1376313755 @in_loop = old
13764- end
13765-
13766- def scan_captured_locals(nid, excludes, names, types)
13767- # Type hint: use str_array method to force param typing
13768- if excludes.length < 0
13769- excludes.push("")
13770- end
13771- if names.length < 0
13772- names.push("")
13773- end
13774- if types.length < 0
13775- types.push("")
13776- end
13777- if nid < 0
13778- return
13779- end
13780- if @nd_type[nid] == "LocalVariableReadNode"
13781- lname = @nd_name[nid]
13782- if not_in(lname, excludes) == 1
13783- if not_in(lname, names) == 1
13784- names.push(lname)
13785- vt = find_var_type(lname)
13786- if vt == ""
13787- vt = "int"
13788- end
13789- types.push(vt)
13790- end
13791- end
13792- end
13793- if @nd_type[nid] == "LocalVariableWriteNode"
13794- lname = @nd_name[nid]
13795- if not_in(lname, excludes) == 1
13796- if not_in(lname, names) == 1
13797- names.push(lname)
13798- vt = find_var_type(lname)
13799- if vt == ""
13800- vt = "int"
13801- end
13802- types.push(vt)
13803- end
13804- end
13805- end
13806- # Recurse
13807- if @nd_body[nid] >= 0
13808- scan_captured_locals(@nd_body[nid], excludes, names, types)
13809- end
13810- stmts = parse_id_list(@nd_stmts[nid])
13811- k = 0
13812- while k < stmts.length
13813- scan_captured_locals(stmts[k], excludes, names, types)
13814- k = k + 1
13815- end
13816- if @nd_expression[nid] >= 0
13817- scan_captured_locals(@nd_expression[nid], excludes, names, types)
13818- end
13819- if @nd_predicate[nid] >= 0
13820- scan_captured_locals(@nd_predicate[nid], excludes, names, types)
13821- end
13822- if @nd_left[nid] >= 0
13823- scan_captured_locals(@nd_left[nid], excludes, names, types)
13824- end
13825- if @nd_right[nid] >= 0
13826- scan_captured_locals(@nd_right[nid], excludes, names, types)
13827- end
13828- if @nd_subsequent[nid] >= 0
13829- scan_captured_locals(@nd_subsequent[nid], excludes, names, types)
13830- end
13831- if @nd_else_clause[nid] >= 0
13832- scan_captured_locals(@nd_else_clause[nid], excludes, names, types)
13833- end
13834- if @nd_arguments[nid] >= 0
13835- scan_captured_locals(@nd_arguments[nid], excludes, names, types)
13836- end
13837- args = parse_id_list(@nd_args[nid])
13838- k = 0
13839- while k < args.length
13840- scan_captured_locals(args[k], excludes, names, types)
13841- k = k + 1
13842- end
13843- if @nd_receiver[nid] >= 0
13844- scan_captured_locals(@nd_receiver[nid], excludes, names, types)
13845- end
1384613756 end
1384713757
1384813758 def compile_map_block(nid)