Commit 65acf2f9
65acf2f90b71Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified
Description
Add well-known module constants (Float::, File::, Math::, Integer::)
Float::MAX/MIN/EPSILON/INFINITY/NAN emit DBL_MAX/DBL_MIN/DBL_EPSILON etc. File::SEPARATOR/PATH_SEPARATOR emit string literals. Math::PI/E emit M_PI/M_E. Integer::MAX/MIN raise NameError at runtime (they are undefined in Ruby).
517 -> 518 pass
Co-Authored-By: Claude Sonnet 4.6 [email protected]
Details
- Commit
- 65acf2f90b71
- Parent
- c593be1fdfb9
src/analyze.cmodifiedView file
@@ -1176,6 +1176,25 @@
11761176
LocalVar *lv = nm ? comp_const(c, nm) : NULL;11771177
if (lv) return lv->type;11781178
if (nm && !strcmp(nm, "ARGV")) return TY_STR_ARRAY;1179+
/* well-known module constants */1180+
int par_id = nt_ref(nt, id, "parent");1181+
const char *par_ty = par_id >= 0 ? nt_type(nt, par_id) : NULL;1182+
const char *par_nm = (par_ty && !strcmp(par_ty, "ConstantReadNode")) ? nt_str(nt, par_id, "name") : NULL;1183+
if (par_nm && !strcmp(par_nm, "Float")) {1184+
if (nm && (!strcmp(nm, "MAX") || !strcmp(nm, "MIN") || !strcmp(nm, "EPSILON") ||1185+
!strcmp(nm, "INFINITY") || !strcmp(nm, "NAN") || !strcmp(nm, "DIG") ||1186+
!strcmp(nm, "MANT_DIG") || !strcmp(nm, "RADIX"))) return TY_FLOAT;1187+
}1188+
if (par_nm && !strcmp(par_nm, "Math")) {1189+
if (nm && (!strcmp(nm, "PI") || !strcmp(nm, "E"))) return TY_FLOAT;1190+
}1191+
if (par_nm && !strcmp(par_nm, "File")) {1192+
if (nm && (!strcmp(nm, "SEPARATOR") || !strcmp(nm, "PATH_SEPARATOR") ||1193+
!strcmp(nm, "ALT_SEPARATOR"))) return TY_STRING;1194+
}1195+
if (par_nm && !strcmp(par_nm, "Integer")) {1196+
if (nm && (!strcmp(nm, "MAX") || !strcmp(nm, "MIN"))) return TY_UNKNOWN; /* raises NameError */1197+
}11791198
return TY_UNKNOWN;11801199
}11811200
if (!strcmp(ty, "SelfNode")) {src/codegen.cmodifiedView file
Loading diff…