forked from MightyPork/crsn
implement "lds" for objects (buffers, cin)
This commit is contained in:
@@ -10,6 +10,7 @@ use std::convert::TryFrom;
|
||||
use std::io;
|
||||
use crsn::asm::instr::cond::Flag;
|
||||
use std::fmt;
|
||||
use crsn::asm::data::Wr;
|
||||
|
||||
mod console {
|
||||
use std::{io};
|
||||
@@ -244,4 +245,52 @@ impl CrsnExtension for StdioOps {
|
||||
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
/// Run-time method called to read all values from an object ("lds" using the object handle syntax)
|
||||
fn read_obj_all(&self, state: &mut RunState, whandle: Wr, rhandle: Value)
|
||||
-> Result<Option<()>, Fault>
|
||||
{
|
||||
if rhandle == self.hdl_stdin {
|
||||
loop {
|
||||
match console::read_char() {
|
||||
Ok(c) => {
|
||||
state.write(whandle, c as Value)?;
|
||||
}
|
||||
Err(e) => {
|
||||
if e.kind() != io::ErrorKind::InvalidData {
|
||||
state.set_flag(Flag::Eof, true);
|
||||
} else {
|
||||
state.set_flag(Flag::Invalid, true);
|
||||
}
|
||||
return Ok(Some(()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if rhandle == self.hdl_stdin_raw {
|
||||
loop {
|
||||
match console::read_byte() {
|
||||
Ok(c) => {
|
||||
state.write(whandle, c as Value)?;
|
||||
}
|
||||
Err(e) => {
|
||||
if e.kind() != io::ErrorKind::InvalidData {
|
||||
state.set_flag(Flag::Eof, true);
|
||||
} else {
|
||||
state.set_flag(Flag::Invalid, true);
|
||||
}
|
||||
return Ok(Some(()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if rhandle == self.hdl_stdout || rhandle == self.hdl_stdout_raw {
|
||||
state.set_flag(Flag::Invalid, true);
|
||||
return Ok(Some(()));
|
||||
}
|
||||
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user