Skip to main content

wowlab_engine_domain/rotation/bytecode/
program.rs

1//! Immutable portable bytecode instructions, register counts, and prepared schema.
2
3use std::sync::Arc;
4
5use super::instruction::{FloatRegister, Instruction};
6use crate::rotation::context::ContextSchema;
7
8#[derive(Clone, Copy, Debug, Eq, PartialEq)]
9pub(super) struct RegisterCounts {
10    pub(super) bools: u32,
11    pub(super) ints: u32,
12    pub(super) floats: u32,
13}
14
15impl RegisterCounts {
16    pub(super) const fn bools(self) -> usize {
17        self.bools as usize
18    }
19
20    pub(super) const fn ints(self) -> usize {
21        self.ints as usize
22    }
23
24    pub(super) const fn floats(self) -> usize {
25        self.floats as usize
26    }
27}
28
29#[derive(Debug)]
30pub(super) struct BytecodeProgram {
31    pub(super) instructions: Box<[Instruction]>,
32    register_counts: RegisterCounts,
33    now_register: Option<FloatRegister>,
34    schema: Arc<ContextSchema>,
35}
36
37impl BytecodeProgram {
38    pub(super) fn new(
39        instructions: Vec<Instruction>,
40        register_counts: RegisterCounts,
41        schema: Arc<ContextSchema>,
42    ) -> Self {
43        Self {
44            instructions: instructions.into_boxed_slice(),
45            register_counts,
46            now_register: None,
47            schema,
48        }
49    }
50
51    pub(super) const fn with_optional_now_register(
52        mut self,
53        now_register: Option<FloatRegister>,
54    ) -> Self {
55        self.now_register = now_register;
56
57        self
58    }
59
60    pub(super) const fn register_counts(&self) -> RegisterCounts {
61        self.register_counts
62    }
63
64    pub(super) const fn now_register(&self) -> Option<FloatRegister> {
65        self.now_register
66    }
67
68    pub(super) fn schema(&self) -> &ContextSchema {
69        &self.schema
70    }
71}