MCPcopy Index your code
hub / github.com/endbasic/endbasic / alloc

Method alloc

core/src/compiler/syms.rs:524–549  ·  view source on GitHub ↗

Allocates a new temporary register.

(&mut self)

Source from the content-addressed store, hash-verified

522
523 /// Allocates a new temporary register.
524 pub(crate) fn alloc(&mut self) -> Result<Register> {
525 let temp;
526 let new_next_temp;
527 {
528 let mut next_temp = self.next_temp.borrow_mut();
529 temp = *next_temp;
530 self.ntemps += 1;
531 new_next_temp = match next_temp.checked_add(1) {
532 Some(reg) => reg,
533 None => return Err(Error::OutOfRegisters(RegisterScope::Temp)),
534 };
535 *next_temp = new_next_temp;
536 }
537
538 {
539 let mut count_temps = self.count_temps.borrow_mut();
540 *count_temps = max(*count_temps, new_next_temp);
541 }
542
543 match u8::try_from(usize::from(self.nlocals) + usize::from(temp)) {
544 Ok(reg) => {
545 Ok(Register::local(reg).map_err(|_| Error::OutOfRegisters(RegisterScope::Temp))?)
546 }
547 Err(_) => Err(Error::OutOfRegisters(RegisterScope::Temp)),
548 }
549 }
550}
551
552#[cfg(test)]

Callers 11

compile_integer_exprsFunction · 0.80
compile_pending_opsFunction · 0.80
compile_exprFunction · 0.80
compile_assignmentFunction · 0.80
compile_case_guardFunction · 0.80
compile_guardFunction · 0.80
compile_forFunction · 0.80
compile_ifFunction · 0.80
compile_whileFunction · 0.80
compile_stmtFunction · 0.80
compile_argsFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected