Skip to content

Commit

Permalink
Resolving issued from code review, and fixing a few typos
Browse files Browse the repository at this point in the history
  • Loading branch information
luketpeterson committed Aug 15, 2023
1 parent da2a7ba commit ec321fb
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion c/src/atom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ pub unsafe extern "C" fn atom_eq(a: *const atom_ref_t, b: *const atom_ref_t) ->
/// @ingroup atom_group
/// @param[in] a A pointer to an `atom_t` or an `atom_ref_t` representing the first atom
/// @param[in] b A pointer to an `atom_t` or an `atom_ref_t` representing the second atom
/// @return `true` is the atoms can be converted to each other by renaming variables, otherwise `false`
/// @return `true` if the atoms can be converted to each other by renaming variables, otherwise `false`
///
#[no_mangle]
pub extern "C" fn atoms_are_equivalent(a: *const atom_ref_t, b: *const atom_ref_t) -> bool {
Expand Down
3 changes: 2 additions & 1 deletion c/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ pub mod metta;
/// @note This function should be called once, prior to any other calls to Hyperon C functions
///
//TODO: Is there a way we can get rid of this function in the external API?
// Discussion about alternative ways to init the logger here: https://github.com/trueagi-io/hyperon-experimental/pull/314
// Discussion about alternative ways to init the logger here: https://github.com/trueagi-io/hyperon-experimental/pull/314
// and here: https://github.com/trueagi-io/hyperon-experimental/issues/146
#[no_mangle]
pub extern "C" fn init_logger() {
hyperon::common::init_logger(false);
Expand Down
10 changes: 0 additions & 10 deletions c/src/metta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,6 @@ pub extern "C" fn tokenizer_clone(tokenizer: *const tokenizer_t) -> tokenizer_t
/// @ingroup tokenizer_and_parser_group
/// @note `sexpr_parser_t` handles must be freed with `sexpr_parser_free()`
///
//
//QUESTION FOR VITALY: Do we need the sexpr_parser_t type in the C and Python interfaces? It looks like
// the only thing they can do is provide a path for text to be parsed either stand-alone or inside the
// MeTTa interpreter. So we could eliminate `sexpr_parser_t` type altogether, and just have a stand-alone
// `parse_sexpr(tokenizer, input_text) -> atom_t` function, and change `metta_run` to take a text string
// rather than a parser.
//
//Do you think it makes sense to simplify the C & Python APIs, or do you think more parsing control will
// be added to the C & Python APIs in the future?
//
#[repr(C)]
pub struct sexpr_parser_t {
/// Internal. Should not be accessed directly
Expand Down
4 changes: 2 additions & 2 deletions c/src/space.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ struct RustSpaceObserver(std::cell::RefCell<CObserver>);

impl From<SpaceObserverRef<CObserver>> for space_observer_t {
fn from(observer: SpaceObserverRef<CObserver>) -> Self {
Self{ observer: std::rc::Rc::into_raw(observer.0).cast() }
Self{ observer: std::rc::Rc::into_raw(observer.into_inner()).cast() }
}
}

Expand All @@ -394,7 +394,7 @@ impl space_observer_t {
cell.get_mut()
}
fn into_inner(self) -> SpaceObserverRef<CObserver> {
unsafe{ SpaceObserverRef(std::rc::Rc::from_raw(self.observer.cast())) }
unsafe{ std::rc::Rc::from_raw(self.observer.cast::<std::cell::RefCell<CObserver>>()).into() }
}
}

Expand Down
17 changes: 16 additions & 1 deletion lib/src/space/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,30 @@ pub trait SpaceObserver {

/// A reference to a SpaceObserver that has been registered with a Space
#[derive(Clone)]
pub struct SpaceObserverRef<T: SpaceObserver> (pub Rc<RefCell<T>>);
pub struct SpaceObserverRef<T: SpaceObserver> (Rc<RefCell<T>>);

impl<T: SpaceObserver> SpaceObserverRef<T> {
/// Returns a [Ref] to mutably access the [SpaceObserver]
pub fn borrow(&self) -> Ref<T> {
self.0.borrow()
}
/// Returns a [RefMut] to mutably access the [SpaceObserver]
pub fn borrow_mut(&self) -> RefMut<T> {
self.0.borrow_mut()
}
/// Returns the contents of the `SpaceObserverRef`
///
/// This method is used in the implementation of the C API bindings, and is probably
/// not necessary for Rust API clients
pub fn into_inner(self) -> Rc<RefCell<T>> {
self.0
}
}

impl<T: SpaceObserver> From<Rc<RefCell<T>>> for SpaceObserverRef<T> {
fn from(observer: Rc<RefCell<T>>) -> Self {
Self(observer)
}
}

/// Space iterator.
Expand Down

0 comments on commit ec321fb

Please sign in to comment.