pub mod frame;
mod value;
use std::sync::Arc;
use frame::{ExecutionContext, ExecutionFrame};
use value::RuntimeValue;
use crate::bc::{BytecodeValue, Op};
pub const FRAME_WIDTH: usize = 16;
pub const FRAME_SIZE: usize = FRAME_WIDTH * FRAME_WIDTH;
pub struct Runtime {
code: Arc<[Op]>,
input_section: Arc<[RuntimeValue]>,
input_buffer: Arc<[RuntimeValue]>,
}
impl Runtime {
pub fn new(
code: Vec<Op>,
input_section: Vec<BytecodeValue>,
input_buffer: Vec<BytecodeValue>,
) -> Self {
Self {
code: code.into(),
input_section: input_section
.iter()
.copied()
.map(|v| RuntimeValue::from(v))
.collect(),
input_buffer: input_buffer
.iter()
.copied()
.map(|v| RuntimeValue::from(v))
.collect(),
}
}
pub fn create_frame(&self, pos: [f64; 2]) -> ExecutionFrame {
ExecutionFrame::new(
self.code.clone(),
self.input_section.clone(),
self.input_buffer.clone(),
ExecutionContext {
x: pos[0],
y: pos[1],
scale_x: 1.0,
scale_y: 1.0,
},
)
}
}