From dc675ae908ef54bdf91f7b36872b86b41d3d92e2 Mon Sep 17 00:00:00 2001 From: Qkessler Date: Tue, 5 Dec 2023 12:45:04 +0100 Subject: [PATCH] WIP: Add documentation for cdr and car and move build.rs to rune_defun --- Cargo.toml | 7 ------- crates/rune-core/src/cons.rs | 19 +++++++++++++++++-- crates/rune-core/src/gc/context.rs | 2 +- crates/rune-core/src/gc/root.rs | 4 ++-- crates/rune-core/src/object/tagged.rs | 2 +- crates/rune-defun/Cargo.toml | 7 +++++++ build.rs => crates/rune-defun/build.rs | 2 +- {src => crates/rune-defun/src}/debug.rs | 0 crates/rune-defun/src/interpreter.rs | 2 +- crates/rune-defun/src/lib.rs | 1 + src/print.rs | 2 +- 11 files changed, 32 insertions(+), 16 deletions(-) rename build.rs => crates/rune-defun/build.rs (99%) rename {src => crates/rune-defun/src}/debug.rs (100%) diff --git a/Cargo.toml b/Cargo.toml index 37e01e83..5f647b95 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -50,8 +50,6 @@ num_enum = "0.7.1" paste = "1.0.12" sptr = { workspace = true } streaming-iterator = "0.1.9" -fallible-iterator = { workspace = true } -fallible-streaming-iterator = { workspace = true } indexmap = { workspace = true } fxhash = { workspace = true } [target.'cfg(not(target_env = "msvc"))'.dependencies] @@ -61,11 +59,6 @@ text-buffer = { workspace = true } rune-macros = { workspace = true } rune-core = { workspace = true } -[build-dependencies] -syn = { workspace = true } -quote = { workspace = true } -proc-macro2 = {workspace = true } - # [dev-dependencies] # backtrace-on-stack-overflow = "0.3.0" diff --git a/crates/rune-core/src/cons.rs b/crates/rune-core/src/cons.rs index 01d36317..4d819595 100644 --- a/crates/rune-core/src/cons.rs +++ b/crates/rune-core/src/cons.rs @@ -65,11 +65,26 @@ impl Cons { self.mutable = false; } - pub(crate) fn car(&self) -> GcObj { + /// See [`cdr`]. The CAR of a list is, quite simply, the first item in the list. + /// See [Emacs manual](https://www.gnu.org/software/emacs/manual/html_node/eintr/car-_0026-cdr.html). + /// + /// Examples: + /// + /// '(rose violet daisy buttercup) -> car -> rose + /// '(test) -> car -> test + pub fn car(&self) -> GcObj { self.car.get() } - pub(crate) fn cdr(&self) -> GcObj { + /// See [`car`]. The CDR of a list is the rest of the list, that is, the cdr function + /// returns the part of the list that follows the first item. + /// See [Emacs manual](https://www.gnu.org/software/emacs/manual/html_node/eintr/car-_0026-cdr.html). + /// + /// Examples: + /// + /// '(rose violet daisy buttercup) -> cdr -> (violet daisy buttercup) + /// '(test) -> cdr -> nil + pub fn cdr(&self) -> GcObj { self.cdr.get() } diff --git a/crates/rune-core/src/gc/context.rs b/crates/rune-core/src/gc/context.rs index e123388b..160c241e 100644 --- a/crates/rune-core/src/gc/context.rs +++ b/crates/rune-core/src/gc/context.rs @@ -150,7 +150,7 @@ impl<'ob, 'rt> Context<'rt> { self.root_set } - pub(crate) fn garbage_collect(&mut self, force: bool) { + pub fn garbage_collect(&mut self, force: bool) { let mut objects = self.block.objects.borrow_mut(); if cfg!(not(test)) && !force diff --git a/crates/rune-core/src/gc/root.rs b/crates/rune-core/src/gc/root.rs index e8688b74..59ce328a 100644 --- a/crates/rune-core/src/gc/root.rs +++ b/crates/rune-core/src/gc/root.rs @@ -235,7 +235,7 @@ where } impl Rt { - pub(crate) fn bind<'ob>(&self, _: &'ob Context) -> >::Out + pub fn bind<'ob>(&self, _: &'ob Context) -> >::Out where T: WithLifetime<'ob> + Copy, { @@ -331,7 +331,7 @@ impl Rt> { } } - pub(crate) fn get<'ob, U>(&self, cx: &'ob Context) -> U + pub fn get<'ob, U>(&self, cx: &'ob Context) -> U where Gc: WithLifetime<'ob, Out = Gc> + Copy, Gc: Untag, diff --git a/crates/rune-core/src/object/tagged.rs b/crates/rune-core/src/object/tagged.rs index 466e8cb1..e7bf4a82 100755 --- a/crates/rune-core/src/object/tagged.rs +++ b/crates/rune-core/src/object/tagged.rs @@ -113,7 +113,7 @@ impl Gc { } } -pub(crate) trait Untag { +pub trait Untag { fn untag_erased(self) -> T; } diff --git a/crates/rune-defun/Cargo.toml b/crates/rune-defun/Cargo.toml index be023e3c..8462d621 100644 --- a/crates/rune-defun/Cargo.toml +++ b/crates/rune-defun/Cargo.toml @@ -12,9 +12,16 @@ rand = { workspace = true } titlecase = { workspace = true} hostname = { workspace = true} bstr = { workspace = true } +fallible-iterator = { workspace = true } +fallible-streaming-iterator = { workspace = true } rune-core = { workspace = true } rune-macros = { workspace = true } +[build-dependencies] +syn = { workspace = true } +quote = { workspace = true } +proc-macro2 = {workspace = true } + [lints] workspace = true diff --git a/build.rs b/crates/rune-defun/build.rs similarity index 99% rename from build.rs rename to crates/rune-defun/build.rs index 250f2f46..aba80ece 100755 --- a/build.rs +++ b/crates/rune-defun/build.rs @@ -60,7 +60,7 @@ fn main() { let mut all_defun = Vec::new(); let mut all_defvar = Vec::new(); let mut all_defsym = Vec::new(); - let src_dir = Path::new(env!("CARGO_WORKSPACE_DIR")).join("src"); + let src_dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("src"); // rerun for all top level files for entry in fs::read_dir(&src_dir).unwrap() { diff --git a/src/debug.rs b/crates/rune-defun/src/debug.rs similarity index 100% rename from src/debug.rs rename to crates/rune-defun/src/debug.rs diff --git a/crates/rune-defun/src/interpreter.rs b/crates/rune-defun/src/interpreter.rs index a0ff47bc..cc21476e 100755 --- a/crates/rune-defun/src/interpreter.rs +++ b/crates/rune-defun/src/interpreter.rs @@ -1,9 +1,9 @@ -use crate::{root, rooted_iter}; use anyhow::Context as _; use anyhow::Result as AnyResult; use anyhow::{anyhow, bail, ensure}; use fallible_iterator::FallibleIterator; use fallible_streaming_iterator::FallibleStreamingIterator; +use rune_core::{root, rooted_iter}; use rune_core::cons::{Cons, ElemStreamIter}; use rune_core::env::{sym, Env, Symbol}; diff --git a/crates/rune-defun/src/lib.rs b/crates/rune-defun/src/lib.rs index f5911181..1bffe0a3 100644 --- a/crates/rune-defun/src/lib.rs +++ b/crates/rune-defun/src/lib.rs @@ -5,6 +5,7 @@ pub mod bytecode; pub mod casefiddle; pub mod character; pub mod data; +pub mod debug; pub mod defs; pub mod editfns; pub mod emacs; diff --git a/src/print.rs b/src/print.rs index 402174b0..2b8b77df 100644 --- a/src/print.rs +++ b/src/print.rs @@ -1,4 +1,4 @@ -use crate::core::object::GcObj; +use rune_core::object::GcObj; use rune_macros::defun; #[defun]