MCPcopy Index your code
hub / github.com/aiscriptdev/aiscript / interpret

Method interpret

aiscript-vm/src/vm/mod.rs:165–194  ·  view source on GitHub ↗
(&mut self)

Source from the content-addressed store, hash-verified

163 }
164
165 pub fn interpret(&mut self) -> Result<ReturnValue, VmError> {
166 loop {
167 const FUEL_PER_GC: i32 = 1024 * 10;
168 let mut fuel = Fuel::new(FUEL_PER_GC);
169 // periodically exit the arena in order to collect garbage concurrently with running the VM.
170 let result = self.arena.mutate_root(|_, state| state.step(&mut fuel));
171
172 const COLLECTOR_GRANULARITY: f64 = 10240.0;
173 if self.arena.metrics().allocation_debt() > COLLECTOR_GRANULARITY {
174 // Do garbage collection.
175 #[cfg(feature = "debug")]
176 println!("Collecting...");
177 if self.arena.collection_phase() == CollectionPhase::Sweeping {
178 self.arena.collect_debt();
179 } else {
180 // Immediately transition to `CollectionPhase::Sweeping`.
181 self.arena.mark_all().unwrap().start_sweeping();
182 }
183 }
184
185 match result {
186 Ok(result) => {
187 if let Some(value) = result {
188 return Ok(value);
189 }
190 }
191 Err(err) => return Err(err),
192 }
193 }
194 }
195}
196
197#[derive(Copy, Clone)]

Callers 5

evalFunction · 0.80
run_fileMethod · 0.80
test_inject_variablesFunction · 0.80
test_inject_instanceFunction · 0.80
execute_codeMethod · 0.80

Calls 8

mutate_rootMethod · 0.80
stepMethod · 0.80
allocation_debtMethod · 0.80
collection_phaseMethod · 0.80
collect_debtMethod · 0.80
start_sweepingMethod · 0.80
mark_allMethod · 0.80
metricsMethod · 0.45

Tested by 2

test_inject_variablesFunction · 0.64
test_inject_instanceFunction · 0.64