Skip to content

Commit

Permalink
Cast wasm types
Browse files Browse the repository at this point in the history
  • Loading branch information
oovm committed Nov 7, 2023
1 parent ac249db commit 7c67180
Show file tree
Hide file tree
Showing 32 changed files with 279 additions and 224 deletions.
1 change: 1 addition & 0 deletions projects/valkyrie-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ license = "MPL-2.0"
edition = "2021"

[dependencies]
pretty-print = "0.1.9"
ordered-float = "4.1.1"
heck = "0.4.1"
serde = "1.0.188"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
use shredder::Scan;
use std::fmt::{Debug, Display, Formatter};
use super::*;
use nyar_error::FileSpan;

/// A unique identifier used to query the valkyrie object
#[derive(Clone, PartialEq, Eq, Hash, Scan)]
#[derive(Clone, PartialEq, Eq, Hash)]
pub struct ValkyrieID {
path: Vec<String>,
name: Vec<String>,
file: FileSpan,
}

impl Debug for ValkyrieID {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.debug_tuple("ValkyrieID").field(&self.path).finish()
f.debug_tuple("ValkyrieID").field(&self.name).finish()
}
}

impl Display for ValkyrieID {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.write_str(&self.path.join("∷"))
f.write_str(&self.name.join("∷"))
}
}

