Skip to content

Commit

Permalink
upgrade ABI 0.0.7 ; tag 0.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
tiye committed Jan 30, 2024
1 parent b81d8a4 commit 250fc8f
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 57 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@ jobs:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: dtolnay/rust-toolchain@stable
with:
# toolchain: nightly
toolchain: nightly
components: clippy

- uses: supplypike/setup-bin@v3
with:
uri: "https://github.com/calcit-lang/calcit/releases/download/0.8.0-a3/cr"
uri: "https://github.com/calcit-lang/calcit/releases/download/0.8.21/cr"
name: "cr"
version: "0.8.0-a3"
version: "0.8.21"

- uses: supplypike/setup-bin@v3
with:
uri: "https://github.com/calcit-lang/calcit/releases/download/0.8.0-a3/caps"
uri: "https://github.com/calcit-lang/calcit/releases/download/0.8.21/caps"
name: "caps"
version: "0.8.0-a3"
version: "0.8.21"

- run: cargo build --release

Expand Down
39 changes: 34 additions & 5 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "calcit_std"
version = "0.2.0-a1"
version = "0.2.1"
authors = ["jiyinyiyong <[email protected]>"]
edition = "2021"

Expand All @@ -17,8 +17,8 @@ crate-type = ["dylib"] # Creates dynamic lib
serde = { version = "1.0.185", features = ["derive"] }
serde_json = "1.0.105"
chrono = "0.4.26"
cirru_edn = "0.4.2"
cirru_parser = "0.1.25"
cirru_edn = "0.5.4"
cirru_parser = "0.1.28"
nanoid = "0.4.0"
rand = "0.8.5"
ctrlc = "3.4.0"
Expand Down
2 changes: 1 addition & 1 deletion calcit.cirru

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

2 changes: 1 addition & 1 deletion compact.cirru
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

{} (:package |calcit.std)
:configs $ {} (:init-fn |calcit.std.test/main!) (:reload-fn |calcit.std.test/reload!) (:version |0.2.0-a2)
:configs $ {} (:init-fn |calcit.std.test/main!) (:reload-fn |calcit.std.test/reload!) (:version |0.2.1)
:modules $ []
:entries $ {}
:files $ {}
Expand Down
20 changes: 10 additions & 10 deletions src/date.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! TODO, need to store offset as well,
//! currently lack of offset, prefer using Local time
use std::collections::HashMap;
use std::{collections::HashMap, sync::Arc};

