Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
Git Init with small 'isa' demo
Browse files Browse the repository at this point in the history
Change-Id: I39ed4809035ac72e822934b063617bab1de86fa9
  • Loading branch information
Cypher1 committed Apr 22, 2022
1 parent 0d1ca3f commit e3b592a
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Cargo.toml
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"
70 changes: 70 additions & 0 deletions src/main.rs
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));
}
}

0 comments on commit e3b592a

Please sign in to comment.