Most files suffered major changes

- Less ambiguous syntax
- Better parser (Chumsky only does tokenization now)
- Tidy(|ier) error handling
- Facade for simplified embedding
- External code grouped in (fairly) self-contained Systems
- Dynamic action dispatch
- Many STL additions
This commit is contained in:
2023-08-17 20:47:08 +01:00
parent 751a02a1ec
commit 3fdabc29da
139 changed files with 4269 additions and 1783 deletions

View File

@@ -74,7 +74,7 @@ macro_rules! atomic_impl {
($typ:ident) => {
$crate::atomic_impl! {$typ, |this: &Self, _: $crate::interpreter::Context| {
use $crate::foreign::ExternFn;
Ok(this.clone().to_xfn_cls())
Ok(this.clone().xfn_cls())
}}
};
($typ:ident, $next_phase:expr) => {
@@ -108,7 +108,7 @@ macro_rules! atomic_impl {
Err(e) => return Err($crate::interpreter::RuntimeError::Extern(e)),
}
} else {
next_self.to_atom_cls()
next_self.atom_cls()
};
// package and return
Ok($crate::foreign::AtomicReturn { clause, gas, inert: false })

View File

@@ -14,7 +14,7 @@ use crate::foreign::Atomic;
/// on [Any], [Debug] and [DynClone].
#[macro_export]
macro_rules! atomic_inert {
($typ:ident) => {
($typ:ident, $typename:expr) => {
impl $crate::foreign::Atomic for $typ {
$crate::atomic_defaults! {}
@@ -23,11 +23,25 @@ macro_rules! atomic_inert {
ctx: $crate::interpreter::Context,
) -> $crate::foreign::AtomicResult {
Ok($crate::foreign::AtomicReturn {
clause: self.clone().to_atom_cls(),
clause: self.clone().atom_cls(),
gas: ctx.gas,
inert: true,
})
}
}
impl TryFrom<&ExprInst> for $typ {
type Error = std::rc::Rc<dyn $crate::foreign::ExternError>;
fn try_from(
value: &$crate::interpreted::ExprInst,
) -> Result<Self, Self::Error> {
$crate::systems::cast_exprinst::with_atom(
value,
$typename,
|a: &$typ| Ok(a.clone()),
)
}
}
};
}

View File

@@ -74,25 +74,27 @@ use crate::write_fn_step;
#[macro_export]
macro_rules! define_fn {
// Unary function entry
($( #[ $attr:meta ] )* $qual:vis $name:ident = $body:expr) => {paste::paste!{
$crate::write_fn_step!(
$( #[ $attr ] )* $qual $name
>
[< Internal $name >]
);
$crate::write_fn_step!(
[< Internal $name >]
{}
out = expr => Ok(expr);
{
let lambda = $body;
lambda(out)
}
);
}};
($( #[ $attr:meta ] )* $qual:vis $name:ident = |$x:ident| $body:expr) => {
paste::paste!{
$crate::write_fn_step!(
$( #[ $attr ] )* $qual $name
>
[< Internal $name >]
);
$crate::write_fn_step!(
[< Internal $name >]
{}
out = expr => Ok(expr);
{
let lambda = |$x: &$crate::interpreted::ExprInst| $body;
lambda(out)
}
);
}
};
// xname is optional only if every conversion is implicit
($( #[ $attr:meta ] )* $qual:vis $name:ident {
$( $arg:ident: $typ:ty ),+
$( $arg:ident: $typ:ty ),+ $(,)?
} => $body:expr) => {
$crate::define_fn!{expr=expr in
$( #[ $attr ] )* $qual $name {
@@ -105,7 +107,7 @@ macro_rules! define_fn {
$( #[ $attr:meta ] )*
$qual:vis $name:ident {
$arg0:ident: $typ0:ty $( as $parse0:expr )?
$(, $arg:ident: $typ:ty $( as $parse:expr )? )*
$(, $arg:ident: $typ:ty $( as $parse:expr )? )* $(,)?
} => $body:expr
) => {paste::paste!{
// Generate initial state

View File

@@ -21,7 +21,7 @@ use crate::interpreted::ExprInst;
/// ```no_run
/// // FIXME this is a very old example that wouldn't compile now
/// use unicode_segmentation::UnicodeSegmentation;
///
///
/// use orchidlang::{write_fn_step, Literal, Primitive};
/// use orchidlang::interpreted::Clause;
/// use orchidlang::stl::litconv::{with_str, with_uint};