Build cellfixedoffsets mapping: cell/free index -> localsplus index. Merged cells (cellvar also in varnames) get the local slot index. Non-merged cells get slots after nlocals. Free vars follow.
(
varnames: &IndexSet<String>,
cellvars: &IndexSet<String>,
freevars: &IndexSet<String>,
)
| 3096 | /// Merged cells (cellvar also in varnames) get the local slot index. |
| 3097 | /// Non-merged cells get slots after nlocals. Free vars follow. |
| 3098 | pub(crate) fn build_cellfixedoffsets( |
| 3099 | varnames: &IndexSet<String>, |
| 3100 | cellvars: &IndexSet<String>, |
| 3101 | freevars: &IndexSet<String>, |
| 3102 | ) -> Vec<u32> { |
| 3103 | let nlocals = varnames.len(); |
| 3104 | let ncells = cellvars.len(); |
| 3105 | let nfrees = freevars.len(); |
| 3106 | let mut fixed = Vec::with_capacity(ncells + nfrees); |
| 3107 | let mut numdropped = 0usize; |
| 3108 | for (i, cellvar) in cellvars.iter().enumerate() { |
| 3109 | if let Some(local_idx) = varnames.get_index_of(cellvar) { |
| 3110 | fixed.push(local_idx as u32); |
| 3111 | numdropped += 1; |
| 3112 | } else { |
| 3113 | fixed.push((nlocals + i - numdropped) as u32); |
| 3114 | } |
| 3115 | } |
| 3116 | for i in 0..nfrees { |
| 3117 | fixed.push((nlocals + ncells - numdropped + i) as u32); |
| 3118 | } |
| 3119 | fixed |
| 3120 | } |
| 3121 | |
| 3122 | /// Convert DEREF instruction opargs from cell-relative indices to localsplus indices |
| 3123 | /// using the cellfixedoffsets mapping. |
no test coverage detected