Skip to content

Commit

Permalink
Removed unique AnyList.
Browse files Browse the repository at this point in the history
  • Loading branch information
uberFoo committed May 22, 2024
1 parent 88ec1fe commit 0b6f100
Show file tree
Hide file tree
Showing 29 changed files with 240 additions and 1,181 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sarzak"
version = "2.13.28"
version = "2.13.29"
edition = "2021"
authors = ["Keith T. Star <[email protected]>"]
categories = ["compilers", "memory-management"]
Expand Down
2 changes: 1 addition & 1 deletion models/lu_dog.json

Large diffs are not rendered by default.

95 changes: 12 additions & 83 deletions src/v2/lu_dog/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//!
//! # Contents:
//!
//! * [`AnyList`]
//! * [`Argument`]
//! * [`AWait`]
//! * [`Binary`]
Expand Down Expand Up @@ -108,24 +107,22 @@ use serde::{Deserialize, Serialize};
use uuid::Uuid;

use crate::v2::lu_dog::types::{
AWait, AnyList, Argument, Binary, Block, Body, BooleanLiteral, BooleanOperator, Call,
CharLiteral, Comparison, DataStructure, DwarfSourceFile, EnumField, EnumGeneric,
EnumGenericType, Enumeration, Expression, ExpressionBit, ExpressionStatement,
ExternalImplementation, Field, FieldAccess, FieldAccessTarget, FieldExpression, FloatLiteral,
ForLoop, FormatBit, FormatString, FuncGeneric, Function, FunctionCall, Grouped,
HaltAndCatchFire, ImplementationBlock, Import, Index, IntegerLiteral, Item, Lambda,
LambdaParameter, LetStatement, List, ListElement, ListExpression, Literal, LocalVariable, Map,
MapElement, MapExpression, MethodCall, NamedFieldExpression, ObjectWrapper, Operator,
Parameter, PathElement, Pattern, RangeExpression, ResultStatement, Span, Statement,
StaticMethodCall, StringBit, StringLiteral, StructExpression, StructField, StructGeneric,
TupleField, TypeCast, Unary, Unit, UnnamedFieldExpression, ValueType, Variable,
VariableExpression, WoogStruct, XFuture, XIf, XMacro, XMatch, XPath, XPlugin, XPrint, XReturn,
XValue, ZObjectStore,
AWait, Argument, Binary, Block, Body, BooleanLiteral, BooleanOperator, Call, CharLiteral,
Comparison, DataStructure, DwarfSourceFile, EnumField, EnumGeneric, EnumGenericType,
Enumeration, Expression, ExpressionBit, ExpressionStatement, ExternalImplementation, Field,
FieldAccess, FieldAccessTarget, FieldExpression, FloatLiteral, ForLoop, FormatBit,
FormatString, FuncGeneric, Function, FunctionCall, Grouped, HaltAndCatchFire,
ImplementationBlock, Import, Index, IntegerLiteral, Item, Lambda, LambdaParameter,
LetStatement, List, ListElement, ListExpression, Literal, LocalVariable, Map, MapElement,
MapExpression, MethodCall, NamedFieldExpression, ObjectWrapper, Operator, Parameter,
PathElement, Pattern, RangeExpression, ResultStatement, Span, Statement, StaticMethodCall,
StringBit, StringLiteral, StructExpression, StructField, StructGeneric, TupleField, TypeCast,
Unary, Unit, UnnamedFieldExpression, ValueType, Variable, VariableExpression, WoogStruct,
XFuture, XIf, XMacro, XMatch, XPath, XPlugin, XPrint, XReturn, XValue, ZObjectStore,
};

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct ObjectStore {
any_list: Rc<RefCell<HashMap<Uuid, Rc<RefCell<AnyList>>>>>,
argument: Rc<RefCell<HashMap<Uuid, Rc<RefCell<Argument>>>>>,
a_wait: Rc<RefCell<HashMap<Uuid, Rc<RefCell<AWait>>>>>,
binary: Rc<RefCell<HashMap<Uuid, Rc<RefCell<Binary>>>>>,
Expand Down Expand Up @@ -222,7 +219,6 @@ pub struct ObjectStore {
impl ObjectStore {
pub fn new() -> Self {
let store = Self {
any_list: Rc::new(RefCell::new(HashMap::default())),
argument: Rc::new(RefCell::new(HashMap::default())),
a_wait: Rc::new(RefCell::new(HashMap::default())),
binary: Rc::new(RefCell::new(HashMap::default())),
Expand Down Expand Up @@ -325,44 +321,6 @@ impl ObjectStore {
}

// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"v2::lu_dog-object-store-methods"}}}
/// Inter (insert) [`AnyList`] into the store.
///
pub fn inter_any_list(&mut self, any_list: Rc<RefCell<AnyList>>) {
let read = any_list.borrow();
self.any_list.borrow_mut().insert(read.id, any_list.clone());
}

/// Exhume (get) [`AnyList`] from the store.
///
pub fn exhume_any_list(&self, id: &Uuid) -> Option<Rc<RefCell<AnyList>>> {
self.any_list
.borrow()
.get(id)
.map(|any_list| any_list.clone())
}

/// Exorcise (remove) [`AnyList`] from the store.
///
pub fn exorcise_any_list(&mut self, id: &Uuid) -> Option<Rc<RefCell<AnyList>>> {
self.any_list
.borrow_mut()
.remove(id)
.map(|any_list| any_list.clone())
}

/// Get an iterator over the internal `HashMap<&Uuid, AnyList>`.
///
pub fn iter_any_list(&self) -> impl Iterator<Item = Rc<RefCell<AnyList>>> + '_ {
let values: Vec<Rc<RefCell<AnyList>>> = self
.any_list
.borrow()
.values()
.map(|any_list| any_list.clone())
.collect();
let len = values.len();
(0..len).map(move |i| values[i].clone())
}

/// Inter (insert) [`Argument`] into the store.
///
pub fn inter_argument(&mut self, argument: Rc<RefCell<Argument>>) {
Expand Down Expand Up @@ -3793,18 +3751,6 @@ impl ObjectStore {
let path = path.join("lu_dog.json");
fs::create_dir_all(&path)?;

// Persist Any List.
{
let path = path.join("any_list");
fs::create_dir_all(&path)?;
for any_list in self.any_list.borrow().values() {
let path = path.join(format!("{}.json", any_list.borrow().id));
let file = fs::File::create(path)?;
let mut writer = io::BufWriter::new(file);
serde_json::to_writer_pretty(&mut writer, &any_list)?;
}
}

// Persist Argument.
{
let path = path.join("argument");
Expand Down Expand Up @@ -4852,23 +4798,6 @@ impl ObjectStore {

let store = Self::new();

// Load Any List.
{
let path = path.join("any_list");
let entries = fs::read_dir(path)?;
for entry in entries {
let entry = entry?;
let path = entry.path();
let file = fs::File::open(path)?;
let reader = io::BufReader::new(file);
let any_list: Rc<RefCell<AnyList>> = serde_json::from_reader(reader)?;
store
.any_list
.borrow_mut()
.insert(any_list.borrow().id, any_list.clone());
}
}

// Load Argument.
{
let path = path.join("argument");
Expand Down
1 change: 1 addition & 0 deletions src/v2/lu_dog/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ pub use crate::v2::lu_dog::addition::ADDITION;
pub use crate::v2::lu_dog::and::And;
pub use crate::v2::lu_dog::and::AND;
pub use crate::v2::lu_dog::any_list::AnyList;
pub use crate::v2::lu_dog::any_list::ANY_LIST;
pub use crate::v2::lu_dog::argument::Argument;
pub use crate::v2::lu_dog::assignment::Assignment;
pub use crate::v2::lu_dog::assignment::ASSIGNMENT;
Expand Down
46 changes: 16 additions & 30 deletions src/v2/lu_dog/types/any_list.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
// {"magic":"","directive":{"Start":{"directive":"allow-editing","tag":"any_list-struct-definition-file"}}}
// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"any_list-use-statements"}}}
use std::cell::RefCell;
use std::rc::Rc;
use uuid::Uuid;

use crate::v2::lu_dog::types::value_type::ValueType;
use crate::v2::lu_dog::types::value_type::ValueTypeEnum;
use serde::{Deserialize, Serialize};

use crate::v2::lu_dog::store::ObjectStore as LuDogStore;
use uuid::{uuid, Uuid};
// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}}

// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"any_list-const-documentation"}}}
Expand All @@ -18,38 +11,31 @@ use crate::v2::lu_dog::store::ObjectStore as LuDogStore;
// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}}
// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"any_list-const-definition"}}}
// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"any_list-struct-definition"}}}
pub const ANY_LIST: Uuid = uuid!["356fe736-c2f0-5d4e-baa6-8725754ed1d3"];

#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct AnyList {
pub bogus: Uuid,
pub id: Uuid,
}
// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}}
// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"any_list-implementation"}}}
pub struct AnyList;

impl AnyList {
// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"any_list-struct-impl-new"}}}
/// Inter a new 'Any List' in the store, and return it's `id`.
pub fn new(bogus: Uuid, store: &mut LuDogStore) -> Rc<RefCell<AnyList>> {
let id = Uuid::new_v4();
let new = Rc::new(RefCell::new(AnyList { bogus, id }));
store.inter_any_list(new.clone());
new
pub fn new() -> Self {
Self {}
}
// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}}
// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"any_list-impl-nav-subtype-to-supertype-value_type"}}}
// Navigate to [`ValueType`] across R1(isa)
pub fn r1_value_type<'a>(&'a self, store: &'a LuDogStore) -> Vec<Rc<RefCell<ValueType>>> {
vec![store
.iter_value_type()
.find(|value_type| {
if let ValueTypeEnum::AnyList(id) = value_type.borrow().subtype {
id == self.id
} else {
false
}
})
.unwrap()]

pub fn id(&self) -> Uuid {
ANY_LIST
}
// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}}
}

impl Default for AnyList {
fn default() -> Self {
Self::new()
}
}
// {"magic":"","directive":{"End":{"directive":"ignore-orig"}}}
// {"magic":"","directive":{"End":{"directive":"allow-editing"}}}
10 changes: 3 additions & 7 deletions src/v2/lu_dog/types/value_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::cell::RefCell;
use std::rc::Rc;
use uuid::Uuid;

use crate::v2::lu_dog::types::any_list::AnyList;
use crate::v2::lu_dog::types::any_list::ANY_LIST;
use crate::v2::lu_dog::types::char::CHAR;
use crate::v2::lu_dog::types::empty::EMPTY;
use crate::v2::lu_dog::types::enum_generic::EnumGeneric;
Expand Down Expand Up @@ -97,15 +97,11 @@ impl ValueType {
// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"value_type-new-impl"}}}
// {"magic":"","directive":{"Start":{"directive":"ignore-orig","tag":"value_type-struct-impl-new_any_list"}}}
/// Inter a new ValueType in the store, and return it's `id`.
pub fn new_any_list(
bogus: bool,
subtype: &Rc<RefCell<AnyList>>,
store: &mut LuDogStore,
) -> Rc<RefCell<ValueType>> {
pub fn new_any_list(bogus: bool, store: &mut LuDogStore) -> Rc<RefCell<ValueType>> {
let id = Uuid::new_v4();
let new = Rc::new(RefCell::new(ValueType {
bogus: bogus,
subtype: ValueTypeEnum::AnyList(subtype.borrow().id), // b
subtype: ValueTypeEnum::AnyList(ANY_LIST),
id,
}));
store.inter_value_type(new.clone());
Expand Down
Loading

0 comments on commit 0b6f100

Please sign in to comment.