Skip to content

Commit db34469

Browse files
docs(fstr): refactor comments.
1 parent ea9ab8d commit db34469

6 files changed

Lines changed: 13 additions & 15 deletions

File tree

compiler/src/abi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ struct HandleSlot {
9393
rc: u32,
9494
}
9595

96-
// Refcounted u32u64 (Val bits) map; single instance per script run, cleared between runs.
96+
// Refcounted u32->u64 (Val bits) map; single instance per script run, cleared between runs.
9797
pub struct HandleTable {
9898
slots: Vec<HandleSlot>,
9999
free_list: Vec<u32>,

compiler/src/modules/fstr.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
/* Format an f64 to a Python-display string (NaN, ±inf, ±0.0,
2-
whole-number floats with trailing ".0", else Rust's default). */
1+
/* f64 -> Python-style string: nan/±inf/±0.0/whole->".0" suffix/else default. */
32
pub fn format_f64(f: f64) -> alloc::string::String {
4-
// Lowercase per CPython repr/str semantics (was "NaN" — capitalised mismatch).
3+
// Lowercase per CPython semantics; "NaN" was a mismatch.
54
if f.is_nan() { return alloc::string::String::from("nan"); }
65
if f == f64::INFINITY { return alloc::string::String::from("inf"); }
76
if f == f64::NEG_INFINITY { return alloc::string::String::from("-inf"); }
87
if f == 0.0 {
98
return if f.is_sign_negative() { alloc::string::String::from("-0.0") } else { alloc::string::String::from("0.0") };
109
}
1110

12-
// Whole-number floats: itoa + ".0" avoids Rust's "1" output for 1.0.
11+
// Whole float: itoa + ".0" avoids Rust's bare "1" for 1.0.
1312
const I64_UPPER: f64 = i64::MAX as f64;
1413
if f.is_finite() && f >= (i64::MIN as f64) && f < I64_UPPER && f == (f as i64) as f64 {
1514
let mut b = itoa::Buffer::new();
@@ -23,7 +22,7 @@ pub fn format_f64(f: f64) -> alloc::string::String {
2322
format_general(f)
2423
}
2524

26-
/* 32-byte stack buffer is enough for any f64 in default formatting. */
25+
/* 32-byte stack buffer fits any f64 default format. */
2726
fn format_general(f: f64) -> alloc::string::String {
2827
let mut buf = FmtBuf::new();
2928
let _ = core::fmt::write(&mut buf, core::format_args!("{}", f));
@@ -71,8 +70,7 @@ macro_rules! s {
7170
($($t:tt)*) => {{ let mut _s = alloc::string::String::new(); $crate::s!(@b _s; $($t)*); _s }};
7271
}
7372

74-
/* Format little-endian base-10⁹ digit groups as a decimal string.
75-
Highest group is unpadded; the rest are zero-padded to width 9. */
73+
/* Formats little-endian base-10⁹ groups as decimal; highest unpadded, rest zero-padded to 9. */
7674
pub fn format_dec_groups(groups: &[u32]) -> alloc::string::String {
7775
let mut out = alloc::string::String::new();
7876
for (i, &g) in groups.iter().rev().enumerate() {

compiler/src/modules/parser/literals.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ impl<'src, I: Iterator<Item = Token>> Parser<'src, I> {
280280
}
281281
}
282282

283-
/* Dispatches call: print/rangededicated opcodes; builtinstable; nativesCallExtern; else LoadName+Call. */
283+
/* Dispatches call: print/range->dedicated opcodes; builtins->table; natives->CallExtern; else LoadName+Call. */
284284
pub(super) fn call(&mut self, name: String) -> bool {
285285
let call_pos = self.last_end as u32;
286286
if name == "print" {

compiler/src/modules/parser/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ impl<'src, I: Iterator<Item = Token>> Parser<'src, I> {
313313
self.lexeme(&t).to_string()
314314
}
315315

316-
/* Skips Newline/Nl/Comment; maps EndmarkerNone; latches saw_newline for ternary detection. */
316+
/* Skips Newline/Nl/Comment; maps Endmarker->None; latches saw_newline for ternary detection. */
317317
pub(super) fn peek(&mut self) -> Option<TokenType> {
318318
loop {
319319
match self.tokens.peek().map(|t| t.kind) {

compiler/src/modules/parser/stmt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ impl<'src, I: Iterator<Item = Token>> Parser<'src, I> {
1111

1212
/* Statement dispatch; returns true if a value is left on the stack for caller to PopTop. */
1313
pub(super) fn stmt(&mut self) -> bool {
14-
// Record ipsource offset before any emit so resolve() can map ip to source.
14+
// Record ip->source offset before any emit so resolve() can map ip to source.
1515
let ip = self.chunk.instructions.len() as u32;
1616
let pos = self.tokens.peek().map(|t| t.start as u32).unwrap_or(self.last_end as u32);
1717
self.chunk.stmt_pos.push((ip, pos));

compiler/src/modules/parser/types.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ pub struct SSAChunk {
119119
pub phi_map: Vec<usize>,
120120
pub nonlocals: Vec<String>,
121121
pub(super) name_index: HashMap<String, u16>,
122-
/* stmt ipbyte_offset map; binary-searched on error path; hot dispatch never touches it. */
122+
/* stmt ip->byte_offset map; binary-searched on error path; hot dispatch never touches it. */
123123
pub stmt_pos: Vec<(u32, u32)>,
124-
/* Call ipbyte_offset map; finer than stmt_pos; traceback caret lands under the call. */
124+
/* Call ip->byte_offset map; finer than stmt_pos; traceback caret lands under the call. */
125125
pub call_byte_pos: Vec<(u32, u32)>,
126126
/* Source text; shared via Arc across sub-chunks. Empty for manually constructed chunks. */
127127
pub source: alloc::sync::Arc<alloc::string::String>,
@@ -135,7 +135,7 @@ pub struct SSAChunk {
135135
}
136136

137137
impl SSAChunk {
138-
/* Binary-searches stmt_pos to map ipbyte offset; statement-level precision. */
138+
/* Binary-searches stmt_pos to map ip->byte offset; statement-level precision. */
139139
pub fn resolve(&self, ip: u32) -> Option<u32> {
140140
let i = self.stmt_pos.partition_point(|&(s, _)| s <= ip).checked_sub(1)?;
141141
Some(self.stmt_pos[i].1)
@@ -304,7 +304,7 @@ fn display_width(s: &str) -> usize {
304304
}
305305

306306
impl Diagnostic {
307-
/* Byte offset (line, col), 1-indexed; col counts display cells for wide-char alignment. */
307+
/* Byte offset -> (line, col), 1-indexed; col counts display cells for wide-char alignment. */
308308
fn line_col(src: &str, byte: usize) -> (usize, usize) {
309309
let byte = byte.min(src.len());
310310
let line = src[..byte].matches('\n').count() + 1;

0 commit comments

Comments
 (0)