Expand All @@ -24,22 +25,22 @@ impl ValkyrieID {
where
I: IntoIterator<Item = String>,
{
Self { path: path.into_iter().collect() }
Self { name: path.into_iter().collect(), file: Default::default() }
}
pub fn name(&self) -> &str {
match self.path.last() {
match self.name.last() {
Some(s) => s.as_str(),
None => panic!("Empty namepath"),
}
}
pub fn full_name(&self) -> &[String] {
self.path.as_slice()
self.name.as_slice()
}
pub fn namespace(&self) -> &[String] {
match self.path.len() {
match self.name.len() {
0 => panic!("Empty namepath"),
1 => &[],
_ => &self.path[0..self.path.len() - 1],
_ => &self.name[0..self.name.len() - 1],
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ pub struct ValkyrieMaybe {
}

impl ValkyrieMaybe {
pub fn value<V>(v: V, rhs: ValkyrieType) -> ValkyrieMaybe
pub fn value<V>(v: &V, rhs: ValkyrieType) -> ValkyrieMaybe
where
V: ValkyrieValueType,
{
Self { ok: true, value: Some(v.as_valkyrie()), lhs_type: Some(v.as_type()), rhs_type: Some(rhs) }
}
pub fn error<V>(v: V, lhs: ValkyrieType) -> ValkyrieMaybe
pub fn error<V>(v: &V, lhs: ValkyrieType) -> ValkyrieMaybe
where
V: ValkyrieValueType,
{
Expand Down
74 changes: 74 additions & 0 deletions projects/valkyrie-types/src/atomic/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// pub mod boolean;
// #[cfg(feature = "polars")]
// pub mod data_frame;
// pub mod images;
// pub mod json_like;
// pub mod list;
// pub mod module_name;
pub mod id;
pub mod maybe;
pub mod text;

// pub mod primitive;
// pub mod result;

pub mod boolean;
pub mod number;

use crate::values::{ValkyrieValue, ValkyrieValueType};
use std::fmt::{Debug, Display, Formatter};
//
// use crate::{
// collection::list::{ValkyrieList, ValkyrieOrdinal},
// types::ValkyrieMetaType,
// ValkyrieDict, ValkyrieType, ValkyrieValue,
// };
// use indexmap::IndexMap;
// use shredder::{marker::GcSafe, Gc, Scan, Scanner};
// use std::{
// collections::{hash_map::DefaultHasher, BTreeMap, BTreeSet},
// fmt::{Debug, Formatter},
// hash::{Hash, Hasher},
// ops::Not,
// sync::Arc,
// };
//
/// The display style of a token
pub enum TokenType {
/// A keyword
Keyword,
/// `a, b, c`
Punctuation,
/// `a + b`
Operator,
/// `structure StructureName`
Structure,
/// `class ClassName`
Class,
/// `enumerate EnumerateName`
Enumerate,
/// `union UnionName`
Union,
/// `unite UniteName`
Unite,
/// `variant VariantName`
Variant,
/// `interfaces InterfaceName`
Interface,
/// `trait TraitName`
Trait,
/// `let variable`
Variable,
/// `let mut variable`
VariableMutable,
/// `method(parameter)`
Parameter,
/// `method(mut parameter)`
ParameterMutable,
/// `method(self)`
ParameterSelf,
/// `method(mut self)`
ParameterSelfMutable,
/// `constant`
Constant,
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,21 @@ impl ValkyrieValueType for char {
ValkyrieType::Text { character: true, encoding: "Unicode" }
}
}

impl<'a> ValkyrieValueType for &'a str {
fn as_valkyrie(&self) -> ValkyrieValue {
ValkyrieValue::Text(ValkyrieText { character: false, encoding: "Utf8Text", buffer: self.as_bytes().to_vec() })
}
fn as_type(&self) -> ValkyrieType {
ValkyrieType::Text { character: false, encoding: "Utf8Text" }
}
}

impl ValkyrieValueType for String {
fn as_valkyrie(&self) -> ValkyrieValue {
ValkyrieValue::Text(ValkyrieText { character: false, encoding: "Utf8Text", buffer: self.as_bytes().to_vec() })
}
fn as_type(&self) -> ValkyrieType {
ValkyrieType::Text { character: false, encoding: "Utf8Text" }
}
}
73 changes: 0 additions & 73 deletions projects/valkyrie-types/src/builtin/mod.rs

This file was deleted.

15 changes: 0 additions & 15 deletions projects/valkyrie-types/src/builtin/pointer/mod.rs

This file was deleted.

16 changes: 16 additions & 0 deletions projects/valkyrie-types/src/combine/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// use crate::{
// modifiers::AccessType,
// types::{atomic_type::ValkyrieDocument, ValkyrieMetaType},
// InitializeType, ValkyrieID,
// };
// use std::{
// collections::BTreeMap,
// fmt::{Debug, Formatter},
// ops::Range,
// };
// use valkyrie_ast::ExpressionNode;
// pub mod classes;
// pub mod fields;
pub mod unions;
// pub mod interfaces;
// pub mod names;
8 changes: 8 additions & 0 deletions projects/valkyrie-types/src/combine/unions/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use crate::{ValkyrieID, ValkyrieType};
use indexmap::IndexMap;
use std::collections::BTreeSet;

pub struct ValkyrieUnion {
structured: Option<ValkyrieID>,
set: IndexMap<String, ValkyrieType>,
}
1 change: 0 additions & 1 deletion projects/valkyrie-types/src/definitions/instances/mod.rs

This file was deleted.

17 changes: 0 additions & 17 deletions projects/valkyrie-types/src/definitions/mod.rs

This file was deleted.

7 changes: 4 additions & 3 deletions projects/valkyrie-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

extern crate core;

mod builtin;
mod atomic;
// mod codegen;
// mod collection;
// mod functions;
// mod modifiers;
// // #[cfg(test)]
// mod definitions;
mod combine;
// mod encoding;
// mod singletons;
// pub mod testing;
Expand All @@ -25,7 +25,8 @@ mod values;
//

pub use crate::{
builtin::{maybe::ValkyrieMaybe, number::ValkyrieNumber, text::ValkyrieText},
atomic::{id::ValkyrieID, maybe::ValkyrieMaybe, number::ValkyrieNumber, text::ValkyrieText},
combine::unions::ValkyrieUnion,
values::{ValkyrieType, ValkyrieValue, ValkyrieValueType},
};
// pub use self::{
Expand Down
Loading

0 comments on commit 7c67180

Please sign in to comment.