Skip to content

Commit

Permalink
Merge pull request #231 from koto-lang/object-improvements
Browse files Browse the repository at this point in the history
Introduce trait-based objects
  • Loading branch information
irh authored Aug 8, 2023
2 parents 460222a + 962efc0 commit 227806a
Show file tree
Hide file tree
Showing 46 changed files with 2,787 additions and 2,105 deletions.
7 changes: 3 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ The Koto project adheres to

#### Internals

- `MetaMapBuilder` is now available to simplify the creation of `MetaMap`s.
- The `KotoObject` trait has been introduced to simplify creating custom object
types, replacing `ExternalValue`.
- Preludes are now available in the `koto` and `koto_runtime` crates.
- `Ptr<T>` and `PtrMut<T>` wrappers have been introduced as the core memory
types for the runtime, replacing uses of `Rc<T>` and `Rc<RefCell<T>>`.
Expand Down Expand Up @@ -96,7 +97,7 @@ The Koto project adheres to

- `Value` no longer implements `fmt::Display`, instead `value_to_string` can be
called on `Koto` or the Vm to get a string.
- `Value::ExternalValue` is now `Value::External`.
- `Value::ExternalValue` has been replaced by `Value::Object`.
- `ValueTuple::data` has been removed, with a `Deref` impl to `&[Value]` taking
its place.
- Type strings and strings returned by `KotoFile` implementations are now
Expand Down Expand Up @@ -136,8 +137,6 @@ The Koto project adheres to
# You can use:
"hello"[2..4]
```
- The `Value::ExternalData` variant has been removed, `ExternalValue` can be
used instead.

### Fixed

Expand Down
52 changes: 42 additions & 10 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ smallvec = { version = "1.10.0", features = ["const_generics", "union"] }
tempfile = "3.1"
# A crate for getting the crate binary in an integration test.
test_bin = "0.4.0"
# derive(Error)
thiserror = "1.0.44"
# A native Rust encoder and decoder of TOML-formatted files and streams.
toml = { version = "0.5.6", features = ["preserve_order"] }
# Powerful library for word wrapping, indenting, and dedenting strings
Expand Down
7 changes: 7 additions & 0 deletions core/memory/src/rc/ptr_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ impl<T: ?Sized> PtrMut<T> {
pub fn try_borrow_mut(&self) -> Result<BorrowMut<'_, T>, BorrowMutError> {
self.0.try_borrow_mut().map(BorrowMut)
}

/// Returns true if the two `PtsMut`s point to the same allocation
///
/// See also: [std::rc::Rc::ptr_eq]
pub fn ptr_eq(this: &Self, other: &Self) -> bool {
Rc::ptr_eq(&this.0, &other.0)
}
}

impl<T> From<T> for PtrMut<T> {
Expand Down
1 change: 1 addition & 0 deletions core/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ downcast-rs = { workspace = true }
indexmap = { workspace = true }
rustc-hash = { workspace = true }
smallvec = { workspace = true }
thiserror = { workspace = true }
unicode-segmentation = { workspace = true }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
Expand Down
Loading

0 comments on commit 227806a

Please sign in to comment.