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

add interval tree #63

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from
27 changes: 22 additions & 5 deletions src/core/env.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
use super::gc::{Context, ObjectMap, Rto, Slot};
use super::object::{LispBuffer, Object, OpenBuffer, Symbol, WithLifetime};
use anyhow::{anyhow, Result};
use crate::intervals::IntervalTree;

use super::gc::{Context, ObjectMap,
Rto, Slot};
use super::object::{LispBuffer, Object, ObjectType, OpenBuffer, Symbol, WithLifetime};
use anyhow::{anyhow, bail, Result};
use rune_core::hashmap::IndexMap;
use rune_macros::Trace;

mod stack;
Expand All @@ -20,8 +24,9 @@ pub(crate) struct Env<'a> {
binding_stack: Vec<(Slot<Symbol<'a>>, Option<Slot<Object<'a>>>)>,
pub(crate) match_data: Slot<Object<'a>>,
#[no_trace]
pub(crate) current_buffer: Option<OpenBuffer<'a>>,
pub(crate) stack: LispStack<'a>,
pub current_buffer: Option<OpenBuffer<'a>>,
pub buffer_textprops: ObjectMap<String, Slot<IntervalTree<'a>>>,
pub stack: LispStack<'a>,
}

// RootedEnv created by #[derive(Trace)]
Expand Down Expand Up @@ -94,6 +99,18 @@ impl<'a> RootedEnv<'a> {
Ok(())
}

#[inline]
pub fn get_buffer_textprops<'ob>(&mut self, buffer: &LispBuffer) -> Result<&mut IntervalTree<'a>> {
let buffer_name = &buffer.lock()?.name;
Ok(self.buffer_textprops_mut(buffer_name.clone()))
// self.buffer_textprops.get(buffer_name)
}

#[inline]
pub fn buffer_textprops_mut(&mut self, buffer_name: String) -> &mut IntervalTree<'a> {
self.buffer_textprops.entry(buffer_name).or_insert(IntervalTree::new())
}

pub(crate) fn set_buffer(&mut self, buffer: &LispBuffer) -> Result<()> {
if let Some(current) = &self.current_buffer {
if buffer == current {
Expand Down
4 changes: 2 additions & 2 deletions src/fns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ fn equal_including_properties<'ob>(o1: Object<'ob>, o2: Object<'ob>) -> bool {
}

#[defun]
fn plist_get<'ob>(plist: Object<'ob>, prop: Object<'ob>) -> Result<Object<'ob>> {
let Ok(plist) = List::try_from(plist) else { return Ok(NIL) };
pub fn plist_get<'ob>(plist: Object<'ob>, prop: Object<'ob>) -> Result<Object<'ob>> {
let Ok(plist) = Gc::<ListType>::try_from(plist) else { return Ok(NIL) };
// TODO: this function should never fail. Need to implement safe iterator
let mut iter = plist.elements();
while let Some(cur_prop) = iter.next() {
Expand Down
Loading
Loading