Skip to content

Commit 2ea1b7d

Browse files
committed
wip: basic tests working, integrating into driver
1 parent b790d44 commit 2ea1b7d

File tree

7 files changed

+118
-61
lines changed

7 files changed

+118
-61
lines changed

compiler/plc_driver/src/pipelines.rs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,9 @@ impl<T: SourceContainer> BuildPipeline<T> {
255255
Box::new(VirtualTableGenerator::new(self.context.provider())),
256256
Box::new(PolymorphicCallLowerer::new(self.context.provider())),
257257
Box::new(PropertyLowerer::new(self.context.provider())),
258-
Box::new(InitParticipant::new(self.project.get_init_symbol_name(), self.context.provider())),
259258
Box::new(AggregateTypeLowerer::new(self.context.provider())),
260259
Box::new(InheritanceLowerer::new(self.context.provider())),
260+
Box::new(InitParticipant::new(self.project.get_init_symbol_name(), self.context.provider())),
261261
]
262262
}
263263
/// Register all default participants (excluding codegen/linking)
@@ -604,21 +604,6 @@ impl IndexedProject {
604604

605605
AnnotatedProject { units: annotated_units, index, annotations }
606606
}
607-
608-
/// Adds additional, internally generated units to provide functions to be called by a runtime
609-
/// in order to initialize pointers before first cycle.
610-
///
611-
/// This method will consume the provided indexed project, modify the AST and re-index each unit
612-
pub fn extend_with_init_units(
613-
self,
614-
symbol_name: &'static str,
615-
id_provider: IdProvider,
616-
) -> IndexedProject {
617-
let units = self.project.units;
618-
let lowered =
619-
InitVisitor::visit(units, self.index, self.unresolvables, id_provider.clone(), symbol_name);
620-
ParsedProject { units: lowered }.index(id_provider.clone())
621-
}
622607
}
623608

624609
#[derive(Debug)]

compiler/plc_driver/src/pipelines/participant.rs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::{
1111
sync::{Arc, Mutex, RwLock},
1212
};
1313

14-
use ast::provider::IdProvider;
14+
use ast::{provider::IdProvider, visitor::AstVisitor};
1515
use plc::{
1616
codegen::GeneratedModule,
1717
lowering::{
@@ -21,7 +21,7 @@ use plc::{
2121
ConfigFormat, OnlineChange, Target,
2222
};
2323
use plc_diagnostics::diagnostics::Diagnostic;
24-
use plc_lowering::inheritance::InheritanceLowerer;
24+
use plc_lowering::{inheritance::InheritanceLowerer, initializer::Initializer};
2525
use project::{object::Object, project::LibraryInformation};
2626
use source_code::SourceContainer;
2727

@@ -224,8 +224,33 @@ impl InitParticipant {
224224
}
225225

226226
impl PipelineParticipantMut for InitParticipant {
227+
/*
228+
229+
/// Adds additional, internally generated units to provide functions to be called by a runtime
230+
/// in order to initialize pointers before first cycle.
231+
///
232+
/// This method will consume the provided indexed project, modify the AST and re-index each unit
233+
pub fn extend_with_init_units(
234+
self,
235+
symbol_name: &'static str,
236+
id_provider: IdProvider,
237+
) -> IndexedProject {
238+
let units = self.project.units;
239+
let lowered =
240+
InitVisitor::visit(units, self.index, self.unresolvables, id_provider.clone(), symbol_name);
241+
ParsedProject { units: lowered }.index(id_provider.clone())
242+
}
243+
*/
227244
fn pre_annotate(&mut self, indexed_project: IndexedProject) -> IndexedProject {
228-
indexed_project.extend_with_init_units(self.symbol_name, self.id_provider.clone())
245+
// Create a new init lowerer
246+
let IndexedProject { mut project, index, .. } = indexed_project;
247+
for unit in project.units.iter_mut() {
248+
let mut initializer = Initializer::new(self.id_provider.clone(), &index);
249+
initializer.apply_initialization(unit);
250+
}
251+
// indexed_project.extend_with_init_units(self.symbol_name, self.id_provider.clone())
252+
// Append new units and constructor to the ast and re-index
253+
project.index(self.id_provider.clone())
229254
}
230255
}
231256

compiler/plc_driver/src/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ where
5252
pipelines::ParsedProject::parse(&ctxt, &project, &mut diagnostician)?
5353
//Index
5454
.index(ctxt.provider())
55-
.extend_with_init_units(project.get_init_symbol_name(), ctxt.provider())
55+
// .extend_with_init_units(project.get_init_symbol_name(), ctxt.provider())
5656
//Resolve
5757
.annotate(ctxt.provider())
5858
//Codegen

compiler/plc_lowering/src/.initializer.rs.pending-snap

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)