forked from Orchid/orchid
Cleaned up atoms
- Atoms now use MFBI to distinguish between thin and owned atoms. - Introduced TryFromExpr and ToExpr (formerly ToClause) from the old FFI - Standardized on Bottom being a ProjErr, which means that there will be no RTErr
This commit is contained in:
@@ -1,11 +1,15 @@
|
||||
use orchid_extension::atom::owned_atom_info;
|
||||
use std::sync::Arc;
|
||||
|
||||
use orchid_extension::atom::AtomicFeatures;
|
||||
use orchid_extension::fs::DeclFs;
|
||||
use orchid_extension::fun::Fun;
|
||||
use orchid_extension::system::{System, SystemCard};
|
||||
use orchid_extension::system_ctor::SystemCtor;
|
||||
use orchid_extension::tree::GenTree;
|
||||
|
||||
use crate::string::str_atom::StringAtom;
|
||||
use crate::string::str_leer::StringLexer;
|
||||
use crate::OrcString;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct StdSystem;
|
||||
@@ -18,13 +22,16 @@ impl SystemCtor for StdSystem {
|
||||
}
|
||||
impl SystemCard for StdSystem {
|
||||
type Ctor = Self;
|
||||
const ATOM_DEFS: &'static [Option<orchid_extension::atom::AtomInfo>] =
|
||||
&[Some(owned_atom_info::<StringAtom>())];
|
||||
const ATOM_DEFS: &'static [Option<fn() -> &'static orchid_extension::atom::AtomInfo>] = &[
|
||||
Some(StringAtom::info)
|
||||
];
|
||||
}
|
||||
impl System for StdSystem {
|
||||
fn lexers() -> Vec<orchid_extension::lexer::LexerObj> { vec![&StringLexer] }
|
||||
fn vfs() -> DeclFs { DeclFs::Mod(&[]) }
|
||||
fn env() -> GenTree {
|
||||
GenTree::module([("std", GenTree::module([("string", GenTree::module([]))]))])
|
||||
GenTree::module([("std", GenTree::module([("string", GenTree::module([
|
||||
("concat", GenTree::cnst(Fun::new(|left: OrcString| Fun::new(move |right: OrcString| StringAtom::new(Arc::new(left.get_string().to_string() + &right.get_string()))))))
|
||||
]))]))])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,11 +8,12 @@ use orchid_api_traits::{Encode, Request};
|
||||
use orchid_base::id_store::IdStore;
|
||||
use orchid_base::interner::{deintern, Tok};
|
||||
use orchid_base::location::Pos;
|
||||
use orchid_extension::atom::{AtomCard, OwnedAtom, TypAtom};
|
||||
use orchid_extension::atom::{Atomic, TypAtom};
|
||||
use orchid_extension::atom_owned::{OwnedAtom, OwnedVariant};
|
||||
use orchid_extension::error::{ProjectError, ProjectResult};
|
||||
use orchid_extension::expr::{ExprHandle, OwnedExpr};
|
||||
use orchid_extension::system::{downcast_atom, SysCtx};
|
||||
use orchid_extension::try_from_expr::TryFromExpr;
|
||||
use orchid_extension::conv::TryFromExpr;
|
||||
|
||||
pub static STR_REPO: IdStore<Arc<String>> = IdStore::new();
|
||||
|
||||
@@ -31,7 +32,8 @@ pub(crate) enum StringAtom {
|
||||
Val(NonZeroU64),
|
||||
Int(Tok<String>),
|
||||
}
|
||||
impl AtomCard for StringAtom {
|
||||
impl Atomic for StringAtom {
|
||||
type Variant = OwnedVariant;
|
||||
type Data = StringVal;
|
||||
type Req = StringGetVal;
|
||||
}
|
||||
@@ -72,6 +74,7 @@ impl OwnedAtom for StringAtom {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct OrcString(TypAtom<StringAtom>);
|
||||
impl OrcString {
|
||||
pub fn get_string(&self) -> Arc<String> {
|
||||
@@ -92,9 +95,9 @@ impl ProjectError for NotString {
|
||||
}
|
||||
}
|
||||
impl TryFromExpr for OrcString {
|
||||
fn try_from_expr(expr: ExprHandle) -> ProjectResult<Self> {
|
||||
(OwnedExpr::new(expr).foreign_atom().map_err(|expr| expr.position.clone()))
|
||||
.and_then(|fatom| downcast_atom(fatom).map_err(|f| f.position))
|
||||
fn try_from_expr(expr: ExprHandle) -> ProjectResult<OrcString> {
|
||||
(OwnedExpr::new(expr).foreign_atom().map_err(|expr| expr.pos.clone()))
|
||||
.and_then(|fatom| downcast_atom(fatom).map_err(|f| f.pos))
|
||||
.map_err(|p| NotString(p).pack())
|
||||
.map(OrcString)
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ use orchid_base::interner::intern;
|
||||
use orchid_base::location::Pos;
|
||||
use orchid_base::name::VName;
|
||||
use orchid_base::vname;
|
||||
use orchid_extension::atom::OwnedAtom;
|
||||
use orchid_extension::atom::AtomicFeatures;
|
||||
use orchid_extension::error::{ErrorSansOrigin, ProjectErrorObj, ProjectResult};
|
||||
use orchid_extension::lexer::{LexContext, Lexer};
|
||||
use orchid_extension::tree::{wrap_tokv, GenTok, GenTokTree};
|
||||
|
||||
Reference in New Issue
Block a user