fix unit tests, cargo fiox

master
Ondřej Hruška 4 years ago
parent 5107b78ae5
commit 2752fa4beb
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 11
      crsn/src/asm/parse/mod.rs
  2. 2
      crsn/src/asm/parse/parse_data.rs
  3. 2
      crsn/src/builtin/exec.rs
  4. 55
      crsn/src/builtin/parse.rs
  5. 2
      crsn/src/runtime/run_thread.rs
  6. 2
      crsn/src/runtime/run_thread/state.rs

@ -53,6 +53,17 @@ pub struct ParserState {
pub parsing_expr : bool,
}
impl ParserState {
pub fn reset(&mut self) {
self.global_reg_aliases.clear();
self.reg_aliases.clear();
self.reg_alias_stack.clear();
self.constants.clear();
self.parsing_expr = false;
self.const_eval.reset();
}
}
pub fn parse(source: &str, pos: &SourcePosition, parsers: &ParserContext) -> Result<Vec<Op>, CrsnError> {
let (items, _pos) = expect_list(sexp::parse(source)?, true)?;

@ -124,7 +124,7 @@ pub fn parse_data_disp(tok: Sexp, pcx: &ParserContext) -> Result<DataDisp, CrsnE
}
let mut state_mut = pcx.state.borrow_mut();
state_mut.const_eval.clear_all();
state_mut.const_eval.reset();
let ticl = state_mut.const_eval.thread_info.clone();
op.execute(&ticl, &mut state_mut.const_eval)

@ -89,7 +89,7 @@ impl OpTrait for BuiltinOp {
values.push(state.read(arg)?);
}
let mut frame2 = StackFrame::new(pos, &values);
let frame2 = StackFrame::new(pos, &values);
let handle_val = state.add_coroutine(frame2);
state.write(handle, handle_val)?;

@ -1,4 +1,4 @@
use sexp::{Atom, Sexp, SourcePosition, atom_qs, atom_s};
use sexp::{Atom, Sexp, SourcePosition, atom_qs};
use crate::asm::data::literal::{RoutineName};
use crate::asm::data::reg::parse_reg;
@ -452,7 +452,7 @@ pub(crate) fn to_sexp(op: &BuiltinOp) -> Sexp {
if args.is_empty() {
sexp::list(&[A("spawn"), A(handle), A(proc)])
} else {
let mut v = vec![A("spawn"), A(handle), A(proc)];
let mut v = vec![A("spawn"), A(handle), A(&proc.name)];
v.extend(args.iter().map(|r| A(r)));
sexp::list(&v)
}
@ -473,10 +473,15 @@ mod test {
use sexp::SourcePosition;
use crate::asm::parse::{parse_instructions, ParserContext};
use crate::asm::parse::{parse_instructions, ParserContext, ParserState};
use crate::asm::parse::sexp_expect::expect_list;
use crate::builtin::BuiltinOps;
use crate::module::OpTrait;
use std::cell::RefCell;
use std::sync::Arc;
use crate::runtime::run_thread::{ThreadInfo, ThreadToken, RunState};
use crate::runtime::program::Program;
use crate::runtime::frame::REG_COUNT;
#[test]
fn roundtrip() {
@ -562,13 +567,42 @@ mod test {
let parser = BuiltinOps::new();
let parsers = &[parser];
let parsers = Arc::new(vec![parser]);
let ti = Arc::new(ThreadInfo {
id: ThreadToken(0),
uniq: Default::default(),
program: Program::new(vec![], parsers.clone()).unwrap(),
cycle_time: Default::default(),
scheduler_interval: Default::default(),
extensions: parsers.clone(),
});
let pcx = ParserContext {
parsers: &parsers,
state: RefCell::new(ParserState {
reg_aliases: Default::default(),
reg_alias_stack: vec![],
global_reg_aliases: Default::default(),
constants: Default::default(),
// This is a fake thread to pass to constant expressions when evaluating them.
// This allows to evaluate nearly all instructions at compile time.
const_eval: RunState {
thread_info: ti.clone(),
cr: Default::default(),
parked: Default::default(),
global_regs: [0; REG_COUNT],
ext_data: Default::default(),
cr_deadline: None
},
const_eval_ti: ti.clone(),
parsing_expr: false
}),
};
for (sample, expected) in samples {
let pcx = ParserContext {
parsers,
state: Default::default(),
};
pcx.state.borrow_mut().reset();
println!("Parse: {}", sample);
@ -587,10 +621,7 @@ mod test {
assert_eq!(expected, exported);
println!(" - 2nd cycle");
let pcx = ParserContext {
parsers,
state: Default::default(),
};
pcx.state.borrow_mut().reset();
/* second cycle, nothing should change */
let s = sexp::parse(&format!("({})", exported))

@ -126,7 +126,7 @@ impl RunThread {
'find: for (n, th) in self.state.parked.iter_mut().enumerate() {
if th.handle == handle {
if let CoroutineState::Finished(_) = &th.cr_state {
let mut crs = mem::replace(&mut th.cr_state, CoroutineState::Ready);
let crs = mem::replace(&mut th.cr_state, CoroutineState::Ready);
self.state.parked.remove(n); // delete it
found = true;

@ -72,7 +72,7 @@ impl Default for CoroutineState {
impl RunState {
/// Clear everything. Caution: when done at runtime, this effectively reboots the thread
pub fn clear_all(&mut self) {
pub fn reset(&mut self) {
self.cr = Default::default();
self.parked = Default::default();
self.global_regs = Default::default();

Loading…
Cancel
Save