Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrating List to ternary-tree #123

Merged
merged 3 commits into from
Nov 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "calcit_runner"
version = "0.5.0-a21"
version = "0.5.0-a22"
authors = ["jiyinyiyong <jiyinyiyong@gmail.com>"]
edition = "2018"
license = "MIT"
Expand Down Expand Up @@ -30,6 +30,8 @@ notify = "4.0.17"
walkdir = "2"
hex = "0.4.3"
rpds = "0.10.0"
im_ternary_tree = "0.0.1-a4"
# im_ternary_tree = { path = "/Users/chen/repo/calcit-lang/ternary-tree" }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
libloading = "0.7.1"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@calcit/procs",
"version": "0.5.0-a21",
"version": "0.5.0-a22",
"main": "./lib/calcit.procs.js",
"devDependencies": {
"@types/node": "^16.10.5",
Expand Down
11 changes: 6 additions & 5 deletions src/bin/cr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use notify::{RecommendedWatcher, RecursiveMode, Watcher};
use calcit_runner::{
builtins, call_stack, cli_args, codegen, codegen::emit_js::gen_stack, codegen::COMPILE_ERRORS_FILE, program, runner, snapshot, util,
};
use im_ternary_tree::TernaryTreeList;

pub struct ProgramSettings {
entry_path: PathBuf,
Expand Down Expand Up @@ -103,7 +104,7 @@ fn main() -> Result<(), String> {
&calcit_runner::primes::BUILTIN_CLASSES_ENTRY.to_string().into_boxed_str(),
None,
check_warnings,
&rpds::Vector::new_sync(),
&TernaryTreeList::Empty,
)
.map_err(|e| e.msg)?;

Expand All @@ -114,7 +115,7 @@ fn main() -> Result<(), String> {
} else {
let started_time = Instant::now();

let v = calcit_runner::run_program(init_fn, rpds::vector_sync![]).map_err(|e| {
let v = calcit_runner::run_program(init_fn, TernaryTreeList::Empty).map_err(|e| {
for w in e.warnings {
println!("{}", w);
}
Expand Down Expand Up @@ -223,7 +224,7 @@ fn recall_program(content: &str, init_fn: &str, reload_fn: &str, settings: &Prog
} else {
// run from `reload_fn` after reload
let started_time = Instant::now();
let v = calcit_runner::run_program(reload_fn, rpds::vector_sync![]).map_err(|e| {
let v = calcit_runner::run_program(reload_fn, TernaryTreeList::Empty).map_err(|e| {
for w in e.warnings {
println!("{}", w);
}
Expand Down Expand Up @@ -267,7 +268,7 @@ fn run_codegen(init_fn: &str, reload_fn: &str, emit_path: &str, ir_mode: bool) -
gen_stack::clear_stack();

// preprocess to init
match runner::preprocess::preprocess_ns_def(&init_ns, &init_def, &init_def, None, check_warnings, &rpds::Vector::new_sync()) {
match runner::preprocess::preprocess_ns_def(&init_ns, &init_def, &init_def, None, check_warnings, &TernaryTreeList::Empty) {
Ok(_) => (),
Err(failure) => {
println!("\nfailed preprocessing, {}", failure);
Expand All @@ -285,7 +286,7 @@ fn run_codegen(init_fn: &str, reload_fn: &str, emit_path: &str, ir_mode: bool) -
}

// preprocess to reload
match runner::preprocess::preprocess_ns_def(&reload_ns, &reload_def, &init_def, None, check_warnings, &rpds::Vector::new_sync()) {
match runner::preprocess::preprocess_ns_def(&reload_ns, &reload_def, &init_def, None, check_warnings, &TernaryTreeList::Empty) {
Ok(_) => (),
Err(failure) => {
println!("\nfailed preprocessing, {}", failure);
Expand Down
19 changes: 10 additions & 9 deletions src/bin/injection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use calcit_runner::{
primes::{Calcit, CalcitErr, CalcitItems, CrListWrap},
runner::track,
};
use im_ternary_tree::TernaryTreeList;

/// FFI protocol types
type EdnFfi = fn(args: Vec<Edn>) -> Result<Edn, String>;
Expand Down Expand Up @@ -48,7 +49,7 @@ pub fn call_dylib_edn(xs: &CalcitItems, _call_stack: &CallStackVec) -> Result<Ca
return CalcitErr::err_str(format!("&call-dylib-edn expected a method name, got {}", xs[1]));
};
let mut ys: Vec<Edn> = Vec::with_capacity(xs.len());
for (idx, v) in xs.iter().enumerate() {
for (idx, v) in xs.into_iter().enumerate() {
if idx > 1 {
ys.push(calcit_to_edn(v).map_err(CalcitErr::use_str)?);
}
Expand All @@ -70,7 +71,7 @@ pub fn call_dylib_edn(xs: &CalcitItems, _call_stack: &CallStackVec) -> Result<Ca

pub fn echo(xs: &CalcitItems, _call_stack: &CallStackVec) -> Result<Calcit, CalcitErr> {
let mut s = String::from("");
for (idx, x) in xs.iter().enumerate() {
for (idx, x) in xs.into_iter().enumerate() {
if idx > 0 {
s.push(' ');
}
Expand Down Expand Up @@ -103,7 +104,7 @@ pub fn call_dylib_edn_fn(xs: &CalcitItems, call_stack: &CallStackVec) -> Result<
};
let mut ys: Vec<Edn> = Vec::with_capacity(xs.len() - 2);
let callback = xs[xs.len() - 1].clone();
for (idx, v) in xs.iter().enumerate() {
for (idx, v) in xs.into_iter().enumerate() {
if idx > 1 && idx < xs.len() - 1 {
ys.push(calcit_to_edn(v).map_err(CalcitErr::use_str)?);
}
Expand Down Expand Up @@ -134,9 +135,9 @@ pub fn call_dylib_edn_fn(xs: &CalcitItems, call_stack: &CallStackVec) -> Result<
ys.to_owned(),
Arc::new(move |ps: Vec<Edn>| -> Result<Edn, String> {
if let Calcit::Fn(_, def_ns, _, def_scope, args, body) = &callback {
let mut real_args = rpds::vector_sync![];
let mut real_args = TernaryTreeList::Empty;
for p in ps {
real_args.push_back_mut(edn_to_calcit(&p));
real_args = real_args.push(edn_to_calcit(&p));
}
let r = runner::run_fn(&real_args, def_scope, args, body, def_ns, &copied_stack);
match r {
Expand Down Expand Up @@ -189,7 +190,7 @@ pub fn blocking_dylib_edn_fn(xs: &CalcitItems, call_stack: &CallStackVec) -> Res
};
let mut ys: Vec<Edn> = Vec::with_capacity(xs.len() - 2);
let callback = xs[xs.len() - 1].clone();
for (idx, v) in xs.iter().enumerate() {
for (idx, v) in xs.into_iter().enumerate() {
if idx > 1 && idx < xs.len() - 1 {
ys.push(calcit_to_edn(v).map_err(CalcitErr::use_str)?);
}
Expand Down Expand Up @@ -218,9 +219,9 @@ pub fn blocking_dylib_edn_fn(xs: &CalcitItems, call_stack: &CallStackVec) -> Res
ys.to_owned(),
Arc::new(move |ps: Vec<Edn>| -> Result<Edn, String> {
if let Calcit::Fn(_, def_ns, _, def_scope, args, body) = &callback {
let mut real_args = rpds::vector_sync![];
let mut real_args = TernaryTreeList::Empty;
for p in ps {
real_args.push_back_mut(edn_to_calcit(&p));
real_args = real_args.push(edn_to_calcit(&p));
}
let r = runner::run_fn(&real_args, def_scope, args, body, def_ns, &copied_stack.clone());
match r {
Expand Down Expand Up @@ -256,7 +257,7 @@ pub fn on_ctrl_c(xs: &CalcitItems, call_stack: &CallStackVec) -> Result<Calcit,
let copied_stack = Arc::new(call_stack.to_owned());
ctrlc::set_handler(move || {
if let Calcit::Fn(_name, def_ns, _, def_scope, args, body) = cb.as_ref() {
if let Err(e) = runner::run_fn(&rpds::vector_sync![], def_scope, args, body, def_ns, &copied_stack) {
if let Err(e) = runner::run_fn(&TernaryTreeList::Empty, def_scope, args, body, def_ns, &copied_stack) {
println!("error: {}", e);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/builtins/effects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ lazy_static! {

pub fn raise(xs: &CalcitItems) -> Result<Calcit, CalcitErr> {
let mut s = String::from("");
for (idx, x) in xs.iter().enumerate() {
for (idx, x) in xs.into_iter().enumerate() {
if idx > 0 {
s.push(' ');
}
Expand Down
Loading