MCPcopy Create free account
hub / github.com/dylan-sutton-chavez/edge-python / format_op

Method format_op

compiler/src/modules/vm/handlers/dunder.rs:360–368  ·  view source on GitHub ↗

`format(v, spec)` dispatch: instance `__format__(spec)` wins; otherwise the built-in spec engine runs. Empty spec on an instance still goes through `__format__` so user formatting can opt in. */

(&mut self, v: Val, spec: &str, chunk: &SSAChunk, slots: &mut [Val])

Source from the content-addressed store, hash-verified

358
359 /* `format(v, spec)` dispatch: instance `__format__(spec)` wins; otherwise the built-in spec engine runs. Empty spec on an instance still goes through `__format__` so user formatting can opt in. */
360 pub(crate) fn format_op(&mut self, v: Val, spec: &str, chunk: &SSAChunk, slots: &mut [Val]) -> Result<String, VmErr> {
361 if v.is_heap() && matches!(self.heap.get(v), HeapObj::Instance(..)) {
362 let spec_val = self.heap.alloc(HeapObj::Str(spec.to_string()))?;
363 if let Some(r) = self.try_call_dunder(v, "__format__", &[spec_val], chunk, slots)? {
364 return self.require_str(r, "__format__");
365 }
366 }
367 super::format::format_value(v, spec, &self.heap).map_err(super::format::fmt_err)
368 }
369
370 /* Coerce a `__len__` / `__length_hint__` return value to bool semantics; rejects negatives. */
371 fn len_to_bool(&self, v: Val) -> Result<bool, VmErr> {

Callers 2

handle_containerMethod · 0.80
call_formatMethod · 0.80

Calls 5

format_valueFunction · 0.85
is_heapMethod · 0.80
try_call_dunderMethod · 0.80
require_strMethod · 0.80
allocMethod · 0.45

Tested by

no test coverage detected