forked from Orchid/orchid
September-october commit
- manual parser - stl refinements - all language constructs are now Send
This commit is contained in:
@@ -3,7 +3,7 @@ use super::error::RuntimeError;
|
||||
use super::Return;
|
||||
use crate::foreign::AtomicReturn;
|
||||
use crate::representations::interpreted::{Clause, ExprInst};
|
||||
use crate::representations::{PathSet, Primitive};
|
||||
use crate::representations::PathSet;
|
||||
use crate::utils::never::{unwrap_always, Always};
|
||||
use crate::utils::Side;
|
||||
|
||||
@@ -77,9 +77,8 @@ pub fn apply(
|
||||
) -> Result<Return, RuntimeError> {
|
||||
let (state, (gas, inert)) = f.try_update(|clause, loc| match clause {
|
||||
// apply an ExternFn or an internal function
|
||||
Clause::P(Primitive::ExternFn(f)) => {
|
||||
let clause =
|
||||
f.apply(x, ctx.clone()).map_err(|e| RuntimeError::Extern(e))?;
|
||||
Clause::ExternFn(f) => {
|
||||
let clause = f.apply(x, ctx.clone()).map_err(RuntimeError::Extern)?;
|
||||
Ok((clause, (ctx.gas.map(|g| g - 1), false)))
|
||||
},
|
||||
Clause::Lambda { args, body } => Ok(if let Some(args) = args {
|
||||
@@ -97,7 +96,7 @@ pub fn apply(
|
||||
} else {
|
||||
Err(RuntimeError::MissingSymbol(name.clone(), loc))
|
||||
},
|
||||
Clause::P(Primitive::Atom(atom)) => {
|
||||
Clause::Atom(atom) => {
|
||||
// take a step in expanding atom
|
||||
let AtomicReturn { clause, gas, inert } = atom.run(ctx.clone())?;
|
||||
Ok((Clause::Apply { f: clause.wrap(), x }, (gas, inert)))
|
||||
|
||||
@@ -8,7 +8,6 @@ use super::{run, Context, Return, RuntimeError};
|
||||
use crate::foreign::{Atom, Atomic, ExternError};
|
||||
use crate::interpreted::{Clause, Expr, ExprInst};
|
||||
use crate::utils::take_with_output;
|
||||
use crate::Primitive;
|
||||
|
||||
trait_set! {
|
||||
trait Handler = FnMut(Box<dyn Any>) -> HandlerRes;
|
||||
@@ -71,9 +70,9 @@ pub fn run_handler(
|
||||
loop {
|
||||
let mut ret = run(expr, ctx.clone())?;
|
||||
let quit = take_with_output(&mut ret.state, |exi| match exi.expr_val() {
|
||||
Expr { clause: Clause::P(Primitive::Atom(a)), .. } => {
|
||||
Expr { clause: Clause::Atom(a), .. } => {
|
||||
match handlers.dispatch(a.0) {
|
||||
Err(b) => (Clause::P(Primitive::Atom(Atom(b))).wrap(), Ok(true)),
|
||||
Err(b) => (Clause::Atom(Atom(b)).wrap(), Ok(true)),
|
||||
Ok(e) => match e {
|
||||
Ok(expr) => (expr, Ok(false)),
|
||||
Err(e) => (Clause::Bottom.wrap(), Err(e)),
|
||||
|
||||
@@ -3,7 +3,6 @@ use super::context::{Context, Return};
|
||||
use super::error::RuntimeError;
|
||||
use crate::foreign::AtomicReturn;
|
||||
use crate::representations::interpreted::{Clause, ExprInst};
|
||||
use crate::representations::Primitive;
|
||||
|
||||
/// Normalize an expression using beta reduction with memoization
|
||||
pub fn run(expr: ExprInst, mut ctx: Context) -> Result<Return, RuntimeError> {
|
||||
@@ -19,7 +18,7 @@ pub fn run(expr: ExprInst, mut ctx: Context) -> Result<Return, RuntimeError> {
|
||||
ctx.gas = res.gas;
|
||||
cls = res.state.expr().clause.clone();
|
||||
},
|
||||
Clause::P(Primitive::Atom(data)) => {
|
||||
Clause::Atom(data) => {
|
||||
let AtomicReturn { clause, gas, inert } = data.run(ctx.clone())?;
|
||||
if inert {
|
||||
return Ok((clause, (gas, true)));
|
||||
|
||||
Reference in New Issue
Block a user