Skip to main content

runmat_vm/interpreter/dispatch/
arrays.rs

1use crate::ops::arrays as array_ops;
2use runmat_builtins::Value;
3use runmat_runtime::RuntimeError;
4use std::future::Future;
5
6pub fn create_matrix(stack: &mut Vec<Value>, rows: usize, cols: usize) -> Result<(), RuntimeError> {
7    array_ops::create_matrix(stack, rows, cols)
8}
9
10pub async fn create_matrix_dynamic<F, Fut>(
11    stack: &mut Vec<Value>,
12    num_rows: usize,
13    create_from_values: F,
14) -> Result<(), RuntimeError>
15where
16    F: FnMut(Vec<Vec<Value>>) -> Fut,
17    Fut: Future<Output = Result<Value, RuntimeError>>,
18{
19    array_ops::create_matrix_dynamic(stack, num_rows, create_from_values).await
20}
21
22pub async fn create_range<F, Fut>(
23    stack: &mut Vec<Value>,
24    has_step: bool,
25    call_colon: F,
26) -> Result<(), RuntimeError>
27where
28    F: FnMut(Vec<Value>) -> Fut,
29    Fut: Future<Output = Result<Value, RuntimeError>>,
30{
31    array_ops::create_range(stack, has_step, call_colon).await
32}
33
34pub fn pack_to_row(stack: &mut Vec<Value>, count: usize) -> Result<(), RuntimeError> {
35    array_ops::pack_to_row(stack, count)
36}
37
38pub fn pack_to_col(stack: &mut Vec<Value>, count: usize) -> Result<(), RuntimeError> {
39    array_ops::pack_to_col(stack, count)
40}
41
42pub fn unpack(stack: &mut Vec<Value>, out_count: usize) -> Result<(), RuntimeError> {
43    array_ops::unpack(stack, out_count)
44}