Introduce unified Series trait
This commit introduces the `Series` trait to provide a unified interface for accessing indexed data across different series types (RecordSeries, SeriesView, and future SharedSeries). This simplifies the VM's indexer logic and lays the groundwork for the dual series architecture.
This commit is contained in:
+7
-24
@@ -529,41 +529,24 @@ impl VM {
|
||||
}
|
||||
res => break res,
|
||||
}
|
||||
} else if let Some(view) = obj.as_any().downcast_ref::<crate::ast::rtl::series::SeriesView>() {
|
||||
// Support for `(prices 0)` or `prices[0]` - reading from the 0-copy view!
|
||||
} else if let Some(series) = obj.as_series() {
|
||||
// Unified Series Access (Step 1 of Dual Series Architecture)
|
||||
// This handles RecordSeries, SeriesView, and future SharedSeries polymorphically.
|
||||
if arg_vals.len() != 1 {
|
||||
break Err("Series indexer expects exactly 1 argument (the lookback index)".to_string());
|
||||
break Err(format!("{} indexer expects exactly 1 argument (the lookback index)", obj.type_name()));
|
||||
}
|
||||
if let Value::Int(idx) = arg_vals[0] {
|
||||
if idx < 0 {
|
||||
break Err("Series lookback index cannot be negative".to_string());
|
||||
break Err(format!("{} lookback index cannot be negative", obj.type_name()));
|
||||
}
|
||||
if let Some(val) = view.inner.borrow().get_value(idx as usize) {
|
||||
if let Some(val) = series.get_item(idx as usize) {
|
||||
break Ok(val);
|
||||
} else {
|
||||
// Out of bounds / not enough data yet
|
||||
break Ok(Value::Void);
|
||||
}
|
||||
} 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());
|
||||
break Err(format!("{} index must be an integer", obj.type_name()));
|
||||
}
|
||||
} else {
|
||||
break Err(format!("Object is not callable: {}", obj.type_name()));
|
||||
|
||||
Reference in New Issue
Block a user