MCPcopy Index your code
hub / github.com/RustPython/RustPython / mark_lines

Function mark_lines

crates/vm/src/builtins/frame.rs:396–412  ·  view source on GitHub ↗

Build a mapping from instruction index to line number. Returns -1 for indices with no line start.

(code: &bytecode::CodeObject<C>)

Source from the content-addressed store, hash-verified

394 /// Build a mapping from instruction index to line number.
395 /// Returns -1 for indices with no line start.
396 pub fn mark_lines<C: Constant>(code: &bytecode::CodeObject<C>) -> Vec<i32> {
397 let len = code.instructions.len();
398 let mut line_starts = vec![-1i32; len];
399 let mut last_line: i32 = -1;
400
401 for (i, (loc, _)) in code.locations.iter().enumerate() {
402 if i >= len {
403 break;
404 }
405 let line = loc.line.get() as i32;
406 if line != last_line && line > 0 {
407 line_starts[i] = line;
408 last_line = line;
409 }
410 }
411 line_starts
412 }
413
414 /// Find the first line number >= `line` that has code.
415 pub fn first_line_not_before(lines: &[i32], line: i32) -> i32 {

Callers 1

set_f_linenoMethod · 0.85

Calls 3

lenMethod · 0.45
iterMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected