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

Method call_format

compiler/src/modules/vm/builtins/io.rs:101–119  ·  view source on GitHub ↗

`format(value [, spec])`.

(&mut self, op: u16, chunk: &crate::modules::parser::SSAChunk, slots: &mut [Val])

Source from the content-addressed store, hash-verified

99
100 // `format(value [, spec])`.
101 pub fn call_format(&mut self, op: u16, chunk: &crate::modules::parser::SSAChunk, slots: &mut [Val]) -> Result<(), VmErr> {
102 if op != 1 && op != 2 {
103 return Err(cold_type("format() takes 1 or 2 arguments"));
104 }
105 let spec_val = if op == 2 { Some(self.pop()?) } else { None };
106 let val = self.pop()?;
107 let result = match spec_val {
108 Some(sv) => {
109 // `sv` may be a non-heap value (int/float); guard before indexing the heap.
110 let spec = match sv.is_heap().then(|| self.heap.get(sv)) {
111 Some(HeapObj::Str(s)) => s.clone(),
112 _ => return Err(cold_type("format() spec must be a string")),
113 };
114 self.format_op(val, &spec, chunk, slots)?
115 }
116 None => self.display_op(val, chunk, slots)?,
117 };
118 self.alloc_and_push_str(result)
119 }
120}

Callers 1

dispatch_nativeMethod · 0.80

Calls 7

cold_typeFunction · 0.85
is_heapMethod · 0.80
format_opMethod · 0.80
display_opMethod · 0.80
alloc_and_push_strMethod · 0.80
popMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected