LIFETIMES AND MUTABILITY LIFETIMES AND MUTABILITY LIFETIMES AND MUTABILITY LIFETIMES AND MUTABILITY LIFETIMES AND MUTABILITY LIFETIMES AND MUTABILITY LIFETIMES AND MUTABILITY

This commit is contained in:
DOOM1EM8Cover 2023-08-29 07:57:52 +01:00
parent 15468a910d
commit eef6a218f8
12 changed files with 97 additions and 92 deletions

View file

@ -2,9 +2,5 @@
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
<mapping directory="$PROJECT_DIR$/core_stdlib" vcs="Git" />
<mapping directory="$PROJECT_DIR$/package-manager" vcs="Git" />
<mapping directory="$PROJECT_DIR$/package-manager-server" vcs="Git" />
<mapping directory="$PROJECT_DIR$/runtime" vcs="Git" />
</component>
</project>

View file

@ -4,6 +4,7 @@ use std::path::Path;
use std::collections::HashMap;
use std::fs::File;
use std::io::Write;
use std::rc::Rc;
// Crate Uses
use crate::codegen;
@ -12,7 +13,7 @@ use crate::project::idl::constants::CONGREGATION_EXTENSION;
use crate::project::ir::interpreter::Interpreter as ProjectInterpreter;
use crate::project::ir::compiler::Compile;
use crate::project::ir::{compiler, diff, frozen};
use crate::project::ir::frozen::{FrozenUnit, FrozenWhole};
use crate::project::ir::frozen::FrozenUnit;
use crate::project::ir::frozen::meta::Index;
use crate::project::ir::context::ProjectContext;
use crate::schema::{idl, ir};
@ -37,19 +38,15 @@ pub fn build(path: &Path) -> Result<()> {
let latest_frozen = frozen::loader::from_latest_frozen(&frozen_path);
let (compiled_project, frozen)
let (mut compiled_project, frozen)
= ProjectInterpreter::from_origin(config_path)?;
// TODO: Check integrity of the frozen contents, if they are valid, if something is broken, etc
if let Some(latest_frozen) = latest_frozen {
diff::differ(
&latest_frozen, &compiled_project,
true, true
);
diff::differ(&latest_frozen, &frozen, true, true);
}
let mut project_ctx = compiled_project.borrow_mut();
let schema_paths = frozen::schema_paths(&frozen);
for relative in schema_paths {
let concrete = format!("{:}/{}", path.to_str().unwrap(), relative);
@ -57,24 +54,24 @@ pub fn build(path: &Path) -> Result<()> {
let unit = idl::parser_new::from_path(concrete_path)?;
let context = ir::context::SchemaContext::with_project_and_main(
unit, &compiled_project
);
let context = ir::context::SchemaContext::with_project_and_main(unit);
project_ctx.add_schema_context(RefCell::new(context));
compiled_project.add_schema_context(
Rc::new(RefCell::new(context))
);
}
compiler::interpret::interpret_context(&compiled_project)?;
compiler::interpret::interpret_context(&mut compiled_project)?;
// generate_code_for_targets(&compiled_project).unwrap();
generate_code_for_targets(&mut compiled_project, &frozen)?;
todo!()
// Ok(())
Ok(())
}
pub fn generate_code_for_targets(compiled_project: &mut FrozenWhole) -> Result<()> {
for item in compiled_project.1.iter() {
pub fn generate_code_for_targets<'a>(
compiled_project: &mut ProjectContext<'a>, frozen_units: &'a Vec<FrozenUnit>
) -> Result<()> {
for item in frozen_units.iter() {
match item {
FrozenUnit::CodeGeneration(details) => {
let Some((name, version)) = details.name.split_once("#") else {
@ -99,7 +96,7 @@ pub fn generate_code_for_targets(compiled_project: &mut FrozenWhole) -> Result<(
)
}
generate_code_for_context(&compiled_project.0, generator, &path)?;
generate_code_for_context(&compiled_project, generator, &path)?;
},
_ => {}
}
@ -129,11 +126,12 @@ pub fn resolve_path_query(query: &Option<String>, args: Args) -> Result<String,
#[allow(unused)]
pub fn generate_code_for_context(
context: &ProjectContext, generator: Option<&GeneratorFn>, target_path: &Path
context: &ProjectContext, generator: Option<&GeneratorFn>,
target_path: &Path
) -> Result<()> {
/*
for schema_context in context.schema_contexts.iter() {
let frozen_schema = schema_context.frozen_schema.as_ref().unwrap();
let schema_ctx = schema_context.borrow();
let frozen_schema = schema_ctx.frozen_schema.as_ref().unwrap();
let mut code = "Generated code with Comline compiler".to_owned();
@ -143,9 +141,6 @@ pub fn generate_code_for_context(
}
Ok(())
*/
todo!()
}
pub fn build_index(frozen_path: &Path) {

View file

@ -1,6 +1,5 @@
// Standard Uses
use std::cell::RefCell;
// Crate Uses
use crate::project::ir::context::ProjectContext;
use crate::schema::ir::compiler::interpreter::meta_stage;
@ -9,15 +8,17 @@ use crate::schema::ir::compiler::interpreter::meta_stage;
use eyre::{anyhow, Result};
pub fn interpret_context<'a>(project_context: &'a RefCell<ProjectContext<'a>>) -> Result<()> {
let len = project_context.borrow().schema_contexts.len();
pub fn interpret_context<'a>(
// project_context: &'a RefCell<ProjectContext<'a>>,
project_context: &'a ProjectContext<'a>,
) -> Result<()> {
let len = project_context.schema_contexts.len();
for i in 0..len {
let project_ctx = &project_context.borrow();
let schema_ctx = &project_ctx.schema_contexts[i];
meta_stage::compile_schema_metadata(&schema_ctx)
.map_err(|e| anyhow!("{}", e))?;
meta_stage::compile_schema_metadata(
&project_context.schema_contexts[i],
project_context
).map_err(|e| anyhow!("{}", e))?;
}
/*

View file

@ -5,6 +5,7 @@ use std::rc::Rc;
// Crate Uses
use crate::project::idl::ast::{SourcedWhole as ProjectSourcedWhole};
use crate::schema::idl::ast::unit::{ASTUnit, Details};
use crate::schema::ir::context::SchemaContext;
// External Uses
@ -19,7 +20,7 @@ pub enum Origin {
pub struct ProjectContext<'a> {
pub origin: Origin,
pub config: ProjectSourcedWhole,
pub schema_contexts: Vec<RefCell<SchemaContext<'a>>>,
pub schema_contexts: Vec<Rc<RefCell<SchemaContext<'a>>>>,
pub relative_projects: Vec<ProjectContext<'a>>,
}
@ -53,7 +54,7 @@ impl<'a> ProjectContext<'a> {
todo!()
}
pub(crate) fn add_schema_context(&mut self, context: RefCell<SchemaContext<'a>>) {
pub(crate) fn add_schema_context(&mut self, context: Rc<RefCell<SchemaContext<'a>>>) {
self.schema_contexts.push(context);
}
@ -62,23 +63,20 @@ impl<'a> ProjectContext<'a> {
}
pub(crate) fn find_schema_by_import(&self, import: &str)
-> Option<&mut SchemaContext>
-> Option<&'a Rc<RefCell<SchemaContext>>>
{
/*
for schema_context in self.schema_contexts {
if let Some(unit) = schema_context.schema.1.find_namespace() {
for schema_context in self.schema_contexts.iter() {
let units = &schema_context.borrow().schema.1;
if let Some(unit) = units.find_namespace() {
if let ASTUnit::Namespace(_, namespace) = &unit.1 {
if namespace == import {
return Some(*schema_context)
return Some(schema_context)
}
}
}
}
None
*/
todo!()
}
/*

View file

@ -4,14 +4,15 @@ pub mod versioning;
// Standard Uses
use std::fmt::Debug;
use std::cell::RefCell;
// Crate Uses
use crate::project::ir::context::ProjectContext;
use crate::project::ir::frozen::{Dependency, FrozenUnit, FrozenWhole};
use crate::autodoc::document::Document;
use crate::project::ir::diff::versioning::Versioning;
// External Uses
use downcast_rs::{Downcast, impl_downcast};
use semver::Version;
pub trait Differ: Downcast + Debug {
@ -34,12 +35,9 @@ impl_downcast!(Differ);
#[allow(unused)]
pub fn differ(
previous: &Vec<FrozenUnit>, next: &RefCell<ProjectContext>,
previous: &Vec<FrozenUnit>, next: &Vec<FrozenUnit>,
document_gen: bool, auto_version: bool
) {
todo!()
/*
let mut previous_version = versioning::version_from(previous).unwrap_or(
&Version::parse("0.0.0").unwrap().to_string()
);
@ -53,19 +51,18 @@ pub fn differ(
let document = listeners[0].downcast_ref::<Document>().unwrap();
let versioning = listeners[1].downcast_ref::<Versioning>().unwrap();
*/
}
#[allow(unused)]
pub fn match_differ(
mut listeners: &mut Vec<Box<dyn Differ>>,
previous: &Vec<FrozenUnit>, next: &FrozenWhole
previous: &Vec<FrozenUnit>, next: &Vec<FrozenUnit>
) {
for node in previous {
use FrozenUnit::*;
match node {
Namespace(_) => {
search_other(node, &next.1).map(|l| {
search_other(node, &next).map(|l| {
let Namespace(old) = node else { panic!() };
let Namespace(new) = l else { panic!() };
@ -77,7 +74,7 @@ pub fn match_differ(
});
}
SpecificationVersion(_) => {
search_other(node, &next.1).map(|l| {
search_other(node, &next).map(|l| {
let SpecificationVersion(old) = node else { panic!() };
let SpecificationVersion(new) = l else { panic!() };

View file

@ -3,7 +3,6 @@ pub mod report;
pub mod interpret;
pub mod freezing;
use std::cell::RefCell;
// Standard Uses
use std::path::Path;
@ -25,7 +24,8 @@ pub struct Interpreter<'a> {
#[allow(unused)]
impl<'a> Compile for Interpreter<'a> {
type Output = Result<(RefCell<ProjectContext<'a>>, Vec<FrozenUnit>)>;
// type Output = Result<(RefCell<ProjectContext<'a>>, Vec<FrozenUnit>)>;
type Output = Result<(ProjectContext<'a>, Vec<FrozenUnit>)>;
fn from_ast(ast: Vec<ASTUnit>) -> Self::Output {
todo!()
@ -36,7 +36,8 @@ impl<'a> Compile for Interpreter<'a> {
let frozen = interpret::interpret_context(&context)
.map_err(|e| anyhow!("{:?}", e))?;
Ok((RefCell::new(context), frozen))
// Ok((RefCell::new(context), frozen))
Ok((context, frozen))
}
fn from_source(source: &str) -> Self::Output {
@ -57,6 +58,7 @@ impl<'a> Compile for Interpreter<'a> {
let frozen = interpret::interpret_context(&context)
.map_err(|e| anyhow!("{:?}", e))?;
Ok((RefCell::new(context), frozen))
// Ok((RefCell::new(context), frozen))
Ok((context, frozen))
}
}

View file

@ -1,5 +1,6 @@
// Standard Uses
use std::rc::Rc;
use std::cell::RefCell;
// Local Uses
use crate::utils::codemap::{CodeMap, Span};
@ -105,6 +106,7 @@ pub enum ASTUnit {
}
}
pub(crate) fn namespace(units: &Vec<SpannedUnit>) -> &String {
let mut namespace: Option<&String> = None;
@ -137,7 +139,8 @@ pub type SourcedWholeRc = (CodeMap, Vec<Rc<SpannedUnit>>);
pub trait Details<'a> {
fn find_namespace(&self) -> Option<&'a SpannedUnit>;
fn find_namespace(&self) -> Option<&'a SpannedUnit> { todo!() }
fn find_namespace_rc(&self) -> Option<&'a Rc<RefCell<SpannedUnit>>> { todo!() }
}
impl<'a> Details<'a> for &'a Vec<SpannedUnit> {
@ -165,3 +168,17 @@ impl<'a> Details<'a> for &'a Vec<Rc<SpannedUnit>> {
None
}
}
impl<'a> Details<'a> for &'a Vec<Rc<RefCell<SpannedUnit>>> {
fn find_namespace_rc(&self) -> Option<&'a Rc<RefCell<SpannedUnit>>> {
for unit in self.iter() {
match unit.borrow().1 {
ASTUnit::Namespace(_, _) => return Some(unit),
_ => {}
}
}
None
}
}

View file

@ -1,14 +1,13 @@
// Standard Uses
use std::path::Path;
use std::rc::Rc;
use std::sync::Arc;
// Local Uses
use crate::utils::codemap::{CodeMap, FileMap};
use crate::schema::idl::ast::unit::{ASTUnit, SourcedWhole, SourcedWholeRc, SpannedUnit};
use crate::schema::idl::ast::unit::{ASTUnit, SourcedWhole, SpannedUnit};
// External Uses
use eyre::Result;
use eyre::{bail, Result};
use pest::iterators::Pair;
use pest::Parser;
@ -20,9 +19,6 @@ pub struct SchemaParser;
#[allow(unused)]
pub fn from_path(path: &Path) -> Result<SourcedWhole> {
todo!();
/*
if !path.exists() { bail!("Path doesn't exist: {:?}", path) }
let source = std::fs::read_to_string(path).unwrap();
@ -32,10 +28,9 @@ pub fn from_path(path: &Path) -> Result<SourcedWhole> {
);
sourced_whole
*/
}
pub fn parse_source(source: String, name: String) -> Result<SourcedWholeRc> {
pub fn parse_source(source: String, name: String) -> Result<SourcedWhole> {
let mut codemap = CodeMap::new();
let file = codemap.insert_file(name, source.clone());
@ -44,7 +39,7 @@ pub fn parse_source(source: String, name: String) -> Result<SourcedWholeRc> {
for pair in pairs {
if let Ok(unit) = parse_inner(pair, &file) {
units.push(Rc::new(unit))
units.push(unit)
}
}

View file

@ -16,7 +16,8 @@ use crate::report::ReportDetails;
#[allow(unused)]
pub fn interpret_context<'a>(
schema_context: &'a mut SchemaContext<'a>, project_context: &RefMut<ProjectContext>
schema_context: &'a mut SchemaContext<'a>,
project_context: &'a RefMut<ProjectContext<'a>>
) -> Result<(), ReportDetails<CompileError>> {
let mut interpreted: Vec<FrozenUnit> = vec![];
@ -148,14 +149,13 @@ pub fn interpret_context<'a>(
}
#[allow(unused)]
pub fn interpret_node(schema_context: &SchemaContext, node: &ASTUnit)
pub fn interpret_node<'a>(
schema_context: &'a SchemaContext<'a>,
project_context: &'a ProjectContext<'a>,
node: &ASTUnit
)
-> Result<FrozenUnit, ReportDetails<CompileError>>
{
let Some(project_ctx) = schema_context.project_context else {
panic!()
};
let project_ctx = project_ctx.borrow_mut();
use crate::schema::idl::ast::unit::ASTUnit::*;
match node {
Namespace(_, n) => {
@ -183,7 +183,7 @@ pub fn interpret_node(schema_context: &SchemaContext, node: &ASTUnit)
*/
}
Import(_, i) => {
let relative_unit = project_ctx.find_schema_by_import(&i);
let relative_unit = project_context.find_schema_by_import(&i);
/*
if relative_unit.is_none() {

View file

@ -1,5 +1,7 @@
// Standard Uses
use std::cell::RefCell;
use std::rc::Rc;
use crate::project::ir::context::ProjectContext;
// Crate Uses
use crate::report::ReportDetails;
@ -10,10 +12,10 @@ use crate::schema::ir::context::SchemaContext;
pub fn compile_schema_metadata<'a>(
schema_context: &'a RefCell<SchemaContext<'a>>,
schema_context: &Rc<RefCell<SchemaContext>>,
project_context: &'a ProjectContext<'a>
) -> Result<(), ReportDetails<CompileError>> {
let schema_ctx = schema_context.borrow();
let project_ctx = schema_ctx.project_context.unwrap().borrow();
for i in 0..schema_ctx.schema.1.len() {
let spanned_unit = &schema_ctx.schema.1[i];
@ -23,7 +25,7 @@ pub fn compile_schema_metadata<'a>(
Namespace(_, n) => {
let name = n.clone();
let Some(_) = project_ctx.find_schema_by_import(&n) else
let Some(_) = project_context.find_schema_by_import(&n) else
{
return Err(ReportDetails {
// kind: "Namespace".to_string(),
@ -40,10 +42,11 @@ pub fn compile_schema_metadata<'a>(
})
};
if let Some(name) = &schema_ctx.compile_state.borrow_mut().namespace {
let mut compile_state = schema_ctx.compile_state.borrow_mut();
if let Some(name) = &compile_state.namespace {
panic!("Namespace {} was already previously set", name)
} else {
schema_ctx.compile_state.borrow_mut().namespace = Some(name)
compile_state.namespace = Some(name)
}
}
Docstring {..} => {

View file

@ -7,7 +7,7 @@ pub mod report;
// Local Uses
use crate::schema::idl::parser_new;
use crate::schema::idl::ast::unit::{ASTUnit, SourcedWholeRc};
use crate::schema::idl::ast::unit::{ASTUnit, SourcedWhole};
// External Uses
@ -29,5 +29,5 @@ pub trait Compile {
}
fn from_sourced_whole(sourced: SourcedWholeRc) -> Self::Output;
fn from_sourced_whole(sourced: SourcedWhole) -> Self::Output;
}

View file

@ -2,7 +2,6 @@ use std::cell::RefCell;
use std::collections::HashMap;
// Local Uses
use crate::project::ir::context::ProjectContext;
use crate::schema::idl::ast::unit::{SourcedWhole, SpannedUnit};
use crate::schema::ir::compiler::interpreter::semi_frozen::SemiFrozenUnit;
use crate::schema::ir::frozen::unit::FrozenUnit;
@ -16,6 +15,7 @@ pub struct CompileState<'a> {
pub consts: HashMap<&'a SpannedUnit, SemiFrozenUnit>
}
#[allow(unused)]
impl<'a> CompileState<'_> {
pub(crate) fn to_frozen(&self) -> Vec<FrozenUnit> {
let mut interpreted = vec![];
@ -29,7 +29,7 @@ impl<'a> CompileState<'_> {
pub struct SchemaContext<'a> {
pub schema: SourcedWhole,
pub frozen_schema: Option<Vec<FrozenUnit>>,
pub project_context: Option<&'a RefCell<ProjectContext<'a>>>,
// pub project_context: Option<&'a RefCell<ProjectContext<'a>>>,
// pub project_context: Option<&'a mut ProjectContext<'a>>,
pub compile_state: RefCell<CompileState<'a>>
// pub compile_state: RefCell<CompileState>
@ -41,18 +41,19 @@ impl<'a> SchemaContext<'a> {
Self {
schema,
frozen_schema: None,
project_context: None,
// project_context: None,
compile_state: Default::default(),
}
}
pub fn with_project_and_main(
schema: SourcedWhole, project: &'a RefCell<ProjectContext<'a>>
schema: SourcedWhole,
// project: &'a RefCell<ProjectContext<'a>>
) -> Self {
Self {
schema,
frozen_schema: None,
project_context: Some(project),
// project_context: Some(project),
compile_state: Default::default(),
}
}
@ -61,7 +62,7 @@ impl<'a> SchemaContext<'a> {
Self {
schema,
frozen_schema: None,
project_context: None,
// project_context: None,
compile_state: Default::default(),
}
}