use chrono::{DateTime, Datelike, Duration, Local, LocalResult, NaiveDate, TimeZone, Timelike, Utc, Weekday};
use cirru_edn::Edn;
Expand Down Expand Up @@ -49,12 +49,12 @@ pub fn format_time(args: Vec<Edn>) -> Result<Edn, String> {
if args.len() == 2 {
match (&args[0], &args[1]) {
(Edn::Number(n), Edn::Nil) => match Local.timestamp_opt((n.floor() / 1000.0) as i64, (n.fract() * 1_000_000.0) as u32) {
LocalResult::Single(time) => Ok(Edn::Str(time.to_rfc3339().into_boxed_str())),
LocalResult::Single(time) => Ok(Edn::Str(time.to_rfc3339().into())),
LocalResult::Ambiguous(min_time, max_time) => Err(format!("format-time failed, ambiguous: {min_time} {max_time}")),
LocalResult::None => Err(format!("format-time out of range: {n}")),
},
(Edn::Number(n), Edn::Str(f)) => match Local.timestamp_opt((n.floor() / 1000.0) as i64, (n.fract() * 1_000_000.0) as u32) {
LocalResult::Single(time) => Ok(Edn::Str(time.format(f).to_string().into_boxed_str())),
LocalResult::Single(time) => Ok(Edn::Str(time.format(f).to_string().into())),
LocalResult::None => Err(format!("format-time out of range: {n} {f}")),
LocalResult::Ambiguous(min_time, max_time) => Err(format!("format-time ambiguous: {min_time} {max_time}")),
},
Expand Down Expand Up @@ -114,13 +114,13 @@ pub fn from_ymd(args: Vec<Edn>) -> Result<Edn, String> {
.and_hms_opt(0, 0, 0)
.ok_or("from_ymd got none")?,
) {
LocalResult::None => Ok(Edn::Tuple(Box::new(Edn::tag("none")), vec![])),
LocalResult::None => Ok(Edn::Tuple(Arc::new(Edn::tag("none")), vec![])),
LocalResult::Single(d) => Ok(Edn::Tuple(
Box::new(Edn::tag("single")),
Arc::new(Edn::tag("single")),
vec![Edn::Number(d.timestamp_millis() as f64)],
)),
LocalResult::Ambiguous(d, d2) => Ok(Edn::Tuple(
Box::new(Edn::tag("ambiguous")),
Arc::new(Edn::tag("ambiguous")),
vec![Edn::Number(d.timestamp_millis() as f64), Edn::Number(d2.timestamp_millis() as f64)],
)),
}
Expand Down Expand Up @@ -148,20 +148,20 @@ pub fn from_ywd(args: Vec<Edn>) -> Result<Edn, String> {
6 => Weekday::Sat,
_ => {
return Ok(Edn::Tuple(
Box::new(Edn::tag("err")),
Arc::new(Edn::tag("err")),
vec![Edn::str(format!("invalid digit for weekday: {d}"))],
))
}
};
match NaiveDate::from_isoywd_opt(*y as i32, *w as u32, weekday) {
Some(time) => match Local.from_local_datetime(&time.and_hms_opt(0, 0, 0).ok_or("hms got none")?) {
LocalResult::None => Ok(Edn::Tuple(Box::new(Edn::tag("none")), vec![])),
LocalResult::None => Ok(Edn::Tuple(Arc::new(Edn::tag("none")), vec![])),
LocalResult::Single(d) => Ok(Edn::Tuple(
Box::new(Edn::tag("single")),
Arc::new(Edn::tag("single")),
vec![Edn::Number(d.timestamp_millis() as f64)],
)),
LocalResult::Ambiguous(d, d2) => Ok(Edn::Tuple(
Box::new(Edn::tag("single")),
Arc::new(Edn::tag("single")),
vec![Edn::Number(d.timestamp_millis() as f64), Edn::Number(d2.timestamp_millis() as f64)],
)),
},
Expand Down
8 changes: 4 additions & 4 deletions src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub fn read_file(args: Vec<Edn>) -> Result<Edn, String> {
if let Edn::Str(name) = &args[0] {
let task = fs::read_to_string(&**name);
match task {
Ok(s) => Ok(Edn::Str(s.into_boxed_str())),
Ok(s) => Ok(Edn::Str(s.into())),
Err(e) => Err(format!("Failed to read file {name:?}: {e}")),
}
} else {
Expand Down Expand Up @@ -129,7 +129,7 @@ pub fn read_dir(args: Vec<Edn>) -> Result<Edn, String> {
Ok(children) => {
let mut content: Vec<Edn> = vec![];
for c in children {
content.push(Edn::Str(format!("{}", c.unwrap().path().display()).into_boxed_str()));
content.push(Edn::Str(format!("{}", c.unwrap().path().display()).into()));
}
// println!("child dir: {:?}", content);

Expand Down Expand Up @@ -245,7 +245,7 @@ pub fn walk_dir(args: Vec<Edn>) -> Result<Edn, String> {
let entry = entry.unwrap();
let path = entry.path();
if path.is_file() {
content.push(Edn::Str(format!("{}", path.display()).into_boxed_str()));
content.push(Edn::Str(format!("{}", path.display()).into()));
}
}
Ok(Edn::List(content))
Expand All @@ -267,7 +267,7 @@ pub fn glob_call(args: Vec<Edn>) -> Result<Edn, String> {
match entry {
Ok(entry) => {
if entry.is_file() {
content.push(Edn::Str(format!("{}", entry.display()).into_boxed_str()));
content.push(Edn::Str(format!("{}", entry.display()).into()));
}
}
Err(e) => return Err(format!("Failed to read: {}", e)),
Expand Down
4 changes: 1 addition & 3 deletions src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ use cirru_edn::Edn;
pub fn md5(args: Vec<Edn>) -> Result<Edn, String> {
if args.len() == 1 {
if let Edn::Str(s) = &args[0] {
Ok(Edn::Str(
format!("{:x}", md5::compute(&**s)).into_boxed_str(),
))
Ok(Edn::Str(format!("{:x}", md5::compute(&**s)).into()))
} else {
Err(format!("md5 expected a string, {}", &args[0]))
}
Expand Down
8 changes: 4 additions & 4 deletions src/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub fn json_to_edn(data: &Value) -> Edn {
// special logic to parse keyword
Edn::Tag(EdnTag::new(s.strip_prefix(':').unwrap()))
} else {
Edn::Str(s.to_owned().into_boxed_str())
Edn::Str(s.to_owned().into())
}
}
Value::Array(xs) => {
Expand All @@ -30,7 +30,7 @@ pub fn json_to_edn(data: &Value) -> Edn {
let key = if k.starts_with(':') {
Edn::tag(k.strip_prefix(':').unwrap())
} else {
Edn::Str(k.to_owned().into_boxed_str())
Edn::Str(k.to_owned().into())
};
ys.insert(key, json_to_edn(v));
}
Expand Down Expand Up @@ -118,14 +118,14 @@ pub fn stringify_json(args: Vec<Edn>) -> Result<Edn, String> {
Edn::Bool(add_colon) => {
let ret = edn_to_json(args[0].to_owned(), *add_colon)?;
match serde_json::to_string(&ret) {
Ok(s) => Ok(Edn::Str(s.into_boxed_str())),
Ok(s) => Ok(Edn::Str(s.into())),
Err(e) => Err(format!("failed to generate string: {e}")),
}
}
Edn::Nil => {
let ret = edn_to_json(args[0].to_owned(), false)?;
match serde_json::to_string(&ret) {
Ok(s) => Ok(Edn::Str(s.into_boxed_str())),
Ok(s) => Ok(Edn::Str(s.into())),
Err(e) => Err(format!("failed to generate string: {e}")),
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ pub use time::{set_interval, set_timeout};

#[no_mangle]
pub fn abi_version() -> String {
String::from("0.0.6")
String::from("0.0.7")
}
15 changes: 3 additions & 12 deletions src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,20 @@ pub fn execute_command(args: Vec<Edn>) -> Result<Edn, String> {
xs.push((**s).to_owned());
}
} else {
return Err(format!(
"execute-command expected string in list, got {}",
piece
));
return Err(format!("execute-command expected string in list, got {}", piece));
}
}

match Command::new(cmd).current_dir(&**dir).args(&xs).output() {
Ok(t) => {
let content = String::from_utf8(t.stdout).unwrap();
let stderr = String::from_utf8(t.stderr).unwrap();
Ok(Edn::List(vec![
Edn::Str(content.into_boxed_str()),
Edn::Str(stderr.into_boxed_str()),
]))
Ok(Edn::List(vec![Edn::Str(content.into()), Edn::Str(stderr.into())]))
}
Err(e) => Err(format!("Failed to excute: {e}")),
}
}
(_, _) => Err(format!(
"excute-command expected string and list: {:?}",
args
)),
(_, _) => Err(format!("excute-command expected string and list: {:?}", args)),
}
} else {
Err(format!("excute-command expected 2 args: {args:?}"))
Expand Down
11 changes: 4 additions & 7 deletions src/random.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,16 @@ pub fn call_nanoid(xs: Vec<Edn>) -> Result<Edn, String> {
};

match (size, &xs[1]) {
(None, Edn::Nil) => Ok(Edn::Str(nanoid!().into_boxed_str())),
(Some(n), Edn::Nil) => Ok(Edn::Str(nanoid!(n).into_boxed_str())),
(None, Edn::Nil) => Ok(Edn::Str(nanoid!().into())),
(Some(n), Edn::Nil) => Ok(Edn::Str(nanoid!(n).into())),
(Some(n), Edn::Str(s)) => {
let mut charset: Vec<char> = vec![];
for c in s.chars() {
charset.push(c);
}
Ok(Edn::Str(nanoid!(n, &charset).into_boxed_str()))
Ok(Edn::Str(nanoid!(n, &charset).into()))
}
(a, b) => Err(format!(
"nanoid! expected size or charset, got: {:?} {:?}",
a, b
)),
(a, b) => Err(format!("nanoid! expected size or charset, got: {:?} {:?}", a, b)),
}
} else {
Err(format!("nanoid! expected 2 args, got: {xs:?}"))
Expand Down

0 comments on commit 250fc8f

Please sign in to comment.