Add RecordSeries::get_record and support for (my_ticks 0)

This commit introduces the `get_record` method to `RecordSeries`,
allowing for the dynamic reconstruction of a full record from its
constituent fields at a given index. This enables idiomatic access to
series data using indexing like `(my_ticks 0)`.

The `push-series` function has also been updated to correctly handle the
structure of records when pushing data into a `RecordSeries`.
This commit is contained in:
Michael Schimmel
2026-03-01 18:44:46 +01:00
parent b612df6e10
commit 46b546446f
3 changed files with 58 additions and 17 deletions
+18
View File
@@ -547,6 +547,24 @@ impl VM {
} else {
break Err("Series index must be an integer".to_string());
}
} else if let Some(rs) = obj.as_any().downcast_ref::<crate::ast::rtl::series::RecordSeries>() {
// Support for `(my_ticks 0)` - reconstructs the full Record from SoA!
if arg_vals.len() != 1 {
break Err("RecordSeries indexer expects exactly 1 argument (the lookback index)".to_string());
}
if let Value::Int(idx) = arg_vals[0] {
if idx < 0 {
break Err("RecordSeries lookback index cannot be negative".to_string());
}
if let Some(rec) = rs.get_record(idx as usize) {
break Ok(rec);
} else {
// Out of bounds / not enough data yet
break Ok(Value::Void);
}
} else {
break Err("RecordSeries index must be an integer".to_string());
}
} else {
break Err(format!("Object is not callable: {}", obj.type_name()));
}