This repository has been archived by the owner on Mar 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change-Id: I39ed4809035ac72e822934b063617bab1de86fa9
- Loading branch information
Showing
2 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[package] | ||
name = "arcs-ibis" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
crepe = "0.1.5" | ||
lazy_static = "1.4.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#[macro_use] | ||
extern crate lazy_static; | ||
|
||
use crepe::crepe; | ||
use std::collections::HashMap; | ||
|
||
type Ent = u32; | ||
|
||
struct Context { | ||
last_ent: Ent, | ||
names: HashMap<Ent, String>, | ||
} | ||
|
||
impl Context { | ||
fn new() -> Self { | ||
Self { | ||
last_ent: 0, | ||
names: HashMap::new(), | ||
} | ||
} | ||
|
||
fn get_ent(&mut self) -> Ent { | ||
self.last_ent += 1; | ||
self.last_ent | ||
} | ||
|
||
fn name(&self, id: &Ent) -> &str { | ||
// TODO: Check! | ||
self.names.get(id).unwrap() | ||
} | ||
|
||
fn decl(&mut self, name: &str) -> Ent { | ||
let new_id: Ent = self.get_ent(); | ||
// TODO: Check! | ||
self.names.insert(new_id, name.to_string()); | ||
new_id | ||
} | ||
} | ||
|
||
crepe! { | ||
@input | ||
struct IsAClaim(Ent, Ent); | ||
@input | ||
struct Exists(Ent); | ||
|
||
@output | ||
struct IsA(Ent, Ent); | ||
|
||
IsA(x,x) <- Exists(x); | ||
IsA(x,x) <- IsAClaim(x, _); | ||
IsA(x,x) <- IsAClaim(_, x); | ||
IsA(x, z) <- IsAClaim(x, y), IsA(y, z); | ||
} | ||
|
||
fn main() { | ||
let mut ctx = Context::new(); | ||
let mut runtime = Crepe::new(); | ||
|
||
let socretes: Ent = ctx.decl("socretes"); | ||
let man: Ent = ctx.decl("man"); | ||
let mortal: Ent = ctx.decl("mortal"); | ||
|
||
runtime.extend(&[Exists(socretes), Exists(man), Exists(mortal)]); | ||
runtime.extend(&[IsAClaim(socretes, man), IsAClaim(man, mortal)]); | ||
|
||
let (reachable,) = &runtime.run(); | ||
for IsA(x, y) in reachable { | ||
println!("{} is a {}", ctx.name(x), ctx.name(y)); | ||
} | ||
} |