elementary shell behavior: can kick off a foreground process and
handle signals
This commit is contained in:
parent
3b1ae0efd5
commit
99cb9e5a2e
17 changed files with 619 additions and 167 deletions
|
|
@ -10,4 +10,5 @@ edition = "2018"
|
||||||
dirs = "3.0"
|
dirs = "3.0"
|
||||||
nu-ansi-term = "0.47.0"
|
nu-ansi-term = "0.47.0"
|
||||||
reedline = "0.17.0"
|
reedline = "0.17.0"
|
||||||
|
nix = "0.26.2"
|
||||||
|
ctrlc = { version = "3.0", features = ["termination"] }
|
||||||
|
|
@ -498,6 +498,8 @@ Note: this section only tracks the state of incomplete TODO items. Having everyt
|
||||||
- make const all the error messages
|
- make const all the error messages
|
||||||
|
|
||||||
** TODO alpha tasks
|
** TODO alpha tasks
|
||||||
|
- Can pass args to relish scripts (via interpreter)
|
||||||
|
- Can pass args to relish scripts (via command line)
|
||||||
- History length configurable
|
- History length configurable
|
||||||
- Search delim configurable
|
- Search delim configurable
|
||||||
- Escape sequences in strings
|
- Escape sequences in strings
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,6 @@
|
||||||
(elem list)
|
(elem list)
|
||||||
(reverse (cons (reverse list) elem)))
|
(reverse (cons (reverse list) elem)))
|
||||||
|
|
||||||
;; please dont misuse this tool
|
|
||||||
(def set
|
(def set
|
||||||
'sets an existing variable without touching its docstring.
|
'sets an existing variable without touching its docstring.
|
||||||
|
|
||||||
|
|
@ -106,6 +105,7 @@ Returns true if the list contains the element.'
|
||||||
() (split PATH ':'))
|
() (split PATH ':'))
|
||||||
|
|
||||||
(def add-path
|
(def add-path
|
||||||
'adds a directory to PATH'
|
'Takes one argument.
|
||||||
|
adds a directory to PATH'
|
||||||
(path) (set (q PATH)
|
(path) (set (q PATH)
|
||||||
(concat PATH ':' path)))
|
(concat PATH ':' path)))
|
||||||
|
|
@ -14,21 +14,27 @@
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
use nu_ansi_term::{Color, Style};
|
|
||||||
use dirs::home_dir;
|
|
||||||
use relish::ast::{eval, lex, Ctr, Seg, SymTable, run, load_defaults, load_environment};
|
use relish::ast::{eval, lex, Ctr, Seg, SymTable, run, load_defaults, load_environment};
|
||||||
use relish::stdlib::{dynamic_stdlib, static_stdlib};
|
use relish::stdlib::{dynamic_stdlib, static_stdlib};
|
||||||
|
use relish::aux::ShellState;
|
||||||
|
|
||||||
|
use std::cell::RefCell;
|
||||||
|
use std::rc::Rc;
|
||||||
|
use std::borrow::Cow;
|
||||||
|
use std::env;
|
||||||
|
|
||||||
|
use nix::unistd;
|
||||||
|
use nu_ansi_term::{Color, Style};
|
||||||
|
use dirs::home_dir;
|
||||||
use reedline::{
|
use reedline::{
|
||||||
FileBackedHistory, DefaultHinter, DefaultValidator, Reedline, Signal,
|
FileBackedHistory, DefaultHinter, DefaultValidator, Reedline, Signal,
|
||||||
Prompt, PromptEditMode, PromptHistorySearch, PromptHistorySearchStatus,
|
Prompt, PromptEditMode, PromptHistorySearch, PromptHistorySearchStatus,
|
||||||
};
|
};
|
||||||
use std::borrow::Cow;
|
|
||||||
|
|
||||||
|
|
||||||
use std::env;
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct CustomPrompt(String, String, String);
|
pub struct CustomPrompt(String, String, String);
|
||||||
|
|
||||||
impl Prompt for CustomPrompt {
|
impl Prompt for CustomPrompt {
|
||||||
fn render_prompt_left(&self) -> Cow<str> {
|
fn render_prompt_left(&self) -> Cow<str> {
|
||||||
{
|
{
|
||||||
|
|
@ -75,12 +81,20 @@ fn main() {
|
||||||
let hist_file_name = home_dir.clone() + HIST_FILE;
|
let hist_file_name = home_dir.clone() + HIST_FILE;
|
||||||
let cfg_file_name = home_dir + CONFIG_FILE_DEFAULT;
|
let cfg_file_name = home_dir + CONFIG_FILE_DEFAULT;
|
||||||
|
|
||||||
|
let shell_state_bindings = Rc::new(RefCell::from(ShellState {
|
||||||
|
parent_pid: unistd::Pid::from_raw(0),
|
||||||
|
parent_pgid: unistd::Pid::from_raw(0),
|
||||||
|
children: vec![],
|
||||||
|
last_exit_code: 0,
|
||||||
|
}));
|
||||||
|
|
||||||
// setup symtable
|
// setup symtable
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
load_defaults(&mut syms);
|
load_defaults(&mut syms);
|
||||||
load_environment(&mut syms);
|
load_environment(&mut syms);
|
||||||
static_stdlib(&mut syms).unwrap_or_else(|err: String| eprintln!("{}", err));
|
static_stdlib(&mut syms).unwrap_or_else(|err: String| eprintln!("{}", err));
|
||||||
dynamic_stdlib(&mut syms).unwrap_or_else(|err: String| eprintln!("{}", err));
|
// reload this later with the state bindings
|
||||||
|
dynamic_stdlib(&mut syms, None).unwrap_or_else(|err: String| eprintln!("{}", err));
|
||||||
|
|
||||||
// if there are args those are scripts, run them and exit
|
// if there are args those are scripts, run them and exit
|
||||||
if env::args().count() > 1 {
|
if env::args().count() > 1 {
|
||||||
|
|
@ -100,7 +114,7 @@ fn main() {
|
||||||
run(cfg_file.clone(), &mut syms)
|
run(cfg_file.clone(), &mut syms)
|
||||||
.unwrap_or_else(|err: String| eprintln!("failed to load script {}\n{}", cfg_file, err));
|
.unwrap_or_else(|err: String| eprintln!("failed to load script {}\n{}", cfg_file, err));
|
||||||
}
|
}
|
||||||
dynamic_stdlib(&mut syms).unwrap_or_else(|err: String| eprintln!("{}", err));
|
dynamic_stdlib(&mut syms, Some(shell_state_bindings)).unwrap_or_else(|err: String| eprintln!("{}", err));
|
||||||
|
|
||||||
// setup readline
|
// setup readline
|
||||||
let mut rl = Reedline::create();
|
let mut rl = Reedline::create();
|
||||||
|
|
@ -134,7 +148,7 @@ fn main() {
|
||||||
|
|
||||||
Signal::CtrlD => {
|
Signal::CtrlD => {
|
||||||
println!("EOF!");
|
println!("EOF!");
|
||||||
panic!();
|
return
|
||||||
},
|
},
|
||||||
|
|
||||||
Signal::CtrlC => {
|
Signal::CtrlC => {
|
||||||
|
|
|
||||||
13
src/lex.rs
13
src/lex.rs
|
|
@ -206,13 +206,20 @@ fn process(document: &String) -> Result<Box<Seg>, String> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Returns true if token
|
/* Returns true if token
|
||||||
* - is all alphanumeric except dash and underscore
|
* - is all alphanumeric except dash, question, and underscore
|
||||||
*
|
* - equals is also allowed but only for shell command compatibility
|
||||||
* else returns false
|
* else returns false
|
||||||
*/
|
*/
|
||||||
fn tok_is_symbol(token: &str) -> Option<String> {
|
fn tok_is_symbol(token: &str) -> Option<String> {
|
||||||
for t in token.chars() {
|
for t in token.chars() {
|
||||||
if !t.is_alphanumeric() && t != '-' && t != '_' && t != '?' {
|
if !t.is_alphanumeric() &&
|
||||||
|
t != '-' &&
|
||||||
|
t != '_' &&
|
||||||
|
t != '?' &&
|
||||||
|
t != '=' &&
|
||||||
|
t != '.' &&
|
||||||
|
t != '/'
|
||||||
|
{
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,3 +33,8 @@ pub mod ast {
|
||||||
pub mod stdlib {
|
pub mod stdlib {
|
||||||
pub use crate::stl::{dynamic_stdlib, static_stdlib};
|
pub use crate::stl::{dynamic_stdlib, static_stdlib};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub mod aux {
|
||||||
|
pub use crate::stl::posix::args_from_ast;
|
||||||
|
pub use crate::stl::posix::ShellState;
|
||||||
|
}
|
||||||
|
|
|
||||||
53
src/run.rs
53
src/run.rs
|
|
@ -19,7 +19,7 @@ use crate::eval::eval;
|
||||||
use crate::lex::lex;
|
use crate::lex::lex;
|
||||||
use crate::segment::{Ctr, Seg};
|
use crate::segment::{Ctr, Seg};
|
||||||
use crate::sym::{Args, SymTable, Symbol, ValueType};
|
use crate::sym::{Args, SymTable, Symbol, ValueType};
|
||||||
use std::path::Path;
|
use std::path::{Path};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::iter::FromIterator;
|
use std::iter::FromIterator;
|
||||||
use std::env::{vars, var, current_dir};
|
use std::env::{vars, var, current_dir};
|
||||||
|
|
@ -133,6 +133,22 @@ pub fn load_environment(syms: &mut SymTable) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn find_on_path(filename: String) -> Option<String> {
|
||||||
|
let mut prefixes = get_paths();
|
||||||
|
if let Ok(s) = current_dir() {
|
||||||
|
prefixes.push(String::from(s.to_str().unwrap()));
|
||||||
|
}
|
||||||
|
prefixes.push(String::from("/"));
|
||||||
|
for prefix in prefixes {
|
||||||
|
let candidate = Path::new(&prefix.clone()).join(filename.clone());
|
||||||
|
|
||||||
|
if candidate.exists() {
|
||||||
|
return Some(String::from(candidate.to_str().unwrap()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
pub fn run(filename: String, syms: &mut SymTable) -> Result<(), String> {
|
pub fn run(filename: String, syms: &mut SymTable) -> Result<(), String> {
|
||||||
let script_read_res = fs::read_to_string(filename);
|
let script_read_res = fs::read_to_string(filename);
|
||||||
if script_read_res.is_err() {
|
if script_read_res.is_err() {
|
||||||
|
|
@ -149,25 +165,30 @@ pub const RUN_DOCSTRING: &str = "Takes one string argument.
|
||||||
Attempts to find argument in PATH and attempts to call argument";
|
Attempts to find argument in PATH and attempts to call argument";
|
||||||
|
|
||||||
pub fn run_callback(ast: &Seg, syms: &mut SymTable) -> Result<Ctr, String> {
|
pub fn run_callback(ast: &Seg, syms: &mut SymTable) -> Result<Ctr, String> {
|
||||||
let mut prefixes = get_paths();
|
|
||||||
if let Ok(s) = current_dir() {
|
|
||||||
prefixes.push(String::from(s.to_str().unwrap()));
|
|
||||||
}
|
|
||||||
prefixes.push(String::from("/"));
|
|
||||||
if let Ctr::String(ref filename) = *ast.car {
|
if let Ctr::String(ref filename) = *ast.car {
|
||||||
for prefix in prefixes {
|
if filename.ends_with(".rls") {
|
||||||
let candidate = Path::new(&prefix.clone()).join(filename);
|
if let Some(filepath) = find_on_path(filename.to_string()) {
|
||||||
if candidate.exists() {
|
return run(filepath, syms)
|
||||||
if filename.ends_with(".rls") {
|
.and(Ok(Ctr::None))
|
||||||
return run(String::from(candidate.to_str().unwrap()), syms)
|
} else {
|
||||||
.and(Ok(Ctr::None))
|
let canonical_path_res = fs::canonicalize(filename);
|
||||||
} else {
|
if canonical_path_res.is_err() {
|
||||||
return Err("binary called, unimplemented!".to_string())
|
return Err(canonical_path_res
|
||||||
|
.err()
|
||||||
|
.unwrap()
|
||||||
|
.to_string());
|
||||||
}
|
}
|
||||||
|
let canonical_path = canonical_path_res.ok().unwrap();
|
||||||
|
return run(
|
||||||
|
canonical_path
|
||||||
|
.to_string_lossy()
|
||||||
|
.to_string(),
|
||||||
|
syms
|
||||||
|
).and(Ok(Ctr::None))
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return Err("binary called, unimplemented!".to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
Err(format!("file {} not found", filename))
|
|
||||||
} else {
|
} else {
|
||||||
Err("impossible: not a string".to_string())
|
Err("impossible: not a string".to_string())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
16
src/stl.rs
16
src/stl.rs
|
|
@ -19,7 +19,9 @@ use crate::segment::{Ctr, Seg, Type};
|
||||||
use crate::run::{run_callback, RUN_DOCSTRING};
|
use crate::run::{run_callback, RUN_DOCSTRING};
|
||||||
use crate::sym::{Args, SymTable, Symbol, ValueType};
|
use crate::sym::{Args, SymTable, Symbol, ValueType};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
use std::cell::RefCell;
|
||||||
|
|
||||||
|
pub mod posix;
|
||||||
pub mod append;
|
pub mod append;
|
||||||
pub mod boolean;
|
pub mod boolean;
|
||||||
pub mod control;
|
pub mod control;
|
||||||
|
|
@ -613,7 +615,7 @@ pub fn static_stdlib(syms: &mut SymTable) -> Result<(), String> {
|
||||||
/// dynamic_stdlib
|
/// dynamic_stdlib
|
||||||
/// takes configuration data and uses it to insert dynamic
|
/// takes configuration data and uses it to insert dynamic
|
||||||
/// callbacks with configuration into a symtable
|
/// callbacks with configuration into a symtable
|
||||||
pub fn dynamic_stdlib(syms: &mut SymTable) -> Result<(), String> {
|
pub fn dynamic_stdlib(syms: &mut SymTable, shell: Option<Rc<RefCell<posix::ShellState>>>) -> Result<(), String> {
|
||||||
//get CFG_RELISH_ENV from syms
|
//get CFG_RELISH_ENV from syms
|
||||||
let env_cfg_user_form = syms
|
let env_cfg_user_form = syms
|
||||||
.call_symbol(&"CFG_RELISH_ENV".to_string(), &Seg::new(), true)
|
.call_symbol(&"CFG_RELISH_ENV".to_string(), &Seg::new(), true)
|
||||||
|
|
@ -637,5 +639,17 @@ pub fn dynamic_stdlib(syms: &mut SymTable) -> Result<(), String> {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if let Some(shell_state) = shell {
|
||||||
|
let posix_cfg_user_form = syms
|
||||||
|
.call_symbol(&"CFG_RELISH_POSIX".to_string(), &Seg::new(), true)
|
||||||
|
.unwrap_or_else(|_: String| Box::new(Ctr::None))
|
||||||
|
.to_string()
|
||||||
|
.eq("true");
|
||||||
|
|
||||||
|
if posix_cfg_user_form {
|
||||||
|
posix::load_posix_shell(syms, shell_state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
285
src/stl/posix.rs
Normal file
285
src/stl/posix.rs
Normal file
|
|
@ -0,0 +1,285 @@
|
||||||
|
/* relish: versatile lisp shell
|
||||||
|
* Copyright (C) 2021 Aidan Hahn
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
use crate::segment::{Ctr, Seg};
|
||||||
|
use crate::sym::{SymTable, ValueType, Symbol, Args};
|
||||||
|
use crate::eval::eval;
|
||||||
|
use crate::run;
|
||||||
|
use std::collections::VecDeque;
|
||||||
|
use std::cell::RefCell;
|
||||||
|
use std::rc::Rc;
|
||||||
|
use std::process::{Command, Child, Stdio};
|
||||||
|
use nix::unistd;
|
||||||
|
use ctrlc;
|
||||||
|
|
||||||
|
/* WONTDO: flag, switch
|
||||||
|
* Step 6: ? function
|
||||||
|
* Step 7: pipe control flow that circuits across a list of calls hooking stdin to stdout
|
||||||
|
* Step 8.1: load=binary script=call
|
||||||
|
* Step 8.2: call-to-string function
|
||||||
|
* Step 9: ignore job control signals
|
||||||
|
* Step 10: background processes
|
||||||
|
* Step 11: Be able to list all background processes with j function
|
||||||
|
* Step 12: Be able to fg a bg process
|
||||||
|
* Step 13: Be able to bg an fg process (Ctrl Z)
|
||||||
|
* Step 14: changedir
|
||||||
|
* Step 15: pwd
|
||||||
|
* Step 16: circuit casts int to bool automatically
|
||||||
|
* Step 17: Documentation
|
||||||
|
* - list functions and their docstrings
|
||||||
|
* - examples of pipe and circuit
|
||||||
|
* - job control
|
||||||
|
* Step 18: call-with
|
||||||
|
* - let style setting of files as stream targets
|
||||||
|
* - and of course documentation
|
||||||
|
*/
|
||||||
|
|
||||||
|
pub struct ShellState {
|
||||||
|
pub parent_pid: unistd::Pid,
|
||||||
|
pub parent_pgid: unistd::Pid,
|
||||||
|
pub children: Vec<Child>,
|
||||||
|
pub last_exit_code: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn args_from_ast(ast: &Seg, syms: &mut SymTable) -> Vec<String> {
|
||||||
|
let mut args = vec![];
|
||||||
|
|
||||||
|
ast.circuit(&mut |arg_ctr: &Ctr| -> bool {
|
||||||
|
match arg_ctr {
|
||||||
|
Ctr::String(s) => args.push(s.clone()) == (),
|
||||||
|
Ctr::Symbol(ref s) => if !syms.contains_key(s) {
|
||||||
|
args.push(s.clone()) == ()
|
||||||
|
} else {
|
||||||
|
let eval_args = Seg::new();
|
||||||
|
let eval_res = syms.call_symbol(s, &eval_args, false);
|
||||||
|
if let Ok(res_ctr) = eval_res {
|
||||||
|
match *res_ctr {
|
||||||
|
Ctr::Lambda(_) => false,
|
||||||
|
Ctr::Seg(_) => false,
|
||||||
|
Ctr::String(s) => args.push(s.clone()) == (),
|
||||||
|
_ => args.push(res_ctr.to_string()) == (),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
eprintln!("couldnt eval args!") != ()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Ctr::Seg(ref form) => {
|
||||||
|
let eval_res = eval(form, syms);
|
||||||
|
if let Ok(res_ctr) = eval_res {
|
||||||
|
match *res_ctr {
|
||||||
|
Ctr::Lambda(_) => false,
|
||||||
|
Ctr::Seg(_) => false,
|
||||||
|
Ctr::String(s) => args.push(s) == (),
|
||||||
|
_ => args.push(res_ctr.to_string()) == (),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
eprintln!("couldnt eval args!") != ()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Ctr::Lambda(_) => eprintln!("lambda passed as shell parameter") != (),
|
||||||
|
_ => args.push(arg_ctr.to_string()) == (),
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
args
|
||||||
|
}
|
||||||
|
|
||||||
|
fn launch_command(
|
||||||
|
path: String,
|
||||||
|
args: &[String],
|
||||||
|
infd: Stdio,
|
||||||
|
outfd: Stdio,
|
||||||
|
errfd: Stdio,
|
||||||
|
background: bool,
|
||||||
|
state: &mut ShellState
|
||||||
|
) -> Result<(), String> {
|
||||||
|
let newchld = Command::new(path)
|
||||||
|
.args(args)
|
||||||
|
.stdin(infd)
|
||||||
|
.stdout(outfd)
|
||||||
|
.stderr(errfd).spawn();
|
||||||
|
|
||||||
|
if let Ok(child) = newchld {
|
||||||
|
let pid = child.id();
|
||||||
|
state.children.push(child);
|
||||||
|
if !background {
|
||||||
|
make_foreground(pid, state)
|
||||||
|
} else {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Err(format!("couldnt spawn command: {}", newchld.err().unwrap()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// the analogous make_background happens in the app when the user sends it the corresponding signal
|
||||||
|
fn make_foreground(pid: u32, state: &mut ShellState) -> Result<(), String>{
|
||||||
|
for i in &mut state.children {
|
||||||
|
if i.id() == pid {
|
||||||
|
let exit = i.wait().unwrap();
|
||||||
|
if let Some(code) = exit.code() {
|
||||||
|
state.last_exit_code = code;
|
||||||
|
} else {
|
||||||
|
state.last_exit_code = -1;
|
||||||
|
}
|
||||||
|
if let Err(e) = unistd::tcsetpgrp(0, state.parent_pgid) {
|
||||||
|
return Err(format!("error setting terminal: {}!", e));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(pos) = state.children.iter().position(|x| x.id() == pid) {
|
||||||
|
state.children.remove(pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
const LOAD_DOCSTRING: &str = "Calls a binary off disk with given arguments.
|
||||||
|
Arguments may be of any type except lambda. If a symbol is not defined it will be passed as a string.
|
||||||
|
first argument (command name) will be found on path (or an error returned).
|
||||||
|
|
||||||
|
examples:
|
||||||
|
(l ping google.com)
|
||||||
|
(let ((ping-count 4))
|
||||||
|
(l ping -c ping-count google.com))
|
||||||
|
(l emacs -nw (concat HOME '/.relishrc'))
|
||||||
|
";
|
||||||
|
|
||||||
|
|
||||||
|
fn load_callback(ast: &Seg, syms: &mut SymTable, state: &mut ShellState) -> Result<Ctr, String> {
|
||||||
|
if ast.is_empty() {
|
||||||
|
Err("need at least one argument".to_string())
|
||||||
|
} else {
|
||||||
|
let mut args = VecDeque::from(args_from_ast(ast, syms));
|
||||||
|
if let Some(filepath) = run::find_on_path(args.pop_front().unwrap()) {
|
||||||
|
launch_command(
|
||||||
|
filepath,
|
||||||
|
&Vec::from(args.make_contiguous()),
|
||||||
|
Stdio::inherit(),
|
||||||
|
Stdio::inherit(),
|
||||||
|
Stdio::inherit(),
|
||||||
|
false,
|
||||||
|
state,
|
||||||
|
)?;
|
||||||
|
Ok(Ctr::Integer(state.last_exit_code.into()))
|
||||||
|
} else {
|
||||||
|
Err("file not found".to_string())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const Q_DOCSTRING: &str = "returns exit code of last process to be run in posix layer";
|
||||||
|
fn q_callback(_ast: &Seg, _syms: &SymTable, state: &mut ShellState) -> Result<Ctr, String> {
|
||||||
|
Ok(Ctr::Integer(state.last_exit_code.into()))
|
||||||
|
}
|
||||||
|
|
||||||
|
const BG_DOCSTRING: &str = "";
|
||||||
|
fn bg_callback(_ast: &Seg, _syms: &mut SymTable, _state: &mut ShellState) -> Result<Ctr, String> {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn load_posix_shell(syms: &mut SymTable, shell_state: Rc<RefCell<ShellState>>) {
|
||||||
|
let pid = unistd::getpid();
|
||||||
|
let pgid_res = unistd::getpgid(Some(pid));
|
||||||
|
if !pgid_res.is_ok() {
|
||||||
|
panic!("couldn't get pgid")
|
||||||
|
}
|
||||||
|
let pgid = pgid_res.ok().unwrap();
|
||||||
|
|
||||||
|
// one mut borrow
|
||||||
|
{
|
||||||
|
let mut state = shell_state.borrow_mut();
|
||||||
|
state.parent_pid = pid;
|
||||||
|
state.parent_pgid = pgid;
|
||||||
|
}
|
||||||
|
|
||||||
|
let term_pgrp_res = unistd::tcgetpgrp(0);
|
||||||
|
if !term_pgrp_res.is_ok() {
|
||||||
|
panic!("couldn't get terminal's pgrp")
|
||||||
|
}
|
||||||
|
|
||||||
|
let term_owner = term_pgrp_res.ok().unwrap();
|
||||||
|
if pgid != term_owner {
|
||||||
|
nix::sys::signal::kill(
|
||||||
|
term_owner,
|
||||||
|
nix::sys::signal::Signal::SIGTTIN,
|
||||||
|
).expect("couldn't take terminal from owning process")
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Err(e) = unistd::setpgid(
|
||||||
|
unistd::Pid::from_raw(0),
|
||||||
|
unistd::Pid::from_raw(0)
|
||||||
|
) {
|
||||||
|
panic!("couldn't set PGID: {}", e)
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Err(e) = unistd::tcsetpgrp(0, pid) {
|
||||||
|
panic!("couldn't grab terminal: {}", e)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// these clones are needed for callbacks which consume references
|
||||||
|
let bg_ss = shell_state.clone();
|
||||||
|
let q_ss = shell_state.clone();
|
||||||
|
|
||||||
|
syms.insert(
|
||||||
|
String::from("l"),
|
||||||
|
Symbol {
|
||||||
|
name: String::from("load"),
|
||||||
|
args: Args::Infinite,
|
||||||
|
conditional_branches: true,
|
||||||
|
docs: String::from(LOAD_DOCSTRING),
|
||||||
|
value: ValueType::Internal(Rc::new(move |ast: &Seg, symtable: &mut SymTable| -> Result<Ctr, String> {
|
||||||
|
load_callback(ast, symtable, &mut shell_state.borrow_mut())
|
||||||
|
})),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
syms.insert(
|
||||||
|
String::from("bg"),
|
||||||
|
Symbol {
|
||||||
|
name: String::from("background"),
|
||||||
|
args: Args::Infinite,
|
||||||
|
conditional_branches: true,
|
||||||
|
docs: String::from(BG_DOCSTRING),
|
||||||
|
value: ValueType::Internal(Rc::new(move |ast: &Seg, symtable: &mut SymTable| -> Result<Ctr, String> {
|
||||||
|
bg_callback(ast, symtable, &mut bg_ss.clone().borrow_mut())
|
||||||
|
})),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
syms.insert(
|
||||||
|
String::from("?"),
|
||||||
|
Symbol {
|
||||||
|
name: String::from("?"),
|
||||||
|
args: Args::None,
|
||||||
|
conditional_branches: false,
|
||||||
|
docs: String::from(Q_DOCSTRING),
|
||||||
|
value: ValueType::Internal(Rc::new(move |ast: &Seg, symtable: &mut SymTable| -> Result<Ctr, String> {
|
||||||
|
q_callback(ast, symtable, &mut q_ss.clone().borrow_mut())
|
||||||
|
})),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
if let Err(e) = ctrlc::set_handler(move || println!("POSIX layer caught SIG-something")) {
|
||||||
|
eprintln!("WARNING: couldn't set sig handler: {}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -15,8 +15,8 @@ mod lex_tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_bad_symbol() {
|
fn test_bad_symbol() {
|
||||||
let document = String::from("(as/dd)");
|
let document = String::from("(as@dd)");
|
||||||
let output: &str = "Problem lexing document: \"Unparsable token: as/dd\"";
|
let output: &str = "Problem lexing document: \"Unparsable token: as@dd\"";
|
||||||
assert_eq!(lex(&document).err().unwrap(), output.to_string(),);
|
assert_eq!(lex(&document).err().unwrap(), output.to_string(),);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ mod append_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -25,7 +25,7 @@ mod append_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
|
|
@ -42,7 +42,7 @@ mod append_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
|
|
@ -59,7 +59,7 @@ mod append_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
|
|
@ -76,7 +76,7 @@ mod append_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
|
|
@ -93,7 +93,7 @@ mod append_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
|
|
@ -110,7 +110,7 @@ mod append_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
|
|
@ -126,7 +126,7 @@ mod append_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
|
|
@ -144,7 +144,7 @@ mod append_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
|
|
@ -160,7 +160,7 @@ mod append_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
|
|
@ -178,7 +178,7 @@ mod append_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
|
|
@ -198,7 +198,7 @@ mod append_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
eval(&lex(&document.to_string()).unwrap(), &mut syms).unwrap();
|
eval(&lex(&document.to_string()).unwrap(), &mut syms).unwrap();
|
||||||
let ch1 = lex(&check1.to_string()).unwrap();
|
let ch1 = lex(&check1.to_string()).unwrap();
|
||||||
let ch2 = lex(&check2.to_string()).unwrap();
|
let ch2 = lex(&check2.to_string()).unwrap();
|
||||||
|
|
@ -224,7 +224,7 @@ mod append_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
eval(&lex(&document.to_string()).unwrap(), &mut syms).unwrap();
|
eval(&lex(&document.to_string()).unwrap(), &mut syms).unwrap();
|
||||||
let ch1 = lex(&check1.to_string()).unwrap();
|
let ch1 = lex(&check1.to_string()).unwrap();
|
||||||
let ch2 = lex(&check2.to_string()).unwrap();
|
let ch2 = lex(&check2.to_string()).unwrap();
|
||||||
|
|
@ -250,7 +250,7 @@ mod append_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
eval(&lex(&document.to_string()).unwrap(), &mut syms).unwrap();
|
eval(&lex(&document.to_string()).unwrap(), &mut syms).unwrap();
|
||||||
let ch1 = lex(&check1.to_string()).unwrap();
|
let ch1 = lex(&check1.to_string()).unwrap();
|
||||||
let ch2 = lex(&check2.to_string()).unwrap();
|
let ch2 = lex(&check2.to_string()).unwrap();
|
||||||
|
|
@ -276,7 +276,7 @@ mod append_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
eval(&lex(&document.to_string()).unwrap(), &mut syms).unwrap();
|
eval(&lex(&document.to_string()).unwrap(), &mut syms).unwrap();
|
||||||
let ch1 = lex(&check1.to_string()).unwrap();
|
let ch1 = lex(&check1.to_string()).unwrap();
|
||||||
let ch2 = lex(&check2.to_string()).unwrap();
|
let ch2 = lex(&check2.to_string()).unwrap();
|
||||||
|
|
@ -299,7 +299,7 @@ mod append_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
|
|
@ -316,7 +316,7 @@ mod append_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
|
|
@ -333,7 +333,7 @@ mod append_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ mod bool_lib_tests {
|
||||||
let result = "true";
|
let result = "true";
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -23,7 +23,7 @@ mod bool_lib_tests {
|
||||||
let result = "false";
|
let result = "false";
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -38,7 +38,7 @@ mod bool_lib_tests {
|
||||||
let result = "false";
|
let result = "false";
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -53,7 +53,7 @@ mod bool_lib_tests {
|
||||||
let result = "true";
|
let result = "true";
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -68,7 +68,7 @@ mod bool_lib_tests {
|
||||||
let result = "true";
|
let result = "true";
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -83,7 +83,7 @@ mod bool_lib_tests {
|
||||||
let result = "false";
|
let result = "false";
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -98,7 +98,7 @@ mod bool_lib_tests {
|
||||||
let result = "false";
|
let result = "false";
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -115,7 +115,7 @@ mod bool_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
|
|
||||||
let doc_tree = lex(&document.to_string()).unwrap();
|
let doc_tree = lex(&document.to_string()).unwrap();
|
||||||
let change_tree = lex(&change.to_string()).unwrap();
|
let change_tree = lex(&change.to_string()).unwrap();
|
||||||
|
|
@ -154,7 +154,7 @@ mod bool_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
|
|
||||||
let doc_tree = lex(&document.to_string()).unwrap();
|
let doc_tree = lex(&document.to_string()).unwrap();
|
||||||
let change_tree = lex(&change.to_string()).unwrap();
|
let change_tree = lex(&change.to_string()).unwrap();
|
||||||
|
|
@ -187,7 +187,7 @@ mod bool_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
|
|
||||||
let doc_tree = lex(&document.to_string()).unwrap();
|
let doc_tree = lex(&document.to_string()).unwrap();
|
||||||
let change_tree = lex(&change.to_string()).unwrap();
|
let change_tree = lex(&change.to_string()).unwrap();
|
||||||
|
|
@ -217,7 +217,7 @@ mod bool_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
|
|
||||||
if let Ctr::Bool(b) = *eval(&test, &mut syms).unwrap() {
|
if let Ctr::Bool(b) = *eval(&test, &mut syms).unwrap() {
|
||||||
assert!(b)
|
assert!(b)
|
||||||
|
|
@ -233,7 +233,7 @@ mod bool_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
|
|
||||||
if let Ctr::Bool(b) = *eval(&test, &mut syms).unwrap() {
|
if let Ctr::Bool(b) = *eval(&test, &mut syms).unwrap() {
|
||||||
assert!(!b)
|
assert!(!b)
|
||||||
|
|
@ -249,7 +249,7 @@ mod bool_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
|
|
||||||
if let Ctr::Bool(b) = *eval(&test, &mut syms).unwrap() {
|
if let Ctr::Bool(b) = *eval(&test, &mut syms).unwrap() {
|
||||||
assert!(!b)
|
assert!(!b)
|
||||||
|
|
@ -265,7 +265,7 @@ mod bool_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
|
|
||||||
if let Ctr::Bool(b) = *eval(&test, &mut syms).unwrap() {
|
if let Ctr::Bool(b) = *eval(&test, &mut syms).unwrap() {
|
||||||
assert!(!b)
|
assert!(!b)
|
||||||
|
|
@ -281,7 +281,7 @@ mod bool_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
|
|
||||||
if let Ctr::Bool(b) = *eval(&test, &mut syms).unwrap() {
|
if let Ctr::Bool(b) = *eval(&test, &mut syms).unwrap() {
|
||||||
assert!(b)
|
assert!(b)
|
||||||
|
|
@ -297,7 +297,7 @@ mod bool_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
|
|
||||||
if let Ctr::Bool(b) = *eval(&test, &mut syms).unwrap() {
|
if let Ctr::Bool(b) = *eval(&test, &mut syms).unwrap() {
|
||||||
assert!(b)
|
assert!(b)
|
||||||
|
|
@ -313,7 +313,7 @@ mod bool_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
|
|
||||||
if let Ctr::Bool(b) = *eval(&test, &mut syms).unwrap() {
|
if let Ctr::Bool(b) = *eval(&test, &mut syms).unwrap() {
|
||||||
assert!(!b)
|
assert!(!b)
|
||||||
|
|
@ -329,7 +329,7 @@ mod bool_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
|
|
||||||
if let Ctr::Bool(b) = *eval(&test, &mut syms).unwrap() {
|
if let Ctr::Bool(b) = *eval(&test, &mut syms).unwrap() {
|
||||||
assert!(b)
|
assert!(b)
|
||||||
|
|
@ -345,7 +345,7 @@ mod bool_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
|
|
||||||
if let Ctr::Bool(b) = *eval(&test, &mut syms).unwrap() {
|
if let Ctr::Bool(b) = *eval(&test, &mut syms).unwrap() {
|
||||||
assert!(!b)
|
assert!(!b)
|
||||||
|
|
@ -361,7 +361,7 @@ mod bool_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
|
|
||||||
if let Ctr::Bool(b) = *eval(&test, &mut syms).unwrap() {
|
if let Ctr::Bool(b) = *eval(&test, &mut syms).unwrap() {
|
||||||
assert!(b)
|
assert!(b)
|
||||||
|
|
@ -377,7 +377,7 @@ mod bool_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
|
|
||||||
if let Ctr::Bool(b) = *eval(&test, &mut syms).unwrap() {
|
if let Ctr::Bool(b) = *eval(&test, &mut syms).unwrap() {
|
||||||
assert!(!b)
|
assert!(!b)
|
||||||
|
|
@ -393,7 +393,7 @@ mod bool_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
|
|
||||||
if let Ctr::Bool(b) = *eval(&test, &mut syms).unwrap() {
|
if let Ctr::Bool(b) = *eval(&test, &mut syms).unwrap() {
|
||||||
assert!(b)
|
assert!(b)
|
||||||
|
|
@ -409,7 +409,7 @@ mod bool_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
|
|
||||||
if let Ctr::Bool(b) = *eval(&test, &mut syms).unwrap() {
|
if let Ctr::Bool(b) = *eval(&test, &mut syms).unwrap() {
|
||||||
assert!(!b)
|
assert!(!b)
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ mod control_lib_tests {
|
||||||
let result = 1;
|
let result = 1;
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -23,7 +23,7 @@ mod control_lib_tests {
|
||||||
let result = 2;
|
let result = 2;
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -38,7 +38,7 @@ mod control_lib_tests {
|
||||||
let result = "(1)";
|
let result = "(1)";
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -56,7 +56,7 @@ mod control_lib_tests {
|
||||||
let result = "('1' '2')";
|
let result = "('1' '2')";
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -75,7 +75,7 @@ mod control_lib_tests {
|
||||||
let result = "('hello world')";
|
let result = "('hello world')";
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
eval(&lex(&document1.to_string()).unwrap(), &mut syms).unwrap();
|
eval(&lex(&document1.to_string()).unwrap(), &mut syms).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document2.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document2.to_string()).unwrap(), &mut syms)
|
||||||
|
|
@ -91,7 +91,7 @@ mod control_lib_tests {
|
||||||
let result = "('1' '2')";
|
let result = "('1' '2')";
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -111,7 +111,7 @@ mod control_lib_tests {
|
||||||
let result = "('1' '2' '3')";
|
let result = "('1' '2' '3')";
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -140,7 +140,7 @@ mod control_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
|
|
||||||
eval(&switch_tree, &mut syms).unwrap();
|
eval(&switch_tree, &mut syms).unwrap();
|
||||||
eval(&while_tree, &mut syms).unwrap();
|
eval(&while_tree, &mut syms).unwrap();
|
||||||
|
|
@ -167,7 +167,7 @@ mod control_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
|
|
||||||
eval(&switch_tree, &mut syms).unwrap();
|
eval(&switch_tree, &mut syms).unwrap();
|
||||||
eval(&while_tree, &mut syms).unwrap();
|
eval(&while_tree, &mut syms).unwrap();
|
||||||
|
|
@ -194,7 +194,7 @@ mod control_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
|
|
||||||
eval(&another_tree, &mut syms).unwrap();
|
eval(&another_tree, &mut syms).unwrap();
|
||||||
eval(&switch_tree, &mut syms).unwrap();
|
eval(&switch_tree, &mut syms).unwrap();
|
||||||
|
|
@ -212,7 +212,7 @@ mod control_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
|
|
||||||
eval(&doc_tree, &mut syms).unwrap();
|
eval(&doc_tree, &mut syms).unwrap();
|
||||||
let res = eval(&test_tree, &mut syms);
|
let res = eval(&test_tree, &mut syms);
|
||||||
|
|
@ -229,7 +229,7 @@ mod control_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
|
|
||||||
eval(&doc_tree, &mut syms).unwrap();
|
eval(&doc_tree, &mut syms).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ mod decl_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
|
|
||||||
eval(&lex(&doc1.to_string()).unwrap(), &mut syms).unwrap();
|
eval(&lex(&doc1.to_string()).unwrap(), &mut syms).unwrap();
|
||||||
let res = *eval(&lex(&doc2.to_string()).unwrap(), &mut syms).unwrap();
|
let res = *eval(&lex(&doc2.to_string()).unwrap(), &mut syms).unwrap();
|
||||||
|
|
@ -25,7 +25,7 @@ mod decl_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
|
|
||||||
eval(&lex(&doc1.to_string()).unwrap(), &mut syms).unwrap();
|
eval(&lex(&doc1.to_string()).unwrap(), &mut syms).unwrap();
|
||||||
let res = *eval(&lex(&doc2.to_string()).unwrap(), &mut syms).unwrap();
|
let res = *eval(&lex(&doc2.to_string()).unwrap(), &mut syms).unwrap();
|
||||||
|
|
@ -40,7 +40,7 @@ mod decl_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
|
|
||||||
eval(&lex(&doc1.to_string()).unwrap(), &mut syms).unwrap();
|
eval(&lex(&doc1.to_string()).unwrap(), &mut syms).unwrap();
|
||||||
let res = *eval(&lex(&doc2.to_string()).unwrap(), &mut syms).unwrap();
|
let res = *eval(&lex(&doc2.to_string()).unwrap(), &mut syms).unwrap();
|
||||||
|
|
@ -56,7 +56,7 @@ mod decl_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
|
|
||||||
eval(&lex(&doc1.to_string()).unwrap(), &mut syms).unwrap();
|
eval(&lex(&doc1.to_string()).unwrap(), &mut syms).unwrap();
|
||||||
eval(&lex(&doc2.to_string()).unwrap(), &mut syms).unwrap();
|
eval(&lex(&doc2.to_string()).unwrap(), &mut syms).unwrap();
|
||||||
|
|
@ -72,7 +72,7 @@ mod decl_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
|
|
||||||
eval(&lex(&doc1.to_string()).unwrap(), &mut syms).unwrap();
|
eval(&lex(&doc1.to_string()).unwrap(), &mut syms).unwrap();
|
||||||
eval(&lex(&doc2.to_string()).unwrap(), &mut syms).unwrap();
|
eval(&lex(&doc2.to_string()).unwrap(), &mut syms).unwrap();
|
||||||
|
|
@ -98,7 +98,7 @@ mod decl_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
|
|
||||||
eval(&lex(&doc1.to_string()).unwrap(), &mut syms).unwrap();
|
eval(&lex(&doc1.to_string()).unwrap(), &mut syms).unwrap();
|
||||||
eval(&lex(&doc2.to_string()).unwrap(), &mut syms).unwrap();
|
eval(&lex(&doc2.to_string()).unwrap(), &mut syms).unwrap();
|
||||||
|
|
@ -117,7 +117,7 @@ mod decl_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
|
|
||||||
eval(&lex(&doc1.to_string()).unwrap(), &mut syms).unwrap();
|
eval(&lex(&doc1.to_string()).unwrap(), &mut syms).unwrap();
|
||||||
eval(&lex(&doc2.to_string()).unwrap(), &mut syms).unwrap();
|
eval(&lex(&doc2.to_string()).unwrap(), &mut syms).unwrap();
|
||||||
|
|
@ -136,7 +136,7 @@ mod decl_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
|
|
||||||
eval(&lex(&doc1.to_string()).unwrap(), &mut syms).unwrap();
|
eval(&lex(&doc1.to_string()).unwrap(), &mut syms).unwrap();
|
||||||
let res = *eval(&lex(&doc2.to_string()).unwrap(), &mut syms).unwrap();
|
let res = *eval(&lex(&doc2.to_string()).unwrap(), &mut syms).unwrap();
|
||||||
|
|
@ -150,7 +150,7 @@ mod decl_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
|
|
||||||
let def_tree = lex(&doc1.to_string()).unwrap();
|
let def_tree = lex(&doc1.to_string()).unwrap();
|
||||||
let set_tree = lex(&doc2.to_string()).unwrap();
|
let set_tree = lex(&doc2.to_string()).unwrap();
|
||||||
|
|
@ -165,7 +165,7 @@ mod decl_lib_tests {
|
||||||
let doc = "(set? test)";
|
let doc = "(set? test)";
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
let set_tree = lex(&doc.to_string()).unwrap();
|
let set_tree = lex(&doc.to_string()).unwrap();
|
||||||
if let Ctr::Bool(b) = *eval(&set_tree, &mut syms).unwrap() {
|
if let Ctr::Bool(b) = *eval(&set_tree, &mut syms).unwrap() {
|
||||||
assert!(!b);
|
assert!(!b);
|
||||||
|
|
@ -179,7 +179,7 @@ mod decl_lib_tests {
|
||||||
let doc3 = "t";
|
let doc3 = "t";
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
let set_tree = lex(&doc1.to_string()).unwrap();
|
let set_tree = lex(&doc1.to_string()).unwrap();
|
||||||
let env_tree = lex(&doc2.to_string()).unwrap();
|
let env_tree = lex(&doc2.to_string()).unwrap();
|
||||||
let tst_tree = lex(&doc3.to_string()).unwrap();
|
let tst_tree = lex(&doc3.to_string()).unwrap();
|
||||||
|
|
@ -194,7 +194,7 @@ mod decl_lib_tests {
|
||||||
let result = "(add 1 2)";
|
let result = "(add 1 2)";
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -211,7 +211,7 @@ mod decl_lib_tests {
|
||||||
let result = "3";
|
let result = "3";
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -226,7 +226,7 @@ mod decl_lib_tests {
|
||||||
let result = "(1 2 3)";
|
let result = "(1 2 3)";
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -236,7 +236,7 @@ mod decl_lib_tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* THIS TEST REMOVED BECAUSE EVAL SHOULDNT ARBITRARILY DO THINGS TWICE
|
/* THIS TEST REMOVED BECAUSE EVAL SHOULDNT ARBITRARILY DO THINGS TWICE
|
||||||
* KEPT FOR REFERENCE PURPOSES JUST IN CASE
|
* KEPT FOR REFERENCE PURPOSES JUST IN CASE.
|
||||||
#[test]
|
#[test]
|
||||||
fn test_eval_var_deref() {
|
fn test_eval_var_deref() {
|
||||||
let def1 = "(def one '' 1)";
|
let def1 = "(def one '' 1)";
|
||||||
|
|
@ -261,7 +261,7 @@ mod decl_lib_tests {
|
||||||
let document = "(lambda (x y) (add x y))";
|
let document = "(lambda (x y) (add x y))";
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -275,7 +275,7 @@ mod decl_lib_tests {
|
||||||
let document = "(lambda () (add 1 2))";
|
let document = "(lambda () (add 1 2))";
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -289,7 +289,7 @@ mod decl_lib_tests {
|
||||||
let document = "((lambda (x y) (add x y)) 1 2)";
|
let document = "((lambda (x y) (add x y)) 1 2)";
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
let it = *eval(
|
let it = *eval(
|
||||||
&lex(&document.to_string()).unwrap(),
|
&lex(&document.to_string()).unwrap(),
|
||||||
&mut syms).unwrap();
|
&mut syms).unwrap();
|
||||||
|
|
@ -306,7 +306,7 @@ mod decl_lib_tests {
|
||||||
(adder 1 2))";
|
(adder 1 2))";
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
let it = *eval(
|
let it = *eval(
|
||||||
&lex(&document.to_string()).unwrap(),
|
&lex(&document.to_string()).unwrap(),
|
||||||
&mut syms).unwrap();
|
&mut syms).unwrap();
|
||||||
|
|
@ -324,7 +324,7 @@ mod decl_lib_tests {
|
||||||
(adder 1 2))";
|
(adder 1 2))";
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
let it = *eval(
|
let it = *eval(
|
||||||
&lex(&document.to_string()).unwrap(),
|
&lex(&document.to_string()).unwrap(),
|
||||||
&mut syms).unwrap();
|
&mut syms).unwrap();
|
||||||
|
|
@ -343,7 +343,7 @@ mod decl_lib_tests {
|
||||||
(appl adder 2))";
|
(appl adder 2))";
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
let it = *eval(
|
let it = *eval(
|
||||||
&lex(&document.to_string()).unwrap(),
|
&lex(&document.to_string()).unwrap(),
|
||||||
&mut syms).unwrap();
|
&mut syms).unwrap();
|
||||||
|
|
@ -361,7 +361,7 @@ mod decl_lib_tests {
|
||||||
let document = "(get-doc (q help))";
|
let document = "(get-doc (q help))";
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
let _ = *eval(
|
let _ = *eval(
|
||||||
&lex(&highly_inadvisable.to_string()).unwrap(),
|
&lex(&highly_inadvisable.to_string()).unwrap(),
|
||||||
&mut syms).unwrap();
|
&mut syms).unwrap();
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ mod math_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -25,7 +25,7 @@ mod math_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -41,7 +41,7 @@ mod math_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -57,7 +57,7 @@ mod math_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -73,7 +73,7 @@ mod math_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -89,7 +89,7 @@ mod math_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -105,7 +105,7 @@ mod math_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -121,7 +121,7 @@ mod math_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -137,7 +137,7 @@ mod math_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -153,7 +153,7 @@ mod math_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -169,7 +169,7 @@ mod math_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -185,7 +185,7 @@ mod math_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -201,7 +201,7 @@ mod math_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -220,7 +220,7 @@ mod math_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
let _ = *eval(&lex(&document.to_string()).unwrap(), &mut syms).unwrap();
|
let _ = *eval(&lex(&document.to_string()).unwrap(), &mut syms).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&check1.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&check1.to_string()).unwrap(), &mut syms)
|
||||||
|
|
@ -244,7 +244,7 @@ mod math_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
let _ = *eval(&lex(&document.to_string()).unwrap(), &mut syms).unwrap();
|
let _ = *eval(&lex(&document.to_string()).unwrap(), &mut syms).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&check1.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&check1.to_string()).unwrap(), &mut syms)
|
||||||
|
|
@ -261,7 +261,7 @@ mod math_lib_tests {
|
||||||
let result1 = "3";
|
let result1 = "3";
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
let _ = *eval(&lex(&document.to_string()).unwrap(), &mut syms).unwrap();
|
let _ = *eval(&lex(&document.to_string()).unwrap(), &mut syms).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&check1.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&check1.to_string()).unwrap(), &mut syms)
|
||||||
|
|
@ -279,7 +279,7 @@ mod math_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
let _ = *eval(&lex(&document.to_string()).unwrap(), &mut syms).unwrap();
|
let _ = *eval(&lex(&document.to_string()).unwrap(), &mut syms).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&check1.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&check1.to_string()).unwrap(), &mut syms)
|
||||||
|
|
@ -296,7 +296,7 @@ mod math_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -312,7 +312,7 @@ mod math_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -328,7 +328,7 @@ mod math_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -344,7 +344,7 @@ mod math_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -360,7 +360,7 @@ mod math_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -376,7 +376,7 @@ mod math_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -392,7 +392,7 @@ mod math_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -408,7 +408,7 @@ mod math_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -424,7 +424,7 @@ mod math_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -440,7 +440,7 @@ mod math_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -456,7 +456,7 @@ mod math_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -472,7 +472,7 @@ mod math_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -488,7 +488,7 @@ mod math_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -504,7 +504,7 @@ mod math_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -520,7 +520,7 @@ mod math_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -536,7 +536,7 @@ mod math_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -552,7 +552,7 @@ mod math_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -568,7 +568,7 @@ mod math_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -584,7 +584,7 @@ mod math_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -600,7 +600,7 @@ mod math_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -617,7 +617,7 @@ mod math_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
|
|
||||||
let doc_tree = lex(&document.to_string()).unwrap();
|
let doc_tree = lex(&document.to_string()).unwrap();
|
||||||
let change_tree = lex(&change.to_string()).unwrap();
|
let change_tree = lex(&change.to_string()).unwrap();
|
||||||
|
|
@ -656,7 +656,7 @@ mod math_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
|
|
||||||
let doc_tree = lex(&document.to_string()).unwrap();
|
let doc_tree = lex(&document.to_string()).unwrap();
|
||||||
let change_tree = lex(&change.to_string()).unwrap();
|
let change_tree = lex(&change.to_string()).unwrap();
|
||||||
|
|
@ -689,7 +689,7 @@ mod math_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
|
|
||||||
let doc_tree = lex(&document.to_string()).unwrap();
|
let doc_tree = lex(&document.to_string()).unwrap();
|
||||||
let change_tree = lex(&change.to_string()).unwrap();
|
let change_tree = lex(&change.to_string()).unwrap();
|
||||||
|
|
@ -720,7 +720,7 @@ mod math_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
|
|
||||||
let doc_tree = lex(&document.to_string()).unwrap();
|
let doc_tree = lex(&document.to_string()).unwrap();
|
||||||
let change_tree = lex(&change.to_string()).unwrap();
|
let change_tree = lex(&change.to_string()).unwrap();
|
||||||
|
|
@ -759,7 +759,7 @@ mod math_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
|
|
||||||
let doc_tree = lex(&document.to_string()).unwrap();
|
let doc_tree = lex(&document.to_string()).unwrap();
|
||||||
let change_tree = lex(&change.to_string()).unwrap();
|
let change_tree = lex(&change.to_string()).unwrap();
|
||||||
|
|
@ -792,7 +792,7 @@ mod math_lib_tests {
|
||||||
|
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
|
|
||||||
let doc_tree = lex(&document.to_string()).unwrap();
|
let doc_tree = lex(&document.to_string()).unwrap();
|
||||||
let change_tree = lex(&change.to_string()).unwrap();
|
let change_tree = lex(&change.to_string()).unwrap();
|
||||||
|
|
|
||||||
103
tests/test_lib_posix.rs
Normal file
103
tests/test_lib_posix.rs
Normal file
|
|
@ -0,0 +1,103 @@
|
||||||
|
mod posix_tests {
|
||||||
|
use relish::aux::args_from_ast;
|
||||||
|
use relish::stdlib::{dynamic_stdlib, static_stdlib};
|
||||||
|
use relish::ast::{lex, eval, SymTable};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_cmd_singlet() {
|
||||||
|
let document = "(binary)";
|
||||||
|
let result = vec!["binary"];
|
||||||
|
|
||||||
|
let mut syms = SymTable::new();
|
||||||
|
static_stdlib(&mut syms).unwrap();
|
||||||
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
|
|
||||||
|
if let Ok(ref s) = lex(&document.to_string()) {
|
||||||
|
assert_eq!(
|
||||||
|
args_from_ast(s, &mut syms),
|
||||||
|
result
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
panic!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_cmd_list() {
|
||||||
|
let document = "(binary --flag=1 122 'yeet' true)";
|
||||||
|
let result = vec!["binary", "--flag=1", "122", "yeet", "true"];
|
||||||
|
|
||||||
|
let mut syms = SymTable::new();
|
||||||
|
static_stdlib(&mut syms).unwrap();
|
||||||
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
|
|
||||||
|
if let Ok(ref s) = lex(&document.to_string()) {
|
||||||
|
assert_eq!(
|
||||||
|
args_from_ast(s, &mut syms),
|
||||||
|
result
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
panic!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_cmd_syms_undef() {
|
||||||
|
let document = "(binary --flag=1 122 'yeet' true syms)";
|
||||||
|
let result = vec!["binary", "--flag=1", "122", "yeet", "true", "syms"];
|
||||||
|
|
||||||
|
let mut syms = SymTable::new();
|
||||||
|
static_stdlib(&mut syms).unwrap();
|
||||||
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
|
|
||||||
|
if let Ok(ref s) = lex(&document.to_string()) {
|
||||||
|
assert_eq!(
|
||||||
|
args_from_ast(s, &mut syms),
|
||||||
|
result
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
panic!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_cmd_syms_unwrap_simple() {
|
||||||
|
let decl = "(def syms '' 1)";
|
||||||
|
let document = "(binary --flag=1 122 'yeet' true syms)";
|
||||||
|
let result = vec!["binary", "--flag=1", "122", "yeet", "true", "1"];
|
||||||
|
|
||||||
|
let mut syms = SymTable::new();
|
||||||
|
static_stdlib(&mut syms).unwrap();
|
||||||
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
|
|
||||||
|
eval(&lex(&decl.to_string()).unwrap(), &mut syms).unwrap();
|
||||||
|
|
||||||
|
if let Ok(ref s) = lex(&document.to_string()) {
|
||||||
|
assert_eq!(
|
||||||
|
args_from_ast(s, &mut syms),
|
||||||
|
result
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
panic!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_cmd_syms_unwrap_eval() {
|
||||||
|
let document = "(binary --flag=1 122 'yeet' true (add 1 2))";
|
||||||
|
let result = vec!["binary", "--flag=1", "122", "yeet", "true", "3"];
|
||||||
|
|
||||||
|
let mut syms = SymTable::new();
|
||||||
|
static_stdlib(&mut syms).unwrap();
|
||||||
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
|
|
||||||
|
if let Ok(ref s) = lex(&document.to_string()) {
|
||||||
|
assert_eq!(
|
||||||
|
args_from_ast(s, &mut syms),
|
||||||
|
result
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
panic!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -8,7 +8,7 @@ mod str_lib_tests {
|
||||||
let result = "'test'";
|
let result = "'test'";
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -23,7 +23,7 @@ mod str_lib_tests {
|
||||||
let result = "'test123'";
|
let result = "'test123'";
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -38,7 +38,7 @@ mod str_lib_tests {
|
||||||
let result = "''";
|
let result = "''";
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -53,7 +53,7 @@ mod str_lib_tests {
|
||||||
let result = 4;
|
let result = 4;
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -68,7 +68,7 @@ mod str_lib_tests {
|
||||||
let result = 4;
|
let result = 4;
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -83,7 +83,7 @@ mod str_lib_tests {
|
||||||
let result = 4;
|
let result = 4;
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -98,7 +98,7 @@ mod str_lib_tests {
|
||||||
let result = 7;
|
let result = 7;
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -113,7 +113,7 @@ mod str_lib_tests {
|
||||||
let result = 4;
|
let result = 4;
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -128,7 +128,7 @@ mod str_lib_tests {
|
||||||
let result = "'4'";
|
let result = "'4'";
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -143,7 +143,7 @@ mod str_lib_tests {
|
||||||
let result = "'(1 2 3)'";
|
let result = "'(1 2 3)'";
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -158,7 +158,7 @@ mod str_lib_tests {
|
||||||
let result = "true";
|
let result = "true";
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -173,7 +173,7 @@ mod str_lib_tests {
|
||||||
let result = "false";
|
let result = "false";
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -188,7 +188,7 @@ mod str_lib_tests {
|
||||||
let result = "('one' 'two' 'three')";
|
let result = "('one' 'two' 'three')";
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -203,7 +203,7 @@ mod str_lib_tests {
|
||||||
let result = "('one' 'two' 'three')";
|
let result = "('one' 'two' 'three')";
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -218,7 +218,7 @@ mod str_lib_tests {
|
||||||
let result = "('one.two.three')";
|
let result = "('one.two.three')";
|
||||||
let mut syms = SymTable::new();
|
let mut syms = SymTable::new();
|
||||||
static_stdlib(&mut syms).unwrap();
|
static_stdlib(&mut syms).unwrap();
|
||||||
dynamic_stdlib(&mut syms).unwrap();
|
dynamic_stdlib(&mut syms, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue