Update various types to use their own definitions

This commit refactors several modules to use the defined types from
`ast::types` and `ast::nodes` directly, rather than using fully
qualified paths. This improves code readability and reduces redundancy.

Specifically, the following changes were made:

- In `analyzer.rs`, `crate::ast::types::Identity` and
  `crate::ast::types::Purity` are now used directly.
- In `binder.rs`, `crate::ast::types::NodeIdentity`,
  `crate::ast::types::SourceLocation`,
  `crate::ast::types::RecordLayout`, and `crate::ast::types::Value` are
  now used directly.
- In `macros.rs`, types like `Address`, `VirtualId`, `NodeIdentity`,
  `SourceLocation`, `StaticType`, and `Purity` are now used directly.
- In `optimizer/engine.rs`, `Address<VirtualId>` is now used directly.
- In `type_checker.rs`, `BoundPhase`, `Signature`, `Keyword`, and
  `RecordLayout` are now used directly.
- In `environment.rs`, `CompilerScope`, `LocalInfo`, `CapturePass`,
  `AnalyzedPhase`, `NativeFunction`, and `Closure` are now used
  directly.
- In `nodes.rs`, `RecordLayout`, `Keyword`, `Purity`, and `StaticType`
  are now used directly.
- In `parser.rs`, `SourceLocation` and `NodeIdentity` are now used
  directly.
- In `rtl/math.rs`, `NativeFunction`, `Purity`, `Signature`,
  `StaticType`, `Value`, `RefCell`, and `Rc` are now used directly.
- In `rtl/streams.rs`, `ScalarValue`, `SeriesMember`, `Object`,
  `PipeFn`, `Value`, `VM`, `RingBuffer`, `RecordSeries`, `SeriesView`,
  `build_map_stream`, and `build_pipeline_node` are now used directly.
- In `rtl/type_registry.rs`, `RecordLayout`, `Keyword`, `Purity`,
  `Signature`, `StaticType`, and `Value` are now used directly.
- In `vm.rs`, `RecordSeries`, `SeriesView`, `build_map_stream`,
  `build_pipeline_node`, `StreamNode`, `Object`, and `PipeFn` are now
  used directly.
- In `utils/tester.rs`, `TypedNode` is now used directly.
This commit is contained in:
2026-03-22 18:30:56 +01:00
parent 1cbc656554
commit 007446a167
13 changed files with 112 additions and 104 deletions
+19 -19
View File
@@ -1,5 +1,7 @@
use crate::ast::nodes::{Address, AnalyzedNode, ExecNode, IdentifierBinding, NodeKind, StackOffset};
use crate::ast::types::{Object, Value};
use crate::ast::rtl::series::{RecordSeries, SeriesView};
use crate::ast::rtl::streams::{build_map_stream, build_pipeline_node, StreamNode};
use crate::ast::types::{Object, PipeFn, Value};
use std::any::Any;
use std::cell::RefCell;
use std::rc::Rc;
@@ -386,19 +388,19 @@ impl VM {
Value::Object(obj) => {
let any_ptr = obj.as_any();
if let Some(record_series) =
any_ptr.downcast_ref::<crate::ast::rtl::series::RecordSeries>()
any_ptr.downcast_ref::<RecordSeries>()
{
if let Some(field_series) = record_series.field(*field) {
let view =
crate::ast::rtl::series::SeriesView::new(field_series, *field);
SeriesView::new(field_series, *field);
return Ok(Value::Object(std::rc::Rc::new(view))); } else {
return Err(format!(
"RecordSeries does not have field :{}",
field.name()
));
}
} else if let Some(sn) = obj.as_any().downcast_ref::<crate::ast::rtl::streams::StreamNode>() {
let mapped = crate::ast::rtl::streams::build_map_stream(sn.inner.clone(), *field);
} else if let Some(sn) = obj.as_any().downcast_ref::<StreamNode>() {
let mapped = build_map_stream(sn.inner.clone(), *field);
return Ok(Value::Object(Rc::new(mapped)));
}
Err(format!(
@@ -431,8 +433,6 @@ impl VM {
inputs,
lambda,
} => {
use crate::ast::rtl::streams::StreamNode;
let mut obs_streams = Vec::new();
for input in inputs {
let val = self.eval_internal(obs, input)?;
@@ -453,9 +453,9 @@ impl VM {
let lambda_val = self.eval_internal(obs, lambda)?;
// Create the persistent execution closure for the PipeStream
let mut pipe_vm = crate::ast::vm::VM::new(self.globals.clone());
let executor: Box<crate::ast::types::PipeFn> = match lambda_val {
let mut pipe_vm = VM::new(self.globals.clone());
let executor: Box<PipeFn> = match lambda_val {
Value::Object(obj) => {
let my_closure = obj.clone();
Box::new(move |args: &[Value]| -> Value {
@@ -476,7 +476,7 @@ impl VM {
// Delegate to the RTL Factory for specialized buffer instantiation
let node =
crate::ast::rtl::streams::build_pipeline_node(obs_streams, executor, &node.ty.ty);
build_pipeline_node(obs_streams, executor, &node.ty.ty);
Ok(Value::Object(node))
}
@@ -547,10 +547,10 @@ impl VM {
// Polymorphic Field Access: Allow `.field` on a RecordSeries
if let Some(rs) = obj
.as_any()
.downcast_ref::<crate::ast::rtl::series::RecordSeries>()
.downcast_ref::<RecordSeries>()
{
if let Some(field_series) = rs.field(k) {
let view = crate::ast::rtl::series::SeriesView::new(
let view = SeriesView::new(
field_series,
k,
);
@@ -561,8 +561,8 @@ impl VM {
k.name()
));
}
} else if let Some(sn) = obj.as_any().downcast_ref::<crate::ast::rtl::streams::StreamNode>() {
let mapped = crate::ast::rtl::streams::build_map_stream(sn.inner.clone(), k);
} else if let Some(sn) = obj.as_any().downcast_ref::<StreamNode>() {
let mapped = build_map_stream(sn.inner.clone(), k);
return Ok(Value::Object(Rc::new(mapped)));
}
return Err(format!(
@@ -616,10 +616,10 @@ impl VM {
} else if let Value::Object(obj) = rec {
if let Some(rs) = obj
.as_any()
.downcast_ref::<crate::ast::rtl::series::RecordSeries>()
.downcast_ref::<RecordSeries>()
{
if let Some(field_series) = rs.field(*k) {
let view = crate::ast::rtl::series::SeriesView::new(
let view = SeriesView::new(
field_series,
*k,
);
@@ -630,8 +630,8 @@ impl VM {
k.name()
))
}
} else if let Some(sn) = obj.as_any().downcast_ref::<crate::ast::rtl::streams::StreamNode>() {
let mapped = crate::ast::rtl::streams::build_map_stream(sn.inner.clone(), *k);
} else if let Some(sn) = obj.as_any().downcast_ref::<StreamNode>() {
let mapped = build_map_stream(sn.inner.clone(), *k);
Ok(Value::Object(Rc::new(mapped)))
} else {
Err(format!(