Commit 063bcbf9 authored by Jeff Smits's avatar Jeff Smits

Split SSL into multiple files

parent 5cfb1317
......@@ -2,7 +2,7 @@ use error::{Result, Error};
use factory::{ATermFactory, ATerm, ATermRef};
use preprocess::SDefT;
use primitives::{Primitives, eval_prim_ref};
use primitives::ssl::SslState;
use primitives::ssl::State;
use std::collections::HashMap;
use std::fmt;
......@@ -18,7 +18,7 @@ pub struct MutContext<'a> {
pub scopes: RefCell<Vec<Scope<ATermRef>>>,
pub factory: &'a ATermFactory,
pub primitives: Vec<&'static Primitives>,
pub ssl_state: RefCell<SslState>,
pub ssl_state: RefCell<State>,
}
impl<'a> MutContext<'a> {
......@@ -31,7 +31,7 @@ impl<'a> MutContext<'a> {
factory: factory,
primitives: primitives,
scopes: RefCell::new(scopes),
ssl_state: RefCell::new(SslState::new()),
ssl_state: RefCell::new(State::new()),
}
}
......
use context::MutContext;
use error::{Error, Result};
use factory::ATermRef;
use interpreter::{from_cons_nil_list, to_cons_nil_list};
use preprocess::SDefT;
use super::State;
use aterm::{Term, ATermFactory as ATF, ATerm as A};
use aterm::print::ATermWrite;
use aterm::parse::ATermRead;
use std::collections::HashMap;
use std::path::{Path, PathBuf};
use std::fs::{File, OpenOptions};
use std::io::{Read, Write};
use std::io;
use std::fmt;
use std::error::Error as StdError;
macro_rules! eprintln {
($($tt:tt)*) => {{
use std::io::{Write, stderr};
writeln!(&mut stderr(), $($tt)*).unwrap();
}}
}
pub fn dynamic_rules_hashtable<'a>(context: &MutContext<'a>,
sargs: Vec<SDefT>,
targs: Vec<ATermRef>,
current: ATermRef)
-> Result<ATermRef> {
// TODO
unimplemented!();
}
pub fn table_hashtable<'a>(context: &MutContext<'a>,
sargs: Vec<SDefT>,
targs: Vec<ATermRef>,
current: ATermRef)
-> Result<ATermRef> {
// TODO
unimplemented!();
}
pub fn hashtable_get<'a>(context: &MutContext<'a>,
sargs: Vec<SDefT>,
targs: Vec<ATermRef>,
current: ATermRef)
-> Result<ATermRef> {
// TODO
unimplemented!();
}
pub fn hashtable_create<'a>(context: &MutContext<'a>,
sargs: Vec<SDefT>,
targs: Vec<ATermRef>,
current: ATermRef)
-> Result<ATermRef> {
// TODO
unimplemented!();
}
pub fn hashtable_put<'a>(context: &MutContext<'a>,
sargs: Vec<SDefT>,
targs: Vec<ATermRef>,
current: ATermRef)
-> Result<ATermRef> {
// TODO
unimplemented!();
}
pub fn hashtable_reset<'a>(context: &MutContext<'a>,
sargs: Vec<SDefT>,
targs: Vec<ATermRef>,
current: ATermRef)
-> Result<ATermRef> {
// TODO
unimplemented!();
}
pub fn hashtable_destroy<'a>(context: &MutContext<'a>,
sargs: Vec<SDefT>,
targs: Vec<ATermRef>,
current: ATermRef)
-> Result<ATermRef> {
// TODO
unimplemented!();
}
pub fn hashtable_remove<'a>(context: &MutContext<'a>,
sargs: Vec<SDefT>,
targs: Vec<ATermRef>,
current: ATermRef)
-> Result<ATermRef> {
// TODO
unimplemented!();
}
pub fn hashtable_keys<'a>(context: &MutContext<'a>,
sargs: Vec<SDefT>,
targs: Vec<ATermRef>,
current: ATermRef)
-> Result<ATermRef> {
// TODO
unimplemented!();
}
pub fn table_fold<'a>(context: &MutContext<'a>,
sargs: Vec<SDefT>,
targs: Vec<ATermRef>,
current: ATermRef)
-> Result<ATermRef> {
// TODO
unimplemented!();
}
pub fn table_keys_fold<'a>(context: &MutContext<'a>,
sargs: Vec<SDefT>,
targs: Vec<ATermRef>,
current: ATermRef)
-> Result<ATermRef> {
// TODO
unimplemented!();
}
pub fn table_values_fold<'a>(context: &MutContext<'a>,
sargs: Vec<SDefT>,
targs: Vec<ATermRef>,
current: ATermRef)
-> Result<ATermRef> {
// TODO
unimplemented!();
}
// LIST
pub fn get_list_length<'a>(context: &MutContext<'a>,
sargs: Vec<SDefT>,
targs: Vec<ATermRef>,
current: ATermRef)
-> Result<ATermRef> {
// TODO
unimplemented!();
}
pub fn list_loop<'a>(context: &MutContext<'a>,
sargs: Vec<SDefT>,
targs: Vec<ATermRef>,
current: ATermRef)
-> Result<ATermRef> {
// TODO
unimplemented!();
}
pub fn list_fold<'a>(context: &MutContext<'a>,
sargs: Vec<SDefT>,
targs: Vec<ATermRef>,
current: ATermRef)
-> Result<ATermRef> {
// TODO
unimplemented!();
}
\ No newline at end of file
use context::MutContext;
use error::{Error, Result};
use factory::ATermRef;
use interpreter::{from_cons_nil_list, to_cons_nil_list};
use preprocess::SDefT;
use super::State;
use aterm::{Term, ATermFactory as ATF, ATerm as A};
use aterm::print::ATermWrite;
use aterm::parse::ATermRead;
use std::collections::HashMap;
use std::path::{Path, PathBuf};
use std::fs::{File, OpenOptions};
use std::io::{Read, Write};
use std::io;
use std::fmt;
use std::error::Error as StdError;
macro_rules! eprintln {
($($tt:tt)*) => {{
use std::io::{Write, stderr};
writeln!(&mut stderr(), $($tt)*).unwrap();
}}
}
pub fn indexedSet_create<'a>(context: &MutContext<'a>,
sargs: Vec<SDefT>,
targs: Vec<ATermRef>,
current: ATermRef)
-> Result<ATermRef> {
// TODO
unimplemented!();
}
pub fn indexedSet_destroy<'a>(context: &MutContext<'a>,
sargs: Vec<SDefT>,
targs: Vec<ATermRef>,
current: ATermRef)
-> Result<ATermRef> {
// TODO
unimplemented!();
}
pub fn indexedSet_put<'a>(context: &MutContext<'a>,
sargs: Vec<SDefT>,
targs: Vec<ATermRef>,
current: ATermRef)
-> Result<ATermRef> {
// TODO
unimplemented!();
}
pub fn indexedSet_getIndex<'a>(context: &MutContext<'a>,
sargs: Vec<SDefT>,
targs: Vec<ATermRef>,
current: ATermRef)
-> Result<ATermRef> {
// TODO
unimplemented!();
}
pub fn indexedSet_elements<'a>(context: &MutContext<'a>,
sargs: Vec<SDefT>,
targs: Vec<ATermRef>,
current: ATermRef)
-> Result<ATermRef> {
// TODO
unimplemented!();
}
pub fn indexedSet_remove<'a>(context: &MutContext<'a>,
sargs: Vec<SDefT>,
targs: Vec<ATermRef>,
current: ATermRef)
-> Result<ATermRef> {
// TODO
unimplemented!();
}
pub fn indexedSet_reset<'a>(context: &MutContext<'a>,
sargs: Vec<SDefT>,
targs: Vec<ATermRef>,
current: ATermRef)
-> Result<ATermRef> {
// TODO
unimplemented!();
}
\ No newline at end of file
use context::MutContext;
use error::{Error, Result};
use factory::ATermRef;
use preprocess::SDefT;
use aterm::{ATermFactory as ATF, ATerm as A};
pub fn is_int<'a>(_context: &MutContext<'a>,
_sargs: Vec<SDefT>,
targs: Vec<ATermRef>,
current: ATermRef)
-> Result<ATermRef> {
if targs.len() < 1 {
return Err(Error::UnknownBehaviour("Primitive is_int called with wrong argument count"));
}
targs[0]
.get_int()
.map(|_| current)
.ok_or(Error::StrategyFailed)
}
pub fn int<'a>(context: &MutContext<'a>,
_sargs: Vec<SDefT>,
targs: Vec<ATermRef>,
current: ATermRef)
-> Result<ATermRef> {
if targs.len() < 1 {
return Err(Error::UnknownBehaviour("Primitive int called with wrong argument count"));
}
targs[0]
.get_int()
.map(|_| targs[0].clone())
.or_else(|| {
targs[0]
.get_real()
.map(|r| context.factory.int(r as i32))
})
.ok_or(Error::StrategyFailed)
}
pub fn iori<'a>(context: &MutContext<'a>,
_sargs: Vec<SDefT>,
targs: Vec<ATermRef>,
current: ATermRef)
-> Result<ATermRef> {
if targs.len() < 2 {
return Err(Error::UnknownBehaviour("Primitive iori called with wrong argument count"));
}
let i1 = targs[0].get_int().ok_or(Error::StrategyFailed)?;
let i2 = targs[1].get_int().ok_or(Error::StrategyFailed)?;
Ok(context.factory.int(i1 | i2))
}
pub fn xori<'a>(context: &MutContext<'a>,
_sargs: Vec<SDefT>,
targs: Vec<ATermRef>,
current: ATermRef)
-> Result<ATermRef> {
if targs.len() < 2 {
return Err(Error::UnknownBehaviour("Primitive xori called with wrong argument count"));
}
let i1 = targs[0].get_int().ok_or(Error::StrategyFailed)?;
let i2 = targs[1].get_int().ok_or(Error::StrategyFailed)?;
Ok(context.factory.int(i1 ^ i2))
}
pub fn andi<'a>(context: &MutContext<'a>,
_sargs: Vec<SDefT>,
targs: Vec<ATermRef>,
current: ATermRef)
-> Result<ATermRef> {
if targs.len() < 2 {
return Err(Error::UnknownBehaviour("Primitive andi called with wrong argument count"));
}
let i1 = targs[0].get_int().ok_or(Error::StrategyFailed)?;
let i2 = targs[1].get_int().ok_or(Error::StrategyFailed)?;
Ok(context.factory.int(i1 & i2))
}
pub fn shli<'a>(context: &MutContext<'a>,
_sargs: Vec<SDefT>,
targs: Vec<ATermRef>,
current: ATermRef)
-> Result<ATermRef> {
if targs.len() < 2 {
return Err(Error::UnknownBehaviour("Primitive shli called with wrong argument count"));
}
let i1 = targs[0].get_int().ok_or(Error::StrategyFailed)?;
let i2 = targs[1].get_int().ok_or(Error::StrategyFailed)?;
Ok(context.factory.int(i1 << i2))
}
pub fn shri<'a>(context: &MutContext<'a>,
_sargs: Vec<SDefT>,
targs: Vec<ATermRef>,
current: ATermRef)
-> Result<ATermRef> {
if targs.len() < 2 {
return Err(Error::UnknownBehaviour("Primitive shri called with wrong argument count"));
}
let i1 = targs[0].get_int().ok_or(Error::StrategyFailed)?;
let i2 = targs[1].get_int().ok_or(Error::StrategyFailed)?;
Ok(context.factory.int(i1 >> i2))
}
pub fn addi<'a>(context: &MutContext<'a>,
_sargs: Vec<SDefT>,
targs: Vec<ATermRef>,
current: ATermRef)
-> Result<ATermRef> {
if targs.len() < 2 {
return Err(Error::UnknownBehaviour("Primitive addi called with wrong argument count"));
}
let i1 = targs[0].get_int().ok_or(Error::StrategyFailed)?;
let i2 = targs[1].get_int().ok_or(Error::StrategyFailed)?;
Ok(context.factory.int(i1 + i2))
}
pub fn divi<'a>(context: &MutContext<'a>,
_sargs: Vec<SDefT>,
targs: Vec<ATermRef>,
current: ATermRef)
-> Result<ATermRef> {
if targs.len() < 2 {
return Err(Error::UnknownBehaviour("Primitive divi called with wrong argument count"));
}
let i1 = targs[0].get_int().ok_or(Error::StrategyFailed)?;
let i2 = targs[1].get_int().ok_or(Error::StrategyFailed)?;
Ok(context.factory.int(i1 / i2))
}
pub fn gti<'a>(context: &MutContext<'a>,
_sargs: Vec<SDefT>,
targs: Vec<ATermRef>,
current: ATermRef)
-> Result<ATermRef> {
if targs.len() < 2 {
return Err(Error::UnknownBehaviour("Primitive gti called with wrong argument count"));
}
let i1 = targs[0].get_int().ok_or(Error::StrategyFailed)?;
let i2 = targs[1].get_int().ok_or(Error::StrategyFailed)?;
if i1 > i2 {
Ok(current)
} else {
Err(Error::StrategyFailed)
}
}
pub fn muli<'a>(context: &MutContext<'a>,
_sargs: Vec<SDefT>,
targs: Vec<ATermRef>,
current: ATermRef)
-> Result<ATermRef> {
if targs.len() < 2 {
return Err(Error::UnknownBehaviour("Primitive muli called with wrong argument count"));
}
let i1 = targs[0].get_int().ok_or(Error::StrategyFailed)?;
let i2 = targs[1].get_int().ok_or(Error::StrategyFailed)?;
Ok(context.factory.int(i1 * i2))
}
pub fn modi<'a>(context: &MutContext<'a>,
_sargs: Vec<SDefT>,
targs: Vec<ATermRef>,
current: ATermRef)
-> Result<ATermRef> {
if targs.len() < 2 {
return Err(Error::UnknownBehaviour("Primitive modi called with wrong argument count"));
}
let i1 = targs[0].get_int().ok_or(Error::StrategyFailed)?;
let i2 = targs[1].get_int().ok_or(Error::StrategyFailed)?;
Ok(context.factory.int(i1 % i2))
}
pub fn subti<'a>(context: &MutContext<'a>,
_sargs: Vec<SDefT>,
targs: Vec<ATermRef>,
current: ATermRef)
-> Result<ATermRef> {
if targs.len() < 2 {
return Err(Error::UnknownBehaviour("Primitive subti called with wrong argument count"));
}
let i1 = targs[0].get_int().ok_or(Error::StrategyFailed)?;
let i2 = targs[1].get_int().ok_or(Error::StrategyFailed)?;
Ok(context.factory.int(i1 - i2))
}
pub fn int_to_string<'a>(context: &MutContext<'a>,
_sargs: Vec<SDefT>,
targs: Vec<ATermRef>,
current: ATermRef)
-> Result<ATermRef> {
if targs.len() < 1 {
return Err(Error::UnknownBehaviour("Primitive int_to_string called with wrong argument \
count"));
}
targs[0]
.get_int()
.map(|i| context.factory.string(i.to_string()))
.ok_or(Error::StrategyFailed)
}
pub fn string_to_int<'a>(context: &MutContext<'a>,
_sargs: Vec<SDefT>,
targs: Vec<ATermRef>,
current: ATermRef)
-> Result<ATermRef> {
if targs.len() < 1 {
return Err(Error::UnknownBehaviour("Primitive string_to_int called with wrong argument \
count"));
}
targs[0]
.get_string()
.and_then(|s| s.trim().parse().ok().map(|i| context.factory.int(i)))
.ok_or(Error::StrategyFailed)
}
pub fn rand<'a>(context: &MutContext<'a>,
_sargs: Vec<SDefT>,
targs: Vec<ATermRef>,
current: ATermRef)
-> Result<ATermRef> {
use rand;
Ok(context.factory.int(rand::random()))
}
\ No newline at end of file
use context::MutContext;
use error::{Error, Result};
use factory::ATermRef;
use interpreter::{from_cons_nil_list, to_cons_nil_list};
use preprocess::SDefT;
use super::State;
use aterm::{Term, ATermFactory as ATF, ATerm as A};
use aterm::print::ATermWrite;
use aterm::parse::ATermRead;
use std::collections::HashMap;
use std::path::{Path, PathBuf};
use std::fs::{File, OpenOptions};
use std::io::{Read, Write};
use std::io;
use std::fmt;
use std::error::Error as StdError;
macro_rules! eprintln {
($($tt:tt)*) => {{
use std::io::{Write, stderr};
writeln!(&mut stderr(), $($tt)*).unwrap();
}}
}
pub fn stacktrace_get_all_frame_names<'a>(context: &MutContext<'a>,
sargs: Vec<SDefT>,
targs: Vec<ATermRef>,
current: ATermRef)
-> Result<ATermRef> {
// TODO
unimplemented!();
}
\ No newline at end of file
mod int;
mod real;
mod string;
mod sys;
mod indexed_set;
mod hash_table;
mod term;
mod interpreter;
pub struct State {
string: StringState,
sys: SysState,
}
impl State {
pub fn new() -> Self {
State {
string: StringState::new(),
sys: SysState::new(),
}
}
}
pub use self::int::*;
pub use self::real::*;
pub use self::string::*;
pub use self::sys::*;
pub use self::indexed_set::*;
pub use self::hash_table::*;
pub use self::term::*;
pub use self::interpreter::*;
use context::MutContext;
use error::{Error, Result};
use factory::ATermRef;
use preprocess::SDefT;
use aterm::{ATermFactory as ATF, ATerm as A};
pub fn is_real<'a>(_context: &MutContext<'a>,
_sargs: Vec<SDefT>,
targs: Vec<ATermRef>,
current: ATermRef)
-> Result<ATermRef> {
if targs.len() < 1 {
return Err(Error::UnknownBehaviour("Primitive is_real called with wrong argument count"));
}
targs[0]
.get_real()
.map(|_| current)
.ok_or(Error::StrategyFailed)
}
pub fn real<'a>(context: &MutContext<'a>,
_sargs: Vec<SDefT>,
targs: Vec<ATermRef>,
current: ATermRef)
-> Result<ATermRef> {
if targs.len() < 1 {
return Err(Error::UnknownBehaviour("Primitive is_real called with wrong argument count"));
}
targs[0]
.get_real()
.map(|_| targs[0].clone())
.or_else(|| {
targs[0]
.get_int()
.map(|i| context.factory.real(i as f32))
})
.ok_or(Error::StrategyFailed)
}
pub fn addr<'a>(context: &MutContext<'a>,
_sargs: Vec<SDefT>,
targs: Vec<ATermRef>,
current: ATermRef)
-> Result<ATermRef> {
if targs.len() < 2 {
return Err(Error::UnknownBehaviour("Primitive addr called with wrong argument count"));
}
let r1 = targs[0].get_real().ok_or(Error::StrategyFailed)?;
let r2 = targs[1].get_real().ok_or(Error::StrategyFailed)?;
Ok(context.factory.real(r1 + r2))
}
pub fn divr<'a>(context: &MutContext<'a>,
_sargs: Vec<SDefT>,
targs: Vec<ATermRef>,
current: ATermRef)
-> Result<ATermRef> {
if targs.len() < 2 {
return Err(Error::UnknownBehaviour("Primitive divr called with wrong argument count"));
}
let r1 = targs[0].get_real().ok_or(Error::StrategyFailed)?;
let r2 = targs[1].get_real().ok_or(Error::StrategyFailed)?;
Ok(context.factory.real(r1 / r2))
}
pub fn gtr<'a>(context: &MutContext<'a>,
_sargs: Vec<SDefT>,
targs: Vec<ATermRef>,
current: ATermRef)
-> Result<ATermRef> {
if targs.len() < 2 {
return Err(Error::UnknownBehaviour("Primitive gtr called with wrong argument count"));
}
let r1 = targs[0].get_real().ok_or(Error::StrategyFailed)?;
let r2 = targs[1].get_real().ok_or(Error::StrategyFailed)?;
if r1 > r2 {
Ok(current)
} else {
Err(Error::StrategyFailed)
}
}
pub fn mulr<'a>(context: &MutContext<'a>,
_sargs: Vec<SDefT>,
targs: Vec<ATermRef>,
current: ATermRef)
-> Result<ATermRef> {
if targs.len() < 2 {
return Err(Error::UnknownBehaviour("Primitive mulr called with wrong argument count"));
}
let r1 = targs[0].get_real().ok_or(Error::StrategyFailed)?;
let r2 = targs[1].get_real().ok_or(Error::StrategyFailed)?;
Ok(context.factory.real(r1 * r2))
}
pub fn modr<'a>(context: &MutContext<'a>,
_sargs: Vec<SDefT>,
targs: Vec<ATermRef>,
current: ATermRef)
-> Result<ATermRef> {
if targs.len() < 2 {
return Err(Error::UnknownBehaviour("Primitive modr called with wrong argument count"));
}
let r1 = targs[0].get_real().ok_or(Error::StrategyFailed)?;
let r2 = targs[1].get_real().ok_or(Error::StrategyFailed)?;
Ok(context.factory.real(r1 % r2))
}
pub fn subtr<'a>(context: &MutContext<'a>,
_sargs: Vec<SDefT>,
targs: Vec<ATermRef>,
current: ATermRef)
-> Result<ATermRef> {
if targs.len() < 2 {
return Err(Error::UnknownBehaviour("Primitive subtr called with wrong argument count"));
}
let r1 = targs[0].get_real().ok_or(Error::StrategyFailed)?;
let r2 = targs[1].get_real().ok_or(Error::StrategyFailed)?;
Ok(context.factory.real(r1 - r2))
}
pub fn real_to_string<'a>(context: &MutContext<'a>,
_sargs: Vec<SDefT>,
targs: Vec<ATermRef>,
current: ATermRef)