pre-recording backup
This commit is contained in:
35
src/external/cpsio/print.rs
vendored
35
src/external/cpsio/print.rs
vendored
@@ -1,11 +1,12 @@
|
||||
use std::fmt::Debug;
|
||||
use std::io::{self, Write};
|
||||
use std::rc::Rc;
|
||||
|
||||
use crate::external::litconv::with_str;
|
||||
use crate::representations::PathSet;
|
||||
use crate::{atomic_impl, atomic_redirect, externfn_impl};
|
||||
use crate::representations::interpreted::{Clause, ExprInst};
|
||||
use crate::foreign::{Atomic, AtomicResult, AtomicReturn};
|
||||
use crate::interpreter::Context;
|
||||
use crate::{atomic_impl, atomic_redirect, externfn_impl, atomic_defaults};
|
||||
use crate::representations::interpreted::ExprInst;
|
||||
|
||||
use super::io::IO;
|
||||
|
||||
/// Print function
|
||||
///
|
||||
@@ -22,13 +23,21 @@ externfn_impl!(Print2, |_: &Self, x: ExprInst| Ok(Print1{x}));
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Print1{ x: ExprInst }
|
||||
atomic_redirect!(Print1, x);
|
||||
atomic_impl!(Print1, |Self{ x }: &Self, _| {
|
||||
with_str(x, |s| {
|
||||
print!("{}", s);
|
||||
io::stdout().flush().unwrap();
|
||||
Ok(Clause::Lambda {
|
||||
args: Some(PathSet{ steps: Rc::new(vec![]), next: None }),
|
||||
body: Clause::LambdaArg.wrap()
|
||||
})
|
||||
atomic_impl!(Print1);
|
||||
externfn_impl!(Print1, |this: &Self, x: ExprInst| {
|
||||
with_str(&this.x, |s| {
|
||||
Ok(Print0{ s: s.clone(), x })
|
||||
})
|
||||
});
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Print0{ s: String, x: ExprInst }
|
||||
impl Atomic for Print0 {
|
||||
atomic_defaults!();
|
||||
fn run(&self, ctx: Context) -> AtomicResult {
|
||||
Ok(AtomicReturn::from_data(
|
||||
IO::Print(self.s.clone(), self.x.clone()),
|
||||
ctx
|
||||
))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user