Skip to content

Commit

Permalink
handle warnings related to Box Vec
Browse files Browse the repository at this point in the history
  • Loading branch information
tiye committed Nov 29, 2021
1 parent e8481b5 commit 7f474dc
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 54 deletions.
13 changes: 3 additions & 10 deletions src/bin/injection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ pub fn call_dylib_edn_fn(xs: &CalcitItems, call_stack: &CallStackList) -> Result
for p in ps {
real_args = real_args.push(edn_to_calcit(&p));
}
let r = runner::run_fn(&real_args, scope, args.to_owned(), body, def_ns.to_owned(), &copied_stack);
let r = runner::run_fn(&real_args, scope, args, body, def_ns.to_owned(), &copied_stack);
match r {
Ok(ret) => calcit_to_edn(&ret),
Err(e) => {
Expand Down Expand Up @@ -229,7 +229,7 @@ pub fn blocking_dylib_edn_fn(xs: &CalcitItems, call_stack: &CallStackList) -> Re
for p in ps {
real_args = real_args.push(edn_to_calcit(&p));
}
let r = runner::run_fn(&real_args, scope, args.to_owned(), body, def_ns.to_owned(), &copied_stack.clone());
let r = runner::run_fn(&real_args, scope, args, body, def_ns.to_owned(), &copied_stack.clone());
match r {
Ok(ret) => calcit_to_edn(&ret),
Err(e) => {
Expand Down Expand Up @@ -267,14 +267,7 @@ pub fn on_ctrl_c(xs: &CalcitItems, call_stack: &CallStackList) -> Result<Calcit,
def_ns, scope, args, body, ..
} = cb.as_ref()
{
if let Err(e) = runner::run_fn(
&FingerList::new_empty(),
scope,
args.to_owned(),
body,
def_ns.to_owned(),
&copied_stack,
) {
if let Err(e) = runner::run_fn(&FingerList::new_empty(), scope, args, body, def_ns.to_owned(), &copied_stack) {
println!("error: {}", e);
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/builtins/lists.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ pub fn foldl(xs: &CalcitItems, call_stack: &CallStackList) -> Result<Calcit, Cal
) => {
for x in &**xs {
let values = FingerList::from(&[Size(ret), Size(x.to_owned())]);
ret = runner::run_fn(&values, scope, args.to_owned(), body, def_ns.to_owned(), call_stack)?;
ret = runner::run_fn(&values, scope, args, body, def_ns.to_owned(), call_stack)?;
}
Ok(ret)
}
Expand All @@ -211,7 +211,7 @@ pub fn foldl(xs: &CalcitItems, call_stack: &CallStackList) -> Result<Calcit, Cal
) => {
for x in xs {
let values = FingerList::from(&[Size(ret), Size(x.to_owned())]);
ret = runner::run_fn(&values, scope, args.to_owned(), body, def_ns.to_owned(), call_stack)?;
ret = runner::run_fn(&values, scope, args, body, def_ns.to_owned(), call_stack)?;
}
Ok(ret)
}
Expand All @@ -234,7 +234,7 @@ pub fn foldl(xs: &CalcitItems, call_stack: &CallStackList) -> Result<Calcit, Cal
Size(ret),
Size(Calcit::List(Box::new(FingerList::from(&[Size(k.to_owned()), Size(x.to_owned())])))),
]);
ret = runner::run_fn(&values, scope, args.to_owned(), body, def_ns.to_owned(), call_stack)?;
ret = runner::run_fn(&values, scope, args, body, def_ns.to_owned(), call_stack)?;
}
Ok(ret)
}
Expand Down Expand Up @@ -283,7 +283,7 @@ pub fn foldl_shortcut(xs: &CalcitItems, call_stack: &CallStackList) -> Result<Ca
let mut state = acc.to_owned();
for x in &**xs {
let values = FingerList::from(&[Size(state), Size(x.to_owned())]);
let pair = runner::run_fn(&values, scope, args.to_owned(), body, def_ns.to_owned(), call_stack)?;
let pair = runner::run_fn(&values, scope, args, body, def_ns.to_owned(), call_stack)?;
match pair {
Calcit::Tuple(x0, x1) => match &*x0 {
Calcit::Bool(b) => {
Expand Down Expand Up @@ -320,7 +320,7 @@ pub fn foldl_shortcut(xs: &CalcitItems, call_stack: &CallStackList) -> Result<Ca
let mut state = acc.to_owned();
for x in xs {
let values = FingerList::from(&[Size(state), Size(x.to_owned())]);
let pair = runner::run_fn(&values, scope, args.to_owned(), body, def_ns.to_owned(), call_stack)?;
let pair = runner::run_fn(&values, scope, args, body, def_ns.to_owned(), call_stack)?;
match pair {
Calcit::Tuple(x0, x1) => match &*x0 {
Calcit::Bool(b) => {
Expand Down Expand Up @@ -360,7 +360,7 @@ pub fn foldl_shortcut(xs: &CalcitItems, call_stack: &CallStackList) -> Result<Ca
Size(state),
Size(Calcit::List(Box::new(FingerList::from(&[Size(k.to_owned()), Size(x.to_owned())])))),
]);
let pair = runner::run_fn(&values, scope, args.to_owned(), body, def_ns.to_owned(), call_stack)?;
let pair = runner::run_fn(&values, scope, args, body, def_ns.to_owned(), call_stack)?;
match pair {
Calcit::Tuple(x0, x1) => match &*x0 {
Calcit::Bool(b) => {
Expand Down Expand Up @@ -420,7 +420,7 @@ pub fn foldr_shortcut(xs: &CalcitItems, call_stack: &CallStackList) -> Result<Ca
for i in 0..size {
let x = xs[size - 1 - i].to_owned();
let values = FingerList::from(&[Size(state), Size(x)]);
let pair = runner::run_fn(&values, scope, args.to_owned(), body, def_ns.to_owned(), call_stack)?;
let pair = runner::run_fn(&values, scope, args, body, def_ns.to_owned(), call_stack)?;
match pair {
Calcit::Tuple(x0, x1) => match &*x0 {
Calcit::Bool(b) => {
Expand Down Expand Up @@ -474,7 +474,7 @@ pub fn sort(xs: &CalcitItems, call_stack: &CallStackList) -> Result<Calcit, Calc
let mut xs2: Vec<&Calcit> = xs.into_iter().collect::<Vec<&Calcit>>();
xs2.sort_by(|a, b| -> Ordering {
let values = FingerList::from(&[Size((*a).to_owned()), Size((*b).to_owned())]);
let v = runner::run_fn(&values, scope, args.to_owned(), body, def_ns.to_owned(), call_stack);
let v = runner::run_fn(&values, scope, args, body, def_ns.to_owned(), call_stack);
match v {
Ok(Calcit::Number(x)) if x < 0.0 => Ordering::Less,
Ok(Calcit::Number(x)) if x == 0.0 => Ordering::Equal,
Expand Down
2 changes: 1 addition & 1 deletion src/builtins/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ pub fn invoke_method(name: &str, invoke_args: &CalcitItems, call_stack: &CallSta
// dirty copy...
Calcit::Fn {
def_ns, scope, args, body, ..
} => runner::run_fn(&method_args, scope, args.to_owned(), body, def_ns.to_owned(), call_stack),
} => runner::run_fn(&method_args, scope, args, body, def_ns.to_owned(), call_stack),
Calcit::Proc(proc) => builtins::handle_proc(proc, &method_args, call_stack),
Calcit::Syntax(syn, _ns) => Err(CalcitErr::use_msg_stack(
format!("cannot get syntax here since instance is always evaluated, got: {}", syn),
Expand Down
2 changes: 1 addition & 1 deletion src/builtins/refs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn modify_ref(path: Arc<str>, v: Calcit, call_stack: &CallStackList) -> Result<(
def_ns, scope, args, body, ..
} => {
let values = FingerList::from(&[Size(v.to_owned()), Size(prev.to_owned())]);
runner::run_fn(&values, scope, args.to_owned(), body, def_ns.to_owned(), call_stack)?;
runner::run_fn(&values, scope, args, body, def_ns.to_owned(), call_stack)?;
}
a => {
return Err(CalcitErr::use_msg_stack(
Expand Down
12 changes: 6 additions & 6 deletions src/builtins/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub fn defmacro(expr: &CalcitItems, _scope: &CalcitScope, def_ns: Arc<str>) -> R
}
}

pub fn get_raw_args(args: &CalcitItems) -> Result<Box<Vec<Arc<str>>>, String> {
pub fn get_raw_args(args: &CalcitItems) -> Result<Vec<Arc<str>>, String> {
let mut xs: Vec<Arc<str>> = vec![];
for item in args {
if let Calcit::Symbol { sym, .. } = item {
Expand All @@ -53,7 +53,7 @@ pub fn get_raw_args(args: &CalcitItems) -> Result<Box<Vec<Arc<str>>>, String> {
return Err(format!("Unexpected argument: {}", item));
}
}
Ok(Box::new(xs))
Ok(xs)
}

pub fn quote(expr: &CalcitItems, _scope: &CalcitScope, _file_ns: Arc<str>) -> Result<Calcit, CalcitErr> {
Expand Down Expand Up @@ -206,7 +206,7 @@ pub fn macroexpand(
// println!("macro: {:?} ... {:?}", args, rest_nodes);
// keep expanding until return value is not a recur
loop {
let body_scope = runner::bind_args(args.to_owned(), &rest_nodes, scope, call_stack)?;
let body_scope = runner::bind_args(&args, &rest_nodes, scope, call_stack)?;
let v = runner::evaluate_lines(&body, &body_scope, def_ns.to_owned(), call_stack)?;
match v {
Calcit::Recur(rest_code) => {
Expand Down Expand Up @@ -243,7 +243,7 @@ pub fn macroexpand_1(
let v = runner::evaluate_expr(&xs[0], scope, file_ns.to_owned(), call_stack)?;
match v {
Calcit::Macro { def_ns, args, body, .. } => {
let body_scope = runner::bind_args(args.to_owned(), &xs.skip(1)?, scope, call_stack)?;
let body_scope = runner::bind_args(&args, &xs.skip(1)?, scope, call_stack)?;
runner::evaluate_lines(&body, &body_scope, def_ns, call_stack)
}
_ => Ok(quoted_code),
Expand Down Expand Up @@ -279,7 +279,7 @@ pub fn macroexpand_all(
// println!("macro: {:?} ... {:?}", args, rest_nodes);
// keep expanding until return value is not a recur
loop {
let body_scope = runner::bind_args(args.to_owned(), &rest_nodes, scope, call_stack)?;
let body_scope = runner::bind_args(&args, &rest_nodes, scope, call_stack)?;
let v = runner::evaluate_lines(&body, &body_scope, def_ns.to_owned(), call_stack)?;
match v {
Calcit::Recur(rest_code) => {
Expand Down Expand Up @@ -336,7 +336,7 @@ pub fn call_try(expr: &CalcitItems, scope: &CalcitScope, file_ns: Arc<str>, call
def_ns, scope, args, body, ..
} => {
let values = FingerList::from(&[Size(err_data)]);
runner::run_fn(&values, &scope, args.to_owned(), &body, def_ns, call_stack)
runner::run_fn(&values, &scope, &args, &body, def_ns, call_stack)
}
Calcit::Proc(proc) => builtins::handle_proc(&proc, &FingerList::from(&[Size(err_data)]), call_stack),
a => CalcitErr::err_str(format!("try expected a function handler, got: {}", a)),
Expand Down
15 changes: 3 additions & 12 deletions src/codegen/emit_js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ fn gen_call_code(
(Some(Calcit::Symbol { sym, .. }), Some(Calcit::List(ys))) => {
let func_body = body.skip(2)?;
gen_stack::push_call_stack(ns, sym, StackKind::Codegen, xs.to_owned(), &FingerList::new_empty());
let ret = gen_js_func(sym, get_raw_args(ys)?, &func_body, ns, false, local_defs, file_imports, keywords);
let ret = gen_js_func(sym, &get_raw_args(ys)?, &func_body, ns, false, local_defs, file_imports, keywords);
gen_stack::pop_call_stack();
match ret {
Ok(code) => Ok(format!("{}{}", return_code, code)),
Expand Down Expand Up @@ -940,7 +940,7 @@ fn uses_recur(xs: &Calcit) -> bool {

fn gen_js_func(
name: &str,
args: Box<Vec<Arc<str>>>,
args: &Vec<Arc<str>>,
raw_body: &CalcitItems,
ns: &str,
exported: bool,
Expand Down Expand Up @@ -1239,16 +1239,7 @@ pub fn emit_js(entry_ns: &str, emit_path: &str) -> Result<(), String> {
..
} => {
gen_stack::push_call_stack(def_ns, name, StackKind::Codegen, f.to_owned(), &FingerList::new_empty());
defs_code.push_str(&gen_js_func(
&def,
args.to_owned(),
code,
&ns,
true,
&def_names,
&file_imports,
&keywords,
)?);
defs_code.push_str(&gen_js_func(&def, args, code, &ns, true, &def_names, &file_imports, &keywords)?);
gen_stack::pop_call_stack();
}
Calcit::Thunk(code, _) => {
Expand Down
2 changes: 1 addition & 1 deletion src/codegen/gen_ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ fn dump_items_code(xs: &CalcitItems) -> Edn {
Edn::List(ys)
}

fn dump_args_code(xs: &Box<Vec<Arc<str>>>) -> Edn {
fn dump_args_code(xs: &Vec<Arc<str>>) -> Edn {
let mut ys: Vec<Edn> = Vec::with_capacity(xs.len());
for x in &**xs {
ys.push(Edn::sym(&*x.to_owned()));
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub fn run_program(init_ns: Arc<str>, init_def: Arc<str>, params: CalcitItems) -
Calcit::Fn {
def_ns, scope, args, body, ..
} => {
let result = runner::run_fn(&params, &scope, args.to_owned(), &body, def_ns, &rpds::List::new_sync());
let result = runner::run_fn(&params, &scope, &args, &body, def_ns, &rpds::List::new_sync());
match result {
Ok(v) => Ok(v),
Err(failure) => {
Expand Down
14 changes: 7 additions & 7 deletions src/primes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,19 @@ pub enum Calcit {
Record(EdnKwd, Arc<Vec<EdnKwd>>, Arc<Vec<Calcit>>), // usize of keyword id
Proc(Arc<str>),
Macro {
name: Arc<str>, // name
def_ns: Arc<str>, // ns
id: Arc<str>, // an id
args: Box<Vec<Arc<str>>>, // args
body: Arc<CalcitItems>, // body
name: Arc<str>, // name
def_ns: Arc<str>, // ns
id: Arc<str>, // an id
args: Vec<Arc<str>>, // args
body: Arc<CalcitItems>, // body
},
Fn {
name: Arc<str>, // name
def_ns: Arc<str>, // ns
id: Arc<str>, // an id
scope: Arc<CalcitScope>,
args: Box<Vec<Arc<str>>>, // args
body: Arc<CalcitItems>, // body
args: Vec<Arc<str>>, // args
body: Arc<CalcitItems>, // body
},
Syntax(CalcitSyntax, Arc<str>), // name, ns... notice that `ns` is a meta info
}
Expand Down
10 changes: 5 additions & 5 deletions src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ pub fn evaluate_expr(expr: &Calcit, scope: &CalcitScope, file_ns: Arc<str>, call
&values,
);

run_fn(&values, def_scope, args.to_owned(), body, def_ns.to_owned(), &next_stack)
run_fn(&values, def_scope, args, body, def_ns.to_owned(), &next_stack)
}
Calcit::Macro {
name, def_ns, args, body, ..
Expand All @@ -133,7 +133,7 @@ pub fn evaluate_expr(expr: &Calcit, scope: &CalcitScope, file_ns: Arc<str>, call

Ok(loop {
// need to handle recursion
let body_scope = bind_args(args.to_owned(), &current_values, &rpds::HashTrieMap::new_sync(), call_stack)?;
let body_scope = bind_args(args, &current_values, &rpds::HashTrieMap::new_sync(), call_stack)?;
let code = evaluate_lines(body, &body_scope, def_ns.to_owned(), &next_stack)?;
match code {
Calcit::Recur(ys) => {
Expand Down Expand Up @@ -285,14 +285,14 @@ fn eval_symbol_from_program(sym: &str, ns: &str, call_stack: &CallStackList) ->
pub fn run_fn(
values: &CalcitItems,
scope: &CalcitScope,
args: Box<Vec<Arc<str>>>,
args: &Vec<Arc<str>>,
body: &CalcitItems,
file_ns: Arc<str>,
call_stack: &CallStackList,
) -> Result<Calcit, CalcitErr> {
let mut current_values = Box::new(values.to_owned());
loop {
let body_scope = bind_args(args.to_owned(), &current_values, scope, call_stack)?;
let body_scope = bind_args(args, &current_values, scope, call_stack)?;
let v = evaluate_lines(body, &body_scope, file_ns.to_owned(), call_stack)?;
match v {
Calcit::Recur(xs) => {
Expand All @@ -306,7 +306,7 @@ pub fn run_fn(
/// create new scope by writing new args
/// notice that `&` is a mark for spreading, `?` for optional arguments
pub fn bind_args(
args: Box<Vec<Arc<str>>>,
args: &Vec<Arc<str>>,
values: &CalcitItems,
base_scope: &CalcitScope,
call_stack: &CallStackList,
Expand Down
4 changes: 2 additions & 2 deletions src/runner/preprocess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ fn process_list_call(
loop {
// need to handle recursion
// println!("evaling line: {:?}", body);
let body_scope = runner::bind_args(def_args.to_owned(), &current_values, &rpds::HashTrieMap::new_sync(), &next_stack)?;
let body_scope = runner::bind_args(def_args, &current_values, &rpds::HashTrieMap::new_sync(), &next_stack)?;
let code = runner::evaluate_lines(body, &body_scope, def_ns.to_owned(), &next_stack)?;
match code {
Calcit::Recur(ys) => {
Expand Down Expand Up @@ -463,7 +463,7 @@ fn process_list_call(

// detects arguments of top-level functions when possible
fn check_fn_args(
defined_args: &Box<Vec<Arc<str>>>,
defined_args: &Vec<Arc<str>>,
params: &CalcitItems,
file_ns: Arc<str>,
f_name: Arc<str>,
Expand Down

0 comments on commit 7f474dc

Please sign in to comment.