Skip to content

Commit

Permalink
EDN import and export (#178)
Browse files Browse the repository at this point in the history
Adds EDN import and export.

- feature: `eu` now has experimental support import of `.edn` files and export to edn (using `-x edn`). Currently only single top-level forms are supported so, for example, reading streamed logs in edn is not possible. See https://github.com/edn-format/edn for the EDN spec.
  • Loading branch information
gmorpheme authored Feb 27, 2022
1 parent bdecb2d commit 4c76924
Show file tree
Hide file tree
Showing 34 changed files with 522 additions and 367 deletions.
58 changes: 58 additions & 0 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 @@ -42,6 +42,8 @@ uuid = { version = "0.8.2", features = ["serde", "v4"] }
webbrowser = "0.5.5"
bitmaps = "3.1.0"
pretty-hex = "0.2.1"
edn-format = "3.2.2"
ordered-float = "2.10.0"

[[bench]]
harness = false
Expand Down
49 changes: 14 additions & 35 deletions benches/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use eucalypt::{

use criterion::{black_box, criterion_group, criterion_main, Criterion};

fn box_one<'guard>(view: MutatorHeapView<'guard>, empty: RefPtr<EnvFrame>) -> Closure {
fn box_one(view: MutatorHeapView, empty: RefPtr<EnvFrame>) -> Closure {
Closure::new(
view.data(
DataConstructor::BoxedString.tag(),
Expand All @@ -34,25 +34,16 @@ fn box_one<'guard>(view: MutatorHeapView<'guard>, empty: RefPtr<EnvFrame>) -> Cl
)
}

fn identity<'guard>(view: MutatorHeapView<'guard>, empty: RefPtr<EnvFrame>) -> RefPtr<Closure> {
view.alloc(Closure::close(
&LambdaForm::new(1, view.atom(Ref::L(0)).unwrap().as_ptr(), Smid::default()),
empty,
))
.unwrap()
.as_ptr()
}

fn fake_bindings<'guard>(view: MutatorHeapView<'guard>, width: usize) -> Vec<LambdaForm> {
fn fake_bindings(view: MutatorHeapView, width: usize) -> Vec<LambdaForm> {
iter::repeat_with(|| {
LambdaForm::new(1, view.atom(Ref::L(0)).unwrap().as_ptr(), Smid::default())
})
.take(width)
.collect()
}

fn fake_env_stack<'guard>(
view: MutatorHeapView<'guard>,
fn fake_env_stack(
view: MutatorHeapView,
empty: RefPtr<EnvFrame>,
width: usize,
height: usize,
Expand All @@ -68,48 +59,39 @@ fn fake_env_stack<'guard>(
}

/// Allocate a letrec of identify function bindings
fn alloc_let<'guard>(
view: MutatorHeapView<'guard>,
fn alloc_let(
view: MutatorHeapView,
empty: RefPtr<EnvFrame>,
bindings: &[LambdaForm],
) -> RefPtr<EnvFrame> {
view.from_let(bindings, empty, Smid::default())
}

/// Allocate a letrec of identify function bindings
fn alloc_letrec<'guard>(
view: MutatorHeapView<'guard>,
fn alloc_letrec(
view: MutatorHeapView,
empty: RefPtr<EnvFrame>,
bindings: &[LambdaForm],
) -> RefPtr<EnvFrame> {
view.from_letrec(bindings, empty, Smid::default())
}

/// Access deep closure
fn access<'guard>(
view: MutatorHeapView<'guard>,
env: RefPtr<EnvFrame>,
depth: usize,
) -> Option<Closure> {
fn access(view: MutatorHeapView, env: RefPtr<EnvFrame>, depth: usize) -> Option<Closure> {
let e = view.scoped(env);
(*e).get(&view, depth)
}

/// Update deep closure with a new value
fn update<'guard>(
view: MutatorHeapView<'guard>,
empty: RefPtr<EnvFrame>,
env: RefPtr<EnvFrame>,
depth: usize,
) {
fn update(view: MutatorHeapView, empty: RefPtr<EnvFrame>, env: RefPtr<EnvFrame>, depth: usize) {
let e = view.scoped(env);
let value = box_one(view, empty);
(*e).update(&view, depth, value).unwrap();
}

/// Create an identity lambda and saturate it
fn create_and_saturate_lambda<'guard>(view: MutatorHeapView<'guard>, empty: RefPtr<EnvFrame>) {
let mut lambda = Closure::close(
fn create_and_saturate_lambda(view: MutatorHeapView, empty: RefPtr<EnvFrame>) {
let lambda = Closure::close(
&LambdaForm::new(1, view.atom(Ref::L(0)).unwrap().as_ptr(), Smid::default()),
empty,
);
Expand All @@ -118,11 +100,8 @@ fn create_and_saturate_lambda<'guard>(view: MutatorHeapView<'guard>, empty: RefP
}

/// Create an identity lambda and saturate it
fn create_partially_apply_and_saturate_lambda<'guard>(
view: MutatorHeapView<'guard>,
empty: RefPtr<EnvFrame>,
) {
let mut lambda = Closure::close(
fn create_partially_apply_and_saturate_lambda(view: MutatorHeapView, empty: RefPtr<EnvFrame>) {
let lambda = Closure::close(
&LambdaForm::new(2, view.atom(Ref::L(0)).unwrap().as_ptr(), Smid::default()),
empty,
);
Expand Down
5 changes: 5 additions & 0 deletions harness/test/050_edn.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{:k "foo"
:k1 "bar"
:blah
:quux [:x :y :z]
:RESULT :PASS}
13 changes: 5 additions & 8 deletions src/core/anaphora.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,12 @@ pub mod tests {

#[test]
pub fn test_to_binding_pattern() {
let _0 = free("_0");
let _1 = free("_1");
let ana0 = free("_0");
let ana1 = free("_1");

let mut hm: HashMap<Anaphor<Smid, i32>, FreeVar<String>> = HashMap::new();
hm.insert(Anaphor::ExplicitNumbered(0), _0.clone());
hm.insert(Anaphor::ExplicitNumbered(1), _1.clone());
assert_eq!(
to_binding_pattern(&hm).unwrap(),
vec![_0.clone(), _1.clone()]
);
hm.insert(Anaphor::ExplicitNumbered(0), ana0.clone());
hm.insert(Anaphor::ExplicitNumbered(1), ana1.clone());
assert_eq!(to_binding_pattern(&hm).unwrap(), vec![ana0, ana1]);
}
}
2 changes: 1 addition & 1 deletion src/core/cook/fill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ pub mod tests {

assert_term_eq!(
soup(fill(&[ana.clone(), plus.clone(), var(x.clone())])),
soup(vec![ana.clone(), plus.clone(), var(x.clone())])
soup(vec![ana, plus, var(x)])
);
}
}
12 changes: 6 additions & 6 deletions src/core/cook/fixity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ pub mod tests {
);

let expected = let_(
vec![(plus.clone(), bif("FOO")), (minus.clone(), bif("BAR"))],
soup(vec![num(1), infixl(50, var(plus.clone())), num(2)]),
vec![(plus.clone(), bif("FOO")), (minus, bif("BAR"))],
soup(vec![num(1), infixl(50, var(plus)), num(2)]),
);

assert_term_eq!(distribute(expr).unwrap(), expected);
Expand All @@ -149,8 +149,8 @@ pub mod tests {
let expected = let_(
vec![(plus.clone(), bif("FOO"))],
let_(
vec![(minus.clone(), bif("BAR"))],
soup(vec![num(1), infixl(50, var(plus.clone())), num(2)]),
vec![(minus, bif("BAR"))],
soup(vec![num(1), infixl(50, var(plus)), num(2)]),
),
);

Expand All @@ -171,8 +171,8 @@ pub mod tests {
);

let expected = let_(
vec![(plus.clone(), bif("FOO")), (minus.clone(), bif("BAR"))],
soup(vec![num(1), infixr(90, var(minus.clone())), num(2)]),
vec![(plus, bif("FOO")), (minus.clone(), bif("BAR"))],
soup(vec![num(1), infixr(90, var(minus)), num(2)]),
);

assert_term_eq!(distribute(expr).unwrap(), expected);
Expand Down
Loading

0 comments on commit 4c76924

Please sign in to comment.