Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2b4bd90

Browse files
committed
Begin clojure.lang cllection protocols
1 parent 0753cb2 commit 2b4bd90

File tree

9 files changed

+93
-24
lines changed

9 files changed

+93
-24
lines changed

README.md

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
# ClojuRust
22
A proof of concept version of Clojure in Rust.
33

4+
<!-- TOC -->
5+
6+
- [ClojuRust](#clojurust)
7+
- [Current state](#current-state)
8+
- [Goals](#goals)
9+
- [Documentation](#documentation)
10+
- [Licence](#licence)
11+
- [Persistent data structures licence](#persistent-data-structures-licence)
12+
- [Original Clojure licence](#original-clojure-licence)
13+
- [clojure.core original code](#clojurecore-original-code)
14+
15+
<!-- /TOC -->
16+
417
## Current state
518
WIP in an analysis and test state, and so a working version is out of sight for now.
619

7-
As I'm a newbie in Rust, I hit all the bads of borrowing, referencing, Arcs, automatic derefs, timeline problems... But it begin to enter in my fingers... ;)
20+
As I'm a newbie in Rust, I hit all the bads of borrowing, referencing, Arcs, automatic derefs, timeline problems... But it begin to enter in my fingers... :wink:
821

922
For now, in the creation of the clojure::rust modules, say the Rust host environment, as Clojure is an hosted language. Rust, as a bare-metal language, has no dynamic abilities per se, and is even opposed to such an approach as all is verified at compile time. So a lot of information should be statically stored for the library to function.
1023

@@ -23,35 +36,32 @@ Meanwhile, the first Core Clojure classes can be developed in parallel, for test
2336
## Documentation
2437
The whole documentation will be located in a .io page (WIP)
2538

26-
## Copyrights
27-
### ClojuRust
28-
29-
Copyright (c) 2020 Ivan Pierre, kilroySoft, <Ivan Pierre, [email protected]>, under MPL 2.0.
30-
31-
* Code is on GitHub: https://github.com/clojurust/clojurust
39+
## Licence
40+
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
3241

33-
### Clojure
34-
As clojure::lang::* is a translation of original code of Java Clojure core, reference is due to Rich Hickey:
42+
If a copy of the MPL was not distributed within this file, You can obtain one at http://mozilla.org/MPL/2.0/.
3543

36-
Copyright (c) Rich Hickey. All rights reserved. Under EPL 1.0.
3744

38-
* Original project can be found in the main repository: https://github.com/clojure/clojure
45+
Copyright (c) 2020 Ivan Pierre, kilroySoft, <Ivan Pierre, [email protected]>, under MPL 2.0.
3946

40-
But the project is not in this stage for now.
47+
* Code is on GitHub: https://github.com/clojurust/clojurust
4148

42-
### Crate for the persistent data structures
49+
### Persistent data structures licence
4350

4451
Copyright 2017 Bodil Stokke, under MPL 2.0.
4552

4653
* Crate doc is here: https://crates.io/crates/im
4754
* Code is on GitHub: https://github.com/bodil/im-rs
4855

49-
## Licence
50-
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
56+
### Original Clojure licence
57+
As clojure::lang::* is a translation of original code of Java Clojure core, reference is due to Rich Hickey:
5158

52-
If a copy of the MPL was not distributed within this file, You can obtain one at http://mozilla.org/MPL/2.0/.
59+
Copyright (c) Rich Hickey. All rights reserved. Under EPL 1.0.
60+
61+
* Original project can be found in the main repository: https://github.com/clojure/clojure
62+
63+
But the project is not in this stage for now.
5364

54-
### Original Clojure licence
5565
As clojure::lang is on Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php), there could be some problem of double licence problem.
5666

5767
As is, I put this advice of the original project licence:

src/clojure/lang/a_map_entry.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//! Protocol AMapEntry
2+
3+
use crate::clojure;
4+
use clojure::rust::object::*;
5+
use clojure::rust::obj_error::*;
6+
use clojure::lang::a_persistent_vector::*;
7+
use clojure::lang::i_persistent_stack::*;
8+
use clojure::lang::i_persistent_collection::*;
9+
use clojure::lang::i_seq::*;
10+
use clojure::lang::i_map_entry::*;
11+
12+
pub trait AMapEntry : TObject + APersistentVector + IMapEntry {
13+
fn assocN(&self, i: usize, val: &Object) -> ObjResult<&'_ IPersistentVector>;
14+
fn cons(&self, o: &Object) -> ObjResult<&'_ IPersistentVector>;
15+
fn count(&self) -> ObjResult<usize>;
16+
fn empty(&self) -> ObjResult<&'_ IPersistentCollection>;
17+
fn nth(&self, i: usize) -> ObjResult<Object>;
18+
fn pop(&self) -> ObjResult<&'_ IPersistentStack>;
19+
fn seq(&self) -> ObjResult<&'_ ISeq>;
20+
fn setValue(value: Object) -> ObjResult<Object>;
21+
}

src/clojure/lang/i_map_entry.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//! Protocol IMapEntry
2+
3+
use crate::clojure;
4+
use clojure::rust::object::*;
5+
use clojure::rust::obj_error::*;
6+
use clojure::rust::map::*;
7+
8+
pub trait IMapEntry: TObject + Entry {
9+
fn key(&self) -> ObjResult<Object>;
10+
fn val(&self) -> ObjResult<Object>;
11+
}

src/clojure/rust/associative.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//! Protocol Associative
2+
3+
use crate::clojure;
4+
use clojure::rust::object::*;
5+
use clojure::rust::obj_error::*;
6+
use clojure::lang::i_map_entry::*;
7+
8+
pub trait Associative {
9+
fn assoc(&self, key: &Object, value: &Object) -> ObjResult<&Associative>;
10+
fn containsKey(&self, key: &Object) -> ObjResult<bool>;
11+
fn entryAt(&self, key: &Object) -> ObjResult<&IMapEntry>;
12+
}

src/clojure/rust/counted.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
/// Protocol `Counted`
22
3+
use crate::clojure;
4+
use clojure::rust::object::*;
5+
use clojure::rust::obj_error::*;
6+
37
use crate::init_obj;
48
use crate::init_init_obj;
59

6-
// castable_to!(SGlobals => [sync] TObject, Globals);
7-
810
init_obj! {
911
Counted {
1012
}
1113
}
1214

13-
pub trait Counted {
15+
pub trait Counted: TObject {
1416
/// give the nr of elements
15-
fn count(&self) -> usize;
17+
fn count(&self) -> ObjResult<usize>;
1618
}

src/clojure/rust/indexed.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
use crate::clojure;
55
use clojure::rust::counted::*;
66
use clojure::rust::object::*;
7+
use clojure::rust::obj_error::*;
78

89
// castable_to!(SGlobals => [sync] TObject, Globals);
910

10-
pub trait Indexed: Counted {
11-
fn nth_1(&self, i: usize) -> Object;
12-
fn nth_2(&self, i: usize, notFound: Object) -> Object;
11+
pub trait Indexed: TObject + Counted {
12+
fn nth_1(&self, i: usize) -> ObjResult<Object>;
13+
fn nth_2(&self, i: usize, notFound: Object) -> ObjResult<Object>;
1314
}
1415

src/clojure/rust/iterable.rs

Whitespace-only changes.

src/clojure/rust/map.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//! An object that maps keys to values. A map cannot contain duplicate keys; each key can map to at most one value.
2+
3+
trait Map<K, V>{}
4+
5+
/// This is an entry for K = V = Object
6+
pub trait Entry {
7+
8+
}

src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,25 @@ pub mod clojure {
3535
pub mod a_persistent_vector;
3636
pub mod a_persistent_set;
3737
pub mod a_persistent_map;
38+
pub mod a_map_entry;
3839
pub mod persistent_vector;
3940
pub mod persistent_set;
4041
pub mod persistent_map;
42+
pub mod i_map_entry;
4143
}
4244

4345
/// Rust host Module
4446
pub mod rust {
4547
pub mod class;
4648
pub mod counted;
49+
pub mod associative;
4750
pub mod indexed;
4851
pub mod fn_method_native;
4952
pub mod function;
5053
pub mod globals;
5154
pub mod member;
5255
pub mod number;
56+
pub mod map;
5357
pub mod obj_error;
5458
pub mod object;
5559
pub mod protocol;

0 commit comments

Comments
 (0)